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 destroy_animate(void) 112 { 113 MSG msg; 114 115 PostMessageA(hAnimateParentWnd, WM_CLOSE, 0, 0); 116 while (GetMessageA(&msg,0,0,0)) 117 { 118 TranslateMessage(&msg); 119 DispatchMessageA(&msg); 120 } 121 hAnimateParentWnd = NULL; 122 } 123 124 static void cleanup(void) 125 { 126 UnregisterClassA(animateTestClass, GetModuleHandleA(NULL)); 127 } 128 129 static void test_play(void) 130 { 131 LONG res; 132 DWORD err; 133 134 create_animate(0, 0); 135 SetLastError(0xdeadbeef); 136 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, (LPARAM)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); 140 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(); 147 148 create_animate(0, 0); 149 res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, (LPARAM)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(); 154 } 155 156 START_TEST(animate) 157 { 158 shell32 = LoadLibraryA("Shell32.dll"); 159 160 test_play(); 161 162 cleanup(); 163 } 164