[COMCTL32_WINETEST] Sync with Wine Staging 2.16. CORE-13762
[reactos.git] / rostests / winetests / comctl32 / animate.c
1 /* Unit tests for the animate control.
2 *
3 * Copyright 2016 Bruno Jesus
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
20 #include <stdarg.h>
21
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26 #include "commctrl.h"
27
28 #include "wine/test.h"
29
30 #define SEARCHING_AVI_INDEX 151 /* From shell32 resource library */
31 #define INVALID_AVI_INDEX 0xffff
32
33 static HWND hAnimateParentWnd, hAnimateWnd;
34 static const char animateTestClass[] = "AnimateTestClass";
35 static WNDPROC animate_wndproc;
36 static HANDLE shell32;
37
38 /* try to make sure pending X events have been processed before continuing */
39 static void flush_events(void)
40 {
41 MSG msg;
42 int diff = 100;
43 DWORD time = GetTickCount() + diff;
44
45 while (diff > 0)
46 {
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();
50 }
51 }
52
53 static LRESULT CALLBACK animate_test_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
54 {
55 switch(msg)
56 {
57 case WM_DESTROY:
58 PostQuitMessage(0);
59 break;
60
61 default:
62 return DefWindowProcA(hWnd, msg, wParam, lParam);
63 }
64 return 0L;
65 }
66
67 static void update_window(HWND hWnd)
68 {
69 UpdateWindow(hWnd);
70 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
71 }
72
73 static void create_animate(DWORD parent_style, DWORD animate_style)
74 {
75 WNDCLASSA wc;
76 RECT rect;
77 BOOL ret;
78
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);
90
91 SetRect(&rect, 0, 0, 200, 200);
92 ret = AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
93 ok(ret, "got %d\n", ret);
94
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");
98
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);
104
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);
109 }
110
111 static void init(void)
112 {
113 HMODULE hComctl32;
114 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
115
116 hComctl32 = GetModuleHandleA("comctl32.dll");
117 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
118 if (pInitCommonControlsEx)
119 {
120 INITCOMMONCONTROLSEX iccex;
121 iccex.dwSize = sizeof(iccex);
122 iccex.dwICC = ICC_ANIMATE_CLASS;
123 pInitCommonControlsEx(&iccex);
124 }
125 else
126 InitCommonControls();
127
128 shell32 = LoadLibraryA("Shell32.dll");
129 }
130
131 static void destroy_animate(void)
132 {
133 MSG msg;
134
135 PostMessageA(hAnimateParentWnd, WM_CLOSE, 0, 0);
136 while (GetMessageA(&msg,0,0,0))
137 {
138 TranslateMessage(&msg);
139 DispatchMessageA(&msg);
140 }
141 hAnimateParentWnd = NULL;
142 }
143
144 static void cleanup(void)
145 {
146 UnregisterClassA(animateTestClass, GetModuleHandleA(NULL));
147 }
148
149 static void test_play(void)
150 {
151 LONG res;
152 DWORD err;
153
154 create_animate(0, 0);
155 SetLastError(0xdeadbeef);
156 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, (LPARAM)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);
160
161 SetLastError(0xdeadbeef);
162 res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
163 err = GetLastError();
164 ok(res == 0, "Play should have failed\n");
165 ok(err == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", err);
166 destroy_animate();
167
168 create_animate(0, 0);
169 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, (LPARAM)MAKEINTRESOURCE(SEARCHING_AVI_INDEX));
170 ok(res != 0, "Load AVI resource failed\n");
171 res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
172 ok(res != 0, "Play should have worked\n");
173 destroy_animate();
174 }
175
176 START_TEST(animate)
177 {
178 init();
179
180 test_play();
181
182 cleanup();
183 }