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
22 //#include <windows.h>
24 #include <wine/test.h>
30 static PVOID (WINAPI
* pAlloc
)(LONG
);
31 static PVOID (WINAPI
* pReAlloc
)(PVOID
, LONG
);
32 static BOOL (WINAPI
* pFree
)(PVOID
);
33 static LONG (WINAPI
* pGetSize
)(PVOID
);
35 static INT (WINAPI
* pStr_GetPtrA
)(LPCSTR
, LPSTR
, INT
);
36 static BOOL (WINAPI
* pStr_SetPtrA
)(LPSTR
, LPCSTR
);
37 static INT (WINAPI
* pStr_GetPtrW
)(LPCWSTR
, LPWSTR
, INT
);
38 static BOOL (WINAPI
* pStr_SetPtrW
)(LPWSTR
, LPCWSTR
);
40 static HMODULE hComctl32
= 0;
42 static char testicon_data
[] =
44 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x01, 0x00,
45 0x20, 0x00, 0x40, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
46 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00,
47 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x0b,
48 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0xde, 0xde, 0xde, 0xff, 0xde, 0xde, 0xde, 0xff, 0xde, 0xde,
50 0xde, 0xff, 0xde, 0xde, 0xde, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 #define COMCTL32_GET_PROC(ordinal, func) \
55 p ## func = (void*)GetProcAddress(hComctl32, (LPSTR)ordinal); \
57 trace("GetProcAddress(%d)(%s) failed\n", ordinal, #func); \
58 FreeLibrary(hComctl32); \
61 static BOOL
InitFunctionPtrs(void)
63 hComctl32
= LoadLibraryA("comctl32.dll");
67 trace("Could not load comctl32.dll\n");
71 COMCTL32_GET_PROC(71, Alloc
);
72 COMCTL32_GET_PROC(72, ReAlloc
);
73 COMCTL32_GET_PROC(73, Free
);
74 COMCTL32_GET_PROC(74, GetSize
);
76 COMCTL32_GET_PROC(233, Str_GetPtrA
)
77 COMCTL32_GET_PROC(234, Str_SetPtrA
)
78 COMCTL32_GET_PROC(235, Str_GetPtrW
)
79 COMCTL32_GET_PROC(236, Str_SetPtrW
)
84 static void test_GetPtrAW(void)
88 static const char source
[] = "Just a source string";
89 static const char desttest
[] = "Just a destination string";
90 static char dest
[MAX_PATH
];
92 int destsize
= MAX_PATH
;
95 sourcelen
= strlen(source
) + 1;
97 count
= pStr_GetPtrA(NULL
, NULL
, 0);
98 ok (count
== 0, "Expected count to be 0, it was %d\n", count
);
102 /* Crashes on W98, NT4, W2K, XP, W2K3
103 * Our implementation also crashes and we should probably leave
106 count
= pStr_GetPtrA(NULL
, NULL
, destsize
);
107 trace("count : %d\n", count
);
110 count
= pStr_GetPtrA(source
, NULL
, 0);
111 ok (count
== sourcelen
||
112 broken(count
== sourcelen
- 1), /* win9x */
113 "Expected count to be %d, it was %d\n", sourcelen
, count
);
115 strcpy(dest
, desttest
);
116 count
= pStr_GetPtrA(source
, dest
, 0);
117 ok (count
== sourcelen
||
118 broken(count
== 0), /* win9x */
119 "Expected count to be %d, it was %d\n", sourcelen
, count
);
120 ok (!lstrcmpA(dest
, desttest
) ||
121 broken(!lstrcmpA(dest
, "")), /* Win7 */
122 "Expected destination to not have changed\n");
124 count
= pStr_GetPtrA(source
, NULL
, destsize
);
125 ok (count
== sourcelen
||
126 broken(count
== sourcelen
- 1), /* win9x */
127 "Expected count to be %d, it was %d\n", sourcelen
, count
);
129 count
= pStr_GetPtrA(source
, dest
, destsize
);
130 ok (count
== sourcelen
||
131 broken(count
== sourcelen
- 1), /* win9x */
132 "Expected count to be %d, it was %d\n", sourcelen
, count
);
133 ok (!lstrcmpA(source
, dest
), "Expected source and destination to be the same\n");
135 strcpy(dest
, desttest
);
136 count
= pStr_GetPtrA(NULL
, dest
, destsize
);
137 ok (count
== 0, "Expected count to be 0, it was %d\n", count
);
138 ok (dest
[0] == '\0', "Expected destination to be cut-off and 0 terminated\n");
141 count
= pStr_GetPtrA(source
, dest
, destsize
);
143 broken(count
== 14), /* win9x */
144 "Expected count to be 15, it was %d\n", count
);
145 ok (!memcmp(source
, dest
, 14), "Expected first part of source and destination to be the same\n");
146 ok (dest
[14] == '\0', "Expected destination to be cut-off and 0 terminated\n");
150 static void test_Alloc(void)
156 /* allocate size 0 */
158 ok(p
!= NULL
, "Expected non-NULL ptr\n");
160 /* get the minimum size */
165 ok(res
== TRUE
, "Expected TRUE, got %d\n", res
);
167 /* allocate size 1 */
169 ok(p
!= NULL
, "Expected non-NULL ptr\n");
171 /* get the allocated size */
174 broken(size
== min
), /* win9x */
175 "Expected 1, got %d\n", size
);
177 /* reallocate the block */
179 ok(p
!= NULL
, "Expected non-NULL ptr\n");
181 /* get the new size */
184 broken(size
== min
), /* win9x */
185 "Expected 2, got %d\n", size
);
189 ok(res
== TRUE
, "Expected TRUE, got %d\n", res
);
191 /* free a NULL ptr */
194 broken(res
== FALSE
), /* win9x */
195 "Expected TRUE, got %d\n", res
);
197 /* reallocate a NULL ptr */
198 p
= pReAlloc(NULL
, 2);
199 ok(p
!= NULL
, "Expectd non-NULL ptr\n");
202 ok(res
== TRUE
, "Expected TRUE, got %d\n", res
);
205 static void test_TaskDialogIndirect(void)
210 hinst
= LoadLibraryA("comctl32.dll");
212 ptr
= GetProcAddress(hinst
, "TaskDialogIndirect");
217 skip("TaskDialogIndirect not exported by name\n");
219 win_skip("TaskDialogIndirect not exported by name\n");
224 ptr2
= GetProcAddress(hinst
, (const CHAR
*)345);
225 ok(ptr
== ptr2
, "got wrong pointer for ordinal 345, %p expected %p\n", ptr2
, ptr
);
228 static void test_LoadIconWithScaleDown(void)
230 static const WCHAR nonexisting_fileW
[] = {'n','o','n','e','x','i','s','t','i','n','g','.','i','c','o',0};
231 static const WCHAR nonexisting_resourceW
[] = {'N','o','n','e','x','i','s','t','i','n','g',0};
232 static const WCHAR prefixW
[] = {'I','C','O',0};
233 HRESULT (WINAPI
*pLoadIconMetric
)(HINSTANCE
, const WCHAR
*, int, HICON
*);
234 HRESULT (WINAPI
*pLoadIconWithScaleDown
)(HINSTANCE
, const WCHAR
*, int, int, HICON
*);
235 WCHAR tmp_path
[MAX_PATH
], icon_path
[MAX_PATH
];
247 hinst
= LoadLibraryA("comctl32.dll");
248 pLoadIconMetric
= (void *)GetProcAddress(hinst
, "LoadIconMetric");
249 pLoadIconWithScaleDown
= (void *)GetProcAddress(hinst
, "LoadIconWithScaleDown");
250 if (!pLoadIconMetric
|| !pLoadIconWithScaleDown
)
253 skip("LoadIconMetric or pLoadIconWithScaleDown not exported by name\n");
255 win_skip("LoadIconMetric or pLoadIconWithScaleDown not exported by name\n");
261 GetTempPathW(MAX_PATH
, tmp_path
);
262 GetTempFileNameW(tmp_path
, prefixW
, 0, icon_path
);
263 handle
= CreateFileW(icon_path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
264 FILE_ATTRIBUTE_NORMAL
, NULL
);
265 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFileW failed with error %u\n", GetLastError());
266 res
= WriteFile(handle
, testicon_data
, sizeof(testicon_data
), &written
, NULL
);
267 ok(res
&& written
== sizeof(testicon_data
), "Failed to write icon file\n");
271 ptr
= GetProcAddress(hinst
, (const char *)380);
272 ok(ptr
== pLoadIconMetric
,
273 "got wrong pointer for ordinal 380, %p expected %p\n", ptr
, pLoadIconMetric
);
275 ptr
= GetProcAddress(hinst
, (const char *)381);
276 ok(ptr
== pLoadIconWithScaleDown
,
277 "got wrong pointer for ordinal 381, %p expected %p\n", ptr
, pLoadIconWithScaleDown
);
279 /* invalid arguments */
280 icon
= (HICON
)0x1234;
281 hr
= pLoadIconMetric(NULL
, (LPWSTR
)IDI_APPLICATION
, 0x100, &icon
);
282 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %x\n", hr
);
283 ok(icon
== NULL
, "Expected NULL, got %p\n", icon
);
285 icon
= (HICON
)0x1234;
286 hr
= pLoadIconMetric(NULL
, NULL
, LIM_LARGE
, &icon
);
287 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %x\n", hr
);
288 ok(icon
== NULL
, "Expected NULL, got %p\n", icon
);
290 icon
= (HICON
)0x1234;
291 hr
= pLoadIconWithScaleDown(NULL
, NULL
, 32, 32, &icon
);
292 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %x\n", hr
);
293 ok(icon
== NULL
, "Expected NULL, got %p\n", icon
);
295 /* non-existing filename */
296 hr
= pLoadIconMetric(NULL
, nonexisting_fileW
, LIM_LARGE
, &icon
);
298 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
299 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
301 hr
= pLoadIconWithScaleDown(NULL
, nonexisting_fileW
, 32, 32, &icon
);
303 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
304 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
306 /* non-existing resource name */
307 hr
= pLoadIconMetric(hinst
, nonexisting_resourceW
, LIM_LARGE
, &icon
);
308 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
309 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
311 hr
= pLoadIconWithScaleDown(hinst
, nonexisting_resourceW
, 32, 32, &icon
);
312 ok(hr
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
),
313 "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr
);
315 /* load icon using predefined identifier */
316 hr
= pLoadIconMetric(NULL
, (LPWSTR
)IDI_APPLICATION
, LIM_SMALL
, &icon
);
317 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
318 res
= GetIconInfo(icon
, &info
);
319 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
320 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
321 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
322 ok(bmp
.bmWidth
== GetSystemMetrics(SM_CXSMICON
), "Wrong icon width %d\n", bmp
.bmWidth
);
323 ok(bmp
.bmHeight
== GetSystemMetrics(SM_CYSMICON
), "Wrong icon height %d\n", bmp
.bmHeight
);
326 hr
= pLoadIconMetric(NULL
, (LPWSTR
)IDI_APPLICATION
, LIM_LARGE
, &icon
);
327 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
328 res
= GetIconInfo(icon
, &info
);
329 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
330 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
331 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
332 ok(bmp
.bmWidth
== GetSystemMetrics(SM_CXICON
), "Wrong icon width %d\n", bmp
.bmWidth
);
333 ok(bmp
.bmHeight
== GetSystemMetrics(SM_CYICON
), "Wrong icon height %d\n", bmp
.bmHeight
);
336 hr
= pLoadIconWithScaleDown(NULL
, (LPWSTR
)IDI_APPLICATION
, 42, 42, &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
== 42, "Wrong icon width %d\n", bmp
.bmWidth
);
343 ok(bmp
.bmHeight
== 42, "Wrong icon height %d\n", bmp
.bmHeight
);
346 /* load icon from file */
347 hr
= pLoadIconMetric(NULL
, icon_path
, LIM_SMALL
, &icon
);
348 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
349 res
= GetIconInfo(icon
, &info
);
350 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
351 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
352 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
353 ok(bmp
.bmWidth
== GetSystemMetrics(SM_CXSMICON
), "Wrong icon width %d\n", bmp
.bmWidth
);
354 ok(bmp
.bmHeight
== GetSystemMetrics(SM_CYSMICON
), "Wrong icon height %d\n", bmp
.bmHeight
);
357 hr
= pLoadIconWithScaleDown(NULL
, icon_path
, 42, 42, &icon
);
358 ok(hr
== S_OK
, "Expected S_OK, got %x\n", hr
);
359 res
= GetIconInfo(icon
, &info
);
360 ok(res
, "Failed to get icon info, error %u\n", GetLastError());
361 bytes
= GetObjectA(info
.hbmColor
, sizeof(bmp
), &bmp
);
362 ok(bytes
> 0, "Failed to get bitmap info for icon\n");
363 ok(bmp
.bmWidth
== 42, "Wrong icon width %d\n", bmp
.bmWidth
);
364 ok(bmp
.bmHeight
== 42, "Wrong icon height %d\n", bmp
.bmHeight
);
367 DeleteFileW(icon_path
);
371 static void check_class( const char *name
, int must_exist
, UINT style
, UINT ignore
)
375 if (GetClassInfoA( 0, name
, &wc
))
378 ok( !(~wc
.style
& style
& ~ignore
), "System class %s is missing bits %x (%08x/%08x)\n",
379 name
, ~wc
.style
& style
, wc
.style
, style
);
380 ok( !(wc
.style
& ~style
), "System class %s has extra bits %x (%08x/%08x)\n",
381 name
, wc
.style
& ~style
, wc
.style
, style
);
382 ok( !wc
.hInstance
, "System class %s has hInstance %p\n", name
, wc
.hInstance
);
385 ok( !must_exist
, "System class %s does not exist\n", name
);
388 /* test styles of system classes */
389 static void test_builtin_classes(void)
391 /* check style bits */
392 check_class( "Button", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0 );
393 check_class( "ComboBox", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0 );
394 check_class( "Edit", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
, 0 );
395 check_class( "ListBox", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
, 0 );
396 check_class( "ScrollBar", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
, 0 );
397 check_class( "Static", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
, 0 );
398 check_class( "ComboLBox", 1, CS_SAVEBITS
| CS_DBLCLKS
| CS_DROPSHADOW
| CS_GLOBALCLASS
, CS_DROPSHADOW
);
403 ULONG_PTR ctx_cookie
;
406 if(!InitFunctionPtrs())
412 if (!load_v6_module(&ctx_cookie
, &hCtx
))
415 test_builtin_classes();
416 test_TaskDialogIndirect();
417 test_LoadIconWithScaleDown();
419 unload_v6_module(ctx_cookie
, hCtx
);