shell32/tests: Use SetRect instead of open coding it.
[wine.git] / dlls / comctl32 / tests / animate.c
blobc64dbfaf73d44bdffea416c5c6102fa9cf262940
1 /* Unit tests for the animate control.
3 * Copyright 2016 Bruno Jesus
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 "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26 #include "commctrl.h"
28 #include "wine/test.h"
30 #define SEARCHING_AVI_INDEX 151 /* From shell32 resource library */
31 #define INVALID_AVI_INDEX 0xffff
33 static HWND hAnimateParentWnd, hAnimateWnd;
34 static const char animateTestClass[] = "AnimateTestClass";
35 static WNDPROC animate_wndproc;
36 static HANDLE shell32;
38 /* try to make sure pending X events have been processed before continuing */
39 static void flush_events(void)
41 MSG msg;
42 int diff = 100;
43 DWORD time = GetTickCount() + diff;
45 while (diff > 0)
47 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
48 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
49 diff = time - GetTickCount();
53 static LRESULT CALLBACK animate_test_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
55 switch(msg)
57 case WM_DESTROY:
58 PostQuitMessage(0);
59 break;
61 default:
62 return DefWindowProcA(hWnd, msg, wParam, lParam);
64 return 0L;
67 static void update_window(HWND hWnd)
69 UpdateWindow(hWnd);
70 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
73 static void create_animate(DWORD parent_style, DWORD animate_style)
75 WNDCLASSA wc;
76 RECT rect;
77 BOOL ret;
79 wc.style = CS_HREDRAW | CS_VREDRAW;
80 wc.cbClsExtra = 0;
81 wc.cbWndExtra = 0;
82 wc.hInstance = GetModuleHandleA(NULL);
83 wc.hIcon = NULL;
84 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
85 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
86 wc.lpszMenuName = NULL;
87 wc.lpszClassName = animateTestClass;
88 wc.lpfnWndProc = animate_test_wnd_proc;
89 RegisterClassA(&wc);
91 SetRect(&rect, 0, 0, 200, 200);
92 ret = AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
93 ok(ret, "got %d\n", ret);
95 hAnimateParentWnd = CreateWindowExA(0, animateTestClass, "Animate Test", WS_OVERLAPPEDWINDOW | parent_style,
96 CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
97 ok(hAnimateParentWnd != NULL, "failed to create parent wnd\n");
99 GetClientRect(hAnimateParentWnd, &rect);
100 hAnimateWnd = CreateWindowExA(0, ANIMATE_CLASSA, NULL, WS_CHILD | WS_VISIBLE | animate_style,
101 0, 0, rect.right, rect.bottom, hAnimateParentWnd, NULL, shell32, 0);
102 ok(hAnimateWnd != NULL, "failed to create parent wnd\n");
103 animate_wndproc = (WNDPROC)SetWindowLongPtrA(hAnimateWnd, GWLP_WNDPROC, 0);
105 ShowWindow(hAnimateParentWnd, SW_SHOWNORMAL);
106 ok(GetUpdateRect(hAnimateParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
107 flush_events();
108 update_window(hAnimateParentWnd);
111 static void init(void)
113 HMODULE hComctl32;
114 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
116 hComctl32 = GetModuleHandleA("comctl32.dll");
117 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
118 if (pInitCommonControlsEx)
120 INITCOMMONCONTROLSEX iccex;
121 iccex.dwSize = sizeof(iccex);
122 iccex.dwICC = ICC_ANIMATE_CLASS;
123 pInitCommonControlsEx(&iccex);
125 else
126 InitCommonControls();
128 shell32 = LoadLibraryA("Shell32.dll");
131 static void destroy_animate(void)
133 MSG msg;
135 PostMessageA(hAnimateParentWnd, WM_CLOSE, 0, 0);
136 while (GetMessageA(&msg,0,0,0))
138 TranslateMessage(&msg);
139 DispatchMessageA(&msg);
141 hAnimateParentWnd = NULL;
144 static void cleanup(void)
146 UnregisterClassA(animateTestClass, GetModuleHandleA(NULL));
149 static void test_play(void)
151 LONG res;
152 DWORD err;
154 create_animate(0, 0);
155 SetLastError(0xdeadbeef);
156 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, MAKEINTRESOURCE(INVALID_AVI_INDEX));
157 err = GetLastError();
158 ok(res == 0, "Invalid video should have failed\n");
159 ok(err == ERROR_RESOURCE_NAME_NOT_FOUND, "Expected 1814, got %u\n", err);
161 SetLastError(0xdeadbeef);
162 res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
163 ok(res == 0, "Play should have failed\n");
164 ok(err == ERROR_RESOURCE_NAME_NOT_FOUND, "Expected 1814, got %u\n", err);
165 destroy_animate();
167 create_animate(0, 0);
168 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, MAKEINTRESOURCE(SEARCHING_AVI_INDEX));
169 ok(res != 0, "Load AVI resource failed\n");
170 res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
171 ok(res != 0, "Play should have worked\n");
172 destroy_animate();
175 START_TEST(animate)
177 init();
179 test_play();
181 cleanup();