2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
34 static HKEY hkey_main
;
37 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
38 static const char * sTestpath2
= "%FOO%\\subdir1";
39 static const DWORD ptr_size
= 8 * sizeof(void*);
41 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
42 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
43 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
44 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
45 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
46 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
47 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
50 /* Debugging functions from wine/libs/wine/debug.c */
52 /* allocate some tmp string space */
53 /* FIXME: this is not 100% thread-safe */
54 static char *get_temp_buffer( int size
)
56 static char *list
[32];
61 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
63 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
65 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
66 if (ret
) list
[idx
] = ret
;
70 static const char *wine_debugstr_an( const char *str
, int n
)
72 static const char hex
[16] = "0123456789abcdef";
76 if (!((ULONG_PTR
)str
>> 16))
78 if (!str
) return "(null)";
79 res
= get_temp_buffer( 6 );
80 sprintf( res
, "#%04x", LOWORD(str
) );
83 if (n
== -1) n
= strlen(str
);
85 size
= 10 + min( 300, n
* 4 );
86 dst
= res
= get_temp_buffer( size
);
88 while (n
-- > 0 && dst
<= res
+ size
- 9)
90 unsigned char c
= *str
++;
93 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
94 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
95 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
96 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
97 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
99 if (c
>= ' ' && c
<= 126)
105 *dst
++ = hex
[(c
>> 4) & 0x0f];
106 *dst
++ = hex
[c
& 0x0f];
121 #define ADVAPI32_GET_PROC(func) \
122 p ## func = (void*)GetProcAddress(hadvapi32, #func)
124 static void InitFunctionPtrs(void)
126 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
127 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
128 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
130 /* This function was introduced with Windows 2003 SP1 */
131 ADVAPI32_GET_PROC(RegGetValueA
);
132 ADVAPI32_GET_PROC(RegDeleteTreeA
);
133 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
135 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
136 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
137 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
138 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
141 /* delete key and all its subkeys */
142 static DWORD
delete_key( HKEY hkey
)
147 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
150 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
152 ret
= delete_key( tmp
);
157 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
158 RegDeleteKeyA( hkey
, "" );
162 static void setup_main_key(void)
164 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
166 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
169 #define lok ok_(__FILE__, line)
170 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
171 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
174 DWORD ret
, type
, cbData
;
180 /* When successful RegQueryValueExA() leaves GLE as is,
181 * so we must reset it to detect unimplemented functions.
183 SetLastError(0xdeadbeef);
184 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
185 GLE
= GetLastError();
186 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
187 /* It is wrong for the Ansi version to not be implemented */
188 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
189 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
191 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
192 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
193 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
195 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
196 memset(value
, 0xbd, cbData
+1);
198 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
199 GLE
= GetLastError();
200 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
203 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
204 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
208 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
209 wine_debugstr_an((char*)value
, cbData
), cbData
,
210 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
211 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
213 HeapFree(GetProcessHeap(), 0, value
);
216 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
217 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
220 DWORD ret
, type
, cbData
;
225 /* When successful RegQueryValueExW() leaves GLE as is,
226 * so we must reset it to detect unimplemented functions.
228 SetLastError(0xdeadbeef);
229 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
230 GLE
= GetLastError();
231 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
232 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
234 win_skip("RegQueryValueExW() is not implemented\n");
238 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
239 lok(cbData
== full_byte_len
,
240 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
242 /* Give enough space to overflow by one WCHAR */
243 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
244 memset(value
, 0xbd, cbData
+2);
246 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
247 GLE
= GetLastError();
248 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
251 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
252 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
253 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
255 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
256 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
257 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
258 HeapFree(GetProcessHeap(), 0, value
);
261 static void test_set_value(void)
265 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
266 static const WCHAR name2W
[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
267 static const WCHAR emptyW
[] = {0};
268 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
269 static const WCHAR string2W
[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
270 static const WCHAR substring2W
[] = {'T','h','i','s',0};
272 static const char name1A
[] = "CleanSingleString";
273 static const char name2A
[] = "SomeIntraZeroedString";
274 static const char emptyA
[] = "";
275 static const char string1A
[] = "ThisNeverBreaks";
276 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
277 static const char substring2A
[] = "This";
281 /* Crashes on NT4, Windows 2000 and XP SP1 */
282 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
283 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
286 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
287 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
288 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
289 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
291 /* RegSetValueA ignores the size passed in */
292 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
293 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
294 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
295 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
297 /* stops at first null */
298 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
299 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
300 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
301 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
303 /* only REG_SZ is supported on NT*/
304 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
305 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
307 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
308 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
310 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
311 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
313 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
314 * Surprisingly enough we're supposed to get zero bytes out of it.
316 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
317 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
318 test_hkey_main_Value_A(name1A
, NULL
, 0);
319 test_hkey_main_Value_W(name1W
, NULL
, 0);
321 /* test RegSetValueExA with an empty string */
322 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
323 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
324 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
325 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
327 /* test RegSetValueExA with off-by-one size */
328 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
329 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
330 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
331 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
333 /* test RegSetValueExA with normal string */
334 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
335 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
336 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
337 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
339 /* test RegSetValueExA with intrazeroed string */
340 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
341 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
342 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
343 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
347 /* Crashes on NT4, Windows 2000 and XP SP1 */
348 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
349 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
351 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
352 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
355 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
356 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
357 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
358 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
360 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
361 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
362 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
363 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
365 /* RegSetValueW ignores the size passed in */
366 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
367 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
368 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
369 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
371 /* stops at first null */
372 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
373 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
374 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
375 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
377 /* only REG_SZ is supported */
378 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
379 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
380 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
381 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
382 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
383 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
385 /* test RegSetValueExW with off-by-one size */
386 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
387 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
388 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
389 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
391 /* test RegSetValueExW with normal string */
392 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
393 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
394 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
395 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
397 /* test RegSetValueExW with intrazeroed string */
398 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
399 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
400 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
401 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
403 /* test RegSetValueExW with data = 1 */
404 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
405 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
406 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
407 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
410 static void create_test_entries(void)
412 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
414 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
415 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
417 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
418 "RegSetValueExA failed\n");
419 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
420 "RegSetValueExA failed\n");
421 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
422 "RegSetValueExA failed\n");
423 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
424 "RegSetValueExA failed\n");
425 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
426 "RegSetValueExA failed\n");
427 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
428 "RegSetValueExA failed\n");
429 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
430 "RegSetValueExA failed\n");
433 static void test_enum_value(void)
437 char value
[20], data
[20];
438 WCHAR valueW
[20], dataW
[20];
439 DWORD val_count
, data_count
, type
;
440 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
441 static const WCHAR testW
[] = {'T','e','s','t',0};
442 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
444 /* create the working key for new 'Test' value */
445 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
446 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
448 /* check NULL data with zero length */
449 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
450 if (GetVersion() & 0x80000000)
451 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
453 ok( !res
, "RegSetValueExA returned %d\n", res
);
454 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
455 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
456 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
457 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
459 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
460 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
462 /* overflow both name and data */
466 strcpy( value
, "xxxxxxxxxx" );
467 strcpy( data
, "xxxxxxxxxx" );
468 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
469 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
470 ok( val_count
== 2, "val_count set to %d\n", val_count
);
471 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
472 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
473 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
474 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
480 strcpy( value
, "xxxxxxxxxx" );
481 strcpy( data
, "xxxxxxxxxx" );
482 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
483 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
484 ok( val_count
== 3, "val_count set to %d\n", val_count
);
485 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
486 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
487 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
488 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
489 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
490 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
491 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
493 /* overflow empty name */
497 strcpy( value
, "xxxxxxxxxx" );
498 strcpy( data
, "xxxxxxxxxx" );
499 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
500 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
501 ok( val_count
== 0, "val_count set to %d\n", val_count
);
502 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
503 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
504 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
505 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
506 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
507 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
513 strcpy( value
, "xxxxxxxxxx" );
514 strcpy( data
, "xxxxxxxxxx" );
515 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
516 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
517 ok( val_count
== 20, "val_count set to %d\n", val_count
);
518 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
519 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
520 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
521 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
527 strcpy( value
, "xxxxxxxxxx" );
528 strcpy( data
, "xxxxxxxxxx" );
529 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
530 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
531 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
532 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
533 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
534 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
535 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
539 SetLastError(0xdeadbeef);
540 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
541 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
543 win_skip("RegSetValueExW is not implemented\n");
546 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
548 /* overflow both name and data */
552 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
553 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
554 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
555 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
556 ok( val_count
== 2, "val_count set to %d\n", val_count
);
557 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
558 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
559 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
560 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
566 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
567 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
568 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
569 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
570 ok( val_count
== 3, "val_count set to %d\n", val_count
);
571 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
572 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
573 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
574 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
580 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
581 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
582 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
583 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
584 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
585 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
586 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
587 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
588 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
594 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
595 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
596 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
597 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
598 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
599 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
600 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
601 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
602 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
605 RegDeleteKeyA(test_key
, "");
606 RegCloseKey(test_key
);
609 static void test_query_value_ex(void)
616 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
617 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
618 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
619 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
623 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
624 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
625 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
627 size
= sizeof(buffer
);
628 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
629 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
630 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
633 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
634 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
637 static void test_get_value(void)
644 CHAR expanded
[] = "bar\\subdir1";
645 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
649 win_skip("RegGetValue not available on this platform\n");
653 /* Invalid parameter */
654 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
655 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
657 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
658 size
= type
= dw
= 0xdeadbeef;
659 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
660 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
661 ok(size
== 4, "size=%d\n", size
);
662 ok(type
== REG_DWORD
, "type=%d\n", type
);
663 ok(dw
== 0x12345678, "dw=%d\n", dw
);
665 /* Query by subkey-name */
666 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
667 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
669 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
670 size
= type
= dw
= 0xdeadbeef;
671 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
672 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
673 /* Although the function failed all values are retrieved */
674 ok(size
== 4, "size=%d\n", size
);
675 ok(type
== REG_DWORD
, "type=%d\n", type
);
676 ok(dw
== 0x12345678, "dw=%d\n", dw
);
678 /* Test RRF_ZEROONFAILURE */
679 type
= dw
= 0xdeadbeef; size
= 4;
680 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
681 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
682 /* Again all values are retrieved ... */
683 ok(size
== 4, "size=%d\n", size
);
684 ok(type
== REG_DWORD
, "type=%d\n", type
);
685 /* ... except the buffer, which is zeroed out */
686 ok(dw
== 0, "dw=%d\n", dw
);
688 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
689 type
= size
= 0xbadbeef;
690 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
691 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
692 ok(size
== 4, "size=%d\n", size
);
693 ok(type
== REG_DWORD
, "type=%d\n", type
);
695 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
696 size
= type
= dw
= 0xdeadbeef;
697 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
698 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
699 ok(size
== 4, "size=%d\n", size
);
700 ok(type
== REG_DWORD
, "type=%d\n", type
);
701 ok(dw
== 0x12345678, "dw=%d\n", dw
);
703 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
704 size
= type
= dw
= 0xdeadbeef;
705 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
706 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
707 ok(size
== 4, "size=%d\n", size
);
708 ok(type
== REG_BINARY
, "type=%d\n", type
);
709 ok(dw
== 0x12345678, "dw=%d\n", dw
);
711 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
712 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
713 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
714 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
715 ok(size
== 8, "size=%d\n", size
);
716 ok(type
== REG_BINARY
, "type=%d\n", type
);
717 ok(qw
[0] == 0x12345678 &&
718 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
720 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
721 type
= dw
= 0xdeadbeef; size
= 4;
722 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
723 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
724 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
725 ok(size
== 8, "size=%d\n", size
);
727 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
728 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
729 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
730 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
731 ok(size
== 8, "size=%d\n", size
);
732 ok(type
== REG_BINARY
, "type=%d\n", type
);
733 ok(qw
[0] == 0x12345678 &&
734 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
736 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
737 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
738 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
739 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
740 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
741 ok(type
== REG_SZ
, "type=%d\n", type
);
742 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
744 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
745 type
= 0xdeadbeef; size
= 0;
746 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
747 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
748 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
749 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
750 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
751 ok(type
== REG_SZ
, "type=%d\n", type
);
753 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
754 strcpy(buf
, sTestpath1
);
757 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
758 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
759 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
761 size
== 1, /* win2k3 */
763 ok(type
== REG_SZ
, "type=%d\n", type
);
764 ok(!strcmp(sTestpath1
, buf
) ||
766 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
768 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
769 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
770 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
771 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
772 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
773 ok(type
== REG_SZ
, "type=%d\n", type
);
774 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
776 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
778 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
779 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
780 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
781 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
782 (size
== strlen(sTestpath2
)+1),
783 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
785 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
786 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
787 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
788 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
789 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
790 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
791 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
792 ok(type
== REG_SZ
, "type=%d\n", type
);
793 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
795 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
796 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
797 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
798 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
799 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
800 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
801 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
802 ok(type
== REG_SZ
, "type=%d\n", type
);
803 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
805 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
806 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
807 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
808 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
809 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
810 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
811 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
813 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
815 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
816 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
817 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
818 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
819 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
821 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
822 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
823 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
825 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
826 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
827 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
828 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
830 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
831 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
832 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
833 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
834 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
835 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
836 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
837 ok(type
== REG_SZ
, "type=%d\n", type
);
838 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
841 static void test_reg_open_key(void)
844 HKEY hkResult
= NULL
;
845 HKEY hkPreserve
= NULL
;
846 HKEY hkRoot64
= NULL
;
847 HKEY hkRoot32
= NULL
;
849 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
851 EXPLICIT_ACCESSA access
;
853 SECURITY_DESCRIPTOR
*sd
;
855 /* successful open */
856 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
857 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
858 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
859 hkPreserve
= hkResult
;
861 /* open same key twice */
862 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
863 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
864 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
865 ok(hkResult
!= NULL
, "hkResult != NULL\n");
866 RegCloseKey(hkResult
);
868 /* open nonexistent key
869 * check that hkResult is set to NULL
871 hkResult
= hkPreserve
;
872 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
873 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
874 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
876 /* open the same nonexistent key again to make sure the key wasn't created */
877 hkResult
= hkPreserve
;
878 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
879 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
880 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
882 /* send in NULL lpSubKey
883 * check that hkResult receives the value of hKey
885 hkResult
= hkPreserve
;
886 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
887 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
888 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
890 /* send empty-string in lpSubKey */
891 hkResult
= hkPreserve
;
892 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
893 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
894 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
896 /* send in NULL lpSubKey and NULL hKey
897 * hkResult is set to NULL
899 hkResult
= hkPreserve
;
900 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
901 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
902 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
904 /* only send NULL hKey
905 * the value of hkResult remains unchanged
907 hkResult
= hkPreserve
;
908 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
909 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
910 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
911 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
912 RegCloseKey(hkResult
);
914 /* send in NULL hkResult */
915 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
916 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
918 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
919 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
921 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
922 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
924 /* beginning backslash character */
925 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
926 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
927 broken(ret
== ERROR_SUCCESS
), /* wow64 */
928 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
929 if (!ret
) RegCloseKey(hkResult
);
932 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
933 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
934 ret
== ERROR_BAD_PATHNAME
, /* NT */
935 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
936 RegCloseKey(hkResult
);
940 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
941 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
942 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
943 RegCloseKey(hkResult
);
946 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
947 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
948 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
949 RegCloseKey(hkResult
);
951 /* check special HKEYs on 64bit
952 * only the lower 4 bytes of the supplied key are used
956 /* HKEY_CURRENT_USER */
957 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
958 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
959 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
960 RegCloseKey(hkResult
);
962 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
963 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
964 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
965 RegCloseKey(hkResult
);
967 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
968 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
969 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
970 RegCloseKey(hkResult
);
972 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
973 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
974 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
975 RegCloseKey(hkResult
);
977 /* HKEY_LOCAL_MACHINE */
978 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
979 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
980 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
981 RegCloseKey(hkResult
);
984 /* Try using WOW64 flags when opening a key with a DACL set to verify that
985 * the registry access check is performed correctly. Redirection isn't
986 * being tested, so the tests don't care about whether the process is
987 * running under WOW64. */
988 if (!pIsWow64Process
)
990 win_skip("WOW64 flags are not recognized\n");
994 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
995 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
996 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
997 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
999 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1000 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1001 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1002 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1004 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1005 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1007 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1009 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1010 access
.grfAccessMode
= SET_ACCESS
;
1011 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1012 access
.Trustee
.pMultipleTrustee
= NULL
;
1013 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1014 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1015 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1016 access
.Trustee
.ptstrName
= (char *)world_sid
;
1018 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1019 ok(ret
== ERROR_SUCCESS
,
1020 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1022 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1023 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1025 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1027 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1029 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1031 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1032 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1034 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1036 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1038 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1041 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1042 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1043 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1044 RegCloseKey(hkResult
);
1047 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1048 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1049 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1050 RegCloseKey(hkResult
);
1052 HeapFree(GetProcessHeap(), 0, sd
);
1055 RegDeleteKeyA(hkRoot64
, "");
1056 RegCloseKey(hkRoot64
);
1057 RegDeleteKeyA(hkRoot32
, "");
1058 RegCloseKey(hkRoot32
);
1061 static void test_reg_create_key(void)
1065 HKEY hkRoot64
= NULL
;
1066 HKEY hkRoot32
= NULL
;
1069 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1071 EXPLICIT_ACCESSA access
;
1073 SECURITY_DESCRIPTOR
*sd
;
1075 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1076 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1077 /* should succeed: all versions of Windows ignore the access rights
1078 * to the parent handle */
1079 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1080 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1083 RegDeleteKey(hkey2
, "");
1084 RegDeleteKey(hkey1
, "");
1088 /* test creation of volatile keys */
1089 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1090 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1091 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1092 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1093 if (!ret
) RegCloseKey( hkey2
);
1094 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1095 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1097 /* should succeed if the key already exists */
1098 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1099 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1102 RegDeleteKey(hkey2
, "");
1103 RegDeleteKey(hkey1
, "");
1107 /* beginning backslash character */
1108 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1109 if (!(GetVersion() & 0x80000000))
1110 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1112 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1113 RegDeleteKey(hkey1
, NULL
);
1117 /* WOW64 flags - open an existing key */
1119 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1120 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1121 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1125 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1126 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1127 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1130 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1131 * the registry access check is performed correctly. Redirection isn't
1132 * being tested, so the tests don't care about whether the process is
1133 * running under WOW64. */
1134 if (!pIsWow64Process
)
1136 win_skip("WOW64 flags are not recognized\n");
1140 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1141 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1142 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1143 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1145 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1146 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1147 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1148 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1150 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1151 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1153 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1155 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1156 access
.grfAccessMode
= SET_ACCESS
;
1157 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1158 access
.Trustee
.pMultipleTrustee
= NULL
;
1159 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1160 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1161 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1162 access
.Trustee
.ptstrName
= (char *)world_sid
;
1164 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1165 ok(ret
== ERROR_SUCCESS
,
1166 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1168 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1169 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1171 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1173 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1175 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1177 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1178 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1180 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1182 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1184 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1187 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1188 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1189 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1190 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1194 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1195 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1196 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1197 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1200 HeapFree(GetProcessHeap(), 0, sd
);
1203 RegDeleteKeyA(hkRoot64
, "");
1204 RegCloseKey(hkRoot64
);
1205 RegDeleteKeyA(hkRoot32
, "");
1206 RegCloseKey(hkRoot32
);
1209 static void test_reg_close_key(void)
1214 /* successfully close key
1215 * hkHandle remains changed after call to RegCloseKey
1217 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1218 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1219 ret
= RegCloseKey(hkHandle
);
1220 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1222 /* try to close the key twice */
1223 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1224 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1225 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1227 /* try to close a NULL handle */
1228 ret
= RegCloseKey(NULL
);
1229 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1230 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1232 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1233 * win98 doesn't give a new handle when the same key is opened.
1234 * Not re-opening will make some next tests fail.
1236 if (hkey_main
== hkHandle
)
1238 trace("The main handle is most likely closed, so re-opening\n");
1239 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1243 static void test_reg_delete_key(void)
1247 ret
= RegDeleteKey(hkey_main
, NULL
);
1249 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1250 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1251 * Not re-creating will make some next tests fail.
1253 if (ret
== ERROR_SUCCESS
)
1255 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1256 " re-creating the main key\n");
1260 ok(ret
== ERROR_INVALID_PARAMETER
||
1261 ret
== ERROR_ACCESS_DENIED
||
1262 ret
== ERROR_BADKEY
, /* Win95 */
1266 static void test_reg_save_key(void)
1270 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1271 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1274 static void test_reg_load_key(void)
1279 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1280 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1282 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1283 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1285 RegCloseKey(hkHandle
);
1288 static void test_reg_unload_key(void)
1292 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1293 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1295 DeleteFile("saved_key");
1296 DeleteFile("saved_key.LOG");
1299 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1301 TOKEN_PRIVILEGES tp
;
1305 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1308 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1310 CloseHandle(hToken
);
1314 tp
.PrivilegeCount
= 1;
1315 tp
.Privileges
[0].Luid
= luid
;
1318 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1320 tp
.Privileges
[0].Attributes
= 0;
1322 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1323 if (GetLastError() != ERROR_SUCCESS
)
1325 CloseHandle(hToken
);
1329 CloseHandle(hToken
);
1333 /* tests that show that RegConnectRegistry and
1334 OpenSCManager accept computer names without the
1335 \\ prefix (what MSDN says). */
1336 static void test_regconnectregistry( void)
1338 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1339 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1340 DWORD len
= sizeof(compName
) ;
1346 SetLastError(0xdeadbeef);
1347 ret
= GetComputerNameA(compName
, &len
);
1348 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1351 lstrcpyA(netwName
, "\\\\");
1352 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1354 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1356 retl
== ERROR_DLL_INIT_FAILED
||
1357 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1358 "RegConnectRegistryA failed err = %d\n", retl
);
1359 if( !retl
) RegCloseKey( hkey
);
1361 retl
= RegConnectRegistryA( netwName
, 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 SetLastError(0xdeadbeef);
1369 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1370 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1372 win_skip("OpenSCManagerA is not implemented\n");
1376 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1377 CloseServiceHandle( schnd
);
1379 SetLastError(0xdeadbeef);
1380 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1381 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1382 CloseServiceHandle( schnd
);
1386 static void test_reg_query_value(void)
1393 static const WCHAR expected
[] = {'d','a','t','a',0};
1395 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1396 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1398 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1399 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1401 /* try an invalid hkey */
1402 SetLastError(0xdeadbeef);
1404 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1405 ok(ret
== ERROR_INVALID_HANDLE
||
1406 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1407 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1408 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1409 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1411 /* try a NULL hkey */
1412 SetLastError(0xdeadbeef);
1414 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1415 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1416 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1417 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1419 /* try a NULL value */
1421 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1422 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1423 ok(size
== 5, "Expected 5, got %d\n", size
);
1425 /* try a NULL size */
1426 SetLastError(0xdeadbeef);
1428 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1429 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1430 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1431 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1433 /* try a NULL value and size */
1434 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1435 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1437 /* try a size too small */
1438 SetLastError(0xdeadbeef);
1441 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1442 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1443 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1444 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1445 ok(size
== 5, "Expected 5, got %d\n", size
);
1447 /* successfully read the value using 'subkey' */
1449 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1450 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1451 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1452 ok(size
== 5, "Expected 5, got %d\n", size
);
1454 /* successfully read the value using the subkey key */
1456 ret
= RegQueryValueA(subkey
, NULL
, 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 /* unicode - try size too small */
1462 SetLastError(0xdeadbeef);
1465 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1466 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1468 win_skip("RegQueryValueW is not implemented\n");
1471 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1472 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1473 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1474 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1476 /* unicode - try size in WCHARS */
1477 SetLastError(0xdeadbeef);
1478 size
= sizeof(valW
) / sizeof(WCHAR
);
1479 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1480 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1481 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1482 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1483 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1485 /* unicode - successfully read the value */
1486 size
= sizeof(valW
);
1487 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1488 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1489 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1490 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1492 /* unicode - set the value without a NULL terminator */
1493 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1494 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1496 /* unicode - read the unterminated value, value is terminated for us */
1497 memset(valW
, 'a', sizeof(valW
));
1498 size
= sizeof(valW
);
1499 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1500 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1501 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1502 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1505 RegDeleteKeyA(subkey
, "");
1506 RegCloseKey(subkey
);
1509 static void test_string_termination(void)
1513 static const char string
[] = "FullString";
1516 DWORD insize
, outsize
, nsize
;
1518 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1519 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1521 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1522 insize
=sizeof(string
)-1;
1523 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1524 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1526 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1527 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1529 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1530 insize
=sizeof(string
)-2;
1531 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1532 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1534 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1535 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1536 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1538 /* RegQueryValueExA may return a string with no trailing '\0' */
1540 memset(buffer
, 0xbd, sizeof(buffer
));
1541 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1542 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1543 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1544 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1545 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1546 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1548 /* RegQueryValueExA adds a trailing '\0' if there is room */
1550 memset(buffer
, 0xbd, sizeof(buffer
));
1551 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1552 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1553 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1554 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1555 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1556 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1558 /* RegEnumValueA may return a string with no trailing '\0' */
1560 memset(buffer
, 0xbd, sizeof(buffer
));
1562 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1563 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1564 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1565 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1566 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1567 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1568 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1570 /* RegEnumValueA adds a trailing '\0' if there is room */
1572 memset(buffer
, 0xbd, sizeof(buffer
));
1574 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1575 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1576 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1577 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1578 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1579 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1580 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1582 RegDeleteKeyA(subkey
, "");
1583 RegCloseKey(subkey
);
1586 static void test_reg_delete_tree(void)
1588 CHAR buffer
[MAX_PATH
];
1589 HKEY subkey
, subkey2
;
1592 if(!pRegDeleteTreeA
) {
1593 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1597 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1598 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1599 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1600 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1601 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1602 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1603 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1604 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1605 ret
= RegCloseKey(subkey2
);
1606 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1608 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1609 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1610 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1611 "subkey2 was not deleted\n");
1613 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1614 "Default value of subkey not longer present\n");
1616 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1617 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1618 ret
= RegCloseKey(subkey2
);
1619 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1620 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1621 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1622 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1623 "subkey2 was not deleted\n");
1624 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1625 "Default value of subkey not longer present\n");
1627 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1628 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1629 ret
= RegCloseKey(subkey2
);
1630 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1631 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1632 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1633 ret
= RegCloseKey(subkey2
);
1634 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1635 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1636 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1637 ret
= pRegDeleteTreeA(subkey
, NULL
);
1638 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1639 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1640 "subkey was deleted\n");
1641 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1642 "subkey2 was not deleted\n");
1643 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1644 "subkey3 was not deleted\n");
1646 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1647 ok(ret
== ERROR_SUCCESS
,
1648 "Default value of subkey is not present\n");
1649 ok(!lstrlenA(buffer
),
1650 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1652 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1653 "Value is still present\n");
1655 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1656 ok(ret
== ERROR_FILE_NOT_FOUND
,
1657 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1660 static void test_rw_order(void)
1664 static char keyname
[] = "test_rw_order";
1666 DWORD values
, value_len
, value_name_max_len
;
1669 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1670 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1671 if(ret
!= ERROR_SUCCESS
) {
1672 skip("Couldn't create key. Skipping.\n");
1676 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1677 "RegSetValueExA for value \"A\" failed\n");
1678 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1679 "RegSetValueExA for value \"C\" failed\n");
1680 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1681 "RegSetValueExA for value \"D\" failed\n");
1682 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1683 "RegSetValueExA for value \"B\" failed\n");
1685 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1686 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1687 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1689 /* Value enumeration preserves RegSetValueEx call order */
1691 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1692 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1694 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1695 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1697 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1698 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1700 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1701 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1703 ok(!RegDeleteKey(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1706 static void test_symlinks(void)
1708 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1709 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1711 UNICODE_STRING target_str
;
1715 DWORD target_len
, type
, len
, dw
, err
;
1717 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1719 win_skip( "Can't perform symlink tests\n" );
1723 pRtlFormatCurrentUserKeyPath( &target_str
);
1725 target_len
= target_str
.Length
+ sizeof(targetW
);
1726 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1727 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1728 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1730 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1731 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1732 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1734 /* REG_SZ is not allowed */
1735 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1736 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1737 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1738 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1739 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1740 /* other values are not allowed */
1741 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1742 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1744 /* try opening the target through the link */
1746 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1747 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1749 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1750 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1753 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1754 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1757 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1758 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1760 len
= sizeof(buffer
);
1761 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1762 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1763 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1765 len
= sizeof(buffer
);
1766 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1767 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1769 /* REG_LINK can be created in non-link keys */
1770 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1771 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1772 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1773 len
= sizeof(buffer
);
1774 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1775 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1776 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1777 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1778 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1782 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1783 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1785 len
= sizeof(buffer
);
1786 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1787 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1788 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1790 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1791 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1794 /* now open the symlink itself */
1796 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1797 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1798 len
= sizeof(buffer
);
1799 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1800 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1801 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1804 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1805 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1806 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1807 len
= sizeof(buffer
);
1808 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1809 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1810 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1813 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1814 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1815 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1817 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1818 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1819 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1821 err
= RegDeleteKey( hkey_main
, "target" );
1822 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1824 err
= RegDeleteKey( hkey_main
, "link" );
1825 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1827 status
= pNtDeleteKey( link
);
1828 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1829 RegCloseKey( link
);
1831 HeapFree( GetProcessHeap(), 0, target
);
1832 pRtlFreeUnicodeString( &target_str
);
1835 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1838 DWORD err
, type
, dw
, len
= sizeof(dw
);
1840 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1841 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1842 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1844 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1845 if (err
== ERROR_FILE_NOT_FOUND
)
1848 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1853 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1855 DWORD dw
= get_key_value( root
, name
, flags
);
1856 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1858 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1860 static void test_redirection(void)
1862 DWORD err
, type
, dw
, len
;
1863 HKEY key
, root32
, root64
, key32
, key64
;
1864 BOOL is_vista
= FALSE
;
1869 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
1871 skip( "Not on Wow64, no redirection\n" );
1876 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1877 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
1878 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1880 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1881 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
1882 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1884 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1885 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
1886 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1888 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1889 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
1890 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1893 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1894 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1897 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1898 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1902 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1903 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1904 ok( dw
== 32, "wrong value %u\n", dw
);
1908 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1909 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1910 ok( dw
== 64, "wrong value %u\n", dw
);
1912 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1913 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1914 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1918 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1919 /* the new (and simpler) Win7 mechanism doesn't */
1920 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1922 trace( "using Vista-style Wow6432Node handling\n" );
1925 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1926 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1927 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1928 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1929 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1930 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1934 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
1936 trace( "using Vista-style Wow6432Node handling\n" );
1939 check_key_value( key
, "Wine\\Winetest", 0, 64 );
1940 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1946 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1947 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1948 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1949 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1950 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1951 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1952 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1953 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1954 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
1955 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
1956 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1959 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1960 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1961 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1962 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1963 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1964 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1965 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1966 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1967 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1971 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
1972 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1975 /* KEY_WOW64 flags have no effect on 64-bit */
1976 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1977 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1978 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1979 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
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 );
1989 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1990 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1991 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1992 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1993 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1994 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1999 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2000 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2001 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2002 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2003 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2004 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2005 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2008 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2009 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2010 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2011 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2012 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2013 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2017 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2018 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2019 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2020 check_key_value( key
, "Winetest", 0, 32 );
2021 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2022 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2027 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2028 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2029 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2030 dw
= get_key_value( key
, "Winetest", 0 );
2031 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2032 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2033 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2036 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2037 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2038 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2039 check_key_value( key
, "Winetest", 0, 32 );
2040 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2041 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2045 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2046 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2047 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2048 check_key_value( key
, "Winetest", 0, ptr_size
);
2049 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2050 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2051 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2052 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2057 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2058 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2059 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2060 dw
= get_key_value( key
, "Winetest", 0 );
2061 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2062 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2063 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2064 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2067 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2068 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2069 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2070 check_key_value( key
, "Winetest", 0, 32 );
2071 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2072 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2076 if (pRegDeleteKeyExA
)
2078 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2079 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2080 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2081 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2082 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2083 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2087 err
= RegDeleteKeyA( key32
, "" );
2088 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2089 err
= RegDeleteKeyA( key64
, "" );
2090 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2091 RegDeleteKeyA( key64
, "" );
2092 RegDeleteKeyA( root64
, "" );
2094 RegCloseKey( key32
);
2095 RegCloseKey( key64
);
2096 RegCloseKey( root32
);
2097 RegCloseKey( root64
);
2100 static void test_classesroot(void)
2102 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2104 DWORD type
= REG_SZ
;
2105 static CHAR buffer
[8];
2108 /* create a key in the user's classes */
2109 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2112 RegCloseKey( hkey
);
2114 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2115 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2116 if (res
== ERROR_ACCESS_DENIED
)
2118 skip("not enough privileges to add a user class\n");
2122 /* try to open that key in hkcr */
2123 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2124 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2125 todo_wine
ok(res
== ERROR_SUCCESS
||
2126 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2127 "test key not found in hkcr: %d\n", res
);
2130 skip("HKCR key merging not supported\n");
2132 RegCloseKey( hkey
);
2136 /* set a value in user's classes */
2137 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2138 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2140 /* try to find the value in hkcr */
2141 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2142 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2143 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2145 /* modify the value in hkcr */
2146 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2147 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2149 /* check if the value is also modified in user's classes */
2150 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2151 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2152 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2154 /* set a value in hkcr */
2155 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2156 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2158 /* try to find the value in user's classes */
2159 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2160 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2161 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2163 /* modify the value in user's classes */
2164 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2165 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2167 /* check if the value is also modified in hkcr */
2168 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2169 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2170 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2175 RegCloseKey( hkey
);
2176 RegCloseKey( hkcr
);
2178 /* create a key in the hklm classes */
2179 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2182 RegCloseKey( hklm
);
2184 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2185 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2186 if (res
== ERROR_ACCESS_DENIED
)
2188 skip("not enough privileges to add a system class\n");
2192 /* try to open that key in hkcr */
2193 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2194 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2195 ok(res
== ERROR_SUCCESS
,
2196 "test key not found in hkcr: %d\n", res
);
2200 RegCloseKey( hklm
);
2204 /* set a value in hklm classes */
2205 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2206 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2208 /* try to find the value in hkcr */
2209 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2210 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2211 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2213 /* modify the value in hkcr */
2214 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2215 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2217 /* check that the value is not modified in hklm classes */
2218 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2219 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2220 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2222 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2223 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2225 /* try to open that key in hkcr */
2226 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2227 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2228 ok(res
== ERROR_SUCCESS
,
2229 "test key not found in hkcr: %d\n", res
);
2231 /* set a value in user's classes */
2232 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2233 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2235 /* try to find the value in hkcr */
2236 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2237 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2238 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2240 /* modify the value in hklm */
2241 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2242 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2244 /* check that the value is not overwritten in hkcr or user's classes */
2245 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2246 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2247 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2248 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2249 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2250 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2252 /* modify the value in hkcr */
2253 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2254 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2256 /* check that the value is overwritten in hklm and user's classes */
2257 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2258 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2259 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2260 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2261 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2262 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2264 /* create a subkey in hklm */
2265 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2266 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2267 /* try to open that subkey in hkcr */
2268 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2269 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2271 /* set a value in hklm classes */
2272 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2273 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2275 /* try to find the value in hkcr */
2276 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2277 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2278 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2280 /* modify the value in hkcr */
2281 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2282 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2284 /* check that the value is modified in hklm classes */
2285 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2286 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2287 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2289 /* create a subkey in user's classes */
2290 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2291 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2293 /* set a value in user's classes */
2294 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2295 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2297 /* try to find the value in hkcr */
2298 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2299 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2300 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2302 /* modify the value in hklm */
2303 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2304 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2306 /* check that the value is not overwritten in hkcr or user's classes */
2307 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2308 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2309 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2310 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2311 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2312 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2314 /* modify the value in hkcr */
2315 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2316 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2318 /* check that the value is not overwritten in hklm, but in user's classes */
2319 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2320 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2321 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2322 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2323 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2324 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2326 /* new subkey in hkcr */
2327 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2328 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2329 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2330 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2332 /* try to open that new subkey in user's classes and hklm */
2333 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2334 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2336 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2337 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2339 /* check that the value is present in hklm */
2340 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2341 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2342 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2345 RegCloseKey( hkeysub1
);
2346 RegCloseKey( hklmsub1
);
2348 /* delete subkey1 from hkcr (should point at user's classes) */
2349 res
= RegDeleteKey(hkcr
, "subkey1");
2350 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2352 /* confirm key was removed in hkey but not hklm */
2353 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2354 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2355 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2356 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2358 /* delete subkey1 from hkcr again (which should now point at hklm) */
2359 res
= RegDeleteKey(hkcr
, "subkey1");
2360 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2362 /* confirm hkey was removed in hklm */
2363 RegCloseKey( hklmsub1
);
2364 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2365 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2371 delete_key( hkeysub1
);
2372 delete_key( hklmsub1
);
2373 delete_key( hkcrsub1
);
2374 delete_key( hklmsub2
);
2375 delete_key( hkcrsub2
);
2376 RegCloseKey( hkey
);
2377 RegCloseKey( hklm
);
2378 RegCloseKey( hkcr
);
2379 RegCloseKey( hkeysub1
);
2380 RegCloseKey( hklmsub1
);
2381 RegCloseKey( hkcrsub1
);
2382 RegCloseKey( hklmsub2
);
2383 RegCloseKey( hkcrsub2
);
2386 static void test_deleted_key(void)
2390 DWORD val_count
, type
;
2393 /* Open the test key, then delete it while it's open */
2394 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2396 delete_key( hkey_main
);
2398 val_count
= sizeof(value
);
2400 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2401 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2403 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2404 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2406 val_count
= sizeof(value
);
2408 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2409 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2411 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2412 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2414 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2415 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2417 RegCloseKey( hkey2
);
2419 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2420 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2422 RegCloseKey( hkey2
);
2424 res
= RegFlushKey( hkey
);
2425 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2427 RegCloseKey( hkey
);
2432 static void test_delete_value(void)
2437 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2438 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2440 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2441 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2443 res
= RegDeleteValueA( hkey_main
, "test" );
2444 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2446 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2447 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2449 res
= RegDeleteValueA( hkey_main
, "test" );
2450 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2452 memset(longname
, 'a', 400);
2454 res
= RegDeleteValueA( hkey_main
, longname
);
2455 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2456 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2459 START_TEST(registry
)
2461 /* Load pointers for functions that are not available in all Windows versions */
2466 create_test_entries();
2468 test_query_value_ex();
2470 test_reg_open_key();
2471 test_reg_create_key();
2472 test_reg_close_key();
2473 test_reg_delete_key();
2474 test_reg_query_value();
2475 test_string_termination();
2480 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2481 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2482 set_privileges(SE_RESTORE_NAME
, TRUE
))
2484 test_reg_save_key();
2485 test_reg_load_key();
2486 test_reg_unload_key();
2488 set_privileges(SE_BACKUP_NAME
, FALSE
);
2489 set_privileges(SE_RESTORE_NAME
, FALSE
);
2492 test_reg_delete_tree();
2495 test_delete_value();
2498 delete_key( hkey_main
);
2500 test_regconnectregistry();