mshtml: Added IHTMLDocument2::write implementation.
[wine] / dlls / shell32 / tests / systray.c
1 /* Unit tests for systray
2  *
3  * Copyright 2007 Mikolaj Zalewski
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 #define _WIN32_IE 0x600
20 #include <assert.h>
21 #include <stdarg.h>
22
23 #include <windows.h>
24
25 #include "wine/test.h"
26
27
28 static HWND hMainWnd;
29 static BOOL (WINAPI *pShell_NotifyIconW)(DWORD,PNOTIFYICONDATAW);
30
31 void test_cbsize(void)
32 {
33     NOTIFYICONDATAA nidA;
34
35     if (pShell_NotifyIconW)
36     {
37         NOTIFYICONDATAW nidW;
38
39         ZeroMemory(&nidW, sizeof(nidW));
40         nidW.cbSize = NOTIFYICONDATAW_V1_SIZE;
41         nidW.hWnd = hMainWnd;
42         nidW.uID = 1;
43         nidW.uFlags = NIF_ICON|NIF_MESSAGE;
44         nidW.hIcon = LoadIcon(NULL, IDI_APPLICATION);
45         nidW.uCallbackMessage = WM_USER+17;
46         ok(pShell_NotifyIconW(NIM_ADD, &nidW), "NIM_ADD failed!\n");
47
48         /* using an invalid cbSize does work */
49         nidW.cbSize = 3;
50         nidW.hWnd = hMainWnd;
51         nidW.uID = 1;
52         ok(pShell_NotifyIconW(NIM_DELETE, &nidW), "NIM_DELETE failed!\n");
53         /* as icon doesn't exist anymore - now there will be an error */
54         nidW.cbSize = sizeof(nidW);
55         ok(!pShell_NotifyIconW(NIM_DELETE, &nidW), "The icon was not deleted\n");
56     }
57
58     /* same for Shell_NotifyIconA */
59     ZeroMemory(&nidA, sizeof(nidA));
60     nidA.cbSize = NOTIFYICONDATAA_V1_SIZE;
61     nidA.hWnd = hMainWnd;
62     nidA.uID = 1;
63     nidA.uFlags = NIF_ICON|NIF_MESSAGE;
64     nidA.hIcon = LoadIcon(NULL, IDI_APPLICATION);
65     nidA.uCallbackMessage = WM_USER+17;
66     ok(Shell_NotifyIconA(NIM_ADD, &nidA), "NIM_ADD failed!\n");
67
68     /* using an invalid cbSize does work */
69     nidA.cbSize = 3;
70     nidA.hWnd = hMainWnd;
71     nidA.uID = 1;
72     ok(Shell_NotifyIconA(NIM_DELETE, &nidA), "NIM_DELETE failed!\n");
73     /* as icon doesn't exist anymore - now there will be an error */
74     nidA.cbSize = sizeof(nidA);
75     ok(!Shell_NotifyIconA(NIM_DELETE, &nidA), "The icon was not deleted\n");
76 }
77
78 static void test_SHAppBarMessage(void)
79 {
80     APPBARDATA abd;
81     HWND hwnd, foregnd;
82     UINT_PTR ret;
83
84     memset(&abd, 0xcc, sizeof(abd));
85     abd.cbSize = sizeof(abd);
86     abd.uEdge = ABE_BOTTOM;
87
88     hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
89     ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
90     ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
91
92     /* Presumably one can pass a hwnd with ABM_GETAUTOHIDEBAR to specify a monitor.
93        Pass the foreground window and check */
94     foregnd = GetForegroundWindow();
95     if(foregnd)
96     {
97         abd.hWnd = foregnd;
98         hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
99         ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
100         ok(abd.hWnd == foregnd, "hWnd overwritten\n");
101         if(hwnd)
102         {
103             HMONITOR appbar_mon, foregnd_mon;
104             appbar_mon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
105             foregnd_mon = MonitorFromWindow(foregnd, MONITOR_DEFAULTTONEAREST);
106             ok(appbar_mon == foregnd_mon, "Windows on different monitors\n");
107         }
108     }
109
110     memset(&abd, 0xcc, sizeof(abd));
111     abd.cbSize = sizeof(abd);
112     ret = SHAppBarMessage(ABM_GETTASKBARPOS, &abd);
113     if(ret)
114     {
115         ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
116 todo_wine
117 {
118         ok(abd.uEdge >= ABE_LEFT && abd.uEdge <= ABE_BOTTOM, "uEdge not returned\n");
119         ok(abd.rc.left != 0xcccccccc, "rc not updated\n");
120 }
121     }
122
123     return;
124 }
125
126 START_TEST(systray)
127 {
128     WNDCLASSA wc;
129     MSG msg;
130     RECT rc;
131     HMODULE hdll;
132
133     hdll = GetModuleHandleA("shell32.dll");
134     pShell_NotifyIconW = (void*)GetProcAddress(hdll, "Shell_NotifyIconW");
135
136     wc.style = CS_HREDRAW | CS_VREDRAW;
137     wc.cbClsExtra = 0;
138     wc.cbWndExtra = 0;
139     wc.hInstance = GetModuleHandleA(NULL);
140     wc.hIcon = NULL;
141     wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
142     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
143     wc.lpszMenuName = NULL;
144     wc.lpszClassName = "MyTestWnd";
145     wc.lpfnWndProc = DefWindowProc;
146     RegisterClassA(&wc);
147
148     hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
149       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
150     GetClientRect(hMainWnd, &rc);
151     ShowWindow(hMainWnd, SW_SHOW);
152
153     test_cbsize();
154
155     PostQuitMessage(0);
156     while(GetMessageA(&msg,0,0,0)) {
157         TranslateMessage(&msg);
158         DispatchMessageA(&msg);
159     }
160     DestroyWindow(hMainWnd);
161
162     test_SHAppBarMessage();
163 }