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
25 #include "wine/test.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,
52 #define COMCTL32_GET_PROC(ordinal, func) \
53 p ## func = (void*)GetProcAddress(hComctl32, (LPSTR)ordinal); \
55 trace("GetProcAddress(%d)(%s) failed\n", ordinal, #func); \
56 FreeLibrary(hComctl32); \
59 static BOOL
InitFunctionPtrs(void)
61 hComctl32
= LoadLibraryA("comctl32.dll");
65 trace("Could not load comctl32.dll\n");
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
)
82 static void test_GetPtrAW(void)
86 static const char source
[] = "Just a source string";
87 static const char desttest
[] = "Just a destination string";
88 static char dest
[MAX_PATH
];
90 int destsize
= MAX_PATH
;
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
);
100 /* Crashes on W98, NT4, W2K, XP, W2K3
101 * Our implementation also crashes and we should probably leave
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");
139 count
= pStr_GetPtrA(source
, dest
, destsize
);
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)
154 /* allocate size 0 */
156 ok(p
!= NULL
, "Expected non-NULL ptr\n");
158 /* get the minimum size */
163 ok(res
== TRUE
, "Expected TRUE, got %d\n", res
);
165 /* allocate size 1 */
167 ok(p
!= NULL
, "Expected non-NULL ptr\n");
169 /* get the allocated size */
172 broken(size
== min
), /* win9x */
173 "Expected 1, got %d\n", size
);
175 /* reallocate the block */
177 ok(p
!= NULL
, "Expected non-NULL ptr\n");
179 /* get the new size */
182 broken(size
== min
), /* win9x */
183 "Expected 2, got %d\n", size
);
187 ok(res
== TRUE
, "Expected TRUE, got %d\n", res
);
189 /* free a NULL ptr */
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
, "Expected non-NULL ptr\n");
200 ok(res
== TRUE
, "Expected TRUE, got %d\n", res
);
203 static void test_LoadIconWithScaleDown(void)
205 HRESULT (WINAPI
*pLoadIconMetric
)(HINSTANCE
, const WCHAR
*, int, HICON
*);
206 HRESULT (WINAPI
*pLoadIconWithScaleDown
)(HINSTANCE
, const WCHAR
*, int, int, HICON
*);
207 WCHAR tmp_path
[MAX_PATH
], icon_path
[MAX_PATH
];
219 hinst
= LoadLibraryA("comctl32.dll");
220 pLoadIconMetric
= (void *)GetProcAddress(hinst
, "LoadIconMetric");
221 pLoadIconWithScaleDown
= (void *)GetProcAddress(hinst
, "LoadIconWithScaleDown");
222 if (!pLoadIconMetric
|| !pLoadIconWithScaleDown
)
224 win_skip("LoadIconMetric or pLoadIconWithScaleDown not exported by name\n");
229 GetTempPathW(MAX_PATH
, tmp_path
);
230 GetTempFileNameW(tmp_path
, L
"ICO", 0, icon_path
);
231 handle
= CreateFileW(icon_path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
232 FILE_ATTRIBUTE_NORMAL
, NULL
);
233 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFileW failed with error %u\n", GetLastError());
234 res
= WriteFile(handle
, testicon_data
, sizeof(testicon_data
), &written
, NULL
);
235 ok(res
&& written
== sizeof(testicon_data
), "Failed to write icon file\n");
239 ptr
= GetProcAddress(hinst
, (const char *)380);
240 ok(ptr
== pLoadIconMetric
,
241 "got wrong pointer for ordinal 380, %p expected %p\n", ptr
, pLoadIconMetric
);
243 ptr
= GetProcAddress(hinst
, (const char *)381);
244 ok(ptr
== pLoadIconWithScaleDown
,
245 "got wrong pointer for ordinal 381, %p expected %p\n", ptr
, pLoadIconWithScaleDown
);
247 /* invalid arguments */
248 icon
= (HICON
)0x1234;
249 hr
= pLoadIconMetric(NULL
, (LPWSTR
)IDI_APPLICATION
, 0x100, &icon
);
250 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %x\n", hr
);
251 ok(icon
== NULL
, "Expected NULL, got %p\n", icon
);
253 icon
= (HICON
)0x1234;
254 hr
= pLoadIconMetric(NULL
, NULL
, LIM_LARGE
, &icon
);
255 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %x\n", hr
);
256 ok(icon
== NULL
, "Expected NULL, got %p\n", icon
);
258 icon
= (HICON
)0x1234;
259 hr
= pLoadIconWithScaleDown(NULL
, NULL
, 32, 32, &icon
);
260 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %x\n", hr
);
261 ok(icon
== NULL
, "Expected NULL, got %p\n", icon
);
263 /* non-existing filename */
264 hr
= pLoadIconMetric(NULL
, L
"nonexisting.ico", LIM_LARGE
, &icon
);
265 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* Win7 */,
266 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
268 hr
= pLoadIconWithScaleDown(NULL
, L
"nonexisting.ico", 32, 32, &icon
);
270 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
271 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
273 /* non-existing resource name */
274 hr
= pLoadIconMetric(hinst
, L
"Nonexisting", LIM_LARGE
, &icon
);
275 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
276 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
278 hr
= pLoadIconWithScaleDown(hinst
, L
"Noneexisting", 32, 32, &icon
);
279 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
280 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
282 /* load icon using predefined identifier */
283 hr
= pLoadIconMetric(NULL
, (LPWSTR
)IDI_APPLICATION
, LIM_SMALL
, &icon
);
284 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
285 res
= GetIconInfo(icon
, &info
);
286 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
287 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
288 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
289 ok(bmp
.bmWidth
== GetSystemMetrics(SM_CXSMICON
), "Wrong icon width %d\n", bmp
.bmWidth
);
290 ok(bmp
.bmHeight
== GetSystemMetrics(SM_CYSMICON
), "Wrong icon height %d\n", bmp
.bmHeight
);
293 hr
= pLoadIconMetric(NULL
, (LPWSTR
)IDI_APPLICATION
, LIM_LARGE
, &icon
);
294 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
295 res
= GetIconInfo(icon
, &info
);
296 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
297 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
298 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
299 ok(bmp
.bmWidth
== GetSystemMetrics(SM_CXICON
), "Wrong icon width %d\n", bmp
.bmWidth
);
300 ok(bmp
.bmHeight
== GetSystemMetrics(SM_CYICON
), "Wrong icon height %d\n", bmp
.bmHeight
);
303 hr
= pLoadIconWithScaleDown(NULL
, (LPWSTR
)IDI_APPLICATION
, 42, 42, &icon
);
304 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
305 res
= GetIconInfo(icon
, &info
);
306 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
307 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
308 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
309 ok(bmp
.bmWidth
== 42, "Wrong icon width %d\n", bmp
.bmWidth
);
310 ok(bmp
.bmHeight
== 42, "Wrong icon height %d\n", bmp
.bmHeight
);
313 /* load icon from file */
314 hr
= pLoadIconMetric(NULL
, icon_path
, LIM_SMALL
, &icon
);
315 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
316 res
= GetIconInfo(icon
, &info
);
317 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
318 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
319 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
320 ok(bmp
.bmWidth
== GetSystemMetrics(SM_CXSMICON
), "Wrong icon width %d\n", bmp
.bmWidth
);
321 ok(bmp
.bmHeight
== GetSystemMetrics(SM_CYSMICON
), "Wrong icon height %d\n", bmp
.bmHeight
);
324 hr
= pLoadIconWithScaleDown(NULL
, icon_path
, 42, 42, &icon
);
325 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
326 res
= GetIconInfo(icon
, &info
);
327 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
328 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
329 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
330 ok(bmp
.bmWidth
== 42, "Wrong icon width %d\n", bmp
.bmWidth
);
331 ok(bmp
.bmHeight
== 42, "Wrong icon height %d\n", bmp
.bmHeight
);
334 DeleteFileW(icon_path
);
338 static void check_class( const char *name
, int must_exist
, UINT style
, UINT ignore
, BOOL v6
)
342 if (GetClassInfoA( 0, name
, &wc
))
347 todo_wine_if(!strcmp(name
, "SysLink") && !must_exist
&& !v6
)
348 ok( must_exist
, "System class %s should %sexist\n", name
, must_exist
? "" : "NOT " );
349 if (!must_exist
) return;
351 todo_wine_if(!strcmp(name
, "ScrollBar") || (!strcmp(name
, "tooltips_class32") && v6
))
352 ok( !(~wc
.style
& style
& ~ignore
), "System class %s is missing bits %x (%08x/%08x)\n",
353 name
, ~wc
.style
& style
, wc
.style
, style
);
354 todo_wine_if((!strcmp(name
, "tooltips_class32") && v6
) || !strcmp(name
, "SysLink"))
355 ok( !(wc
.style
& ~style
), "System class %s has extra bits %x (%08x/%08x)\n",
356 name
, wc
.style
& ~style
, wc
.style
, style
);
357 ok( !wc
.hInstance
, "System class %s has hInstance %p\n", name
, wc
.hInstance
);
359 hwnd
= CreateWindowA(name
, 0, 0, 0, 0, 0, 0, 0, NULL
, GetModuleHandleA(NULL
), 0);
360 ok( hwnd
!= NULL
, "Failed to create window for class %s.\n", name
);
361 GetClassNameA(hwnd
, buff
, ARRAY_SIZE(buff
));
362 ok( !strcmp(name
, buff
), "Unexpected class name %s, expected %s.\n", buff
, name
);
366 ok( !must_exist
, "System class %s does not exist\n", name
);
369 /* test styles of system classes */
370 static void test_builtin_classes(void)
372 /* check style bits */
373 check_class( "Button", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
374 check_class( "ComboBox", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
375 check_class( "Edit", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
376 check_class( "ListBox", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
377 check_class( "ScrollBar", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
378 check_class( "Static", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
379 check_class( "ComboLBox", 1, CS_SAVEBITS
| CS_DBLCLKS
| CS_DROPSHADOW
| CS_GLOBALCLASS
, CS_DROPSHADOW
, FALSE
);
382 static void test_comctl32_classes(BOOL v6
)
384 check_class(ANIMATE_CLASSA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
385 check_class(WC_COMBOBOXEXA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
386 check_class(DATETIMEPICK_CLASSA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
387 check_class(WC_HEADERA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
388 check_class(HOTKEY_CLASSA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
389 check_class(WC_IPADDRESSA
, 1, CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
390 check_class(WC_LISTVIEWA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
391 check_class(MONTHCAL_CLASSA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
392 check_class(WC_NATIVEFONTCTLA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
393 check_class(WC_PAGESCROLLERA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
394 check_class(PROGRESS_CLASSA
, 1, CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
395 check_class(REBARCLASSNAMEA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
396 check_class(STATUSCLASSNAMEA
, 1, CS_DBLCLKS
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
397 check_class(WC_TABCONTROLA
, 1, CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
398 check_class(TOOLBARCLASSNAMEA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
400 check_class(TOOLTIPS_CLASSA
, 1, CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
| CS_DROPSHADOW
, CS_SAVEBITS
| CS_HREDRAW
| CS_VREDRAW
/* XP */, TRUE
);
402 check_class(TOOLTIPS_CLASSA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
| CS_SAVEBITS
, CS_HREDRAW
| CS_VREDRAW
/* XP */, FALSE
);
403 check_class(TRACKBAR_CLASSA
, 1, CS_GLOBALCLASS
, 0, FALSE
);
404 check_class(WC_TREEVIEWA
, 1, CS_DBLCLKS
| CS_GLOBALCLASS
, 0, FALSE
);
405 check_class(UPDOWN_CLASSA
, 1, CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0, FALSE
);
406 check_class("SysLink", v6
, CS_GLOBALCLASS
, 0, FALSE
);
411 ULONG_PTR ctx_cookie
;
414 if(!InitFunctionPtrs())
420 test_comctl32_classes(FALSE
);
422 if (!load_v6_module(&ctx_cookie
, &hCtx
))
425 test_comctl32_classes(TRUE
);
426 test_builtin_classes();
427 test_LoadIconWithScaleDown();
429 unload_v6_module(ctx_cookie
, hCtx
);