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
);
350 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
351 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
354 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
355 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
356 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
357 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
359 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
360 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
361 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
362 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
364 /* RegSetValueW ignores the size passed in */
365 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
366 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
367 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
368 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
370 /* stops at first null */
371 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
372 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
373 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
374 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
376 /* only REG_SZ is supported */
377 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
378 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
379 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
380 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
381 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
382 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
384 /* test RegSetValueExW with off-by-one size */
385 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
386 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
387 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
388 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
390 /* test RegSetValueExW with normal string */
391 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
392 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
393 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
394 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
396 /* test RegSetValueExW with intrazeroed string */
397 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
398 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
399 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
400 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
402 /* test RegSetValueExW with data = 1 */
403 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
404 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
405 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
406 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
409 static void create_test_entries(void)
411 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
413 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
414 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
416 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
417 "RegSetValueExA failed\n");
418 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
419 "RegSetValueExA failed\n");
420 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
421 "RegSetValueExA failed\n");
422 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
423 "RegSetValueExA failed\n");
424 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
425 "RegSetValueExA failed\n");
426 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
427 "RegSetValueExA failed\n");
428 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
429 "RegSetValueExA failed\n");
432 static void test_enum_value(void)
436 char value
[20], data
[20];
437 WCHAR valueW
[20], dataW
[20];
438 DWORD val_count
, data_count
, type
;
439 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
440 static const WCHAR testW
[] = {'T','e','s','t',0};
441 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
443 /* create the working key for new 'Test' value */
444 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
445 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
447 /* check NULL data with zero length */
448 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
449 if (GetVersion() & 0x80000000)
450 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
452 ok( !res
, "RegSetValueExA returned %d\n", res
);
453 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
454 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
455 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
456 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
458 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
459 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
461 /* overflow both name and data */
465 strcpy( value
, "xxxxxxxxxx" );
466 strcpy( data
, "xxxxxxxxxx" );
467 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
468 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
469 ok( val_count
== 2, "val_count set to %d\n", val_count
);
470 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
471 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
472 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
473 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
479 strcpy( value
, "xxxxxxxxxx" );
480 strcpy( data
, "xxxxxxxxxx" );
481 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
482 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
483 ok( val_count
== 3, "val_count set to %d\n", val_count
);
484 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
485 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
486 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
487 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
488 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
489 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
490 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
492 /* overflow empty name */
496 strcpy( value
, "xxxxxxxxxx" );
497 strcpy( data
, "xxxxxxxxxx" );
498 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
499 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
500 ok( val_count
== 0, "val_count set to %d\n", val_count
);
501 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
502 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
503 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
504 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
505 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
506 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
512 strcpy( value
, "xxxxxxxxxx" );
513 strcpy( data
, "xxxxxxxxxx" );
514 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
515 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
516 ok( val_count
== 20, "val_count set to %d\n", val_count
);
517 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
518 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
519 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
520 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
526 strcpy( value
, "xxxxxxxxxx" );
527 strcpy( data
, "xxxxxxxxxx" );
528 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
529 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
530 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
531 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
532 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
533 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
534 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
538 SetLastError(0xdeadbeef);
539 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
540 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
542 win_skip("RegSetValueExW is not implemented\n");
545 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
547 /* overflow both name and data */
551 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
552 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
553 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
554 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
555 ok( val_count
== 2, "val_count set to %d\n", val_count
);
556 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
557 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
558 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
559 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
565 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
566 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
567 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
568 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
569 ok( val_count
== 3, "val_count set to %d\n", val_count
);
570 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
571 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
572 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
573 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
579 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
580 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
581 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
582 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
583 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
584 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
585 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
586 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
587 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
593 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
594 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
595 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
596 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
597 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
598 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
599 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
600 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
601 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
604 RegDeleteKeyA(test_key
, "");
605 RegCloseKey(test_key
);
608 static void test_query_value_ex(void)
615 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
616 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
617 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
618 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
622 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
623 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
624 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
626 size
= sizeof(buffer
);
627 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
628 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
629 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
632 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
633 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
636 static void test_get_value(void)
643 CHAR expanded
[] = "bar\\subdir1";
644 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
648 win_skip("RegGetValue not available on this platform\n");
652 /* Invalid parameter */
653 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
654 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
656 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
657 size
= type
= dw
= 0xdeadbeef;
658 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
659 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
660 ok(size
== 4, "size=%d\n", size
);
661 ok(type
== REG_DWORD
, "type=%d\n", type
);
662 ok(dw
== 0x12345678, "dw=%d\n", dw
);
664 /* Query by subkey-name */
665 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
666 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
668 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
669 size
= type
= dw
= 0xdeadbeef;
670 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
671 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
672 /* Although the function failed all values are retrieved */
673 ok(size
== 4, "size=%d\n", size
);
674 ok(type
== REG_DWORD
, "type=%d\n", type
);
675 ok(dw
== 0x12345678, "dw=%d\n", dw
);
677 /* Test RRF_ZEROONFAILURE */
678 type
= dw
= 0xdeadbeef; size
= 4;
679 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
680 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
681 /* Again all values are retrieved ... */
682 ok(size
== 4, "size=%d\n", size
);
683 ok(type
== REG_DWORD
, "type=%d\n", type
);
684 /* ... except the buffer, which is zeroed out */
685 ok(dw
== 0, "dw=%d\n", dw
);
687 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
688 type
= size
= 0xbadbeef;
689 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
690 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
691 ok(size
== 4, "size=%d\n", size
);
692 ok(type
== REG_DWORD
, "type=%d\n", type
);
694 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
695 size
= type
= dw
= 0xdeadbeef;
696 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
697 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
698 ok(size
== 4, "size=%d\n", size
);
699 ok(type
== REG_DWORD
, "type=%d\n", type
);
700 ok(dw
== 0x12345678, "dw=%d\n", dw
);
702 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
703 size
= type
= dw
= 0xdeadbeef;
704 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
705 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
706 ok(size
== 4, "size=%d\n", size
);
707 ok(type
== REG_BINARY
, "type=%d\n", type
);
708 ok(dw
== 0x12345678, "dw=%d\n", dw
);
710 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
711 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
712 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
713 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
714 ok(size
== 8, "size=%d\n", size
);
715 ok(type
== REG_BINARY
, "type=%d\n", type
);
716 ok(qw
[0] == 0x12345678 &&
717 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
719 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
720 type
= dw
= 0xdeadbeef; size
= 4;
721 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
722 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
723 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
724 ok(size
== 8, "size=%d\n", size
);
726 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
727 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
728 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
729 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
730 ok(size
== 8, "size=%d\n", size
);
731 ok(type
== REG_BINARY
, "type=%d\n", type
);
732 ok(qw
[0] == 0x12345678 &&
733 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
735 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
736 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
737 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
738 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
739 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
740 ok(type
== REG_SZ
, "type=%d\n", type
);
741 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
743 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
744 type
= 0xdeadbeef; size
= 0;
745 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
746 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
747 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
748 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
749 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
750 ok(type
== REG_SZ
, "type=%d\n", type
);
752 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
753 strcpy(buf
, sTestpath1
);
756 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
757 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
758 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
760 size
== 1, /* win2k3 */
762 ok(type
== REG_SZ
, "type=%d\n", type
);
763 ok(!strcmp(sTestpath1
, buf
) ||
765 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
767 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
768 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
769 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
770 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
771 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
772 ok(type
== REG_SZ
, "type=%d\n", type
);
773 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
775 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
777 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
778 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
779 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
780 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
781 (size
== strlen(sTestpath2
)+1),
782 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
784 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
785 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
786 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
787 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
788 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
789 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
790 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
791 ok(type
== REG_SZ
, "type=%d\n", type
);
792 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
794 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
795 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
796 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
797 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
798 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
799 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
800 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
801 ok(type
== REG_SZ
, "type=%d\n", type
);
802 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
804 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
805 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
806 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
807 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
808 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
809 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
810 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
812 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
814 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
815 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
816 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
817 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
818 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
820 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
821 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
822 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
824 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
825 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
826 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
828 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
829 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
830 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
831 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
832 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
833 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
834 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
835 ok(type
== REG_SZ
, "type=%d\n", type
);
836 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
839 static void test_reg_open_key(void)
842 HKEY hkResult
= NULL
;
843 HKEY hkPreserve
= NULL
;
844 HKEY hkRoot64
= NULL
;
845 HKEY hkRoot32
= NULL
;
847 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
849 EXPLICIT_ACCESSA access
;
851 SECURITY_DESCRIPTOR
*sd
;
853 /* successful open */
854 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
855 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
856 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
857 hkPreserve
= hkResult
;
859 /* open same key twice */
860 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
861 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
862 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
863 ok(hkResult
!= NULL
, "hkResult != NULL\n");
864 RegCloseKey(hkResult
);
866 /* open nonexistent key
867 * check that hkResult is set to NULL
869 hkResult
= hkPreserve
;
870 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
871 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
872 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
874 /* open the same nonexistent key again to make sure the key wasn't created */
875 hkResult
= hkPreserve
;
876 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
877 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
878 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
880 /* send in NULL lpSubKey
881 * check that hkResult receives the value of hKey
883 hkResult
= hkPreserve
;
884 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
885 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
886 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
888 /* send empty-string in lpSubKey */
889 hkResult
= hkPreserve
;
890 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
891 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
892 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
894 /* send in NULL lpSubKey and NULL hKey
895 * hkResult is set to NULL
897 hkResult
= hkPreserve
;
898 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
899 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
900 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
902 /* only send NULL hKey
903 * the value of hkResult remains unchanged
905 hkResult
= hkPreserve
;
906 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
907 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
908 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
909 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
910 RegCloseKey(hkResult
);
912 /* send in NULL hkResult */
913 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
914 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
916 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
917 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
919 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
920 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
922 /* beginning backslash character */
923 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
924 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
925 broken(ret
== ERROR_SUCCESS
), /* wow64 */
926 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
927 if (!ret
) RegCloseKey(hkResult
);
930 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
931 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
932 ret
== ERROR_BAD_PATHNAME
, /* NT */
933 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
934 RegCloseKey(hkResult
);
938 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
939 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
940 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
941 RegCloseKey(hkResult
);
944 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
945 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
946 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
947 RegCloseKey(hkResult
);
949 /* Try using WOW64 flags when opening a key with a DACL set to verify that
950 * the registry access check is performed correctly. Redirection isn't
951 * being tested, so the tests don't care about whether the process is
952 * running under WOW64. */
953 if (!pIsWow64Process
)
955 win_skip("WOW64 flags are not recognized\n");
959 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
960 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
961 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
962 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
964 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
965 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
966 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
967 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
969 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
970 0, 0, 0, 0, 0, 0, 0, &world_sid
);
972 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
974 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
975 access
.grfAccessMode
= SET_ACCESS
;
976 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
977 access
.Trustee
.pMultipleTrustee
= NULL
;
978 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
979 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
980 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
981 access
.Trustee
.ptstrName
= (char *)world_sid
;
983 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
984 ok(ret
== ERROR_SUCCESS
,
985 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
987 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
988 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
990 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
992 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
994 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
996 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
997 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
999 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1001 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1003 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1006 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1007 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1008 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1009 RegCloseKey(hkResult
);
1012 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1013 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1014 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1015 RegCloseKey(hkResult
);
1017 HeapFree(GetProcessHeap(), 0, sd
);
1020 RegDeleteKeyA(hkRoot64
, "");
1021 RegCloseKey(hkRoot64
);
1022 RegDeleteKeyA(hkRoot32
, "");
1023 RegCloseKey(hkRoot32
);
1026 static void test_reg_create_key(void)
1030 HKEY hkRoot64
= NULL
;
1031 HKEY hkRoot32
= NULL
;
1034 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1036 EXPLICIT_ACCESSA access
;
1038 SECURITY_DESCRIPTOR
*sd
;
1040 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1041 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1042 /* should succeed: all versions of Windows ignore the access rights
1043 * to the parent handle */
1044 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1045 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1048 RegDeleteKey(hkey2
, "");
1049 RegDeleteKey(hkey1
, "");
1053 /* test creation of volatile keys */
1054 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1055 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1056 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1057 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1058 if (!ret
) RegCloseKey( hkey2
);
1059 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1060 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1062 /* should succeed if the key already exists */
1063 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1064 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1067 RegDeleteKey(hkey2
, "");
1068 RegDeleteKey(hkey1
, "");
1072 /* beginning backslash character */
1073 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1074 if (!(GetVersion() & 0x80000000))
1075 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1077 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1078 RegDeleteKey(hkey1
, NULL
);
1082 /* WOW64 flags - open an existing key */
1084 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1085 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1086 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1090 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1091 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1092 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1095 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1096 * the registry access check is performed correctly. Redirection isn't
1097 * being tested, so the tests don't care about whether the process is
1098 * running under WOW64. */
1099 if (!pIsWow64Process
)
1101 win_skip("WOW64 flags are not recognized\n");
1105 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1106 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1107 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1108 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1110 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1111 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1112 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1113 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1115 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1116 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1118 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1120 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1121 access
.grfAccessMode
= SET_ACCESS
;
1122 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1123 access
.Trustee
.pMultipleTrustee
= NULL
;
1124 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1125 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1126 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1127 access
.Trustee
.ptstrName
= (char *)world_sid
;
1129 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1130 ok(ret
== ERROR_SUCCESS
,
1131 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1133 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1134 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1136 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1138 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1140 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1142 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1143 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1145 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1147 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1149 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1152 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1153 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1154 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1155 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1159 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1160 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1161 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1162 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1165 HeapFree(GetProcessHeap(), 0, sd
);
1168 RegDeleteKeyA(hkRoot64
, "");
1169 RegCloseKey(hkRoot64
);
1170 RegDeleteKeyA(hkRoot32
, "");
1171 RegCloseKey(hkRoot32
);
1174 static void test_reg_close_key(void)
1179 /* successfully close key
1180 * hkHandle remains changed after call to RegCloseKey
1182 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1183 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1184 ret
= RegCloseKey(hkHandle
);
1185 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1187 /* try to close the key twice */
1188 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1189 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1190 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1192 /* try to close a NULL handle */
1193 ret
= RegCloseKey(NULL
);
1194 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1195 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1197 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1198 * win98 doesn't give a new handle when the same key is opened.
1199 * Not re-opening will make some next tests fail.
1201 if (hkey_main
== hkHandle
)
1203 trace("The main handle is most likely closed, so re-opening\n");
1204 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1208 static void test_reg_delete_key(void)
1212 ret
= RegDeleteKey(hkey_main
, NULL
);
1214 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1215 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1216 * Not re-creating will make some next tests fail.
1218 if (ret
== ERROR_SUCCESS
)
1220 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1221 " re-creating the main key\n");
1225 ok(ret
== ERROR_INVALID_PARAMETER
||
1226 ret
== ERROR_ACCESS_DENIED
||
1227 ret
== ERROR_BADKEY
, /* Win95 */
1231 static void test_reg_save_key(void)
1235 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1236 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1239 static void test_reg_load_key(void)
1244 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1245 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1247 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1248 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1250 RegCloseKey(hkHandle
);
1253 static void test_reg_unload_key(void)
1257 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1258 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1260 DeleteFile("saved_key");
1261 DeleteFile("saved_key.LOG");
1264 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1266 TOKEN_PRIVILEGES tp
;
1270 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1273 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1275 CloseHandle(hToken
);
1279 tp
.PrivilegeCount
= 1;
1280 tp
.Privileges
[0].Luid
= luid
;
1283 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1285 tp
.Privileges
[0].Attributes
= 0;
1287 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1288 if (GetLastError() != ERROR_SUCCESS
)
1290 CloseHandle(hToken
);
1294 CloseHandle(hToken
);
1298 /* tests that show that RegConnectRegistry and
1299 OpenSCManager accept computer names without the
1300 \\ prefix (what MSDN says). */
1301 static void test_regconnectregistry( void)
1303 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1304 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1305 DWORD len
= sizeof(compName
) ;
1311 SetLastError(0xdeadbeef);
1312 ret
= GetComputerNameA(compName
, &len
);
1313 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1316 lstrcpyA(netwName
, "\\\\");
1317 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1319 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1321 retl
== ERROR_DLL_INIT_FAILED
||
1322 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1323 "RegConnectRegistryA failed err = %d\n", retl
);
1324 if( !retl
) RegCloseKey( hkey
);
1326 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1328 retl
== ERROR_DLL_INIT_FAILED
||
1329 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1330 "RegConnectRegistryA failed err = %d\n", retl
);
1331 if( !retl
) RegCloseKey( hkey
);
1333 SetLastError(0xdeadbeef);
1334 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1335 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1337 win_skip("OpenSCManagerA is not implemented\n");
1341 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1342 CloseServiceHandle( schnd
);
1344 SetLastError(0xdeadbeef);
1345 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1346 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1347 CloseServiceHandle( schnd
);
1351 static void test_reg_query_value(void)
1358 static const WCHAR expected
[] = {'d','a','t','a',0};
1360 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1361 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1363 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1364 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1366 /* try an invalid hkey */
1367 SetLastError(0xdeadbeef);
1369 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1370 ok(ret
== ERROR_INVALID_HANDLE
||
1371 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1372 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1373 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1374 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1376 /* try a NULL hkey */
1377 SetLastError(0xdeadbeef);
1379 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1380 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1381 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1382 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1384 /* try a NULL value */
1386 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1387 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1388 ok(size
== 5, "Expected 5, got %d\n", size
);
1390 /* try a NULL size */
1391 SetLastError(0xdeadbeef);
1393 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1394 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1395 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1396 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1398 /* try a NULL value and size */
1399 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1400 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1402 /* try a size too small */
1403 SetLastError(0xdeadbeef);
1406 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1407 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1408 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1409 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1410 ok(size
== 5, "Expected 5, got %d\n", size
);
1412 /* successfully read the value using 'subkey' */
1414 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1415 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1416 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1417 ok(size
== 5, "Expected 5, got %d\n", size
);
1419 /* successfully read the value using the subkey key */
1421 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1422 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1423 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1424 ok(size
== 5, "Expected 5, got %d\n", size
);
1426 /* unicode - try size too small */
1427 SetLastError(0xdeadbeef);
1430 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1431 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1433 win_skip("RegQueryValueW is not implemented\n");
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 - try size in WCHARS */
1442 SetLastError(0xdeadbeef);
1443 size
= sizeof(valW
) / sizeof(WCHAR
);
1444 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1445 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1446 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1447 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1448 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1450 /* unicode - successfully read the value */
1451 size
= sizeof(valW
);
1452 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1453 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1454 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1455 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1457 /* unicode - set the value without a NULL terminator */
1458 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1459 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1461 /* unicode - read the unterminated value, value is terminated for us */
1462 memset(valW
, 'a', sizeof(valW
));
1463 size
= sizeof(valW
);
1464 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1465 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1466 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1467 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1470 RegDeleteKeyA(subkey
, "");
1471 RegCloseKey(subkey
);
1474 static void test_string_termination(void)
1478 static const char string
[] = "FullString";
1481 DWORD insize
, outsize
, nsize
;
1483 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1484 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1486 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1487 insize
=sizeof(string
)-1;
1488 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1489 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1491 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1492 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1494 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1495 insize
=sizeof(string
)-2;
1496 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1497 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1499 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1500 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1501 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1503 /* RegQueryValueExA may return a string with no trailing '\0' */
1505 memset(buffer
, 0xbd, sizeof(buffer
));
1506 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1507 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1508 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1509 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1510 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1511 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1513 /* RegQueryValueExA adds a trailing '\0' if there is room */
1515 memset(buffer
, 0xbd, sizeof(buffer
));
1516 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1517 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1518 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1519 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1520 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1521 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1523 /* RegEnumValueA may return a string with no trailing '\0' */
1525 memset(buffer
, 0xbd, sizeof(buffer
));
1527 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1528 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1529 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1530 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1531 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1532 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1533 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1535 /* RegEnumValueA adds a trailing '\0' if there is room */
1537 memset(buffer
, 0xbd, sizeof(buffer
));
1539 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1540 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1541 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1542 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1543 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1544 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1545 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1547 RegDeleteKeyA(subkey
, "");
1548 RegCloseKey(subkey
);
1551 static void test_reg_delete_tree(void)
1553 CHAR buffer
[MAX_PATH
];
1554 HKEY subkey
, subkey2
;
1557 if(!pRegDeleteTreeA
) {
1558 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1562 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1563 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1564 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1565 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1566 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1567 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1568 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1569 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1570 ret
= RegCloseKey(subkey2
);
1571 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1573 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1574 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1575 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1576 "subkey2 was not deleted\n");
1578 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1579 "Default value of subkey not longer present\n");
1581 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1582 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1583 ret
= RegCloseKey(subkey2
);
1584 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1585 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1586 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1587 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1588 "subkey2 was not deleted\n");
1589 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1590 "Default value of subkey not longer present\n");
1592 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1593 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1594 ret
= RegCloseKey(subkey2
);
1595 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1596 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1597 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1598 ret
= RegCloseKey(subkey2
);
1599 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1600 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1601 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1602 ret
= pRegDeleteTreeA(subkey
, NULL
);
1603 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1604 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1605 "subkey was deleted\n");
1606 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1607 "subkey2 was not deleted\n");
1608 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1609 "subkey3 was not deleted\n");
1611 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1612 ok(ret
== ERROR_SUCCESS
,
1613 "Default value of subkey is not present\n");
1614 ok(!lstrlenA(buffer
),
1615 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1617 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1618 "Value is still present\n");
1620 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1621 ok(ret
== ERROR_FILE_NOT_FOUND
,
1622 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1625 static void test_rw_order(void)
1629 static char keyname
[] = "test_rw_order";
1631 DWORD values
, value_len
, value_name_max_len
;
1634 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1635 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1636 if(ret
!= ERROR_SUCCESS
) {
1637 skip("Couldn't create key. Skipping.\n");
1641 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1642 "RegSetValueExA for value \"A\" failed\n");
1643 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1644 "RegSetValueExA for value \"C\" failed\n");
1645 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1646 "RegSetValueExA for value \"D\" failed\n");
1647 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1648 "RegSetValueExA for value \"B\" failed\n");
1650 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1651 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1652 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1654 /* Value enumeration preserves RegSetValueEx call order */
1656 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1657 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1659 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1660 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1662 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1663 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1665 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1666 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1668 ok(!RegDeleteKey(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1671 static void test_symlinks(void)
1673 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1674 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1676 UNICODE_STRING target_str
;
1680 DWORD target_len
, type
, len
, dw
, err
;
1682 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1684 win_skip( "Can't perform symlink tests\n" );
1688 pRtlFormatCurrentUserKeyPath( &target_str
);
1690 target_len
= target_str
.Length
+ sizeof(targetW
);
1691 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1692 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1693 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1695 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1696 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1697 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1699 /* REG_SZ is not allowed */
1700 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1701 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1702 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1703 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1704 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1705 /* other values are not allowed */
1706 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1707 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1709 /* try opening the target through the link */
1711 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1712 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1714 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1715 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1718 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1719 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1722 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1723 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1725 len
= sizeof(buffer
);
1726 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1727 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1728 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1730 len
= sizeof(buffer
);
1731 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1732 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1734 /* REG_LINK can be created in non-link keys */
1735 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1736 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1737 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1738 len
= sizeof(buffer
);
1739 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1740 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1741 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1742 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1743 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1747 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1748 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1750 len
= sizeof(buffer
);
1751 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1752 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1753 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1755 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1756 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1759 /* now open the symlink itself */
1761 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1762 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx 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_OPEN_LINK
,
1770 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1771 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1772 len
= sizeof(buffer
);
1773 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1774 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1775 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1778 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1779 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1780 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1782 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1783 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1784 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1786 err
= RegDeleteKey( hkey_main
, "target" );
1787 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1789 err
= RegDeleteKey( hkey_main
, "link" );
1790 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1792 status
= pNtDeleteKey( link
);
1793 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1794 RegCloseKey( link
);
1796 HeapFree( GetProcessHeap(), 0, target
);
1797 pRtlFreeUnicodeString( &target_str
);
1800 static const DWORD ptr_size
= 8 * sizeof(void*);
1802 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1805 DWORD err
, type
, dw
, len
= sizeof(dw
);
1807 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1808 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1809 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1811 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1812 if (err
== ERROR_FILE_NOT_FOUND
)
1815 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1820 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1822 DWORD dw
= get_key_value( root
, name
, flags
);
1823 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1825 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1827 static void test_redirection(void)
1829 DWORD err
, type
, dw
, len
;
1830 HKEY key
, root32
, root64
, key32
, key64
;
1831 BOOL is_vista
= FALSE
;
1836 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
1838 skip( "Not on Wow64, no redirection\n" );
1843 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1844 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
1845 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1847 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1848 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
1849 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1851 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1852 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
1853 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1855 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1856 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
1857 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1860 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1861 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1864 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1865 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1869 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1870 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1871 ok( dw
== 32, "wrong value %u\n", dw
);
1875 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1876 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1877 ok( dw
== 64, "wrong value %u\n", dw
);
1879 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1880 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1881 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1885 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1886 /* the new (and simpler) Win7 mechanism doesn't */
1887 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1889 trace( "using Vista-style Wow6432Node handling\n" );
1892 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1893 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1894 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1895 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1896 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1897 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1901 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
1903 trace( "using Vista-style Wow6432Node handling\n" );
1906 check_key_value( key
, "Wine\\Winetest", 0, 64 );
1907 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1913 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1914 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1915 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1916 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1917 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1918 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1919 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1920 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1921 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
1922 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
1923 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1926 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1927 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1928 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1929 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1930 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1931 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1932 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1933 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1934 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1938 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
1939 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1942 /* KEY_WOW64 flags have no effect on 64-bit */
1943 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1944 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1945 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1946 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1950 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1951 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1952 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1953 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1956 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1957 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1958 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1959 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1960 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1961 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1966 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1967 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1968 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1969 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1970 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1971 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1972 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1975 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1976 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1977 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1978 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1979 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1980 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1984 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
1985 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1986 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1987 check_key_value( key
, "Winetest", 0, 32 );
1988 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1989 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
1994 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
1995 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1996 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1997 dw
= get_key_value( key
, "Winetest", 0 );
1998 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
1999 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2000 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2003 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2004 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2005 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2006 check_key_value( key
, "Winetest", 0, 32 );
2007 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2008 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2012 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2013 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2014 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2015 check_key_value( key
, "Winetest", 0, ptr_size
);
2016 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2017 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2018 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2019 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2024 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2025 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2026 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2027 dw
= get_key_value( key
, "Winetest", 0 );
2028 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2029 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2030 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2031 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2034 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2035 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2036 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2037 check_key_value( key
, "Winetest", 0, 32 );
2038 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2039 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2043 if (pRegDeleteKeyExA
)
2045 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2046 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2047 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2048 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2049 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2050 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2054 err
= RegDeleteKeyA( key32
, "" );
2055 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2056 err
= RegDeleteKeyA( key64
, "" );
2057 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2058 RegDeleteKeyA( key64
, "" );
2059 RegDeleteKeyA( root64
, "" );
2061 RegCloseKey( key32
);
2062 RegCloseKey( key64
);
2063 RegCloseKey( root32
);
2064 RegCloseKey( root64
);
2067 static void test_classesroot(void)
2069 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2071 DWORD type
= REG_SZ
;
2072 static CHAR buffer
[8];
2075 /* create a key in the user's classes */
2076 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2079 RegCloseKey( hkey
);
2081 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2082 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2083 if (res
== ERROR_ACCESS_DENIED
)
2085 skip("not enough privileges to add a user class\n");
2089 /* try to open that key in hkcr */
2090 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2091 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2092 todo_wine
ok(res
== ERROR_SUCCESS
||
2093 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2094 "test key not found in hkcr: %d\n", res
);
2097 skip("HKCR key merging not supported\n");
2099 RegCloseKey( hkey
);
2103 /* set a value in user's classes */
2104 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2105 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2107 /* try to find the value in hkcr */
2108 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2109 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2110 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2112 /* modify the value in hkcr */
2113 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2114 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2116 /* check if the value is also modified in user's classes */
2117 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2118 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2119 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2121 /* set a value in hkcr */
2122 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2123 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2125 /* try to find the value in user's classes */
2126 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2127 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2128 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2130 /* modify the value in user's classes */
2131 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2132 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2134 /* check if the value is also modified in hkcr */
2135 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2136 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2137 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2142 RegCloseKey( hkey
);
2143 RegCloseKey( hkcr
);
2145 /* create a key in the hklm classes */
2146 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2149 RegCloseKey( hklm
);
2151 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2152 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2153 if (res
== ERROR_ACCESS_DENIED
)
2155 skip("not enough privileges to add a system class\n");
2159 /* try to open that key in hkcr */
2160 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2161 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2162 ok(res
== ERROR_SUCCESS
,
2163 "test key not found in hkcr: %d\n", res
);
2167 RegCloseKey( hklm
);
2171 /* set a value in hklm classes */
2172 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2173 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2175 /* try to find the value in hkcr */
2176 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2177 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2178 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2180 /* modify the value in hkcr */
2181 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2182 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2184 /* check that the value is not modified in hklm classes */
2185 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2186 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2187 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2189 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2190 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2192 /* try to open that key in hkcr */
2193 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2194 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2195 ok(res
== ERROR_SUCCESS
,
2196 "test key not found in hkcr: %d\n", res
);
2198 /* set a value in user's classes */
2199 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2200 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2202 /* try to find the value in hkcr */
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
);
2207 /* modify the value in hklm */
2208 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2209 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2211 /* check that the value is not overwritten in hkcr or user's classes */
2212 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2213 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2214 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2215 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2216 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2217 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2219 /* modify the value in hkcr */
2220 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2221 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2223 /* check that the value is overwritten in hklm and user's classes */
2224 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2225 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2226 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2227 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2228 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2229 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2231 /* create a subkey in hklm */
2232 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2233 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2234 /* try to open that subkey in hkcr */
2235 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2236 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2238 /* set a value in hklm classes */
2239 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2240 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2242 /* try to find the value in hkcr */
2243 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2244 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2245 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2247 /* modify the value in hkcr */
2248 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2249 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2251 /* check that the value is modified in hklm classes */
2252 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2253 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2254 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2256 /* create a subkey in user's classes */
2257 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2258 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2260 /* set a value in user's classes */
2261 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2262 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2264 /* try to find the value in hkcr */
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
);
2269 /* modify the value in hklm */
2270 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2271 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2273 /* check that the value is not overwritten in hkcr or user's classes */
2274 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2275 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2276 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2277 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2278 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2279 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2281 /* modify the value in hkcr */
2282 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2283 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2285 /* check that the value is not overwritten in hklm, but in user's classes */
2286 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2287 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2288 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2289 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2290 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2291 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2293 /* new subkey in hkcr */
2294 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2295 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2296 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2297 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2299 /* try to open that new subkey in user's classes and hklm */
2300 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2301 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2303 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2304 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2306 /* check that the value is present in hklm */
2307 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2308 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2309 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2315 delete_key( hkeysub1
);
2316 delete_key( hklmsub1
);
2317 delete_key( hkcrsub1
);
2318 delete_key( hklmsub2
);
2319 delete_key( hkcrsub2
);
2320 RegCloseKey( hkey
);
2321 RegCloseKey( hklm
);
2322 RegCloseKey( hkcr
);
2323 RegCloseKey( hkeysub1
);
2324 RegCloseKey( hklmsub1
);
2325 RegCloseKey( hkcrsub1
);
2326 RegCloseKey( hklmsub2
);
2327 RegCloseKey( hkcrsub2
);
2330 static void test_deleted_key(void)
2334 DWORD val_count
, type
;
2337 /* Open the test key, then delete it while it's open */
2338 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2340 delete_key( hkey_main
);
2342 val_count
= sizeof(value
);
2344 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2345 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2347 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2348 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2350 val_count
= sizeof(value
);
2352 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2353 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2355 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2356 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2358 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2359 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2361 RegCloseKey( hkey2
);
2363 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2364 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2366 RegCloseKey( hkey2
);
2368 res
= RegFlushKey( hkey
);
2369 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2371 RegCloseKey( hkey
);
2376 static void test_delete_value(void)
2381 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2382 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2384 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2385 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2387 res
= RegDeleteValueA( hkey_main
, "test" );
2388 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2390 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2391 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2393 res
= RegDeleteValueA( hkey_main
, "test" );
2394 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2396 memset(longname
, 'a', 400);
2398 res
= RegDeleteValueA( hkey_main
, longname
);
2399 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2400 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2403 START_TEST(registry
)
2405 /* Load pointers for functions that are not available in all Windows versions */
2410 create_test_entries();
2412 test_query_value_ex();
2414 test_reg_open_key();
2415 test_reg_create_key();
2416 test_reg_close_key();
2417 test_reg_delete_key();
2418 test_reg_query_value();
2419 test_string_termination();
2424 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2425 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2426 set_privileges(SE_RESTORE_NAME
, TRUE
))
2428 test_reg_save_key();
2429 test_reg_load_key();
2430 test_reg_unload_key();
2432 set_privileges(SE_BACKUP_NAME
, FALSE
);
2433 set_privileges(SE_RESTORE_NAME
, FALSE
);
2436 test_reg_delete_tree();
2439 test_delete_value();
2442 delete_key( hkey_main
);
2444 test_regconnectregistry();