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 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
32 static const char * sTestpath2 = "%FOO%\\subdir1";
34 /* delete key and all its subkeys */
35 static DWORD delete_key( HKEY hkey )
40 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
43 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
45 ret = delete_key( tmp );
50 if (ret != ERROR_NO_MORE_ITEMS) return ret;
51 RegDeleteKeyA( hkey, NULL );
55 static void setup_main_key(void)
57 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
59 assert (!RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Wine\\Test", 0, NULL,
60 REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey_main, NULL ));
63 static void create_test_entries(void)
65 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
66 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
68 ok(!RegSetValueExA(hkey_main,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1),
69 "RegSetValueExA failed\n");
70 ok(!RegSetValueExA(hkey_main,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1),
71 "RegSetValueExA failed\n");
72 ok(!RegSetValueExA(hkey_main,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)+1),
73 "RegSetValueExA failed\n");
76 static void test_enum_value(void)
79 char value[20], data[20];
80 WCHAR valueW[20], dataW[20];
81 DWORD val_count, data_count, type;
82 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
83 static const WCHAR testW[] = {'T','e','s','t',0};
84 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
86 /* check NULL data with zero length */
87 res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, NULL, 0 );
88 if (GetVersion() & 0x80000000)
89 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
91 ok( !res, "RegSetValueExA returned %ld\n", res );
92 res = RegSetValueExA( hkey_main, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
93 ok( !res, "RegSetValueExA returned %ld\n", res );
94 res = RegSetValueExA( hkey_main, "Test", 0, REG_BINARY, NULL, 0 );
95 ok( !res, "RegSetValueExA returned %ld\n", res );
97 res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
98 ok( res == 0, "RegSetValueExA failed error %ld\n", res );
100 /* overflow both name and data */
104 strcpy( value, "xxxxxxxxxx" );
105 strcpy( data, "xxxxxxxxxx" );
106 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
107 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
108 ok( val_count == 2, "val_count set to %ld\n", val_count );
109 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
110 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
111 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
112 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
118 strcpy( value, "xxxxxxxxxx" );
119 strcpy( data, "xxxxxxxxxx" );
120 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
121 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
122 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
123 ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count );
124 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
125 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
127 /* v5.1.2600.0 (XP Home) does not touch value or data in this case */
128 ok( !strcmp( value, "Te" ), "value set to '%s' instead of 'Te'\n", value );
129 ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
132 /* overflow empty name */
136 strcpy( value, "xxxxxxxxxx" );
137 strcpy( data, "xxxxxxxxxx" );
138 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
139 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
140 ok( val_count == 0, "val_count set to %ld\n", val_count );
141 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
142 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
143 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
145 /* v5.1.2600.0 (XP Home) does not touch data in this case */
146 ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
153 strcpy( value, "xxxxxxxxxx" );
154 strcpy( data, "xxxxxxxxxx" );
155 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
156 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
157 ok( val_count == 20, "val_count set to %ld\n", val_count );
158 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
159 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
160 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
161 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
167 strcpy( value, "xxxxxxxxxx" );
168 strcpy( data, "xxxxxxxxxx" );
169 res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count );
170 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
171 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
172 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
173 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
174 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
175 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
180 res = RegSetValueExW( hkey_main, testW, 0, REG_SZ, (BYTE *)foobarW, 7*sizeof(WCHAR) );
181 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
183 ok( res == 0, "RegSetValueExW failed error %ld\n", res );
185 /* overflow both name and data */
189 memcpy( valueW, xxxW, sizeof(xxxW) );
190 memcpy( dataW, xxxW, sizeof(xxxW) );
191 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
192 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
193 ok( val_count == 2, "val_count set to %ld\n", val_count );
194 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
195 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
196 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
197 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
203 memcpy( valueW, xxxW, sizeof(xxxW) );
204 memcpy( dataW, xxxW, sizeof(xxxW) );
205 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
206 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
207 ok( val_count == 3, "val_count set to %ld\n", val_count );
208 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
209 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
210 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
211 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
217 memcpy( valueW, xxxW, sizeof(xxxW) );
218 memcpy( dataW, xxxW, sizeof(xxxW) );
219 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
220 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
221 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
222 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
223 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
224 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
225 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
231 memcpy( valueW, xxxW, sizeof(xxxW) );
232 memcpy( dataW, xxxW, sizeof(xxxW) );
233 res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
234 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
235 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
236 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
237 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
238 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
239 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
243 RegDeleteValueA( hkey_main, "Test" );
246 static void test_query_value_ex()
252 ret = RegQueryValueExA(hkey_main, "Test2", NULL, &type, NULL, &size);
253 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
254 ok(size == strlen(sTestpath1) + 1, "(%ld,%ld)\n", (DWORD)strlen(sTestpath1) + 1, size);
255 ok(type == REG_SZ, "type %ld is not REG_SZ\n", type);
261 create_test_entries();
263 test_query_value_ex();
266 delete_key( hkey_main );