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
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); \
43 trace("GetProcAddress(%s) failed\n", #func); \
44 FreeLibrary(hUxtheme); \
48 static BOOL
InitFunctionPtrs(void)
50 hUxtheme
= LoadLibraryA("uxtheme.dll");
52 trace("Could not load uxtheme.dll\n");
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
)
79 static void test_IsThemed(void)
85 SetLastError(0xdeadbeef);
86 bThemeActive
= pIsThemeActive();
87 trace("Theming is %s\n", (bThemeActive
) ? "active" : "inactive");
89 ok( GetLastError() == ERROR_SUCCESS
,
90 "Expected ERROR_SUCCESS, got 0x%08x\n",
93 /* This test is not themed */
94 SetLastError(0xdeadbeef);
95 bAppThemed
= pIsAppThemed();
99 ok( bAppThemed
== FALSE
, "Expected FALSE as this test executable is not (yet) themed.\n");
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");
105 ok( GetLastError() == ERROR_SUCCESS
,
106 "Expected ERROR_SUCCESS, got 0x%08x\n",
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",
117 static void test_GetWindowTheme(void)
123 SetLastError(0xdeadbeef);
124 hTheme
= pGetWindowTheme(NULL
);
125 ok( hTheme
== NULL
, "Expected a NULL return, got %p\n", hTheme
);
127 ok( GetLastError() == E_HANDLE
,
128 "Expected E_HANDLE, got 0x%08x\n",
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
);
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",
142 bDestroyed
= DestroyWindow(hWnd
);
144 trace("Window %p couldn't be destroyed : 0x%08x\n",
145 hWnd
, GetLastError());
148 static void test_SetWindowTheme(void)
154 SetLastError(0xdeadbeef);
155 hRes
= pSetWindowTheme(NULL
, NULL
, NULL
);
158 ok( hRes
== E_HANDLE
, "Expected E_HANDLE, got 0x%08x\n", hRes
);
159 ok( GetLastError() == 0xdeadbeef,
160 "Expected 0xdeadbeef, got 0x%08x\n",
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
);
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",
175 bDestroyed
= DestroyWindow(hWnd
);
177 trace("Window %p couldn't be destroyed : 0x%08x\n",
178 hWnd
, GetLastError());
181 static void test_OpenThemeData(void)
183 HTHEME hTheme
, hTheme2
;
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();
198 SetLastError(0xdeadbeef);
199 hTheme
= pOpenThemeData(NULL
, NULL
);
200 ok( hTheme
== NULL
, "Expected a NULL return, got %p\n", hTheme
);
202 ok( GetLastError() == E_POINTER
,
203 "Expected GLE() to be E_POINTER, got 0x%08x\n",
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
);
211 ok( GetLastError() == E_PROP_ID_UNSUPPORTED
,
212 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
215 SetLastError(0xdeadbeef);
216 hTheme
= pOpenThemeData(NULL
, szClassList
);
219 ok( hTheme
!= NULL
, "got NULL, expected a HTHEME handle\n");
221 ok( GetLastError() == ERROR_SUCCESS
,
222 "Expected ERROR_SUCCESS, got 0x%08x\n",
227 ok( hTheme
== NULL
, "Expected a NULL return, got %p\n", hTheme
);
229 ok( GetLastError() == E_PROP_ID_UNSUPPORTED
,
230 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
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
);
238 SetLastError(0xdeadbeef);
239 hTheme
= pOpenThemeData(hWnd
, NULL
);
240 ok( hTheme
== NULL
, "Expected a NULL return, got %p\n", hTheme
);
242 ok( GetLastError() == E_POINTER
,
243 "Expected GLE() to be E_POINTER, got 0x%08x\n",
246 SetLastError(0xdeadbeef);
247 hTheme
= pOpenThemeData(hWnd
, szInvalidClassList
);
248 ok( hTheme
== NULL
, "Expected a NULL return, got %p\n", hTheme
);
250 ok( GetLastError() == E_PROP_ID_UNSUPPORTED
,
251 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
256 SetLastError(0xdeadbeef);
257 hTheme
= pOpenThemeData(hWnd
, szButtonClassList
);
258 ok( hTheme
== NULL
, "Expected a NULL return, got %p\n", hTheme
);
260 ok( GetLastError() == E_PROP_ID_UNSUPPORTED
,
261 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
263 trace("No active theme, skipping rest of OpenThemeData tests\n");
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");
273 ok( GetLastError() == ERROR_SUCCESS
,
274 "Expected ERROR_SUCCESS, got 0x%08x\n",
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");
282 ok( GetLastError() == ERROR_SUCCESS
,
283 "Expected ERROR_SUCCESS, got 0x%08x\n",
286 SetLastError(0xdeadbeef);
287 hTheme
= pOpenThemeData(hWnd
, szClassList
);
288 ok( hTheme
!= NULL
, "got NULL, expected a HTHEME handle\n");
290 ok( GetLastError() == ERROR_SUCCESS
,
291 "Expected ERROR_SUCCESS, got 0x%08x\n",
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",
299 ok( GetLastError() == 0xdeadbeef,
300 "Expected 0xdeadbeef, got 0x%08x\n",
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",
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",
318 /* See if closing makes a difference for GetWindowTheme */
319 SetLastError(0xdeadbeef);
321 hTheme2
= pGetWindowTheme(hWnd
);
322 ok( hTheme
== hTheme2
, "Expected the same HTHEME handle (%p<->%p)\n",
324 ok( GetLastError() == 0xdeadbeef,
325 "Expected 0xdeadbeef, got 0x%08x\n",
328 SetLastError(0xdeadbeef);
329 bTPDefined
= pIsThemePartDefined(hTheme
, 0 , 0);
332 ok( bTPDefined
== FALSE
, "Expected FALSE\n");
333 ok( GetLastError() == ERROR_SUCCESS
,
334 "Expected ERROR_SUCCESS, got 0x%08x\n",
338 bDestroyed
= DestroyWindow(hWnd
);
340 trace("Window %p couldn't be destroyed : 0x%08x\n",
341 hWnd
, GetLastError());
344 static void test_GetCurrentThemeName(void)
348 WCHAR currentTheme
[MAX_PATH
];
349 WCHAR currentColor
[MAX_PATH
];
350 WCHAR currentSize
[MAX_PATH
];
352 bThemeActive
= pIsThemeActive();
355 SetLastError(0xdeadbeef);
356 hRes
= pGetCurrentThemeName(NULL
, 0, NULL
, 0, NULL
, 0);
358 ok( hRes
== S_OK
, "Expected S_OK, got 0x%08x\n", hRes
);
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",
365 /* Number of characters given is 0 */
366 SetLastError(0xdeadbeef);
367 hRes
= pGetCurrentThemeName(currentTheme
, 0, NULL
, 0, NULL
, 0);
369 ok( hRes
== S_OK
, "Expected S_OK, got 0x%08x\n", hRes
);
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",
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);
385 ok( LOWORD(hRes
) == ERROR_INSUFFICIENT_BUFFER
, "Expected 0x8007007A, got 0x%08x\n", hRes
);
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",
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
),
396 currentSize
, sizeof(currentSize
) / sizeof(WCHAR
));
399 ok( LOWORD(hRes
) == ERROR_INSUFFICIENT_BUFFER
, "Expected 0x8007007A, got 0x%08x\n", hRes
);
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",
406 /* Given number of characters is correct */
407 SetLastError(0xdeadbeef);
408 hRes
= pGetCurrentThemeName(currentTheme
, sizeof(currentTheme
) / sizeof(WCHAR
), NULL
, 0, NULL
, 0);
410 ok( hRes
== S_OK
, "Expected S_OK, got 0x%08x\n", hRes
);
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",
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);
421 ok( hRes
== E_POINTER
, "Expected E_POINTER, got 0x%08x\n", hRes
);
422 ok( GetLastError() == 0xdeadbeef,
423 "Expected 0xdeadbeef, got 0x%08x\n",
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
));
432 ok( hRes
== S_OK
, "Expected S_OK, got 0x%08x\n", hRes
);
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",
439 SetLastError(0xdeadbeef);
440 hRes
= pGetCurrentThemeName(currentTheme
, sizeof(currentTheme
) / sizeof(WCHAR
),
441 currentColor
, sizeof(currentTheme
) / sizeof(WCHAR
),
442 currentSize
, sizeof(currentSize
));
444 ok( hRes
== S_OK
, "Expected S_OK, got 0x%08x\n", hRes
);
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",
452 SetLastError(0xdeadbeef);
453 hRes
= pGetCurrentThemeName(currentTheme
, sizeof(currentTheme
) / sizeof(WCHAR
),
454 currentColor
, sizeof(currentColor
) / sizeof(WCHAR
),
455 currentSize
, sizeof(currentSize
) / sizeof(WCHAR
));
457 ok( hRes
== S_OK
, "Expected S_OK, got 0x%08x\n", hRes
);
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",
465 static void test_CloseThemeData(void)
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",
479 if(!InitFunctionPtrs())
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");
491 trace("Starting test_GetWindowTheme()\n");
492 test_GetWindowTheme();
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();
507 trace("Starting test_CloseThemeData()\n");
508 test_CloseThemeData();
510 FreeLibrary(hUxtheme
);