shdocvw: Always create BindStatusCallback object.
[wine.git] / dlls / user32 / tests / resource.c
blob59f86ef56b6514e823164a9989230ed3094546e8
1 /* Unit test suite for resources.
3 * Copyright 2004 Ferenc Wagner
4 * Copyright 2003, 2004 Mike McCormack
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 <assert.h>
22 #include <windows.h>
24 #include "wine/test.h"
26 static UINT (WINAPI *pPrivateExtractIconsA)(LPCTSTR, int, int, int, HICON *, UINT *, UINT, UINT) = NULL;
28 static void init_function_pointers(void)
30 HMODULE hmod = GetModuleHandleA("user32.dll");
31 pPrivateExtractIconsA = (void*)GetProcAddress(hmod, "PrivateExtractIconsA");
34 static void test_LoadStringA (void)
36 HINSTANCE hInst = GetModuleHandle (NULL);
37 static const char str[] = "String resource"; /* same in resource.rc */
38 char buf[128];
39 struct string_test {
40 int bufsiz;
41 int expected;
43 struct string_test tests[] = {{sizeof buf, sizeof str - 1},
44 {sizeof str, sizeof str - 1},
45 {sizeof str - 1, sizeof str - 2}};
46 unsigned int i;
47 int ret;
49 assert (sizeof str < sizeof buf);
50 for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
51 const int bufsiz = tests[i].bufsiz;
52 const int expected = tests[i].expected;
53 const int len = LoadStringA (hInst, 0, buf, bufsiz);
55 ok (len == expected, "bufsiz=%d: got %d, expected %d\n",
56 bufsiz, len, expected);
57 ok (!memcmp (buf, str, len),
58 "bufsiz=%d: got '%s', expected '%.*s'\n",
59 bufsiz, buf, len, str);
60 ok (buf[len] == 0, "bufsiz=%d: NUL termination missing\n",
61 bufsiz);
64 ret = LoadStringA(hInst, 1, buf, sizeof(buf) );
65 ok( ret > 0, "LoadString failed: ret %d err %d\n", ret, GetLastError());
66 ok( LoadStringA( hInst, MAKELONG( 1, 0x8000 ), buf, sizeof(buf)) == ret,
67 "LoadString failed: ret %d err %d\n", ret, GetLastError());
68 ok( LoadStringA( hInst, MAKELONG( 1, 0xffff ), buf, sizeof(buf)) == ret,
69 "LoadString failed: ret %d err %d\n", ret, GetLastError());
71 ret = LoadStringA(hInst, 65534, buf, sizeof(buf) );
72 ok( ret > 0, "LoadString failed: ret %d err %d\n", ret, GetLastError());
73 ok( LoadStringA( hInst, MAKELONG( 65534, 0x8000 ), buf, sizeof(buf)) == ret,
74 "LoadString failed: ret %d err %d\n", ret, GetLastError());
75 ok( LoadStringA( hInst, MAKELONG( 65534, 0xffff ), buf, sizeof(buf)) == ret,
76 "LoadString failed: ret %d err %d\n", ret, GetLastError());
79 static void test_accel1(void)
81 UINT r, n;
82 HACCEL hAccel;
83 ACCEL ac[10];
85 /* now create our own valid accelerator table */
86 n = 0;
87 ac[n].cmd = 1000;
88 ac[n].key = 'A';
89 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
91 ac[n].cmd = 1001;
92 ac[n].key = 'B';
93 ac[n++].fVirt = FNOINVERT;
95 ac[n].cmd = 0;
96 ac[n].key = 0;
97 ac[n++].fVirt = 0;
99 hAccel = CreateAcceleratorTable( &ac[0], n );
100 ok( hAccel != NULL, "create accelerator table\n");
102 r = DestroyAcceleratorTable( hAccel );
103 ok( r, "destroy accelerator table\n");
105 /* now try create an invalid one */
106 n = 0;
107 ac[n].cmd = 1000;
108 ac[n].key = 'A';
109 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
111 ac[n].cmd = 0xffff;
112 ac[n].key = 0xffff;
113 ac[n++].fVirt = (SHORT) 0xffff;
115 ac[n].cmd = 0xfff0;
116 ac[n].key = 0xffff;
117 ac[n++].fVirt = (SHORT) 0xfff0;
119 ac[n].cmd = 0xfff0;
120 ac[n].key = 0xffff;
121 ac[n++].fVirt = (SHORT) 0x0000;
123 ac[n].cmd = 0xfff0;
124 ac[n].key = 0xffff;
125 ac[n++].fVirt = (SHORT) 0x0001;
127 hAccel = CreateAcceleratorTable( &ac[0], n );
128 ok( hAccel != NULL, "create accelerator table\n");
130 r = CopyAcceleratorTable( hAccel, NULL, 0 );
131 ok( r == n, "two entries in table\n");
133 r = CopyAcceleratorTable( hAccel, &ac[0], r );
134 ok( r == n, "still should be two entries in table\n");
136 n=0;
137 ok( ac[n].cmd == 1000, "cmd 0 not preserved\n");
138 ok( ac[n].key == 'A', "key 0 not preserved\n");
139 ok( ac[n].fVirt == (FVIRTKEY | FNOINVERT), "fVirt 0 not preserved\n");
141 n++;
142 ok( ac[n].cmd == 0xffff, "cmd 1 not preserved\n");
143 ok( ac[n].key == 0xffff, "key 1 not preserved\n");
144 ok( ac[n].fVirt == 0x007f, "fVirt 1 not changed\n");
146 n++;
147 ok( ac[n].cmd == 0xfff0, "cmd 2 not preserved\n");
148 ok( ac[n].key == 0x00ff, "key 2 not preserved\n");
149 ok( ac[n].fVirt == 0x0070, "fVirt 2 not changed\n");
151 n++;
152 ok( ac[n].cmd == 0xfff0, "cmd 3 not preserved\n");
153 ok( ac[n].key == 0x00ff, "key 3 not preserved\n");
154 ok( ac[n].fVirt == 0x0000, "fVirt 3 not changed\n");
156 n++;
157 ok( ac[n].cmd == 0xfff0, "cmd 4 not preserved\n");
158 ok( ac[n].key == 0xffff, "key 4 not preserved\n");
159 ok( ac[n].fVirt == 0x0001, "fVirt 4 not changed\n");
161 r = DestroyAcceleratorTable( hAccel );
162 ok( r, "destroy accelerator table\n");
164 hAccel = CreateAcceleratorTable( &ac[0], 0 );
165 ok( !hAccel, "zero elements should fail\n");
167 /* these will on crash win2k
168 hAccel = CreateAcceleratorTable( NULL, 1 );
169 hAccel = CreateAcceleratorTable( &ac[0], -1 );
174 * memcmp on the tables works in Windows, but does not work in wine, as
175 * there is an extra undefined and unused byte between fVirt and the key
177 static void test_accel2(void)
179 ACCEL ac[2], out[2];
180 HACCEL hac;
182 ac[0].cmd = 0;
183 ac[0].fVirt = 0;
184 ac[0].key = 0;
186 ac[1].cmd = 0;
187 ac[1].fVirt = 0;
188 ac[1].key = 0;
191 * crashes on win2k
192 * hac = CreateAcceleratorTable( NULL, 1 );
195 /* try a zero count */
196 hac = CreateAcceleratorTable( &ac[0], 0 );
197 ok( !hac , "fail\n");
198 ok( !DestroyAcceleratorTable( hac ), "destroy failed\n");
200 /* creating one accelerator should work */
201 hac = CreateAcceleratorTable( &ac[0], 1 );
202 ok( hac != NULL , "fail\n");
203 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy failed\n");
204 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
206 /* how about two of the same type? */
207 hac = CreateAcceleratorTable( &ac[0], 2);
208 ok( hac != NULL , "fail\n");
209 ok( 2 == CopyAcceleratorTable( hac, NULL, 100 ), "copy null failed\n");
210 ok( 2 == CopyAcceleratorTable( hac, NULL, 0 ), "copy null failed\n");
211 ok( 2 == CopyAcceleratorTable( hac, NULL, 1 ), "copy null failed\n");
212 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
213 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
214 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
215 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
217 /* how about two of the same type with a non-zero key? */
218 ac[0].key = 0x20;
219 ac[1].key = 0x20;
220 hac = CreateAcceleratorTable( &ac[0], 2);
221 ok( hac != NULL , "fail\n");
222 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
223 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
224 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
226 /* how about two of the same type with a non-zero virtual key? */
227 ac[0].fVirt = FVIRTKEY;
228 ac[0].key = 0x40;
229 ac[1].fVirt = FVIRTKEY;
230 ac[1].key = 0x40;
231 hac = CreateAcceleratorTable( &ac[0], 2);
232 ok( hac != NULL , "fail\n");
233 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
234 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
235 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
237 /* how virtual key codes */
238 ac[0].fVirt = FVIRTKEY;
239 hac = CreateAcceleratorTable( &ac[0], 1);
240 ok( hac != NULL , "fail\n");
241 ok( 1 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
242 /* ok( !memcmp( ac, out, sizeof ac/2 ), "tables different\n"); */
243 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
245 /* how turning on all bits? */
246 ac[0].cmd = 0xffff;
247 ac[0].fVirt = 0xff;
248 ac[0].key = 0xffff;
249 hac = CreateAcceleratorTable( &ac[0], 1);
250 ok( hac != NULL , "fail\n");
251 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
252 /* ok( memcmp( ac, out, sizeof ac/2 ), "tables not different\n"); */
253 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
254 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
255 ok( out[0].key == ac[0].key, "key modified\n");
256 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
258 /* how turning on all bits? */
259 memset( ac, 0xff, sizeof ac );
260 hac = CreateAcceleratorTable( &ac[0], 2);
261 ok( hac != NULL , "fail\n");
262 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
263 /* ok( memcmp( ac, out, sizeof ac ), "tables not different\n"); */
264 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
265 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
266 ok( out[0].key == ac[0].key, "key modified\n");
267 ok( out[1].cmd == ac[1].cmd, "cmd modified\n");
268 ok( out[1].fVirt == (ac[1].fVirt&0x7f), "fVirt not modified\n");
269 ok( out[1].key == ac[1].key, "key modified\n");
270 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
273 static void test_PrivateExtractIcons(void) {
274 CONST CHAR szShell32Dll[] = "shell32.dll";
275 HICON ahIcon[256];
276 UINT aIconId[256];
277 UINT cIcons, cIcons2;
279 if (!pPrivateExtractIconsA) return;
281 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, NULL, NULL, 0, 0);
282 cIcons2 = pPrivateExtractIconsA(szShell32Dll, 4, MAKELONG(32,16), MAKELONG(32,16),
283 NULL, NULL, 256, 0);
284 ok((cIcons == cIcons2) && (cIcons > 0),
285 "Icon count should be independent of requested icon sizes and base icon index! "
286 "(cIcons=%d, cIcons2=%d)\n", cIcons, cIcons2);
288 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, ahIcon, aIconId, 0, 0);
289 ok(cIcons == 0, "Zero icons requested, got cIcons=%d\n", cIcons);
291 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, ahIcon, aIconId, 3, 0);
292 ok(cIcons == 3, "Three icons requested got cIcons=%d\n", cIcons);
294 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, MAKELONG(32,16), MAKELONG(32,16),
295 ahIcon, aIconId, 3, 0);
296 ok(cIcons == 4, "Three icons requested, four expected, got cIcons=%d\n", cIcons);
299 static void test_LoadImage(void)
301 HBITMAP bmp;
302 HRSRC hres;
304 bmp = LoadBitmapA(GetModuleHandle(NULL), MAKEINTRESOURCE(100));
305 ok(bmp != NULL, "Could not load a bitmap resource\n");
306 if (bmp) DeleteObject(bmp);
308 hres = FindResource(GetModuleHandle(NULL), "#100", RT_BITMAP);
309 ok(hres != NULL, "Could not find a bitmap resource with a numeric string\n");
311 bmp = LoadBitmapA(GetModuleHandle(NULL), "#100");
312 ok(bmp != NULL, "Could not load a bitmap resource with a numeric string\n");
313 if (bmp) DeleteObject(bmp);
316 START_TEST(resource)
318 init_function_pointers();
319 test_LoadStringA ();
320 test_accel1();
321 test_accel2();
322 test_PrivateExtractIcons();
323 test_LoadImage();