2 * Unit tests for registry 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"
29 static HKEY hkey_main;
31 /* delete key and all its subkeys */
32 static DWORD delete_key( HKEY hkey )
37 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
40 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
42 ret = delete_key( tmp );
47 if (ret != ERROR_NO_MORE_ITEMS) return ret;
48 RegDeleteKeyA( hkey, NULL );
52 static void setup_main_key(void)
54 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
56 assert (!RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Wine\\Test", 0, NULL,
57 REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey_main, NULL ));
60 static void test_enum_value(void)
63 char value[20], data[20];
64 WCHAR valueW[20], dataW[20];
65 DWORD val_count, data_count, type;
66 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
67 static const WCHAR testW[] = {'T','e','s','t',0};
68 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
70 /* check NULL data with zero length */
71 res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, NULL, 0 );
72 if (GetVersion() & 0x80000000)
73 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
75 ok( !res, "RegSetValueExA returned %ld\n", res );
76 res = RegSetValueExA( hkey_main, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
77 ok( !res, "RegSetValueExA returned %ld\n", res );
78 res = RegSetValueExA( hkey_main, "Test", 0, REG_BINARY, NULL, 0 );
79 ok( !res, "RegSetValueExA returned %ld\n", res );
81 res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
82 ok( res == 0, "RegSetValueExA failed error %ld\n", res );
84 /* overflow both name and data */
88 strcpy( value, "xxxxxxxxxx" );
89 strcpy( data, "xxxxxxxxxx" );
90 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
91 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
92 ok( val_count == 2, "val_count set to %ld\n", val_count );
93 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
94 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
95 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
96 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
102 strcpy( value, "xxxxxxxxxx" );
103 strcpy( data, "xxxxxxxxxx" );
104 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
105 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
106 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
107 ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count );
108 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
109 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
111 /* v5.1.2600.0 (XP Home) does not touch value or data in this case */
112 ok( !strcmp( value, "Te" ), "value set to '%s' instead of 'Te'\n", value );
113 ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
116 /* overflow empty name */
120 strcpy( value, "xxxxxxxxxx" );
121 strcpy( data, "xxxxxxxxxx" );
122 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
123 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
124 ok( val_count == 0, "val_count set to %ld\n", val_count );
125 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
126 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
127 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
129 /* v5.1.2600.0 (XP Home) does not touch data in this case */
130 ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
137 strcpy( value, "xxxxxxxxxx" );
138 strcpy( data, "xxxxxxxxxx" );
139 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
140 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
141 ok( val_count == 20, "val_count set to %ld\n", val_count );
142 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
143 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
144 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
145 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
151 strcpy( value, "xxxxxxxxxx" );
152 strcpy( data, "xxxxxxxxxx" );
153 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
154 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
155 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
156 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
157 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
158 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
159 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
164 res = RegSetValueExW( hkey_main, testW, 0, REG_SZ, (BYTE *)foobarW, 7*sizeof(WCHAR) );
165 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
167 ok( res == 0, "RegSetValueExW failed error %ld\n", res );
169 /* overflow both name and data */
173 memcpy( valueW, xxxW, sizeof(xxxW) );
174 memcpy( dataW, xxxW, sizeof(xxxW) );
175 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
176 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
177 ok( val_count == 2, "val_count set to %ld\n", val_count );
178 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
179 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
180 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
181 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
187 memcpy( valueW, xxxW, sizeof(xxxW) );
188 memcpy( dataW, xxxW, sizeof(xxxW) );
189 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
190 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
191 ok( val_count == 3, "val_count set to %ld\n", val_count );
192 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
193 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
194 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
195 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
201 memcpy( valueW, xxxW, sizeof(xxxW) );
202 memcpy( dataW, xxxW, sizeof(xxxW) );
203 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
204 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
205 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
206 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
207 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
208 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
209 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
215 memcpy( valueW, xxxW, sizeof(xxxW) );
216 memcpy( dataW, xxxW, sizeof(xxxW) );
217 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
218 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
219 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
220 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
221 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
222 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
223 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
227 RegDeleteValueA( hkey_main, "Test" );
236 delete_key( hkey_main );