wined3d: Use the texture dimension helpers in wined3d_texture_update_overlay().
[wine.git] / dlls / comctl32 / tests / misc.c
blob5cc6c29225e15e7bf34da9a25134a44477dda56d
1 /*
2 * Misc tests
4 * Copyright 2006 Paul Vriens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdio.h>
22 #include <windows.h>
23 #include <commctrl.h>
25 #include "wine/test.h"
26 #include "v6util.h"
28 static PVOID (WINAPI * pAlloc)(LONG);
29 static PVOID (WINAPI * pReAlloc)(PVOID, LONG);
30 static BOOL (WINAPI * pFree)(PVOID);
31 static LONG (WINAPI * pGetSize)(PVOID);
33 static INT (WINAPI * pStr_GetPtrA)(LPCSTR, LPSTR, INT);
34 static BOOL (WINAPI * pStr_SetPtrA)(LPSTR, LPCSTR);
35 static INT (WINAPI * pStr_GetPtrW)(LPCWSTR, LPWSTR, INT);
36 static BOOL (WINAPI * pStr_SetPtrW)(LPWSTR, LPCWSTR);
38 static HMODULE hComctl32 = 0;
40 static char testicon_data[] =
42 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x01, 0x00,
43 0x20, 0x00, 0x40, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
44 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00,
45 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x0b,
46 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0xde, 0xde, 0xde, 0xff, 0xde, 0xde, 0xde, 0xff, 0xde, 0xde,
48 0xde, 0xff, 0xde, 0xde, 0xde, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00
52 #define COMCTL32_GET_PROC(ordinal, func) \
53 p ## func = (void*)GetProcAddress(hComctl32, (LPSTR)ordinal); \
54 if(!p ## func) { \
55 trace("GetProcAddress(%d)(%s) failed\n", ordinal, #func); \
56 FreeLibrary(hComctl32); \
59 static BOOL InitFunctionPtrs(void)
61 hComctl32 = LoadLibraryA("comctl32.dll");
63 if(!hComctl32)
65 trace("Could not load comctl32.dll\n");
66 return FALSE;
69 COMCTL32_GET_PROC(71, Alloc);
70 COMCTL32_GET_PROC(72, ReAlloc);
71 COMCTL32_GET_PROC(73, Free);
72 COMCTL32_GET_PROC(74, GetSize);
74 COMCTL32_GET_PROC(233, Str_GetPtrA)
75 COMCTL32_GET_PROC(234, Str_SetPtrA)
76 COMCTL32_GET_PROC(235, Str_GetPtrW)
77 COMCTL32_GET_PROC(236, Str_SetPtrW)
79 return TRUE;
82 static void test_GetPtrAW(void)
84 if (pStr_GetPtrA)
86 static const char source[] = "Just a source string";
87 static const char desttest[] = "Just a destination string";
88 static char dest[MAX_PATH];
89 int sourcelen;
90 int destsize = MAX_PATH;
91 int count;
93 sourcelen = strlen(source) + 1;
95 count = pStr_GetPtrA(NULL, NULL, 0);
96 ok (count == 0, "Expected count to be 0, it was %d\n", count);
98 if (0)
100 /* Crashes on W98, NT4, W2K, XP, W2K3
101 * Our implementation also crashes and we should probably leave
102 * it like that.
104 count = pStr_GetPtrA(NULL, NULL, destsize);
105 trace("count : %d\n", count);
108 count = pStr_GetPtrA(source, NULL, 0);
109 ok (count == sourcelen ||
110 broken(count == sourcelen - 1), /* win9x */
111 "Expected count to be %d, it was %d\n", sourcelen, count);
113 strcpy(dest, desttest);
114 count = pStr_GetPtrA(source, dest, 0);
115 ok (count == sourcelen ||
116 broken(count == 0), /* win9x */
117 "Expected count to be %d, it was %d\n", sourcelen, count);
118 ok (!lstrcmpA(dest, desttest) ||
119 broken(!lstrcmpA(dest, "")), /* Win7 */
120 "Expected destination to not have changed\n");
122 count = pStr_GetPtrA(source, NULL, destsize);
123 ok (count == sourcelen ||
124 broken(count == sourcelen - 1), /* win9x */
125 "Expected count to be %d, it was %d\n", sourcelen, count);
127 count = pStr_GetPtrA(source, dest, destsize);
128 ok (count == sourcelen ||
129 broken(count == sourcelen - 1), /* win9x */
130 "Expected count to be %d, it was %d\n", sourcelen, count);
131 ok (!lstrcmpA(source, dest), "Expected source and destination to be the same\n");
133 strcpy(dest, desttest);
134 count = pStr_GetPtrA(NULL, dest, destsize);
135 ok (count == 0, "Expected count to be 0, it was %d\n", count);
136 ok (dest[0] == '\0', "Expected destination to be cut-off and 0 terminated\n");
138 destsize = 15;
139 count = pStr_GetPtrA(source, dest, destsize);
140 ok (count == 15 ||
141 broken(count == 14), /* win9x */
142 "Expected count to be 15, it was %d\n", count);
143 ok (!memcmp(source, dest, 14), "Expected first part of source and destination to be the same\n");
144 ok (dest[14] == '\0', "Expected destination to be cut-off and 0 terminated\n");
148 static void test_Alloc(void)
150 PCHAR p;
151 BOOL res;
152 DWORD size, min;
154 /* allocate size 0 */
155 p = pAlloc(0);
156 ok(p != NULL, "Expected non-NULL ptr\n");
158 /* get the minimum size */
159 min = pGetSize(p);
161 /* free the block */
162 res = pFree(p);
163 ok(res == TRUE, "Expected TRUE, got %d\n", res);
165 /* allocate size 1 */
166 p = pAlloc(1);
167 ok(p != NULL, "Expected non-NULL ptr\n");
169 /* get the allocated size */
170 size = pGetSize(p);
171 ok(size == 1 ||
172 broken(size == min), /* win9x */
173 "Expected 1, got %d\n", size);
175 /* reallocate the block */
176 p = pReAlloc(p, 2);
177 ok(p != NULL, "Expected non-NULL ptr\n");
179 /* get the new size */
180 size = pGetSize(p);
181 ok(size == 2 ||
182 broken(size == min), /* win9x */
183 "Expected 2, got %d\n", size);
185 /* free the block */
186 res = pFree(p);
187 ok(res == TRUE, "Expected TRUE, got %d\n", res);
189 /* free a NULL ptr */
190 res = pFree(NULL);
191 ok(res == TRUE ||
192 broken(res == FALSE), /* win9x */
193 "Expected TRUE, got %d\n", res);
195 /* reallocate a NULL ptr */
196 p = pReAlloc(NULL, 2);
197 ok(p != NULL, "Expectd non-NULL ptr\n");
199 res = pFree(p);
200 ok(res == TRUE, "Expected TRUE, got %d\n", res);
203 static void test_TaskDialogIndirect(void)
205 HINSTANCE hinst;
206 void *ptr, *ptr2;
208 hinst = LoadLibraryA("comctl32.dll");
210 ptr = GetProcAddress(hinst, "TaskDialogIndirect");
211 if (!ptr)
213 win_skip("TaskDialogIndirect not exported by name\n");
214 return;
217 ptr2 = GetProcAddress(hinst, (const CHAR*)345);
218 ok(ptr == ptr2, "got wrong pointer for ordinal 345, %p expected %p\n", ptr2, ptr);
221 static void test_LoadIconWithScaleDown(void)
223 static const WCHAR nonexisting_fileW[] = {'n','o','n','e','x','i','s','t','i','n','g','.','i','c','o',0};
224 static const WCHAR nonexisting_resourceW[] = {'N','o','n','e','x','i','s','t','i','n','g',0};
225 static const WCHAR prefixW[] = {'I','C','O',0};
226 HRESULT (WINAPI *pLoadIconMetric)(HINSTANCE, const WCHAR *, int, HICON *);
227 HRESULT (WINAPI *pLoadIconWithScaleDown)(HINSTANCE, const WCHAR *, int, int, HICON *);
228 WCHAR tmp_path[MAX_PATH], icon_path[MAX_PATH];
229 ICONINFO info;
230 HMODULE hinst;
231 HANDLE handle;
232 DWORD written;
233 HRESULT hr;
234 BITMAP bmp;
235 HICON icon;
236 void *ptr;
237 int bytes;
238 BOOL res;
240 hinst = LoadLibraryA("comctl32.dll");
241 pLoadIconMetric = (void *)GetProcAddress(hinst, "LoadIconMetric");
242 pLoadIconWithScaleDown = (void *)GetProcAddress(hinst, "LoadIconWithScaleDown");
243 if (!pLoadIconMetric || !pLoadIconWithScaleDown)
245 win_skip("LoadIconMetric or pLoadIconWithScaleDown not exported by name\n");
246 FreeLibrary(hinst);
247 return;
250 GetTempPathW(MAX_PATH, tmp_path);
251 GetTempFileNameW(tmp_path, prefixW, 0, icon_path);
252 handle = CreateFileW(icon_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
253 FILE_ATTRIBUTE_NORMAL, NULL);
254 ok(handle != INVALID_HANDLE_VALUE, "CreateFileW failed with error %u\n", GetLastError());
255 res = WriteFile(handle, testicon_data, sizeof(testicon_data), &written, NULL);
256 ok(res && written == sizeof(testicon_data), "Failed to write icon file\n");
257 CloseHandle(handle);
259 /* test ordinals */
260 ptr = GetProcAddress(hinst, (const char *)380);
261 ok(ptr == pLoadIconMetric,
262 "got wrong pointer for ordinal 380, %p expected %p\n", ptr, pLoadIconMetric);
264 ptr = GetProcAddress(hinst, (const char *)381);
265 ok(ptr == pLoadIconWithScaleDown,
266 "got wrong pointer for ordinal 381, %p expected %p\n", ptr, pLoadIconWithScaleDown);
268 /* invalid arguments */
269 icon = (HICON)0x1234;
270 hr = pLoadIconMetric(NULL, (LPWSTR)IDI_APPLICATION, 0x100, &icon);
271 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", hr);
272 ok(icon == NULL, "Expected NULL, got %p\n", icon);
274 icon = (HICON)0x1234;
275 hr = pLoadIconMetric(NULL, NULL, LIM_LARGE, &icon);
276 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", hr);
277 ok(icon == NULL, "Expected NULL, got %p\n", icon);
279 icon = (HICON)0x1234;
280 hr = pLoadIconWithScaleDown(NULL, NULL, 32, 32, &icon);
281 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", hr);
282 ok(icon == NULL, "Expected NULL, got %p\n", icon);
284 /* non-existing filename */
285 hr = pLoadIconMetric(NULL, nonexisting_fileW, LIM_LARGE, &icon);
286 todo_wine
287 ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND),
288 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr);
290 hr = pLoadIconWithScaleDown(NULL, nonexisting_fileW, 32, 32, &icon);
291 todo_wine
292 ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND),
293 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr);
295 /* non-existing resource name */
296 hr = pLoadIconMetric(hinst, nonexisting_resourceW, LIM_LARGE, &icon);
297 ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND),
298 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr);
300 hr = pLoadIconWithScaleDown(hinst, nonexisting_resourceW, 32, 32, &icon);
301 ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND),
302 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr);
304 /* load icon using predefined identifier */
305 hr = pLoadIconMetric(NULL, (LPWSTR)IDI_APPLICATION, LIM_SMALL, &icon);
306 ok(hr == S_OK, "Expected S_OK, got %x\n", hr);
307 res = GetIconInfo(icon, &info);
308 ok(res, "Failed to get icon info, error %u\n", GetLastError());
309 bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp);
310 ok(bytes > 0, "Failed to get bitmap info for icon\n");
311 ok(bmp.bmWidth == GetSystemMetrics(SM_CXSMICON), "Wrong icon width %d\n", bmp.bmWidth);
312 ok(bmp.bmHeight == GetSystemMetrics(SM_CYSMICON), "Wrong icon height %d\n", bmp.bmHeight);
313 DestroyIcon(icon);
315 hr = pLoadIconMetric(NULL, (LPWSTR)IDI_APPLICATION, LIM_LARGE, &icon);
316 ok(hr == S_OK, "Expected S_OK, got %x\n", hr);
317 res = GetIconInfo(icon, &info);
318 ok(res, "Failed to get icon info, error %u\n", GetLastError());
319 bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp);
320 ok(bytes > 0, "Failed to get bitmap info for icon\n");
321 ok(bmp.bmWidth == GetSystemMetrics(SM_CXICON), "Wrong icon width %d\n", bmp.bmWidth);
322 ok(bmp.bmHeight == GetSystemMetrics(SM_CYICON), "Wrong icon height %d\n", bmp.bmHeight);
323 DestroyIcon(icon);
325 hr = pLoadIconWithScaleDown(NULL, (LPWSTR)IDI_APPLICATION, 42, 42, &icon);
326 ok(hr == S_OK, "Expected S_OK, got %x\n", hr);
327 res = GetIconInfo(icon, &info);
328 ok(res, "Failed to get icon info, error %u\n", GetLastError());
329 bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp);
330 ok(bytes > 0, "Failed to get bitmap info for icon\n");
331 ok(bmp.bmWidth == 42, "Wrong icon width %d\n", bmp.bmWidth);
332 ok(bmp.bmHeight == 42, "Wrong icon height %d\n", bmp.bmHeight);
333 DestroyIcon(icon);
335 /* load icon from file */
336 hr = pLoadIconMetric(NULL, icon_path, LIM_SMALL, &icon);
337 ok(hr == S_OK, "Expected S_OK, got %x\n", hr);
338 res = GetIconInfo(icon, &info);
339 ok(res, "Failed to get icon info, error %u\n", GetLastError());
340 bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp);
341 ok(bytes > 0, "Failed to get bitmap info for icon\n");
342 ok(bmp.bmWidth == GetSystemMetrics(SM_CXSMICON), "Wrong icon width %d\n", bmp.bmWidth);
343 ok(bmp.bmHeight == GetSystemMetrics(SM_CYSMICON), "Wrong icon height %d\n", bmp.bmHeight);
344 DestroyIcon(icon);
346 hr = pLoadIconWithScaleDown(NULL, icon_path, 42, 42, &icon);
347 ok(hr == S_OK, "Expected S_OK, got %x\n", hr);
348 res = GetIconInfo(icon, &info);
349 ok(res, "Failed to get icon info, error %u\n", GetLastError());
350 bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp);
351 ok(bytes > 0, "Failed to get bitmap info for icon\n");
352 ok(bmp.bmWidth == 42, "Wrong icon width %d\n", bmp.bmWidth);
353 ok(bmp.bmHeight == 42, "Wrong icon height %d\n", bmp.bmHeight);
354 DestroyIcon(icon);
356 DeleteFileW(icon_path);
357 FreeLibrary(hinst);
360 static void check_class( const char *name, int must_exist, UINT style, UINT ignore )
362 WNDCLASSA wc;
364 if (GetClassInfoA( 0, name, &wc ))
366 todo_wine
367 ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
368 name, ~wc.style & style, wc.style, style );
369 ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
370 name, wc.style & ~style, wc.style, style );
371 ok( !wc.hInstance, "System class %s has hInstance %p\n", name, wc.hInstance );
373 else
374 ok( !must_exist, "System class %s does not exist\n", name );
377 /* test styles of system classes */
378 static void test_builtin_classes(void)
380 /* check style bits */
381 check_class( "Button", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS, 0 );
382 check_class( "ComboBox", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS, 0 );
383 check_class( "Edit", 1, CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS, 0 );
384 check_class( "ListBox", 1, CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS, 0 );
385 check_class( "ScrollBar", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS, 0 );
386 check_class( "Static", 1, CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS, 0 );
387 check_class( "ComboLBox", 1, CS_SAVEBITS | CS_DBLCLKS | CS_DROPSHADOW | CS_GLOBALCLASS, CS_DROPSHADOW );
390 START_TEST(misc)
392 ULONG_PTR ctx_cookie;
393 HANDLE hCtx;
395 if(!InitFunctionPtrs())
396 return;
398 test_GetPtrAW();
399 test_Alloc();
401 if (!load_v6_module(&ctx_cookie, &hCtx))
402 return;
404 test_builtin_classes();
405 test_TaskDialogIndirect();
406 test_LoadIconWithScaleDown();
408 unload_v6_module(ctx_cookie, hCtx);