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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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");
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 */
45 struct string_test tests[] = {{sizeof buf, sizeof str - 1},
46 {sizeof str, sizeof str - 1},
47 {sizeof str - 1, sizeof str - 2}};
50 assert (sizeof str < sizeof buf);
51 for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
52 const int bufsiz = tests[i].bufsiz;
53 const int expected = tests[i].expected;
54 const int len = LoadStringA (hInst, 0, buf, bufsiz);
56 ok (len == expected, "bufsiz=%d: got %d, expected %d\n",
57 bufsiz, len, expected);
58 ok (!memcmp (buf, str, len),
59 "bufsiz=%d: got '%s', expected '%.*s'\n",
60 bufsiz, buf, len, str);
61 ok (buf[len] == 0, "bufsiz=%d: NUL termination missing\n",
66 static void test_accel1(void)
72 /* now create our own valid accelerator table */
76 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
80 ac[n++].fVirt = FNOINVERT;
86 hAccel = CreateAcceleratorTable( &ac[0], n );
87 ok( hAccel != NULL, "create accelerator table\n");
89 r = DestroyAcceleratorTable( hAccel );
90 ok( r, "destroy accelerator table\n");
92 /* now try create an invalid one */
96 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
100 ac[n++].fVirt = (SHORT) 0xffff;
104 ac[n++].fVirt = (SHORT) 0xfff0;
108 ac[n++].fVirt = (SHORT) 0x0000;
112 ac[n++].fVirt = (SHORT) 0x0001;
114 hAccel = CreateAcceleratorTable( &ac[0], n );
115 ok( hAccel != NULL, "create accelerator table\n");
117 r = CopyAcceleratorTable( hAccel, NULL, 0 );
118 ok( r == n, "two entries in table\n");
120 r = CopyAcceleratorTable( hAccel, &ac[0], r );
121 ok( r == n, "still should be two entries in table\n");
124 ok( ac[n].cmd == 1000, "cmd 0 not preserved\n");
125 ok( ac[n].key == 'A', "key 0 not preserved\n");
126 ok( ac[n].fVirt == (FVIRTKEY | FNOINVERT), "fVirt 0 not preserved\n");
129 ok( ac[n].cmd == 0xffff, "cmd 1 not preserved\n");
130 ok( ac[n].key == 0xffff, "key 1 not preserved\n");
131 ok( ac[n].fVirt == 0x007f, "fVirt 1 not changed\n");
134 ok( ac[n].cmd == 0xfff0, "cmd 2 not preserved\n");
135 ok( ac[n].key == 0x00ff, "key 2 not preserved\n");
136 ok( ac[n].fVirt == 0x0070, "fVirt 2 not changed\n");
139 ok( ac[n].cmd == 0xfff0, "cmd 3 not preserved\n");
140 ok( ac[n].key == 0x00ff, "key 3 not preserved\n");
141 ok( ac[n].fVirt == 0x0000, "fVirt 3 not changed\n");
144 ok( ac[n].cmd == 0xfff0, "cmd 4 not preserved\n");
145 ok( ac[n].key == 0xffff, "key 4 not preserved\n");
146 ok( ac[n].fVirt == 0x0001, "fVirt 4 not changed\n");
148 r = DestroyAcceleratorTable( hAccel );
149 ok( r, "destroy accelerator table\n");
151 hAccel = CreateAcceleratorTable( &ac[0], 0 );
152 ok( !hAccel, "zero elements should fail\n");
154 /* these will on crash win2k
155 hAccel = CreateAcceleratorTable( NULL, 1 );
156 hAccel = CreateAcceleratorTable( &ac[0], -1 );
161 * memcmp on the tables works in Windows, but does not work in wine, as
162 * there is an extra undefined and unused byte between fVirt and the key
164 static void test_accel2(void)
179 * hac = CreateAcceleratorTable( NULL, 1 );
182 /* try a zero count */
183 hac = CreateAcceleratorTable( &ac[0], 0 );
184 ok( !hac , "fail\n");
185 ok( !DestroyAcceleratorTable( hac ), "destroy failed\n");
187 /* creating one accelerator should work */
188 hac = CreateAcceleratorTable( &ac[0], 1 );
189 ok( hac != NULL , "fail\n");
190 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy failed\n");
191 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
193 /* how about two of the same type? */
194 hac = CreateAcceleratorTable( &ac[0], 2);
195 ok( hac != NULL , "fail\n");
196 ok( 2 == CopyAcceleratorTable( hac, NULL, 100 ), "copy null failed\n");
197 ok( 2 == CopyAcceleratorTable( hac, NULL, 0 ), "copy null failed\n");
198 ok( 2 == CopyAcceleratorTable( hac, NULL, 1 ), "copy null failed\n");
199 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
200 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
201 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
202 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
204 /* how about two of the same type with a non-zero key? */
207 hac = CreateAcceleratorTable( &ac[0], 2);
208 ok( hac != NULL , "fail\n");
209 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
210 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
211 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
213 /* how about two of the same type with a non-zero virtual key? */
214 ac[0].fVirt = FVIRTKEY;
216 ac[1].fVirt = FVIRTKEY;
218 hac = CreateAcceleratorTable( &ac[0], 2);
219 ok( hac != NULL , "fail\n");
220 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
221 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
222 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
224 /* how virtual key codes */
225 ac[0].fVirt = FVIRTKEY;
226 hac = CreateAcceleratorTable( &ac[0], 1);
227 ok( hac != NULL , "fail\n");
228 ok( 1 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
229 /* ok( !memcmp( ac, out, sizeof ac/2 ), "tables different\n"); */
230 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
232 /* how turning on all bits? */
236 hac = CreateAcceleratorTable( &ac[0], 1);
237 ok( hac != NULL , "fail\n");
238 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
239 /* ok( memcmp( ac, out, sizeof ac/2 ), "tables not different\n"); */
240 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
241 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
242 ok( out[0].key == ac[0].key, "key modified\n");
243 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
245 /* how turning on all bits? */
246 memset( ac, 0xff, sizeof ac );
247 hac = CreateAcceleratorTable( &ac[0], 2);
248 ok( hac != NULL , "fail\n");
249 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
250 /* ok( memcmp( ac, out, sizeof ac ), "tables not different\n"); */
251 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
252 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
253 ok( out[0].key == ac[0].key, "key modified\n");
254 ok( out[1].cmd == ac[1].cmd, "cmd modified\n");
255 ok( out[1].fVirt == (ac[1].fVirt&0x7f), "fVirt not modified\n");
256 ok( out[1].key == ac[1].key, "key modified\n");
257 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
260 static void test_PrivateExtractIcons(void) {
261 CONST CHAR szShell32Dll[] = "shell32.dll";
264 UINT cIcons, cIcons2;
266 if (!pPrivateExtractIconsA) return;
268 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, NULL, NULL, 0, 0);
269 cIcons2 = pPrivateExtractIconsA(szShell32Dll, 4, MAKELONG(32,16), MAKELONG(32,16),
271 ok((cIcons == cIcons2) && (cIcons > 0),
272 "Icon count should be independent of requested icon sizes and base icon index! "
273 "(cIcons=%d, cIcons2=%d)\n", cIcons, cIcons2);
275 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, ahIcon, aIconId, 0, 0);
276 ok(cIcons == 0, "Zero icons requested, got cIcons=%d\n", cIcons);
278 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, 16, 16, ahIcon, aIconId, 3, 0);
279 ok(cIcons == 3, "Three icons requested got cIcons=%d\n", cIcons);
281 cIcons = pPrivateExtractIconsA(szShell32Dll, 0, MAKELONG(32,16), MAKELONG(32,16),
282 ahIcon, aIconId, 3, 0);
283 ok(cIcons == 4, "Three icons requested, four expected, got cIcons=%d\n", cIcons);
288 init_function_pointers();
292 test_PrivateExtractIcons();