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
22 #define SEARCHING_AVI_INDEX 151 /* From shell32 resource library */
23 #define INVALID_AVI_INDEX 0xffff
25 static HWND hAnimateParentWnd
, hAnimateWnd
;
26 static const char animateTestClass
[] = "AnimateTestClass";
27 static WNDPROC animate_wndproc
;
28 static HANDLE shell32
;
30 /* try to make sure pending X events have been processed before continuing */
31 static void flush_events(void)
35 DWORD time
= GetTickCount() + diff
;
39 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min(10,diff
), QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
40 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
41 diff
= time
- GetTickCount();
45 static LRESULT CALLBACK
animate_test_wnd_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
54 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
59 static void update_window(HWND hWnd
)
62 ok(!GetUpdateRect(hWnd
, NULL
, FALSE
), "GetUpdateRect must return zero after UpdateWindow\n");
65 static void create_animate(DWORD parent_style
, DWORD animate_style
)
71 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
74 wc
.hInstance
= GetModuleHandleA(NULL
);
76 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
77 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
78 wc
.lpszMenuName
= NULL
;
79 wc
.lpszClassName
= animateTestClass
;
80 wc
.lpfnWndProc
= animate_test_wnd_proc
;
83 SetRect(&rect
, 0, 0, 200, 200);
84 ret
= AdjustWindowRect(&rect
, WS_OVERLAPPEDWINDOW
, FALSE
);
85 ok(ret
, "got %d\n", ret
);
87 hAnimateParentWnd
= CreateWindowExA(0, animateTestClass
, "Animate Test", WS_OVERLAPPEDWINDOW
| parent_style
,
88 CW_USEDEFAULT
, CW_USEDEFAULT
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
89 ok(hAnimateParentWnd
!= NULL
, "failed to create parent wnd\n");
91 GetClientRect(hAnimateParentWnd
, &rect
);
92 hAnimateWnd
= CreateWindowExA(0, ANIMATE_CLASSA
, NULL
, WS_CHILD
| WS_VISIBLE
| animate_style
,
93 0, 0, rect
.right
, rect
.bottom
, hAnimateParentWnd
, NULL
, shell32
, 0);
94 ok(hAnimateWnd
!= NULL
, "failed to create parent wnd\n");
95 animate_wndproc
= (WNDPROC
)SetWindowLongPtrA(hAnimateWnd
, GWLP_WNDPROC
, 0);
97 ShowWindow(hAnimateParentWnd
, SW_SHOWNORMAL
);
98 ok(GetUpdateRect(hAnimateParentWnd
, NULL
, FALSE
), "GetUpdateRect: There should be a region that needs to be updated\n");
100 update_window(hAnimateParentWnd
);
103 static void init(void)
106 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
108 hComctl32
= GetModuleHandleA("comctl32.dll");
109 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
110 if (pInitCommonControlsEx
)
112 INITCOMMONCONTROLSEX iccex
;
113 iccex
.dwSize
= sizeof(iccex
);
114 iccex
.dwICC
= ICC_ANIMATE_CLASS
;
115 pInitCommonControlsEx(&iccex
);
118 InitCommonControls();
120 shell32
= LoadLibraryA("Shell32.dll");
123 static void destroy_animate(void)
127 PostMessageA(hAnimateParentWnd
, WM_CLOSE
, 0, 0);
128 while (GetMessageA(&msg
,0,0,0))
130 TranslateMessage(&msg
);
131 DispatchMessageA(&msg
);
133 hAnimateParentWnd
= NULL
;
136 static void cleanup(void)
138 UnregisterClassA(animateTestClass
, GetModuleHandleA(NULL
));
141 static void test_play(void)
146 create_animate(0, 0);
147 SetLastError(0xdeadbeef);
148 res
= SendMessageA(hAnimateWnd
, ACM_OPENA
,(WPARAM
)shell32
, (LPARAM
)MAKEINTRESOURCE(INVALID_AVI_INDEX
));
149 err
= GetLastError();
150 ok(res
== 0, "Invalid video should have failed\n");
151 ok(err
== ERROR_RESOURCE_NAME_NOT_FOUND
, "Expected 1814, got %u\n", err
);
153 SetLastError(0xdeadbeef);
154 res
= SendMessageA(hAnimateWnd
, ACM_PLAY
, (WPARAM
) -1, MAKELONG(0, -1));
155 err
= GetLastError();
156 ok(res
== 0, "Play should have failed\n");
157 ok(err
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", err
);
160 create_animate(0, 0);
161 res
= SendMessageA(hAnimateWnd
, ACM_OPENA
,(WPARAM
)shell32
, (LPARAM
)MAKEINTRESOURCE(SEARCHING_AVI_INDEX
));
162 ok(res
!= 0, "Load AVI resource failed\n");
163 res
= SendMessageA(hAnimateWnd
, ACM_PLAY
, (WPARAM
) -1, MAKELONG(0, -1));
164 ok(res
!= 0, "Play should have worked\n");