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 void test_LoadStringA (void)
28 HINSTANCE hInst = GetModuleHandle (NULL);
29 static const char str[] = "String resource"; /* same in resource.rc */
35 struct string_test tests[] = {{sizeof buf, sizeof str - 1},
36 {sizeof str, sizeof str - 1},
37 {sizeof str - 1, sizeof str - 2}};
40 assert (sizeof str < sizeof buf);
41 for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
42 const int bufsiz = tests[i].bufsiz;
43 const int expected = tests[i].expected;
44 const int len = LoadStringA (hInst, 0, buf, bufsiz);
46 ok (len == expected, "bufsiz=%d: got %d, expected %d\n",
47 bufsiz, len, expected);
48 ok (!memcmp (buf, str, len),
49 "bufsiz=%d: got '%s', expected '%.*s'\n",
50 bufsiz, buf, len, str);
51 ok (buf[len] == 0, "bufsiz=%d: NUL termination missing\n",
56 static void test_accel1(void)
62 /* now create our own valid accelerator table */
66 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
70 ac[n++].fVirt = FNOINVERT;
76 hAccel = CreateAcceleratorTable( &ac[0], n );
77 ok( hAccel != NULL, "create accelerator table\n");
79 r = DestroyAcceleratorTable( hAccel );
80 ok( r, "destroy accelerator table\n");
82 /* now try create an invalid one */
86 ac[n++].fVirt = FVIRTKEY | FNOINVERT;
90 ac[n++].fVirt = (SHORT) 0xffff;
94 ac[n++].fVirt = (SHORT) 0xfff0;
98 ac[n++].fVirt = (SHORT) 0x0000;
102 ac[n++].fVirt = (SHORT) 0x0001;
104 hAccel = CreateAcceleratorTable( &ac[0], n );
105 ok( hAccel != NULL, "create accelerator table\n");
107 r = CopyAcceleratorTable( hAccel, NULL, 0 );
108 ok( r == n, "two entries in table\n");
110 r = CopyAcceleratorTable( hAccel, &ac[0], r );
111 ok( r == n, "still should be two entries in table\n");
114 ok( ac[n].cmd == 1000, "cmd 0 not preserved\n");
115 ok( ac[n].key == 'A', "key 0 not preserved\n");
116 ok( ac[n].fVirt == (FVIRTKEY | FNOINVERT), "fVirt 0 not preserved\n");
119 ok( ac[n].cmd == 0xffff, "cmd 1 not preserved\n");
120 ok( ac[n].key == 0xffff, "key 1 not preserved\n");
121 ok( ac[n].fVirt == 0x007f, "fVirt 1 not changed\n");
124 ok( ac[n].cmd == 0xfff0, "cmd 2 not preserved\n");
125 ok( ac[n].key == 0x00ff, "key 2 not preserved\n");
126 ok( ac[n].fVirt == 0x0070, "fVirt 2 not changed\n");
129 ok( ac[n].cmd == 0xfff0, "cmd 3 not preserved\n");
130 ok( ac[n].key == 0x00ff, "key 3 not preserved\n");
131 ok( ac[n].fVirt == 0x0000, "fVirt 3 not changed\n");
134 ok( ac[n].cmd == 0xfff0, "cmd 4 not preserved\n");
135 ok( ac[n].key == 0xffff, "key 4 not preserved\n");
136 ok( ac[n].fVirt == 0x0001, "fVirt 4 not changed\n");
138 r = DestroyAcceleratorTable( hAccel );
139 ok( r, "destroy accelerator table\n");
141 hAccel = CreateAcceleratorTable( &ac[0], 0 );
142 ok( !hAccel, "zero elements should fail\n");
144 /* these will on crash win2k
145 hAccel = CreateAcceleratorTable( NULL, 1 );
146 hAccel = CreateAcceleratorTable( &ac[0], -1 );
151 * memcmp on the tables works in Windows, but does not work in wine, as
152 * there is an extra undefined and unused byte between fVirt and the key
154 static void test_accel2(void)
169 * hac = CreateAcceleratorTable( NULL, 1 );
172 /* try a zero count */
173 hac = CreateAcceleratorTable( &ac[0], 0 );
174 ok( !hac , "fail\n");
175 ok( !DestroyAcceleratorTable( hac ), "destroy failed\n");
177 /* creating one accelerator should work */
178 hac = CreateAcceleratorTable( &ac[0], 1 );
179 ok( hac != NULL , "fail\n");
180 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy failed\n");
181 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
183 /* how about two of the same type? */
184 hac = CreateAcceleratorTable( &ac[0], 2);
185 ok( hac != NULL , "fail\n");
186 ok( 2 == CopyAcceleratorTable( hac, NULL, 100 ), "copy null failed\n");
187 ok( 2 == CopyAcceleratorTable( hac, NULL, 0 ), "copy null failed\n");
188 ok( 2 == CopyAcceleratorTable( hac, NULL, 1 ), "copy null failed\n");
189 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
190 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
191 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
192 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
194 /* how about two of the same type with a non-zero key? */
197 hac = CreateAcceleratorTable( &ac[0], 2);
198 ok( hac != NULL , "fail\n");
199 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
200 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
201 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
203 /* how about two of the same type with a non-zero virtual key? */
204 ac[0].fVirt = FVIRTKEY;
206 ac[1].fVirt = FVIRTKEY;
208 hac = CreateAcceleratorTable( &ac[0], 2);
209 ok( hac != NULL , "fail\n");
210 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
211 /* ok( !memcmp( ac, out, sizeof ac ), "tables different\n"); */
212 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
214 /* how virtual key codes */
215 ac[0].fVirt = FVIRTKEY;
216 hac = CreateAcceleratorTable( &ac[0], 1);
217 ok( hac != NULL , "fail\n");
218 ok( 1 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
219 /* ok( !memcmp( ac, out, sizeof ac/2 ), "tables different\n"); */
220 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
222 /* how turning on all bits? */
226 hac = CreateAcceleratorTable( &ac[0], 1);
227 ok( hac != NULL , "fail\n");
228 ok( 1 == CopyAcceleratorTable( hac, out, 1 ), "copy 1 failed\n");
229 /* ok( memcmp( ac, out, sizeof ac/2 ), "tables not different\n"); */
230 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
231 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
232 ok( out[0].key == ac[0].key, "key modified\n");
233 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");
235 /* how turning on all bits? */
236 memset( ac, 0xff, sizeof ac );
237 hac = CreateAcceleratorTable( &ac[0], 2);
238 ok( hac != NULL , "fail\n");
239 ok( 2 == CopyAcceleratorTable( hac, out, 2 ), "copy 2 failed\n");
240 /* ok( memcmp( ac, out, sizeof ac ), "tables not different\n"); */
241 ok( out[0].cmd == ac[0].cmd, "cmd modified\n");
242 ok( out[0].fVirt == (ac[0].fVirt&0x7f), "fVirt not modified\n");
243 ok( out[0].key == ac[0].key, "key modified\n");
244 ok( out[1].cmd == ac[1].cmd, "cmd modified\n");
245 ok( out[1].fVirt == (ac[1].fVirt&0x7f), "fVirt not modified\n");
246 ok( out[1].key == ac[1].key, "key modified\n");
247 ok( DestroyAcceleratorTable( hac ), "destroy failed\n");