2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
33 static HKEY hkey_main;
36 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
37 static const char * sTestpath2 = "%FOO%\\subdir1";
39 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
40 static DWORD (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR);
41 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
42 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
43 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
44 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
45 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
48 /* Debugging functions from wine/libs/wine/debug.c */
50 /* allocate some tmp string space */
51 /* FIXME: this is not 100% thread-safe */
52 static char *get_temp_buffer( int size )
54 static char *list[32];
59 idx = ++pos % (sizeof(list)/sizeof(list[0]));
61 ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
63 ret = HeapAlloc( GetProcessHeap(), 0, size );
64 if (ret) list[idx] = ret;
68 static const char *wine_debugstr_an( const char *str, int n )
70 static const char hex[16] = "0123456789abcdef";
74 if (!((ULONG_PTR)str >> 16))
76 if (!str) return "(null)";
77 res = get_temp_buffer( 6 );
78 sprintf( res, "#%04x", LOWORD(str) );
81 if (n == -1) n = strlen(str);
83 size = 10 + min( 300, n * 4 );
84 dst = res = get_temp_buffer( size );
86 while (n-- > 0 && dst <= res + size - 9)
88 unsigned char c = *str++;
91 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
92 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
93 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
94 case '"': *dst++ = '\\'; *dst++ = '"'; break;
95 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
97 if (c >= ' ' && c <= 126)
103 *dst++ = hex[(c >> 4) & 0x0f];
104 *dst++ = hex[c & 0x0f];
119 #define ADVAPI32_GET_PROC(func) \
120 p ## func = (void*)GetProcAddress(hadvapi32, #func)
122 static void InitFunctionPtrs(void)
124 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
125 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
126 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
128 /* This function was introduced with Windows 2003 SP1 */
129 ADVAPI32_GET_PROC(RegGetValueA);
130 ADVAPI32_GET_PROC(RegDeleteTreeA);
131 ADVAPI32_GET_PROC(RegDeleteKeyExA);
133 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
134 pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
135 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
136 pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
139 /* delete key and all its subkeys */
140 static DWORD delete_key( HKEY hkey )
145 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
148 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
150 ret = delete_key( tmp );
155 if (ret != ERROR_NO_MORE_ITEMS) return ret;
156 RegDeleteKeyA( hkey, "" );
160 static void setup_main_key(void)
162 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
164 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
167 #define lok ok_(__FILE__, line)
168 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
169 static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
172 DWORD ret, type, cbData;
178 /* When successful RegQueryValueExA() leaves GLE as is,
179 * so we must reset it to detect unimplemented functions.
181 SetLastError(0xdeadbeef);
182 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
183 GLE = GetLastError();
184 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret, GLE);
185 /* It is wrong for the Ansi version to not be implemented */
186 ok(GLE == 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE);
187 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
189 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
190 lok(type == REG_SZ, "RegQueryValueExA/1 returned type %d\n", type);
191 lok(cbData == full_byte_len || cbData == str_byte_len /* Win9x */,
192 "cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
194 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
195 memset(value, 0xbd, cbData+1);
197 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
198 GLE = GetLastError();
199 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
202 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
203 lok(*value == 0xbd || (cbData == 1 && *value == '\0') /* Win9x */,
204 "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
208 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
209 wine_debugstr_an((char*)value, cbData), cbData,
210 wine_debugstr_an(string, full_byte_len), full_byte_len);
211 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
213 HeapFree(GetProcessHeap(), 0, value);
216 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
217 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
220 DWORD ret, type, cbData;
225 /* When successful RegQueryValueExW() leaves GLE as is,
226 * so we must reset it to detect unimplemented functions.
228 SetLastError(0xdeadbeef);
229 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
230 GLE = GetLastError();
231 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
232 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
234 win_skip("RegQueryValueExW() is not implemented\n");
238 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
239 lok(cbData == full_byte_len,
240 "cbData=%d instead of %d\n", cbData, full_byte_len);
242 /* Give enough space to overflow by one WCHAR */
243 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
244 memset(value, 0xbd, cbData+2);
246 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
247 GLE = GetLastError();
248 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
251 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
252 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
253 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
255 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
256 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
257 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
258 HeapFree(GetProcessHeap(), 0, value);
261 static void test_set_value(void)
265 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
266 static const WCHAR name2W[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
267 static const WCHAR emptyW[] = {0};
268 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
269 static const WCHAR string2W[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
270 static const WCHAR substring2W[] = {'T','h','i','s',0};
272 static const char name1A[] = "CleanSingleString";
273 static const char name2A[] = "SomeIntraZeroedString";
274 static const char emptyA[] = "";
275 static const char string1A[] = "ThisNeverBreaks";
276 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
277 static const char substring2A[] = "This";
281 /* Crashes on NT4, Windows 2000 and XP SP1 */
282 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
283 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
286 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
287 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
288 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
289 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
291 /* RegSetValueA ignores the size passed in */
292 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
293 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
294 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
295 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
297 /* stops at first null */
298 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
299 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
300 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
301 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
303 /* only REG_SZ is supported on NT*/
304 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
305 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
306 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS),
307 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret);
309 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
310 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
311 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS),
312 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret);
314 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
315 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
316 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS),
317 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret);
319 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
320 * Surprisingly enough we're supposed to get zero bytes out of it.
322 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
323 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
324 test_hkey_main_Value_A(name1A, NULL, 0);
325 test_hkey_main_Value_W(name1W, NULL, 0);
327 /* test RegSetValueExA with an empty string */
328 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
329 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
330 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
331 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
333 /* test RegSetValueExA with off-by-one size */
334 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
335 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
336 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
337 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
339 /* test RegSetValueExA with normal string */
340 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
341 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
342 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
343 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
345 /* test RegSetValueExA with intrazeroed string */
346 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
347 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
348 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
349 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
351 /* 9x doesn't support W-calls, so don't test them then */
352 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
356 /* Crashes on NT4, Windows 2000 and XP SP1 */
357 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
358 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
361 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
362 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
363 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
364 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
366 /* RegSetValueA ignores the size passed in */
367 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
368 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
369 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
370 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
372 /* stops at first null */
373 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
374 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
375 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
376 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
378 /* only REG_SZ is supported */
379 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
380 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
381 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
382 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
383 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
384 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
386 /* test RegSetValueExW with off-by-one size */
387 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
388 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
389 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
390 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
392 /* test RegSetValueExW with normal string */
393 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
394 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
395 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
396 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
398 /* test RegSetValueExW with intrazeroed string */
399 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
400 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
401 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
402 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
405 static void create_test_entries(void)
407 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
409 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
410 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
412 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
413 "RegSetValueExA failed\n");
414 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
415 "RegSetValueExA failed\n");
416 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
417 "RegSetValueExA failed\n");
418 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
419 "RegSetValueExA failed\n");
420 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
421 "RegSetValueExA failed\n");
422 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
423 "RegSetValueExA failed\n");
424 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
425 "RegSetValueExA failed\n");
428 static void test_enum_value(void)
432 char value[20], data[20];
433 WCHAR valueW[20], dataW[20];
434 DWORD val_count, data_count, type;
435 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
436 static const WCHAR testW[] = {'T','e','s','t',0};
437 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
439 /* create the working key for new 'Test' value */
440 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
441 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
443 /* check NULL data with zero length */
444 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
445 if (GetVersion() & 0x80000000)
446 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
448 ok( !res, "RegSetValueExA returned %d\n", res );
449 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
450 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
451 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
452 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
454 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
455 ok( res == 0, "RegSetValueExA failed error %d\n", res );
457 /* overflow both name and data */
461 strcpy( value, "xxxxxxxxxx" );
462 strcpy( data, "xxxxxxxxxx" );
463 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
464 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
465 ok( val_count == 2, "val_count set to %d\n", val_count );
466 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
467 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
468 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
469 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
475 strcpy( value, "xxxxxxxxxx" );
476 strcpy( data, "xxxxxxxxxx" );
477 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
478 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
479 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
480 ok( val_count == 2 || val_count == 3, "val_count set to %d\n", val_count );
481 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
482 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
483 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
484 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
485 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
486 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
487 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
489 /* overflow empty name */
493 strcpy( value, "xxxxxxxxxx" );
494 strcpy( data, "xxxxxxxxxx" );
495 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
496 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
497 ok( val_count == 0, "val_count set to %d\n", val_count );
498 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
499 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
500 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
501 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
502 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
503 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
509 strcpy( value, "xxxxxxxxxx" );
510 strcpy( data, "xxxxxxxxxx" );
511 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
512 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
513 ok( val_count == 20, "val_count set to %d\n", val_count );
514 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
515 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
516 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
517 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
523 strcpy( value, "xxxxxxxxxx" );
524 strcpy( data, "xxxxxxxxxx" );
525 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
526 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
527 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
528 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
529 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
530 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
531 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
535 SetLastError(0xdeadbeef);
536 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
537 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
539 win_skip("RegSetValueExW is not implemented\n");
542 ok( res == 0, "RegSetValueExW failed error %d\n", res );
544 /* overflow both name and data */
548 memcpy( valueW, xxxW, sizeof(xxxW) );
549 memcpy( dataW, xxxW, sizeof(xxxW) );
550 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
551 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
552 ok( val_count == 2, "val_count set to %d\n", val_count );
553 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
554 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
555 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
556 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
562 memcpy( valueW, xxxW, sizeof(xxxW) );
563 memcpy( dataW, xxxW, sizeof(xxxW) );
564 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
565 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
566 ok( val_count == 3, "val_count set to %d\n", val_count );
567 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
568 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
569 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
570 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
576 memcpy( valueW, xxxW, sizeof(xxxW) );
577 memcpy( dataW, xxxW, sizeof(xxxW) );
578 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
579 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
580 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
581 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
582 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
583 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
584 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
590 memcpy( valueW, xxxW, sizeof(xxxW) );
591 memcpy( dataW, xxxW, sizeof(xxxW) );
592 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
593 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
594 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
595 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
596 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
597 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
598 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
601 RegDeleteKeyA(test_key, "");
602 RegCloseKey(test_key);
605 static void test_query_value_ex(void)
612 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
613 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
614 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
615 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
619 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
620 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
621 /* the type parameter is cleared on Win9x, but is set to a random value on
622 * NT, so don't do that test there. The size parameter is left untouched on Win9x
623 * but cleared on NT+, this can be tested on all platforms.
625 if (GetVersion() & 0x80000000)
627 ok(type == 0, "type should have been set to 0 instead of 0x%x\n", type);
628 ok(size == 0xdeadbeef, "size should have been left untouched (0xdeadbeef)\n");
632 trace("test_query_value_ex: type set to: 0x%08x\n", type);
633 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
636 size = sizeof(buffer);
637 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
638 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
639 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
642 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
643 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
646 static void test_get_value(void)
653 CHAR expanded[] = "bar\\subdir1";
654 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
658 win_skip("RegGetValue not available on this platform\n");
662 /* Invalid parameter */
663 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
664 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
666 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
667 size = type = dw = 0xdeadbeef;
668 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
669 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
670 ok(size == 4, "size=%d\n", size);
671 ok(type == REG_DWORD, "type=%d\n", type);
672 ok(dw == 0x12345678, "dw=%d\n", dw);
674 /* Query by subkey-name */
675 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
676 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
678 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
679 size = type = dw = 0xdeadbeef;
680 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
681 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
682 /* Although the function failed all values are retrieved */
683 ok(size == 4, "size=%d\n", size);
684 ok(type == REG_DWORD, "type=%d\n", type);
685 ok(dw == 0x12345678, "dw=%d\n", dw);
687 /* Test RRF_ZEROONFAILURE */
688 type = dw = 0xdeadbeef; size = 4;
689 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
690 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
691 /* Again all values are retrieved ... */
692 ok(size == 4, "size=%d\n", size);
693 ok(type == REG_DWORD, "type=%d\n", type);
694 /* ... except the buffer, which is zeroed out */
695 ok(dw == 0, "dw=%d\n", dw);
697 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
698 type = size = 0xbadbeef;
699 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
700 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
701 ok(size == 4, "size=%d\n", size);
702 ok(type == REG_DWORD, "type=%d\n", type);
704 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
705 size = type = dw = 0xdeadbeef;
706 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
707 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
708 ok(size == 4, "size=%d\n", size);
709 ok(type == REG_DWORD, "type=%d\n", type);
710 ok(dw == 0x12345678, "dw=%d\n", dw);
712 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
713 size = type = dw = 0xdeadbeef;
714 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
715 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
716 ok(size == 4, "size=%d\n", size);
717 ok(type == REG_BINARY, "type=%d\n", type);
718 ok(dw == 0x12345678, "dw=%d\n", dw);
720 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
721 qw[0] = qw[1] = size = type = 0xdeadbeef;
722 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
723 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
724 ok(size == 8, "size=%d\n", size);
725 ok(type == REG_BINARY, "type=%d\n", type);
726 ok(qw[0] == 0x12345678 &&
727 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
729 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
730 type = dw = 0xdeadbeef; size = 4;
731 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
732 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
733 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
734 ok(size == 8, "size=%d\n", size);
736 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
737 qw[0] = qw[1] = size = type = 0xdeadbeef;
738 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
739 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
740 ok(size == 8, "size=%d\n", size);
741 ok(type == REG_BINARY, "type=%d\n", type);
742 ok(qw[0] == 0x12345678 &&
743 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
745 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
746 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
747 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
748 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
749 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
750 ok(type == REG_SZ, "type=%d\n", type);
751 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
753 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
754 type = 0xdeadbeef; size = 0;
755 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
756 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
757 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
758 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
759 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
760 ok(type == REG_SZ, "type=%d\n", type);
762 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
763 strcpy(buf, sTestpath1);
766 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
767 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
768 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
770 size == 1, /* win2k3 */
772 ok(type == REG_SZ, "type=%d\n", type);
773 ok(!strcmp(sTestpath1, buf) ||
775 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
777 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
778 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
779 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
780 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
781 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
782 ok(type == REG_SZ, "type=%d\n", type);
783 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
785 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
787 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
788 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
789 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
790 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
791 (size == strlen(sTestpath2)+1),
792 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
794 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
795 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
796 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
797 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
798 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
799 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
800 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
801 ok(type == REG_SZ, "type=%d\n", type);
802 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
804 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
805 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
806 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
807 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
808 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
809 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
810 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
811 ok(type == REG_SZ, "type=%d\n", type);
812 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
814 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
815 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
816 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
817 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
818 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
819 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
820 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
822 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
824 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
825 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
826 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
827 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
828 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
830 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
831 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
832 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
834 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
835 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
836 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
838 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
839 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
840 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
841 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
842 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
843 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
844 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
845 ok(type == REG_SZ, "type=%d\n", type);
846 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
849 static void test_reg_open_key(void)
852 HKEY hkResult = NULL;
853 HKEY hkPreserve = NULL;
855 /* successful open */
856 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
857 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
858 ok(hkResult != NULL, "expected hkResult != NULL\n");
859 hkPreserve = hkResult;
861 /* these tests fail on Win9x, but we want to be compatible with NT, so
862 * run them if we can */
863 if (!(GetVersion() & 0x80000000))
865 /* open same key twice */
866 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
867 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
868 ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
869 ok(hkResult != NULL, "hkResult != NULL\n");
870 RegCloseKey(hkResult);
872 /* open nonexistent key
873 * check that hkResult is set to NULL
875 hkResult = hkPreserve;
876 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
877 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
878 ok(hkResult == NULL, "expected hkResult == NULL\n");
880 /* open the same nonexistent key again to make sure the key wasn't created */
881 hkResult = hkPreserve;
882 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
883 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
884 ok(hkResult == NULL, "expected hkResult == NULL\n");
886 /* send in NULL lpSubKey
887 * check that hkResult receives the value of hKey
889 hkResult = hkPreserve;
890 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
891 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
892 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
894 /* send empty-string in lpSubKey */
895 hkResult = hkPreserve;
896 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
897 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
898 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
900 /* send in NULL lpSubKey and NULL hKey
901 * hkResult is set to NULL
903 hkResult = hkPreserve;
904 ret = RegOpenKeyA(NULL, NULL, &hkResult);
905 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
906 ok(hkResult == NULL, "expected hkResult == NULL\n");
909 /* only send NULL hKey
910 * the value of hkResult remains unchanged
912 hkResult = hkPreserve;
913 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
914 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
915 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
916 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
917 RegCloseKey(hkResult);
919 /* send in NULL hkResult */
920 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
921 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
923 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
924 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
926 ret = RegOpenKeyA(NULL, NULL, NULL);
927 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
929 /* beginning backslash character */
930 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
931 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
932 ret == ERROR_FILE_NOT_FOUND || /* Win9x,ME */
933 broken(ret == ERROR_SUCCESS), /* wow64 */
934 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
935 if (!ret) RegCloseKey(hkResult);
938 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
939 ok(ret == ERROR_SUCCESS || /* 2k/XP */
940 ret == ERROR_BAD_PATHNAME || /* NT */
941 ret == ERROR_FILE_NOT_FOUND /* Win9x,ME */
942 , "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
943 RegCloseKey(hkResult);
947 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
948 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
949 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
950 RegCloseKey(hkResult);
953 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
954 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
955 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
956 RegCloseKey(hkResult);
959 static void test_reg_create_key(void)
963 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
964 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
965 /* should succeed: all versions of Windows ignore the access rights
966 * to the parent handle */
967 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
968 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
971 RegDeleteKey(hkey2, "");
972 RegDeleteKey(hkey1, "");
976 /* test creation of volatile keys */
977 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
978 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
979 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
980 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE || broken(!ret), /* win9x */
981 "RegCreateKeyExA failed with error %d\n", ret);
982 if (!ret) RegCloseKey( hkey2 );
983 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
984 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
986 /* should succeed if the key already exists */
987 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
988 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
991 RegDeleteKey(hkey2, "");
992 RegDeleteKey(hkey1, "");
996 /* beginning backslash character */
997 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
998 if (!(GetVersion() & 0x80000000))
999 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1001 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1002 RegDeleteKey(hkey1, NULL);
1006 /* WOW64 flags - open an existing key */
1008 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1009 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1010 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1014 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1015 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1016 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1020 static void test_reg_close_key(void)
1025 /* successfully close key
1026 * hkHandle remains changed after call to RegCloseKey
1028 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1029 ret = RegCloseKey(hkHandle);
1030 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1032 /* try to close the key twice */
1033 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1034 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1035 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1037 /* try to close a NULL handle */
1038 ret = RegCloseKey(NULL);
1039 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1040 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1042 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1043 * win98 doesn't give a new handle when the same key is opened.
1044 * Not re-opening will make some next tests fail.
1046 if (hkey_main == hkHandle)
1048 trace("The main handle is most likely closed, so re-opening\n");
1049 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1053 static void test_reg_delete_key(void)
1057 ret = RegDeleteKey(hkey_main, NULL);
1059 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1060 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1061 * Not re-creating will make some next tests fail.
1063 if (ret == ERROR_SUCCESS)
1065 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1066 " re-creating the main key\n");
1070 ok(ret == ERROR_INVALID_PARAMETER ||
1071 ret == ERROR_ACCESS_DENIED ||
1072 ret == ERROR_BADKEY, /* Win95 */
1076 static void test_reg_save_key(void)
1080 ret = RegSaveKey(hkey_main, "saved_key", NULL);
1081 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1084 static void test_reg_load_key(void)
1089 ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1090 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1092 ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1093 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1095 RegCloseKey(hkHandle);
1098 static void test_reg_unload_key(void)
1102 ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
1103 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1105 DeleteFile("saved_key");
1106 DeleteFile("saved_key.LOG");
1109 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1111 TOKEN_PRIVILEGES tp;
1115 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1118 if(!LookupPrivilegeValue(NULL, privilege, &luid))
1120 CloseHandle(hToken);
1124 tp.PrivilegeCount = 1;
1125 tp.Privileges[0].Luid = luid;
1128 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1130 tp.Privileges[0].Attributes = 0;
1132 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1133 if (GetLastError() != ERROR_SUCCESS)
1135 CloseHandle(hToken);
1139 CloseHandle(hToken);
1143 /* tests that show that RegConnectRegistry and
1144 OpenSCManager accept computer names without the
1145 \\ prefix (what MSDN says). */
1146 static void test_regconnectregistry( void)
1148 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1149 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1150 DWORD len = sizeof(compName) ;
1156 SetLastError(0xdeadbeef);
1157 ret = GetComputerNameA(compName, &len);
1158 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1161 lstrcpyA(netwName, "\\\\");
1162 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1164 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1166 retl == ERROR_DLL_INIT_FAILED ||
1167 retl == ERROR_BAD_NETPATH, /* some win2k */
1168 "RegConnectRegistryA failed err = %d\n", retl);
1169 if( !retl) RegCloseKey( hkey);
1171 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1173 retl == ERROR_DLL_INIT_FAILED ||
1174 retl == ERROR_BAD_NETPATH, /* some win2k */
1175 "RegConnectRegistryA failed err = %d\n", retl);
1176 if( !retl) RegCloseKey( hkey);
1178 SetLastError(0xdeadbeef);
1179 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1180 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1182 win_skip("OpenSCManagerA is not implemented\n");
1186 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1187 CloseServiceHandle( schnd);
1189 SetLastError(0xdeadbeef);
1190 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1191 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1192 CloseServiceHandle( schnd);
1196 static void test_reg_query_value(void)
1203 static const WCHAR expected[] = {'d','a','t','a',0};
1205 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1206 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1208 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1209 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1211 /* try an invalid hkey */
1212 SetLastError(0xdeadbeef);
1214 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1215 ok(ret == ERROR_INVALID_HANDLE ||
1216 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1217 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1218 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1219 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1221 /* try a NULL hkey */
1222 SetLastError(0xdeadbeef);
1224 ret = RegQueryValueA(NULL, "subkey", val, &size);
1225 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1226 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1227 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1229 /* try a NULL value */
1231 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1232 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1233 ok(size == 5, "Expected 5, got %d\n", size);
1235 /* try a NULL size */
1236 SetLastError(0xdeadbeef);
1238 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1239 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1240 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1241 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1243 /* try a NULL value and size */
1244 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1245 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1247 /* try a size too small */
1248 SetLastError(0xdeadbeef);
1251 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1252 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1253 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1254 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1255 ok(size == 5, "Expected 5, got %d\n", size);
1257 /* successfully read the value using 'subkey' */
1259 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1260 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1261 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1262 ok(size == 5, "Expected 5, got %d\n", size);
1264 /* successfully read the value using the subkey key */
1266 ret = RegQueryValueA(subkey, NULL, val, &size);
1267 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1268 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1269 ok(size == 5, "Expected 5, got %d\n", size);
1271 /* unicode - try size too small */
1272 SetLastError(0xdeadbeef);
1275 ret = RegQueryValueW(subkey, NULL, valW, &size);
1276 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1278 win_skip("RegQueryValueW is not implemented\n");
1281 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1282 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1283 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1284 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1286 /* unicode - try size in WCHARS */
1287 SetLastError(0xdeadbeef);
1288 size = sizeof(valW) / sizeof(WCHAR);
1289 ret = RegQueryValueW(subkey, NULL, valW, &size);
1290 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1291 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1292 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1293 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1295 /* unicode - successfully read the value */
1296 size = sizeof(valW);
1297 ret = RegQueryValueW(subkey, NULL, valW, &size);
1298 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1299 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1300 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1302 /* unicode - set the value without a NULL terminator */
1303 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1304 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1306 /* unicode - read the unterminated value, value is terminated for us */
1307 memset(valW, 'a', sizeof(valW));
1308 size = sizeof(valW);
1309 ret = RegQueryValueW(subkey, NULL, valW, &size);
1310 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1311 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1312 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1315 RegDeleteKeyA(subkey, "");
1316 RegCloseKey(subkey);
1319 static void test_string_termination(void)
1323 static const char string[] = "FullString";
1326 DWORD insize, outsize, nsize;
1328 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
1329 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1331 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1332 insize=sizeof(string)-1;
1333 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1334 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1336 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1337 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
1339 /* Off-by-two RegSetValueExA -> no trailing '\0', except on Win9x */
1340 insize=sizeof(string)-2;
1341 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1342 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1344 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
1345 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1346 ok(outsize == insize || broken(outsize == sizeof(string)) /* Win9x */,
1347 "wrong size %u != %u\n", outsize, insize);
1349 if (outsize == insize)
1351 /* RegQueryValueExA may return a string with no trailing '\0' */
1353 memset(buffer, 0xbd, sizeof(buffer));
1354 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1355 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1356 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1357 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1358 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1359 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1361 /* RegQueryValueExA adds a trailing '\0' if there is room */
1363 memset(buffer, 0xbd, sizeof(buffer));
1364 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1365 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1366 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1367 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1368 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1369 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1371 /* RegEnumValueA may return a string with no trailing '\0' */
1373 memset(buffer, 0xbd, sizeof(buffer));
1375 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1376 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1377 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1378 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1379 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1380 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1381 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1383 /* RegEnumValueA adds a trailing '\0' if there is room */
1385 memset(buffer, 0xbd, sizeof(buffer));
1387 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1388 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1389 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1390 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1391 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1392 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1393 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1396 RegDeleteKeyA(subkey, "");
1397 RegCloseKey(subkey);
1400 static void test_reg_delete_tree(void)
1402 CHAR buffer[MAX_PATH];
1403 HKEY subkey, subkey2;
1406 if(!pRegDeleteTreeA) {
1407 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1411 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1412 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1413 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1414 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1415 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1416 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1417 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
1418 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1419 ret = RegCloseKey(subkey2);
1420 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1422 ret = pRegDeleteTreeA(subkey, "subkey2");
1423 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1424 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1425 "subkey2 was not deleted\n");
1427 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1428 "Default value of subkey not longer present\n");
1430 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1431 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1432 ret = RegCloseKey(subkey2);
1433 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1434 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
1435 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1436 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1437 "subkey2 was not deleted\n");
1438 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1439 "Default value of subkey not longer present\n");
1441 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1442 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1443 ret = RegCloseKey(subkey2);
1444 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1445 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
1446 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1447 ret = RegCloseKey(subkey2);
1448 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1449 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
1450 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1451 ret = pRegDeleteTreeA(subkey, NULL);
1452 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1453 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
1454 "subkey was deleted\n");
1455 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1456 "subkey2 was not deleted\n");
1457 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
1458 "subkey3 was not deleted\n");
1460 ret = RegQueryValueA(subkey, NULL, buffer, &size);
1461 ok(ret == ERROR_SUCCESS,
1462 "Default value of subkey is not present\n");
1463 ok(!lstrlenA(buffer),
1464 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
1466 ok(RegQueryValueA(subkey, "value", buffer, &size),
1467 "Value is still present\n");
1469 ret = pRegDeleteTreeA(hkey_main, "not-here");
1470 ok(ret == ERROR_FILE_NOT_FOUND,
1471 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1474 static void test_rw_order(void)
1478 static char keyname[] = "test_rw_order";
1480 DWORD values, value_len, value_name_max_len;
1483 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
1484 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
1485 if(ret != ERROR_SUCCESS) {
1486 skip("Couldn't create key. Skipping.\n");
1490 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1491 "RegSetValueExA for value \"A\" failed\n");
1492 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1493 "RegSetValueExA for value \"C\" failed\n");
1494 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1495 "RegSetValueExA for value \"D\" failed\n");
1496 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1497 "RegSetValueExA for value \"B\" failed\n");
1499 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
1500 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
1501 ok(values == 4, "Expected 4 values, got %u\n", values);
1503 /* Value enumeration preserves RegSetValueEx call order */
1505 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1506 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
1508 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1509 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
1511 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1512 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
1514 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1515 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
1517 ok(!RegDeleteKey(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
1520 static void test_symlinks(void)
1522 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1523 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1525 UNICODE_STRING target_str;
1529 DWORD target_len, type, len, dw, err;
1531 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
1533 win_skip( "Can't perform symlink tests\n" );
1537 pRtlFormatCurrentUserKeyPath( &target_str );
1539 target_len = target_str.Length + sizeof(targetW);
1540 target = HeapAlloc( GetProcessHeap(), 0, target_len );
1541 memcpy( target, target_str.Buffer, target_str.Length );
1542 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
1544 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1545 KEY_ALL_ACCESS, NULL, &link, NULL );
1546 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
1548 /* REG_SZ is not allowed */
1549 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
1550 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1551 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
1552 (BYTE *)target, target_len - sizeof(WCHAR) );
1553 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1554 /* other values are not allowed */
1555 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
1556 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1558 /* try opening the target through the link */
1560 err = RegOpenKeyA( hkey_main, "link", &key );
1561 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
1563 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1564 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1567 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1568 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1571 err = RegOpenKeyA( hkey_main, "link", &key );
1572 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1574 len = sizeof(buffer);
1575 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1576 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1577 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1579 len = sizeof(buffer);
1580 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1581 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1583 /* REG_LINK can be created in non-link keys */
1584 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
1585 (BYTE *)target, target_len - sizeof(WCHAR) );
1586 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1587 len = sizeof(buffer);
1588 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1589 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1590 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1591 err = RegDeleteValueA( key, "SymbolicLinkValue" );
1592 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
1596 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1597 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1599 len = sizeof(buffer);
1600 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1601 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1602 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1604 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1605 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1608 /* now open the symlink itself */
1610 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
1611 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
1612 len = sizeof(buffer);
1613 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1614 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1615 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1618 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
1619 KEY_ALL_ACCESS, NULL, &key, NULL );
1620 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1621 len = sizeof(buffer);
1622 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1623 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1624 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1627 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1628 KEY_ALL_ACCESS, NULL, &key, NULL );
1629 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1631 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
1632 KEY_ALL_ACCESS, NULL, &key, NULL );
1633 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1635 err = RegDeleteKey( hkey_main, "target" );
1636 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
1638 err = RegDeleteKey( hkey_main, "link" );
1639 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
1641 status = pNtDeleteKey( link );
1642 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
1643 RegCloseKey( link );
1645 HeapFree( GetProcessHeap(), 0, target );
1646 pRtlFreeUnicodeString( &target_str );
1649 static const DWORD ptr_size = 8 * sizeof(void*);
1651 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
1654 DWORD err, type, dw, len = sizeof(dw);
1656 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
1657 if (err == ERROR_FILE_NOT_FOUND) return 0;
1658 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
1660 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
1661 if (err == ERROR_FILE_NOT_FOUND)
1664 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
1669 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
1671 DWORD dw = get_key_value( root, name, flags );
1672 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
1674 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1676 static void test_redirection(void)
1678 DWORD err, type, dw, len;
1679 HKEY key, root32, root64, key32, key64;
1680 BOOL is_vista = FALSE;
1685 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
1687 skip( "Not on Wow64, no redirection\n" );
1692 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1693 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
1694 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1696 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1697 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
1698 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1700 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1701 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
1702 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1704 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1705 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
1706 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1709 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1710 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1713 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1714 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1718 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
1719 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1720 ok( dw == 32, "wrong value %u\n", dw );
1724 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
1725 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1726 ok( dw == 64, "wrong value %u\n", dw );
1728 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1729 KEY_ALL_ACCESS, NULL, &key, NULL );
1730 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1734 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1735 /* the new (and simpler) Win7 mechanism doesn't */
1736 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1738 trace( "using Vista-style Wow6432Node handling\n" );
1741 check_key_value( key, "Wine\\Winetest", 0, 32 );
1742 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1743 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1744 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1745 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1746 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1750 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
1752 trace( "using Vista-style Wow6432Node handling\n" );
1755 check_key_value( key, "Wine\\Winetest", 0, 64 );
1756 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1762 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1763 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1764 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1765 dw = get_key_value( key, "Wine\\Winetest", 0 );
1766 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1767 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1768 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1769 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1770 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
1771 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
1772 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1775 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1776 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1777 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1778 check_key_value( key, "Wine\\Winetest", 0, 32 );
1779 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1780 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1781 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1782 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1783 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1787 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
1788 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1791 /* KEY_WOW64 flags have no effect on 64-bit */
1792 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1793 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1794 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1795 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1799 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1800 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1801 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1802 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1805 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1806 KEY_ALL_ACCESS, NULL, &key, NULL );
1807 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1808 check_key_value( key, "Wine\\Winetest", 0, 32 );
1809 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1810 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1815 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1816 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1817 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1818 dw = get_key_value( key, "Wine\\Winetest", 0 );
1819 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1820 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1821 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1824 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1825 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1826 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1827 check_key_value( key, "Wine\\Winetest", 0, 32 );
1828 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1829 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1833 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1834 KEY_ALL_ACCESS, NULL, &key, NULL );
1835 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1836 check_key_value( key, "Winetest", 0, 32 );
1837 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1838 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
1843 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1844 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1845 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1846 dw = get_key_value( key, "Winetest", 0 );
1847 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
1848 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1849 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
1852 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1853 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1854 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1855 check_key_value( key, "Winetest", 0, 32 );
1856 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1857 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
1861 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1862 KEY_ALL_ACCESS, NULL, &key, NULL );
1863 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1864 check_key_value( key, "Winetest", 0, ptr_size );
1865 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
1866 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
1867 if (ptr_size == 32) ok( dw == 32, "wrong value %u\n", dw );
1868 else todo_wine ok( dw == 32, "wrong value %u\n", dw );
1873 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1874 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1875 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1876 dw = get_key_value( key, "Winetest", 0 );
1877 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1878 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
1879 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
1880 todo_wine ok( dw == 32, "wrong value %u\n", dw );
1883 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1884 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1885 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1886 check_key_value( key, "Winetest", 0, 32 );
1887 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1888 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
1892 if (pRegDeleteKeyExA)
1894 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
1895 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
1896 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
1897 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
1898 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
1899 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
1903 err = RegDeleteKeyA( key32, "" );
1904 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
1905 err = RegDeleteKeyA( key64, "" );
1906 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
1907 RegDeleteKeyA( key64, "" );
1908 RegDeleteKeyA( root64, "" );
1910 RegCloseKey( key32 );
1911 RegCloseKey( key64 );
1912 RegCloseKey( root32 );
1913 RegCloseKey( root64 );
1916 static void test_classesroot(void)
1918 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
1920 DWORD type = REG_SZ;
1921 static CHAR buffer[8];
1924 /* create a key in the user's classes */
1925 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
1928 RegCloseKey( hkey );
1930 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
1931 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
1933 /* try to open that key in hkcr */
1934 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
1935 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
1936 todo_wine ok(res == ERROR_SUCCESS ||
1937 broken(res == ERROR_FILE_NOT_FOUND /* Win9x */),
1938 "test key not found in hkcr: %d\n", res);
1941 trace( "HKCR key merging not supported\n" );
1943 RegCloseKey( hkey );
1947 /* set a value in user's classes */
1948 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
1949 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
1951 /* try to find the value in hkcr */
1952 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
1953 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
1954 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
1956 /* modify the value in hkcr */
1957 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
1958 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
1960 /* check if the value is also modified in user's classes */
1961 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
1962 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
1963 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
1965 /* set a value in hkcr */
1966 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
1967 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
1969 /* try to find the value in user's classes */
1970 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
1971 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
1972 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
1974 /* modify the value in user's classes */
1975 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
1976 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
1978 /* check if the value is also modified in hkcr */
1979 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
1980 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
1981 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
1986 RegCloseKey( hkey );
1987 RegCloseKey( hkcr );
1989 /* create a key in the hklm classes */
1990 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
1993 RegCloseKey( hklm );
1995 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
1996 KEY_ALL_ACCESS, NULL, &hklm, NULL );
1997 if (res == ERROR_ACCESS_DENIED)
1999 skip("not enough privileges to add a system class\n");
2003 /* try to open that key in hkcr */
2004 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2005 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2006 ok(res == ERROR_SUCCESS,
2007 "test key not found in hkcr: %d\n", res);
2011 RegCloseKey( hklm );
2015 /* set a value in hklm classes */
2016 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2017 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2019 /* try to find the value in hkcr */
2020 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2021 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2022 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2024 /* modify the value in hkcr */
2025 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2026 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2028 /* check that the value is not modified in hklm classes */
2029 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2030 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2031 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2033 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2034 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2036 /* try to open that key in hkcr */
2037 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2038 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2039 ok(res == ERROR_SUCCESS,
2040 "test key not found in hkcr: %d\n", res);
2042 /* set a value in user's classes */
2043 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2044 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2046 /* try to find the value in hkcr */
2047 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2048 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2049 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2051 /* modify the value in hklm */
2052 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2053 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2055 /* check that the value is not overwritten in hkcr or user's classes */
2056 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2057 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2058 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2059 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2060 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2061 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2063 /* modify the value in hkcr */
2064 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2065 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2067 /* check that the value is overwritten in hklm and user's classes */
2068 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2069 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2070 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2071 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2072 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2073 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2075 /* create a subkey in hklm */
2076 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2077 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2078 /* try to open that subkey in hkcr */
2079 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2080 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2082 /* set a value in hklm classes */
2083 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2084 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2086 /* try to find the value in hkcr */
2087 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2088 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2089 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2091 /* modify the value in hkcr */
2092 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2093 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2095 /* check that the value is modified in hklm classes */
2096 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2097 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2098 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2100 /* create a subkey in user's classes */
2101 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2102 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2104 /* set a value in user's classes */
2105 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2106 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2108 /* try to find the value in hkcr */
2109 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2110 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2111 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2113 /* modify the value in hklm */
2114 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2115 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2117 /* check that the value is not overwritten in hkcr or user's classes */
2118 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2119 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2120 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2121 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2122 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2123 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2125 /* modify the value in hkcr */
2126 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2127 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2129 /* check that the value is not overwritten in hklm, but in user's classes */
2130 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2131 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2132 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2133 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2134 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2135 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2137 /* new subkey in hkcr */
2138 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
2139 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
2140 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2141 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2143 /* try to open that new subkey in user's classes and hklm */
2144 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2145 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
2147 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2148 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2150 /* check that the value is present in hklm */
2151 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2152 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2153 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2159 delete_key( hkeysub1 );
2160 delete_key( hklmsub1 );
2161 delete_key( hkcrsub1 );
2162 delete_key( hklmsub2 );
2163 delete_key( hkcrsub2 );
2164 RegCloseKey( hkey );
2165 RegCloseKey( hklm );
2166 RegCloseKey( hkcr );
2167 RegCloseKey( hkeysub1 );
2168 RegCloseKey( hklmsub1 );
2169 RegCloseKey( hkcrsub1 );
2170 RegCloseKey( hklmsub2 );
2171 RegCloseKey( hkcrsub2 );
2174 static void test_deleted_key(void)
2178 DWORD val_count, type;
2181 /* Open the test key, then delete it while it's open */
2182 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
2184 delete_key( hkey_main );
2186 val_count = sizeof(value);
2188 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
2189 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2191 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
2192 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2194 val_count = sizeof(value);
2196 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
2197 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2199 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
2200 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2202 res = RegOpenKeyA( hkey, "test", &hkey2 );
2203 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2205 RegCloseKey( hkey2 );
2207 res = RegCreateKeyA( hkey, "test", &hkey2 );
2208 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2210 RegCloseKey( hkey2 );
2212 res = RegFlushKey( hkey );
2213 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2215 RegCloseKey( hkey );
2220 static void test_delete_value(void)
2225 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
2226 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2228 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2229 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2231 res = RegDeleteValueA( hkey_main, "test" );
2232 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2234 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2235 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2237 res = RegDeleteValueA( hkey_main, "test" );
2238 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2240 memset(longname, 'a', 400);
2242 res = RegDeleteValueA( hkey_main, longname );
2243 ok(res == ERROR_FILE_NOT_FOUND || broken(res == ERROR_MORE_DATA), /* nt4, win2k */
2244 "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2247 START_TEST(registry)
2249 /* Load pointers for functions that are not available in all Windows versions */
2254 create_test_entries();
2256 test_query_value_ex();
2258 test_reg_open_key();
2259 test_reg_create_key();
2260 test_reg_close_key();
2261 test_reg_delete_key();
2262 test_reg_query_value();
2263 test_string_termination();
2268 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2269 if (set_privileges(SE_BACKUP_NAME, TRUE) &&
2270 set_privileges(SE_RESTORE_NAME, TRUE))
2272 test_reg_save_key();
2273 test_reg_load_key();
2274 test_reg_unload_key();
2276 set_privileges(SE_BACKUP_NAME, FALSE);
2277 set_privileges(SE_RESTORE_NAME, FALSE);
2280 test_reg_delete_tree();
2283 test_delete_value();
2286 delete_key( hkey_main );
2288 test_regconnectregistry();