1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for DrawThemeParentBackground 5 * PROGRAMMERS: Giannis Adamopoulos 6 */ 7 8 #include <apitest.h> 9 #include <stdio.h> 10 #include <windows.h> 11 #include <uxtheme.h> 12 #include <undocuser.h> 13 #include <msgtrace.h> 14 #include <user32testhelpers.h> 15 16 HWND hWnd1, hWnd2; 17 18 static int get_iwnd(HWND hWnd) 19 { 20 if(hWnd == hWnd1) return 1; 21 else if(hWnd == hWnd2) return 2; 22 else return 0; 23 } 24 25 static LRESULT CALLBACK TestProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 26 { 27 int iwnd = get_iwnd(hwnd); 28 29 if(message > WM_USER || !iwnd || message == WM_GETICON) 30 return DefWindowProc(hwnd, message, wParam, lParam); 31 32 RECORD_MESSAGE(iwnd, message, SENT, 0,0); 33 return DefWindowProc(hwnd, message, wParam, lParam); 34 } 35 36 static void FlushMessages() 37 { 38 MSG msg; 39 40 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) 41 { 42 int iwnd = get_iwnd(msg.hwnd); 43 if(iwnd && msg.message <= WM_USER) 44 RECORD_MESSAGE(iwnd, msg.message, POST,0,0); 45 DispatchMessageW( &msg ); 46 } 47 } 48 49 MSG_ENTRY draw_parent_chain[]={{1, WM_ERASEBKGND}, 50 {1, WM_PRINTCLIENT}, 51 {0,0}}; 52 53 void Test_Messages() 54 { 55 HDC hdc; 56 RECT rc; 57 58 RegisterSimpleClass(TestProc, L"testClass"); 59 60 hWnd1 = CreateWindowW(L"testClass", L"Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 200, 200, 0, NULL, NULL, NULL); 61 ok (hWnd1 != NULL, "Expected CreateWindowW to succeed\n"); 62 63 hWnd2 = CreateWindowW(L"testClass", L"test window", WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, hWnd1, NULL, NULL, NULL); 64 ok (hWnd2 != NULL, "Expected CreateWindowW to succeed\n"); 65 66 FlushMessages(); 67 EMPTY_CACHE(); 68 69 hdc = GetDC(hWnd1); 70 71 DrawThemeParentBackground(hWnd2, hdc, NULL); 72 FlushMessages(); 73 COMPARE_CACHE(draw_parent_chain); 74 75 DrawThemeParentBackground(hWnd1, hdc, NULL); 76 FlushMessages(); 77 COMPARE_CACHE(empty_chain); 78 79 ShowWindow(hWnd1, SW_SHOW); 80 UpdateWindow(hWnd1); 81 ShowWindow(hWnd2, SW_SHOW); 82 UpdateWindow(hWnd2); 83 84 FlushMessages(); 85 EMPTY_CACHE(); 86 87 DrawThemeParentBackground(hWnd2, NULL, NULL); 88 FlushMessages(); 89 COMPARE_CACHE(empty_chain); 90 91 DrawThemeParentBackground(hWnd1, NULL, NULL); 92 FlushMessages(); 93 COMPARE_CACHE(empty_chain); 94 95 DrawThemeParentBackground(hWnd2, hdc, NULL); 96 FlushMessages(); 97 COMPARE_CACHE(draw_parent_chain); 98 99 DrawThemeParentBackground(hWnd1, hdc, NULL); 100 FlushMessages(); 101 COMPARE_CACHE(empty_chain); 102 103 memset(&rc, 0, sizeof(rc)); 104 105 DrawThemeParentBackground(hWnd2, hdc, &rc); 106 FlushMessages(); 107 COMPARE_CACHE(draw_parent_chain); 108 109 DrawThemeParentBackground(hWnd1, hdc, &rc); 110 FlushMessages(); 111 COMPARE_CACHE(empty_chain); 112 } 113 114 BOOL bGotException; 115 116 static LONG WINAPI VEHandler_1(PEXCEPTION_POINTERS ExceptionInfo) 117 { 118 ok(FALSE, "VEHandler_1 called!\n"); 119 return EXCEPTION_CONTINUE_SEARCH; 120 } 121 122 static LONG WINAPI VEHandler_2(PEXCEPTION_POINTERS ExceptionInfo) 123 { 124 bGotException = TRUE; 125 return EXCEPTION_CONTINUE_SEARCH; 126 } 127 128 void Test_Params() 129 { 130 HRESULT hr; 131 HDC hdc; 132 PVOID pVEH; 133 134 bGotException = FALSE; 135 136 pVEH = AddVectoredExceptionHandler(1, VEHandler_1); 137 138 hr = DrawThemeParentBackground(NULL, NULL, NULL); 139 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 140 141 hr = DrawThemeParentBackground((HWND)(ULONG_PTR)0xdeaddeaddeaddeadULL, NULL, NULL); 142 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 143 144 hr = DrawThemeParentBackground(NULL, (HDC)(ULONG_PTR)0xdeaddeaddeaddeadULL, NULL); 145 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 146 147 hr = DrawThemeParentBackground((HWND)(ULONG_PTR)0xdeaddeaddeaddeadULL, (HDC)(ULONG_PTR)0xdeaddeaddeaddeadULL, NULL); 148 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 149 150 RemoveVectoredExceptionHandler(pVEH); 151 152 RegisterSimpleClass(DefWindowProcW, L"testClass2"); 153 154 hWnd1 = CreateWindowW(L"testClass2", L"Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 200, 200, 0, NULL, NULL, NULL); 155 ok (hWnd1 != NULL, "Expected CreateWindowW to succeed\n"); 156 hWnd2 = CreateWindowW(L"testClass2", L"test window", WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, hWnd1, NULL, NULL, NULL); 157 ok (hWnd2 != NULL, "Expected CreateWindowW to succeed\n"); 158 159 ShowWindow(hWnd1, SW_SHOW); 160 UpdateWindow(hWnd1); 161 ShowWindow(hWnd2, SW_SHOW); 162 UpdateWindow(hWnd2); 163 164 hr = DrawThemeParentBackground(hWnd1, NULL, NULL); 165 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 166 167 hdc = GetDC(hWnd1); 168 ok (hdc != NULL, "Expected GetDC to succeed\n"); 169 170 hr = DrawThemeParentBackground(NULL, hdc, NULL); 171 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 172 173 hr = DrawThemeParentBackground(hWnd1, hdc, NULL); 174 ok (hr == S_OK, "Expected success got 0x%lx error\n", hr); 175 176 hr = DrawThemeParentBackground(hWnd1, (HDC)(ULONG_PTR)0xdeaddeaddeaddeadULL, NULL); 177 ok (hr == S_OK, "Expected success got 0x%lx error\n", hr); 178 179 pVEH = AddVectoredExceptionHandler(1, VEHandler_2); 180 hr = DrawThemeParentBackground(hWnd1, hdc, (RECT*)(ULONG_PTR)0xdeaddeaddeaddeadULL); 181 ok (hr == E_POINTER, "Expected success got 0x%lx error\n", hr); 182 RemoveVectoredExceptionHandler(pVEH); 183 ok (bGotException == TRUE, "Excepted a handled exception\n"); 184 185 hr = DrawThemeParentBackground(hWnd2, NULL, NULL); 186 ok (hr == E_HANDLE, "Expected E_HANDLE got 0x%lx error\n", hr); 187 188 hr = DrawThemeParentBackground(hWnd2, hdc, NULL); 189 if (IsThemeActive()) 190 ok (hr == S_FALSE, "Expected S_FALSE got 0x%lx error\n", hr); 191 else 192 skip("Theme not active\n"); 193 194 ReleaseDC(hWnd1, hdc); 195 hdc = GetDC(hWnd2); 196 ok (hdc != NULL, "Expected GetDC to succeed\n"); 197 198 hr = DrawThemeParentBackground(hWnd1, hdc, NULL); 199 ok (hr == S_OK, "Expected success got 0x%lx error\n", hr); 200 201 hr = DrawThemeParentBackground(hWnd2, hdc, NULL); 202 if (IsThemeActive()) 203 ok (hr == S_FALSE, "Expected S_FALSE got 0x%lx error\n", hr); 204 else 205 skip("Theme not active\n"); 206 ReleaseDC(hWnd2, hdc); 207 208 209 } 210 211 START_TEST(DrawThemeParentBackground) 212 { 213 Test_Messages(); 214 Test_Params(); 215 } 216