wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / comctl32 / tests / animate.c
blob400de55b5eb8b562668e626a2f290fecf6fad3d0
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 destroy_animate(void)
113 MSG msg;
115 PostMessageA(hAnimateParentWnd, WM_CLOSE, 0, 0);
116 while (GetMessageA(&msg,0,0,0))
118 TranslateMessage(&msg);
119 DispatchMessageA(&msg);
121 hAnimateParentWnd = NULL;
124 static void cleanup(void)
126 UnregisterClassA(animateTestClass, GetModuleHandleA(NULL));
129 static void test_play(void)
131 LONG res;
132 DWORD err;
134 create_animate(0, 0);
135 SetLastError(0xdeadbeef);
136 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, MAKEINTRESOURCE(INVALID_AVI_INDEX));
137 err = GetLastError();
138 ok(res == 0, "Invalid video should have failed\n");
139 ok(err == ERROR_RESOURCE_NAME_NOT_FOUND, "Expected 1814, got %u\n", err);
141 SetLastError(0xdeadbeef);
142 res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
143 err = GetLastError();
144 ok(res == 0, "Play should have failed\n");
145 ok(err == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", err);
146 destroy_animate();
148 create_animate(0, 0);
149 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, MAKEINTRESOURCE(SEARCHING_AVI_INDEX));
150 ok(res != 0, "Load AVI resource failed\n");
151 res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
152 ok(res != 0, "Play should have worked\n");
153 destroy_animate();
156 START_TEST(animate)
158 shell32 = LoadLibraryA("Shell32.dll");
160 test_play();
162 cleanup();