2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
34 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
36 static HKEY hkey_main
;
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 LONG (WINAPI
*pRegCopyTreeA
)(HKEY
,const char *,HKEY
);
45 static LONG (WINAPI
*pRegDeleteTreeA
)(HKEY
,const char *);
46 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
47 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
48 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
49 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
50 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
51 static LONG (WINAPI
*pRegDeleteKeyValueA
)(HKEY
,LPCSTR
,LPCSTR
);
52 static LONG (WINAPI
*pRegSetKeyValueW
)(HKEY
,LPCWSTR
,LPCWSTR
,DWORD
,const void*,DWORD
);
54 static BOOL limited_user
;
57 /* Debugging functions from wine/libs/wine/debug.c */
59 /* allocate some tmp string space */
60 /* FIXME: this is not 100% thread-safe */
61 static char *get_temp_buffer( int size
)
63 static char *list
[32];
68 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
70 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
72 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
73 if (ret
) list
[idx
] = ret
;
77 static const char *wine_debugstr_an( const char *str
, int n
)
79 static const char hex
[16] = "0123456789abcdef";
83 if (!((ULONG_PTR
)str
>> 16))
85 if (!str
) return "(null)";
86 res
= get_temp_buffer( 6 );
87 sprintf( res
, "#%04x", LOWORD(str
) );
90 if (n
== -1) n
= strlen(str
);
92 size
= 10 + min( 300, n
* 4 );
93 dst
= res
= get_temp_buffer( size
);
95 while (n
-- > 0 && dst
<= res
+ size
- 9)
97 unsigned char c
= *str
++;
100 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
101 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
102 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
103 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
104 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
106 if (c
>= ' ' && c
<= 126)
112 *dst
++ = hex
[(c
>> 4) & 0x0f];
113 *dst
++ = hex
[c
& 0x0f];
128 #define ADVAPI32_GET_PROC(func) \
129 p ## func = (void*)GetProcAddress(hadvapi32, #func)
131 static void InitFunctionPtrs(void)
133 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
134 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
135 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
137 /* This function was introduced with Windows 2003 SP1 */
138 ADVAPI32_GET_PROC(RegGetValueA
);
139 ADVAPI32_GET_PROC(RegCopyTreeA
);
140 ADVAPI32_GET_PROC(RegDeleteTreeA
);
141 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
142 ADVAPI32_GET_PROC(RegDeleteKeyValueA
);
143 ADVAPI32_GET_PROC(RegSetKeyValueW
);
145 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
146 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
147 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
148 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
151 /* delete key and all its subkeys */
152 static DWORD
delete_key( HKEY hkey
)
157 if ((ret
= RegOpenKeyExA( hkey
, "", 0, KEY_ENUMERATE_SUB_KEYS
, &hkey
))) return ret
;
158 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
161 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
163 ret
= delete_key( tmp
);
168 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
169 RegDeleteKeyA( hkey
, "" );
174 static void setup_main_key(void)
176 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
178 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
181 static void check_user_privs(void)
184 HKEY hkey
= (HKEY
)0xdeadbeef;
186 ret
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WRITE
, &hkey
);
187 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_ACCESS_DENIED
, "expected success or access denied, got %i\n", ret
);
188 if (ret
== ERROR_SUCCESS
)
190 ok(hkey
!= NULL
, "RegOpenKeyExA succeeded but returned NULL hkey\n");
195 ok(hkey
== NULL
, "RegOpenKeyExA failed but returned hkey %p\n", hkey
);
197 trace("running as limited user\n");
201 #define lok ok_(__FILE__, line)
202 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
203 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
206 DWORD ret
, type
, cbData
;
212 /* When successful RegQueryValueExA() leaves GLE as is,
213 * so we must reset it to detect unimplemented functions.
215 SetLastError(0xdeadbeef);
216 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
217 GLE
= GetLastError();
218 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
219 /* It is wrong for the Ansi version to not be implemented */
220 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
221 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
223 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
224 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
225 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
227 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
228 memset(value
, 0xbd, cbData
+1);
230 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
231 GLE
= GetLastError();
232 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
235 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
236 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
240 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
241 wine_debugstr_an((char*)value
, cbData
), cbData
,
242 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
243 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
245 HeapFree(GetProcessHeap(), 0, value
);
248 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
249 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
252 DWORD ret
, type
, cbData
;
257 /* When successful RegQueryValueExW() leaves GLE as is,
258 * so we must reset it to detect unimplemented functions.
260 SetLastError(0xdeadbeef);
261 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
262 GLE
= GetLastError();
263 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
264 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
266 win_skip("RegQueryValueExW() is not implemented\n");
270 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
271 lok(cbData
== full_byte_len
,
272 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
274 /* Give enough space to overflow by one WCHAR */
275 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
276 memset(value
, 0xbd, cbData
+2);
278 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
279 GLE
= GetLastError();
280 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
283 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
284 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
285 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
287 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
288 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
289 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
290 HeapFree(GetProcessHeap(), 0, value
);
293 static void test_set_value(void)
297 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
298 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};
299 static const WCHAR emptyW
[] = {0};
300 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
301 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};
302 static const WCHAR substring2W
[] = {'T','h','i','s',0};
304 static const char name1A
[] = "CleanSingleString";
305 static const char name2A
[] = "SomeIntraZeroedString";
306 static const char emptyA
[] = "";
307 static const char string1A
[] = "ThisNeverBreaks";
308 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
309 static const char substring2A
[] = "This";
313 /* Crashes on NT4, Windows 2000 and XP SP1 */
314 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
315 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
318 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
319 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
320 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
321 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
323 /* RegSetValueA ignores the size passed in */
324 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
325 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
326 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
327 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
329 /* stops at first null */
330 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
331 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
332 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
333 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
335 /* only REG_SZ is supported on NT*/
336 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
337 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
339 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
340 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
342 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
343 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
345 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
346 * Surprisingly enough we're supposed to get zero bytes out of it.
348 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
349 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
350 test_hkey_main_Value_A(name1A
, NULL
, 0);
351 test_hkey_main_Value_W(name1W
, NULL
, 0);
353 /* test RegSetValueExA with an empty string */
354 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
355 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
356 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
357 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
359 /* test RegSetValueExA with off-by-one size */
360 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
361 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
362 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
363 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
365 /* test RegSetValueExA with normal string */
366 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
367 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
368 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
369 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
371 /* test RegSetValueExA with intrazeroed string */
372 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
373 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
374 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
375 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
379 /* Crashes on NT4, Windows 2000 and XP SP1 */
380 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
381 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
383 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
384 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
387 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
388 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
389 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
390 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
392 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
393 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
394 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
395 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
397 /* RegSetValueW ignores the size passed in */
398 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
399 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
400 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
401 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
403 /* stops at first null */
404 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
405 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
406 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
407 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
409 /* only REG_SZ is supported */
410 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, 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_EXPAND_SZ
, string2W
, sizeof(string2W
));
413 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
414 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
415 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
417 /* test RegSetValueExW with off-by-one size */
418 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
419 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
420 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
421 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
423 /* test RegSetValueExW with normal string */
424 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
425 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
426 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
427 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
429 /* test RegSetValueExW with intrazeroed string */
430 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
431 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
432 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
433 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
435 /* test RegSetValueExW with data = 1 */
436 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
437 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
438 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
439 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
441 if (pRegGetValueA
) /* avoid a crash on Windows 2000 */
443 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_SZ
, NULL
, 4);
444 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
446 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_SZ
, NULL
, 0);
447 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
449 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_DWORD
, NULL
, 4);
450 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
452 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_DWORD
, NULL
, 0);
453 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
457 if (!pRegSetKeyValueW
)
458 win_skip("RegSetKeyValue() is not supported.\n");
461 static const WCHAR subkeyW
[] = {'s','u','b','k','e','y',0};
465 ret
= pRegSetKeyValueW(hkey_main
, NULL
, name1W
, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
466 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
467 test_hkey_main_Value_A(name1A
, string2A
, sizeof(string2A
));
468 test_hkey_main_Value_W(name1W
, string2W
, sizeof(string2W
));
470 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
471 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
473 ret
= RegOpenKeyExW(hkey_main
, subkeyW
, 0, KEY_QUERY_VALUE
, &subkey
);
474 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
476 ret
= RegQueryValueExW(subkey
, name1W
, 0, &type
, NULL
, &len
);
477 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
478 ok(len
== sizeof(string1W
), "got %d\n", len
);
479 ok(type
== REG_SZ
, "got type %d\n", type
);
481 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 0);
482 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
484 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 4);
485 ok(ret
== ERROR_NOACCESS
, "got %d\n", ret
);
487 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_DWORD
, NULL
, 4);
488 ok(ret
== ERROR_NOACCESS
, "got %d\n", ret
);
494 static void create_test_entries(void)
496 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
498 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
499 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
501 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
502 "RegSetValueExA failed\n");
503 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
504 "RegSetValueExA failed\n");
505 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
506 "RegSetValueExA failed\n");
507 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
508 "RegSetValueExA failed\n");
509 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
510 "RegSetValueExA failed\n");
511 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
512 "RegSetValueExA failed\n");
513 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
514 "RegSetValueExA failed\n");
517 static void test_enum_value(void)
521 char value
[20], data
[20];
522 WCHAR valueW
[20], dataW
[20];
523 DWORD val_count
, data_count
, type
;
524 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
525 static const WCHAR testW
[] = {'T','e','s','t',0};
526 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
528 /* create the working key for new 'Test' value */
529 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
530 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
532 /* check NULL data with zero length */
533 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
534 if (GetVersion() & 0x80000000)
535 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
537 ok( !res
, "RegSetValueExA returned %d\n", res
);
538 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
539 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
540 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
541 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
543 /* test reading the value and data without setting them */
547 strcpy( value
, "xxxxxxxxxx" );
548 strcpy( data
, "xxxxxxxxxx" );
549 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
550 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
551 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
552 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
553 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
554 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
555 ok( !strcmp( data
, "xxxxxxxxxx" ), "data is '%s' instead of xxxxxxxxxx\n", data
);
560 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
561 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
562 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
563 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
564 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
565 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
566 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
567 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
568 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data is not 'xxxxxxxxxx'\n" );
570 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
571 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
573 /* overflow both name and data */
577 strcpy( value
, "xxxxxxxxxx" );
578 strcpy( data
, "xxxxxxxxxx" );
579 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
580 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
581 ok( val_count
== 2, "val_count set to %d\n", val_count
);
582 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
583 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
584 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
585 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
591 strcpy( value
, "xxxxxxxxxx" );
592 strcpy( data
, "xxxxxxxxxx" );
593 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
594 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
595 ok( val_count
== 3, "val_count set to %d\n", val_count
);
596 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
597 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
598 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
599 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
600 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
601 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
602 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
604 /* overflow empty name */
608 strcpy( value
, "xxxxxxxxxx" );
609 strcpy( data
, "xxxxxxxxxx" );
610 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
611 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
612 ok( val_count
== 0, "val_count set to %d\n", val_count
);
613 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
614 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
615 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
616 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
617 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
618 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
624 strcpy( value
, "xxxxxxxxxx" );
625 strcpy( data
, "xxxxxxxxxx" );
626 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
627 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
628 ok( val_count
== 20, "val_count set to %d\n", val_count
);
629 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
630 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
631 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
632 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
638 strcpy( value
, "xxxxxxxxxx" );
639 strcpy( data
, "xxxxxxxxxx" );
640 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
641 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
642 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
643 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
644 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
645 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
646 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
648 if (pRegGetValueA
) /* avoid a crash on Windows 2000 */
650 /* no value and no val_count parameter */
653 strcpy( data
, "xxxxxxxxxx" );
654 res
= RegEnumValueA( test_key
, 0, NULL
, NULL
, NULL
, &type
, (BYTE
*)data
, &data_count
);
655 ok( res
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", res
);
657 /* no value parameter */
661 strcpy( data
, "xxxxxxxxxx" );
662 res
= RegEnumValueA( test_key
, 0, NULL
, &val_count
, NULL
, &type
, (BYTE
*)data
, &data_count
);
663 ok( res
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", res
);
665 /* no val_count parameter */
668 strcpy( value
, "xxxxxxxxxx" );
669 strcpy( data
, "xxxxxxxxxx" );
670 res
= RegEnumValueA( test_key
, 0, value
, NULL
, NULL
, &type
, (BYTE
*)data
, &data_count
);
671 ok( res
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", res
);
676 SetLastError(0xdeadbeef);
677 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
678 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
680 win_skip("RegSetValueExW is not implemented\n");
683 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
685 /* overflow both name and data */
689 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
690 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
691 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
692 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
693 ok( val_count
== 2, "val_count set to %d\n", val_count
);
694 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
695 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
696 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
697 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
703 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
704 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
705 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
706 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
707 ok( val_count
== 3, "val_count set to %d\n", val_count
);
708 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
709 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
710 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
711 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
717 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
718 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
719 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
720 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
721 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
722 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
723 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
724 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
725 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
731 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
732 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
733 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
734 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
735 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
736 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
737 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
738 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
739 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
741 if (pRegGetValueA
) /* avoid a crash on Windows 2000 */
743 /* no valueW and no val_count parameter */
746 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
747 res
= RegEnumValueW( test_key
, 0, NULL
, NULL
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
748 ok( res
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", res
);
750 /* no valueW parameter */
754 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
755 res
= RegEnumValueW( test_key
, 0, NULL
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
756 ok( res
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", res
);
758 /* no val_count parameter */
761 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
762 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
763 res
= RegEnumValueW( test_key
, 0, valueW
, NULL
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
764 ok( res
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", res
);
768 RegDeleteKeyA(test_key
, "");
769 RegCloseKey(test_key
);
772 static void test_query_value_ex(void)
779 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
780 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
781 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
782 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
786 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
787 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
788 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
790 size
= sizeof(buffer
);
791 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
792 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
793 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
796 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
797 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
800 static void test_get_value(void)
807 CHAR expanded
[] = "bar\\subdir1";
808 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
812 win_skip("RegGetValue not available on this platform\n");
816 /* Invalid parameter */
817 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
818 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
820 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
821 size
= type
= dw
= 0xdeadbeef;
822 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
823 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
824 ok(size
== 4, "size=%d\n", size
);
825 ok(type
== REG_DWORD
, "type=%d\n", type
);
826 ok(dw
== 0x12345678, "dw=%d\n", dw
);
828 /* Query by subkey-name */
829 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
830 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
832 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
833 size
= type
= dw
= 0xdeadbeef;
834 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
835 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
836 /* Although the function failed all values are retrieved */
837 ok(size
== 4, "size=%d\n", size
);
838 ok(type
== REG_DWORD
, "type=%d\n", type
);
839 ok(dw
== 0x12345678, "dw=%d\n", dw
);
841 /* Test RRF_ZEROONFAILURE */
842 type
= dw
= 0xdeadbeef; size
= 4;
843 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
844 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
845 /* Again all values are retrieved ... */
846 ok(size
== 4, "size=%d\n", size
);
847 ok(type
== REG_DWORD
, "type=%d\n", type
);
848 /* ... except the buffer, which is zeroed out */
849 ok(dw
== 0, "dw=%d\n", dw
);
851 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
852 type
= size
= 0xbadbeef;
853 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
854 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
855 ok(size
== 4, "size=%d\n", size
);
856 ok(type
== REG_DWORD
, "type=%d\n", type
);
858 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
859 size
= type
= dw
= 0xdeadbeef;
860 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
861 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
862 ok(size
== 4, "size=%d\n", size
);
863 ok(type
== REG_DWORD
, "type=%d\n", type
);
864 ok(dw
== 0x12345678, "dw=%d\n", dw
);
866 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
867 size
= type
= dw
= 0xdeadbeef;
868 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
869 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
870 ok(size
== 4, "size=%d\n", size
);
871 ok(type
== REG_BINARY
, "type=%d\n", type
);
872 ok(dw
== 0x12345678, "dw=%d\n", dw
);
874 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
875 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
876 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
877 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
878 ok(size
== 8, "size=%d\n", size
);
879 ok(type
== REG_BINARY
, "type=%d\n", type
);
880 ok(qw
[0] == 0x12345678 &&
881 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
883 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
884 type
= dw
= 0xdeadbeef; size
= 4;
885 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
886 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
887 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
888 ok(size
== 8, "size=%d\n", size
);
890 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
891 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
892 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
893 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
894 ok(size
== 8, "size=%d\n", size
);
895 ok(type
== REG_BINARY
, "type=%d\n", type
);
896 ok(qw
[0] == 0x12345678 &&
897 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
899 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
900 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
901 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
902 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
903 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
904 ok(type
== REG_SZ
, "type=%d\n", type
);
905 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
907 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
908 type
= 0xdeadbeef; size
= 0;
909 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
910 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
911 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
912 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
913 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
914 ok(type
== REG_SZ
, "type=%d\n", type
);
916 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
917 strcpy(buf
, sTestpath1
);
920 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
921 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
922 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
924 size
== 1, /* win2k3 */
926 ok(type
== REG_SZ
, "type=%d\n", type
);
927 ok(!strcmp(sTestpath1
, buf
) ||
929 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
931 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
932 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
933 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
934 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
935 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
936 ok(type
== REG_SZ
, "type=%d\n", type
);
937 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
939 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
941 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
942 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
943 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
944 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
945 (size
== strlen(sTestpath2
)+1),
946 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
948 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
949 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
950 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
951 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
952 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
953 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
954 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
955 ok(type
== REG_SZ
, "type=%d\n", type
);
956 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
958 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
959 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
960 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
961 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
962 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
963 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
964 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
965 ok(type
== REG_SZ
, "type=%d\n", type
);
966 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
968 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
969 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
970 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
971 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
972 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
973 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
974 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
976 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
978 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
979 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
980 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
981 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
982 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
984 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
985 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
986 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
988 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
989 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
990 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
991 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
993 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
994 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
995 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
996 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
997 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
998 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
999 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
1000 ok(type
== REG_SZ
, "type=%d\n", type
);
1001 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
1004 static void test_reg_open_key(void)
1007 HKEY hkResult
= NULL
;
1008 HKEY hkPreserve
= NULL
;
1009 HKEY hkRoot64
= NULL
;
1010 HKEY hkRoot32
= NULL
;
1012 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1014 EXPLICIT_ACCESSA access
;
1016 SECURITY_DESCRIPTOR
*sd
;
1018 /* successful open */
1019 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
1020 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1021 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1022 hkPreserve
= hkResult
;
1024 /* open same key twice */
1025 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
1026 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1027 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
1028 ok(hkResult
!= NULL
, "hkResult != NULL\n");
1029 RegCloseKey(hkResult
);
1031 /* trailing slashes */
1032 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test\\\\", &hkResult
);
1033 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1034 RegCloseKey(hkResult
);
1036 /* open nonexistent key
1037 * check that hkResult is set to NULL
1039 hkResult
= hkPreserve
;
1040 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
1041 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1042 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
1044 /* open the same nonexistent key again to make sure the key wasn't created */
1045 hkResult
= hkPreserve
;
1046 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
1047 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1048 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
1050 /* send in NULL lpSubKey
1051 * check that hkResult receives the value of hKey
1053 hkResult
= hkPreserve
;
1054 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
1055 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1056 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
1058 /* send empty-string in lpSubKey */
1059 hkResult
= hkPreserve
;
1060 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
1061 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1062 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
1064 /* send in NULL lpSubKey and NULL hKey
1065 * hkResult is set to NULL
1067 hkResult
= hkPreserve
;
1068 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
1069 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1070 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
1072 /* only send NULL hKey
1073 * the value of hkResult remains unchanged
1075 hkResult
= hkPreserve
;
1076 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
1077 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1078 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1079 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
1081 /* send in NULL hkResult */
1082 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
1083 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1085 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
1086 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1088 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
1089 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1091 /* beginning backslash character */
1092 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
1093 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
1094 broken(ret
== ERROR_SUCCESS
), /* wow64 */
1095 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1096 if (!ret
) RegCloseKey(hkResult
);
1099 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
1100 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
1101 ret
== ERROR_BAD_PATHNAME
, /* NT */
1102 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1103 RegCloseKey(hkResult
);
1105 /* NULL or empty subkey of special root */
1107 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, NULL
, 0, KEY_QUERY_VALUE
, &hkResult
);
1108 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1109 ok(hkResult
== HKEY_CLASSES_ROOT
, "expected hkResult == HKEY_CLASSES_ROOT\n");
1112 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "", 0, KEY_QUERY_VALUE
, &hkResult
);
1113 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1114 ok(hkResult
== HKEY_CLASSES_ROOT
, "expected hkResult == HKEY_CLASSES_ROOT\n");
1117 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\", 0, KEY_QUERY_VALUE
, &hkResult
);
1118 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1119 ok(hkResult
!= HKEY_CLASSES_ROOT
, "expected hkResult to be a new key\n");
1120 ok(!RegCloseKey(hkResult
), "got invalid hkey\n");
1122 /* empty subkey of existing handle */
1123 hkResult
= hkPreserve
;
1124 ret
= RegOpenKeyExA(hkPreserve
, "", 0, KEY_QUERY_VALUE
, &hkResult
);
1125 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1126 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
1127 ok(!RegCloseKey(hkResult
), "got invalid hkey\n");
1129 /* NULL subkey of existing handle */
1130 hkResult
= hkPreserve
;
1131 ret
= RegOpenKeyExA(hkPreserve
, NULL
, 0, KEY_QUERY_VALUE
, &hkResult
);
1132 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1133 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
1134 ok(!RegCloseKey(hkResult
), "got invalid hkey\n");
1136 /* empty subkey of NULL */
1137 hkResult
= hkPreserve
;
1138 ret
= RegOpenKeyExA(NULL
, "", 0, KEY_QUERY_VALUE
, &hkResult
);
1139 ok(ret
== ERROR_INVALID_HANDLE
, "expected ERROR_INVALID_HANDLE, got %d\n", ret
);
1140 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
1142 RegCloseKey(hkPreserve
);
1146 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
1147 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1148 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1149 RegCloseKey(hkResult
);
1152 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
1153 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1154 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1155 RegCloseKey(hkResult
);
1157 /* check special HKEYs on 64bit
1158 * only the lower 4 bytes of the supplied key are used
1162 /* HKEY_CURRENT_USER */
1163 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
1164 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1165 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1166 RegCloseKey(hkResult
);
1168 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
1169 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1170 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1171 RegCloseKey(hkResult
);
1173 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1174 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1175 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1176 RegCloseKey(hkResult
);
1178 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
1179 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1180 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1181 RegCloseKey(hkResult
);
1183 /* HKEY_LOCAL_MACHINE */
1184 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1185 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1186 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1187 RegCloseKey(hkResult
);
1190 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1191 * the registry access check is performed correctly. Redirection isn't
1192 * being tested, so the tests don't care about whether the process is
1193 * running under WOW64. */
1194 if (!pIsWow64Process
)
1196 win_skip("WOW64 flags are not recognized\n");
1200 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1201 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1203 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1204 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1206 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1207 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1209 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1210 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1212 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1213 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1215 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1216 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1218 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1219 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1221 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1223 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1224 access
.grfAccessMode
= SET_ACCESS
;
1225 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1226 access
.Trustee
.pMultipleTrustee
= NULL
;
1227 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1228 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1229 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1230 access
.Trustee
.ptstrName
= (char *)world_sid
;
1232 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1233 ok(ret
== ERROR_SUCCESS
,
1234 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1236 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1237 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1239 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1241 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1243 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1247 skip("not enough privileges to modify HKLM\n");
1253 error
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1254 ok(error
== ERROR_SUCCESS
,
1255 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1257 error
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1258 ok(error
== ERROR_SUCCESS
,
1259 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1262 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1263 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1264 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1265 RegCloseKey(hkResult
);
1268 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1269 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1270 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1271 RegCloseKey(hkResult
);
1274 HeapFree(GetProcessHeap(), 0, sd
);
1277 RegDeleteKeyA(hkRoot64
, "");
1278 RegCloseKey(hkRoot64
);
1279 RegDeleteKeyA(hkRoot32
, "");
1280 RegCloseKey(hkRoot32
);
1283 static void test_reg_create_key(void)
1287 HKEY hkRoot64
= NULL
;
1288 HKEY hkRoot32
= NULL
;
1291 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1293 EXPLICIT_ACCESSA access
;
1295 SECURITY_DESCRIPTOR
*sd
;
1297 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1298 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1299 /* should succeed: all versions of Windows ignore the access rights
1300 * to the parent handle */
1301 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1302 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1305 RegDeleteKeyA(hkey2
, "");
1306 RegDeleteKeyA(hkey1
, "");
1310 /* test creation of volatile keys */
1311 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1312 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1313 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1314 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1315 if (!ret
) RegCloseKey( hkey2
);
1316 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1317 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1319 /* should succeed if the key already exists */
1320 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1321 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1324 RegDeleteKeyA(hkey2
, "");
1325 RegDeleteKeyA(hkey1
, "");
1329 /* beginning backslash character */
1330 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1331 if (!(GetVersion() & 0x80000000))
1332 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1334 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1335 RegDeleteKeyA(hkey1
, "");
1339 /* trailing backslash characters */
1340 ret
= RegCreateKeyExA(hkey_main
, "Subkey4\\\\", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1341 ok(ret
== ERROR_SUCCESS
, "RegCreateKeyExA failed with error %d\n", ret
);
1342 RegDeleteKeyA(hkey1
, "");
1345 /* WOW64 flags - open an existing key */
1347 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1348 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1349 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1353 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1354 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1355 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1358 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1359 * the registry access check is performed correctly. Redirection isn't
1360 * being tested, so the tests don't care about whether the process is
1361 * running under WOW64. */
1362 if (!pIsWow64Process
)
1364 win_skip("WOW64 flags are not recognized\n");
1368 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1369 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1371 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1372 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1374 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1375 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1377 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1378 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1380 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1381 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1383 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1384 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1386 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1387 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1389 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1391 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1392 access
.grfAccessMode
= SET_ACCESS
;
1393 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1394 access
.Trustee
.pMultipleTrustee
= NULL
;
1395 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1396 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1397 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1398 access
.Trustee
.ptstrName
= (char *)world_sid
;
1400 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1401 ok(dwRet
== ERROR_SUCCESS
,
1402 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1404 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1405 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1407 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1409 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1411 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1415 skip("not enough privileges to modify HKLM\n");
1419 ret
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1420 ok(ret
== ERROR_SUCCESS
,
1421 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1423 ret
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1424 ok(ret
== ERROR_SUCCESS
,
1425 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1428 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1429 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1430 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1431 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1435 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1436 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1437 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1438 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1442 HeapFree(GetProcessHeap(), 0, sd
);
1445 RegDeleteKeyA(hkRoot64
, "");
1446 RegCloseKey(hkRoot64
);
1447 RegDeleteKeyA(hkRoot32
, "");
1448 RegCloseKey(hkRoot32
);
1451 static void test_reg_close_key(void)
1456 /* successfully close key
1457 * hkHandle remains changed after call to RegCloseKey
1459 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1460 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1461 ret
= RegCloseKey(hkHandle
);
1462 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1464 /* try to close the key twice */
1465 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1466 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1467 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1469 /* try to close a NULL handle */
1470 ret
= RegCloseKey(NULL
);
1471 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1472 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1474 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1475 * win98 doesn't give a new handle when the same key is opened.
1476 * Not re-opening will make some next tests fail.
1478 if (hkey_main
== hkHandle
)
1480 trace("The main handle is most likely closed, so re-opening\n");
1481 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1485 static void test_reg_delete_key(void)
1490 ret
= RegDeleteKeyA(hkey_main
, NULL
);
1492 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1493 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1494 * Not re-creating will make some next tests fail.
1496 if (ret
== ERROR_SUCCESS
)
1498 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1499 " re-creating the main key\n");
1503 ok(ret
== ERROR_INVALID_PARAMETER
||
1504 ret
== ERROR_ACCESS_DENIED
||
1505 ret
== ERROR_BADKEY
, /* Win95 */
1508 ret
= RegCreateKeyA(hkey_main
, "deleteme", &key
);
1509 ok(ret
== ERROR_SUCCESS
, "Could not create key, got %d\n", ret
);
1510 ret
= RegDeleteKeyA(key
, "");
1511 ok(ret
== ERROR_SUCCESS
, "RegDeleteKeyA failed, got %d\n", ret
);
1513 ret
= RegOpenKeyA(hkey_main
, "deleteme", &key
);
1514 ok(ret
== ERROR_FILE_NOT_FOUND
, "Key was not deleted, got %d\n", ret
);
1518 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1520 TOKEN_PRIVILEGES tp
;
1524 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1527 if(!LookupPrivilegeValueA(NULL
, privilege
, &luid
))
1529 CloseHandle(hToken
);
1533 tp
.PrivilegeCount
= 1;
1534 tp
.Privileges
[0].Luid
= luid
;
1537 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1539 tp
.Privileges
[0].Attributes
= 0;
1541 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1542 if (GetLastError() != ERROR_SUCCESS
)
1544 CloseHandle(hToken
);
1548 CloseHandle(hToken
);
1552 static void test_reg_save_key(void)
1556 if (!set_privileges(SE_BACKUP_NAME
, TRUE
) ||
1557 !set_privileges(SE_RESTORE_NAME
, FALSE
))
1559 win_skip("Failed to set SE_BACKUP_NAME privileges, skipping tests\n");
1563 ret
= RegSaveKeyA(hkey_main
, "saved_key", NULL
);
1564 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1566 set_privileges(SE_BACKUP_NAME
, FALSE
);
1569 static void test_reg_load_key(void)
1574 if (!set_privileges(SE_RESTORE_NAME
, TRUE
) ||
1575 !set_privileges(SE_BACKUP_NAME
, FALSE
))
1577 win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n");
1581 ret
= RegLoadKeyA(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1582 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1584 set_privileges(SE_RESTORE_NAME
, FALSE
);
1586 ret
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1587 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1589 RegCloseKey(hkHandle
);
1592 static void test_reg_unload_key(void)
1596 if (!set_privileges(SE_RESTORE_NAME
, TRUE
) ||
1597 !set_privileges(SE_BACKUP_NAME
, FALSE
))
1599 win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n");
1603 ret
= RegUnLoadKeyA(HKEY_LOCAL_MACHINE
, "Test");
1604 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1606 set_privileges(SE_RESTORE_NAME
, FALSE
);
1608 DeleteFileA("saved_key");
1609 DeleteFileA("saved_key.LOG");
1612 /* tests that show that RegConnectRegistry and
1613 OpenSCManager accept computer names without the
1614 \\ prefix (what MSDN says). */
1615 static void test_regconnectregistry( void)
1617 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1618 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1619 DWORD len
= sizeof(compName
) ;
1625 SetLastError(0xdeadbeef);
1626 ret
= GetComputerNameA(compName
, &len
);
1627 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1630 lstrcpyA(netwName
, "\\\\");
1631 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1633 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1635 retl
== ERROR_DLL_INIT_FAILED
||
1636 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1637 "RegConnectRegistryA failed err = %d\n", retl
);
1638 if( !retl
) RegCloseKey( hkey
);
1640 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1642 retl
== ERROR_DLL_INIT_FAILED
||
1643 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1644 "RegConnectRegistryA failed err = %d\n", retl
);
1645 if( !retl
) RegCloseKey( hkey
);
1647 SetLastError(0xdeadbeef);
1648 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1649 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1651 win_skip("OpenSCManagerA is not implemented\n");
1655 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1656 CloseServiceHandle( schnd
);
1658 SetLastError(0xdeadbeef);
1659 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1660 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1661 CloseServiceHandle( schnd
);
1665 static void test_reg_query_value(void)
1672 static const WCHAR expected
[] = {'d','a','t','a',0};
1674 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1675 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1677 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1678 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1680 /* try an invalid hkey */
1681 SetLastError(0xdeadbeef);
1683 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1684 ok(ret
== ERROR_INVALID_HANDLE
||
1685 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1686 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1687 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1688 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1690 /* try a NULL hkey */
1691 SetLastError(0xdeadbeef);
1693 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1694 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1695 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1696 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1698 /* try a NULL value */
1700 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1701 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1702 ok(size
== 5, "Expected 5, got %d\n", size
);
1704 /* try a NULL size */
1705 SetLastError(0xdeadbeef);
1707 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1708 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1709 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1710 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1712 /* try a NULL value and size */
1713 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1714 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1716 /* try a size too small */
1717 SetLastError(0xdeadbeef);
1720 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1721 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1722 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1723 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1724 ok(size
== 5, "Expected 5, got %d\n", size
);
1726 /* successfully read the value using 'subkey' */
1728 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1729 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1730 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1731 ok(size
== 5, "Expected 5, got %d\n", size
);
1733 /* successfully read the value using the subkey key */
1735 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1736 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1737 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1738 ok(size
== 5, "Expected 5, got %d\n", size
);
1740 /* unicode - try size too small */
1741 SetLastError(0xdeadbeef);
1744 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1745 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1747 win_skip("RegQueryValueW is not implemented\n");
1750 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1751 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1752 ok(!valW
[0], "Expected valW to be untouched\n");
1753 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1755 /* unicode - try size in WCHARS */
1756 SetLastError(0xdeadbeef);
1757 size
= sizeof(valW
) / sizeof(WCHAR
);
1758 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1759 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1760 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1761 ok(!valW
[0], "Expected valW to be untouched\n");
1762 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1764 /* unicode - successfully read the value */
1765 size
= sizeof(valW
);
1766 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1767 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1768 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1769 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1771 /* unicode - set the value without a NULL terminator */
1772 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1773 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1775 /* unicode - read the unterminated value, value is terminated for us */
1776 memset(valW
, 'a', sizeof(valW
));
1777 size
= sizeof(valW
);
1778 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1779 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1780 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1781 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1784 RegDeleteKeyA(subkey
, "");
1785 RegCloseKey(subkey
);
1788 static void test_reg_query_info(void)
1793 char classbuffer
[32];
1794 WCHAR classbufferW
[32];
1795 char expectbuffer
[32];
1796 WCHAR expectbufferW
[32];
1797 char subkey_class
[] = "subkey class";
1798 WCHAR subkey_classW
[] = {'s','u','b','k','e','y',' ','c','l','a','s','s',0};
1799 char subsubkey_class
[] = "subsubkey class";
1801 DWORD subkeys
, maxsubkeylen
, maxclasslen
;
1802 DWORD values
, maxvaluenamelen
, maxvaluelen
;
1806 ret
= RegCreateKeyExA(hkey_main
, "subkey", 0, subkey_class
, 0, KEY_ALL_ACCESS
, NULL
, &subkey
, NULL
);
1807 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1809 /* all parameters NULL */
1810 ret
= RegQueryInfoKeyA(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1811 ok(ret
== ERROR_INVALID_HANDLE
, "ret = %d\n", ret
);
1813 ret
= RegQueryInfoKeyW(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1814 ok(ret
== ERROR_INVALID_HANDLE
, "ret = %d\n", ret
);
1816 /* not requesting any information */
1817 ret
= RegQueryInfoKeyA(subkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1818 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1820 ret
= RegQueryInfoKeyW(subkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1821 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1823 /* class without length is invalid */
1824 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1825 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1826 ok(ret
== ERROR_INVALID_PARAMETER
, "ret = %d\n", ret
);
1827 ok(classbuffer
[0] == 0x55, "classbuffer[0] = 0x%x\n", classbuffer
[0]);
1829 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1830 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1831 ok(ret
== ERROR_INVALID_PARAMETER
, "ret = %d\n", ret
);
1832 ok(classbufferW
[0] == 0x5555, "classbufferW[0] = 0x%x\n", classbufferW
[0]);
1836 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1837 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1838 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1839 ok(subkeys
== 0, "subkeys = %u\n", subkeys
);
1840 ok(maxsubkeylen
== 0, "maxsubkeylen = %u\n", maxsubkeylen
);
1841 ok(maxclasslen
== 0, "maxclasslen = %u\n", maxclasslen
);
1842 ok(values
== 0, "values = %u\n", values
);
1843 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1844 ok(maxvaluelen
== 0, "maxvaluelen = %u\n", maxvaluelen
);
1845 todo_wine
ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1846 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1847 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1850 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1851 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1852 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1853 ok(subkeys
== 0, "subkeys = %u\n", subkeys
);
1854 ok(maxsubkeylen
== 0, "maxsubkeylen = %u\n", maxsubkeylen
);
1855 ok(maxclasslen
== 0, "maxclasslen = %u\n", maxclasslen
);
1856 ok(values
== 0, "values = %u\n", values
);
1857 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1858 ok(maxvaluelen
== 0, "maxvaluelen = %u\n", maxvaluelen
);
1859 todo_wine
ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1860 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1861 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1863 ret
= RegCreateKeyExA(subkey
, "subsubkey", 0, subsubkey_class
, 0, KEY_ALL_ACCESS
, NULL
, &subsubkey
, NULL
);
1864 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1866 ret
= RegSetValueExA(subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"data", 5);
1867 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1869 /* with subkey & default value */
1871 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1872 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1873 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1874 ok(subkeys
== 1, "subkeys = %u\n", subkeys
);
1875 ok(maxsubkeylen
== strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen
);
1876 ok(maxclasslen
== strlen(subsubkey_class
), "maxclasslen = %u\n", maxclasslen
);
1877 ok(values
== 1, "values = %u\n", values
);
1878 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1879 ok(maxvaluelen
== sizeof("data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1880 todo_wine
ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1881 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1882 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1885 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1886 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1887 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1888 ok(subkeys
== 1, "subkeys = %u\n", subkeys
);
1889 ok(maxsubkeylen
== strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen
);
1890 ok(maxclasslen
== strlen(subsubkey_class
), "maxclasslen = %u\n", maxclasslen
);
1891 ok(values
== 1, "values = %u\n", values
);
1892 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1893 ok(maxvaluelen
== sizeof("data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1894 todo_wine
ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1895 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1896 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1898 ret
= RegSetValueExA(subkey
, "value one", 0, REG_SZ
, (const BYTE
*)"first value data", 17);
1899 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1901 ret
= RegSetValueExA(subkey
, "value 2", 0, REG_SZ
, (const BYTE
*)"second value data", 18);
1902 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1904 /* with named value */
1905 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1906 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1907 ok(values
== 3, "values = %u\n", values
);
1908 ok(maxvaluenamelen
== strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen
);
1909 ok(maxvaluelen
== sizeof("second value data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1911 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1912 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1913 ok(values
== 3, "values = %u\n", values
);
1914 ok(maxvaluenamelen
== strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen
);
1915 ok(maxvaluelen
== sizeof("second value data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1917 /* class name with zero size buffer */
1918 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1920 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1921 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1922 ok(classlen
== strlen(subkey_class
) /* win2k */ ||
1923 classlen
== 0, "classlen = %u\n", classlen
);
1924 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1925 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)), "classbuffer was modified\n");
1927 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1929 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1930 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1931 ok(classlen
== strlen(subkey_class
) /* win2k */ ||
1932 classlen
== 0, "classlen = %u\n", classlen
);
1933 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1934 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1936 /* class name with one char buffer */
1937 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1939 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1940 ok(ret
== ERROR_MORE_DATA
, "ret = %d\n", ret
);
1941 ok(classlen
== 0, "classlen = %u\n", classlen
);
1942 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1943 expectbuffer
[0] = 0;
1944 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)), "classbuffer was modified\n");
1946 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1948 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1949 ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "ret = %d\n", ret
);
1950 ok(classlen
== 0 /* win8 */ ||
1951 classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1952 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1953 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1955 /* class name with buffer one char too small */
1956 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1957 classlen
= sizeof(subkey_class
) - 1;
1958 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1959 ok(ret
== ERROR_MORE_DATA
, "ret = %d\n", ret
);
1960 ok(classlen
== sizeof(subkey_class
) - 2, "classlen = %u\n", classlen
);
1961 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1962 strcpy(expectbuffer
, subkey_class
);
1963 expectbuffer
[sizeof(subkey_class
) - 2] = 0;
1964 expectbuffer
[sizeof(subkey_class
) - 1] = 0x55;
1965 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)),
1966 "classbuffer = %.*s, expected %s\n",
1967 (int)sizeof(classbuffer
), classbuffer
, expectbuffer
);
1969 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1970 classlen
= sizeof(subkey_class
) - 1;
1971 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1972 ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "ret = %d\n", ret
);
1973 ok(classlen
== sizeof(subkey_class
) - 2 /* win8 */ ||
1974 classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1975 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1976 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1978 /* class name with large enough buffer */
1979 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1980 classlen
= sizeof(subkey_class
);
1981 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1982 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1983 ok(classlen
== sizeof(subkey_class
) - 1, "classlen = %u\n", classlen
);
1984 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1985 strcpy(expectbuffer
, subkey_class
);
1986 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)),
1987 "classbuffer = \"%.*s\", expected %s\n",
1988 (int)sizeof(classbuffer
), classbuffer
, expectbuffer
);
1990 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1991 classlen
= sizeof(subkey_class
);
1992 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1993 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1994 ok(classlen
== sizeof(subkey_class
) - 1, "classlen = %u\n", classlen
);
1995 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1996 lstrcpyW(expectbufferW
, subkey_classW
);
1997 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)),
1998 "classbufferW = %s, expected %s\n",
1999 wine_dbgstr_wn(classbufferW
, sizeof(classbufferW
) / sizeof(WCHAR
)), wine_dbgstr_w(expectbufferW
));
2001 RegDeleteKeyA(subsubkey
, "");
2002 RegCloseKey(subsubkey
);
2003 RegDeleteKeyA(subkey
, "");
2004 RegCloseKey(subkey
);
2007 static void test_string_termination(void)
2011 static const char string
[] = "FullString";
2014 DWORD insize
, outsize
, nsize
;
2016 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
2017 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2019 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
2020 insize
=sizeof(string
)-1;
2021 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
2022 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
2024 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
2025 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
2027 /* Off-by-two RegSetValueExA -> no trailing '\0' */
2028 insize
=sizeof(string
)-2;
2029 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
2030 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
2032 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
2033 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
2034 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
2036 /* RegQueryValueExA may return a string with no trailing '\0' */
2038 memset(buffer
, 0xbd, sizeof(buffer
));
2039 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
2040 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
2041 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
2042 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
2043 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
2044 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
2046 /* RegQueryValueExA adds a trailing '\0' if there is room */
2048 memset(buffer
, 0xbd, sizeof(buffer
));
2049 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
2050 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
2051 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
2052 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
2053 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
2054 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
2056 /* RegEnumValueA may return a string with no trailing '\0' */
2058 memset(buffer
, 0xbd, sizeof(buffer
));
2060 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
2061 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
2062 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
2063 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
2064 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
2065 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
2066 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
2068 /* RegEnumValueA adds a trailing '\0' if there is room */
2070 memset(buffer
, 0xbd, sizeof(buffer
));
2072 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
2073 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
2074 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
2075 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
2076 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
2077 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
2078 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
2080 RegDeleteKeyA(subkey
, "");
2081 RegCloseKey(subkey
);
2084 static void test_reg_copy_tree(void)
2086 HKEY src
, dst
, subkey
;
2087 CHAR buffer
[MAX_PATH
];
2093 win_skip("Skipping RegCopyTreeA tests, function not present\n");
2097 ret
= RegCreateKeyA(hkey_main
, "src", &src
);
2098 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2099 ret
= RegCreateKeyA(hkey_main
, "dst", &dst
);
2100 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2102 /* Copy nonexistent subkey */
2103 ret
= pRegCopyTreeA(src
, "nonexistent_subkey", dst
);
2104 ok(ret
== ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
2106 /* Create test keys and values */
2107 ret
= RegSetValueA(src
, NULL
, REG_SZ
, "data", 4);
2108 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2109 ret
= RegSetValueExA(src
, "value", 0, REG_SZ
, (const BYTE
*)"data2", 5);
2110 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2112 ret
= RegCreateKeyA(src
, "subkey2", &subkey
);
2113 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2114 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data3", 5);
2115 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2116 ret
= RegSetValueExA(subkey
, "value", 0, REG_SZ
, (const BYTE
*)"data4", 5);
2117 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2118 ret
= RegCloseKey(subkey
);
2119 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2121 ret
= RegCreateKeyA(src
, "subkey3", &subkey
);
2122 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2123 ret
= RegCloseKey(subkey
);
2124 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2127 ret
= pRegCopyTreeA(src
, "subkey2", dst
);
2128 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2131 ret
= RegQueryValueA(dst
, NULL
, buffer
, &size
);
2132 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2133 ok(!strcmp(buffer
, "data3"), "Expected 'data3', got '%s'\n", buffer
);
2136 ret
= RegQueryValueExA(dst
, "value", NULL
, &type
, (BYTE
*)buffer
, &dwsize
);
2137 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2138 ok(type
== REG_SZ
, "Expected REG_SZ, got %u\n", type
);
2139 ok(!strcmp(buffer
, "data4"), "Expected 'data4', got '%s'\n", buffer
);
2141 /* Copy full tree */
2142 ret
= pRegCopyTreeA(src
, NULL
, dst
);
2143 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2146 ret
= RegQueryValueA(dst
, NULL
, buffer
, &size
);
2147 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2148 ok(!strcmp(buffer
, "data"), "Expected 'data', got '%s'\n", buffer
);
2151 ret
= RegQueryValueExA(dst
, "value", NULL
, &type
, (BYTE
*)buffer
, &dwsize
);
2152 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2153 ok(type
== REG_SZ
, "Expected REG_SZ, got %u\n", type
);
2154 ok(!strcmp(buffer
, "data2"), "Expected 'data2', got '%s'\n", buffer
);
2156 ret
= RegOpenKeyA(dst
, "subkey2", &subkey
);
2157 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2159 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
2160 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2161 ok(!strcmp(buffer
, "data3"), "Expected 'data3', got '%s'\n", buffer
);
2163 ret
= RegQueryValueExA(subkey
, "value", NULL
, &type
, (BYTE
*)buffer
, &dwsize
);
2164 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2165 ok(type
== REG_SZ
, "Expected REG_SZ, got %u\n", type
);
2166 ok(!strcmp(buffer
, "data4"), "Expected 'data4', got '%s'\n", buffer
);
2167 ret
= RegCloseKey(subkey
);
2168 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2170 ret
= RegOpenKeyA(dst
, "subkey3", &subkey
);
2171 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2172 ret
= RegCloseKey(subkey
);
2173 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2179 static void test_reg_delete_tree(void)
2181 CHAR buffer
[MAX_PATH
];
2182 HKEY subkey
, subkey2
;
2186 if(!pRegDeleteTreeA
) {
2187 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
2191 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
2192 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2193 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
2194 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2195 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
2196 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2197 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
2198 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2199 ret
= RegCloseKey(subkey2
);
2200 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2202 ret
= pRegDeleteTreeA(subkey
, "subkey2");
2203 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2204 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
2205 "subkey2 was not deleted\n");
2207 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
2208 "Default value of subkey not longer present\n");
2210 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
2211 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2212 ret
= RegCloseKey(subkey2
);
2213 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2214 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
2215 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2216 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
2217 "subkey2 was not deleted\n");
2218 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
2219 "Default value of subkey not longer present\n");
2221 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
2222 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2223 ret
= RegCloseKey(subkey2
);
2224 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2225 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
2226 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2227 ret
= RegCloseKey(subkey2
);
2228 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2229 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
2230 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2231 ret
= RegSetValueExA(subkey
, "value", 0, REG_SZ
, (const BYTE
*)"data2", 5);
2232 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2233 ret
= pRegDeleteTreeA(subkey
, NULL
);
2234 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2235 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
2236 "subkey was deleted\n");
2237 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
2238 "subkey2 was not deleted\n");
2239 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
2240 "subkey3 was not deleted\n");
2242 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
2243 ok(ret
== ERROR_SUCCESS
,
2244 "Default value of subkey is not present\n");
2245 ok(!buffer
[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
2247 ok(RegQueryValueExA(subkey
, "value", NULL
, &type
, (BYTE
*)buffer
, &dwsize
),
2248 "Value is still present\n");
2250 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
2251 ok(ret
== ERROR_FILE_NOT_FOUND
,
2252 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
2255 static void test_rw_order(void)
2259 static const char keyname
[] = "test_rw_order";
2261 DWORD values
, value_len
, value_name_max_len
;
2264 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
2265 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
2266 if(ret
!= ERROR_SUCCESS
) {
2267 skip("Couldn't create key. Skipping.\n");
2271 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2272 "RegSetValueExA for value \"A\" failed\n");
2273 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2274 "RegSetValueExA for value \"C\" failed\n");
2275 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2276 "RegSetValueExA for value \"D\" failed\n");
2277 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2278 "RegSetValueExA for value \"B\" failed\n");
2280 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
2281 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
2282 ok(values
== 4, "Expected 4 values, got %u\n", values
);
2284 /* Value enumeration preserves RegSetValueEx call order */
2286 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2287 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
2289 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2290 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
2292 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2293 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
2295 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2296 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
2298 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
2301 static void test_symlinks(void)
2303 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
2304 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
2306 UNICODE_STRING target_str
;
2310 DWORD target_len
, type
, len
, dw
, err
;
2312 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
2314 win_skip( "Can't perform symlink tests\n" );
2318 pRtlFormatCurrentUserKeyPath( &target_str
);
2320 target_len
= target_str
.Length
+ sizeof(targetW
);
2321 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
2322 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
2323 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
2325 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
2326 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
2327 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
2329 /* REG_SZ is not allowed */
2330 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
2331 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
2332 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
2333 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2334 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2335 /* other values are not allowed */
2336 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2337 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
2339 /* try opening the target through the link */
2341 err
= RegOpenKeyA( hkey_main
, "link", &key
);
2342 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
2344 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2345 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2348 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2349 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2352 err
= RegOpenKeyA( hkey_main
, "link", &key
);
2353 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
2355 len
= sizeof(buffer
);
2356 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
2357 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
2358 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
2360 len
= sizeof(buffer
);
2361 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2362 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
2364 /* REG_LINK can be created in non-link keys */
2365 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
2366 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2367 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2368 len
= sizeof(buffer
);
2369 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2370 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2371 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2372 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
2373 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
2377 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2378 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2380 len
= sizeof(buffer
);
2381 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
2382 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2383 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
2385 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2386 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
2389 /* now open the symlink itself */
2391 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
2392 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
2393 len
= sizeof(buffer
);
2394 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2395 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2396 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2399 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
2400 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2401 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2402 len
= sizeof(buffer
);
2403 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2404 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2405 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2408 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
2409 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2410 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
2412 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
2413 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2414 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
2416 err
= RegDeleteKeyA( hkey_main
, "target" );
2417 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
2419 err
= RegDeleteKeyA( hkey_main
, "link" );
2420 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
2422 status
= pNtDeleteKey( link
);
2423 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
2424 RegCloseKey( link
);
2426 HeapFree( GetProcessHeap(), 0, target
);
2427 pRtlFreeUnicodeString( &target_str
);
2430 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
2433 DWORD err
, type
, dw
, len
= sizeof(dw
);
2435 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2436 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
2437 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
2439 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2440 if (err
== ERROR_FILE_NOT_FOUND
)
2443 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
2448 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
2450 DWORD dw
= get_key_value( root
, name
, flags
);
2451 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
2453 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
2455 static void test_redirection(void)
2457 DWORD err
, type
, dw
, len
;
2458 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
2459 BOOL is_vista
= FALSE
;
2460 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
2465 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
2467 skip( "Not on Wow64, no redirection\n" );
2472 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2473 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
2474 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2476 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2477 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
2478 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2480 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2481 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
2482 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2484 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2485 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
2486 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2489 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2490 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2493 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2494 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2498 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2499 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2500 ok( dw
== 32, "wrong value %u\n", dw
);
2504 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2505 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2506 ok( dw
== 64, "wrong value %u\n", dw
);
2508 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2509 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2510 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2514 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2515 /* the new (and simpler) Win7 mechanism doesn't */
2516 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2518 trace( "using Vista-style Wow6432Node handling\n" );
2521 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2522 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2523 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2524 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2525 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2526 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2530 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
2532 trace( "using Vista-style Wow6432Node handling\n" );
2535 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2536 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2542 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2543 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2544 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2545 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2546 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2547 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2548 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2549 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2550 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
2551 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
2552 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2555 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2556 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2557 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2558 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2559 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2560 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2561 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2562 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2563 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2568 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2569 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2570 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2571 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2572 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2573 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
);
2574 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2575 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2578 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2579 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2580 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2581 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2582 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
);
2583 ok( dw
== 32 || broken(dw
== 64) /* vista */, "wrong value %u\n", dw
);
2584 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2588 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
2589 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2592 /* KEY_WOW64 flags have no effect on 64-bit */
2593 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2594 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2595 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2596 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2600 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2601 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2602 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2603 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2606 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2607 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2608 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2609 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2610 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2611 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2616 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2617 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2618 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2619 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2620 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2621 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2622 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2625 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2626 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2627 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2628 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2629 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2630 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2634 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2635 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2636 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2637 check_key_value( key
, "Winetest", 0, 32 );
2638 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2639 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2644 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2645 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2646 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2647 dw
= get_key_value( key
, "Winetest", 0 );
2648 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2649 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2650 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2653 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2654 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2655 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2656 check_key_value( key
, "Winetest", 0, 32 );
2657 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2658 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2662 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2663 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2664 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2665 check_key_value( key
, "Winetest", 0, ptr_size
);
2666 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2667 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2668 todo_wine_if (ptr_size
!= 32)
2669 ok( dw
== 32, "wrong value %u\n", dw
);
2674 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2675 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2676 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2677 dw
= get_key_value( key
, "Winetest", 0 );
2678 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2679 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2680 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2681 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2684 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2685 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2686 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2687 check_key_value( key
, "Winetest", 0, 32 );
2688 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2689 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2693 if (pRegDeleteKeyExA
)
2695 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2696 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2697 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2698 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2699 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2700 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2704 err
= RegDeleteKeyA( key32
, "" );
2705 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2706 err
= RegDeleteKeyA( key64
, "" );
2707 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2708 RegDeleteKeyA( key64
, "" );
2709 RegDeleteKeyA( root64
, "" );
2711 RegCloseKey( key32
);
2712 RegCloseKey( key64
);
2713 RegCloseKey( root32
);
2714 RegCloseKey( root64
);
2716 /* open key in native bit mode */
2717 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2718 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2720 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2722 /* write subkey in opposite bit mode */
2723 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2724 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2726 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2728 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2729 if(err
!= ERROR_SUCCESS
){
2730 win_skip("Can't write to registry\n");
2731 RegCloseKey(op_key
);
2732 RegCloseKey(native
);
2737 /* verify subkey is not present in native mode */
2738 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2739 ok(err
== ERROR_FILE_NOT_FOUND
||
2740 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2743 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2744 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2746 RegCloseKey(op_key
);
2747 RegCloseKey(native
);
2750 static void test_classesroot(void)
2752 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2754 DWORD type
= REG_SZ
;
2755 static CHAR buffer
[8];
2758 /* create a key in the user's classes */
2759 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2762 RegCloseKey( hkey
);
2764 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2765 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2766 if (res
== ERROR_ACCESS_DENIED
)
2768 skip("not enough privileges to add a user class\n");
2771 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2773 /* try to open that key in hkcr */
2774 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2775 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2776 todo_wine
ok(res
== ERROR_SUCCESS
||
2777 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2778 "test key not found in hkcr: %d\n", res
);
2781 skip("HKCR key merging not supported\n");
2783 RegCloseKey( hkey
);
2787 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2789 /* set a value in user's classes */
2790 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2791 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2793 /* try to find the value in hkcr */
2794 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2795 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2796 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2798 /* modify the value in hkcr */
2799 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2800 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2802 /* check if the value is also modified in user's classes */
2803 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2804 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2805 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2807 /* set a value in hkcr */
2808 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2809 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2811 /* try to find the value in user's classes */
2812 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2813 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2814 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2816 /* modify the value in user's classes */
2817 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2818 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2820 /* check if the value is also modified in hkcr */
2821 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2822 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2823 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2828 RegCloseKey( hkey
);
2829 RegCloseKey( hkcr
);
2831 /* create a key in the hklm classes */
2832 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2835 RegCloseKey( hklm
);
2837 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2838 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2839 if (res
== ERROR_ACCESS_DENIED
)
2841 skip("not enough privileges to add a system class\n");
2844 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2846 /* try to open that key in hkcr */
2847 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2848 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2849 ok(res
== ERROR_SUCCESS
,
2850 "test key not found in hkcr: %d\n", res
);
2851 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2855 RegCloseKey( hklm
);
2859 /* set a value in hklm classes */
2860 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2861 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2863 /* try to find the value in hkcr */
2864 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2865 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2866 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2868 /* modify the value in hkcr */
2869 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2870 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2872 /* check that the value is modified in hklm classes */
2873 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2874 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2875 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2877 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2878 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2879 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2881 /* try to open that key in hkcr */
2882 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2883 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2884 ok(res
== ERROR_SUCCESS
,
2885 "test key not found in hkcr: %d\n", res
);
2886 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2888 /* set a value in user's classes */
2889 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2890 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2892 /* try to find the value in hkcr */
2893 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2894 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2895 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2897 /* modify the value in hklm */
2898 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2899 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2901 /* check that the value is not overwritten in hkcr or user's classes */
2902 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2903 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2904 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2905 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2906 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2907 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2909 /* modify the value in hkcr */
2910 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2911 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2913 /* check that the value is overwritten in hklm and user's classes */
2914 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2915 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2916 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2917 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2918 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2919 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2921 /* create a subkey in hklm */
2922 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2923 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2924 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2925 /* try to open that subkey in hkcr */
2926 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2927 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2928 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2930 /* set a value in hklm classes */
2931 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2932 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2934 /* try to find the value in hkcr */
2935 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2936 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2937 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2939 /* modify the value in hkcr */
2940 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2941 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2943 /* check that the value is modified in hklm classes */
2944 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2945 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2946 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2948 /* create a subkey in user's classes */
2949 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2950 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2951 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2953 /* set a value in user's classes */
2954 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2955 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2957 /* try to find the value in hkcr */
2958 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2959 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2960 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2962 /* modify the value in hklm */
2963 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2964 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2966 /* check that the value is not overwritten in hkcr or user's classes */
2967 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2968 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2969 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2970 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2971 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2972 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2974 /* modify the value in hkcr */
2975 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2976 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2978 /* check that the value is not overwritten in hklm, but in user's classes */
2979 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2980 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2981 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2982 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2983 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2984 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2986 /* new subkey in hkcr */
2987 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2988 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2989 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2990 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2991 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2993 /* try to open that new subkey in user's classes and hklm */
2994 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2995 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2997 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2998 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2999 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
3001 /* check that the value is present in hklm */
3002 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
3003 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
3004 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
3007 RegCloseKey( hkeysub1
);
3008 RegCloseKey( hklmsub1
);
3010 /* delete subkey1 from hkcr (should point at user's classes) */
3011 res
= RegDeleteKeyA(hkcr
, "subkey1");
3012 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
3014 /* confirm key was removed in hkey but not hklm */
3015 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
3016 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
3017 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
3018 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
3019 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
3021 /* delete subkey1 from hkcr again (which should now point at hklm) */
3022 res
= RegDeleteKeyA(hkcr
, "subkey1");
3023 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
3025 /* confirm hkey was removed in hklm */
3026 RegCloseKey( hklmsub1
);
3027 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
3028 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
3034 delete_key( hkeysub1
);
3035 delete_key( hklmsub1
);
3036 delete_key( hkcrsub1
);
3037 delete_key( hklmsub2
);
3038 delete_key( hkcrsub2
);
3039 RegCloseKey( hkey
);
3040 RegCloseKey( hklm
);
3041 RegCloseKey( hkcr
);
3042 RegCloseKey( hkeysub1
);
3043 RegCloseKey( hklmsub1
);
3044 RegCloseKey( hkcrsub1
);
3045 RegCloseKey( hklmsub2
);
3046 RegCloseKey( hkcrsub2
);
3049 static void test_classesroot_enum(void)
3051 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
3053 static CHAR buffer
[2];
3056 /* prepare initial testing env in HKCU */
3057 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
3060 RegCloseKey( hkcu
);
3062 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
3063 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
3065 if (res
!= ERROR_SUCCESS
)
3067 skip("failed to add a user class\n");
3071 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
3072 todo_wine
ok(res
== ERROR_SUCCESS
||
3073 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
3074 "test key not found in hkcr: %d\n", res
);
3077 skip("HKCR key merging not supported\n");
3079 RegCloseKey( hkcu
);
3083 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
3084 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
3085 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
3086 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
3087 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
3088 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
3089 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
3090 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
3092 /* test on values in HKCU */
3093 size
= sizeof(buffer
);
3094 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3095 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3096 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
3097 size
= sizeof(buffer
);
3098 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3099 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3100 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
3101 size
= sizeof(buffer
);
3102 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3103 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3105 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
3106 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3107 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
3108 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
3109 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3110 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
3111 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
3112 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3114 /* prepare test env in HKLM */
3115 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
3118 RegCloseKey( hklm
);
3121 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
3122 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
3124 if (res
== ERROR_ACCESS_DENIED
)
3126 RegCloseKey( hkcusub
[0] );
3127 RegCloseKey( hkcusub
[1] );
3129 RegCloseKey( hkcu
);
3130 RegCloseKey( hkcr
);
3131 skip("not enough privileges to add a system class\n");
3135 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
3136 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
3137 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
3138 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
3139 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
3140 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
3141 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
3142 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
3144 /* test on values/keys in both HKCU and HKLM */
3145 size
= sizeof(buffer
);
3146 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3147 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3148 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
3149 size
= sizeof(buffer
);
3150 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3151 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3152 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
3153 size
= sizeof(buffer
);
3154 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3155 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3156 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
3157 size
= sizeof(buffer
);
3158 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3159 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3161 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
3162 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3163 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
3164 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
3165 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3166 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
3167 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
3168 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3169 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
3170 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
3171 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3173 /* delete values/keys from HKCU to test only on HKLM */
3174 RegCloseKey( hkcusub
[0] );
3175 RegCloseKey( hkcusub
[1] );
3177 RegCloseKey( hkcu
);
3179 size
= sizeof(buffer
);
3180 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3181 ok(res
== ERROR_KEY_DELETED
||
3182 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
3183 "expected ERROR_KEY_DELETED, got %d\n", res
);
3184 size
= sizeof(buffer
);
3185 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
3186 ok(res
== ERROR_KEY_DELETED
||
3187 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
3188 "expected ERROR_KEY_DELETED, got %d\n", res
);
3190 /* reopen HKCR handle */
3191 RegCloseKey( hkcr
);
3192 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
3193 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
3194 if (res
) goto cleanup
;
3196 /* test on values/keys in HKLM */
3197 size
= sizeof(buffer
);
3198 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3199 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3200 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
3201 size
= sizeof(buffer
);
3202 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3203 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
3204 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
3205 size
= sizeof(buffer
);
3206 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
3207 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3209 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
3210 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3211 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
3212 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
3213 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
3214 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
3215 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
3216 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3219 RegCloseKey( hklmsub
[0] );
3220 RegCloseKey( hklmsub
[1] );
3222 RegCloseKey( hklm
);
3223 RegCloseKey( hkcr
);
3226 static void test_classesroot_mask(void)
3231 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
3232 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3233 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
3234 "hkcr mask not set in %p\n", hkey
);
3235 RegCloseKey( hkey
);
3237 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
3238 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3239 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3240 RegCloseKey( hkey
);
3242 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
3243 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3244 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3245 RegCloseKey( hkey
);
3247 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
3248 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3249 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3250 RegCloseKey( hkey
);
3252 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
3253 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3254 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3255 RegCloseKey( hkey
);
3258 static void test_deleted_key(void)
3262 DWORD val_count
, type
;
3265 /* Open the test key, then delete it while it's open */
3266 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
3268 delete_key( hkey_main
);
3270 val_count
= sizeof(value
);
3272 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
3273 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3275 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
3276 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3278 val_count
= sizeof(value
);
3280 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
3281 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3283 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3284 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3286 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
3287 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3289 RegCloseKey( hkey2
);
3291 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
3292 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3294 RegCloseKey( hkey2
);
3296 res
= RegFlushKey( hkey
);
3297 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3299 RegCloseKey( hkey
);
3304 static void test_delete_value(void)
3309 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
3310 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3312 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3313 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3315 res
= RegDeleteValueA( hkey_main
, "test" );
3316 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3318 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3319 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3321 res
= RegDeleteValueA( hkey_main
, "test" );
3322 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3324 memset(longname
, 'a', 400);
3326 res
= RegDeleteValueA( hkey_main
, longname
);
3327 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
3328 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3331 static void test_delete_key_value(void)
3336 if (!pRegDeleteKeyValueA
)
3338 win_skip("RegDeleteKeyValue is not available.\n");
3342 ret
= pRegDeleteKeyValueA(NULL
, NULL
, NULL
);
3343 ok(ret
== ERROR_INVALID_HANDLE
, "got %d\n", ret
);
3345 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, NULL
);
3346 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3348 ret
= RegSetValueExA(hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3349 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3351 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3352 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3354 /* NULL subkey name means delete from open key */
3355 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, "test");
3356 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3358 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3359 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3361 /* now with real subkey */
3362 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &subkey
, NULL
);
3363 ok(!ret
, "failed with error %d\n", ret
);
3365 ret
= RegSetValueExA(subkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3366 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3368 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
3369 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3371 ret
= pRegDeleteKeyValueA(hkey_main
, "Subkey1", "test");
3372 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3374 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
3375 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3377 RegDeleteKeyA(subkey
, "");
3378 RegCloseKey(subkey
);
3381 static void test_RegOpenCurrentUser(void)
3386 key
= HKEY_CURRENT_USER
;
3387 ret
= RegOpenCurrentUser(KEY_READ
, &key
);
3388 ok(!ret
, "got %d, error %d\n", ret
, GetLastError());
3389 ok(key
!= HKEY_CURRENT_USER
, "got %p\n", key
);
3393 START_TEST(registry
)
3395 /* Load pointers for functions that are not available in all Windows versions */
3401 create_test_entries();
3403 test_query_value_ex();
3405 test_reg_open_key();
3406 test_reg_create_key();
3407 test_reg_close_key();
3408 test_reg_delete_key();
3409 test_reg_query_value();
3410 test_reg_query_info();
3411 test_string_termination();
3415 test_classesroot_enum();
3416 test_classesroot_mask();
3417 test_reg_save_key();
3418 test_reg_load_key();
3419 test_reg_unload_key();
3420 test_reg_copy_tree();
3421 test_reg_delete_tree();
3424 test_delete_value();
3425 test_delete_key_value();
3426 test_RegOpenCurrentUser();
3429 delete_key( hkey_main
);
3431 test_regconnectregistry();