2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
23 #define WIN32_LEAN_AND_MEAN
28 #include "wine/test.h"
37 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
39 static HKEY hkey_main
;
42 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
43 static const char * sTestpath2
= "%FOO%\\subdir1";
44 static const DWORD ptr_size
= 8 * sizeof(void*);
46 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
47 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
48 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
49 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
50 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
51 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
52 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
55 /* Debugging functions from wine/libs/wine/debug.c */
57 /* allocate some tmp string space */
58 /* FIXME: this is not 100% thread-safe */
59 static char *get_temp_buffer( int size
)
61 static char *list
[32];
66 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
68 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
70 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
71 if (ret
) list
[idx
] = ret
;
75 static const char *wine_debugstr_an( const char *str
, int n
)
77 static const char hex
[16] = "0123456789abcdef";
81 if (!((ULONG_PTR
)str
>> 16))
83 if (!str
) return "(null)";
84 res
= get_temp_buffer( 6 );
85 sprintf( res
, "#%04x", LOWORD(str
) );
88 if (n
== -1) n
= strlen(str
);
90 size
= 10 + min( 300, n
* 4 );
91 dst
= res
= get_temp_buffer( size
);
93 while (n
-- > 0 && dst
<= res
+ size
- 9)
95 unsigned char c
= *str
++;
98 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
99 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
100 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
101 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
102 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
104 if (c
>= ' ' && c
<= 126)
110 *dst
++ = hex
[(c
>> 4) & 0x0f];
111 *dst
++ = hex
[c
& 0x0f];
126 #define ADVAPI32_GET_PROC(func) \
127 p ## func = (void*)GetProcAddress(hadvapi32, #func)
129 static void InitFunctionPtrs(void)
131 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
132 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
133 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
135 /* This function was introduced with Windows 2003 SP1 */
136 ADVAPI32_GET_PROC(RegGetValueA
);
137 ADVAPI32_GET_PROC(RegDeleteTreeA
);
138 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
140 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
141 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
142 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
143 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
146 /* delete key and all its subkeys */
147 static DWORD
delete_key( HKEY hkey
)
152 if ((ret
= RegOpenKeyExA( hkey
, "", 0, KEY_ENUMERATE_SUB_KEYS
, &hkey
))) return ret
;
153 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
156 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
158 ret
= delete_key( tmp
);
163 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
164 RegDeleteKeyA( hkey
, "" );
169 static void setup_main_key(void)
171 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
173 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
176 #define lok ok_(__FILE__, line)
177 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
178 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
181 DWORD ret
, type
, cbData
;
187 /* When successful RegQueryValueExA() leaves GLE as is,
188 * so we must reset it to detect unimplemented functions.
190 SetLastError(0xdeadbeef);
191 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
192 GLE
= GetLastError();
193 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
194 /* It is wrong for the Ansi version to not be implemented */
195 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
196 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
198 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
199 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
200 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
202 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
203 memset(value
, 0xbd, cbData
+1);
205 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
206 GLE
= GetLastError();
207 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
210 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
211 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
215 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
216 wine_debugstr_an((char*)value
, cbData
), cbData
,
217 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
218 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
220 HeapFree(GetProcessHeap(), 0, value
);
223 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
224 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
227 DWORD ret
, type
, cbData
;
232 /* When successful RegQueryValueExW() leaves GLE as is,
233 * so we must reset it to detect unimplemented functions.
235 SetLastError(0xdeadbeef);
236 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
237 GLE
= GetLastError();
238 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
239 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
241 win_skip("RegQueryValueExW() is not implemented\n");
245 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
246 lok(cbData
== full_byte_len
,
247 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
249 /* Give enough space to overflow by one WCHAR */
250 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
251 memset(value
, 0xbd, cbData
+2);
253 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
254 GLE
= GetLastError();
255 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
258 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
259 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
260 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
262 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
263 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
264 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
265 HeapFree(GetProcessHeap(), 0, value
);
268 static void test_set_value(void)
272 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
273 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};
274 static const WCHAR emptyW
[] = {0};
275 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
276 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};
277 static const WCHAR substring2W
[] = {'T','h','i','s',0};
279 static const char name1A
[] = "CleanSingleString";
280 static const char name2A
[] = "SomeIntraZeroedString";
281 static const char emptyA
[] = "";
282 static const char string1A
[] = "ThisNeverBreaks";
283 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
284 static const char substring2A
[] = "This";
288 /* Crashes on NT4, Windows 2000 and XP SP1 */
289 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
290 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
293 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
294 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
295 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
296 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
298 /* RegSetValueA ignores the size passed in */
299 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
300 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
301 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
302 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
304 /* stops at first null */
305 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
306 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
307 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
308 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
310 /* only REG_SZ is supported on NT*/
311 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
312 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
314 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
315 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
317 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
318 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
320 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
321 * Surprisingly enough we're supposed to get zero bytes out of it.
323 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
324 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
325 test_hkey_main_Value_A(name1A
, NULL
, 0);
326 test_hkey_main_Value_W(name1W
, NULL
, 0);
328 /* test RegSetValueExA with an empty string */
329 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
330 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
331 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
332 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
334 /* test RegSetValueExA with off-by-one size */
335 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
336 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
337 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
338 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
340 /* test RegSetValueExA with normal string */
341 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
342 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
343 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
344 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
346 /* test RegSetValueExA with intrazeroed string */
347 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
348 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
349 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
350 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
354 /* Crashes on NT4, Windows 2000 and XP SP1 */
355 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
356 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
358 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
359 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
362 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
363 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
364 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
365 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
367 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
368 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
369 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
370 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
372 /* RegSetValueW ignores the size passed in */
373 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
374 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
375 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
376 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
378 /* stops at first null */
379 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
380 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
381 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
382 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
384 /* only REG_SZ is supported */
385 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
386 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
387 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
388 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
389 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
390 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
392 /* test RegSetValueExW with off-by-one size */
393 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
394 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
395 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
396 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
398 /* test RegSetValueExW with normal string */
399 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
400 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
401 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
402 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
404 /* test RegSetValueExW with intrazeroed string */
405 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
406 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
407 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
408 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
410 /* test RegSetValueExW with data = 1 */
411 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
412 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
413 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
414 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
417 static void create_test_entries(void)
419 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
421 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
422 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
424 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
425 "RegSetValueExA failed\n");
426 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
427 "RegSetValueExA failed\n");
428 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
429 "RegSetValueExA failed\n");
430 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
431 "RegSetValueExA failed\n");
432 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
433 "RegSetValueExA failed\n");
434 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
435 "RegSetValueExA failed\n");
436 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
437 "RegSetValueExA failed\n");
440 static void test_enum_value(void)
444 char value
[20], data
[20];
445 WCHAR valueW
[20], dataW
[20];
446 DWORD val_count
, data_count
, type
;
447 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
448 static const WCHAR testW
[] = {'T','e','s','t',0};
449 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
451 /* create the working key for new 'Test' value */
452 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
453 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
455 /* check NULL data with zero length */
456 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
457 if (GetVersion() & 0x80000000)
458 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
460 ok( !res
, "RegSetValueExA returned %d\n", res
);
461 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
462 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
463 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
464 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
466 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
467 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
469 /* overflow both name and data */
473 strcpy( value
, "xxxxxxxxxx" );
474 strcpy( data
, "xxxxxxxxxx" );
475 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
476 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
477 ok( val_count
== 2, "val_count set to %d\n", val_count
);
478 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
479 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
480 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
481 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
487 strcpy( value
, "xxxxxxxxxx" );
488 strcpy( data
, "xxxxxxxxxx" );
489 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
490 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
491 ok( val_count
== 3, "val_count set to %d\n", val_count
);
492 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
493 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
494 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
495 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
496 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
497 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
498 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
500 /* overflow empty name */
504 strcpy( value
, "xxxxxxxxxx" );
505 strcpy( data
, "xxxxxxxxxx" );
506 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
507 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
508 ok( val_count
== 0, "val_count set to %d\n", val_count
);
509 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
510 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
511 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
512 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
513 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
514 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
520 strcpy( value
, "xxxxxxxxxx" );
521 strcpy( data
, "xxxxxxxxxx" );
522 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
523 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
524 ok( val_count
== 20, "val_count set to %d\n", val_count
);
525 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
526 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
527 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
528 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
534 strcpy( value
, "xxxxxxxxxx" );
535 strcpy( data
, "xxxxxxxxxx" );
536 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
537 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
538 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
539 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
540 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
541 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
542 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
546 SetLastError(0xdeadbeef);
547 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
548 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
550 win_skip("RegSetValueExW is not implemented\n");
553 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
555 /* overflow both name and data */
559 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
560 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
561 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
562 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
563 ok( val_count
== 2, "val_count set to %d\n", val_count
);
564 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
565 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
566 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
567 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
573 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
574 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
575 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
576 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
577 ok( val_count
== 3, "val_count set to %d\n", val_count
);
578 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
579 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
580 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
581 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
587 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
588 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
589 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
590 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
591 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
592 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
593 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
594 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
595 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
601 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
602 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
603 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
604 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
605 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
606 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
607 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
608 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
609 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
612 RegDeleteKeyA(test_key
, "");
613 RegCloseKey(test_key
);
616 static void test_query_value_ex(void)
623 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
624 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
625 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
626 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
630 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
631 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
632 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
634 size
= sizeof(buffer
);
635 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
636 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
637 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
640 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
641 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
644 static void test_get_value(void)
651 CHAR expanded
[] = "bar\\subdir1";
652 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
656 win_skip("RegGetValue not available on this platform\n");
660 /* Invalid parameter */
661 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
662 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
664 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
665 size
= type
= dw
= 0xdeadbeef;
666 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
667 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
668 ok(size
== 4, "size=%d\n", size
);
669 ok(type
== REG_DWORD
, "type=%d\n", type
);
670 ok(dw
== 0x12345678, "dw=%d\n", dw
);
672 /* Query by subkey-name */
673 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
674 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
676 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
677 size
= type
= dw
= 0xdeadbeef;
678 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
679 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
680 /* Although the function failed all values are retrieved */
681 ok(size
== 4, "size=%d\n", size
);
682 ok(type
== REG_DWORD
, "type=%d\n", type
);
683 ok(dw
== 0x12345678, "dw=%d\n", dw
);
685 /* Test RRF_ZEROONFAILURE */
686 type
= dw
= 0xdeadbeef; size
= 4;
687 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
688 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
689 /* Again all values are retrieved ... */
690 ok(size
== 4, "size=%d\n", size
);
691 ok(type
== REG_DWORD
, "type=%d\n", type
);
692 /* ... except the buffer, which is zeroed out */
693 ok(dw
== 0, "dw=%d\n", dw
);
695 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
696 type
= size
= 0xbadbeef;
697 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
698 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
699 ok(size
== 4, "size=%d\n", size
);
700 ok(type
== REG_DWORD
, "type=%d\n", type
);
702 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
703 size
= type
= dw
= 0xdeadbeef;
704 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
705 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
706 ok(size
== 4, "size=%d\n", size
);
707 ok(type
== REG_DWORD
, "type=%d\n", type
);
708 ok(dw
== 0x12345678, "dw=%d\n", dw
);
710 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
711 size
= type
= dw
= 0xdeadbeef;
712 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
713 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
714 ok(size
== 4, "size=%d\n", size
);
715 ok(type
== REG_BINARY
, "type=%d\n", type
);
716 ok(dw
== 0x12345678, "dw=%d\n", dw
);
718 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
719 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
720 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
721 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
722 ok(size
== 8, "size=%d\n", size
);
723 ok(type
== REG_BINARY
, "type=%d\n", type
);
724 ok(qw
[0] == 0x12345678 &&
725 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
727 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
728 type
= dw
= 0xdeadbeef; size
= 4;
729 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
730 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
731 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
732 ok(size
== 8, "size=%d\n", size
);
734 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
735 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
736 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
737 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
738 ok(size
== 8, "size=%d\n", size
);
739 ok(type
== REG_BINARY
, "type=%d\n", type
);
740 ok(qw
[0] == 0x12345678 &&
741 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
743 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
744 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
745 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
746 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
747 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
748 ok(type
== REG_SZ
, "type=%d\n", type
);
749 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
751 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
752 type
= 0xdeadbeef; size
= 0;
753 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
754 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
755 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
756 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
757 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
758 ok(type
== REG_SZ
, "type=%d\n", type
);
760 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
761 strcpy(buf
, sTestpath1
);
764 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
765 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
766 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
768 size
== 1, /* win2k3 */
770 ok(type
== REG_SZ
, "type=%d\n", type
);
771 ok(!strcmp(sTestpath1
, buf
) ||
773 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
775 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
776 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
777 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
778 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
779 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
780 ok(type
== REG_SZ
, "type=%d\n", type
);
781 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
783 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
785 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
786 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
787 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
788 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
789 (size
== strlen(sTestpath2
)+1),
790 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
792 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
793 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
794 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
795 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
796 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
797 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
798 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
799 ok(type
== REG_SZ
, "type=%d\n", type
);
800 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
802 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
803 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
804 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
805 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
806 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
807 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
808 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
809 ok(type
== REG_SZ
, "type=%d\n", type
);
810 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
812 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
813 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
814 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
815 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
816 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
817 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
818 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
820 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
822 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
823 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
824 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
825 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
826 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
828 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
829 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
830 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
832 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
833 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
834 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
835 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
837 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
838 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
839 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
840 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
841 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
842 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
843 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
844 ok(type
== REG_SZ
, "type=%d\n", type
);
845 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
848 static void test_reg_open_key(void)
851 HKEY hkResult
= NULL
;
852 HKEY hkPreserve
= NULL
;
853 HKEY hkRoot64
= NULL
;
854 HKEY hkRoot32
= NULL
;
856 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
858 EXPLICIT_ACCESSA access
;
860 SECURITY_DESCRIPTOR
*sd
;
862 /* successful open */
863 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
864 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
865 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
866 hkPreserve
= hkResult
;
868 /* open same key twice */
869 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
870 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
871 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
872 ok(hkResult
!= NULL
, "hkResult != NULL\n");
873 RegCloseKey(hkResult
);
875 /* open nonexistent key
876 * check that hkResult is set to NULL
878 hkResult
= hkPreserve
;
879 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
880 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
881 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
883 /* open the same nonexistent key again to make sure the key wasn't created */
884 hkResult
= hkPreserve
;
885 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
886 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
887 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
889 /* send in NULL lpSubKey
890 * check that hkResult receives the value of hKey
892 hkResult
= hkPreserve
;
893 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
894 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
895 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
897 /* send empty-string in lpSubKey */
898 hkResult
= hkPreserve
;
899 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
900 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
901 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
903 /* send in NULL lpSubKey and NULL hKey
904 * hkResult is set to NULL
906 hkResult
= hkPreserve
;
907 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
908 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
909 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
911 /* only send NULL hKey
912 * the value of hkResult remains unchanged
914 hkResult
= hkPreserve
;
915 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
916 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
917 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
918 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
919 RegCloseKey(hkResult
);
921 /* send in NULL hkResult */
922 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
923 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
925 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
926 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
928 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
929 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
931 /* beginning backslash character */
932 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
933 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
934 broken(ret
== ERROR_SUCCESS
), /* wow64 */
935 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
936 if (!ret
) RegCloseKey(hkResult
);
939 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
940 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
941 ret
== ERROR_BAD_PATHNAME
, /* NT */
942 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
943 RegCloseKey(hkResult
);
947 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
948 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
949 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
950 RegCloseKey(hkResult
);
953 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
954 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
955 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
956 RegCloseKey(hkResult
);
958 /* check special HKEYs on 64bit
959 * only the lower 4 bytes of the supplied key are used
963 /* HKEY_CURRENT_USER */
964 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
965 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
966 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
967 RegCloseKey(hkResult
);
969 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
970 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
971 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
972 RegCloseKey(hkResult
);
974 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
975 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
976 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
977 RegCloseKey(hkResult
);
979 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
980 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
981 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
982 RegCloseKey(hkResult
);
984 /* HKEY_LOCAL_MACHINE */
985 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
986 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
987 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
988 RegCloseKey(hkResult
);
991 /* Try using WOW64 flags when opening a key with a DACL set to verify that
992 * the registry access check is performed correctly. Redirection isn't
993 * being tested, so the tests don't care about whether the process is
994 * running under WOW64. */
995 if (!pIsWow64Process
)
997 win_skip("WOW64 flags are not recognized\n");
1001 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1002 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1003 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1004 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1006 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1007 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1008 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1009 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1011 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1012 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1014 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1016 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1017 access
.grfAccessMode
= SET_ACCESS
;
1018 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1019 access
.Trustee
.pMultipleTrustee
= NULL
;
1020 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1021 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1022 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1023 access
.Trustee
.ptstrName
= (char *)world_sid
;
1025 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1026 ok(ret
== ERROR_SUCCESS
,
1027 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1029 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1030 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1032 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1034 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1036 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1038 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1039 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1041 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1043 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1045 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1048 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1049 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1050 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1051 RegCloseKey(hkResult
);
1054 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1055 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1056 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1057 RegCloseKey(hkResult
);
1059 HeapFree(GetProcessHeap(), 0, sd
);
1062 RegDeleteKeyA(hkRoot64
, "");
1063 RegCloseKey(hkRoot64
);
1064 RegDeleteKeyA(hkRoot32
, "");
1065 RegCloseKey(hkRoot32
);
1068 static void test_reg_create_key(void)
1072 HKEY hkRoot64
= NULL
;
1073 HKEY hkRoot32
= NULL
;
1076 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1078 EXPLICIT_ACCESSA access
;
1080 SECURITY_DESCRIPTOR
*sd
;
1082 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1083 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1084 /* should succeed: all versions of Windows ignore the access rights
1085 * to the parent handle */
1086 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1087 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1090 RegDeleteKey(hkey2
, "");
1091 RegDeleteKey(hkey1
, "");
1095 /* test creation of volatile keys */
1096 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1097 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1098 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1099 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1100 if (!ret
) RegCloseKey( hkey2
);
1101 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1102 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1104 /* should succeed if the key already exists */
1105 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1106 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1109 RegDeleteKey(hkey2
, "");
1110 RegDeleteKey(hkey1
, "");
1114 /* beginning backslash character */
1115 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1116 if (!(GetVersion() & 0x80000000))
1117 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1119 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1120 RegDeleteKey(hkey1
, NULL
);
1124 /* WOW64 flags - open an existing key */
1126 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1127 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1128 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1132 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1133 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1134 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1137 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1138 * the registry access check is performed correctly. Redirection isn't
1139 * being tested, so the tests don't care about whether the process is
1140 * running under WOW64. */
1141 if (!pIsWow64Process
)
1143 win_skip("WOW64 flags are not recognized\n");
1147 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1148 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1149 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1150 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1152 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1153 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1154 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1155 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1157 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1158 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1160 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1162 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1163 access
.grfAccessMode
= SET_ACCESS
;
1164 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1165 access
.Trustee
.pMultipleTrustee
= NULL
;
1166 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1167 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1168 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1169 access
.Trustee
.ptstrName
= (char *)world_sid
;
1171 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1172 ok(ret
== ERROR_SUCCESS
,
1173 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1175 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1176 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1178 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1180 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1182 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1184 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1185 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1187 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1189 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1191 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1194 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1195 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1196 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1197 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1201 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1202 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1203 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1204 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1207 HeapFree(GetProcessHeap(), 0, sd
);
1210 RegDeleteKeyA(hkRoot64
, "");
1211 RegCloseKey(hkRoot64
);
1212 RegDeleteKeyA(hkRoot32
, "");
1213 RegCloseKey(hkRoot32
);
1216 static void test_reg_close_key(void)
1221 /* successfully close key
1222 * hkHandle remains changed after call to RegCloseKey
1224 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1225 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1226 ret
= RegCloseKey(hkHandle
);
1227 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1229 /* try to close the key twice */
1230 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1231 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1232 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1234 /* try to close a NULL handle */
1235 ret
= RegCloseKey(NULL
);
1236 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1237 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1239 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1240 * win98 doesn't give a new handle when the same key is opened.
1241 * Not re-opening will make some next tests fail.
1243 if (hkey_main
== hkHandle
)
1245 trace("The main handle is most likely closed, so re-opening\n");
1246 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1250 static void test_reg_delete_key(void)
1254 ret
= RegDeleteKey(hkey_main
, NULL
);
1256 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1257 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1258 * Not re-creating will make some next tests fail.
1260 if (ret
== ERROR_SUCCESS
)
1262 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1263 " re-creating the main key\n");
1267 ok(ret
== ERROR_INVALID_PARAMETER
||
1268 ret
== ERROR_ACCESS_DENIED
||
1269 ret
== ERROR_BADKEY
, /* Win95 */
1273 static void test_reg_save_key(void)
1277 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1278 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1281 static void test_reg_load_key(void)
1286 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1287 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1289 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1290 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1292 RegCloseKey(hkHandle
);
1295 static void test_reg_unload_key(void)
1299 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1300 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1302 DeleteFile("saved_key");
1303 DeleteFile("saved_key.LOG");
1306 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1308 TOKEN_PRIVILEGES tp
;
1312 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1315 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1317 CloseHandle(hToken
);
1321 tp
.PrivilegeCount
= 1;
1322 tp
.Privileges
[0].Luid
= luid
;
1325 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1327 tp
.Privileges
[0].Attributes
= 0;
1329 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1330 if (GetLastError() != ERROR_SUCCESS
)
1332 CloseHandle(hToken
);
1336 CloseHandle(hToken
);
1340 /* tests that show that RegConnectRegistry and
1341 OpenSCManager accept computer names without the
1342 \\ prefix (what MSDN says). */
1343 static void test_regconnectregistry( void)
1345 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1346 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1347 DWORD len
= sizeof(compName
) ;
1353 SetLastError(0xdeadbeef);
1354 ret
= GetComputerNameA(compName
, &len
);
1355 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1358 lstrcpyA(netwName
, "\\\\");
1359 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1361 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1363 retl
== ERROR_DLL_INIT_FAILED
||
1364 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1365 "RegConnectRegistryA failed err = %d\n", retl
);
1366 if( !retl
) RegCloseKey( hkey
);
1368 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1370 retl
== ERROR_DLL_INIT_FAILED
||
1371 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1372 "RegConnectRegistryA failed err = %d\n", retl
);
1373 if( !retl
) RegCloseKey( hkey
);
1375 SetLastError(0xdeadbeef);
1376 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1377 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1379 win_skip("OpenSCManagerA is not implemented\n");
1383 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1384 CloseServiceHandle( schnd
);
1386 SetLastError(0xdeadbeef);
1387 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1388 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1389 CloseServiceHandle( schnd
);
1393 static void test_reg_query_value(void)
1400 static const WCHAR expected
[] = {'d','a','t','a',0};
1402 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1403 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1405 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1406 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1408 /* try an invalid hkey */
1409 SetLastError(0xdeadbeef);
1411 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1412 ok(ret
== ERROR_INVALID_HANDLE
||
1413 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1414 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1415 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1416 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1418 /* try a NULL hkey */
1419 SetLastError(0xdeadbeef);
1421 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1422 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1423 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1424 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1426 /* try a NULL value */
1428 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1429 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1430 ok(size
== 5, "Expected 5, got %d\n", size
);
1432 /* try a NULL size */
1433 SetLastError(0xdeadbeef);
1435 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1436 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1437 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1438 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1440 /* try a NULL value and size */
1441 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1442 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1444 /* try a size too small */
1445 SetLastError(0xdeadbeef);
1448 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1449 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1450 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1451 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1452 ok(size
== 5, "Expected 5, got %d\n", size
);
1454 /* successfully read the value using 'subkey' */
1456 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1457 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1458 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1459 ok(size
== 5, "Expected 5, got %d\n", size
);
1461 /* successfully read the value using the subkey key */
1463 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1464 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1465 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1466 ok(size
== 5, "Expected 5, got %d\n", size
);
1468 /* unicode - try size too small */
1469 SetLastError(0xdeadbeef);
1472 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1473 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1475 win_skip("RegQueryValueW is not implemented\n");
1478 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1479 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1480 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1481 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1483 /* unicode - try size in WCHARS */
1484 SetLastError(0xdeadbeef);
1485 size
= sizeof(valW
) / sizeof(WCHAR
);
1486 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1487 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1488 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1489 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1490 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1492 /* unicode - successfully read the value */
1493 size
= sizeof(valW
);
1494 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1495 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1496 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1497 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1499 /* unicode - set the value without a NULL terminator */
1500 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1501 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1503 /* unicode - read the unterminated value, value is terminated for us */
1504 memset(valW
, 'a', sizeof(valW
));
1505 size
= sizeof(valW
);
1506 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1507 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1508 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1509 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1512 RegDeleteKeyA(subkey
, "");
1513 RegCloseKey(subkey
);
1516 static void test_string_termination(void)
1520 static const char string
[] = "FullString";
1523 DWORD insize
, outsize
, nsize
;
1525 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1526 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1528 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1529 insize
=sizeof(string
)-1;
1530 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1531 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1533 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1534 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1536 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1537 insize
=sizeof(string
)-2;
1538 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1539 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1541 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1542 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1543 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1545 /* RegQueryValueExA may return a string with no trailing '\0' */
1547 memset(buffer
, 0xbd, sizeof(buffer
));
1548 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1549 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1550 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1551 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1552 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1553 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1555 /* RegQueryValueExA adds a trailing '\0' if there is room */
1557 memset(buffer
, 0xbd, sizeof(buffer
));
1558 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1559 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1560 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1561 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1562 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1563 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1565 /* RegEnumValueA may return a string with no trailing '\0' */
1567 memset(buffer
, 0xbd, sizeof(buffer
));
1569 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1570 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1571 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1572 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1573 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1574 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1575 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1577 /* RegEnumValueA adds a trailing '\0' if there is room */
1579 memset(buffer
, 0xbd, sizeof(buffer
));
1581 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1582 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1583 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1584 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1585 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1586 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1587 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1589 RegDeleteKeyA(subkey
, "");
1590 RegCloseKey(subkey
);
1593 static void test_reg_delete_tree(void)
1595 CHAR buffer
[MAX_PATH
];
1596 HKEY subkey
, subkey2
;
1599 if(!pRegDeleteTreeA
) {
1600 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1604 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1605 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1606 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1607 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1608 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1609 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1610 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1611 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1612 ret
= RegCloseKey(subkey2
);
1613 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1615 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1616 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1617 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1618 "subkey2 was not deleted\n");
1620 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1621 "Default value of subkey not longer present\n");
1623 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1624 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1625 ret
= RegCloseKey(subkey2
);
1626 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1627 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1628 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1629 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1630 "subkey2 was not deleted\n");
1631 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1632 "Default value of subkey not longer present\n");
1634 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1635 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1636 ret
= RegCloseKey(subkey2
);
1637 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1638 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1639 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1640 ret
= RegCloseKey(subkey2
);
1641 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1642 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1643 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1644 ret
= pRegDeleteTreeA(subkey
, NULL
);
1645 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1646 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1647 "subkey was deleted\n");
1648 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1649 "subkey2 was not deleted\n");
1650 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1651 "subkey3 was not deleted\n");
1653 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1654 ok(ret
== ERROR_SUCCESS
,
1655 "Default value of subkey is not present\n");
1656 ok(!lstrlenA(buffer
),
1657 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1659 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1660 "Value is still present\n");
1662 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1663 ok(ret
== ERROR_FILE_NOT_FOUND
,
1664 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1667 static void test_rw_order(void)
1671 static char keyname
[] = "test_rw_order";
1673 DWORD values
, value_len
, value_name_max_len
;
1676 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1677 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1678 if(ret
!= ERROR_SUCCESS
) {
1679 skip("Couldn't create key. Skipping.\n");
1683 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1684 "RegSetValueExA for value \"A\" failed\n");
1685 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1686 "RegSetValueExA for value \"C\" failed\n");
1687 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1688 "RegSetValueExA for value \"D\" failed\n");
1689 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1690 "RegSetValueExA for value \"B\" failed\n");
1692 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1693 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1694 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1696 /* Value enumeration preserves RegSetValueEx call order */
1698 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1699 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1701 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1702 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1704 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1705 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1707 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1708 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1710 ok(!RegDeleteKey(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1713 static void test_symlinks(void)
1715 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1716 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1718 UNICODE_STRING target_str
;
1722 DWORD target_len
, type
, len
, dw
, err
;
1724 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1726 win_skip( "Can't perform symlink tests\n" );
1730 pRtlFormatCurrentUserKeyPath( &target_str
);
1732 target_len
= target_str
.Length
+ sizeof(targetW
);
1733 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1734 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1735 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1737 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1738 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1739 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1741 /* REG_SZ is not allowed */
1742 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1743 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1744 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1745 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1746 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1747 /* other values are not allowed */
1748 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1749 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1751 /* try opening the target through the link */
1753 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1754 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1756 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1757 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1760 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1761 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1764 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1765 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1767 len
= sizeof(buffer
);
1768 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1769 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1770 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1772 len
= sizeof(buffer
);
1773 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1774 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1776 /* REG_LINK can be created in non-link keys */
1777 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1778 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1779 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1780 len
= sizeof(buffer
);
1781 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1782 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1783 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1784 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1785 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1789 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1790 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1792 len
= sizeof(buffer
);
1793 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1794 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1795 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1797 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1798 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1801 /* now open the symlink itself */
1803 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1804 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1805 len
= sizeof(buffer
);
1806 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1807 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1808 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1811 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1812 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1813 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1814 len
= sizeof(buffer
);
1815 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1816 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1817 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1820 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1821 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1822 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1824 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1825 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1826 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1828 err
= RegDeleteKey( hkey_main
, "target" );
1829 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1831 err
= RegDeleteKey( hkey_main
, "link" );
1832 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1834 status
= pNtDeleteKey( link
);
1835 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1836 RegCloseKey( link
);
1838 HeapFree( GetProcessHeap(), 0, target
);
1839 pRtlFreeUnicodeString( &target_str
);
1842 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1845 DWORD err
, type
, dw
, len
= sizeof(dw
);
1847 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1848 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1849 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1851 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1852 if (err
== ERROR_FILE_NOT_FOUND
)
1855 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1860 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1862 DWORD dw
= get_key_value( root
, name
, flags
);
1863 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1865 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1867 static void test_redirection(void)
1869 DWORD err
, type
, dw
, len
;
1870 HKEY key
, root32
, root64
, key32
, key64
;
1871 BOOL is_vista
= FALSE
;
1876 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
1878 skip( "Not on Wow64, no redirection\n" );
1883 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1884 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
1885 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1887 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1888 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
1889 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1891 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1892 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
1893 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1895 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1896 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
1897 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1900 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1901 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1904 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1905 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1909 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1910 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1911 ok( dw
== 32, "wrong value %u\n", dw
);
1915 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1916 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1917 ok( dw
== 64, "wrong value %u\n", dw
);
1919 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1920 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1921 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1925 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1926 /* the new (and simpler) Win7 mechanism doesn't */
1927 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1929 trace( "using Vista-style Wow6432Node handling\n" );
1932 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1933 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1934 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1935 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1936 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1937 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1941 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
1943 trace( "using Vista-style Wow6432Node handling\n" );
1946 check_key_value( key
, "Wine\\Winetest", 0, 64 );
1947 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1953 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1954 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1955 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1956 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1957 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1958 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1959 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1960 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1961 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
1962 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
1963 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1966 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1967 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1968 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1969 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1970 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1971 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1972 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1973 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1974 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1978 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
1979 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1982 /* KEY_WOW64 flags have no effect on 64-bit */
1983 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1984 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1985 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1986 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1990 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1991 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1992 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1993 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1996 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1997 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1998 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1999 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2000 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2001 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2006 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2007 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2008 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2009 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2010 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2011 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2012 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2015 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2016 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2017 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2018 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2019 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2020 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2024 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2025 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2026 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2027 check_key_value( key
, "Winetest", 0, 32 );
2028 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2029 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2034 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2035 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2036 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2037 dw
= get_key_value( key
, "Winetest", 0 );
2038 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2039 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2040 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2043 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2044 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2045 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2046 check_key_value( key
, "Winetest", 0, 32 );
2047 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2048 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2052 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2053 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2054 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2055 check_key_value( key
, "Winetest", 0, ptr_size
);
2056 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2057 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2058 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2059 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2064 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2065 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2066 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2067 dw
= get_key_value( key
, "Winetest", 0 );
2068 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2069 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2070 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2071 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2074 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2075 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2076 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2077 check_key_value( key
, "Winetest", 0, 32 );
2078 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2079 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2083 if (pRegDeleteKeyExA
)
2085 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2086 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2087 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2088 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2089 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2090 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2094 err
= RegDeleteKeyA( key32
, "" );
2095 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2096 err
= RegDeleteKeyA( key64
, "" );
2097 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2098 RegDeleteKeyA( key64
, "" );
2099 RegDeleteKeyA( root64
, "" );
2101 RegCloseKey( key32
);
2102 RegCloseKey( key64
);
2103 RegCloseKey( root32
);
2104 RegCloseKey( root64
);
2107 static void test_classesroot(void)
2109 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2111 DWORD type
= REG_SZ
;
2112 static CHAR buffer
[8];
2115 /* create a key in the user's classes */
2116 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2119 RegCloseKey( hkey
);
2121 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2122 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2123 if (res
== ERROR_ACCESS_DENIED
)
2125 skip("not enough privileges to add a user class\n");
2128 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2130 /* try to open that key in hkcr */
2131 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2132 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2133 todo_wine
ok(res
== ERROR_SUCCESS
||
2134 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2135 "test key not found in hkcr: %d\n", res
);
2136 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2139 skip("HKCR key merging not supported\n");
2141 RegCloseKey( hkey
);
2145 /* set a value in user's classes */
2146 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2147 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2149 /* try to find the value in hkcr */
2150 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2151 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2152 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2154 /* modify the value in hkcr */
2155 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2156 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2158 /* check if the value is also modified in user's classes */
2159 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2160 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2161 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2163 /* set a value in hkcr */
2164 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2165 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2167 /* try to find the value in user's classes */
2168 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2169 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2170 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2172 /* modify the value in user's classes */
2173 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2174 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2176 /* check if the value is also modified in hkcr */
2177 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2178 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2179 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2184 RegCloseKey( hkey
);
2185 RegCloseKey( hkcr
);
2187 /* create a key in the hklm classes */
2188 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2191 RegCloseKey( hklm
);
2193 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2194 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2195 if (res
== ERROR_ACCESS_DENIED
)
2197 skip("not enough privileges to add a system class\n");
2200 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2202 /* try to open that key in hkcr */
2203 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2204 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2205 ok(res
== ERROR_SUCCESS
,
2206 "test key not found in hkcr: %d\n", res
);
2207 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2211 RegCloseKey( hklm
);
2215 /* set a value in hklm classes */
2216 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2217 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2219 /* try to find the value in hkcr */
2220 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2221 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2222 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2224 /* modify the value in hkcr */
2225 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2226 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2228 /* check that the value is modified in hklm classes */
2229 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2230 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2231 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2233 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2234 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2235 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2237 /* try to open that key in hkcr */
2238 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2239 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2240 ok(res
== ERROR_SUCCESS
,
2241 "test key not found in hkcr: %d\n", res
);
2242 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2244 /* set a value in user's classes */
2245 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2246 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2248 /* try to find the value in hkcr */
2249 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2250 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2251 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2253 /* modify the value in hklm */
2254 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2255 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2257 /* check that the value is not overwritten in hkcr or user's classes */
2258 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2259 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2260 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2261 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2262 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2263 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2265 /* modify the value in hkcr */
2266 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2267 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2269 /* check that the value is overwritten in hklm and user's classes */
2270 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2271 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2272 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2273 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2274 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2275 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2277 /* create a subkey in hklm */
2278 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2279 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2280 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2281 /* try to open that subkey in hkcr */
2282 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2283 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2284 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2286 /* set a value in hklm classes */
2287 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2288 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2290 /* try to find the value in hkcr */
2291 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2292 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2293 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2295 /* modify the value in hkcr */
2296 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2297 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2299 /* check that the value is modified in hklm classes */
2300 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2301 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2302 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2304 /* create a subkey in user's classes */
2305 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2306 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2307 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2309 /* set a value in user's classes */
2310 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2311 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2313 /* try to find the value in hkcr */
2314 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2315 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2316 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2318 /* modify the value in hklm */
2319 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2320 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2322 /* check that the value is not overwritten in hkcr or user's classes */
2323 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2324 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2325 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2326 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2327 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2328 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2330 /* modify the value in hkcr */
2331 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2332 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2334 /* check that the value is not overwritten in hklm, but in user's classes */
2335 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2336 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2337 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2338 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2339 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2340 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2342 /* new subkey in hkcr */
2343 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2344 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2345 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2346 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2347 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2349 /* try to open that new subkey in user's classes and hklm */
2350 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2351 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2353 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2354 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2355 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2357 /* check that the value is present in hklm */
2358 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2359 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2360 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2363 RegCloseKey( hkeysub1
);
2364 RegCloseKey( hklmsub1
);
2366 /* delete subkey1 from hkcr (should point at user's classes) */
2367 res
= RegDeleteKey(hkcr
, "subkey1");
2368 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2370 /* confirm key was removed in hkey but not hklm */
2371 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2372 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2373 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2374 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2375 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2377 /* delete subkey1 from hkcr again (which should now point at hklm) */
2378 res
= RegDeleteKey(hkcr
, "subkey1");
2379 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2381 /* confirm hkey was removed in hklm */
2382 RegCloseKey( hklmsub1
);
2383 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2384 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2390 delete_key( hkeysub1
);
2391 delete_key( hklmsub1
);
2392 delete_key( hkcrsub1
);
2393 delete_key( hklmsub2
);
2394 delete_key( hkcrsub2
);
2395 RegCloseKey( hkey
);
2396 RegCloseKey( hklm
);
2397 RegCloseKey( hkcr
);
2398 RegCloseKey( hkeysub1
);
2399 RegCloseKey( hklmsub1
);
2400 RegCloseKey( hkcrsub1
);
2401 RegCloseKey( hklmsub2
);
2402 RegCloseKey( hkcrsub2
);
2405 static void test_classesroot_enum(void)
2407 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2409 static CHAR buffer
[2];
2412 /* prepare initial testing env in HKCU */
2413 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2416 RegCloseKey( hkcu
);
2418 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2419 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2421 if (res
!= ERROR_SUCCESS
)
2423 skip("failed to add a user class\n");
2427 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2428 todo_wine
ok(res
== ERROR_SUCCESS
||
2429 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2430 "test key not found in hkcr: %d\n", res
);
2433 skip("HKCR key merging not supported\n");
2435 RegCloseKey( hkcu
);
2439 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2440 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2441 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2442 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2443 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2444 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2445 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2446 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2448 /* test on values in HKCU */
2449 size
= sizeof(buffer
);
2450 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2451 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2452 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2453 size
= sizeof(buffer
);
2454 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2455 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2456 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2457 size
= sizeof(buffer
);
2458 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2459 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2461 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2462 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2463 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2464 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2465 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2466 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2467 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2468 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2470 /* prepare test env in HKLM */
2471 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2474 RegCloseKey( hklm
);
2477 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2478 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2480 if (res
== ERROR_ACCESS_DENIED
)
2482 RegCloseKey( hkcusub
[0] );
2483 RegCloseKey( hkcusub
[1] );
2485 RegCloseKey( hkcu
);
2486 RegCloseKey( hkcr
);
2487 skip("not enough privileges to add a system class\n");
2491 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2492 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2493 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2494 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2495 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2496 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2497 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2498 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2500 /* test on values/keys in both HKCU and HKLM */
2501 size
= sizeof(buffer
);
2502 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2503 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2504 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2505 size
= sizeof(buffer
);
2506 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2507 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2508 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2509 size
= sizeof(buffer
);
2510 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2511 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2512 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2513 size
= sizeof(buffer
);
2514 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2515 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2517 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2518 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2519 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2520 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2521 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2522 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2523 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2524 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2525 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2526 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2527 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2529 /* delete values/keys from HKCU to test only on HKLM */
2530 RegCloseKey( hkcusub
[0] );
2531 RegCloseKey( hkcusub
[1] );
2533 RegCloseKey( hkcu
);
2535 size
= sizeof(buffer
);
2536 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2537 ok(res
== ERROR_KEY_DELETED
||
2538 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2539 "expected ERROR_KEY_DELETED, got %d\n", res
);
2540 size
= sizeof(buffer
);
2541 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2542 ok(res
== ERROR_KEY_DELETED
||
2543 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2544 "expected ERROR_KEY_DELETED, got %d\n", res
);
2546 /* reopen HKCR handle */
2547 RegCloseKey( hkcr
);
2548 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2549 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2550 if (res
) goto cleanup
;
2552 /* test on values/keys in HKLM */
2553 size
= sizeof(buffer
);
2554 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2555 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2556 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2557 size
= sizeof(buffer
);
2558 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2559 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2560 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2561 size
= sizeof(buffer
);
2562 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2563 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2565 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2566 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2567 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2568 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2569 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2570 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2571 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2572 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2575 RegCloseKey( hklmsub
[0] );
2576 RegCloseKey( hklmsub
[1] );
2578 RegCloseKey( hklm
);
2579 RegCloseKey( hkcr
);
2582 static void test_classesroot_mask(void)
2587 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
2588 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2589 todo_wine
ok(IS_HKCR(hkey
), "hkcr mask not set in %p\n", hkey
);
2590 RegCloseKey( hkey
);
2592 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
2593 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2594 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2595 RegCloseKey( hkey
);
2597 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
2598 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2599 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2600 RegCloseKey( hkey
);
2602 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
2603 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2604 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2605 RegCloseKey( hkey
);
2607 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
2608 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2609 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2610 RegCloseKey( hkey
);
2613 static void test_deleted_key(void)
2617 DWORD val_count
, type
;
2620 /* Open the test key, then delete it while it's open */
2621 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2623 delete_key( hkey_main
);
2625 val_count
= sizeof(value
);
2627 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2628 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2630 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2631 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2633 val_count
= sizeof(value
);
2635 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2636 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2638 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2639 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2641 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2642 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2644 RegCloseKey( hkey2
);
2646 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2647 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2649 RegCloseKey( hkey2
);
2651 res
= RegFlushKey( hkey
);
2652 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2654 RegCloseKey( hkey
);
2659 static void test_delete_value(void)
2664 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2665 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2667 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2668 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2670 res
= RegDeleteValueA( hkey_main
, "test" );
2671 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2673 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2674 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2676 res
= RegDeleteValueA( hkey_main
, "test" );
2677 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2679 memset(longname
, 'a', 400);
2681 res
= RegDeleteValueA( hkey_main
, longname
);
2682 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2683 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2686 START_TEST(registry
)
2688 /* Load pointers for functions that are not available in all Windows versions */
2693 create_test_entries();
2695 test_query_value_ex();
2697 test_reg_open_key();
2698 test_reg_create_key();
2699 test_reg_close_key();
2700 test_reg_delete_key();
2701 test_reg_query_value();
2702 test_string_termination();
2706 test_classesroot_enum();
2707 test_classesroot_mask();
2709 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2710 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2711 set_privileges(SE_RESTORE_NAME
, TRUE
))
2713 test_reg_save_key();
2714 test_reg_load_key();
2715 test_reg_unload_key();
2717 set_privileges(SE_BACKUP_NAME
, FALSE
);
2718 set_privileges(SE_RESTORE_NAME
, FALSE
);
2721 test_reg_delete_tree();
2724 test_delete_value();
2727 delete_key( hkey_main
);
2729 test_regconnectregistry();