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, "" );
55 static void setup_main_key(void)
57 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
59 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
62 static void create_test_entries(void)
64 DWORD qw[2] = { 0x12345678, 0x87654321 };
66 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
67 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
69 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (LPBYTE)sTestpath1, strlen(sTestpath1)+1),
70 "RegSetValueExA failed\n");
71 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (LPBYTE)sTestpath1, strlen(sTestpath1)+1),
72 "RegSetValueExA failed\n");
73 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (LPBYTE)sTestpath2, strlen(sTestpath2)+1),
74 "RegSetValueExA failed\n");
75 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (LPBYTE)qw, 4),
76 "RegSetValueExA failed\n");
77 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (LPBYTE)qw, 4),
78 "RegSetValueExA failed\n");
79 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (LPBYTE)qw, 8),
80 "RegSetValueExA failed\n");
83 static void test_enum_value(void)
87 char value[20], data[20];
88 WCHAR valueW[20], dataW[20];
89 DWORD val_count, data_count, type;
90 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
91 static const WCHAR testW[] = {'T','e','s','t',0};
92 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
94 /* create the working key for new 'Test' value */
95 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
96 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res);
98 /* check NULL data with zero length */
99 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
100 if (GetVersion() & 0x80000000)
101 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
103 ok( !res, "RegSetValueExA returned %ld\n", res );
104 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
105 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
106 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
107 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
109 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
110 ok( res == 0, "RegSetValueExA failed error %ld\n", res );
112 /* overflow both name and data */
116 strcpy( value, "xxxxxxxxxx" );
117 strcpy( data, "xxxxxxxxxx" );
118 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
119 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
120 ok( val_count == 2, "val_count set to %ld\n", val_count );
121 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
122 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
123 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
124 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
130 strcpy( value, "xxxxxxxxxx" );
131 strcpy( data, "xxxxxxxxxx" );
132 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
133 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
134 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
135 ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count );
136 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
137 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
139 /* v5.1.2600.0 (XP Home) does not touch value or data in this case */
140 ok( !strcmp( value, "Te" ), "value set to '%s' instead of 'Te'\n", value );
141 ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
144 /* overflow empty name */
148 strcpy( value, "xxxxxxxxxx" );
149 strcpy( data, "xxxxxxxxxx" );
150 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
151 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
152 ok( val_count == 0, "val_count set to %ld\n", val_count );
153 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
154 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
155 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
157 /* v5.1.2600.0 (XP Home) does not touch data in this case */
158 ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
165 strcpy( value, "xxxxxxxxxx" );
166 strcpy( data, "xxxxxxxxxx" );
167 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
168 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
169 ok( val_count == 20, "val_count set to %ld\n", val_count );
170 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
171 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
172 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
173 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
179 strcpy( value, "xxxxxxxxxx" );
180 strcpy( data, "xxxxxxxxxx" );
181 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
182 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
183 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
184 ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
185 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
186 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
187 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
192 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
193 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
195 ok( res == 0, "RegSetValueExW failed error %ld\n", res );
197 /* overflow both name and data */
201 memcpy( valueW, xxxW, sizeof(xxxW) );
202 memcpy( dataW, xxxW, sizeof(xxxW) );
203 res = RegEnumValueW( test_key, 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 == 2, "val_count set to %ld\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, xxxW, sizeof(xxxW) ), "value modified\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( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
218 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
219 ok( val_count == 3, "val_count set to %ld\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, xxxW, sizeof(xxxW) ), "value modified\n" );
223 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
229 memcpy( valueW, xxxW, sizeof(xxxW) );
230 memcpy( dataW, xxxW, sizeof(xxxW) );
231 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
232 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
233 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
234 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
235 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
236 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
237 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
243 memcpy( valueW, xxxW, sizeof(xxxW) );
244 memcpy( dataW, xxxW, sizeof(xxxW) );
245 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
246 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
247 ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
248 ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
249 ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
250 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
251 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
254 static void test_query_value_ex(void)
260 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
261 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
262 ok(size == strlen(sTestpath1) + 1, "(%ld,%ld)\n", (DWORD)strlen(sTestpath1) + 1, size);
263 ok(type == REG_SZ, "type %ld is not REG_SZ\n", type);
266 static void test_get_value(void)
269 DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
276 CHAR expanded[] = "bar\\subdir1";
278 /* This function was introduced with Windows 2003 SP1 */
279 hadvapi32 = LoadLibraryA("advapi32.dll");
282 ok(0, "error=%ld\n", GetLastError());
285 pRegGetValueA = (PVOID)GetProcAddress(hadvapi32, "RegGetValueA");
289 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
290 size = type = dw = 0xdeadbeef;
291 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
292 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
293 ok(size == 4, "size=%ld\n", size);
294 ok(type == REG_DWORD, "type=%ld\n", type);
295 ok(dw == 0x12345678, "dw=%ld\n", dw);
297 /* Query by subkey-name */
298 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
299 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
301 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
302 size = type = dw = 0xdeadbeef;
303 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
304 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%ld\n", ret);
305 /* Although the function failed all values are retrieved */
306 ok(size == 4, "size=%ld\n", size);
307 ok(type == REG_DWORD, "type=%ld\n", type);
308 ok(dw == 0x12345678, "dw=%ld\n", dw);
310 /* Test RRF_ZEROONFAILURE */
311 type = dw = 0xdeadbeef; size = 4;
312 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
313 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%ld\n", ret);
314 /* Again all values are retrieved ... */
315 ok(size == 4, "size=%ld\n", size);
316 ok(type == REG_DWORD, "type=%ld\n", type);
317 /* ... except the buffer, which is zeroed out */
318 ok(dw == 0, "dw=%ld\n", dw);
320 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
321 size = type = dw = 0xdeadbeef;
322 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
323 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
324 ok(size == 4, "size=%ld\n", size);
325 ok(type == REG_DWORD, "type=%ld\n", type);
326 ok(dw == 0x12345678, "dw=%ld\n", dw);
328 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
329 size = type = dw = 0xdeadbeef;
330 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
331 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
332 ok(size == 4, "size=%ld\n", size);
333 ok(type == REG_BINARY, "type=%ld\n", type);
334 ok(dw == 0x12345678, "dw=%ld\n", dw);
336 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
337 qw[0] = qw[1] = size = type = 0xdeadbeef;
338 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
339 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%ld\n", ret);
340 ok(size == 8, "size=%ld\n", size);
341 ok(type == REG_BINARY, "type=%ld\n", type);
342 ok(qw[0] == 0x12345678 &&
343 qw[1] == 0x87654321, "qw={%ld,%ld}\n", qw[0], qw[1]);
345 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
346 type = dw = 0xdeadbeef; size = 4;
347 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
348 ok(ret == ERROR_MORE_DATA, "ret=%ld\n", ret);
349 ok(dw == 0xdeadbeef, "dw=%ld\n", dw);
350 ok(size == 8, "size=%ld\n", size);
352 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
353 qw[0] = qw[1] = size = type = 0xdeadbeef;
354 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
355 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
356 ok(size == 8, "size=%ld\n", size);
357 ok(type == REG_BINARY, "type=%ld\n", type);
358 ok(qw[0] == 0x12345678 &&
359 qw[1] == 0x87654321, "qw={%ld,%ld}\n", qw[0], qw[1]);
361 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
362 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
363 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
364 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
365 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%ld\n", strlen(sTestpath1), size);
366 ok(type == REG_SZ, "type=%ld\n", type);
367 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
369 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
370 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
371 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
372 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
373 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%ld\n", strlen(sTestpath1), size);
374 ok(type == REG_SZ, "type=%ld\n", type);
375 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
377 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
378 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
379 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
380 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
382 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded length + 1 here. */
383 ok(size == strlen(expanded)+1, "strlen(expanded)=%ld size=%ld\n", strlen(expanded), size);
385 ok(type == REG_SZ, "type=%ld\n", type);
386 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
388 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
389 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
390 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
391 ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
392 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%ld\n", strlen(sTestpath1), size);
393 ok(type == REG_EXPAND_SZ, "type=%ld\n", type);
394 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
396 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
397 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
398 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%ld\n", ret);
400 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
401 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
402 ok(ret == ERROR_INVALID_PARAMETER, "ret=%ld\n", ret);
405 static void test_reg_open_key(void)
408 HKEY hkResult = NULL;
409 HKEY hkPreserve = NULL;
411 /* successful open */
412 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
413 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
414 ok(hkResult != NULL, "expected hkResult != NULL\n");
415 hkPreserve = hkResult;
417 /* these tests fail on Win9x, but we want to be compatible with NT, so
418 * run them if we can */
419 if (!(GetVersion() & 0x80000000))
421 /* open same key twice */
422 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
423 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
424 ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
425 ok(hkResult != NULL, "hkResult != NULL\n");
426 RegCloseKey(hkResult);
428 /* open nonexistent key
429 * check that hkResult is set to NULL
431 hkResult = hkPreserve;
432 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
433 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
434 ok(hkResult == NULL, "expected hkResult == NULL\n");
436 /* open the same nonexistent key again to make sure the key wasn't created */
437 hkResult = hkPreserve;
438 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
439 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
440 ok(hkResult == NULL, "expected hkResult == NULL\n");
442 /* send in NULL lpSubKey
443 * check that hkResult receives the value of hKey
445 hkResult = hkPreserve;
446 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
447 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
448 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
450 /* send empty-string in lpSubKey */
451 hkResult = hkPreserve;
452 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
453 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
454 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
456 /* send in NULL lpSubKey and NULL hKey
457 * hkResult is set to NULL
459 hkResult = hkPreserve;
460 ret = RegOpenKeyA(NULL, NULL, &hkResult);
461 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
462 ok(hkResult == NULL, "expected hkResult == NULL\n");
465 /* only send NULL hKey
466 * the value of hkResult remains unchanged
468 hkResult = hkPreserve;
469 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
470 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
471 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
472 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
473 RegCloseKey(hkResult);
475 /* send in NULL hkResult */
476 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
477 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
480 static void test_reg_create_key(void)
484 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
485 ok(!ret, "RegCreateKeyExA failed with error %ld\n", ret);
486 /* should succeed: all versions of Windows ignore the access rights
487 * to the parent handle */
488 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
489 ok(!ret, "RegCreateKeyExA failed with error %ld\n", ret);
492 RegDeleteKey(hkey2, NULL);
493 RegDeleteKey(hkey1, NULL);
496 static void test_reg_close_key(void)
501 /* successfully close key
502 * hkHandle remains changed after call to RegCloseKey
504 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
505 ret = RegCloseKey(hkHandle);
506 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
508 /* try to close the key twice */
509 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
510 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
511 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %ld\n", ret);
513 /* try to close a NULL handle */
514 ret = RegCloseKey(NULL);
515 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
516 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
519 static void test_reg_delete_key(void)
523 ret = RegDeleteKey(hkey_main, NULL);
524 ok(ret == ERROR_INVALID_PARAMETER ||
525 ret == ERROR_ACCESS_DENIED ||
526 ret == ERROR_BADKEY, /* Win95 */
530 static void test_reg_save_key(void)
534 ret = RegSaveKey(hkey_main, "saved_key", NULL);
535 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
538 static void test_reg_load_key(void)
543 ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
544 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
546 ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
547 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
549 RegCloseKey(hkHandle);
552 static void test_reg_unload_key(void)
556 ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
557 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
559 DeleteFile("saved_key");
562 static BOOL set_privileges(LPCSTR privilege, BOOL set)
568 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
571 if(!LookupPrivilegeValue(NULL, privilege, &luid))
577 tp.PrivilegeCount = 1;
578 tp.Privileges[0].Luid = luid;
581 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
583 tp.Privileges[0].Attributes = 0;
585 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
586 if (GetLastError() != ERROR_SUCCESS)
599 create_test_entries();
601 test_query_value_ex();
604 test_reg_create_key();
605 test_reg_close_key();
606 test_reg_delete_key();
608 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
609 if (set_privileges(SE_BACKUP_NAME, TRUE) &&
610 set_privileges(SE_RESTORE_NAME, TRUE))
614 test_reg_unload_key();
616 set_privileges(SE_BACKUP_NAME, FALSE);
617 set_privileges(SE_RESTORE_NAME, FALSE);
621 delete_key( hkey_main );