uxtheme/tests: Extra testing for GetLastError.
[wine.git] / dlls / uxtheme / tests / system.c
blob579c3993e35ab4e643660bc13f0c5230be87acd3
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 "uxtheme.h"
26 #include "wine/test.h"
28 static HRESULT (WINAPI * pCloseThemeData)(HTHEME);
29 static BOOL (WINAPI * pIsAppThemed)(VOID);
30 static BOOL (WINAPI * pIsThemeActive)(VOID);
31 static HTHEME (WINAPI * pOpenThemeData)(HWND, LPCWSTR);
32 static HRESULT (WINAPI * pSetWindowTheme)(HWND, LPCWSTR, LPCWSTR);
34 static HMODULE hUxtheme = 0;
36 #define UXTHEME_GET_PROC(func) \
37 p ## func = (void*)GetProcAddress(hUxtheme, #func); \
38 if(!p ## func) { \
39 trace("GetProcAddress(%s) failed\n", #func); \
40 FreeLibrary(hUxtheme); \
41 return FALSE; \
44 static BOOL InitFunctionPtrs(void)
46 hUxtheme = LoadLibraryA("uxtheme.dll");
47 if(!hUxtheme) {
48 trace("Could not load uxtheme.dll\n");
49 return FALSE;
51 if (hUxtheme)
53 UXTHEME_GET_PROC(CloseThemeData)
54 UXTHEME_GET_PROC(IsAppThemed)
55 UXTHEME_GET_PROC(IsThemeActive)
56 UXTHEME_GET_PROC(OpenThemeData)
57 UXTHEME_GET_PROC(SetWindowTheme)
59 return TRUE;
62 static void test_IsThemed(void)
64 BOOL bThemeActive;
65 BOOL bAppThemed;
67 SetLastError(0xdeadbeef);
68 bThemeActive = pIsThemeActive();
69 trace("Theming is %s\n", (bThemeActive) ? "active" : "inactive");
70 todo_wine
71 ok( GetLastError() == ERROR_SUCCESS,
72 "Expected ERROR_SUCCESS, got 0x%08lx\n",
73 GetLastError());
75 /* This test is not themed */
76 SetLastError(0xdeadbeef);
77 bAppThemed = pIsAppThemed();
79 if (bThemeActive)
80 todo_wine
81 ok( bAppThemed == FALSE, "Expected FALSE as this test executable is not (yet) themed.\n");
82 else
83 /* Although Wine currently returns FALSE, the logic behind it is wrong. It is not a todo_wine though in the testing sense */
84 ok( bAppThemed == FALSE, "Expected FALSE as this test executable is not (yet) themed.\n");
86 todo_wine
87 ok( GetLastError() == ERROR_SUCCESS,
88 "Expected ERROR_SUCCESS, got 0x%08lx\n",
89 GetLastError());
92 static void test_SetWindowTheme(void)
94 HRESULT hRes;
95 HWND hWnd;
97 SetLastError(0xdeadbeef);
98 hRes = pSetWindowTheme(NULL, NULL, NULL);
99 todo_wine
101 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08lx\n", hRes);
102 ok( GetLastError() == 0xdeadbeef,
103 "Expected 0xdeadbeef, got 0x%08lx\n",
104 GetLastError());
107 /* Only do the bare minumum to get a valid hwnd */
108 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
109 if (!hWnd) return;
111 SetLastError(0xdeadbeef);
112 hRes = pSetWindowTheme(hWnd, NULL, NULL);
113 ok( hRes == S_OK, "Expected S_OK, got 0x%08lx\n", hRes);
114 ok( GetLastError() == 0xdeadbeef,
115 "Expected 0xdeadbeef, got 0x%08lx\n",
116 GetLastError());
119 static void test_OpenThemeData(void)
121 HTHEME hTheme;
122 HWND hWnd;
123 BOOL bThemeActive;
125 WCHAR szInvalidClassList[] = {'D','E','A','D','B','E','E','F', 0 };
126 WCHAR szButtonClassList[] = {'B','u','t','t','o','n', 0 };
127 WCHAR szClassList[] = {'B','u','t','t','o','n',';','L','i','s','t','B','o','x', 0 };
129 bThemeActive = pIsThemeActive();
131 /* All NULL */
132 SetLastError(0xdeadbeef);
133 hTheme = pOpenThemeData(NULL, NULL);
134 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
135 todo_wine
136 ok( GetLastError() == E_POINTER,
137 "Expected GLE() to be E_POINTER, got 0x%08lx\n",
138 GetLastError());
140 /* A NULL hWnd and an invalid classlist */
141 SetLastError(0xdeadbeef);
142 hTheme = pOpenThemeData(NULL, szInvalidClassList);
143 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
144 todo_wine
145 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
146 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
147 GetLastError());
149 SetLastError(0xdeadbeef);
150 hTheme = pOpenThemeData(NULL, szClassList);
151 if (bThemeActive)
153 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
154 todo_wine
155 ok( GetLastError() == ERROR_SUCCESS,
156 "Expected ERROR_SUCCESS, got 0x%08lx\n",
157 GetLastError());
159 else
161 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
162 todo_wine
163 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
164 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
165 GetLastError());
168 /* Only do the bare minumum to get a valid hdc */
169 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
170 if (!hWnd) return;
172 SetLastError(0xdeadbeef);
173 hTheme = pOpenThemeData(hWnd, NULL);
174 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
175 todo_wine
176 ok( GetLastError() == E_POINTER,
177 "Expected GLE() to be E_POINTER, got 0x%08lx\n",
178 GetLastError());
180 SetLastError(0xdeadbeef);
181 hTheme = pOpenThemeData(hWnd, szInvalidClassList);
182 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
183 todo_wine
184 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
185 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
186 GetLastError());
189 if (!bThemeActive)
191 SetLastError(0xdeadbeef);
192 hTheme = pOpenThemeData(hWnd, szButtonClassList);
193 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
194 todo_wine
195 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
196 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
197 GetLastError());
198 trace("No active theme, skipping rest of OpenThemeData tests\n");
199 return;
202 /* Only do the next checks if we have an active theme */
204 SetLastError(0xdeadbeef);
205 hTheme = pOpenThemeData(hWnd, szButtonClassList);
206 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
207 todo_wine
208 ok( GetLastError() == ERROR_SUCCESS,
209 "Expected ERROR_SUCCESS, got 0x%08lx\n",
210 GetLastError());
212 SetLastError(0xdeadbeef);
213 hTheme = pOpenThemeData(hWnd, szClassList);
214 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
215 todo_wine
216 ok( GetLastError() == ERROR_SUCCESS,
217 "Expected ERROR_SUCCESS, got 0x%08lx\n",
218 GetLastError());
221 static void test_CloseThemeData(void)
223 HRESULT hRes;
225 SetLastError(0xdeadbeef);
226 hRes = pCloseThemeData(NULL);
227 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08lx\n", hRes);
228 ok( GetLastError() == 0xdeadbeef,
229 "Expected 0xdeadbeef, got 0x%08lx\n",
230 GetLastError());
233 START_TEST(system)
235 if(!InitFunctionPtrs())
236 return;
238 /* No real functional tests will be done (yet). The current tests
239 * only show input/return behaviour
242 /* IsThemeActive and IsAppThemed */
243 trace("Starting test_IsThemed()\n");
244 if (pIsAppThemed && pIsThemeActive)
245 test_IsThemed();
247 /* SetWindowTheme */
248 trace("Starting test_SetWindowTheme()\n");
249 if (pSetWindowTheme)
250 test_SetWindowTheme();
252 /* OpenThemeData */
253 trace("Starting test_OpenThemeData()\n");
254 if (pOpenThemeData && pIsThemeActive)
255 test_OpenThemeData();
257 /* CloseThemeData */
258 trace("Starting test_CloseThemeData()\n");
259 if (pCloseThemeData)
260 test_CloseThemeData();
262 FreeLibrary(hUxtheme);