dbghelp: Dwarf abbrev table is now a sparse array.
[wine] / dlls / uxtheme / tests / system.c
1 /* Unit test suite for uxtheme API functions
2  *
3  * Copyright 2006 Paul Vriens
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
21 #include <stdarg.h>
22
23 #include "windows.h"
24 #include "uxtheme.h"
25
26 #include "wine/test.h"
27
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);
33
34 static HMODULE hUxtheme = 0;
35
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; \
42     }
43
44 static BOOL InitFunctionPtrs(void)
45 {
46     hUxtheme = LoadLibraryA("uxtheme.dll");
47     if(!hUxtheme) {
48       trace("Could not load uxtheme.dll\n");
49       return FALSE;
50     }
51     if (hUxtheme)
52     {
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)
58     }
59     return TRUE;
60 }
61
62 static void test_IsThemed(void)
63 {
64     BOOL bThemeActive;
65     BOOL bAppThemed;
66
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());
74
75     /* This test is not themed */
76     SetLastError(0xdeadbeef);
77     bAppThemed = pIsAppThemed();
78
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");
85
86     todo_wine
87         ok( GetLastError() == ERROR_SUCCESS,
88             "Expected ERROR_SUCCESS, got 0x%08lx\n",
89             GetLastError());
90 }
91
92 static void test_SetWindowTheme(void)
93 {
94     HRESULT hRes;
95     HWND    hWnd;
96
97     SetLastError(0xdeadbeef);
98     hRes = pSetWindowTheme(NULL, NULL, NULL);
99     todo_wine
100         ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08lx\n", hRes);
101
102     /* Only do the bare minumum to get a valid hwnd */
103     hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
104     if (!hWnd) return;
105
106     SetLastError(0xdeadbeef);
107     hRes = pSetWindowTheme(hWnd, NULL, NULL);
108     ok( hRes == S_OK, "Expected S_OK, got 0x%08lx\n", hRes);
109 }
110
111 static void test_OpenThemeData(void)
112 {
113     HTHEME    hTheme;
114     HWND      hWnd;
115     BOOL      bThemeActive;
116
117     WCHAR szInvalidClassList[] = {'D','E','A','D','B','E','E','F', 0 };
118     WCHAR szButtonClassList[]  = {'B','u','t','t','o','n', 0 };
119     WCHAR szClassList[]        = {'B','u','t','t','o','n',';','L','i','s','t','B','o','x', 0 };
120
121     SetLastError(0xdeadbeef);
122     bThemeActive = pIsThemeActive();
123
124     /* All NULL */
125     SetLastError(0xdeadbeef);
126     hTheme = pOpenThemeData(NULL, NULL);
127     ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
128     todo_wine
129         ok( GetLastError() == E_POINTER,
130             "Expected GLE() to be E_POINTER, got 0x%08lx\n",
131             GetLastError());
132
133     /* A NULL hWnd and an invalid classlist */
134     SetLastError(0xdeadbeef);
135     hTheme = pOpenThemeData(NULL, szInvalidClassList);
136     ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
137     todo_wine
138         ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
139             "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
140             GetLastError());
141
142     SetLastError(0xdeadbeef);
143     hTheme = pOpenThemeData(NULL, szClassList);
144     if (bThemeActive)
145     {
146         ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
147         todo_wine
148             ok( GetLastError() == ERROR_SUCCESS,
149                 "Expected ERROR_SUCCESS, got 0x%08lx\n",
150                 GetLastError());
151     }
152     else
153     {
154         ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
155         todo_wine
156             ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
157                 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
158                 GetLastError());
159     }
160
161     /* Only do the bare minumum to get a valid hdc */
162     hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
163     if (!hWnd) return;
164
165     SetLastError(0xdeadbeef);
166     hTheme = pOpenThemeData(hWnd, NULL);
167     ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
168     todo_wine
169         ok( GetLastError() == E_POINTER,
170             "Expected GLE() to be E_POINTER, got 0x%08lx\n",
171             GetLastError());
172
173     SetLastError(0xdeadbeef);
174     hTheme = pOpenThemeData(hWnd, szInvalidClassList);
175     ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
176     todo_wine
177         ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
178             "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
179             GetLastError());
180
181
182     if (!bThemeActive)
183     {
184         SetLastError(0xdeadbeef);
185         hTheme = pOpenThemeData(hWnd, szButtonClassList);
186         ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
187         todo_wine
188             ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
189                 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08lx\n",
190                 GetLastError());
191         trace("No active theme, skipping rest of OpenThemeData tests\n");
192         return;
193     }
194
195     /* Only do the next checks if we have an active theme */
196
197     SetLastError(0xdeadbeef);
198     hTheme = pOpenThemeData(hWnd, szButtonClassList);
199     ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
200     todo_wine
201         ok( GetLastError() == ERROR_SUCCESS,
202             "Expected ERROR_SUCCESS, got 0x%08lx\n",
203             GetLastError());
204
205     SetLastError(0xdeadbeef);
206     hTheme = pOpenThemeData(hWnd, szClassList);
207     ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
208     todo_wine
209         ok( GetLastError() == ERROR_SUCCESS,
210             "Expected ERROR_SUCCESS, got 0x%08lx\n",
211             GetLastError());
212 }
213
214 static void test_CloseThemeData(void)
215 {
216     HRESULT hRes;
217
218     SetLastError(0xdeadbeef);
219     hRes = pCloseThemeData(NULL);
220     ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08lx\n", hRes);
221     ok( GetLastError() == 0xdeadbeef,
222         "Expected 0xdeadbeef, got 0x%08lx\n",
223         GetLastError());
224 }
225
226 START_TEST(system)
227 {
228     if(!InitFunctionPtrs())
229         return;
230
231     /* No real functional tests will be done (yet). The current tests
232      * only show input/return behaviour
233      */
234
235     /* IsThemeActive and IsAppThemed */
236     trace("Starting test_IsThemed()\n");
237     if (pIsAppThemed && pIsThemeActive)
238         test_IsThemed();
239
240     /* SetWindowTheme */
241     trace("Starting test_SetWindowTheme()\n");
242     if (pSetWindowTheme)
243         test_SetWindowTheme();
244
245     /* OpenThemeData */
246     trace("Starting test_OpenThemeData()\n");
247     if (pOpenThemeData && pIsThemeActive) 
248         test_OpenThemeData();
249
250     /* CloseThemeData */
251     trace("Starting test_CloseThemeData()\n");
252     if (pCloseThemeData)
253         test_CloseThemeData();
254
255     FreeLibrary(hUxtheme);
256 }