ReactOS  0.4.14-dev-50-g13bb5e2
animate.c
Go to the documentation of this file.
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 
34 static const char animateTestClass[] = "AnimateTestClass";
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 
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 {
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 
80  wc.cbClsExtra = 0;
81  wc.cbWndExtra = 0;
83  wc.hIcon = NULL;
86  wc.lpszMenuName = NULL;
89  RegisterClassA(&wc);
90 
91  SetRect(&rect, 0, 0, 200, 200);
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 
101  0, 0, rect.right, rect.bottom, hAnimateParentWnd, NULL, shell32, 0);
102  ok(hAnimateWnd != NULL, "failed to create parent wnd\n");
104 
106  ok(GetUpdateRect(hAnimateParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
107  flush_events();
109 }
110 
111 static void destroy_animate(void)
112 {
113  MSG msg;
114 
116  while (GetMessageA(&msg,0,0,0))
117  {
120  }
122 }
123 
124 static void cleanup(void)
125 {
127 }
128 
129 static void test_play(void)
130 {
131  LONG res;
132  DWORD err;
133 
134  create_animate(0, 0);
135  SetLastError(0xdeadbeef);
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);
140 
141  SetLastError(0xdeadbeef);
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();
147 
148  create_animate(0, 0);
150  ok(res != 0, "Load AVI resource failed\n");
152  ok(res != 0, "Play should have worked\n");
153  destroy_animate();
154 }
155 
156 START_TEST(animate)
157 {
158  shell32 = LoadLibraryA("Shell32.dll");
159 
160  test_play();
161 
162  cleanup();
163 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI TranslateMessage(_In_ const MSG *)
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define INVALID_AVI_INDEX
Definition: animate.c:31
#define ERROR_RESOURCE_NAME_NOT_FOUND
Definition: winerror.h:1121
BOOL WINAPI PostMessageA(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static void update_window(HWND hWnd)
Definition: animate.c:67
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
static WNDPROC animate_wndproc
Definition: animate.c:35
BOOL WINAPI GetMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
int cbClsExtra
Definition: winuser.h:3139
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3145
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3144
#define WS_CHILD
Definition: pedump.c:617
__u16 time
Definition: mkdosfs.c:366
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI PeekMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define COLOR_WINDOW
Definition: winuser.h:908
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
static void test_play(void)
Definition: animate.c:129
static LRESULT CALLBACK animate_test_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: animate.c:53
static HANDLE shell32
Definition: animate.c:36
BOOL WINAPI AdjustWindowRect(_Inout_ LPRECT, _In_ DWORD, _In_ BOOL)
int cbWndExtra
Definition: winuser.h:3140
START_TEST(animate)
Definition: animate.c:156
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HCURSOR hCursor
Definition: winuser.h:3143
static void create_animate(DWORD parent_style, DWORD animate_style)
Definition: animate.c:73
#define CW_USEDEFAULT
Definition: winuser.h:225
#define MAKELONG(a, b)
Definition: typedefs.h:248
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
const char * LPCSTR
Definition: xmlstorage.h:183
static void cleanup(void)
Definition: animate.c:124
#define WM_DESTROY
Definition: winuser.h:1591
#define CS_VREDRAW
Definition: winuser.h:653
#define ACM_PLAY
Definition: commctrl.h:4128
static void destroy_animate(void)
Definition: animate.c:111
#define WM_CLOSE
Definition: winuser.h:1603
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define WAIT_TIMEOUT
Definition: dderror.h:14
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
static const char animateTestClass[]
Definition: animate.c:34
int ret
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI GetUpdateRect(_In_ HWND, _Out_opt_ LPRECT, _In_ BOOL)
#define SetWindowLongPtrA
Definition: winuser.h:5246
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define err(...)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LPCSTR lpszClassName
Definition: winuser.h:3146
#define ANIMATE_CLASSA
Definition: commctrl.h:4114
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
#define GWLP_WNDPROC
Definition: treelist.c:66
static void flush_events(void)
Definition: animate.c:39
UINT style
Definition: winuser.h:3137
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2880
#define ACM_OPENA
Definition: commctrl.h:4123
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define SW_SHOWNORMAL
Definition: winuser.h:764
static HWND hAnimateWnd
Definition: animate.c:33
HINSTANCE hInstance
Definition: winuser.h:3141
#define QS_ALLINPUT
Definition: winuser.h:874
#define SEARCHING_AVI_INDEX
Definition: animate.c:30
#define ok(value,...)
Definition: atltest.h:57
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
WNDPROC lpfnWndProc
Definition: winuser.h:3138
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
GLuint res
Definition: glext.h:9613
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI UnregisterClassA(_In_ LPCSTR, HINSTANCE)
#define PM_REMOVE
Definition: winuser.h:1182
LONG_PTR LRESULT
Definition: windef.h:209
#define WS_VISIBLE
Definition: pedump.c:620
HBRUSH WINAPI GetSysColorBrush(_In_ int)
static HWND hAnimateParentWnd
Definition: animate.c:33
LPARAM lParam
Definition: combotst.c:139
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
HICON hIcon
Definition: winuser.h:3142