TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / advapi32 / tests / registry.c
blob254a8b662105c08af215b14c068d0227c010ee29
1 /*
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
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include "wine/test.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winternl.h"
29 #include "winreg.h"
30 #include "winsvc.h"
31 #include "winerror.h"
32 #include "aclapi.h"
34 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
36 static HKEY hkey_main;
37 static DWORD GLE;
39 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
40 static const char * sTestpath2 = "%FOO%\\subdir1";
41 static const DWORD ptr_size = 8 * sizeof(void*);
43 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
44 static DWORD (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR);
45 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
46 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
47 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
48 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
49 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
50 static LONG (WINAPI *pRegDeleteKeyValueA)(HKEY,LPCSTR,LPCSTR);
51 static LONG (WINAPI *pRegSetKeyValueW)(HKEY,LPCWSTR,LPCWSTR,DWORD,const void*,DWORD);
53 static BOOL limited_user;
56 /* Debugging functions from wine/libs/wine/debug.c */
58 /* allocate some tmp string space */
59 /* FIXME: this is not 100% thread-safe */
60 static char *get_temp_buffer( int size )
62 static char *list[32];
63 static UINT pos;
64 char *ret;
65 UINT idx;
67 idx = ++pos % (sizeof(list)/sizeof(list[0]));
68 if (list[idx])
69 ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
70 else
71 ret = HeapAlloc( GetProcessHeap(), 0, size );
72 if (ret) list[idx] = ret;
73 return ret;
76 static const char *wine_debugstr_an( const char *str, int n )
78 static const char hex[16] = "0123456789abcdef";
79 char *dst, *res;
80 size_t size;
82 if (!((ULONG_PTR)str >> 16))
84 if (!str) return "(null)";
85 res = get_temp_buffer( 6 );
86 sprintf( res, "#%04x", LOWORD(str) );
87 return res;
89 if (n == -1) n = strlen(str);
90 if (n < 0) n = 0;
91 size = 10 + min( 300, n * 4 );
92 dst = res = get_temp_buffer( size );
93 *dst++ = '"';
94 while (n-- > 0 && dst <= res + size - 9)
96 unsigned char c = *str++;
97 switch (c)
99 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
100 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
101 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
102 case '"': *dst++ = '\\'; *dst++ = '"'; break;
103 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
104 default:
105 if (c >= ' ' && c <= 126)
106 *dst++ = c;
107 else
109 *dst++ = '\\';
110 *dst++ = 'x';
111 *dst++ = hex[(c >> 4) & 0x0f];
112 *dst++ = hex[c & 0x0f];
116 *dst++ = '"';
117 if (n > 0)
119 *dst++ = '.';
120 *dst++ = '.';
121 *dst++ = '.';
123 *dst++ = 0;
124 return res;
127 #define ADVAPI32_GET_PROC(func) \
128 p ## func = (void*)GetProcAddress(hadvapi32, #func)
130 static void InitFunctionPtrs(void)
132 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
133 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
134 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
136 /* This function was introduced with Windows 2003 SP1 */
137 ADVAPI32_GET_PROC(RegGetValueA);
138 ADVAPI32_GET_PROC(RegDeleteTreeA);
139 ADVAPI32_GET_PROC(RegDeleteKeyExA);
140 ADVAPI32_GET_PROC(RegDeleteKeyValueA);
141 ADVAPI32_GET_PROC(RegSetKeyValueW);
143 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
144 pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
145 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
146 pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
149 /* delete key and all its subkeys */
150 static DWORD delete_key( HKEY hkey )
152 char name[MAX_PATH];
153 DWORD ret;
155 if ((ret = RegOpenKeyExA( hkey, "", 0, KEY_ENUMERATE_SUB_KEYS, &hkey ))) return ret;
156 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
158 HKEY tmp;
159 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
161 ret = delete_key( tmp );
162 RegCloseKey( tmp );
164 if (ret) break;
166 if (ret != ERROR_NO_MORE_ITEMS) return ret;
167 RegDeleteKeyA( hkey, "" );
168 RegCloseKey(hkey);
169 return 0;
172 static void setup_main_key(void)
174 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
176 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
179 static void check_user_privs(void)
181 DWORD ret;
182 HKEY hkey = (HKEY)0xdeadbeef;
184 ret = RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WRITE, &hkey);
185 ok(ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED, "expected success or access denied, got %i\n", ret);
186 if (ret == ERROR_SUCCESS)
188 ok(hkey != NULL, "RegOpenKeyExA succeeded but returned NULL hkey\n");
189 RegCloseKey(hkey);
191 else
193 ok(hkey == NULL, "RegOpenKeyExA failed but returned hkey %p\n", hkey);
194 limited_user = TRUE;
195 trace("running as limited user\n");
199 #define lok ok_(__FILE__, line)
200 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
201 static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
202 DWORD full_byte_len)
204 DWORD ret, type, cbData;
205 DWORD str_byte_len;
206 BYTE* value;
208 type=0xdeadbeef;
209 cbData=0xdeadbeef;
210 /* When successful RegQueryValueExA() leaves GLE as is,
211 * so we must reset it to detect unimplemented functions.
213 SetLastError(0xdeadbeef);
214 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
215 GLE = GetLastError();
216 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret, GLE);
217 /* It is wrong for the Ansi version to not be implemented */
218 ok(GLE == 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE);
219 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
221 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
222 lok(type == REG_SZ, "RegQueryValueExA/1 returned type %d\n", type);
223 lok(cbData == full_byte_len, "cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
225 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
226 memset(value, 0xbd, cbData+1);
227 type=0xdeadbeef;
228 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
229 GLE = GetLastError();
230 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
231 if (!string)
233 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
234 lok(*value == 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
236 else
238 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
239 wine_debugstr_an((char*)value, cbData), cbData,
240 wine_debugstr_an(string, full_byte_len), full_byte_len);
241 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
243 HeapFree(GetProcessHeap(), 0, value);
246 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
247 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
248 DWORD full_byte_len)
250 DWORD ret, type, cbData;
251 BYTE* value;
253 type=0xdeadbeef;
254 cbData=0xdeadbeef;
255 /* When successful RegQueryValueExW() leaves GLE as is,
256 * so we must reset it to detect unimplemented functions.
258 SetLastError(0xdeadbeef);
259 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
260 GLE = GetLastError();
261 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
262 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
264 win_skip("RegQueryValueExW() is not implemented\n");
265 return;
268 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
269 lok(cbData == full_byte_len,
270 "cbData=%d instead of %d\n", cbData, full_byte_len);
272 /* Give enough space to overflow by one WCHAR */
273 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
274 memset(value, 0xbd, cbData+2);
275 type=0xdeadbeef;
276 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
277 GLE = GetLastError();
278 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
279 if (string)
281 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
282 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
283 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
285 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
286 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
287 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
288 HeapFree(GetProcessHeap(), 0, value);
291 static void test_set_value(void)
293 DWORD ret;
295 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
296 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};
297 static const WCHAR emptyW[] = {0};
298 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
299 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};
300 static const WCHAR substring2W[] = {'T','h','i','s',0};
302 static const char name1A[] = "CleanSingleString";
303 static const char name2A[] = "SomeIntraZeroedString";
304 static const char emptyA[] = "";
305 static const char string1A[] = "ThisNeverBreaks";
306 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
307 static const char substring2A[] = "This";
309 if (0)
311 /* Crashes on NT4, Windows 2000 and XP SP1 */
312 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
313 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
316 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
317 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
318 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
319 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
321 /* RegSetValueA ignores the size passed in */
322 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
323 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
324 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
325 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
327 /* stops at first null */
328 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
329 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
330 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
331 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
333 /* only REG_SZ is supported on NT*/
334 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
335 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
337 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
338 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
340 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
341 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
343 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
344 * Surprisingly enough we're supposed to get zero bytes out of it.
346 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
347 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
348 test_hkey_main_Value_A(name1A, NULL, 0);
349 test_hkey_main_Value_W(name1W, NULL, 0);
351 /* test RegSetValueExA with an empty string */
352 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
353 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
354 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
355 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
357 /* test RegSetValueExA with off-by-one size */
358 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
359 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
360 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
361 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
363 /* test RegSetValueExA with normal string */
364 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
365 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
366 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
367 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
369 /* test RegSetValueExA with intrazeroed string */
370 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
371 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
372 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
373 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
375 if (0)
377 /* Crashes on NT4, Windows 2000 and XP SP1 */
378 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
379 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
381 RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)1, 1);
382 RegSetValueExA(hkey_main, name2A, 0, REG_DWORD, (const BYTE *)1, 1);
385 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
386 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
387 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
388 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
390 ret = RegSetValueW(hkey_main, name1W, REG_SZ, string1W, sizeof(string1W));
391 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
392 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
393 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
395 /* RegSetValueW ignores the size passed in */
396 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
397 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
398 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
399 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
401 /* stops at first null */
402 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
403 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
404 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
405 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
407 /* only REG_SZ is supported */
408 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
409 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
410 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
411 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
412 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
413 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
415 /* test RegSetValueExW with off-by-one size */
416 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
417 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
418 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
419 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
421 /* test RegSetValueExW with normal string */
422 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
423 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
424 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
425 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
427 /* test RegSetValueExW with intrazeroed string */
428 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
429 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
430 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
431 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
433 /* test RegSetValueExW with data = 1 */
434 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)1, 1);
435 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
436 ret = RegSetValueExW(hkey_main, name2W, 0, REG_DWORD, (const BYTE *)1, 1);
437 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
439 if (pRegGetValueA) /* avoid a crash on Windows 2000 */
441 ret = RegSetValueExW(hkey_main, NULL, 0, REG_SZ, NULL, 4);
442 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
444 ret = RegSetValueExW(hkey_main, NULL, 0, REG_SZ, NULL, 0);
445 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
447 ret = RegSetValueExW(hkey_main, NULL, 0, REG_DWORD, NULL, 4);
448 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
450 ret = RegSetValueExW(hkey_main, NULL, 0, REG_DWORD, NULL, 0);
451 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
454 /* RegSetKeyValue */
455 if (!pRegSetKeyValueW)
456 win_skip("RegSetKeyValue() is not supported.\n");
457 else
459 static const WCHAR subkeyW[] = {'s','u','b','k','e','y',0};
460 DWORD len, type;
461 HKEY subkey;
463 ret = pRegSetKeyValueW(hkey_main, NULL, name1W, REG_SZ, (const BYTE*)string2W, sizeof(string2W));
464 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
465 test_hkey_main_Value_A(name1A, string2A, sizeof(string2A));
466 test_hkey_main_Value_W(name1W, string2W, sizeof(string2W));
468 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_SZ, string1W, sizeof(string1W));
469 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
471 ret = RegOpenKeyExW(hkey_main, subkeyW, 0, KEY_QUERY_VALUE, &subkey);
472 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
473 type = len = 0;
474 ret = RegQueryValueExW(subkey, name1W, 0, &type, NULL, &len);
475 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
476 ok(len == sizeof(string1W), "got %d\n", len);
477 ok(type == REG_SZ, "got type %d\n", type);
479 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_SZ, NULL, 0);
480 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
482 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_SZ, NULL, 4);
483 ok(ret == ERROR_NOACCESS, "got %d\n", ret);
485 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_DWORD, NULL, 4);
486 ok(ret == ERROR_NOACCESS, "got %d\n", ret);
488 RegCloseKey(subkey);
492 static void create_test_entries(void)
494 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
496 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
497 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
499 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
500 "RegSetValueExA failed\n");
501 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
502 "RegSetValueExA failed\n");
503 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
504 "RegSetValueExA failed\n");
505 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
506 "RegSetValueExA failed\n");
507 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
508 "RegSetValueExA failed\n");
509 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
510 "RegSetValueExA failed\n");
511 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
512 "RegSetValueExA failed\n");
515 static void test_enum_value(void)
517 DWORD res;
518 HKEY test_key;
519 char value[20], data[20];
520 WCHAR valueW[20], dataW[20];
521 DWORD val_count, data_count, type;
522 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
523 static const WCHAR testW[] = {'T','e','s','t',0};
524 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
526 /* create the working key for new 'Test' value */
527 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
528 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
530 /* check NULL data with zero length */
531 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
532 if (GetVersion() & 0x80000000)
533 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
534 else
535 ok( !res, "RegSetValueExA returned %d\n", res );
536 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
537 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
538 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
539 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
541 /* test reading the value and data without setting them */
542 val_count = 20;
543 data_count = 20;
544 type = 1234;
545 strcpy( value, "xxxxxxxxxx" );
546 strcpy( data, "xxxxxxxxxx" );
547 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
548 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
549 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
550 ok( data_count == 0, "data_count set to %d instead of 0\n", data_count );
551 ok( type == REG_BINARY, "type %d is not REG_BINARY\n", type );
552 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
553 ok( !strcmp( data, "xxxxxxxxxx" ), "data is '%s' instead of xxxxxxxxxx\n", data );
555 val_count = 20;
556 data_count = 20;
557 type = 1234;
558 memcpy( valueW, xxxW, sizeof(xxxW) );
559 memcpy( dataW, xxxW, sizeof(xxxW) );
560 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
561 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
562 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
563 ok( data_count == 0, "data_count set to %d instead of 0\n", data_count );
564 ok( type == REG_BINARY, "type %d is not REG_BINARY\n", type );
565 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
566 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data is not 'xxxxxxxxxx'\n" );
568 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
569 ok( res == 0, "RegSetValueExA failed error %d\n", res );
571 /* overflow both name and data */
572 val_count = 2;
573 data_count = 2;
574 type = 1234;
575 strcpy( value, "xxxxxxxxxx" );
576 strcpy( data, "xxxxxxxxxx" );
577 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
578 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
579 ok( val_count == 2, "val_count set to %d\n", val_count );
580 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
581 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
582 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
583 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
585 /* overflow name */
586 val_count = 3;
587 data_count = 20;
588 type = 1234;
589 strcpy( value, "xxxxxxxxxx" );
590 strcpy( data, "xxxxxxxxxx" );
591 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
592 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
593 ok( val_count == 3, "val_count set to %d\n", val_count );
594 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
595 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
596 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
597 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
598 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
599 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
600 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
602 /* overflow empty name */
603 val_count = 0;
604 data_count = 20;
605 type = 1234;
606 strcpy( value, "xxxxxxxxxx" );
607 strcpy( data, "xxxxxxxxxx" );
608 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
609 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
610 ok( val_count == 0, "val_count set to %d\n", val_count );
611 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
612 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
613 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
614 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
615 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
616 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
618 /* overflow data */
619 val_count = 20;
620 data_count = 2;
621 type = 1234;
622 strcpy( value, "xxxxxxxxxx" );
623 strcpy( data, "xxxxxxxxxx" );
624 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
625 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
626 ok( val_count == 20, "val_count set to %d\n", val_count );
627 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
628 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
629 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
630 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
632 /* no overflow */
633 val_count = 20;
634 data_count = 20;
635 type = 1234;
636 strcpy( value, "xxxxxxxxxx" );
637 strcpy( data, "xxxxxxxxxx" );
638 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
639 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
640 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
641 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
642 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
643 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
644 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
646 if (pRegGetValueA) /* avoid a crash on Windows 2000 */
648 /* no value and no val_count parameter */
649 data_count = 20;
650 type = 1234;
651 strcpy( data, "xxxxxxxxxx" );
652 res = RegEnumValueA( test_key, 0, NULL, NULL, NULL, &type, (BYTE*)data, &data_count );
653 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
655 /* no value parameter */
656 val_count = 20;
657 data_count = 20;
658 type = 1234;
659 strcpy( data, "xxxxxxxxxx" );
660 res = RegEnumValueA( test_key, 0, NULL, &val_count, NULL, &type, (BYTE*)data, &data_count );
661 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
663 /* no val_count parameter */
664 data_count = 20;
665 type = 1234;
666 strcpy( value, "xxxxxxxxxx" );
667 strcpy( data, "xxxxxxxxxx" );
668 res = RegEnumValueA( test_key, 0, value, NULL, NULL, &type, (BYTE*)data, &data_count );
669 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
672 /* Unicode tests */
674 SetLastError(0xdeadbeef);
675 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
676 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
678 win_skip("RegSetValueExW is not implemented\n");
679 goto cleanup;
681 ok( res == 0, "RegSetValueExW failed error %d\n", res );
683 /* overflow both name and data */
684 val_count = 2;
685 data_count = 2;
686 type = 1234;
687 memcpy( valueW, xxxW, sizeof(xxxW) );
688 memcpy( dataW, xxxW, sizeof(xxxW) );
689 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
690 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
691 ok( val_count == 2, "val_count set to %d\n", val_count );
692 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
693 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
694 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
695 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
697 /* overflow name */
698 val_count = 3;
699 data_count = 20;
700 type = 1234;
701 memcpy( valueW, xxxW, sizeof(xxxW) );
702 memcpy( dataW, xxxW, sizeof(xxxW) );
703 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
704 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
705 ok( val_count == 3, "val_count set to %d\n", val_count );
706 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
707 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
708 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
709 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
711 /* overflow data */
712 val_count = 20;
713 data_count = 2;
714 type = 1234;
715 memcpy( valueW, xxxW, sizeof(xxxW) );
716 memcpy( dataW, xxxW, sizeof(xxxW) );
717 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
718 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
719 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
720 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
721 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
722 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
723 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
725 /* no overflow */
726 val_count = 20;
727 data_count = 20;
728 type = 1234;
729 memcpy( valueW, xxxW, sizeof(xxxW) );
730 memcpy( dataW, xxxW, sizeof(xxxW) );
731 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
732 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
733 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
734 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
735 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
736 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
737 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
739 if (pRegGetValueA) /* avoid a crash on Windows 2000 */
741 /* no valueW and no val_count parameter */
742 data_count = 20;
743 type = 1234;
744 memcpy( dataW, xxxW, sizeof(xxxW) );
745 res = RegEnumValueW( test_key, 0, NULL, NULL, NULL, &type, (BYTE*)dataW, &data_count );
746 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
748 /* no valueW parameter */
749 val_count = 20;
750 data_count = 20;
751 type = 1234;
752 memcpy( dataW, xxxW, sizeof(xxxW) );
753 res = RegEnumValueW( test_key, 0, NULL, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
754 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
756 /* no val_count parameter */
757 data_count = 20;
758 type = 1234;
759 memcpy( valueW, xxxW, sizeof(xxxW) );
760 memcpy( dataW, xxxW, sizeof(xxxW) );
761 res = RegEnumValueW( test_key, 0, valueW, NULL, NULL, &type, (BYTE*)dataW, &data_count );
762 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
765 cleanup:
766 RegDeleteKeyA(test_key, "");
767 RegCloseKey(test_key);
770 static void test_query_value_ex(void)
772 DWORD ret;
773 DWORD size;
774 DWORD type;
775 BYTE buffer[10];
777 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
778 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
779 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
780 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
782 type = 0xdeadbeef;
783 size = 0xdeadbeef;
784 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
785 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
786 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
788 size = sizeof(buffer);
789 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
790 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
791 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
793 size = 4;
794 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
795 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
798 static void test_get_value(void)
800 DWORD ret;
801 DWORD size;
802 DWORD type;
803 DWORD dw, qw[2];
804 CHAR buf[80];
805 CHAR expanded[] = "bar\\subdir1";
806 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
808 if(!pRegGetValueA)
810 win_skip("RegGetValue not available on this platform\n");
811 return;
814 /* Invalid parameter */
815 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
816 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
818 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
819 size = type = dw = 0xdeadbeef;
820 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
821 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
822 ok(size == 4, "size=%d\n", size);
823 ok(type == REG_DWORD, "type=%d\n", type);
824 ok(dw == 0x12345678, "dw=%d\n", dw);
826 /* Query by subkey-name */
827 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
828 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
830 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
831 size = type = dw = 0xdeadbeef;
832 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
833 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
834 /* Although the function failed all values are retrieved */
835 ok(size == 4, "size=%d\n", size);
836 ok(type == REG_DWORD, "type=%d\n", type);
837 ok(dw == 0x12345678, "dw=%d\n", dw);
839 /* Test RRF_ZEROONFAILURE */
840 type = dw = 0xdeadbeef; size = 4;
841 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
842 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
843 /* Again all values are retrieved ... */
844 ok(size == 4, "size=%d\n", size);
845 ok(type == REG_DWORD, "type=%d\n", type);
846 /* ... except the buffer, which is zeroed out */
847 ok(dw == 0, "dw=%d\n", dw);
849 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
850 type = size = 0xbadbeef;
851 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
852 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
853 ok(size == 4, "size=%d\n", size);
854 ok(type == REG_DWORD, "type=%d\n", type);
856 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
857 size = type = dw = 0xdeadbeef;
858 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
859 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
860 ok(size == 4, "size=%d\n", size);
861 ok(type == REG_DWORD, "type=%d\n", type);
862 ok(dw == 0x12345678, "dw=%d\n", dw);
864 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
865 size = type = dw = 0xdeadbeef;
866 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
867 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
868 ok(size == 4, "size=%d\n", size);
869 ok(type == REG_BINARY, "type=%d\n", type);
870 ok(dw == 0x12345678, "dw=%d\n", dw);
872 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
873 qw[0] = qw[1] = size = type = 0xdeadbeef;
874 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
875 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
876 ok(size == 8, "size=%d\n", size);
877 ok(type == REG_BINARY, "type=%d\n", type);
878 ok(qw[0] == 0x12345678 &&
879 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
881 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
882 type = dw = 0xdeadbeef; size = 4;
883 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
884 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
885 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
886 ok(size == 8, "size=%d\n", size);
888 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
889 qw[0] = qw[1] = size = type = 0xdeadbeef;
890 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
891 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
892 ok(size == 8, "size=%d\n", size);
893 ok(type == REG_BINARY, "type=%d\n", type);
894 ok(qw[0] == 0x12345678 &&
895 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
897 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
898 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
899 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
900 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
901 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
902 ok(type == REG_SZ, "type=%d\n", type);
903 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
905 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
906 type = 0xdeadbeef; size = 0;
907 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
908 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
909 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
910 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
911 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
912 ok(type == REG_SZ, "type=%d\n", type);
914 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
915 strcpy(buf, sTestpath1);
916 type = 0xdeadbeef;
917 size = sizeof(buf);
918 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
919 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
920 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
921 ok(size == 0 ||
922 size == 1, /* win2k3 */
923 "size=%d\n", size);
924 ok(type == REG_SZ, "type=%d\n", type);
925 ok(!strcmp(sTestpath1, buf) ||
926 !strcmp(buf, ""),
927 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
929 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
930 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
931 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
932 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
933 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
934 ok(type == REG_SZ, "type=%d\n", type);
935 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
937 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
938 size = 0;
939 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
940 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
941 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
942 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
943 (size == strlen(sTestpath2)+1),
944 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
946 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
947 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
948 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
949 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
950 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
951 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
952 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
953 ok(type == REG_SZ, "type=%d\n", type);
954 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
956 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
957 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
958 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
959 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
960 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
961 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
962 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
963 ok(type == REG_SZ, "type=%d\n", type);
964 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
966 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
967 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
968 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
969 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
970 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
971 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
972 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
974 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
975 size = 0xbadbeef;
976 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
977 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
978 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
979 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
980 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
982 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
983 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
984 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
986 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
987 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
988 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
989 ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
991 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
992 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
993 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
994 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
995 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
996 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
997 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
998 ok(type == REG_SZ, "type=%d\n", type);
999 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
1002 static void test_reg_open_key(void)
1004 DWORD ret = 0;
1005 HKEY hkResult = NULL;
1006 HKEY hkPreserve = NULL;
1007 HKEY hkRoot64 = NULL;
1008 HKEY hkRoot32 = NULL;
1009 BOOL bRet;
1010 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1011 PSID world_sid;
1012 EXPLICIT_ACCESSA access;
1013 PACL key_acl;
1014 SECURITY_DESCRIPTOR *sd;
1016 /* successful open */
1017 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
1018 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1019 ok(hkResult != NULL, "expected hkResult != NULL\n");
1020 hkPreserve = hkResult;
1022 /* open same key twice */
1023 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
1024 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1025 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
1026 ok(hkResult != NULL, "hkResult != NULL\n");
1027 RegCloseKey(hkResult);
1029 /* trailing slashes */
1030 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test\\\\", &hkResult);
1031 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1032 RegCloseKey(hkResult);
1034 /* open nonexistent key
1035 * check that hkResult is set to NULL
1037 hkResult = hkPreserve;
1038 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
1039 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1040 ok(hkResult == NULL, "expected hkResult == NULL\n");
1042 /* open the same nonexistent key again to make sure the key wasn't created */
1043 hkResult = hkPreserve;
1044 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
1045 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1046 ok(hkResult == NULL, "expected hkResult == NULL\n");
1048 /* send in NULL lpSubKey
1049 * check that hkResult receives the value of hKey
1051 hkResult = hkPreserve;
1052 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
1053 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1054 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
1056 /* send empty-string in lpSubKey */
1057 hkResult = hkPreserve;
1058 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
1059 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1060 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
1062 /* send in NULL lpSubKey and NULL hKey
1063 * hkResult is set to NULL
1065 hkResult = hkPreserve;
1066 ret = RegOpenKeyA(NULL, NULL, &hkResult);
1067 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1068 ok(hkResult == NULL, "expected hkResult == NULL\n");
1070 /* only send NULL hKey
1071 * the value of hkResult remains unchanged
1073 hkResult = hkPreserve;
1074 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
1075 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1076 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1077 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
1079 /* send in NULL hkResult */
1080 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
1081 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1083 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
1084 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1086 ret = RegOpenKeyA(NULL, NULL, NULL);
1087 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1089 /* beginning backslash character */
1090 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
1091 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
1092 broken(ret == ERROR_SUCCESS), /* wow64 */
1093 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
1094 if (!ret) RegCloseKey(hkResult);
1096 hkResult = NULL;
1097 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
1098 ok(ret == ERROR_SUCCESS || /* 2k/XP */
1099 ret == ERROR_BAD_PATHNAME, /* NT */
1100 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
1101 RegCloseKey(hkResult);
1103 /* NULL or empty subkey of special root */
1104 hkResult = NULL;
1105 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, NULL, 0, KEY_QUERY_VALUE, &hkResult);
1106 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1107 ok(hkResult == HKEY_CLASSES_ROOT, "expected hkResult == HKEY_CLASSES_ROOT\n");
1109 hkResult = NULL;
1110 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "", 0, KEY_QUERY_VALUE, &hkResult);
1111 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1112 ok(hkResult == HKEY_CLASSES_ROOT, "expected hkResult == HKEY_CLASSES_ROOT\n");
1114 hkResult = NULL;
1115 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\", 0, KEY_QUERY_VALUE, &hkResult);
1116 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1117 ok(hkResult != HKEY_CLASSES_ROOT, "expected hkResult to be a new key\n");
1118 ok(!RegCloseKey(hkResult), "got invalid hkey\n");
1120 /* empty subkey of existing handle */
1121 hkResult = hkPreserve;
1122 ret = RegOpenKeyExA(hkPreserve, "", 0, KEY_QUERY_VALUE, &hkResult);
1123 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1124 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
1125 ok(!RegCloseKey(hkResult), "got invalid hkey\n");
1127 /* NULL subkey of existing handle */
1128 hkResult = hkPreserve;
1129 ret = RegOpenKeyExA(hkPreserve, NULL, 0, KEY_QUERY_VALUE, &hkResult);
1130 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1131 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
1132 ok(!RegCloseKey(hkResult), "got invalid hkey\n");
1134 /* empty subkey of NULL */
1135 hkResult = hkPreserve;
1136 ret = RegOpenKeyExA(NULL, "", 0, KEY_QUERY_VALUE, &hkResult);
1137 ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret);
1138 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
1140 RegCloseKey(hkPreserve);
1142 /* WOW64 flags */
1143 hkResult = NULL;
1144 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
1145 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1146 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1147 RegCloseKey(hkResult);
1149 hkResult = NULL;
1150 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
1151 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1152 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1153 RegCloseKey(hkResult);
1155 /* check special HKEYs on 64bit
1156 * only the lower 4 bytes of the supplied key are used
1158 if (ptr_size == 64)
1160 /* HKEY_CURRENT_USER */
1161 ret = RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER)), "Software", &hkResult);
1162 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1163 ok(hkResult != NULL, "expected hkResult != NULL\n");
1164 RegCloseKey(hkResult);
1166 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)1 << 32), "Software", &hkResult);
1167 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1168 ok(hkResult != NULL, "expected hkResult != NULL\n");
1169 RegCloseKey(hkResult);
1171 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)0xdeadbeef << 32), "Software", &hkResult);
1172 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1173 ok(hkResult != NULL, "expected hkResult != NULL\n");
1174 RegCloseKey(hkResult);
1176 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)0xffffffff << 32), "Software", &hkResult);
1177 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1178 ok(hkResult != NULL, "expected hkResult != NULL\n");
1179 RegCloseKey(hkResult);
1181 /* HKEY_LOCAL_MACHINE */
1182 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_LOCAL_MACHINE) | (ULONG64)0xdeadbeef << 32), "Software", &hkResult);
1183 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1184 ok(hkResult != NULL, "expected hkResult != NULL\n");
1185 RegCloseKey(hkResult);
1188 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1189 * the registry access check is performed correctly. Redirection isn't
1190 * being tested, so the tests don't care about whether the process is
1191 * running under WOW64. */
1192 if (!pIsWow64Process)
1194 win_skip("WOW64 flags are not recognized\n");
1195 return;
1198 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1199 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1200 if (limited_user)
1201 ok(ret == ERROR_ACCESS_DENIED && hkRoot32 == NULL,
1202 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1203 else
1204 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1205 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1207 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1208 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1209 if (limited_user)
1210 ok(ret == ERROR_ACCESS_DENIED && hkRoot64 == NULL,
1211 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1212 else
1213 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1214 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1216 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1217 0, 0, 0, 0, 0, 0, 0, &world_sid);
1218 ok(bRet == TRUE,
1219 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1221 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1222 access.grfAccessMode = SET_ACCESS;
1223 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1224 access.Trustee.pMultipleTrustee = NULL;
1225 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1226 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1227 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1228 access.Trustee.ptstrName = (char *)world_sid;
1230 ret = SetEntriesInAclA(1, &access, NULL, &key_acl);
1231 ok(ret == ERROR_SUCCESS,
1232 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret, GetLastError());
1234 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1235 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1236 ok(bRet == TRUE,
1237 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1239 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1240 ok(bRet == TRUE,
1241 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1243 if (limited_user)
1245 skip("not enough privileges to modify HKLM\n");
1247 else
1249 LONG error;
1251 error = RegSetKeySecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1252 ok(error == ERROR_SUCCESS,
1253 "Expected RegSetKeySecurity to return success, got error %u\n", error);
1255 error = RegSetKeySecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1256 ok(error == ERROR_SUCCESS,
1257 "Expected RegSetKeySecurity to return success, got error %u\n", error);
1259 hkResult = NULL;
1260 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
1261 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1262 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1263 RegCloseKey(hkResult);
1265 hkResult = NULL;
1266 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
1267 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1268 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1269 RegCloseKey(hkResult);
1272 HeapFree(GetProcessHeap(), 0, sd);
1273 LocalFree(key_acl);
1274 FreeSid(world_sid);
1275 RegDeleteKeyA(hkRoot64, "");
1276 RegCloseKey(hkRoot64);
1277 RegDeleteKeyA(hkRoot32, "");
1278 RegCloseKey(hkRoot32);
1281 static void test_reg_create_key(void)
1283 LONG ret;
1284 HKEY hkey1, hkey2;
1285 HKEY hkRoot64 = NULL;
1286 HKEY hkRoot32 = NULL;
1287 DWORD dwRet;
1288 BOOL bRet;
1289 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1290 PSID world_sid;
1291 EXPLICIT_ACCESSA access;
1292 PACL key_acl;
1293 SECURITY_DESCRIPTOR *sd;
1295 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1296 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1297 /* should succeed: all versions of Windows ignore the access rights
1298 * to the parent handle */
1299 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
1300 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1302 /* clean up */
1303 RegDeleteKeyA(hkey2, "");
1304 RegDeleteKeyA(hkey1, "");
1305 RegCloseKey(hkey2);
1306 RegCloseKey(hkey1);
1308 /* test creation of volatile keys */
1309 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
1310 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1311 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1312 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE, "RegCreateKeyExA failed with error %d\n", ret);
1313 if (!ret) RegCloseKey( hkey2 );
1314 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1315 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1316 RegCloseKey(hkey2);
1317 /* should succeed if the key already exists */
1318 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1319 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1321 /* clean up */
1322 RegDeleteKeyA(hkey2, "");
1323 RegDeleteKeyA(hkey1, "");
1324 RegCloseKey(hkey2);
1325 RegCloseKey(hkey1);
1327 /* beginning backslash character */
1328 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1329 if (!(GetVersion() & 0x80000000))
1330 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1331 else {
1332 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1333 RegDeleteKeyA(hkey1, "");
1334 RegCloseKey(hkey1);
1337 /* trailing backslash characters */
1338 ret = RegCreateKeyExA(hkey_main, "Subkey4\\\\", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1339 ok(ret == ERROR_SUCCESS, "RegCreateKeyExA failed with error %d\n", ret);
1340 RegDeleteKeyA(hkey1, "");
1341 RegCloseKey(hkey1);
1343 /* WOW64 flags - open an existing key */
1344 hkey1 = NULL;
1345 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1346 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1347 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1348 RegCloseKey(hkey1);
1350 hkey1 = NULL;
1351 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1352 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1353 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1354 RegCloseKey(hkey1);
1356 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1357 * the registry access check is performed correctly. Redirection isn't
1358 * being tested, so the tests don't care about whether the process is
1359 * running under WOW64. */
1360 if (!pIsWow64Process)
1362 win_skip("WOW64 flags are not recognized\n");
1363 return;
1366 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1367 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1368 if (limited_user)
1369 ok(ret == ERROR_ACCESS_DENIED && hkRoot32 == NULL,
1370 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1371 else
1372 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1373 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1375 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1376 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1377 if (limited_user)
1378 ok(ret == ERROR_ACCESS_DENIED && hkRoot64 == NULL,
1379 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1380 else
1381 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1382 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1384 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1385 0, 0, 0, 0, 0, 0, 0, &world_sid);
1386 ok(bRet == TRUE,
1387 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1389 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1390 access.grfAccessMode = SET_ACCESS;
1391 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1392 access.Trustee.pMultipleTrustee = NULL;
1393 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1394 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1395 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1396 access.Trustee.ptstrName = (char *)world_sid;
1398 dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
1399 ok(dwRet == ERROR_SUCCESS,
1400 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
1402 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1403 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1404 ok(bRet == TRUE,
1405 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1407 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1408 ok(bRet == TRUE,
1409 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1411 if (limited_user)
1413 skip("not enough privileges to modify HKLM\n");
1415 else
1417 ret = RegSetKeySecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1418 ok(ret == ERROR_SUCCESS,
1419 "Expected RegSetKeySecurity to return success, got error %u\n", ret);
1421 ret = RegSetKeySecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1422 ok(ret == ERROR_SUCCESS,
1423 "Expected RegSetKeySecurity to return success, got error %u\n", ret);
1425 hkey1 = NULL;
1426 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1427 KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
1428 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1429 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1430 RegCloseKey(hkey1);
1432 hkey1 = NULL;
1433 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1434 KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
1435 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1436 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1437 RegCloseKey(hkey1);
1440 HeapFree(GetProcessHeap(), 0, sd);
1441 LocalFree(key_acl);
1442 FreeSid(world_sid);
1443 RegDeleteKeyA(hkRoot64, "");
1444 RegCloseKey(hkRoot64);
1445 RegDeleteKeyA(hkRoot32, "");
1446 RegCloseKey(hkRoot32);
1449 static void test_reg_close_key(void)
1451 DWORD ret = 0;
1452 HKEY hkHandle;
1454 /* successfully close key
1455 * hkHandle remains changed after call to RegCloseKey
1457 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1458 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1459 ret = RegCloseKey(hkHandle);
1460 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1462 /* try to close the key twice */
1463 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1464 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1465 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1467 /* try to close a NULL handle */
1468 ret = RegCloseKey(NULL);
1469 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1470 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1472 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1473 * win98 doesn't give a new handle when the same key is opened.
1474 * Not re-opening will make some next tests fail.
1476 if (hkey_main == hkHandle)
1478 trace("The main handle is most likely closed, so re-opening\n");
1479 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1483 static void test_reg_delete_key(void)
1485 DWORD ret;
1486 HKEY key;
1488 ret = RegDeleteKeyA(hkey_main, NULL);
1490 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1491 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1492 * Not re-creating will make some next tests fail.
1494 if (ret == ERROR_SUCCESS)
1496 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1497 " re-creating the main key\n");
1498 setup_main_key();
1500 else
1501 ok(ret == ERROR_INVALID_PARAMETER ||
1502 ret == ERROR_ACCESS_DENIED ||
1503 ret == ERROR_BADKEY, /* Win95 */
1504 "ret=%d\n", ret);
1506 ret = RegCreateKeyA(hkey_main, "deleteme", &key);
1507 ok(ret == ERROR_SUCCESS, "Could not create key, got %d\n", ret);
1508 ret = RegDeleteKeyA(key, "");
1509 ok(ret == ERROR_SUCCESS, "RegDeleteKeyA failed, got %d\n", ret);
1510 RegCloseKey(key);
1511 ret = RegOpenKeyA(hkey_main, "deleteme", &key);
1512 ok(ret == ERROR_FILE_NOT_FOUND, "Key was not deleted, got %d\n", ret);
1513 RegCloseKey(key);
1516 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1518 TOKEN_PRIVILEGES tp;
1519 HANDLE hToken;
1520 LUID luid;
1522 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1523 return FALSE;
1525 if(!LookupPrivilegeValueA(NULL, privilege, &luid))
1527 CloseHandle(hToken);
1528 return FALSE;
1531 tp.PrivilegeCount = 1;
1532 tp.Privileges[0].Luid = luid;
1534 if (set)
1535 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1536 else
1537 tp.Privileges[0].Attributes = 0;
1539 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1540 if (GetLastError() != ERROR_SUCCESS)
1542 CloseHandle(hToken);
1543 return FALSE;
1546 CloseHandle(hToken);
1547 return TRUE;
1550 static void test_reg_save_key(void)
1552 DWORD ret;
1554 if (!set_privileges(SE_BACKUP_NAME, TRUE) ||
1555 !set_privileges(SE_RESTORE_NAME, FALSE))
1557 win_skip("Failed to set SE_BACKUP_NAME privileges, skipping tests\n");
1558 return;
1561 ret = RegSaveKeyA(hkey_main, "saved_key", NULL);
1562 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1564 set_privileges(SE_BACKUP_NAME, FALSE);
1567 static void test_reg_load_key(void)
1569 DWORD ret;
1570 HKEY hkHandle;
1572 if (!set_privileges(SE_RESTORE_NAME, TRUE) ||
1573 !set_privileges(SE_BACKUP_NAME, FALSE))
1575 win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n");
1576 return;
1579 ret = RegLoadKeyA(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1580 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1582 set_privileges(SE_RESTORE_NAME, FALSE);
1584 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1585 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1587 RegCloseKey(hkHandle);
1590 static void test_reg_unload_key(void)
1592 DWORD ret;
1594 if (!set_privileges(SE_RESTORE_NAME, TRUE) ||
1595 !set_privileges(SE_BACKUP_NAME, FALSE))
1597 win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n");
1598 return;
1601 ret = RegUnLoadKeyA(HKEY_LOCAL_MACHINE, "Test");
1602 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1604 set_privileges(SE_RESTORE_NAME, FALSE);
1606 DeleteFileA("saved_key");
1607 DeleteFileA("saved_key.LOG");
1610 /* tests that show that RegConnectRegistry and
1611 OpenSCManager accept computer names without the
1612 \\ prefix (what MSDN says). */
1613 static void test_regconnectregistry( void)
1615 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1616 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1617 DWORD len = sizeof(compName) ;
1618 BOOL ret;
1619 LONG retl;
1620 HKEY hkey;
1621 SC_HANDLE schnd;
1623 SetLastError(0xdeadbeef);
1624 ret = GetComputerNameA(compName, &len);
1625 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1626 if( !ret) return;
1628 lstrcpyA(netwName, "\\\\");
1629 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1631 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1632 ok( !retl ||
1633 retl == ERROR_DLL_INIT_FAILED ||
1634 retl == ERROR_BAD_NETPATH, /* some win2k */
1635 "RegConnectRegistryA failed err = %d\n", retl);
1636 if( !retl) RegCloseKey( hkey);
1638 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1639 ok( !retl ||
1640 retl == ERROR_DLL_INIT_FAILED ||
1641 retl == ERROR_BAD_NETPATH, /* some win2k */
1642 "RegConnectRegistryA failed err = %d\n", retl);
1643 if( !retl) RegCloseKey( hkey);
1645 SetLastError(0xdeadbeef);
1646 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1647 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1649 win_skip("OpenSCManagerA is not implemented\n");
1650 return;
1653 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1654 CloseServiceHandle( schnd);
1656 SetLastError(0xdeadbeef);
1657 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1658 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1659 CloseServiceHandle( schnd);
1663 static void test_reg_query_value(void)
1665 HKEY subkey;
1666 CHAR val[MAX_PATH];
1667 WCHAR valW[5];
1668 LONG size, ret;
1670 static const WCHAR expected[] = {'d','a','t','a',0};
1672 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1673 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1675 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1676 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1678 /* try an invalid hkey */
1679 SetLastError(0xdeadbeef);
1680 size = MAX_PATH;
1681 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1682 ok(ret == ERROR_INVALID_HANDLE ||
1683 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1684 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1685 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1686 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1688 /* try a NULL hkey */
1689 SetLastError(0xdeadbeef);
1690 size = MAX_PATH;
1691 ret = RegQueryValueA(NULL, "subkey", val, &size);
1692 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1693 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1694 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1696 /* try a NULL value */
1697 size = MAX_PATH;
1698 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1699 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1700 ok(size == 5, "Expected 5, got %d\n", size);
1702 /* try a NULL size */
1703 SetLastError(0xdeadbeef);
1704 val[0] = '\0';
1705 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1706 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1707 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1708 ok(!val[0], "Expected val to be untouched, got %s\n", val);
1710 /* try a NULL value and size */
1711 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1712 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1714 /* try a size too small */
1715 SetLastError(0xdeadbeef);
1716 val[0] = '\0';
1717 size = 1;
1718 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1719 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1720 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1721 ok(!val[0], "Expected val to be untouched, got %s\n", val);
1722 ok(size == 5, "Expected 5, got %d\n", size);
1724 /* successfully read the value using 'subkey' */
1725 size = MAX_PATH;
1726 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1727 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1728 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1729 ok(size == 5, "Expected 5, got %d\n", size);
1731 /* successfully read the value using the subkey key */
1732 size = MAX_PATH;
1733 ret = RegQueryValueA(subkey, NULL, val, &size);
1734 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1735 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1736 ok(size == 5, "Expected 5, got %d\n", size);
1738 /* unicode - try size too small */
1739 SetLastError(0xdeadbeef);
1740 valW[0] = '\0';
1741 size = 0;
1742 ret = RegQueryValueW(subkey, NULL, valW, &size);
1743 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1745 win_skip("RegQueryValueW is not implemented\n");
1746 goto cleanup;
1748 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1749 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1750 ok(!valW[0], "Expected valW to be untouched\n");
1751 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1753 /* unicode - try size in WCHARS */
1754 SetLastError(0xdeadbeef);
1755 size = sizeof(valW) / sizeof(WCHAR);
1756 ret = RegQueryValueW(subkey, NULL, valW, &size);
1757 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1758 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1759 ok(!valW[0], "Expected valW to be untouched\n");
1760 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1762 /* unicode - successfully read the value */
1763 size = sizeof(valW);
1764 ret = RegQueryValueW(subkey, NULL, valW, &size);
1765 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1766 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1767 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1769 /* unicode - set the value without a NULL terminator */
1770 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1771 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1773 /* unicode - read the unterminated value, value is terminated for us */
1774 memset(valW, 'a', sizeof(valW));
1775 size = sizeof(valW);
1776 ret = RegQueryValueW(subkey, NULL, valW, &size);
1777 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1778 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1779 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1781 cleanup:
1782 RegDeleteKeyA(subkey, "");
1783 RegCloseKey(subkey);
1786 static void test_reg_query_info(void)
1788 HKEY subkey;
1789 HKEY subsubkey;
1790 LONG ret;
1791 char classbuffer[32];
1792 WCHAR classbufferW[32];
1793 char expectbuffer[32];
1794 WCHAR expectbufferW[32];
1795 char subkey_class[] = "subkey class";
1796 WCHAR subkey_classW[] = {'s','u','b','k','e','y',' ','c','l','a','s','s',0};
1797 char subsubkey_class[] = "subsubkey class";
1798 DWORD classlen;
1799 DWORD subkeys, maxsubkeylen, maxclasslen;
1800 DWORD values, maxvaluenamelen, maxvaluelen;
1801 DWORD sdlen;
1802 FILETIME lastwrite;
1804 ret = RegCreateKeyExA(hkey_main, "subkey", 0, subkey_class, 0, KEY_ALL_ACCESS, NULL, &subkey, NULL);
1805 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1807 /* all parameters NULL */
1808 ret = RegQueryInfoKeyA(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1809 ok(ret == ERROR_INVALID_HANDLE, "ret = %d\n", ret);
1811 ret = RegQueryInfoKeyW(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1812 ok(ret == ERROR_INVALID_HANDLE, "ret = %d\n", ret);
1814 /* not requesting any information */
1815 ret = RegQueryInfoKeyA(subkey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1816 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1818 ret = RegQueryInfoKeyW(subkey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1819 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1821 /* class without length is invalid */
1822 memset(classbuffer, 0x55, sizeof(classbuffer));
1823 ret = RegQueryInfoKeyA(subkey, classbuffer, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1824 ok(ret == ERROR_INVALID_PARAMETER, "ret = %d\n", ret);
1825 ok(classbuffer[0] == 0x55, "classbuffer[0] = 0x%x\n", classbuffer[0]);
1827 memset(classbufferW, 0x55, sizeof(classbufferW));
1828 ret = RegQueryInfoKeyW(subkey, classbufferW, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1829 ok(ret == ERROR_INVALID_PARAMETER, "ret = %d\n", ret);
1830 ok(classbufferW[0] == 0x5555, "classbufferW[0] = 0x%x\n", classbufferW[0]);
1832 /* empty key */
1833 sdlen = 0;
1834 ret = RegQueryInfoKeyA(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1835 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1836 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1837 ok(subkeys == 0, "subkeys = %u\n", subkeys);
1838 ok(maxsubkeylen == 0, "maxsubkeylen = %u\n", maxsubkeylen);
1839 ok(maxclasslen == 0, "maxclasslen = %u\n", maxclasslen);
1840 ok(values == 0, "values = %u\n", values);
1841 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1842 ok(maxvaluelen == 0, "maxvaluelen = %u\n", maxvaluelen);
1843 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1844 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1845 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1847 sdlen = 0;
1848 ret = RegQueryInfoKeyW(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1849 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1850 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1851 ok(subkeys == 0, "subkeys = %u\n", subkeys);
1852 ok(maxsubkeylen == 0, "maxsubkeylen = %u\n", maxsubkeylen);
1853 ok(maxclasslen == 0, "maxclasslen = %u\n", maxclasslen);
1854 ok(values == 0, "values = %u\n", values);
1855 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1856 ok(maxvaluelen == 0, "maxvaluelen = %u\n", maxvaluelen);
1857 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1858 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1859 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1861 ret = RegCreateKeyExA(subkey, "subsubkey", 0, subsubkey_class, 0, KEY_ALL_ACCESS, NULL, &subsubkey, NULL);
1862 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1864 ret = RegSetValueExA(subkey, NULL, 0, REG_SZ, (const BYTE*)"data", 5);
1865 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1867 /* with subkey & default value */
1868 sdlen = 0;
1869 ret = RegQueryInfoKeyA(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1870 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1871 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1872 ok(subkeys == 1, "subkeys = %u\n", subkeys);
1873 ok(maxsubkeylen == strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen);
1874 ok(maxclasslen == strlen(subsubkey_class), "maxclasslen = %u\n", maxclasslen);
1875 ok(values == 1, "values = %u\n", values);
1876 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1877 ok(maxvaluelen == sizeof("data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1878 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1879 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1880 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1882 sdlen = 0;
1883 ret = RegQueryInfoKeyW(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1884 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1885 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1886 ok(subkeys == 1, "subkeys = %u\n", subkeys);
1887 ok(maxsubkeylen == strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen);
1888 ok(maxclasslen == strlen(subsubkey_class), "maxclasslen = %u\n", maxclasslen);
1889 ok(values == 1, "values = %u\n", values);
1890 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1891 ok(maxvaluelen == sizeof("data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1892 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1893 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1894 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1896 ret = RegSetValueExA(subkey, "value one", 0, REG_SZ, (const BYTE*)"first value data", 17);
1897 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1899 ret = RegSetValueExA(subkey, "value 2", 0, REG_SZ, (const BYTE*)"second value data", 18);
1900 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1902 /* with named value */
1903 ret = RegQueryInfoKeyA(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1904 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1905 ok(values == 3, "values = %u\n", values);
1906 ok(maxvaluenamelen == strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen);
1907 ok(maxvaluelen == sizeof("second value data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1909 ret = RegQueryInfoKeyW(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1910 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1911 ok(values == 3, "values = %u\n", values);
1912 ok(maxvaluenamelen == strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen);
1913 ok(maxvaluelen == sizeof("second value data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1915 /* class name with zero size buffer */
1916 memset(classbuffer, 0x55, sizeof(classbuffer));
1917 classlen = 0;
1918 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1919 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1920 ok(classlen == strlen(subkey_class) /* win2k */ ||
1921 classlen == 0, "classlen = %u\n", classlen);
1922 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1923 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)), "classbuffer was modified\n");
1925 memset(classbufferW, 0x55, sizeof(classbufferW));
1926 classlen = 0;
1927 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1928 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1929 ok(classlen == strlen(subkey_class) /* win2k */ ||
1930 classlen == 0, "classlen = %u\n", classlen);
1931 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1932 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)), "classbufferW was modified\n");
1934 /* class name with one char buffer */
1935 memset(classbuffer, 0x55, sizeof(classbuffer));
1936 classlen = 1;
1937 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1938 ok(ret == ERROR_MORE_DATA, "ret = %d\n", ret);
1939 ok(classlen == 0, "classlen = %u\n", classlen);
1940 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1941 expectbuffer[0] = 0;
1942 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)), "classbuffer was modified\n");
1944 memset(classbufferW, 0x55, sizeof(classbufferW));
1945 classlen = 1;
1946 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1947 ok(ret == ERROR_INSUFFICIENT_BUFFER, "ret = %d\n", ret);
1948 ok(classlen == 0 /* win8 */ ||
1949 classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1950 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1951 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)), "classbufferW was modified\n");
1953 /* class name with buffer one char too small */
1954 memset(classbuffer, 0x55, sizeof(classbuffer));
1955 classlen = sizeof(subkey_class) - 1;
1956 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1957 ok(ret == ERROR_MORE_DATA, "ret = %d\n", ret);
1958 ok(classlen == sizeof(subkey_class) - 2, "classlen = %u\n", classlen);
1959 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1960 strcpy(expectbuffer, subkey_class);
1961 expectbuffer[sizeof(subkey_class) - 2] = 0;
1962 expectbuffer[sizeof(subkey_class) - 1] = 0x55;
1963 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)),
1964 "classbuffer = %.*s, expected %s\n",
1965 (int)sizeof(classbuffer), classbuffer, expectbuffer);
1967 memset(classbufferW, 0x55, sizeof(classbufferW));
1968 classlen = sizeof(subkey_class) - 1;
1969 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1970 ok(ret == ERROR_INSUFFICIENT_BUFFER, "ret = %d\n", ret);
1971 ok(classlen == sizeof(subkey_class) - 2 /* win8 */ ||
1972 classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1973 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1974 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)), "classbufferW was modified\n");
1976 /* class name with large enough buffer */
1977 memset(classbuffer, 0x55, sizeof(classbuffer));
1978 classlen = sizeof(subkey_class);
1979 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1980 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1981 ok(classlen == sizeof(subkey_class) - 1, "classlen = %u\n", classlen);
1982 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1983 strcpy(expectbuffer, subkey_class);
1984 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)),
1985 "classbuffer = \"%.*s\", expected %s\n",
1986 (int)sizeof(classbuffer), classbuffer, expectbuffer);
1988 memset(classbufferW, 0x55, sizeof(classbufferW));
1989 classlen = sizeof(subkey_class);
1990 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1991 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1992 ok(classlen == sizeof(subkey_class) - 1, "classlen = %u\n", classlen);
1993 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1994 lstrcpyW(expectbufferW, subkey_classW);
1995 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)),
1996 "classbufferW = %s, expected %s\n",
1997 wine_dbgstr_wn(classbufferW, sizeof(classbufferW) / sizeof(WCHAR)), wine_dbgstr_w(expectbufferW));
1999 RegDeleteKeyA(subsubkey, "");
2000 RegCloseKey(subsubkey);
2001 RegDeleteKeyA(subkey, "");
2002 RegCloseKey(subkey);
2005 static void test_string_termination(void)
2007 HKEY subkey;
2008 LSTATUS ret;
2009 static const char string[] = "FullString";
2010 char name[11];
2011 BYTE buffer[11];
2012 DWORD insize, outsize, nsize;
2014 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
2015 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2017 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
2018 insize=sizeof(string)-1;
2019 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
2020 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
2021 outsize=insize;
2022 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
2023 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
2025 /* Off-by-two RegSetValueExA -> no trailing '\0' */
2026 insize=sizeof(string)-2;
2027 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
2028 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
2029 outsize=0;
2030 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
2031 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
2032 ok(outsize == insize, "wrong size %u != %u\n", outsize, insize);
2034 /* RegQueryValueExA may return a string with no trailing '\0' */
2035 outsize=insize;
2036 memset(buffer, 0xbd, sizeof(buffer));
2037 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
2038 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
2039 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2040 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2041 wine_debugstr_an((char*)buffer, outsize), outsize, string);
2042 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2044 /* RegQueryValueExA adds a trailing '\0' if there is room */
2045 outsize=insize+1;
2046 memset(buffer, 0xbd, sizeof(buffer));
2047 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
2048 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
2049 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2050 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2051 wine_debugstr_an((char*)buffer, outsize), outsize, string);
2052 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2054 /* RegEnumValueA may return a string with no trailing '\0' */
2055 outsize=insize;
2056 memset(buffer, 0xbd, sizeof(buffer));
2057 nsize=sizeof(name);
2058 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
2059 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
2060 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
2061 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2062 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2063 wine_debugstr_an((char*)buffer, outsize), outsize, string);
2064 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2066 /* RegEnumValueA adds a trailing '\0' if there is room */
2067 outsize=insize+1;
2068 memset(buffer, 0xbd, sizeof(buffer));
2069 nsize=sizeof(name);
2070 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
2071 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
2072 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
2073 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2074 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2075 wine_debugstr_an((char*)buffer, outsize), outsize, string);
2076 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2078 RegDeleteKeyA(subkey, "");
2079 RegCloseKey(subkey);
2082 static void test_reg_delete_tree(void)
2084 CHAR buffer[MAX_PATH];
2085 HKEY subkey, subkey2;
2086 LONG size, ret;
2088 if(!pRegDeleteTreeA) {
2089 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
2090 return;
2093 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
2094 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2095 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
2096 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2097 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
2098 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2099 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
2100 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2101 ret = RegCloseKey(subkey2);
2102 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2104 ret = pRegDeleteTreeA(subkey, "subkey2");
2105 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2106 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
2107 "subkey2 was not deleted\n");
2108 size = MAX_PATH;
2109 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
2110 "Default value of subkey not longer present\n");
2112 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
2113 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2114 ret = RegCloseKey(subkey2);
2115 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2116 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
2117 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2118 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
2119 "subkey2 was not deleted\n");
2120 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
2121 "Default value of subkey not longer present\n");
2123 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
2124 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2125 ret = RegCloseKey(subkey2);
2126 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2127 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
2128 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2129 ret = RegCloseKey(subkey2);
2130 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2131 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
2132 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2133 ret = pRegDeleteTreeA(subkey, NULL);
2134 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2135 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
2136 "subkey was deleted\n");
2137 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
2138 "subkey2 was not deleted\n");
2139 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
2140 "subkey3 was not deleted\n");
2141 size = MAX_PATH;
2142 ret = RegQueryValueA(subkey, NULL, buffer, &size);
2143 ok(ret == ERROR_SUCCESS,
2144 "Default value of subkey is not present\n");
2145 ok(!buffer[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
2146 size = MAX_PATH;
2147 ok(RegQueryValueA(subkey, "value", buffer, &size),
2148 "Value is still present\n");
2150 ret = pRegDeleteTreeA(hkey_main, "not-here");
2151 ok(ret == ERROR_FILE_NOT_FOUND,
2152 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
2155 static void test_rw_order(void)
2157 HKEY hKey;
2158 DWORD dw = 0;
2159 static const char keyname[] = "test_rw_order";
2160 char value_buf[2];
2161 DWORD values, value_len, value_name_max_len;
2162 LSTATUS ret;
2164 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
2165 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
2166 if(ret != ERROR_SUCCESS) {
2167 skip("Couldn't create key. Skipping.\n");
2168 return;
2171 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2172 "RegSetValueExA for value \"A\" failed\n");
2173 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2174 "RegSetValueExA for value \"C\" failed\n");
2175 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2176 "RegSetValueExA for value \"D\" failed\n");
2177 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2178 "RegSetValueExA for value \"B\" failed\n");
2180 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
2181 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
2182 ok(values == 4, "Expected 4 values, got %u\n", values);
2184 /* Value enumeration preserves RegSetValueEx call order */
2185 value_len = 2;
2186 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2187 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
2188 value_len = 2;
2189 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2190 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
2191 value_len = 2;
2192 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2193 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
2194 value_len = 2;
2195 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2196 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
2198 ok(!RegDeleteKeyA(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
2201 static void test_symlinks(void)
2203 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
2204 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
2205 BYTE buffer[1024];
2206 UNICODE_STRING target_str;
2207 WCHAR *target;
2208 HKEY key, link;
2209 NTSTATUS status;
2210 DWORD target_len, type, len, dw, err;
2212 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
2214 win_skip( "Can't perform symlink tests\n" );
2215 return;
2218 pRtlFormatCurrentUserKeyPath( &target_str );
2220 target_len = target_str.Length + sizeof(targetW);
2221 target = HeapAlloc( GetProcessHeap(), 0, target_len );
2222 memcpy( target, target_str.Buffer, target_str.Length );
2223 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
2225 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
2226 KEY_ALL_ACCESS, NULL, &link, NULL );
2227 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
2229 /* REG_SZ is not allowed */
2230 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
2231 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
2232 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
2233 (BYTE *)target, target_len - sizeof(WCHAR) );
2234 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
2235 /* other values are not allowed */
2236 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
2237 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
2239 /* try opening the target through the link */
2241 err = RegOpenKeyA( hkey_main, "link", &key );
2242 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
2244 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
2245 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
2247 dw = 0xbeef;
2248 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
2249 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
2250 RegCloseKey( key );
2252 err = RegOpenKeyA( hkey_main, "link", &key );
2253 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
2255 len = sizeof(buffer);
2256 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
2257 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
2258 ok( len == sizeof(DWORD), "wrong len %u\n", len );
2260 len = sizeof(buffer);
2261 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2262 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
2264 /* REG_LINK can be created in non-link keys */
2265 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
2266 (BYTE *)target, target_len - sizeof(WCHAR) );
2267 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
2268 len = sizeof(buffer);
2269 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2270 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2271 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
2272 err = RegDeleteValueA( key, "SymbolicLinkValue" );
2273 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
2275 RegCloseKey( key );
2277 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
2278 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
2280 len = sizeof(buffer);
2281 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
2282 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2283 ok( len == sizeof(DWORD), "wrong len %u\n", len );
2285 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2286 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
2287 RegCloseKey( key );
2289 /* now open the symlink itself */
2291 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
2292 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
2293 len = sizeof(buffer);
2294 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2295 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2296 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
2297 RegCloseKey( key );
2299 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
2300 KEY_ALL_ACCESS, NULL, &key, NULL );
2301 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
2302 len = sizeof(buffer);
2303 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2304 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2305 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
2306 RegCloseKey( key );
2308 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
2309 KEY_ALL_ACCESS, NULL, &key, NULL );
2310 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
2312 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
2313 KEY_ALL_ACCESS, NULL, &key, NULL );
2314 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
2316 err = RegDeleteKeyA( hkey_main, "target" );
2317 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
2319 err = RegDeleteKeyA( hkey_main, "link" );
2320 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
2322 status = pNtDeleteKey( link );
2323 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
2324 RegCloseKey( link );
2326 HeapFree( GetProcessHeap(), 0, target );
2327 pRtlFreeUnicodeString( &target_str );
2330 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
2332 HKEY key;
2333 DWORD err, type, dw, len = sizeof(dw);
2335 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
2336 if (err == ERROR_FILE_NOT_FOUND) return 0;
2337 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
2339 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
2340 if (err == ERROR_FILE_NOT_FOUND)
2341 dw = 0;
2342 else
2343 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
2344 RegCloseKey( key );
2345 return dw;
2348 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
2350 DWORD dw = get_key_value( root, name, flags );
2351 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
2353 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
2355 static void test_redirection(void)
2357 DWORD err, type, dw, len;
2358 HKEY key, root32, root64, key32, key64, native, op_key;
2359 BOOL is_vista = FALSE;
2360 REGSAM opposite = (sizeof(void*) == 8 ? KEY_WOW64_32KEY : KEY_WOW64_64KEY);
2362 if (ptr_size != 64)
2364 BOOL is_wow64;
2365 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
2367 skip( "Not on Wow64, no redirection\n" );
2368 return;
2372 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2373 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
2374 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2376 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2377 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
2378 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2380 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
2381 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
2382 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2384 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
2385 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
2386 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2388 dw = 64;
2389 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
2390 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
2392 dw = 32;
2393 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
2394 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
2396 dw = 0;
2397 len = sizeof(dw);
2398 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
2399 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
2400 ok( dw == 32, "wrong value %u\n", dw );
2402 dw = 0;
2403 len = sizeof(dw);
2404 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
2405 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
2406 ok( dw == 64, "wrong value %u\n", dw );
2408 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2409 KEY_ALL_ACCESS, NULL, &key, NULL );
2410 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2412 if (ptr_size == 32)
2414 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2415 /* the new (and simpler) Win7 mechanism doesn't */
2416 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2418 trace( "using Vista-style Wow6432Node handling\n" );
2419 is_vista = TRUE;
2421 check_key_value( key, "Wine\\Winetest", 0, 32 );
2422 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2423 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2424 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
2425 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
2426 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
2428 else
2430 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
2432 trace( "using Vista-style Wow6432Node handling\n" );
2433 is_vista = TRUE;
2435 check_key_value( key, "Wine\\Winetest", 0, 64 );
2436 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2438 RegCloseKey( key );
2440 if (ptr_size == 32)
2442 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2443 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2444 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2445 dw = get_key_value( key, "Wine\\Winetest", 0 );
2446 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2447 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2448 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2449 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2450 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
2451 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
2452 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2453 RegCloseKey( key );
2455 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2456 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2457 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2458 check_key_value( key, "Wine\\Winetest", 0, 32 );
2459 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2460 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2461 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
2462 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
2463 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
2464 RegCloseKey( key );
2466 else
2468 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2469 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2470 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2471 check_key_value( key, "Wine\\Winetest", 0, 64 );
2472 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2473 dw = get_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY );
2474 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2475 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2476 RegCloseKey( key );
2478 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2479 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2480 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2481 check_key_value( key, "Wine\\Winetest", 0, 32 );
2482 dw = get_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY );
2483 ok( dw == 32 || broken(dw == 64) /* vista */, "wrong value %u\n", dw );
2484 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2485 RegCloseKey( key );
2488 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
2489 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2490 if (ptr_size == 64)
2492 /* KEY_WOW64 flags have no effect on 64-bit */
2493 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2494 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2495 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2496 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2498 else
2500 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2501 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2502 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2503 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2506 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2507 KEY_ALL_ACCESS, NULL, &key, NULL );
2508 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2509 check_key_value( key, "Wine\\Winetest", 0, 32 );
2510 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2511 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2512 RegCloseKey( key );
2514 if (ptr_size == 32)
2516 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2517 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2518 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2519 dw = get_key_value( key, "Wine\\Winetest", 0 );
2520 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2521 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2522 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2523 RegCloseKey( key );
2525 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2526 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2527 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2528 check_key_value( key, "Wine\\Winetest", 0, 32 );
2529 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2530 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2531 RegCloseKey( key );
2534 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2535 KEY_ALL_ACCESS, NULL, &key, NULL );
2536 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2537 check_key_value( key, "Winetest", 0, 32 );
2538 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2539 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2540 RegCloseKey( key );
2542 if (ptr_size == 32)
2544 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2545 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2546 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2547 dw = get_key_value( key, "Winetest", 0 );
2548 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
2549 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2550 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2551 RegCloseKey( key );
2553 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2554 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2555 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2556 check_key_value( key, "Winetest", 0, 32 );
2557 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2558 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2559 RegCloseKey( key );
2562 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2563 KEY_ALL_ACCESS, NULL, &key, NULL );
2564 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2565 check_key_value( key, "Winetest", 0, ptr_size );
2566 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
2567 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2568 if (ptr_size == 32) ok( dw == 32, "wrong value %u\n", dw );
2569 else todo_wine ok( dw == 32, "wrong value %u\n", dw );
2570 RegCloseKey( key );
2572 if (ptr_size == 32)
2574 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2575 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2576 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2577 dw = get_key_value( key, "Winetest", 0 );
2578 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2579 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
2580 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2581 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2582 RegCloseKey( key );
2584 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2585 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2586 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2587 check_key_value( key, "Winetest", 0, 32 );
2588 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2589 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2590 RegCloseKey( key );
2593 if (pRegDeleteKeyExA)
2595 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
2596 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2597 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2598 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2599 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2600 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
2602 else
2604 err = RegDeleteKeyA( key32, "" );
2605 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2606 err = RegDeleteKeyA( key64, "" );
2607 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2608 RegDeleteKeyA( key64, "" );
2609 RegDeleteKeyA( root64, "" );
2611 RegCloseKey( key32 );
2612 RegCloseKey( key64 );
2613 RegCloseKey( root32 );
2614 RegCloseKey( root64 );
2616 /* open key in native bit mode */
2617 err = RegOpenKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, KEY_ALL_ACCESS, &native);
2618 ok(err == ERROR_SUCCESS, "got %i\n", err);
2620 pRegDeleteKeyExA(native, "AWineTest", 0, 0);
2622 /* write subkey in opposite bit mode */
2623 err = RegOpenKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, KEY_ALL_ACCESS | opposite, &op_key);
2624 ok(err == ERROR_SUCCESS, "got %i\n", err);
2626 err = RegCreateKeyExA(op_key, "AWineTest", 0, NULL, 0, KEY_ALL_ACCESS | opposite,
2627 NULL, &key, NULL);
2628 ok(err == ERROR_SUCCESS || err == ERROR_ACCESS_DENIED, "got %i\n", err);
2629 if(err != ERROR_SUCCESS){
2630 win_skip("Can't write to registry\n");
2631 RegCloseKey(op_key);
2632 RegCloseKey(native);
2633 return;
2635 RegCloseKey(key);
2637 /* verify subkey is not present in native mode */
2638 err = RegOpenKeyExA(native, "AWineTest", 0, KEY_ALL_ACCESS, &key);
2639 ok(err == ERROR_FILE_NOT_FOUND ||
2640 broken(err == ERROR_SUCCESS), /* before Win7, HKCR is reflected instead of redirected */
2641 "got %i\n", err);
2643 err = pRegDeleteKeyExA(op_key, "AWineTest", opposite, 0);
2644 ok(err == ERROR_SUCCESS, "got %i\n", err);
2646 RegCloseKey(op_key);
2647 RegCloseKey(native);
2650 static void test_classesroot(void)
2652 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
2653 DWORD size = 8;
2654 DWORD type = REG_SZ;
2655 static CHAR buffer[8];
2656 LONG res;
2658 /* create a key in the user's classes */
2659 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
2661 delete_key( hkey );
2662 RegCloseKey( hkey );
2664 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2665 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL );
2666 if (res == ERROR_ACCESS_DENIED)
2668 skip("not enough privileges to add a user class\n");
2669 return;
2671 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2673 /* try to open that key in hkcr */
2674 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2675 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2676 todo_wine ok(res == ERROR_SUCCESS ||
2677 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2678 "test key not found in hkcr: %d\n", res);
2679 if (res)
2681 skip("HKCR key merging not supported\n");
2682 delete_key( hkey );
2683 RegCloseKey( hkey );
2684 return;
2687 todo_wine ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2689 /* set a value in user's classes */
2690 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2691 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2693 /* try to find the value in hkcr */
2694 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
2695 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2696 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2698 /* modify the value in hkcr */
2699 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2700 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2702 /* check if the value is also modified in user's classes */
2703 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
2704 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2705 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2707 /* set a value in hkcr */
2708 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2709 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2711 /* try to find the value in user's classes */
2712 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
2713 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2714 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2716 /* modify the value in user's classes */
2717 res = RegSetValueExA(hkey, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2718 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2720 /* check if the value is also modified in hkcr */
2721 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
2722 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2723 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2725 /* cleanup */
2726 delete_key( hkey );
2727 delete_key( hkcr );
2728 RegCloseKey( hkey );
2729 RegCloseKey( hkcr );
2731 /* create a key in the hklm classes */
2732 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2734 delete_key( hklm );
2735 RegCloseKey( hklm );
2737 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
2738 KEY_ALL_ACCESS, NULL, &hklm, NULL );
2739 if (res == ERROR_ACCESS_DENIED)
2741 skip("not enough privileges to add a system class\n");
2742 return;
2744 ok(!IS_HKCR(hklm), "hkcr mask set in %p\n", hklm);
2746 /* try to open that key in hkcr */
2747 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2748 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2749 ok(res == ERROR_SUCCESS,
2750 "test key not found in hkcr: %d\n", res);
2751 ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2752 if (res)
2754 delete_key( hklm );
2755 RegCloseKey( hklm );
2756 return;
2759 /* set a value in hklm classes */
2760 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2761 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2763 /* try to find the value in hkcr */
2764 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2765 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2766 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2768 /* modify the value in hkcr */
2769 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2770 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2772 /* check that the value is modified in hklm classes */
2773 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2774 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2775 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2777 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2778 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2779 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2781 /* try to open that key in hkcr */
2782 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2783 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2784 ok(res == ERROR_SUCCESS,
2785 "test key not found in hkcr: %d\n", res);
2786 ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2788 /* set a value in user's classes */
2789 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2790 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2792 /* try to find the value in hkcr */
2793 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2794 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2795 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2797 /* modify the value in hklm */
2798 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2799 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2801 /* check that the value is not overwritten in hkcr or user's classes */
2802 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2803 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2804 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2805 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2806 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2807 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2809 /* modify the value in hkcr */
2810 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2811 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2813 /* check that the value is overwritten in hklm and user's classes */
2814 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2815 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2816 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2817 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2818 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2819 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2821 /* create a subkey in hklm */
2822 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2823 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2824 ok(!IS_HKCR(hklmsub1), "hkcr mask set in %p\n", hklmsub1);
2825 /* try to open that subkey in hkcr */
2826 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2827 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2828 ok(IS_HKCR(hkcrsub1), "hkcr mask not set in %p\n", hkcrsub1);
2830 /* set a value in hklm classes */
2831 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2832 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2834 /* try to find the value in hkcr */
2835 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2836 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2837 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2839 /* modify the value in hkcr */
2840 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2841 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2843 /* check that the value is modified in hklm classes */
2844 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2845 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2846 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2848 /* create a subkey in user's classes */
2849 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2850 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2851 ok(!IS_HKCR(hkeysub1), "hkcr mask set in %p\n", hkeysub1);
2853 /* set a value in user's classes */
2854 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2855 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2857 /* try to find the value in hkcr */
2858 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2859 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2860 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2862 /* modify the value in hklm */
2863 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2864 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2866 /* check that the value is not overwritten in hkcr or user's classes */
2867 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2868 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2869 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2870 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2871 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2872 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2874 /* modify the value in hkcr */
2875 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2876 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2878 /* check that the value is not overwritten in hklm, but in user's classes */
2879 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2880 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2881 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2882 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2883 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2884 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2886 /* new subkey in hkcr */
2887 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
2888 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
2889 ok(IS_HKCR(hkcrsub2), "hkcr mask not set in %p\n", hkcrsub2);
2890 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2891 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2893 /* try to open that new subkey in user's classes and hklm */
2894 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2895 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
2896 hklmsub2 = 0;
2897 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2898 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2899 ok(!IS_HKCR(hklmsub2), "hkcr mask set in %p\n", hklmsub2);
2901 /* check that the value is present in hklm */
2902 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2903 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2904 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2906 /* cleanup */
2907 RegCloseKey( hkeysub1 );
2908 RegCloseKey( hklmsub1 );
2910 /* delete subkey1 from hkcr (should point at user's classes) */
2911 res = RegDeleteKeyA(hkcr, "subkey1");
2912 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
2914 /* confirm key was removed in hkey but not hklm */
2915 res = RegOpenKeyExA(hkey, "subkey1", 0, KEY_READ, &hkeysub1);
2916 ok(res == ERROR_FILE_NOT_FOUND, "test key found in user's classes: %d\n", res);
2917 res = RegOpenKeyExA(hklm, "subkey1", 0, KEY_READ, &hklmsub1);
2918 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2919 ok(!IS_HKCR(hklmsub1), "hkcr mask set in %p\n", hklmsub1);
2921 /* delete subkey1 from hkcr again (which should now point at hklm) */
2922 res = RegDeleteKeyA(hkcr, "subkey1");
2923 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
2925 /* confirm hkey was removed in hklm */
2926 RegCloseKey( hklmsub1 );
2927 res = RegOpenKeyExA(hklm, "subkey1", 0, KEY_READ, &hklmsub1);
2928 ok(res == ERROR_FILE_NOT_FOUND, "test key found in hklm: %d\n", res);
2930 /* final cleanup */
2931 delete_key( hkey );
2932 delete_key( hklm );
2933 delete_key( hkcr );
2934 delete_key( hkeysub1 );
2935 delete_key( hklmsub1 );
2936 delete_key( hkcrsub1 );
2937 delete_key( hklmsub2 );
2938 delete_key( hkcrsub2 );
2939 RegCloseKey( hkey );
2940 RegCloseKey( hklm );
2941 RegCloseKey( hkcr );
2942 RegCloseKey( hkeysub1 );
2943 RegCloseKey( hklmsub1 );
2944 RegCloseKey( hkcrsub1 );
2945 RegCloseKey( hklmsub2 );
2946 RegCloseKey( hkcrsub2 );
2949 static void test_classesroot_enum(void)
2951 HKEY hkcu=0, hklm=0, hkcr=0, hkcusub[2]={0}, hklmsub[2]={0};
2952 DWORD size;
2953 static CHAR buffer[2];
2954 LONG res;
2956 /* prepare initial testing env in HKCU */
2957 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkcu ))
2959 delete_key( hkcu );
2960 RegCloseKey( hkcu );
2962 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2963 KEY_SET_VALUE|KEY_ENUMERATE_SUB_KEYS, NULL, &hkcu, NULL );
2965 if (res != ERROR_SUCCESS)
2967 skip("failed to add a user class\n");
2968 return;
2971 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr );
2972 todo_wine ok(res == ERROR_SUCCESS ||
2973 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2974 "test key not found in hkcr: %d\n", res);
2975 if (res)
2977 skip("HKCR key merging not supported\n");
2978 delete_key( hkcu );
2979 RegCloseKey( hkcu );
2980 return;
2983 res = RegSetValueExA( hkcu, "X", 0, REG_SZ, (const BYTE *) "AA", 3 );
2984 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
2985 res = RegSetValueExA( hkcu, "Y", 0, REG_SZ, (const BYTE *) "B", 2 );
2986 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
2987 res = RegCreateKeyA( hkcu, "A", &hkcusub[0] );
2988 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
2989 res = RegCreateKeyA( hkcu, "B", &hkcusub[1] );
2990 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
2992 /* test on values in HKCU */
2993 size = sizeof(buffer);
2994 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
2995 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2996 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
2997 size = sizeof(buffer);
2998 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
2999 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3000 ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer);
3001 size = sizeof(buffer);
3002 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
3003 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3005 res = RegEnumKeyA( hkcr, 0, buffer, size );
3006 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3007 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
3008 res = RegEnumKeyA( hkcr, 1, buffer, size );
3009 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3010 ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer);
3011 res = RegEnumKeyA( hkcr, 2, buffer, size );
3012 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3014 /* prepare test env in HKLM */
3015 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
3017 delete_key( hklm );
3018 RegCloseKey( hklm );
3021 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, 0,
3022 KEY_SET_VALUE|KEY_ENUMERATE_SUB_KEYS, NULL, &hklm, NULL );
3024 if (res == ERROR_ACCESS_DENIED)
3026 RegCloseKey( hkcusub[0] );
3027 RegCloseKey( hkcusub[1] );
3028 delete_key( hkcu );
3029 RegCloseKey( hkcu );
3030 RegCloseKey( hkcr );
3031 skip("not enough privileges to add a system class\n");
3032 return;
3035 res = RegSetValueExA( hklm, "X", 0, REG_SZ, (const BYTE *) "AB", 3 );
3036 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
3037 res = RegSetValueExA( hklm, "Z", 0, REG_SZ, (const BYTE *) "C", 2 );
3038 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
3039 res = RegCreateKeyA( hklm, "A", &hklmsub[0] );
3040 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
3041 res = RegCreateKeyA( hklm, "C", &hklmsub[1] );
3042 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
3044 /* test on values/keys in both HKCU and HKLM */
3045 size = sizeof(buffer);
3046 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3047 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3048 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
3049 size = sizeof(buffer);
3050 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
3051 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3052 ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer);
3053 size = sizeof(buffer);
3054 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
3055 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3056 ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer);
3057 size = sizeof(buffer);
3058 res = RegEnumValueA( hkcr, 3, buffer, &size, NULL, NULL, NULL, NULL );
3059 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3061 res = RegEnumKeyA( hkcr, 0, buffer, size );
3062 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3063 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
3064 res = RegEnumKeyA( hkcr, 1, buffer, size );
3065 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3066 ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer);
3067 res = RegEnumKeyA( hkcr, 2, buffer, size );
3068 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3069 ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer);
3070 res = RegEnumKeyA( hkcr, 3, buffer, size );
3071 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3073 /* delete values/keys from HKCU to test only on HKLM */
3074 RegCloseKey( hkcusub[0] );
3075 RegCloseKey( hkcusub[1] );
3076 delete_key( hkcu );
3077 RegCloseKey( hkcu );
3079 size = sizeof(buffer);
3080 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3081 ok(res == ERROR_KEY_DELETED ||
3082 res == ERROR_NO_SYSTEM_RESOURCES, /* Windows XP */
3083 "expected ERROR_KEY_DELETED, got %d\n", res);
3084 size = sizeof(buffer);
3085 res = RegEnumKeyA( hkcr, 0, buffer, size );
3086 ok(res == ERROR_KEY_DELETED ||
3087 res == ERROR_NO_SYSTEM_RESOURCES, /* Windows XP */
3088 "expected ERROR_KEY_DELETED, got %d\n", res);
3090 /* reopen HKCR handle */
3091 RegCloseKey( hkcr );
3092 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr );
3093 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
3094 if (res) goto cleanup;
3096 /* test on values/keys in HKLM */
3097 size = sizeof(buffer);
3098 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3099 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3100 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
3101 size = sizeof(buffer);
3102 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
3103 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3104 ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer);
3105 size = sizeof(buffer);
3106 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
3107 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3109 res = RegEnumKeyA( hkcr, 0, buffer, size );
3110 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3111 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
3112 res = RegEnumKeyA( hkcr, 1, buffer, size );
3113 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3114 ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer);
3115 res = RegEnumKeyA( hkcr, 2, buffer, size );
3116 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3118 cleanup:
3119 RegCloseKey( hklmsub[0] );
3120 RegCloseKey( hklmsub[1] );
3121 delete_key( hklm );
3122 RegCloseKey( hklm );
3123 RegCloseKey( hkcr );
3126 static void test_classesroot_mask(void)
3128 HKEY hkey;
3129 LSTATUS res;
3131 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "CLSID", &hkey );
3132 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3133 todo_wine ok(IS_HKCR(hkey) || broken(!IS_HKCR(hkey)) /* WinNT */,
3134 "hkcr mask not set in %p\n", hkey);
3135 RegCloseKey( hkey );
3137 res = RegOpenKeyA( HKEY_CURRENT_USER, "Software", &hkey );
3138 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3139 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3140 RegCloseKey( hkey );
3142 res = RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software", &hkey );
3143 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3144 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3145 RegCloseKey( hkey );
3147 res = RegOpenKeyA( HKEY_USERS, ".Default", &hkey );
3148 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3149 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3150 RegCloseKey( hkey );
3152 res = RegOpenKeyA( HKEY_CURRENT_CONFIG, "Software", &hkey );
3153 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3154 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3155 RegCloseKey( hkey );
3158 static void test_deleted_key(void)
3160 HKEY hkey, hkey2;
3161 char value[20];
3162 DWORD val_count, type;
3163 LONG res;
3165 /* Open the test key, then delete it while it's open */
3166 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
3168 delete_key( hkey_main );
3170 val_count = sizeof(value);
3171 type = 0;
3172 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
3173 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3175 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
3176 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3178 val_count = sizeof(value);
3179 type = 0;
3180 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
3181 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3183 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
3184 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3186 res = RegOpenKeyA( hkey, "test", &hkey2 );
3187 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3188 if (res == 0)
3189 RegCloseKey( hkey2 );
3191 res = RegCreateKeyA( hkey, "test", &hkey2 );
3192 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3193 if (res == 0)
3194 RegCloseKey( hkey2 );
3196 res = RegFlushKey( hkey );
3197 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3199 RegCloseKey( hkey );
3201 setup_main_key();
3204 static void test_delete_value(void)
3206 LONG res;
3207 char longname[401];
3209 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
3210 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
3212 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
3213 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
3215 res = RegDeleteValueA( hkey_main, "test" );
3216 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
3218 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
3219 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
3221 res = RegDeleteValueA( hkey_main, "test" );
3222 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
3224 memset(longname, 'a', 400);
3225 longname[400] = 0;
3226 res = RegDeleteValueA( hkey_main, longname );
3227 ok(res == ERROR_FILE_NOT_FOUND || broken(res == ERROR_MORE_DATA), /* nt4, win2k */
3228 "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
3231 static void test_delete_key_value(void)
3233 HKEY subkey;
3234 LONG ret;
3236 if (!pRegDeleteKeyValueA)
3238 win_skip("RegDeleteKeyValue is not available.\n");
3239 return;
3242 ret = pRegDeleteKeyValueA(NULL, NULL, NULL);
3243 ok(ret == ERROR_INVALID_HANDLE, "got %d\n", ret);
3245 ret = pRegDeleteKeyValueA(hkey_main, NULL, NULL);
3246 ok(ret == ERROR_FILE_NOT_FOUND, "got %d\n", ret);
3248 ret = RegSetValueExA(hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6);
3249 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3251 ret = RegQueryValueExA(hkey_main, "test", NULL, NULL, NULL, NULL);
3252 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3254 /* NULL subkey name means delete from open key */
3255 ret = pRegDeleteKeyValueA(hkey_main, NULL, "test");
3256 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3258 ret = RegQueryValueExA(hkey_main, "test", NULL, NULL, NULL, NULL);
3259 ok(ret == ERROR_FILE_NOT_FOUND, "got %d\n", ret);
3261 /* now with real subkey */
3262 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_WRITE|KEY_READ, NULL, &subkey, NULL);
3263 ok(!ret, "failed with error %d\n", ret);
3265 ret = RegSetValueExA(subkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
3266 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3268 ret = RegQueryValueExA(subkey, "test", NULL, NULL, NULL, NULL);
3269 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3271 ret = pRegDeleteKeyValueA(hkey_main, "Subkey1", "test");
3272 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3274 ret = RegQueryValueExA(subkey, "test", NULL, NULL, NULL, NULL);
3275 ok(ret == ERROR_FILE_NOT_FOUND, "got %d\n", ret);
3277 RegDeleteKeyA(subkey, "");
3278 RegCloseKey(subkey);
3281 START_TEST(registry)
3283 /* Load pointers for functions that are not available in all Windows versions */
3284 InitFunctionPtrs();
3286 setup_main_key();
3287 check_user_privs();
3288 test_set_value();
3289 create_test_entries();
3290 test_enum_value();
3291 test_query_value_ex();
3292 test_get_value();
3293 test_reg_open_key();
3294 test_reg_create_key();
3295 test_reg_close_key();
3296 test_reg_delete_key();
3297 test_reg_query_value();
3298 test_reg_query_info();
3299 test_string_termination();
3300 test_symlinks();
3301 test_redirection();
3302 test_classesroot();
3303 test_classesroot_enum();
3304 test_classesroot_mask();
3305 test_reg_save_key();
3306 test_reg_load_key();
3307 test_reg_unload_key();
3308 test_reg_delete_tree();
3309 test_rw_order();
3310 test_deleted_key();
3311 test_delete_value();
3312 test_delete_key_value();
3314 /* cleanup */
3315 delete_key( hkey_main );
3317 test_regconnectregistry();