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
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)
43 DWORD time
= GetTickCount() + diff
;
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
)
62 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
67 static void update_window(HWND 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
)
79 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
82 wc
.hInstance
= GetModuleHandleA(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
;
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");
108 update_window(hAnimateParentWnd
);
111 static void init(void)
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
);
126 InitCommonControls();
128 shell32
= LoadLibraryA("Shell32.dll");
131 static void destroy_animate(void)
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)
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
);
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");