Added a few more Unicode digits from Unicode version 4.1.
[wine] / dlls / kernel / tests / atom.c
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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++ = '0' + atom / v; first = FALSE; } else if (!first || v == 1) *buffer++ = '0'; 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 %lu for %u\n", GetLastError(), i);
215         }
216         else /* the Win 9x way */
217         {
218             ok(GetLastError() == 0xdeadbeef,
219                "wrong error conditions %lu for %u\n", GetLastError(), i);
220         }
221     }
222
223     /* test string limits & overflow */
224     do_initA(in, "abcdefghij", 255);
225     atom = GlobalAddAtomA(in);
226     ok(atom, "couldn't add atom for %s\n", in);
227     len = GlobalGetAtomNameA(atom, out, sizeof(out));
228     ok(len == 255, "length mismatch (%u instead of 255)\n", len);
229     for (i = 0; i < 255; i++)
230     {
231         ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
232     }
233     ok(out[255] == '\0', "wrong end of string\n");
234     memset(out, '.', sizeof(out));
235     SetLastError(0xdeadbeef);
236     len = GlobalGetAtomNameA(atom, out, 10);
237     if (!len) /* the NT way */
238     {
239         ok(GetLastError() == ERROR_MORE_DATA, "wrong error code (%lu instead of %u)\n", GetLastError(), ERROR_MORE_DATA);
240     }
241     else /* the Win9x way */
242     {
243         ok(GetLastError() == 0xdeadbeef, "wrong error code (%lu instead of %u)\n", GetLastError(), 0xdeadbeef);
244     }
245     for (i = 0; i < 9; i++)
246     {
247         ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
248     }
249     ok(out[9] == '\0', "wrong end of string\n");
250     ok(out[10] == '.', "wrote after end of buf\n");
251     do_initA(in, "abcdefghij", 256);
252     atom = GlobalAddAtomA(in);
253     ok(!atom, "succeeded\n");
254     if (unicode_OS)
255     {
256         /* test integral atoms */
257         for (i = 0; i <= 0xbfff; i++)
258         {
259             memset(outW, 'a', sizeof(outW));
260             len = GlobalGetAtomNameW( (ATOM)i, outW, 10 );
261             if (i)
262             {
263                 WCHAR res[20];
264                 
265                 if (len < 7) /* FIXME: temporary before we fix it */
266                     ok( (len > 1) && (len < 7), "bad length %d\n", len );
267                 else
268                     todo_wine ok( (len > 1) && (len < 7), "bad length %d\n", len );
269                 print_integral( res, i );
270                 memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
271                 ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
272             }
273             else
274                 ok( !len, "bad length %d\n", len );
275
276             memset(outW, '.', sizeof(outW));
277             len = GlobalGetAtomNameW( (ATOM)i, outW, 1);
278             if (i)
279             {
280                 todo_wine ok(len == 1, "succeed (got %u instead of 1)\n", len);
281                 ok(outW[1] == DOUBLE('.'), "buffer overwrite\n");
282             }
283             else ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "0 badly handled\n");
284         }
285
286         do_initW(inW, "abcdefghij", 255);
287         atom = GlobalAddAtomW(inW);
288         ok(atom, "couldn't add atom for %s\n", in);
289         len = GlobalGetAtomNameW(atom, outW, sizeof(outW));
290         ok(len == 255, "length mismatch (%u instead of 255)\n", len);
291         for (i = 0; i < 255; i++)
292         {
293             ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
294         }
295         ok(outW[255] == '\0', "wrong end of string\n");
296         memset(outW, '.', sizeof(outW));
297         len = GlobalGetAtomNameW(atom, outW, 10);
298         todo_wine ok(len == 10, "succeeded\n");
299         for (i = 0; i < 10; i++)
300         {
301             if (i < 9) /* FIXME: temporary */
302                 ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
303             else
304                 todo_wine ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
305         }
306         ok(outW[10] == DOUBLE('.'), "wrote after end of buf\n");
307         do_initW(inW, "abcdefghij", 256);
308         atom = GlobalAddAtomW(inW);
309         ok(!atom, "succeeded\n");
310         ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error code\n");
311     }
312 }
313
314 static void test_error_handling(void)
315 {
316     char buffer[260];
317     WCHAR bufferW[260];
318     int i;
319
320     memset( buffer, 'a', 256 );
321     buffer[256] = 0;
322     ok( !GlobalAddAtomA(buffer), "add succeeded\n" );
323     ok( !GlobalFindAtomA(buffer), "find succeeded\n" );
324
325     if (unicode_OS)
326     {
327         for (i = 0; i < 256; i++) bufferW[i] = 'b';
328         bufferW[256] = 0;
329         ok( !GlobalAddAtomW(bufferW), "add succeeded\n" );
330         ok( !GlobalFindAtomW(bufferW), "find succeeded\n" );
331     }
332 }
333
334 static void test_local_add_atom(void)
335 {
336     ATOM atom, w_atom;
337     int i;
338
339     SetLastError( 0xdeadbeef );
340     atom = AddAtomA( "foobar" );
341     ok( atom >= 0xc000, "bad atom id %x\n", atom );
342     ok( GetLastError() == 0xdeadbeef, "AddAtomA set last error\n" );
343
344     /* Verify that it can be found (or not) appropriately */
345     ok( FindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
346     ok( FindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
347     ok( !FindAtomA( "_foobar" ), "found _foobar\n" );
348
349     /* Add the same atom, specifying string as unicode; should
350      * find the first one, not add a new one */
351     SetLastError( 0xdeadbeef );
352     w_atom = AddAtomW( foobarW );
353     if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
354         unicode_OS = TRUE;
355     else
356         trace("WARNING: Unicode atom APIs are not supported on this platform\n");
357
358     if (unicode_OS)
359     {
360         ok( w_atom == atom, "Unicode atom does not match ASCII\n" );
361         ok( GetLastError() == 0xdeadbeef, "AddAtomW set last error\n" );
362     }
363
364     /* Verify that it can be found (or not) appropriately via unicode name */
365     if (unicode_OS)
366     {
367         ok( FindAtomW( foobarW ) == atom, "could not find atom foobar\n" );
368         ok( FindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" );
369         ok( !FindAtomW( _foobarW ), "found _foobar\n" );
370     }
371
372     /* Test integer atoms
373      * (0x0001 .. 0xbfff) should be valid;
374      * (0xc000 .. 0xffff) should be invalid */
375
376     SetLastError( 0xdeadbeef );
377     ok( AddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
378     if (unicode_OS)
379     {
380         SetLastError( 0xdeadbeef );
381         ok( AddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
382     }
383
384     SetLastError( 0xdeadbeef );
385     for (i = 1; i <= 0xbfff; i++)
386     {
387         SetLastError( 0xdeadbeef );
388         ok( AddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
389             "failed to add atom %x\n", i );
390         if (unicode_OS)
391         {
392             SetLastError( 0xdeadbeef );
393             ok( AddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
394                 "failed to add atom %x\n", i );
395         }
396     }
397
398     for (i = 0xc000; i <= 0xffff; i++)
399     {
400         ok( !AddAtomA((LPCSTR)i), "succeeded adding %x\n", i );
401         if (unicode_OS)
402             ok( !AddAtomW((LPCWSTR)i), "succeeded adding %x\n", i );
403     }
404 }
405
406 static void test_local_get_atom_name(void)
407 {
408     char buf[10], in[257], out[257];
409     WCHAR bufW[10], inW[257], outW[257];
410     int i;
411     UINT len;
412     static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
413
414     ATOM atom = AddAtomA( "foobar" );
415
416     /* Get the name of the atom we added above */
417     memset( buf, '.', sizeof(buf) );
418     len = GetAtomNameA( atom, buf, 10 );
419     ok( len == strlen("foobar"), "bad length %d\n", len );
420     ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents\n" );
421
422     /* Repeat, unicode-style */
423     if (unicode_OS)
424     {
425         for (i = 0; i < 10; i++) bufW[i] = '.';
426         SetLastError( 0xdeadbeef );
427         len = GetAtomNameW( atom, bufW, 10 );
428         ok( len && GetLastError() == 0xdeadbeef, "GetAtomNameW failed\n" );
429         ok( len == lstrlenW(foobarW), "bad length %d\n", len );
430         ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
431     }
432
433     /* Check error code returns */
434     memset(buf, '.', 10);
435     ok( !GetAtomNameA( atom, buf,  0 ), "succeeded\n" );
436     ok( !memcmp( buf, "..........", 10 ), "should not touch buffer\n" );
437
438     if (unicode_OS)
439     {
440         static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
441
442         for (i = 0; i < 10; i++) bufW[i] = '.';
443         ok( !GetAtomNameW( atom, bufW, 0 ), "succeeded\n" );
444         ok( !memcmp( bufW, sampleW, 10 * sizeof(WCHAR) ), "should not touch buffer\n" );
445     }
446
447     /* Test integer atoms */
448     for (i = 0; i <= 0xbfff; i++)
449     {
450         memset( buf, 'a', 10 );
451         len = GetAtomNameA( (ATOM)i, buf, 10 );
452         if (i)
453         {
454             char res[20];
455             ok( (len > 1) && (len < 7), "bad length %d for %s\n", len, buf );
456             sprintf( res, "#%d", i );
457             memset( res + strlen(res) + 1, 'a', 10 );
458             ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
459         }
460         else
461             ok( !len, "bad length %d\n", len );
462
463         len = GetAtomNameA( (ATOM)i, buf, 1);
464         ok(!len, "succeed with %u for %u\n", len, i);
465
466         /* ERROR_MORE_DATA is on nt3.51 sp5 */
467         if (i)
468             ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
469                GetLastError() == ERROR_MORE_DATA ||
470                GetLastError() == 0xdeadbeef, /* the Win 9x way */
471                "wrong error conditions %lu for %u\n", GetLastError(), i);
472         else
473             ok(GetLastError() == ERROR_INVALID_PARAMETER ||
474                GetLastError() == ERROR_MORE_DATA ||
475                GetLastError() == 0xdeadbeef, /* the Win 9x way */
476                "wrong error conditions %lu for %u\n", GetLastError(), i);
477     }
478     /* test string limits & overflow */
479     do_initA(in, "abcdefghij", 255);
480     atom = AddAtomA(in);
481     ok(atom, "couldn't add atom for %s\n", in);
482     len = GetAtomNameA(atom, out, sizeof(out));
483     ok(len == 255, "length mismatch (%u instead of 255)\n", len);
484     for (i = 0; i < 255; i++)
485     {
486         ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
487     }
488     ok(out[255] == '\0', "wrong end of string\n");
489     memset(out, '.', sizeof(out));
490     len = GetAtomNameA(atom, out, 10);
491     todo_wine ok(len == 9, "succeeded %d\n", len);
492     for (i = 0; i < 9; i++)
493     {
494         ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
495     }
496     ok(out[9] == '\0', "wrong end of string\n");
497     ok(out[10] == '.', "buffer overwrite\n");
498     do_initA(in, "abcdefghij", 256);
499     atom = AddAtomA(in);
500     ok(!atom, "succeeded\n");
501
502     /* ERROR_MORE_DATA is on nt3.51 sp5 */
503     ok(GetLastError() == ERROR_INVALID_PARAMETER ||
504        GetLastError() == ERROR_MORE_DATA ||
505        GetLastError() == 0xdeadbeef, /* the Win 9x way */
506        "wrong error code (%lu)\n", GetLastError());
507
508     if (unicode_OS)
509     {
510         /* test integral atoms */
511         for (i = 0; i <= 0xbfff; i++)
512         {
513             memset(outW, 'a', sizeof(outW));
514             len = GetAtomNameW( (ATOM)i, outW, 10 );
515             if (i)
516             {
517                 WCHAR res[20];
518                 
519                 if (len < 7) /* FIXME: temporary before we fix it */
520                     ok( (len > 1) && (len < 7), "bad length %d\n", len );
521                 else
522                     todo_wine ok( (len > 1) && (len < 7), "bad length %d\n", len );
523                 print_integral( res, i );
524                 memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
525                 ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
526             }
527             else
528                 ok( !len, "bad length %d\n", len );
529
530             len = GetAtomNameW( (ATOM)i, outW, 1);
531             ok(!len, "succeed with %u for %u\n", len, i);
532
533             /* ERROR_MORE_DATA is on nt3.51 sp5 */
534             ok(GetLastError() == ERROR_MORE_DATA ||
535                GetLastError() == (i ? ERROR_INSUFFICIENT_BUFFER : ERROR_INVALID_PARAMETER),
536                "wrong error conditions %lu for %u\n", GetLastError(), i);
537         }
538         do_initW(inW, "abcdefghij", 255);
539         atom = AddAtomW(inW);
540         ok(atom, "couldn't add atom for %s\n", in);
541         len = GetAtomNameW(atom, outW, sizeof(outW));
542         ok(len == 255, "length mismatch (%u instead of 255)\n", len);
543         for (i = 0; i < 255; i++)
544         {
545             ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
546         }
547         ok(outW[255] == '\0', "wrong end of string\n");
548         memset(outW, '.', sizeof(outW));
549         len = GetAtomNameW(atom, outW, 10);
550         todo_wine ok(len == 9, "succeeded %d\n", len);
551         for (i = 0; i < 9; i++)
552         {
553             ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
554         }
555         ok(outW[9] == '\0', "wrong end of string\n");
556         ok(outW[10] == DOUBLE('.'), "buffer overwrite\n");
557         do_initW(inW, "abcdefghij", 256);
558         atom = AddAtomW(inW);
559         ok(!atom, "succeeded\n");
560
561         /* ERROR_MORE_DATA is on nt3.51 sp5 */
562         ok(GetLastError() == ERROR_INVALID_PARAMETER ||
563            GetLastError() == ERROR_MORE_DATA,
564            "wrong error code (%lu)\n", GetLastError());
565     }
566 }
567
568 static void test_local_error_handling(void)
569 {
570     char buffer[260];
571     WCHAR bufferW[260];
572     int i;
573
574     memset( buffer, 'a', 256 );
575     buffer[256] = 0;
576     ok( !AddAtomA(buffer), "add succeeded\n" );
577     ok( !FindAtomA(buffer), "find succeeded\n" );
578
579     if (unicode_OS)
580     {
581         for (i = 0; i < 256; i++) bufferW[i] = 'b';
582         bufferW[256] = 0;
583         ok( !AddAtomW(bufferW), "add succeeded\n" );
584         ok( !FindAtomW(bufferW), "find succeeded\n" );
585     }
586 }
587
588 START_TEST(atom)
589 {
590     test_add_atom();
591     test_get_atom_name();
592     test_error_handling();
593     test_local_add_atom();
594     test_local_get_atom_name();
595     test_local_error_handling();
596 }