regedit: Remove dead code.
[wine/hacks.git] / dlls / user / tests / resource.c
blob30ee4afe2acf0c6943152fa7c731c6b409a39e37
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 if (hmod) {
32 pPrivateExtractIconsA = (void*)GetProcAddress(hmod, "PrivateExtractIconsA");
36 static void test_LoadStringA (void)
38 HINSTANCE hInst = GetModuleHandle (NULL);
39 static const char str[] = "String resource"; /* same in resource.rc */
40 char buf[128];
41 struct string_test {
42 int bufsiz;
43 int expected;
45 struct string_test tests[] = {{sizeof buf, sizeof str - 1},
46 {sizeof str, sizeof str - 1},
47 {sizeof str - 1, sizeof str - 2}};
48 unsigned int i;
49 int ret;
51 assert (sizeof str < sizeof buf);
52 for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
53 const int bufsiz = tests[i].bufsiz;
54 const int expected = tests[i].expected;
55 const int len = LoadStringA (hInst, 0, buf, bufsiz);
57 ok (len == expected, "bufsiz=%d: got %d, expected %d\n",
58 bufsiz, len, expected);
59 ok (!memcmp (buf, str, len),
60 "bufsiz=%d: got '%s', expected '%.*s'\n",
61 bufsiz, buf, len, str);
62 ok (buf[len] == 0, "bufsiz=%d: NUL termination missing\n",
63 bufsiz);
66 ret = LoadStringA(hInst, 1, buf, sizeof(buf) );
67 ok( ret > 0, "LoadString failed: ret %d err %ld\n", ret, GetLastError());
68 ok( LoadStringA( hInst, MAKELONG( 1, 0x8000 ), buf, sizeof(buf)) == ret,
69 "LoadString failed: ret %d err %ld\n", ret, GetLastError());
70 ok( LoadStringA( hInst, MAKELONG( 1, 0xffff ), buf, sizeof(buf)) == ret,
71 "LoadString failed: ret %d err %ld\n", ret, GetLastError());
73 ret = LoadStringA(hInst, 65534, buf, sizeof(buf) );
74 ok( ret > 0, "LoadString failed: ret %d err %ld\n", ret, GetLastError());
75 ok( LoadStringA( hInst, MAKELONG( 65534, 0x8000 ), buf, sizeof(buf)) == ret,
76 "LoadString failed: ret %d err %ld\n", ret, GetLastError());
77 ok( LoadStringA( hInst, MAKELONG( 65534, 0xffff ), buf, sizeof(buf)) == ret,
78 "LoadString failed: ret %d err %ld\n", ret, GetLastError());
81 static void test_accel1(void)
83 UINT r, n;
84 HACCEL hAccel;
85 ACCEL ac[10];
87 /* now create our own valid accelerator table */
88 n = 0;
89 ac[n].cmd = 1000;
90 ac[n].key = 'A';
91 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
93 ac[n].cmd = 1001;
94 ac[n].key = 'B';
95 ac[n++].fVirt = FNOINVERT;
97 ac[n].cmd = 0;
98 ac[n].key = 0;
99 ac[n++].fVirt = 0;
101 hAccel = CreateAcceleratorTable( &ac[0], n );
102 ok( hAccel != NULL, "create accelerator table\n");
104 r = DestroyAcceleratorTable( hAccel );
105 ok( r, "destroy accelerator table\n");
107 /* now try create an invalid one */
108 n = 0;
109 ac[n].cmd = 1000;
110 ac[n].key = 'A';
111 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
113 ac[n].cmd = 0xffff;
114 ac[n].key = 0xffff;
115 ac[n++].fVirt = (SHORT) 0xffff;
117 ac[n].cmd = 0xfff0;
118 ac[n].key = 0xffff;
119 ac[n++].fVirt = (SHORT) 0xfff0;
121 ac[n].cmd = 0xfff0;
122 ac[n].key = 0xffff;
123 ac[n++].fVirt = (SHORT) 0x0000;
125 ac[n].cmd = 0xfff0;
126 ac[n].key = 0xffff;
127 ac[n++].fVirt = (SHORT) 0x0001;
129 hAccel = CreateAcceleratorTable( &ac[0], n );
130 ok( hAccel != NULL, "create accelerator table\n");
132 r = CopyAcceleratorTable( hAccel, NULL, 0 );
133 ok( r == n, "two entries in table\n");
135 r = CopyAcceleratorTable( hAccel, &ac[0], r );
136 ok( r == n, "still should be two entries in table\n");
138 n=0;
139 ok( ac[n].cmd == 1000, "cmd 0 not preserved\n");
140 ok( ac[n].key == 'A', "key 0 not preserved\n");
141 ok( ac[n].fVirt == (FVIRTKEY | FNOINVERT), "fVirt 0 not preserved\n");
143 n++;
144 ok( ac[n].cmd == 0xffff, "cmd 1 not preserved\n");
145 ok( ac[n].key == 0xffff, "key 1 not preserved\n");
146 ok( ac[n].fVirt == 0x007f, "fVirt 1 not changed\n");
148 n++;
149 ok( ac[n].cmd == 0xfff0, "cmd 2 not preserved\n");
150 ok( ac[n].key == 0x00ff, "key 2 not preserved\n");
151 ok( ac[n].fVirt == 0x0070, "fVirt 2 not changed\n");
153 n++;
154 ok( ac[n].cmd == 0xfff0, "cmd 3 not preserved\n");
155 ok( ac[n].key == 0x00ff, "key 3 not preserved\n");
156 ok( ac[n].fVirt == 0x0000, "fVirt 3 not changed\n");
158 n++;
159 ok( ac[n].cmd == 0xfff0, "cmd 4 not preserved\n");
160 ok( ac[n].key == 0xffff, "key 4 not preserved\n");
161 ok( ac[n].fVirt == 0x0001, "fVirt 4 not changed\n");
163 r = DestroyAcceleratorTable( hAccel );
164 ok( r, "destroy accelerator table\n");
166 hAccel = CreateAcceleratorTable( &ac[0], 0 );
167 ok( !hAccel, "zero elements should fail\n");
169 /* these will on crash win2k
170 hAccel = CreateAcceleratorTable( NULL, 1 );
171 hAccel = CreateAcceleratorTable( &ac[0], -1 );
176 * memcmp on the tables works in Windows, but does not work in wine, as
177 * there is an extra undefined and unused byte between fVirt and the key
179 static void test_accel2(void)
181 ACCEL ac[2], out[2];
182 HACCEL hac;
184 ac[0].cmd = 0;
185 ac[0].fVirt = 0;
186 ac[0].key = 0;
188 ac[1].cmd = 0;
189 ac[1].fVirt = 0;
190 ac[1].key = 0;
193 * crashes on win2k
194 * hac = CreateAcceleratorTable( NULL, 1 );
197 /* try a zero count */
198 hac = CreateAcceleratorTable( &ac[0], 0 );
199 ok( !hac , "fail\n");
200 ok( !DestroyAcceleratorTable( hac ), "destroy failed\n");
202 /* creating one accelerator should work */
203 hac = CreateAcceleratorTable( &ac[0], 1 );
204 ok( hac != NULL , "fail\n");
205 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy failed\n");
206 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
208 /* how about two of the same type? */
209 hac = CreateAcceleratorTable( &ac[0], 2);
210 ok( hac != NULL , "fail\n");
211 ok( 2 == CopyAcceleratorTable( hac, NULL, 100 ), "copy null failed\n");
212 ok( 2 == CopyAcceleratorTable( hac, NULL, 0 ), "copy null failed\n");
213 ok( 2 == CopyAcceleratorTable( hac, NULL, 1 ), "copy null failed\n");
214 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
215 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
216 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
217 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
219 /* how about two of the same type with a non-zero key? */
220 ac[0].key = 0x20;
221 ac[1].key = 0x20;
222 hac = CreateAcceleratorTable( &ac[0], 2);
223 ok( hac != NULL , "fail\n");
224 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
225 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
226 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
228 /* how about two of the same type with a non-zero virtual key? */
229 ac[0].fVirt = FVIRTKEY;
230 ac[0].key = 0x40;
231 ac[1].fVirt = FVIRTKEY;
232 ac[1].key = 0x40;
233 hac = CreateAcceleratorTable( &ac[0], 2);
234 ok( hac != NULL , "fail\n");
235 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
236 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
237 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
239 /* how virtual key codes */
240 ac[0].fVirt = FVIRTKEY;
241 hac = CreateAcceleratorTable( &ac[0], 1);
242 ok( hac != NULL , "fail\n");
243 ok( 1 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
244 /* ok( !memcmp( ac, out, sizeof ac/2 ), "tables different\n"); */
245 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
247 /* how turning on all bits? */
248 ac[0].cmd = 0xffff;
249 ac[0].fVirt = 0xff;
250 ac[0].key = 0xffff;
251 hac = CreateAcceleratorTable( &ac[0], 1);
252 ok( hac != NULL , "fail\n");
253 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
254 /* ok( memcmp( ac, out, sizeof ac/2 ), "tables not different\n"); */
255 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
256 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
257 ok( out[0].key == ac[0].key, "key modified\n");
258 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
260 /* how turning on all bits? */
261 memset( ac, 0xff, sizeof ac );
262 hac = CreateAcceleratorTable( &ac[0], 2);
263 ok( hac != NULL , "fail\n");
264 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
265 /* ok( memcmp( ac, out, sizeof ac ), "tables not different\n"); */
266 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
267 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
268 ok( out[0].key == ac[0].key, "key modified\n");
269 ok( out[1].cmd == ac[1].cmd, "cmd modified\n");
270 ok( out[1].fVirt == (ac[1].fVirt&0x7f), "fVirt not modified\n");
271 ok( out[1].key == ac[1].key, "key modified\n");
272 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
275 static void test_PrivateExtractIcons(void) {
276 CONST CHAR szShell32Dll[] = "shell32.dll";
277 HICON ahIcon[256];
278 UINT aIconId[256];
279 UINT cIcons, cIcons2;
281 if (!pPrivateExtractIconsA) return;
283 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, NULL, NULL, 0, 0);
284 cIcons2 = pPrivateExtractIconsA(szShell32Dll, 4, MAKELONG(32,16), MAKELONG(32,16),
285 NULL, NULL, 256, 0);
286 ok((cIcons == cIcons2) && (cIcons > 0),
287 "Icon count should be independent of requested icon sizes and base icon index! "
288 "(cIcons=%d, cIcons2=%d)\n", cIcons, cIcons2);
290 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, ahIcon, aIconId, 0, 0);
291 ok(cIcons == 0, "Zero icons requested, got cIcons=%d\n", cIcons);
293 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, ahIcon, aIconId, 3, 0);
294 ok(cIcons == 3, "Three icons requested got cIcons=%d\n", cIcons);
296 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, MAKELONG(32,16), MAKELONG(32,16),
297 ahIcon, aIconId, 3, 0);
298 ok(cIcons == 4, "Three icons requested, four expected, got cIcons=%d\n", cIcons);
301 static void test_LoadImage(void)
303 HBITMAP bmp;
304 HRSRC hres;
306 bmp = LoadBitmapA(GetModuleHandle(NULL), MAKEINTRESOURCE(100));
307 ok(bmp != NULL, "Could not load a bitmap resource\n");
308 if (bmp) DeleteObject(bmp);
310 hres = FindResource(GetModuleHandle(NULL), "#100", RT_BITMAP);
311 ok(hres != NULL, "Could not find a bitmap resource with a numeric string\n");
313 bmp = LoadBitmapA(GetModuleHandle(NULL), "#100");
314 ok(bmp != NULL, "Could not load a bitmap resource with a numeric string\n");
315 if (bmp) DeleteObject(bmp);
318 START_TEST(resource)
320 init_function_pointers();
321 test_LoadStringA ();
322 test_accel1();
323 test_accel2();
324 test_PrivateExtractIcons();
325 test_LoadImage();