2 * Unit tests for atom functions
4 * Copyright (c) 2002 Alexandre Julliard
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"
29 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
30 static const WCHAR FOOBARW[] = {'F','O','O','B','A','R',0};
31 static const WCHAR _foobarW[] = {'_','f','o','o','b','a','r',0};
33 static BOOL unicode_OS;
35 static void test_add_atom(void)
40 SetLastError( 0xdeadbeef );
41 atom = GlobalAddAtomA( "foobar" );
42 ok( atom >= 0xc000, "bad atom id %x\n", atom );
43 ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomA set last error\n" );
45 /* Verify that it can be found (or not) appropriately */
46 ok( GlobalFindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
47 ok( GlobalFindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
48 ok( !GlobalFindAtomA( "_foobar" ), "found _foobar\n" );
50 /* Add the same atom, specifying string as unicode; should
51 * find the first one, not add a new one */
52 SetLastError( 0xdeadbeef );
53 w_atom = GlobalAddAtomW( foobarW );
54 if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
57 trace("WARNING: Unicode atom APIs are not supported on this platform\n");
61 ok( w_atom == atom, "Unicode atom does not match ASCII\n" );
62 ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomW set last error\n" );
65 /* Verify that it can be found (or not) appropriately via unicode name */
68 ok( GlobalFindAtomW( foobarW ) == atom, "could not find atom foobar\n" );
69 ok( GlobalFindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" );
70 ok( !GlobalFindAtomW( _foobarW ), "found _foobar\n" );
74 * (0x0001 .. 0xbfff) should be valid;
75 * (0xc000 .. 0xffff) should be invalid */
77 SetLastError( 0xdeadbeef );
78 ok( GlobalAddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
81 SetLastError( 0xdeadbeef );
82 ok( GlobalAddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
85 SetLastError( 0xdeadbeef );
86 for (i = 1; i <= 0xbfff; i++)
88 SetLastError( 0xdeadbeef );
89 ok( GlobalAddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
90 "failed to add atom %x\n", i );
93 SetLastError( 0xdeadbeef );
94 ok( GlobalAddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
95 "failed to add atom %x\n", i );
99 for (i = 0xc000; i <= 0xffff; i++)
101 ok( !GlobalAddAtomA((LPCSTR)i), "succeeded adding %x\n", i );
103 ok( !GlobalAddAtomW((LPCWSTR)i), "succeeded adding %x\n", i );
107 static void test_get_atom_name(void)
113 static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
115 ATOM atom = GlobalAddAtomA( "foobar" );
117 /* Get the name of the atom we added above */
118 memset( buf, '.', sizeof(buf) );
119 len = GlobalGetAtomNameA( atom, buf, 10 );
120 ok( len == strlen("foobar"), "bad length %d\n", len );
121 ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents\n" );
123 /* Repeat, unicode-style */
126 for (i = 0; i < 10; i++) bufW[i] = '.';
127 SetLastError( 0xdeadbeef );
128 len = GlobalGetAtomNameW( atom, bufW, 10 );
129 ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
130 ok( len == lstrlenW(foobarW), "bad length %d\n", len );
131 ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
134 /* Check error code returns */
135 memset(buf, '.', 10);
136 ok( !GlobalGetAtomNameA( atom, buf, 0 ), "succeeded\n" );
137 ok( !memcmp( buf, "..........", 10 ), "should not touch buffer\n" );
141 static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
143 for (i = 0; i < 10; i++) bufW[i] = '.';
144 ok( !GlobalGetAtomNameW( atom, bufW, 0 ), "succeeded\n" );
145 ok( !memcmp( bufW, sampleW, 10 * sizeof(WCHAR) ), "should not touch buffer\n" );
148 /* Test integer atoms */
149 for (i = 0; i <= 0xbfff; i++)
151 memset( buf, 'a', 10 );
152 len = GlobalGetAtomNameA( (ATOM)i, buf, 10 );
156 ok( (len > 1) && (len < 7), "bad length %d\n", len );
157 sprintf( res, "#%d", i );
158 memset( res + strlen(res) + 1, 'a', 10 );
159 ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
162 ok( !len, "bad length %d\n", len );
166 static void test_error_handling(void)
172 memset( buffer, 'a', 256 );
174 ok( !GlobalAddAtomA(buffer), "add succeeded\n" );
175 ok( !GlobalFindAtomA(buffer), "find succeeded\n" );
179 for (i = 0; i < 256; i++) bufferW[i] = 'b';
181 ok( !GlobalAddAtomW(bufferW), "add succeeded\n" );
182 ok( !GlobalFindAtomW(bufferW), "find succeeded\n" );
186 static void test_local_add_atom(void)
191 SetLastError( 0xdeadbeef );
192 atom = AddAtomA( "foobar" );
193 ok( atom >= 0xc000, "bad atom id %x\n", atom );
194 ok( GetLastError() == 0xdeadbeef, "AddAtomA set last error\n" );
196 /* Verify that it can be found (or not) appropriately */
197 ok( FindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
198 ok( FindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
199 ok( !FindAtomA( "_foobar" ), "found _foobar\n" );
201 /* Add the same atom, specifying string as unicode; should
202 * find the first one, not add a new one */
203 SetLastError( 0xdeadbeef );
204 w_atom = AddAtomW( foobarW );
205 if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
208 trace("WARNING: Unicode atom APIs are not supported on this platform\n");
212 ok( w_atom == atom, "Unicode atom does not match ASCII\n" );
213 ok( GetLastError() == 0xdeadbeef, "AddAtomW set last error\n" );
216 /* Verify that it can be found (or not) appropriately via unicode name */
219 ok( FindAtomW( foobarW ) == atom, "could not find atom foobar\n" );
220 ok( FindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" );
221 ok( !FindAtomW( _foobarW ), "found _foobar\n" );
224 /* Test integer atoms
225 * (0x0001 .. 0xbfff) should be valid;
226 * (0xc000 .. 0xffff) should be invalid */
228 SetLastError( 0xdeadbeef );
229 ok( AddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
232 SetLastError( 0xdeadbeef );
233 ok( AddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
236 SetLastError( 0xdeadbeef );
237 for (i = 1; i <= 0xbfff; i++)
239 SetLastError( 0xdeadbeef );
240 ok( AddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
241 "failed to add atom %x\n", i );
244 SetLastError( 0xdeadbeef );
245 ok( AddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
246 "failed to add atom %x\n", i );
250 for (i = 0xc000; i <= 0xffff; i++)
252 ok( !AddAtomA((LPCSTR)i), "succeeded adding %x\n", i );
254 ok( !AddAtomW((LPCWSTR)i), "succeeded adding %x\n", i );
258 static void test_local_get_atom_name(void)
264 static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
266 ATOM atom = AddAtomA( "foobar" );
268 /* Get the name of the atom we added above */
269 memset( buf, '.', sizeof(buf) );
270 len = GetAtomNameA( atom, buf, 10 );
271 ok( len == strlen("foobar"), "bad length %d\n", len );
272 ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents\n" );
274 /* Repeat, unicode-style */
277 for (i = 0; i < 10; i++) bufW[i] = '.';
278 SetLastError( 0xdeadbeef );
279 len = GetAtomNameW( atom, bufW, 10 );
280 ok( len && GetLastError() == 0xdeadbeef, "GetAtomNameW failed\n" );
281 ok( len == lstrlenW(foobarW), "bad length %d\n", len );
282 ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
285 /* Check error code returns */
286 memset(buf, '.', 10);
287 ok( !GetAtomNameA( atom, buf, 0 ), "succeeded\n" );
288 ok( !memcmp( buf, "..........", 10 ), "should not touch buffer\n" );
292 static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
294 for (i = 0; i < 10; i++) bufW[i] = '.';
295 ok( !GetAtomNameW( atom, bufW, 0 ), "succeeded\n" );
296 ok( !memcmp( bufW, sampleW, 10 * sizeof(WCHAR) ), "should not touch buffer\n" );
299 /* Test integer atoms */
300 for (i = 0; i <= 0xbfff; i++)
302 memset( buf, 'a', 10 );
303 len = GetAtomNameA( (ATOM)i, buf, 10 );
307 ok( (len > 1) && (len < 7), "bad length %d\n", len );
308 sprintf( res, "#%d", i );
309 memset( res + strlen(res) + 1, 'a', 10 );
310 ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
313 ok( !len, "bad length %d\n", len );
317 static void test_local_error_handling(void)
323 memset( buffer, 'a', 256 );
325 ok( !AddAtomA(buffer), "add succeeded\n" );
326 ok( !FindAtomA(buffer), "find succeeded\n" );
330 for (i = 0; i < 256; i++) bufferW[i] = 'b';
332 ok( !AddAtomW(bufferW), "add succeeded\n" );
333 ok( !FindAtomW(bufferW), "find succeeded\n" );
341 test_get_atom_name();
342 test_error_handling();
343 test_local_add_atom();
344 test_local_get_atom_name();
345 test_local_error_handling();