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" );
189 test_get_atom_name();
190 test_error_handling();