TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / shell32 / tests / appbar.c
blob813813115695c15b22a872e1969cdcad751af286
1 /* Unit tests for appbars
3 * Copyright 2008 Vincent Povirk for CodeWeavers
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.
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.
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
20 #include <stdarg.h>
22 #include <windows.h>
23 #include "shellapi.h"
25 #include "wine/test.h"
27 #define MSG_APPBAR WM_APP
29 static const CHAR testwindow_class[] = "testwindow";
31 static HMONITOR (WINAPI *pMonitorFromWindow)(HWND, DWORD);
32 static HRESULT (WINAPI *pGetCurrentProcessExplicitAppUserModelID)(PWSTR*);
34 typedef BOOL (*boolean_function)(void);
36 struct testwindow_info
38 HWND hwnd;
39 BOOL registered;
40 BOOL to_be_deleted;
41 RECT desired_rect;
42 UINT edge;
43 RECT allocated_rect;
46 static struct testwindow_info windows[3];
48 static int expected_bottom;
50 static void testwindow_setpos(HWND hwnd)
52 struct testwindow_info* info = (struct testwindow_info*)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
53 APPBARDATA abd;
54 BOOL ret;
56 ok(info != NULL, "got unexpected ABN_POSCHANGED notification\n");
58 if (!info || !info->registered)
60 return;
63 if (info->to_be_deleted)
65 win_skip("Some Win95 and NT4 systems send messages to removed taskbars\n");
66 return;
69 abd.cbSize = sizeof(abd);
70 abd.hWnd = hwnd;
71 abd.uEdge = info->edge;
72 abd.rc = info->desired_rect;
73 ret = SHAppBarMessage(ABM_QUERYPOS, &abd);
74 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
75 switch (info->edge)
77 case ABE_BOTTOM:
78 ok(info->desired_rect.top == abd.rc.top, "ABM_QUERYPOS changed top of rect from %i to %i\n", info->desired_rect.top, abd.rc.top);
79 abd.rc.top = abd.rc.bottom - (info->desired_rect.bottom - info->desired_rect.top);
80 break;
81 case ABE_LEFT:
82 ok(info->desired_rect.right == abd.rc.right, "ABM_QUERYPOS changed right of rect from %i to %i\n", info->desired_rect.right, abd.rc.right);
83 abd.rc.right = abd.rc.left + (info->desired_rect.right - info->desired_rect.left);
84 break;
85 case ABE_RIGHT:
86 ok(info->desired_rect.left == abd.rc.left, "ABM_QUERYPOS changed left of rect from %i to %i\n", info->desired_rect.left, abd.rc.left);
87 abd.rc.left = abd.rc.right - (info->desired_rect.right - info->desired_rect.left);
88 break;
89 case ABE_TOP:
90 ok(info->desired_rect.bottom == abd.rc.bottom, "ABM_QUERYPOS changed bottom of rect from %i to %i\n", info->desired_rect.bottom, abd.rc.bottom);
91 abd.rc.bottom = abd.rc.top + (info->desired_rect.bottom - info->desired_rect.top);
92 break;
95 ret = SHAppBarMessage(ABM_SETPOS, &abd);
96 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
98 info->allocated_rect = abd.rc;
99 MoveWindow(hwnd, abd.rc.left, abd.rc.top, abd.rc.right-abd.rc.left, abd.rc.bottom-abd.rc.top, TRUE);
102 static LRESULT CALLBACK testwindow_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
104 switch(msg)
106 case MSG_APPBAR:
108 switch(wparam)
110 case ABN_POSCHANGED:
111 testwindow_setpos(hwnd);
112 break;
114 return 0;
118 return DefWindowProcA(hwnd, msg, wparam, lparam);
121 /* process pending messages until a condition is true or 3 seconds pass */
122 static void do_events_until(boolean_function test)
124 MSG msg;
125 UINT_PTR timerid;
126 BOOL timedout=FALSE;
128 timerid = SetTimer(0, 0, 3000, NULL);
130 while (1)
132 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
134 if (msg.hwnd == 0 && msg.message == WM_TIMER && msg.wParam == timerid)
135 timedout = TRUE;
136 TranslateMessage(&msg);
137 DispatchMessageA(&msg);
139 if (timedout || test())
140 break;
141 WaitMessage();
144 KillTimer(0, timerid);
147 /* process any pending messages */
148 static void do_events(void)
150 MSG msg;
152 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
154 TranslateMessage(&msg);
155 DispatchMessageA(&msg);
159 static BOOL no_appbars_intersect(void)
161 int i, j;
162 RECT rc;
164 for (i=0; i<2; i++)
166 for (j=i+1; j<3; j++)
168 if (windows[i].registered && windows[j].registered &&
169 IntersectRect(&rc, &windows[i].allocated_rect, &windows[j].allocated_rect))
170 return FALSE;
173 return TRUE;
176 static BOOL got_expected_bottom(void)
178 return (no_appbars_intersect() && windows[1].allocated_rect.bottom == expected_bottom);
181 static void register_testwindow_class(void)
183 WNDCLASSEXA cls;
185 ZeroMemory(&cls, sizeof(cls));
186 cls.cbSize = sizeof(cls);
187 cls.style = 0;
188 cls.lpfnWndProc = testwindow_wndproc;
189 cls.hInstance = NULL;
190 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
191 cls.hbrBackground = (HBRUSH) COLOR_WINDOW;
192 cls.lpszClassName = testwindow_class;
194 RegisterClassExA(&cls);
197 #define test_window_rects(a, b) \
198 ok(!IntersectRect(&rc, &windows[a].allocated_rect, &windows[b].allocated_rect), \
199 "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n", \
200 windows[a].allocated_rect.left, windows[a].allocated_rect.top, windows[a].allocated_rect.right, windows[a].allocated_rect.bottom, \
201 windows[b].allocated_rect.left, windows[b].allocated_rect.top, windows[b].allocated_rect.right, windows[b].allocated_rect.bottom)
203 static void test_setpos(void)
205 APPBARDATA abd;
206 RECT rc;
207 int screen_width, screen_height;
208 BOOL ret;
209 int org_bottom1;
211 screen_width = GetSystemMetrics(SM_CXSCREEN);
212 screen_height = GetSystemMetrics(SM_CYSCREEN);
214 /* create and register windows[0] */
215 windows[0].hwnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
216 testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0,
217 NULL, NULL, NULL, NULL);
218 ok(windows[0].hwnd != NULL, "couldn't create window\n");
219 do_events();
220 abd.cbSize = sizeof(abd);
221 abd.hWnd = windows[0].hwnd;
222 abd.uCallbackMessage = MSG_APPBAR;
223 ret = SHAppBarMessage(ABM_NEW, &abd);
224 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
226 /* ABM_NEW should return FALSE if the window is already registered */
227 ret = SHAppBarMessage(ABM_NEW, &abd);
228 ok(ret == FALSE, "SHAppBarMessage returned %i\n", ret);
229 do_events();
231 /* dock windows[0] to the bottom of the screen */
232 windows[0].registered = TRUE;
233 windows[0].to_be_deleted = FALSE;
234 windows[0].edge = ABE_BOTTOM;
235 windows[0].desired_rect.left = 0;
236 windows[0].desired_rect.right = screen_width;
237 windows[0].desired_rect.top = screen_height - 15;
238 windows[0].desired_rect.bottom = screen_height;
239 SetWindowLongPtrA(windows[0].hwnd, GWLP_USERDATA, (LONG_PTR)&windows[0]);
240 testwindow_setpos(windows[0].hwnd);
241 do_events();
243 /* create and register windows[1] */
244 windows[1].hwnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
245 testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0,
246 NULL, NULL, NULL, NULL);
247 ok(windows[1].hwnd != NULL, "couldn't create window\n");
248 abd.hWnd = windows[1].hwnd;
249 ret = SHAppBarMessage(ABM_NEW, &abd);
250 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
252 /* dock windows[1] to the bottom of the screen */
253 windows[1].registered = TRUE;
254 windows[1].to_be_deleted = FALSE;
255 windows[1].edge = ABE_BOTTOM;
256 windows[1].desired_rect.left = 0;
257 windows[1].desired_rect.right = screen_width;
258 windows[1].desired_rect.top = screen_height - 10;
259 windows[1].desired_rect.bottom = screen_height;
260 SetWindowLongPtrA(windows[1].hwnd, GWLP_USERDATA, (LONG_PTR)&windows[1]);
261 testwindow_setpos(windows[1].hwnd);
263 /* the windows are adjusted to they don't overlap */
264 do_events_until(no_appbars_intersect);
265 test_window_rects(0, 1);
267 /* make windows[0] larger, forcing windows[1] to move out of its way */
268 windows[0].desired_rect.top = screen_height - 20;
269 testwindow_setpos(windows[0].hwnd);
270 do_events_until(no_appbars_intersect);
271 test_window_rects(0, 1);
273 /* create and register windows[2] */
274 windows[2].hwnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
275 testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0,
276 NULL, NULL, NULL, NULL);
277 ok(windows[2].hwnd != NULL, "couldn't create window\n");
278 do_events();
280 abd.hWnd = windows[2].hwnd;
281 ret = SHAppBarMessage(ABM_NEW, &abd);
282 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
284 /* dock windows[2] to the bottom of the screen */
285 windows[2].registered = TRUE;
286 windows[2].to_be_deleted = FALSE;
287 windows[2].edge = ABE_BOTTOM;
288 windows[2].desired_rect.left = 0;
289 windows[2].desired_rect.right = screen_width;
290 windows[2].desired_rect.top = screen_height - 10;
291 windows[2].desired_rect.bottom = screen_height;
292 SetWindowLongPtrA(windows[2].hwnd, GWLP_USERDATA, (LONG_PTR)&windows[2]);
293 testwindow_setpos(windows[2].hwnd);
295 do_events_until(no_appbars_intersect);
296 test_window_rects(0, 1);
297 test_window_rects(0, 2);
298 test_window_rects(1, 2);
300 /* move windows[2] to the right side of the screen */
301 windows[2].edge = ABE_RIGHT;
302 windows[2].desired_rect.left = screen_width - 15;
303 windows[2].desired_rect.right = screen_width;
304 windows[2].desired_rect.top = 0;
305 windows[2].desired_rect.bottom = screen_height;
306 testwindow_setpos(windows[2].hwnd);
308 do_events_until(no_appbars_intersect);
309 test_window_rects(0, 1);
310 test_window_rects(0, 2);
311 test_window_rects(1, 2);
313 /* move windows[1] to the top of the screen */
314 windows[1].edge = ABE_TOP;
315 windows[1].desired_rect.left = 0;
316 windows[1].desired_rect.right = screen_width;
317 windows[1].desired_rect.top = 0;
318 windows[1].desired_rect.bottom = 15;
319 testwindow_setpos(windows[1].hwnd);
321 do_events_until(no_appbars_intersect);
322 test_window_rects(0, 1);
323 test_window_rects(0, 2);
324 test_window_rects(1, 2);
326 /* move windows[1] back to the bottom of the screen */
327 windows[1].edge = ABE_BOTTOM;
328 windows[1].desired_rect.left = 0;
329 windows[1].desired_rect.right = screen_width;
330 windows[1].desired_rect.top = screen_height - 10;
331 windows[1].desired_rect.bottom = screen_height;
332 testwindow_setpos(windows[1].hwnd);
334 do_events_until(no_appbars_intersect);
335 test_window_rects(0, 1);
336 test_window_rects(0, 2);
337 test_window_rects(1, 2);
339 /* removing windows[0] will cause windows[1] to move down into its space */
340 expected_bottom = max(windows[0].allocated_rect.bottom, windows[1].allocated_rect.bottom);
341 org_bottom1 = windows[1].allocated_rect.bottom;
342 ok(windows[0].allocated_rect.bottom > windows[1].allocated_rect.bottom,
343 "Expected windows[0] to be lower than windows[1]\n");
345 abd.hWnd = windows[0].hwnd;
346 windows[0].to_be_deleted = TRUE;
347 ret = SHAppBarMessage(ABM_REMOVE, &abd);
348 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
349 windows[0].registered = FALSE;
350 DestroyWindow(windows[0].hwnd);
352 do_events_until(got_expected_bottom);
354 if (windows[1].allocated_rect.bottom == org_bottom1)
355 win_skip("Some broken Vista boxes don't move the higher appbar down\n");
356 else
357 ok(windows[1].allocated_rect.bottom == expected_bottom,
358 "windows[1]'s bottom is %i, expected %i\n",
359 windows[1].allocated_rect.bottom, expected_bottom);
361 test_window_rects(1, 2);
363 /* remove the other windows */
364 abd.hWnd = windows[1].hwnd;
365 windows[1].to_be_deleted = TRUE;
366 ret = SHAppBarMessage(ABM_REMOVE, &abd);
367 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
368 windows[1].registered = FALSE;
369 DestroyWindow(windows[1].hwnd);
371 abd.hWnd = windows[2].hwnd;
372 windows[2].to_be_deleted = TRUE;
373 ret = SHAppBarMessage(ABM_REMOVE, &abd);
374 ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
375 windows[2].registered = FALSE;
376 DestroyWindow(windows[2].hwnd);
379 static void test_appbarget(void)
381 APPBARDATA abd;
382 HWND hwnd, foregnd, unset_hwnd;
383 UINT_PTR ret;
385 memset(&abd, 0xcc, sizeof(abd));
386 memset(&unset_hwnd, 0xcc, sizeof(unset_hwnd));
387 abd.cbSize = sizeof(abd);
388 abd.uEdge = ABE_BOTTOM;
390 hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
391 ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
392 ok(abd.hWnd == unset_hwnd, "hWnd overwritten %p\n",abd.hWnd);
394 if (!pMonitorFromWindow)
396 win_skip("MonitorFromWindow is not available\n");
398 else
400 /* Presumably one can pass a hwnd with ABM_GETAUTOHIDEBAR to specify a monitor.
401 Pass the foreground window and check */
402 foregnd = GetForegroundWindow();
403 if(foregnd)
405 abd.hWnd = foregnd;
406 hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
407 ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
408 ok(abd.hWnd == foregnd, "hWnd overwritten\n");
409 if(hwnd)
411 HMONITOR appbar_mon, foregnd_mon;
412 appbar_mon = pMonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
413 foregnd_mon = pMonitorFromWindow(foregnd, MONITOR_DEFAULTTONEAREST);
414 ok(appbar_mon == foregnd_mon, "Windows on different monitors\n");
419 memset(&abd, 0xcc, sizeof(abd));
420 abd.cbSize = sizeof(abd);
421 ret = SHAppBarMessage(ABM_GETTASKBARPOS, &abd);
422 if(ret)
424 ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
425 ok(abd.uEdge <= ABE_BOTTOM ||
426 broken(abd.uEdge == 0xcccccccc), /* Some Win95 and NT4 */
427 "uEdge not returned\n");
428 ok(abd.rc.left != 0xcccccccc, "rc not updated\n");
431 return;
434 static void test_GetCurrentProcessExplicitAppUserModelID(void)
436 WCHAR *appid;
437 HRESULT hr;
439 if (!pGetCurrentProcessExplicitAppUserModelID)
441 win_skip("GetCurrentProcessExplicitAppUserModelID() is not supported.\n");
442 return;
445 if (0) /* crashes on native */
446 hr = pGetCurrentProcessExplicitAppUserModelID(NULL);
448 appid = (void*)0xdeadbeef;
449 hr = pGetCurrentProcessExplicitAppUserModelID(&appid);
450 todo_wine
451 ok(hr == E_FAIL, "got 0x%08x\n", hr);
452 ok(appid == NULL, "got %p\n", appid);
455 START_TEST(appbar)
457 HMODULE huser32, hshell32;
459 huser32 = GetModuleHandleA("user32.dll");
460 hshell32 = GetModuleHandleA("shell32.dll");
461 pMonitorFromWindow = (void*)GetProcAddress(huser32, "MonitorFromWindow");
462 pGetCurrentProcessExplicitAppUserModelID = (void*)GetProcAddress(hshell32, "GetCurrentProcessExplicitAppUserModelID");
464 register_testwindow_class();
466 test_setpos();
467 test_appbarget();
468 test_GetCurrentProcessExplicitAppUserModelID();