1 /*
2 * Unit tests for atom functions
3 *
4 * Copyright (c) 2002 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winuser.h"
29
30 #define DOUBLE(x) (WCHAR)((x<<8)|(x))
31
32 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
33 static const WCHAR FOOBARW[] = {'F','O','O','B','A','R',0};
34 static const WCHAR _foobarW[] = {'_','f','o','o','b','a','r',0};
35
36 static void do_initA(char* tmp, const char* pattern, int len)
37 {
38 const char* p = pattern;
39
40 while (len--)
41 {
42 *tmp++ = *p++;
43 if (!*p) p = pattern;
44 }
45 *tmp = '\0';
46 }
47
48 static void do_initW(WCHAR* tmp, const char* pattern, int len)
49 {
50 const char* p = pattern;
51
52 while (len--)
53 {
54 *tmp++ = *p++;
55 if (!*p) p = pattern;
56 }
57 *tmp = '\0';
58 }
59
60 static void print_integral( WCHAR* buffer, int atom )
61 {
62 BOOL first = TRUE;
63
64 #define X(v) { if (atom >= v) {*buffer++ = '' + atom / v; first = FALSE; } else if (!first || v == 1) *buffer++ = ''; atom %= v; }
65 *buffer++ = '#';
66 X(10000);
67 X(1000);
68 X(100);
69 X(10);
70 X(1);
71 *buffer = '\0';
72 #undef X
73 }
74
75 static BOOL unicode_OS;
76
77 static void test_add_atom(void)
78 {
79 ATOM atom, w_atom;
80 int i;
81
82 SetLastError( 0xdeadbeef );
83 atom = GlobalAddAtomA( "foobar" );
84 ok( atom >= 0xc000, "bad atom id %x\n", atom );
85 ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomA set last error\n" );
86
87 /* Verify that it can be found (or not) appropriately */
88 ok( GlobalFindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
89 ok( GlobalFindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
90 ok( !GlobalFindAtomA( "_foobar" ), "found _foobar\n" );
91
92 /* Add the same atom, specifying string as unicode; should
93 * find the first one, not add a new one */
94 SetLastError( 0xdeadbeef );
95 w_atom = GlobalAddAtomW( foobarW );
96 if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
97 unicode_OS = TRUE;
98 else
99 trace("WARNING: Unicode atom APIs are not supported on this platform\n");
100
101 if (unicode_OS)
102 {
103 ok( w_atom == atom, "Unicode atom does not match ASCII\n" );
104 ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomW set last error\n" );
105 }
106
107 /* Verify that it can be found (or not) appropriately via unicode name */
108 if (unicode_OS)
109 {
110 ok( GlobalFindAtomW( foobarW ) == atom, "could not find atom foobar\n" );
111 ok( GlobalFindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" );
112 ok( !GlobalFindAtomW( _foobarW ), "found _foobar\n" );
113 }
114
115 /* Test integer atoms
116 * (0x0001 .. 0xbfff) should be valid;
117 * (0xc000 .. 0xffff) should be invalid */
118
119 SetLastError( 0xdeadbeef );
120 ok( GlobalAddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
121 if (unicode_OS)
122 {
123 SetLastError( 0xdeadbeef );
124 ok( GlobalAddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
125 }
126
127 SetLastError( 0xdeadbeef );
128 for (i = 1; i <= 0xbfff; i++)
129 {
130 SetLastError( 0xdeadbeef );
131 ok( GlobalAddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
132 "failed to add atom %x\n", i );
133 if (unicode_OS)
134 {
135 SetLastError( 0xdeadbeef );
136 ok( GlobalAddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
137 "failed to add atom %x\n", i );
138 }
139 }
140
141 for (i = 0xc000; i <= 0xffff; i++)
142 {
143 ok( !GlobalAddAtomA((LPCSTR)i), "succeeded adding %x\n", i );
144 if (unicode_OS)
145 ok( !GlobalAddAtomW((LPCWSTR)i), "succeeded adding %x\n", i );
146 }
147 }
148
149 static void test_get_atom_name(void)
150 {
151 char buf[10];
152 WCHAR bufW[10];
153 int i;
154 UINT len;
155 static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
156 char in[257], out[257];
157 WCHAR inW[257], outW[257];
158
159 ATOM atom = GlobalAddAtomA( "foobar" );
160
161 /* Get the name of the atom we added above */
162 memset( buf, '.', sizeof(buf) );
163 len = GlobalGetAtomNameA( atom, buf, 10 );
164 ok( len == strlen("foobar"), "bad length %d\n", len );
165 ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents\n" );
166
167 /* Repeat, unicode-style */
168 if (unicode_OS)
169 {
170 for (i = 0; i < 10; i++) bufW[i] = '.';
171 SetLastError( 0xdeadbeef );
172 len = GlobalGetAtomNameW( atom, bufW, 10 );
173 ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
174 ok( len == lstrlenW(foobarW), "bad length %d\n", len );
175 ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
176 }
177
178 /* Check error code returns */
179 memset(buf, '.', 10);
180 ok( !GlobalGetAtomNameA( atom, buf, 0 ), "succeeded\n" );
181 ok( !memcmp( buf, "..........", 10 ), "should not touch buffer\n" );
182
183 if (unicode_OS)
184 {
185 static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
186
187 for (i = 0; i < 10; i++) bufW[i] = '.';
188 ok( !GlobalGetAtomNameW( atom, bufW, 0 ), "succeeded\n" );
189 ok( !memcmp( bufW, sampleW, 10 * sizeof(WCHAR) ), "should not touch buffer\n" );
190 }
191
192 /* Test integer atoms */
193 for (i = 0; i <= 0xbfff; i++)
194 {
195 memset( buf, 'a', 10 );
196 len = GlobalGetAtomNameA( (ATOM)i, buf, 10 );
197 if (i)
198 {
199 char res[20];
200 ok( (len > 1) && (len < 7), "bad length %d\n", len );
201 sprintf( res, "#%d", i );
202 memset( res + strlen(res) + 1, 'a', 10 );
203 ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
204 }
205 else
206 ok( !len, "bad length %d\n", len );
207
208 SetLastError(0xdeadbeef);
209 len = GlobalGetAtomNameA( (ATOM)i, buf, 2);
210 if (!len) /* the NT way */
211 {
212 ok(GetLastError() == (i ? ERROR_MORE_DATA : ERROR_INVALID_PARAMETER) ||
213 GetLastError() == 0xdeadbeef, /* the Win 9x way */
214 "wrong error conditions %u for %u\n", GetLastError(), i);
215 }
216 else /* the Win 9x way */
217 {
218 ok(GetLastError() == 0xdeadbeef,
219 "wrong error conditions %u for %u\n", GetLastError(), i);
220 }
221 }
222
223 memset( buf, '.', sizeof(buf) );
224 len = GlobalGetAtomNameA( atom, buf, 6 );
225 ok( len == 0 ||
226 len == 5, /* win9x */
227 "bad length %d\n", len );
228 ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n");
229 if (unicode_OS)
230 {
231 static const WCHAR resW[] = {'f','o','o','b','a','r','.','.','.','.'};
232 for (len = 0; len < 10; len++) bufW[len] = '.';
233 SetLastError(0xdeadbeef);
234 len = GlobalGetAtomNameW( atom, bufW, 6 );
235 ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
236 ok( len == lstrlenW(foobarW), "bad length %d\n", len );
237 ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
238 }
239
240 /* test string limits & overflow */
241 do_initA(in, "abcdefghij", 255);
242 atom = GlobalAddAtomA(in);
243 ok(atom, "couldn't add atom for %s\n", in);
244 len = GlobalGetAtomNameA(atom, out, sizeof(out));
245 ok(len == 255, "length mismatch (%u instead of 255)\n", len);
246 for (i = 0; i < 255; i++)
247 {
248 ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
249 }
250 ok(out[255] == '\0', "wrong end of string\n");
251 memset(out, '.', sizeof(out));
252 SetLastError(0xdeadbeef);
253 len = GlobalGetAtomNameA(atom, out, 10);
254 if (!len) /* the NT way */
255 {
256 ok(GetLastError() == ERROR_MORE_DATA, "wrong error code (%u instead of %u)\n", GetLastError(), ERROR_MORE_DATA);
257 }
258 else /* the Win9x way */
259 {
260 ok(GetLastError() == 0xdeadbeef, "wrong error code (%u instead of %u)\n", GetLastError(), 0xdeadbeef);
261 }
262 for (i = 0; i < 9; i++)
263 {
264 ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
265 }
266 ok(out[9] == '\0', "wrong end of string\n");
267 ok(out[10] == '.', "wrote after end of buf\n");
268 do_initA(in, "abcdefghij", 256);
269 atom = GlobalAddAtomA(in);
270 ok(!atom, "succeeded\n");
271 if (unicode_OS)
272 {
273 /* test integral atoms */
274 for (i = 0; i <= 0xbfff; i++)
275 {
276 memset(outW, 'a', sizeof(outW));
277 len = GlobalGetAtomNameW( (ATOM)i, outW, 10 );
278 if (i)
279 {
280 WCHAR res[20];
281
282 ok( (len > 1) && (len < 7), "bad length %d\n", len );
283 print_integral( res, i );
284 memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
285 ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
286 }
287 else
288 ok( !len, "bad length %d\n", len );
289
290 memset(outW, '.', sizeof(outW));
291 SetLastError(0xdeadbeef);
292 len = GlobalGetAtomNameW( (ATOM)i, outW, 1);
293 if (i)
294 {
295 /* len == 0 with ERROR_MORE_DATA is on NT3.51 */
296 ok(len == 1 || (len == 0 && GetLastError() == ERROR_MORE_DATA),
297 "0x%04x: got %u with %d (excepted '1' or '' with "
298 "ERROR_MORE_DATA)\n", i, len, GetLastError());
299 ok(outW[1] == DOUBLE('.'), "buffer overwrite\n");
300 }
301 else ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "0 badly handled\n");
302 }
303
304 do_initW(inW, "abcdefghij", 255);
305 atom = GlobalAddAtomW(inW);
306 ok(atom, "couldn't add atom for %s\n", in);
307 len = GlobalGetAtomNameW(atom, outW, sizeof(outW)/sizeof(outW[0]));
308 ok(len == 255, "length mismatch (%u instead of 255)\n", len);
309 for (i = 0; i < 255; i++)
310 {
311 ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
312 }
313 ok(outW[255] == '\0', "wrong end of string\n");
314 memset(outW, '.', sizeof(outW));
315 len = GlobalGetAtomNameW(atom, outW, 10);
316 ok(len == 10, "succeeded\n");
317 for (i = 0; i < 10; i++)
318 {
319 ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
320 }
321 ok(outW[10] == DOUBLE('.'), "wrote after end of buf\n");
322 do_initW(inW, "abcdefghij", 256);
323 atom = GlobalAddAtomW(inW);
324 ok(!atom, "succeeded\n");
325 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error code\n");
326 }
327 }
328
329 static void test_error_handling(void)
330 {
331 char buffer[260];
332 WCHAR bufferW[260];
333 int i;
334
335 memset( buffer, 'a', 256 );
336 buffer[256] = 0;
337 ok( !GlobalAddAtomA(buffer), "add succeeded\n" );
338 ok( !GlobalFindAtomA(buffer), "find succeeded\n" );
339
340 if (unicode_OS)
341 {
342 for (i = 0; i < 256; i++) bufferW[i] = 'b';
343 bufferW[256] = 0;
344 ok( !GlobalAddAtomW(bufferW), "add succeeded\n" );
345 ok( !GlobalFindAtomW(bufferW), "find succeeded\n" );
346 }
347 }
348
349 static void test_local_add_atom(void)
350 {
351 ATOM atom, w_atom;
352 int i;
353
354 SetLastError( 0xdeadbeef );
355 atom = AddAtomA( "foobar" );
356 ok( atom >= 0xc000, "bad atom id %x\n", atom );
357 ok( GetLastError() == 0xdeadbeef, "AddAtomA set last error\n" );
358
359 /* Verify that it can be found (or not) appropriately */
360 ok( FindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
361 ok( FindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
362 ok( !FindAtomA( "_foobar" ), "found _foobar\n" );
363
364 /* Add the same atom, specifying string as unicode; should
365 * find the first one, not add a new one */
366 SetLastError( 0xdeadbeef );
367 w_atom = AddAtomW( foobarW );
368 if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
369 unicode_OS = TRUE;
370 else
371 trace("WARNING: Unicode atom APIs are not supported on this platform\n");
372
373 if (unicode_OS)
374 {
375 ok( w_atom == atom, "Unicode atom does not match ASCII\n" );
376 ok( GetLastError() == 0xdeadbeef, "AddAtomW set last error\n" );
377 }
378
379 /* Verify that it can be found (or not) appropriately via unicode name */
380 if (unicode_OS)
381 {
382 ok( FindAtomW( foobarW ) == atom, "could not find atom foobar\n" );
383 ok( FindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" );
384 ok( !FindAtomW( _foobarW ), "found _foobar\n" );
385 }
386
387 /* Test integer atoms
388 * (0x0001 .. 0xbfff) should be valid;
389 * (0xc000 .. 0xffff) should be invalid */
390
391 SetLastError( 0xdeadbeef );
392 ok( AddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
393 if (unicode_OS)
394 {
395 SetLastError( 0xdeadbeef );
396 ok( AddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
397 }
398
399 SetLastError( 0xdeadbeef );
400 for (i = 1; i <= 0xbfff; i++)
401 {
402 SetLastError( 0xdeadbeef );
403 ok( AddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
404 "failed to add atom %x\n", i );
405 if (unicode_OS)
406 {
407 SetLastError( 0xdeadbeef );
408 ok( AddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
409 "failed to add atom %x\n", i );
410 }
411 }
412
413 for (i = 0xc000; i <= 0xffff; i++)
414 {
415 ok( !AddAtomA((LPCSTR)i), "succeeded adding %x\n", i );
416 if (unicode_OS)
417 ok( !AddAtomW((LPCWSTR)i), "succeeded adding %x\n", i );
418 }
419 }
420
421 static void test_local_get_atom_name(void)
422 {
423 char buf[10], in[257], out[257];
424 WCHAR bufW[10], inW[257], outW[257];
425 int i;
426 UINT len;
427 static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
428
429 ATOM atom = AddAtomA( "foobar" );
430
431 /* Get the name of the atom we added above */
432 memset( buf, '.', sizeof(buf) );
433 len = GetAtomNameA( atom, buf, 10 );
434 ok( len == strlen("foobar"), "bad length %d\n", len );
435 ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents\n" );
436
437 /* Repeat, unicode-style */
438 if (unicode_OS)
439 {
440 for (i = 0; i < 10; i++) bufW[i] = '.';
441 SetLastError( 0xdeadbeef );
442 len = GetAtomNameW( atom, bufW, 10 );
443 ok( len && GetLastError() == 0xdeadbeef, "GetAtomNameW failed\n" );
444 ok( len == lstrlenW(foobarW), "bad length %d\n", len );
445 ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
446 }
447
448 /* Get the name of the atom we added above */
449 memset( buf, '.', sizeof(buf) );
450 len = GetAtomNameA( atom, buf, 6 );
451 ok( len == 5, "bad length %d\n", len );
452 ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n" );
453
454 /* Repeat, unicode-style */
455 if (unicode_OS)
456 {
457 WCHAR resW[] = {'f','o','o','b','a','\0','.','.','.','.'};
458 for (i = 0; i < 10; i++) bufW[i] = '.';
459 SetLastError( 0xdeadbeef );
460 len = GetAtomNameW( atom, bufW, 6 );
461 ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
462 ok( len == 5, "bad length %d\n", len );
463 ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
464 }
465
466 /* Check error code returns */
467 memset(buf, '.', 10);
468 ok( !GetAtomNameA( atom, buf, 0 ), "succeeded\n" );
469 ok( !memcmp( buf, "..........", 10 ), "should not touch buffer\n" );
470
471 if (unicode_OS)
472 {
473 static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
474
475 for (i = 0; i < 10; i++) bufW[i] = '.';
476 ok( !GetAtomNameW( atom, bufW, 0 ), "succeeded\n" );
477 ok( !memcmp( bufW, sampleW, 10 * sizeof(WCHAR) ), "should not touch buffer\n" );
478 }
479
480 /* Test integer atoms */
481 for (i = 0; i <= 0xbfff; i++)
482 {
483 memset( buf, 'a', 10 );
484 len = GetAtomNameA( (ATOM)i, buf, 10 );
485 if (i)
486 {
487 char res[20];
488 ok( (len > 1) && (len < 7), "bad length %d for %s\n", len, buf );
489 sprintf( res, "#%d", i );
490 memset( res + strlen(res) + 1, 'a', 10 );
491 ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
492 }
493 else
494 ok( !len, "bad length %d\n", len );
495
496 len = GetAtomNameA( (ATOM)i, buf, 1);
497 ok(!len, "succeed with %u for %u\n", len, i);
498
499 /* ERROR_MORE_DATA is on nt3.51 sp5 */
500 if (i)
501 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
502 GetLastError() == ERROR_MORE_DATA ||
503 GetLastError() == 0xdeadbeef, /* the Win 9x way */
504 "wrong error conditions %u for %u\n", GetLastError(), i);
505 else
506 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
507 GetLastError() == ERROR_MORE_DATA ||
508 GetLastError() == 0xdeadbeef, /* the Win 9x way */
509 "wrong error conditions %u for %u\n", GetLastError(), i);
510 }
511 /* test string limits & overflow */
512 do_initA(in, "abcdefghij", 255);
513 atom = AddAtomA(in);
514 ok(atom, "couldn't add atom for %s\n", in);
515 len = GetAtomNameA(atom, out, sizeof(out));
516 ok(len == 255, "length mismatch (%u instead of 255)\n", len);
517 for (i = 0; i < 255; i++)
518 {
519 ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
520 }
521 ok(out[255] == '\0', "wrong end of string\n");
522 memset(out, '.', sizeof(out));
523 len = GetAtomNameA(atom, out, 10);
524 ok(len == 9, "succeeded %d\n", len);
525 for (i = 0; i < 9; i++)
526 {
527 ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
528 }
529 ok(out[9] == '\0', "wrong end of string\n");
530 ok(out[10] == '.', "buffer overwrite\n");
531 do_initA(in, "abcdefghij", 256);
532 atom = AddAtomA(in);
533 ok(!atom, "succeeded\n");
534
535 /* ERROR_MORE_DATA is on nt3.51 sp5 */
536 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
537 GetLastError() == ERROR_MORE_DATA ||
538 GetLastError() == 0xdeadbeef, /* the Win 9x way */
539 "wrong error code (%u)\n", GetLastError());
540
541 if (unicode_OS)
542 {
543 /* test integral atoms */
544 for (i = 0; i <= 0xbfff; i++)
545 {
546 memset(outW, 'a', sizeof(outW));
547 len = GetAtomNameW( (ATOM)i, outW, 10 );
548 if (i)
549 {
550 WCHAR res[20];
551
552 ok( (len > 1) && (len < 7), "bad length %d\n", len );
553 print_integral( res, i );
554 memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
555 ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
556 }
557 else
558 ok( !len, "bad length %d\n", len );
559
560 len = GetAtomNameW( (ATOM)i, outW, 1);
561 ok(!len, "succeed with %u for %u\n", len, i);
562
563 /* ERROR_MORE_DATA is on nt3.51 sp5 */
564 ok(GetLastError() == ERROR_MORE_DATA ||
565 GetLastError() == (i ? ERROR_INSUFFICIENT_BUFFER : ERROR_INVALID_PARAMETER),
566 "wrong error conditions %u for %u\n", GetLastError(), i);
567 }
568 do_initW(inW, "abcdefghij", 255);
569 atom = AddAtomW(inW);
570 ok(atom, "couldn't add atom for %s\n", in);
571 len = GetAtomNameW(atom, outW, sizeof(outW)/sizeof(outW[0]));
572 ok(len == 255, "length mismatch (%u instead of 255)\n", len);
573 for (i = 0; i < 255; i++)
574 {
575 ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
576 }
577 ok(outW[255] == '\0', "wrong end of string\n");
578 memset(outW, '.', sizeof(outW));
579 len = GetAtomNameW(atom, outW, 10);
580 ok(len == 9, "succeeded %d\n", len);
581 for (i = 0; i < 9; i++)
582 {
583 ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
584 }
585 ok(outW[9] == '\0', "wrong end of string\n");
586 ok(outW[10] == DOUBLE('.'), "buffer overwrite\n");
587 do_initW(inW, "abcdefghij", 256);
588 atom = AddAtomW(inW);
589 ok(!atom, "succeeded\n");
590
591 /* ERROR_MORE_DATA is on nt3.51 sp5 */
592 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
593 GetLastError() == ERROR_MORE_DATA,
594 "wrong error code (%u)\n", GetLastError());
595 }
596 }
597
598 static void test_local_error_handling(void)
599 {
600 char buffer[260];
601 WCHAR bufferW[260];
602 int i;
603
604 memset( buffer, 'a', 256 );
605 buffer[256] = 0;
606 ok( !AddAtomA(buffer), "add succeeded\n" );
607 ok( !FindAtomA(buffer), "find succeeded\n" );
608
609 if (unicode_OS)
610 {
611 for (i = 0; i < 256; i++) bufferW[i] = 'b';
612 bufferW[256] = 0;
613 ok( !AddAtomW(bufferW), "add succeeded\n" );
614 ok( !FindAtomW(bufferW), "find succeeded\n" );
615 }
616 }
617
618 START_TEST(atom)
619 {
620 test_add_atom();
621 test_get_atom_name();
622 test_error_handling();
623 test_local_add_atom();
624 test_local_get_atom_name();
625 test_local_error_handling();
626 }
627
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.