comdlg32: Clamp hue and saturation when clicking in colour graph in colour dialog.
[wine/wine64.git] / dlls / uxtheme / tests / system.c
blob1fd3d9742931c2bd4d45bde2197a4a64cfafbe57
1 /* Unit test suite for uxtheme API functions
3 * Copyright 2006 Paul Vriens
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
21 #include <stdarg.h>
23 #include "windows.h"
24 #include "vfwmsgs.h"
25 #include "uxtheme.h"
27 #include "wine/test.h"
29 static HRESULT (WINAPI * pCloseThemeData)(HTHEME);
30 static HRESULT (WINAPI * pGetCurrentThemeName)(LPWSTR, int, LPWSTR, int, LPWSTR, int);
31 static HTHEME (WINAPI * pGetWindowTheme)(HWND);
32 static BOOL (WINAPI * pIsAppThemed)(VOID);
33 static BOOL (WINAPI * pIsThemeActive)(VOID);
34 static BOOL (WINAPI * pIsThemePartDefined)(HTHEME, int, int);
35 static HTHEME (WINAPI * pOpenThemeData)(HWND, LPCWSTR);
36 static HRESULT (WINAPI * pSetWindowTheme)(HWND, LPCWSTR, LPCWSTR);
38 static HMODULE hUxtheme = 0;
40 #define UXTHEME_GET_PROC(func) \
41 p ## func = (void*)GetProcAddress(hUxtheme, #func); \
42 if(!p ## func) { \
43 trace("GetProcAddress(%s) failed\n", #func); \
44 FreeLibrary(hUxtheme); \
45 return FALSE; \
48 static BOOL InitFunctionPtrs(void)
50 hUxtheme = LoadLibraryA("uxtheme.dll");
51 if(!hUxtheme) {
52 trace("Could not load uxtheme.dll\n");
53 return FALSE;
55 if (hUxtheme)
57 UXTHEME_GET_PROC(CloseThemeData)
58 UXTHEME_GET_PROC(GetCurrentThemeName)
59 UXTHEME_GET_PROC(GetWindowTheme)
60 UXTHEME_GET_PROC(IsAppThemed)
61 UXTHEME_GET_PROC(IsThemeActive)
62 UXTHEME_GET_PROC(IsThemePartDefined)
63 UXTHEME_GET_PROC(OpenThemeData)
64 UXTHEME_GET_PROC(SetWindowTheme)
66 /* The following functions should be available, if not return FALSE. The Vista functions will
67 * be checked (at some point in time) within the single tests if needed. All used functions for
68 * now are present on WinXP, W2K3 and Wine.
70 if (!pCloseThemeData || !pGetCurrentThemeName ||
71 !pGetWindowTheme || !pIsAppThemed ||
72 !pIsThemeActive || !pIsThemePartDefined ||
73 !pOpenThemeData || !pSetWindowTheme)
74 return FALSE;
76 return TRUE;
79 static void test_IsThemed(void)
81 BOOL bThemeActive;
82 BOOL bAppThemed;
83 BOOL bTPDefined;
85 SetLastError(0xdeadbeef);
86 bThemeActive = pIsThemeActive();
87 trace("Theming is %s\n", (bThemeActive) ? "active" : "inactive");
88 todo_wine
89 ok( GetLastError() == ERROR_SUCCESS,
90 "Expected ERROR_SUCCESS, got 0x%08x\n",
91 GetLastError());
93 /* This test is not themed */
94 SetLastError(0xdeadbeef);
95 bAppThemed = pIsAppThemed();
97 if (bThemeActive)
98 todo_wine
99 ok( bAppThemed == FALSE, "Expected FALSE as this test executable is not (yet) themed.\n");
100 else
101 /* Although Wine currently returns FALSE, the logic behind it is wrong. It is not a todo_wine though in the testing sense */
102 ok( bAppThemed == FALSE, "Expected FALSE as this test executable is not (yet) themed.\n");
104 todo_wine
105 ok( GetLastError() == ERROR_SUCCESS,
106 "Expected ERROR_SUCCESS, got 0x%08x\n",
107 GetLastError());
109 SetLastError(0xdeadbeef);
110 bTPDefined = pIsThemePartDefined(NULL, 0 , 0);
111 ok( bTPDefined == FALSE, "Expected FALSE\n");
112 ok( GetLastError() == E_HANDLE,
113 "Expected E_HANDLE, got 0x%08x\n",
114 GetLastError());
117 static void test_GetWindowTheme(void)
119 HTHEME hTheme;
120 HWND hWnd;
121 BOOL bDestroyed;
123 SetLastError(0xdeadbeef);
124 hTheme = pGetWindowTheme(NULL);
125 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
126 todo_wine
127 ok( GetLastError() == E_HANDLE,
128 "Expected E_HANDLE, got 0x%08x\n",
129 GetLastError());
131 /* Only do the bare minumum to get a valid hwnd */
132 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
133 if (!hWnd) return;
135 SetLastError(0xdeadbeef);
136 hTheme = pGetWindowTheme(hWnd);
137 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
138 ok( GetLastError() == 0xdeadbeef,
139 "Expected 0xdeadbeef, got 0x%08x\n",
140 GetLastError());
142 bDestroyed = DestroyWindow(hWnd);
143 if (!bDestroyed)
144 trace("Window %p couldn't be destroyed : 0x%08x\n",
145 hWnd, GetLastError());
148 static void test_SetWindowTheme(void)
150 HRESULT hRes;
151 HWND hWnd;
152 BOOL bDestroyed;
154 SetLastError(0xdeadbeef);
155 hRes = pSetWindowTheme(NULL, NULL, NULL);
156 todo_wine
158 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08x\n", hRes);
159 ok( GetLastError() == 0xdeadbeef,
160 "Expected 0xdeadbeef, got 0x%08x\n",
161 GetLastError());
164 /* Only do the bare minumum to get a valid hwnd */
165 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
166 if (!hWnd) return;
168 SetLastError(0xdeadbeef);
169 hRes = pSetWindowTheme(hWnd, NULL, NULL);
170 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
171 ok( GetLastError() == 0xdeadbeef,
172 "Expected 0xdeadbeef, got 0x%08x\n",
173 GetLastError());
175 bDestroyed = DestroyWindow(hWnd);
176 if (!bDestroyed)
177 trace("Window %p couldn't be destroyed : 0x%08x\n",
178 hWnd, GetLastError());
181 static void test_OpenThemeData(void)
183 HTHEME hTheme, hTheme2;
184 HWND hWnd;
185 BOOL bThemeActive;
186 HRESULT hRes;
187 BOOL bDestroyed;
188 BOOL bTPDefined;
190 WCHAR szInvalidClassList[] = {'D','E','A','D','B','E','E','F', 0 };
191 WCHAR szButtonClassList[] = {'B','u','t','t','o','n', 0 };
192 WCHAR szButtonClassList2[] = {'b','U','t','T','o','N', 0 };
193 WCHAR szClassList[] = {'B','u','t','t','o','n',';','L','i','s','t','B','o','x', 0 };
195 bThemeActive = pIsThemeActive();
197 /* All NULL */
198 SetLastError(0xdeadbeef);
199 hTheme = pOpenThemeData(NULL, NULL);
200 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
201 todo_wine
202 ok( GetLastError() == E_POINTER,
203 "Expected GLE() to be E_POINTER, got 0x%08x\n",
204 GetLastError());
206 /* A NULL hWnd and an invalid classlist */
207 SetLastError(0xdeadbeef);
208 hTheme = pOpenThemeData(NULL, szInvalidClassList);
209 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
210 todo_wine
211 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
212 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
213 GetLastError());
215 SetLastError(0xdeadbeef);
216 hTheme = pOpenThemeData(NULL, szClassList);
217 if (bThemeActive)
219 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
220 todo_wine
221 ok( GetLastError() == ERROR_SUCCESS,
222 "Expected ERROR_SUCCESS, got 0x%08x\n",
223 GetLastError());
225 else
227 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
228 todo_wine
229 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
230 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
231 GetLastError());
234 /* Only do the bare minumum to get a valid hdc */
235 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
236 if (!hWnd) return;
238 SetLastError(0xdeadbeef);
239 hTheme = pOpenThemeData(hWnd, NULL);
240 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
241 todo_wine
242 ok( GetLastError() == E_POINTER,
243 "Expected GLE() to be E_POINTER, got 0x%08x\n",
244 GetLastError());
246 SetLastError(0xdeadbeef);
247 hTheme = pOpenThemeData(hWnd, szInvalidClassList);
248 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
249 todo_wine
250 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
251 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
252 GetLastError());
254 if (!bThemeActive)
256 SetLastError(0xdeadbeef);
257 hTheme = pOpenThemeData(hWnd, szButtonClassList);
258 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
259 todo_wine
260 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
261 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
262 GetLastError());
263 trace("No active theme, skipping rest of OpenThemeData tests\n");
264 return;
267 /* Only do the next checks if we have an active theme */
269 SetLastError(0xdeadbeef);
270 hTheme = pOpenThemeData(hWnd, szButtonClassList);
271 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
272 todo_wine
273 ok( GetLastError() == ERROR_SUCCESS,
274 "Expected ERROR_SUCCESS, got 0x%08x\n",
275 GetLastError());
277 /* Test with bUtToN instead of Button */
278 SetLastError(0xdeadbeef);
279 hTheme = pOpenThemeData(hWnd, szButtonClassList2);
280 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
281 todo_wine
282 ok( GetLastError() == ERROR_SUCCESS,
283 "Expected ERROR_SUCCESS, got 0x%08x\n",
284 GetLastError());
286 SetLastError(0xdeadbeef);
287 hTheme = pOpenThemeData(hWnd, szClassList);
288 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
289 todo_wine
290 ok( GetLastError() == ERROR_SUCCESS,
291 "Expected ERROR_SUCCESS, got 0x%08x\n",
292 GetLastError());
294 /* GetWindowTheme should return the last handle opened by OpenThemeData */
295 SetLastError(0xdeadbeef);
296 hTheme2 = pGetWindowTheme(hWnd);
297 ok( hTheme == hTheme2, "Expected the same HTHEME handle (%p<->%p)\n",
298 hTheme, hTheme2);
299 ok( GetLastError() == 0xdeadbeef,
300 "Expected 0xdeadbeef, got 0x%08x\n",
301 GetLastError());
303 SetLastError(0xdeadbeef);
304 hRes = pCloseThemeData(hTheme);
305 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
306 ok( GetLastError() == 0xdeadbeef,
307 "Expected 0xdeadbeef, got 0x%08x\n",
308 GetLastError());
310 /* Close a second time */
311 SetLastError(0xdeadbeef);
312 hRes = pCloseThemeData(hTheme);
313 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
314 ok( GetLastError() == 0xdeadbeef,
315 "Expected 0xdeadbeef, got 0x%08x\n",
316 GetLastError());
318 /* See if closing makes a difference for GetWindowTheme */
319 SetLastError(0xdeadbeef);
320 hTheme2 = NULL;
321 hTheme2 = pGetWindowTheme(hWnd);
322 ok( hTheme == hTheme2, "Expected the same HTHEME handle (%p<->%p)\n",
323 hTheme, hTheme2);
324 ok( GetLastError() == 0xdeadbeef,
325 "Expected 0xdeadbeef, got 0x%08x\n",
326 GetLastError());
328 SetLastError(0xdeadbeef);
329 bTPDefined = pIsThemePartDefined(hTheme, 0 , 0);
330 todo_wine
332 ok( bTPDefined == FALSE, "Expected FALSE\n");
333 ok( GetLastError() == ERROR_SUCCESS,
334 "Expected ERROR_SUCCESS, got 0x%08x\n",
335 GetLastError());
338 bDestroyed = DestroyWindow(hWnd);
339 if (!bDestroyed)
340 trace("Window %p couldn't be destroyed : 0x%08x\n",
341 hWnd, GetLastError());
344 static void test_GetCurrentThemeName(void)
346 BOOL bThemeActive;
347 HRESULT hRes;
348 WCHAR currentTheme[MAX_PATH];
349 WCHAR currentColor[MAX_PATH];
350 WCHAR currentSize[MAX_PATH];
352 bThemeActive = pIsThemeActive();
354 /* All NULLs */
355 SetLastError(0xdeadbeef);
356 hRes = pGetCurrentThemeName(NULL, 0, NULL, 0, NULL, 0);
357 if (bThemeActive)
358 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
359 else
360 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
361 ok( GetLastError() == 0xdeadbeef,
362 "Expected 0xdeadbeef, got 0x%08x\n",
363 GetLastError());
365 /* Number of characters given is 0 */
366 SetLastError(0xdeadbeef);
367 hRes = pGetCurrentThemeName(currentTheme, 0, NULL, 0, NULL, 0);
368 if (bThemeActive)
369 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
370 else
371 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
372 ok( GetLastError() == 0xdeadbeef,
373 "Expected 0xdeadbeef, got 0x%08x\n",
374 GetLastError());
376 /* When the number of characters given is too small (not 0, see above), GetCurrentThemeName returns 0x8007007a.
377 * The only definition I found was in strsafe.h:
379 * #define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL) // 0x7A = 122L = ERROR_INSUFFICIENT_BUFFER
381 SetLastError(0xdeadbeef);
382 hRes = pGetCurrentThemeName(currentTheme, 2, NULL, 0, NULL, 0);
383 if (bThemeActive)
384 todo_wine
385 ok( LOWORD(hRes) == ERROR_INSUFFICIENT_BUFFER, "Expected 0x8007007A, got 0x%08x\n", hRes);
386 else
387 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
388 ok( GetLastError() == 0xdeadbeef,
389 "Expected 0xdeadbeef, got 0x%08x\n",
390 GetLastError());
392 /* The same is true if the number of characters is too small for Color and/or Size */
393 SetLastError(0xdeadbeef);
394 hRes = pGetCurrentThemeName(currentTheme, sizeof(currentTheme) / sizeof(WCHAR),
395 currentColor, 2,
396 currentSize, sizeof(currentSize) / sizeof(WCHAR));
397 if (bThemeActive)
398 todo_wine
399 ok( LOWORD(hRes) == ERROR_INSUFFICIENT_BUFFER, "Expected 0x8007007A, got 0x%08x\n", hRes);
400 else
401 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
402 ok( GetLastError() == 0xdeadbeef,
403 "Expected 0xdeadbeef, got 0x%08x\n",
404 GetLastError());
406 /* Given number of characters is correct */
407 SetLastError(0xdeadbeef);
408 hRes = pGetCurrentThemeName(currentTheme, sizeof(currentTheme) / sizeof(WCHAR), NULL, 0, NULL, 0);
409 if (bThemeActive)
410 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
411 else
412 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
413 ok( GetLastError() == 0xdeadbeef,
414 "Expected 0xdeadbeef, got 0x%08x\n",
415 GetLastError());
417 /* Given number of characters for the theme name is too large */
418 SetLastError(0xdeadbeef);
419 hRes = pGetCurrentThemeName(currentTheme, sizeof(currentTheme), NULL, 0, NULL, 0);
420 todo_wine
421 ok( hRes == E_POINTER, "Expected E_POINTER, got 0x%08x\n", hRes);
422 ok( GetLastError() == 0xdeadbeef,
423 "Expected 0xdeadbeef, got 0x%08x\n",
424 GetLastError());
426 /* The too large case is only for the theme name, not for color name or size name */
427 SetLastError(0xdeadbeef);
428 hRes = pGetCurrentThemeName(currentTheme, sizeof(currentTheme) / sizeof(WCHAR),
429 currentColor, sizeof(currentTheme),
430 currentSize, sizeof(currentSize) / sizeof(WCHAR));
431 if (bThemeActive)
432 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
433 else
434 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
435 ok( GetLastError() == 0xdeadbeef,
436 "Expected 0xdeadbeef, got 0x%08x\n",
437 GetLastError());
439 SetLastError(0xdeadbeef);
440 hRes = pGetCurrentThemeName(currentTheme, sizeof(currentTheme) / sizeof(WCHAR),
441 currentColor, sizeof(currentTheme) / sizeof(WCHAR),
442 currentSize, sizeof(currentSize));
443 if (bThemeActive)
444 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
445 else
446 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
447 ok( GetLastError() == 0xdeadbeef,
448 "Expected 0xdeadbeef, got 0x%08x\n",
449 GetLastError());
451 /* Correct call */
452 SetLastError(0xdeadbeef);
453 hRes = pGetCurrentThemeName(currentTheme, sizeof(currentTheme) / sizeof(WCHAR),
454 currentColor, sizeof(currentColor) / sizeof(WCHAR),
455 currentSize, sizeof(currentSize) / sizeof(WCHAR));
456 if (bThemeActive)
457 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
458 else
459 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
460 ok( GetLastError() == 0xdeadbeef,
461 "Expected 0xdeadbeef, got 0x%08x\n",
462 GetLastError());
465 static void test_CloseThemeData(void)
467 HRESULT hRes;
469 SetLastError(0xdeadbeef);
470 hRes = pCloseThemeData(NULL);
471 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08x\n", hRes);
472 ok( GetLastError() == 0xdeadbeef,
473 "Expected 0xdeadbeef, got 0x%08x\n",
474 GetLastError());
477 START_TEST(system)
479 if(!InitFunctionPtrs())
480 return;
482 /* No real functional tests will be done (yet). The current tests
483 * only show input/return behaviour
486 /* IsThemeActive, IsAppThemed and IsThemePartDefined*/
487 trace("Starting test_IsThemed()\n");
488 test_IsThemed();
490 /* GetWindowTheme */
491 trace("Starting test_GetWindowTheme()\n");
492 test_GetWindowTheme();
494 /* SetWindowTheme */
495 trace("Starting test_SetWindowTheme()\n");
496 test_SetWindowTheme();
498 /* OpenThemeData, a bit more functional now */
499 trace("Starting test_OpenThemeData()\n");
500 test_OpenThemeData();
502 /* GetCurrentThemeName */
503 trace("Starting test_GetCurrentThemeName()\n");
504 test_GetCurrentThemeName();
506 /* CloseThemeData */
507 trace("Starting test_CloseThemeData()\n");
508 test_CloseThemeData();
510 FreeLibrary(hUxtheme);