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";
40 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
41 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
42 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
43 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
44 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
45 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
46 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
49 /* Debugging functions from wine/libs/wine/debug.c */
51 /* allocate some tmp string space */
52 /* FIXME: this is not 100% thread-safe */
53 static char *get_temp_buffer( int size
)
55 static char *list
[32];
60 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
62 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
64 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
65 if (ret
) list
[idx
] = ret
;
69 static const char *wine_debugstr_an( const char *str
, int n
)
71 static const char hex
[16] = "0123456789abcdef";
75 if (!((ULONG_PTR
)str
>> 16))
77 if (!str
) return "(null)";
78 res
= get_temp_buffer( 6 );
79 sprintf( res
, "#%04x", LOWORD(str
) );
82 if (n
== -1) n
= strlen(str
);
84 size
= 10 + min( 300, n
* 4 );
85 dst
= res
= get_temp_buffer( size
);
87 while (n
-- > 0 && dst
<= res
+ size
- 9)
89 unsigned char c
= *str
++;
92 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
93 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
94 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
95 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
96 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
98 if (c
>= ' ' && c
<= 126)
104 *dst
++ = hex
[(c
>> 4) & 0x0f];
105 *dst
++ = hex
[c
& 0x0f];
120 #define ADVAPI32_GET_PROC(func) \
121 p ## func = (void*)GetProcAddress(hadvapi32, #func)
123 static void InitFunctionPtrs(void)
125 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
126 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
127 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
129 /* This function was introduced with Windows 2003 SP1 */
130 ADVAPI32_GET_PROC(RegGetValueA
);
131 ADVAPI32_GET_PROC(RegDeleteTreeA
);
132 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
134 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
135 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
136 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
137 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
140 /* delete key and all its subkeys */
141 static DWORD
delete_key( HKEY hkey
)
146 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
149 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
151 ret
= delete_key( tmp
);
156 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
157 RegDeleteKeyA( hkey
, "" );
161 static void setup_main_key(void)
163 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
165 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
168 #define lok ok_(__FILE__, line)
169 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
170 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
173 DWORD ret
, type
, cbData
;
179 /* When successful RegQueryValueExA() leaves GLE as is,
180 * so we must reset it to detect unimplemented functions.
182 SetLastError(0xdeadbeef);
183 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
184 GLE
= GetLastError();
185 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
186 /* It is wrong for the Ansi version to not be implemented */
187 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
188 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
190 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
191 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
192 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
194 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
195 memset(value
, 0xbd, cbData
+1);
197 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
198 GLE
= GetLastError();
199 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
202 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
203 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
207 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
208 wine_debugstr_an((char*)value
, cbData
), cbData
,
209 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
210 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
212 HeapFree(GetProcessHeap(), 0, value
);
215 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
216 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
219 DWORD ret
, type
, cbData
;
224 /* When successful RegQueryValueExW() leaves GLE as is,
225 * so we must reset it to detect unimplemented functions.
227 SetLastError(0xdeadbeef);
228 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
229 GLE
= GetLastError();
230 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
231 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
233 win_skip("RegQueryValueExW() is not implemented\n");
237 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
238 lok(cbData
== full_byte_len
,
239 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
241 /* Give enough space to overflow by one WCHAR */
242 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
243 memset(value
, 0xbd, cbData
+2);
245 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
246 GLE
= GetLastError();
247 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
250 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
251 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
252 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
254 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
255 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
256 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
257 HeapFree(GetProcessHeap(), 0, value
);
260 static void test_set_value(void)
264 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
265 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};
266 static const WCHAR emptyW
[] = {0};
267 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
268 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};
269 static const WCHAR substring2W
[] = {'T','h','i','s',0};
271 static const char name1A
[] = "CleanSingleString";
272 static const char name2A
[] = "SomeIntraZeroedString";
273 static const char emptyA
[] = "";
274 static const char string1A
[] = "ThisNeverBreaks";
275 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
276 static const char substring2A
[] = "This";
280 /* Crashes on NT4, Windows 2000 and XP SP1 */
281 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
282 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
285 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
286 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
287 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
288 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
290 /* RegSetValueA ignores the size passed in */
291 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
292 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
293 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
294 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
296 /* stops at first null */
297 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
298 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
299 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
300 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
302 /* only REG_SZ is supported on NT*/
303 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
304 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
306 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
307 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
309 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
310 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
312 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
313 * Surprisingly enough we're supposed to get zero bytes out of it.
315 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
316 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
317 test_hkey_main_Value_A(name1A
, NULL
, 0);
318 test_hkey_main_Value_W(name1W
, NULL
, 0);
320 /* test RegSetValueExA with an empty string */
321 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
322 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
323 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
324 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
326 /* test RegSetValueExA with off-by-one size */
327 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
328 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
329 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
330 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
332 /* test RegSetValueExA with normal string */
333 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
334 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
335 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
336 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
338 /* test RegSetValueExA with intrazeroed string */
339 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
340 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
341 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
342 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
346 /* Crashes on NT4, Windows 2000 and XP SP1 */
347 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
348 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
351 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
352 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
353 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
354 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
356 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
357 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
358 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
359 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
361 /* RegSetValueW ignores the size passed in */
362 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
363 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
364 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
365 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
367 /* stops at first null */
368 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
369 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
370 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
371 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
373 /* only REG_SZ is supported */
374 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
375 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
376 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
377 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
378 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
379 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
381 /* test RegSetValueExW with off-by-one size */
382 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
383 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
384 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
385 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
387 /* test RegSetValueExW with normal string */
388 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
389 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
390 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
391 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
393 /* test RegSetValueExW with intrazeroed string */
394 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
395 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
396 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
397 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
400 static void create_test_entries(void)
402 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
404 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
405 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
407 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
408 "RegSetValueExA failed\n");
409 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
410 "RegSetValueExA failed\n");
411 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
412 "RegSetValueExA failed\n");
413 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
414 "RegSetValueExA failed\n");
415 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
416 "RegSetValueExA failed\n");
417 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
418 "RegSetValueExA failed\n");
419 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
420 "RegSetValueExA failed\n");
423 static void test_enum_value(void)
427 char value
[20], data
[20];
428 WCHAR valueW
[20], dataW
[20];
429 DWORD val_count
, data_count
, type
;
430 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
431 static const WCHAR testW
[] = {'T','e','s','t',0};
432 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
434 /* create the working key for new 'Test' value */
435 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
436 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
438 /* check NULL data with zero length */
439 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
440 if (GetVersion() & 0x80000000)
441 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
443 ok( !res
, "RegSetValueExA returned %d\n", res
);
444 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
445 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
446 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
447 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
449 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
450 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
452 /* overflow both name and data */
456 strcpy( value
, "xxxxxxxxxx" );
457 strcpy( data
, "xxxxxxxxxx" );
458 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
459 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
460 ok( val_count
== 2, "val_count set to %d\n", val_count
);
461 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
462 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
463 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
464 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
470 strcpy( value
, "xxxxxxxxxx" );
471 strcpy( data
, "xxxxxxxxxx" );
472 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
473 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
474 ok( val_count
== 3, "val_count set to %d\n", val_count
);
475 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
476 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
477 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
478 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
479 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
480 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
481 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
483 /* overflow empty name */
487 strcpy( value
, "xxxxxxxxxx" );
488 strcpy( data
, "xxxxxxxxxx" );
489 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
490 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
491 ok( val_count
== 0, "val_count set to %d\n", val_count
);
492 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
493 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
494 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
495 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
496 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
497 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
503 strcpy( value
, "xxxxxxxxxx" );
504 strcpy( data
, "xxxxxxxxxx" );
505 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
506 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
507 ok( val_count
== 20, "val_count set to %d\n", val_count
);
508 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
509 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
510 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
511 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
517 strcpy( value
, "xxxxxxxxxx" );
518 strcpy( data
, "xxxxxxxxxx" );
519 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
520 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
521 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
522 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
523 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
524 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
525 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
529 SetLastError(0xdeadbeef);
530 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
531 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
533 win_skip("RegSetValueExW is not implemented\n");
536 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
538 /* overflow both name and data */
542 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
543 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
544 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
545 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
546 ok( val_count
== 2, "val_count set to %d\n", val_count
);
547 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
548 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
549 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
550 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
556 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
557 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
558 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
559 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
560 ok( val_count
== 3, "val_count set to %d\n", val_count
);
561 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
562 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
563 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
564 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
570 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
571 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
572 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
573 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
574 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
575 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
576 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
577 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
578 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
584 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
585 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
586 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
587 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
588 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
589 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
590 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
591 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
592 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
595 RegDeleteKeyA(test_key
, "");
596 RegCloseKey(test_key
);
599 static void test_query_value_ex(void)
606 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
607 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
608 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
609 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
613 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
614 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
615 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
617 size
= sizeof(buffer
);
618 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
619 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
620 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
623 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
624 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
627 static void test_get_value(void)
634 CHAR expanded
[] = "bar\\subdir1";
635 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
639 win_skip("RegGetValue not available on this platform\n");
643 /* Invalid parameter */
644 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
645 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
647 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
648 size
= type
= dw
= 0xdeadbeef;
649 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
650 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
651 ok(size
== 4, "size=%d\n", size
);
652 ok(type
== REG_DWORD
, "type=%d\n", type
);
653 ok(dw
== 0x12345678, "dw=%d\n", dw
);
655 /* Query by subkey-name */
656 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
657 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
659 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
660 size
= type
= dw
= 0xdeadbeef;
661 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
662 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
663 /* Although the function failed all values are retrieved */
664 ok(size
== 4, "size=%d\n", size
);
665 ok(type
== REG_DWORD
, "type=%d\n", type
);
666 ok(dw
== 0x12345678, "dw=%d\n", dw
);
668 /* Test RRF_ZEROONFAILURE */
669 type
= dw
= 0xdeadbeef; size
= 4;
670 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
671 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
672 /* Again all values are retrieved ... */
673 ok(size
== 4, "size=%d\n", size
);
674 ok(type
== REG_DWORD
, "type=%d\n", type
);
675 /* ... except the buffer, which is zeroed out */
676 ok(dw
== 0, "dw=%d\n", dw
);
678 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
679 type
= size
= 0xbadbeef;
680 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
681 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
682 ok(size
== 4, "size=%d\n", size
);
683 ok(type
== REG_DWORD
, "type=%d\n", type
);
685 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
686 size
= type
= dw
= 0xdeadbeef;
687 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
688 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
689 ok(size
== 4, "size=%d\n", size
);
690 ok(type
== REG_DWORD
, "type=%d\n", type
);
691 ok(dw
== 0x12345678, "dw=%d\n", dw
);
693 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
694 size
= type
= dw
= 0xdeadbeef;
695 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
696 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
697 ok(size
== 4, "size=%d\n", size
);
698 ok(type
== REG_BINARY
, "type=%d\n", type
);
699 ok(dw
== 0x12345678, "dw=%d\n", dw
);
701 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
702 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
703 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
704 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
705 ok(size
== 8, "size=%d\n", size
);
706 ok(type
== REG_BINARY
, "type=%d\n", type
);
707 ok(qw
[0] == 0x12345678 &&
708 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
710 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
711 type
= dw
= 0xdeadbeef; size
= 4;
712 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
713 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
714 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
715 ok(size
== 8, "size=%d\n", size
);
717 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
718 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
719 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
720 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
721 ok(size
== 8, "size=%d\n", size
);
722 ok(type
== REG_BINARY
, "type=%d\n", type
);
723 ok(qw
[0] == 0x12345678 &&
724 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
726 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
727 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
728 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
729 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
730 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
731 ok(type
== REG_SZ
, "type=%d\n", type
);
732 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
734 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
735 type
= 0xdeadbeef; size
= 0;
736 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
737 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
738 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
739 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
740 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
741 ok(type
== REG_SZ
, "type=%d\n", type
);
743 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
744 strcpy(buf
, sTestpath1
);
747 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
748 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
749 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
751 size
== 1, /* win2k3 */
753 ok(type
== REG_SZ
, "type=%d\n", type
);
754 ok(!strcmp(sTestpath1
, buf
) ||
756 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
758 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
759 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
760 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
761 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
762 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
763 ok(type
== REG_SZ
, "type=%d\n", type
);
764 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
766 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
768 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
769 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
770 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
771 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
772 (size
== strlen(sTestpath2
)+1),
773 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
775 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
776 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
777 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
778 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
779 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
780 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
781 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
782 ok(type
== REG_SZ
, "type=%d\n", type
);
783 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
785 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
786 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
787 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_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 sTestpath2 length + 1 here. */
790 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
791 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
792 ok(type
== REG_SZ
, "type=%d\n", type
);
793 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
795 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
796 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
797 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
798 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
799 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
800 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
801 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
803 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
805 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
806 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
807 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
808 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
809 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
811 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
812 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
813 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
815 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
816 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
817 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
819 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
820 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
821 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
822 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
823 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
824 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
825 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
826 ok(type
== REG_SZ
, "type=%d\n", type
);
827 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
830 static void test_reg_open_key(void)
833 HKEY hkResult
= NULL
;
834 HKEY hkPreserve
= NULL
;
835 HKEY hkRoot64
= NULL
;
836 HKEY hkRoot32
= NULL
;
838 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
840 EXPLICIT_ACCESSA access
;
842 SECURITY_DESCRIPTOR
*sd
;
844 /* successful open */
845 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
846 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
847 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
848 hkPreserve
= hkResult
;
850 /* open same key twice */
851 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
852 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
853 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
854 ok(hkResult
!= NULL
, "hkResult != NULL\n");
855 RegCloseKey(hkResult
);
857 /* open nonexistent key
858 * check that hkResult is set to NULL
860 hkResult
= hkPreserve
;
861 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
862 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
863 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
865 /* open the same nonexistent key again to make sure the key wasn't created */
866 hkResult
= hkPreserve
;
867 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
868 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
869 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
871 /* send in NULL lpSubKey
872 * check that hkResult receives the value of hKey
874 hkResult
= hkPreserve
;
875 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
876 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
877 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
879 /* send empty-string in lpSubKey */
880 hkResult
= hkPreserve
;
881 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
882 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
883 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
885 /* send in NULL lpSubKey and NULL hKey
886 * hkResult is set to NULL
888 hkResult
= hkPreserve
;
889 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
890 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
891 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
893 /* only send NULL hKey
894 * the value of hkResult remains unchanged
896 hkResult
= hkPreserve
;
897 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
898 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
899 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
900 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
901 RegCloseKey(hkResult
);
903 /* send in NULL hkResult */
904 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
905 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
907 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
908 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
910 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
911 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
913 /* beginning backslash character */
914 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
915 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
916 broken(ret
== ERROR_SUCCESS
), /* wow64 */
917 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
918 if (!ret
) RegCloseKey(hkResult
);
921 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
922 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
923 ret
== ERROR_BAD_PATHNAME
, /* NT */
924 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
925 RegCloseKey(hkResult
);
929 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
930 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
931 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
932 RegCloseKey(hkResult
);
935 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
936 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
937 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
938 RegCloseKey(hkResult
);
940 /* Try using WOW64 flags when opening a key with a DACL set to verify that
941 * the registry access check is performed correctly. Redirection isn't
942 * being tested, so the tests don't care about whether the process is
943 * running under WOW64. */
944 if (!pIsWow64Process
)
946 win_skip("WOW64 flags are not recognized\n");
950 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
951 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
952 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
953 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
955 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
956 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
957 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
958 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
960 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
961 0, 0, 0, 0, 0, 0, 0, &world_sid
);
963 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
965 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
966 access
.grfAccessMode
= SET_ACCESS
;
967 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
968 access
.Trustee
.pMultipleTrustee
= NULL
;
969 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
970 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
971 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
972 access
.Trustee
.ptstrName
= (char *)world_sid
;
974 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
975 ok(ret
== ERROR_SUCCESS
,
976 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
978 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
979 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
981 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
983 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
985 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
987 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
988 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
990 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
992 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
994 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
997 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
998 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
999 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1000 RegCloseKey(hkResult
);
1003 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1004 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1005 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1006 RegCloseKey(hkResult
);
1008 HeapFree(GetProcessHeap(), 0, sd
);
1011 RegDeleteKeyA(hkRoot64
, "");
1012 RegCloseKey(hkRoot64
);
1013 RegDeleteKeyA(hkRoot32
, "");
1014 RegCloseKey(hkRoot32
);
1017 static void test_reg_create_key(void)
1021 HKEY hkRoot64
= NULL
;
1022 HKEY hkRoot32
= NULL
;
1025 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1027 EXPLICIT_ACCESSA access
;
1029 SECURITY_DESCRIPTOR
*sd
;
1031 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1032 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1033 /* should succeed: all versions of Windows ignore the access rights
1034 * to the parent handle */
1035 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1036 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1039 RegDeleteKey(hkey2
, "");
1040 RegDeleteKey(hkey1
, "");
1044 /* test creation of volatile keys */
1045 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1046 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1047 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1048 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1049 if (!ret
) RegCloseKey( hkey2
);
1050 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1051 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1053 /* should succeed if the key already exists */
1054 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1055 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1058 RegDeleteKey(hkey2
, "");
1059 RegDeleteKey(hkey1
, "");
1063 /* beginning backslash character */
1064 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1065 if (!(GetVersion() & 0x80000000))
1066 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1068 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1069 RegDeleteKey(hkey1
, NULL
);
1073 /* WOW64 flags - open an existing key */
1075 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1076 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1077 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1081 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1082 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1083 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1086 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1087 * the registry access check is performed correctly. Redirection isn't
1088 * being tested, so the tests don't care about whether the process is
1089 * running under WOW64. */
1090 if (!pIsWow64Process
)
1092 win_skip("WOW64 flags are not recognized\n");
1096 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1097 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1098 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1099 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1101 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1102 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1103 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1104 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1106 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1107 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1109 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1111 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1112 access
.grfAccessMode
= SET_ACCESS
;
1113 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1114 access
.Trustee
.pMultipleTrustee
= NULL
;
1115 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1116 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1117 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1118 access
.Trustee
.ptstrName
= (char *)world_sid
;
1120 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1121 ok(ret
== ERROR_SUCCESS
,
1122 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1124 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1125 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1127 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1129 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1131 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1133 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1134 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1136 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1138 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1140 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1143 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1144 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1145 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1146 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1150 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1151 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1152 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1153 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1156 HeapFree(GetProcessHeap(), 0, sd
);
1159 RegDeleteKeyA(hkRoot64
, "");
1160 RegCloseKey(hkRoot64
);
1161 RegDeleteKeyA(hkRoot32
, "");
1162 RegCloseKey(hkRoot32
);
1165 static void test_reg_close_key(void)
1170 /* successfully close key
1171 * hkHandle remains changed after call to RegCloseKey
1173 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1174 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1175 ret
= RegCloseKey(hkHandle
);
1176 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1178 /* try to close the key twice */
1179 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1180 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1181 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1183 /* try to close a NULL handle */
1184 ret
= RegCloseKey(NULL
);
1185 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1186 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1188 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1189 * win98 doesn't give a new handle when the same key is opened.
1190 * Not re-opening will make some next tests fail.
1192 if (hkey_main
== hkHandle
)
1194 trace("The main handle is most likely closed, so re-opening\n");
1195 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1199 static void test_reg_delete_key(void)
1203 ret
= RegDeleteKey(hkey_main
, NULL
);
1205 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1206 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1207 * Not re-creating will make some next tests fail.
1209 if (ret
== ERROR_SUCCESS
)
1211 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1212 " re-creating the main key\n");
1216 ok(ret
== ERROR_INVALID_PARAMETER
||
1217 ret
== ERROR_ACCESS_DENIED
||
1218 ret
== ERROR_BADKEY
, /* Win95 */
1222 static void test_reg_save_key(void)
1226 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1227 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1230 static void test_reg_load_key(void)
1235 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1236 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1238 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1239 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1241 RegCloseKey(hkHandle
);
1244 static void test_reg_unload_key(void)
1248 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1249 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1251 DeleteFile("saved_key");
1252 DeleteFile("saved_key.LOG");
1255 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1257 TOKEN_PRIVILEGES tp
;
1261 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1264 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1266 CloseHandle(hToken
);
1270 tp
.PrivilegeCount
= 1;
1271 tp
.Privileges
[0].Luid
= luid
;
1274 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1276 tp
.Privileges
[0].Attributes
= 0;
1278 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1279 if (GetLastError() != ERROR_SUCCESS
)
1281 CloseHandle(hToken
);
1285 CloseHandle(hToken
);
1289 /* tests that show that RegConnectRegistry and
1290 OpenSCManager accept computer names without the
1291 \\ prefix (what MSDN says). */
1292 static void test_regconnectregistry( void)
1294 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1295 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1296 DWORD len
= sizeof(compName
) ;
1302 SetLastError(0xdeadbeef);
1303 ret
= GetComputerNameA(compName
, &len
);
1304 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1307 lstrcpyA(netwName
, "\\\\");
1308 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1310 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1312 retl
== ERROR_DLL_INIT_FAILED
||
1313 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1314 "RegConnectRegistryA failed err = %d\n", retl
);
1315 if( !retl
) RegCloseKey( hkey
);
1317 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1319 retl
== ERROR_DLL_INIT_FAILED
||
1320 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1321 "RegConnectRegistryA failed err = %d\n", retl
);
1322 if( !retl
) RegCloseKey( hkey
);
1324 SetLastError(0xdeadbeef);
1325 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1326 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1328 win_skip("OpenSCManagerA is not implemented\n");
1332 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1333 CloseServiceHandle( schnd
);
1335 SetLastError(0xdeadbeef);
1336 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1337 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1338 CloseServiceHandle( schnd
);
1342 static void test_reg_query_value(void)
1349 static const WCHAR expected
[] = {'d','a','t','a',0};
1351 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1352 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1354 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1355 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1357 /* try an invalid hkey */
1358 SetLastError(0xdeadbeef);
1360 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1361 ok(ret
== ERROR_INVALID_HANDLE
||
1362 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1363 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1364 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1365 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1367 /* try a NULL hkey */
1368 SetLastError(0xdeadbeef);
1370 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1371 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1372 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1373 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1375 /* try a NULL value */
1377 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1378 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1379 ok(size
== 5, "Expected 5, got %d\n", size
);
1381 /* try a NULL size */
1382 SetLastError(0xdeadbeef);
1384 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1385 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1386 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1387 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1389 /* try a NULL value and size */
1390 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1391 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1393 /* try a size too small */
1394 SetLastError(0xdeadbeef);
1397 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1398 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1399 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1400 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1401 ok(size
== 5, "Expected 5, got %d\n", size
);
1403 /* successfully read the value using 'subkey' */
1405 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1406 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1407 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1408 ok(size
== 5, "Expected 5, got %d\n", size
);
1410 /* successfully read the value using the subkey key */
1412 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1413 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1414 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1415 ok(size
== 5, "Expected 5, got %d\n", size
);
1417 /* unicode - try size too small */
1418 SetLastError(0xdeadbeef);
1421 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1422 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1424 win_skip("RegQueryValueW is not implemented\n");
1427 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1428 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1429 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1430 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1432 /* unicode - try size in WCHARS */
1433 SetLastError(0xdeadbeef);
1434 size
= sizeof(valW
) / sizeof(WCHAR
);
1435 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1436 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1437 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1438 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1439 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1441 /* unicode - successfully read the value */
1442 size
= sizeof(valW
);
1443 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1444 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1445 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1446 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1448 /* unicode - set the value without a NULL terminator */
1449 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1450 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1452 /* unicode - read the unterminated value, value is terminated for us */
1453 memset(valW
, 'a', sizeof(valW
));
1454 size
= sizeof(valW
);
1455 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1456 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1457 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1458 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1461 RegDeleteKeyA(subkey
, "");
1462 RegCloseKey(subkey
);
1465 static void test_string_termination(void)
1469 static const char string
[] = "FullString";
1472 DWORD insize
, outsize
, nsize
;
1474 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1475 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1477 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1478 insize
=sizeof(string
)-1;
1479 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1480 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1482 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1483 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1485 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1486 insize
=sizeof(string
)-2;
1487 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1488 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1490 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1491 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1492 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1494 /* RegQueryValueExA may return a string with no trailing '\0' */
1496 memset(buffer
, 0xbd, sizeof(buffer
));
1497 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1498 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1499 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1500 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1501 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1502 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1504 /* RegQueryValueExA adds a trailing '\0' if there is room */
1506 memset(buffer
, 0xbd, sizeof(buffer
));
1507 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1508 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1509 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1510 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1511 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1512 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1514 /* RegEnumValueA may return a string with no trailing '\0' */
1516 memset(buffer
, 0xbd, sizeof(buffer
));
1518 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1519 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1520 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1521 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1522 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1523 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1524 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1526 /* RegEnumValueA adds a trailing '\0' if there is room */
1528 memset(buffer
, 0xbd, sizeof(buffer
));
1530 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1531 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1532 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1533 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1534 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1535 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1536 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1538 RegDeleteKeyA(subkey
, "");
1539 RegCloseKey(subkey
);
1542 static void test_reg_delete_tree(void)
1544 CHAR buffer
[MAX_PATH
];
1545 HKEY subkey
, subkey2
;
1548 if(!pRegDeleteTreeA
) {
1549 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1553 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1554 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1555 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1556 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1557 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1558 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1559 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1560 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1561 ret
= RegCloseKey(subkey2
);
1562 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1564 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1565 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1566 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1567 "subkey2 was not deleted\n");
1569 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1570 "Default value of subkey not longer present\n");
1572 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1573 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1574 ret
= RegCloseKey(subkey2
);
1575 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1576 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1577 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1578 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1579 "subkey2 was not deleted\n");
1580 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1581 "Default value of subkey not longer present\n");
1583 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1584 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1585 ret
= RegCloseKey(subkey2
);
1586 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1587 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1588 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1589 ret
= RegCloseKey(subkey2
);
1590 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1591 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1592 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1593 ret
= pRegDeleteTreeA(subkey
, NULL
);
1594 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1595 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1596 "subkey was deleted\n");
1597 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1598 "subkey2 was not deleted\n");
1599 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1600 "subkey3 was not deleted\n");
1602 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1603 ok(ret
== ERROR_SUCCESS
,
1604 "Default value of subkey is not present\n");
1605 ok(!lstrlenA(buffer
),
1606 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1608 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1609 "Value is still present\n");
1611 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1612 ok(ret
== ERROR_FILE_NOT_FOUND
,
1613 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1616 static void test_rw_order(void)
1620 static char keyname
[] = "test_rw_order";
1622 DWORD values
, value_len
, value_name_max_len
;
1625 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1626 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1627 if(ret
!= ERROR_SUCCESS
) {
1628 skip("Couldn't create key. Skipping.\n");
1632 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1633 "RegSetValueExA for value \"A\" failed\n");
1634 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1635 "RegSetValueExA for value \"C\" failed\n");
1636 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1637 "RegSetValueExA for value \"D\" failed\n");
1638 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1639 "RegSetValueExA for value \"B\" failed\n");
1641 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1642 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1643 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1645 /* Value enumeration preserves RegSetValueEx call order */
1647 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1648 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1650 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1651 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1653 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1654 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1656 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1657 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1659 ok(!RegDeleteKey(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1662 static void test_symlinks(void)
1664 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1665 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1667 UNICODE_STRING target_str
;
1671 DWORD target_len
, type
, len
, dw
, err
;
1673 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1675 win_skip( "Can't perform symlink tests\n" );
1679 pRtlFormatCurrentUserKeyPath( &target_str
);
1681 target_len
= target_str
.Length
+ sizeof(targetW
);
1682 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1683 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1684 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1686 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1687 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1688 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1690 /* REG_SZ is not allowed */
1691 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1692 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1693 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1694 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1695 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1696 /* other values are not allowed */
1697 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1698 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1700 /* try opening the target through the link */
1702 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1703 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1705 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1706 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1709 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1710 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1713 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1714 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1716 len
= sizeof(buffer
);
1717 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1718 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1719 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1721 len
= sizeof(buffer
);
1722 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1723 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1725 /* REG_LINK can be created in non-link keys */
1726 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1727 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1728 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1729 len
= sizeof(buffer
);
1730 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1731 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1732 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1733 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1734 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1738 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1739 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1741 len
= sizeof(buffer
);
1742 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1743 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1744 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1746 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1747 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1750 /* now open the symlink itself */
1752 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1753 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1754 len
= sizeof(buffer
);
1755 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1756 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1757 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1760 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1761 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1762 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1763 len
= sizeof(buffer
);
1764 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1765 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1766 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1769 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1770 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1771 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1773 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1774 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1775 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1777 err
= RegDeleteKey( hkey_main
, "target" );
1778 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1780 err
= RegDeleteKey( hkey_main
, "link" );
1781 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1783 status
= pNtDeleteKey( link
);
1784 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1785 RegCloseKey( link
);
1787 HeapFree( GetProcessHeap(), 0, target
);
1788 pRtlFreeUnicodeString( &target_str
);
1791 static const DWORD ptr_size
= 8 * sizeof(void*);
1793 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1796 DWORD err
, type
, dw
, len
= sizeof(dw
);
1798 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1799 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1800 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1802 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1803 if (err
== ERROR_FILE_NOT_FOUND
)
1806 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1811 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1813 DWORD dw
= get_key_value( root
, name
, flags
);
1814 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1816 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1818 static void test_redirection(void)
1820 DWORD err
, type
, dw
, len
;
1821 HKEY key
, root32
, root64
, key32
, key64
;
1822 BOOL is_vista
= FALSE
;
1827 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
1829 skip( "Not on Wow64, no redirection\n" );
1834 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1835 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
1836 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1838 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1839 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
1840 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1842 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1843 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
1844 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1846 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1847 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
1848 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1851 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1852 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1855 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1856 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1860 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1861 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1862 ok( dw
== 32, "wrong value %u\n", dw
);
1866 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1867 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1868 ok( dw
== 64, "wrong value %u\n", dw
);
1870 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1871 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1872 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1876 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1877 /* the new (and simpler) Win7 mechanism doesn't */
1878 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1880 trace( "using Vista-style Wow6432Node handling\n" );
1883 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1884 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1885 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1886 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1887 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1888 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1892 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
1894 trace( "using Vista-style Wow6432Node handling\n" );
1897 check_key_value( key
, "Wine\\Winetest", 0, 64 );
1898 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1904 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1905 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1906 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1907 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1908 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1909 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1910 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1911 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1912 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
1913 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
1914 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1917 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1918 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1919 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1920 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1921 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1922 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1923 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1924 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1925 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1929 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
1930 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1933 /* KEY_WOW64 flags have no effect on 64-bit */
1934 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1935 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1936 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1937 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1941 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1942 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1943 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1944 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1947 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1948 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1949 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1950 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1951 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1952 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1957 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1958 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1959 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1960 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1961 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1962 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1963 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1966 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1967 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1968 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1969 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1970 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1971 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1975 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
1976 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1977 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1978 check_key_value( key
, "Winetest", 0, 32 );
1979 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1980 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
1985 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
1986 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1987 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1988 dw
= get_key_value( key
, "Winetest", 0 );
1989 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
1990 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1991 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
1994 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
1995 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1996 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1997 check_key_value( key
, "Winetest", 0, 32 );
1998 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1999 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2003 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2004 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2005 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2006 check_key_value( key
, "Winetest", 0, ptr_size
);
2007 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2008 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2009 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2010 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2015 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2016 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2017 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2018 dw
= get_key_value( key
, "Winetest", 0 );
2019 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2020 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2021 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2022 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2025 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2026 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2027 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2028 check_key_value( key
, "Winetest", 0, 32 );
2029 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2030 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2034 if (pRegDeleteKeyExA
)
2036 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2037 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2038 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2039 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2040 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2041 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2045 err
= RegDeleteKeyA( key32
, "" );
2046 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2047 err
= RegDeleteKeyA( key64
, "" );
2048 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2049 RegDeleteKeyA( key64
, "" );
2050 RegDeleteKeyA( root64
, "" );
2052 RegCloseKey( key32
);
2053 RegCloseKey( key64
);
2054 RegCloseKey( root32
);
2055 RegCloseKey( root64
);
2058 static void test_classesroot(void)
2060 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2062 DWORD type
= REG_SZ
;
2063 static CHAR buffer
[8];
2066 /* create a key in the user's classes */
2067 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2070 RegCloseKey( hkey
);
2072 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2073 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2074 if (res
== ERROR_ACCESS_DENIED
)
2076 skip("not enough privileges to add a user class\n");
2080 /* try to open that key in hkcr */
2081 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2082 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2083 todo_wine
ok(res
== ERROR_SUCCESS
||
2084 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2085 "test key not found in hkcr: %d\n", res
);
2088 skip("HKCR key merging not supported\n");
2090 RegCloseKey( hkey
);
2094 /* set a value in user's classes */
2095 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2096 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2098 /* try to find the value in hkcr */
2099 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2100 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2101 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2103 /* modify the value in hkcr */
2104 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2105 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2107 /* check if the value is also modified in user's classes */
2108 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2109 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2110 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2112 /* set a value in hkcr */
2113 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2114 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2116 /* try to find the value in user's classes */
2117 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2118 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2119 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2121 /* modify the value in user's classes */
2122 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2123 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2125 /* check if the value is also modified in hkcr */
2126 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2127 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2128 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2133 RegCloseKey( hkey
);
2134 RegCloseKey( hkcr
);
2136 /* create a key in the hklm classes */
2137 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2140 RegCloseKey( hklm
);
2142 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2143 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2144 if (res
== ERROR_ACCESS_DENIED
)
2146 skip("not enough privileges to add a system class\n");
2150 /* try to open that key in hkcr */
2151 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2152 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2153 ok(res
== ERROR_SUCCESS
,
2154 "test key not found in hkcr: %d\n", res
);
2158 RegCloseKey( hklm
);
2162 /* set a value in hklm classes */
2163 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2164 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2166 /* try to find the value in hkcr */
2167 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2168 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2169 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2171 /* modify the value in hkcr */
2172 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2173 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2175 /* check that the value is not modified in hklm classes */
2176 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2177 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2178 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2180 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2181 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2183 /* try to open that key in hkcr */
2184 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2185 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2186 ok(res
== ERROR_SUCCESS
,
2187 "test key not found in hkcr: %d\n", res
);
2189 /* set a value in user's classes */
2190 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2191 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2193 /* try to find the value in hkcr */
2194 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2195 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2196 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2198 /* modify the value in hklm */
2199 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2200 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2202 /* check that the value is not overwritten in hkcr or user's classes */
2203 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2204 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2205 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2206 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2207 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2208 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2210 /* modify the value in hkcr */
2211 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2212 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2214 /* check that the value is overwritten in hklm and user's classes */
2215 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2216 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2217 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2218 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2219 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2220 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2222 /* create a subkey in hklm */
2223 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2224 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2225 /* try to open that subkey in hkcr */
2226 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2227 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2229 /* set a value in hklm classes */
2230 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2231 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2233 /* try to find the value in hkcr */
2234 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2235 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2236 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2238 /* modify the value in hkcr */
2239 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2240 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2242 /* check that the value is modified in hklm classes */
2243 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2244 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2245 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2247 /* create a subkey in user's classes */
2248 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2249 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2251 /* set a value in user's classes */
2252 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2253 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2255 /* try to find the value in hkcr */
2256 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2257 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2258 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2260 /* modify the value in hklm */
2261 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2262 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2264 /* check that the value is not overwritten in hkcr or user's classes */
2265 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2266 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2267 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2268 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2269 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2270 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2272 /* modify the value in hkcr */
2273 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2274 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2276 /* check that the value is not overwritten in hklm, but in user's classes */
2277 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2278 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2279 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2280 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2281 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2282 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2284 /* new subkey in hkcr */
2285 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2286 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2287 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2288 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2290 /* try to open that new subkey in user's classes and hklm */
2291 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2292 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2294 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2295 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2297 /* check that the value is present in hklm */
2298 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2299 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2300 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2306 delete_key( hkeysub1
);
2307 delete_key( hklmsub1
);
2308 delete_key( hkcrsub1
);
2309 delete_key( hklmsub2
);
2310 delete_key( hkcrsub2
);
2311 RegCloseKey( hkey
);
2312 RegCloseKey( hklm
);
2313 RegCloseKey( hkcr
);
2314 RegCloseKey( hkeysub1
);
2315 RegCloseKey( hklmsub1
);
2316 RegCloseKey( hkcrsub1
);
2317 RegCloseKey( hklmsub2
);
2318 RegCloseKey( hkcrsub2
);
2321 static void test_deleted_key(void)
2325 DWORD val_count
, type
;
2328 /* Open the test key, then delete it while it's open */
2329 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2331 delete_key( hkey_main
);
2333 val_count
= sizeof(value
);
2335 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2336 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2338 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2339 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2341 val_count
= sizeof(value
);
2343 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2344 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2346 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2347 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2349 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2350 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2352 RegCloseKey( hkey2
);
2354 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2355 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2357 RegCloseKey( hkey2
);
2359 res
= RegFlushKey( hkey
);
2360 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2362 RegCloseKey( hkey
);
2367 static void test_delete_value(void)
2372 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2373 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2375 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2376 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2378 res
= RegDeleteValueA( hkey_main
, "test" );
2379 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2381 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2382 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2384 res
= RegDeleteValueA( hkey_main
, "test" );
2385 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2387 memset(longname
, 'a', 400);
2389 res
= RegDeleteValueA( hkey_main
, longname
);
2390 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2391 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2394 START_TEST(registry
)
2396 /* Load pointers for functions that are not available in all Windows versions */
2401 create_test_entries();
2403 test_query_value_ex();
2405 test_reg_open_key();
2406 test_reg_create_key();
2407 test_reg_close_key();
2408 test_reg_delete_key();
2409 test_reg_query_value();
2410 test_string_termination();
2415 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2416 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2417 set_privileges(SE_RESTORE_NAME
, TRUE
))
2419 test_reg_save_key();
2420 test_reg_load_key();
2421 test_reg_unload_key();
2423 set_privileges(SE_BACKUP_NAME
, FALSE
);
2424 set_privileges(SE_RESTORE_NAME
, FALSE
);
2427 test_reg_delete_tree();
2430 test_delete_value();
2433 delete_key( hkey_main
);
2435 test_regconnectregistry();