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
23 #include "wine/test.h"
27 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
28 static const WCHAR FOOBARW[] = {'F','O','O','B','A','R',0};
29 static const WCHAR _foobarW[] = {'_','f','o','o','b','a','r',0};
31 static BOOL unicode_OS;
33 static void test_add_atom(void)
38 SetLastError( 0xdeadbeef );
39 atom = GlobalAddAtomA( "foobar" );
40 ok( (atom >= 0xc000) && (atom <= 0xffff), "bad atom id %x", atom );
41 ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomA set last error" );
43 /* Verify that it can be found (or not) appropriately */
44 ok( GlobalFindAtomA( "foobar" ) == atom, "could not find atom foobar" );
45 ok( GlobalFindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR" );
46 ok( !GlobalFindAtomA( "_foobar" ), "found _foobar" );
48 /* Add the same atom, specifying string as unicode; should
49 * find the first one, not add a new one */
50 SetLastError( 0xdeadbeef );
51 w_atom = GlobalAddAtomW( foobarW );
52 if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
55 trace("WARNING: Unicode atom APIs are not supported on this platform\n");
59 ok( w_atom == atom, "Unicode atom does not match ASCII" );
60 ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomW set last error" );
63 /* Verify that it can be found (or not) appropriately via unicode name */
66 ok( GlobalFindAtomW( foobarW ) == atom, "could not find atom foobar" );
67 ok( GlobalFindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR" );
68 ok( !GlobalFindAtomW( _foobarW ), "found _foobar" );
72 * (0x0001 .. 0xbfff) should be valid;
73 * (0xc000 .. 0xffff) should be invalid */
75 SetLastError( 0xdeadbeef );
76 ok( GlobalAddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0" );
79 SetLastError( 0xdeadbeef );
80 ok( GlobalAddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0" );
83 SetLastError( 0xdeadbeef );
84 for (i = 1; i <= 0xbfff; i++)
86 SetLastError( 0xdeadbeef );
87 ok( GlobalAddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
88 "failed to add atom %x", i );
91 SetLastError( 0xdeadbeef );
92 ok( GlobalAddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
93 "failed to add atom %x", i );
97 for (i = 0xc000; i <= 0xffff; i++)
99 ok( !GlobalAddAtomA((LPCSTR)i), "succeeded adding %x", i );
101 ok( !GlobalAddAtomW((LPCWSTR)i), "succeeded adding %x", i );
105 static void test_get_atom_name(void)
111 static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
113 ATOM atom = GlobalAddAtomA( "foobar" );
115 /* Get the name of the atom we added above */
116 memset( buf, '.', sizeof(buf) );
117 len = GlobalGetAtomNameA( atom, buf, 10 );
118 ok( len == strlen("foobar"), "bad length %d", len );
119 ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents" );
121 /* Repeat, unicode-style */
124 for (i = 0; i < 10; i++) bufW[i] = '.';
125 SetLastError( 0xdeadbeef );
126 len = GlobalGetAtomNameW( atom, bufW, 10 );
127 ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed" );
128 ok( len == lstrlenW(foobarW), "bad length %d", len );
129 ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents" );
132 /* Check error code returns */
133 memset(buf, '.', 10);
134 ok( !GlobalGetAtomNameA( atom, buf, 0 ), "succeeded" );
135 ok( !memcmp( buf, "..........", 10 ), "should not touch buffer" );
139 static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
141 for (i = 0; i < 10; i++) bufW[i] = '.';
142 ok( !GlobalGetAtomNameW( atom, bufW, 0 ), "succeeded" );
143 ok( !memcmp( bufW, sampleW, 10 * sizeof(WCHAR) ), "should not touch buffer" );
146 /* Test integer atoms */
147 for (i = 0; i <= 0xbfff; i++)
149 memset( buf, 'a', 10 );
150 len = GlobalGetAtomNameA( (ATOM)i, buf, 10 );
154 ok( (len > 1) && (len < 7), "bad length %d", len );
155 sprintf( res, "#%d", i );
156 memset( res + strlen(res) + 1, 'a', 10 );
157 ok( !memcmp( res, buf, 10 ), "bad buffer contents %s", buf );
160 ok( !len, "bad length %d", len );
164 static void test_error_handling(void)
170 memset( buffer, 'a', 256 );
172 ok( !GlobalAddAtomA(buffer), "add succeeded" );
173 ok( !GlobalFindAtomA(buffer), "find succeeded" );
177 for (i = 0; i < 256; i++) bufferW[i] = 'b';
179 ok( !GlobalAddAtomW(bufferW), "add succeeded" );
180 ok( !GlobalFindAtomW(bufferW), "find succeeded" );
187 test_get_atom_name();
188 test_error_handling();