Changed the GDI driver interface to pass an opaque PHYSDEV pointer
[wine] / dlls / kernel / tests / atom.pl
1 ################################################################
2 # Tests for atom API calls
3 #
4 # Copyright 2001 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 use wine;
22 use winerror;
23
24 ################################################################
25 # Declarations for functions we use in this script
26
27 wine::declare( "kernel32",
28                GlobalAddAtomA     => ["word", ["str"]],
29                GlobalAddAtomW     => ["word", ["wstr"]],
30                GlobalFindAtomA    => ["word", ["str"]],
31                GlobalFindAtomW    => ["word", ["wstr"]],
32                GlobalDeleteAtom   => ["word", ["word"]],
33                GlobalGetAtomNameA => ["int",  ["word","ptr","int"]],
34                GlobalGetAtomNameW => ["int",  ["word","ptr","int"]],
35 );
36
37 my $name = "foobar";
38
39 ################################################################
40 # GlobalAddAtom/GlobalFindAtom
41
42 # Add an atom
43 my $atom = GlobalAddAtomA( $name );
44 ok( ($atom >= 0xc000) && ($atom <= 0xffff) && !defined($wine::err) );
45
46 # Verify that it can be found (or not) appropriately
47 ok( GlobalFindAtomA($name) == $atom );
48 ok( GlobalFindAtomA(uc $name) == $atom );
49 ok( !GlobalFindAtomA( "_" . $name ) );
50
51 # Add the same atom, specifying string as unicode; should
52 # find the first one, not add a new one
53 my $w_atom = GlobalAddAtomW( wc($name) );
54 ok( $w_atom == $atom && !defined($wine::err) );
55
56 # Verify that it can be found (or not) appropriately via
57 # unicode name
58 ok( GlobalFindAtomW( wc($name)) == $atom );
59 ok( GlobalFindAtomW( wc(uc($name)) ) == $atom );
60 ok( !GlobalFindAtomW( wc("_" . $name) ) );
61
62 # Test integer atoms
63 #
64 # (0x0000 .. 0xbfff) should be valid;
65 # (0xc000 .. 0xffff) should be invalid
66
67 # test limits
68 todo_wine
69 {
70     ok( GlobalAddAtomA(0) == 0 && !defined($wine::err) );
71     ok( GlobalAddAtomW(0) == 0 && !defined($wine::err) );
72 };
73 ok( GlobalAddAtomA(1) == 1 && !defined($wine::err) );
74 ok( GlobalAddAtomW(1) == 1 && !defined($wine::err) );
75 ok( GlobalAddAtomA(0xbfff) == 0xbfff && !defined($wine::err) );
76 ok( GlobalAddAtomW(0xbfff) == 0xbfff && !defined($wine::err) );
77 ok( !GlobalAddAtomA(0xc000) && ($wine::err == ERROR_INVALID_PARAMETER) );
78 ok( !GlobalAddAtomW(0xc000) && ($wine::err == ERROR_INVALID_PARAMETER) );
79 ok( !GlobalAddAtomA(0xffff) && ($wine::err == ERROR_INVALID_PARAMETER) );
80 ok( !GlobalAddAtomW(0xffff) && ($wine::err == ERROR_INVALID_PARAMETER) );
81
82 # test some in between
83 for ($i = 0x0001; ($i <= 0xbfff); $i += 27)
84 {
85     ok( GlobalAddAtomA($i) && !defined($wine::err) );
86     ok( GlobalAddAtomW($i) && !defined($wine::err) );
87 }
88 for ($i = 0xc000; ($i <= 0xffff); $i += 29)
89 {
90     ok( !GlobalAddAtomA($i) && ($wine::err == ERROR_INVALID_PARAMETER) );
91     ok( !GlobalAddAtomW($i) && ($wine::err == ERROR_INVALID_PARAMETER) );
92 }
93
94
95 ################################################################
96 # GlobalGetAtomName
97
98 # Get the name of the atom we added above
99 my $buf = "." x 20;
100 my $len = GlobalGetAtomNameA( $atom, \$buf, length ($buf) );
101 ok( $len == length ($name) );
102 ok( $buf eq ($name . "\x00" . ("." x (length ($buf) - length ($name) - 1))) );
103 $buf = "." x 20;
104 ok( !GlobalGetAtomNameA( $atom, \$buf, 3 ) );
105
106 # Repeat, unicode-style
107 $buf = wc("." x 20);
108 $len = GlobalGetAtomNameW( $atom, \$buf, length ($buf) / 2 );
109 ok( $len == wclen (wc ($name)) );
110 todo_wine
111 {
112     ok( $buf eq (wc ($name) . "\x00\x00" . ("." x (20 - 2 * (wclen (wc ($name)) + 1) ))) );
113 };
114 $buf = wc("." x 20);
115 ok( !GlobalGetAtomNameW( $atom, \$buf, 3 ) );
116
117 # Check error code returns
118 ok( !GlobalGetAtomNameA( $atom, $buf,  0 ) && $wine::err == ERROR_MORE_DATA );
119 ok( !GlobalGetAtomNameA( $atom, $buf, -1 ) && $wine::err == ERROR_MORE_DATA );
120 ok( !GlobalGetAtomNameW( $atom, $buf,  0 ) && $wine::err == ERROR_MORE_DATA );
121 ok( !GlobalGetAtomNameW( $atom, $buf, -1 ) && $wine::err == ERROR_MORE_DATA );
122
123 # Test integer atoms
124 $buf = "a" x 10;
125 for ($i = 0; ($i <= 0xbfff); $i += 37)
126 {
127     $len = GlobalGetAtomNameA( $i, \$buf, length ($buf) );
128     if ($i)
129     {
130         ok( ($len > 1) && ($len < 7) );
131         ok( $buf eq ("#$i\x00" . "a" x (10 - $len - 1) ));
132     }
133     else
134     {
135         todo_wine
136         {
137             ok( ($len > 1) && ($len < 7) );
138             ok( $buf eq ("#$i\x00" . "a" x (10 - $len - 1) ));
139         };
140     }
141 }
142
143 ################################################################
144 # GlobalDeleteAtom
145
146 $name = "barkbar";
147 $n = 5;
148
149 # First make sure it doesn't exist
150 $atom = GlobalAddAtomA( $name );
151 while (!GlobalDeleteAtom( $atom )) { }
152
153 # Now add it a number of times
154 for (1 .. $n) { $atom = GlobalAddAtomA( $name ); }
155
156 # Make sure it's here
157 ok( GlobalFindAtomA( $name ));
158 ok( GlobalFindAtomW( wc($name) ));
159
160 # That many deletions should succeed
161 for (1 .. $n) { ok( !GlobalDeleteAtom( $atom ) ); }
162
163 # It should be gone now
164 ok( !GlobalFindAtomA($name) );
165 ok( !GlobalFindAtomW( wc($name) ));
166
167 # So this one should fail
168 ok( GlobalDeleteAtom( $atom ) == $atom && $wine::err == ERROR_INVALID_HANDLE );
169
170
171 ################################################################
172 # Test error handling
173
174 # ASCII
175 ok( ($atom = GlobalAddAtomA("a" x 255)) );
176 ok( !GlobalDeleteAtom($atom) );
177 ok( !GlobalAddAtomA( "a" x 256 ) && $wine::err == ERROR_INVALID_PARAMETER );
178 ok( !GlobalFindAtomA( "b" x 256 ) && $wine::err == ERROR_INVALID_PARAMETER );
179
180 # Unicode
181 ok( ($atom = GlobalAddAtomW( wc("a" x 255) )) );
182 ok( !GlobalDeleteAtom($atom) );
183 ok( !GlobalAddAtomW( wc("a" x 256) ) && $wine::err == ERROR_INVALID_PARAMETER );
184 ok( !GlobalFindAtomW( wc("b" x 256) ) && $wine::err == ERROR_INVALID_PARAMETER );