2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
31 static HKEY hkey_main
;
34 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
35 static const char * sTestpath2
= "%FOO%\\subdir1";
37 static HMODULE hadvapi32
;
38 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
39 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
43 /* Debugging functions from wine/libs/wine/debug.c */
45 /* allocate some tmp string space */
46 /* FIXME: this is not 100% thread-safe */
47 static char *get_temp_buffer( int size
)
49 static char *list
[32];
54 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
55 if ((ret
= realloc( list
[idx
], size
))) list
[idx
] = ret
;
59 static const char *wine_debugstr_an( const char *str
, int n
)
61 static const char hex
[16] = "0123456789abcdef";
65 if (!((ULONG_PTR
)str
>> 16))
67 if (!str
) return "(null)";
68 res
= get_temp_buffer( 6 );
69 sprintf( res
, "#%04x", LOWORD(str
) );
72 if (n
== -1) n
= strlen(str
);
74 size
= 10 + min( 300, n
* 4 );
75 dst
= res
= get_temp_buffer( size
);
77 while (n
-- > 0 && dst
<= res
+ size
- 9)
79 unsigned char c
= *str
++;
82 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
83 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
84 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
85 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
86 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
88 if (c
>= ' ' && c
<= 126)
94 *dst
++ = hex
[(c
>> 4) & 0x0f];
95 *dst
++ = hex
[c
& 0x0f];
110 static const char *wine_debugstr_wn( const WCHAR
*str
, int n
)
117 if (!str
) return "(null)";
118 res
= get_temp_buffer( 6 );
119 sprintf( res
, "#%04x", LOWORD(str
) );
122 if (n
== -1) n
= lstrlenW(str
);
124 size
= 12 + min( 300, n
* 5);
125 dst
= res
= get_temp_buffer( n
* 5 + 7 );
128 while (n
-- > 0 && dst
<= res
+ size
- 10)
133 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
134 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
135 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
136 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
137 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
139 if (c
>= ' ' && c
<= 126)
144 sprintf(dst
,"%04x",c
);
161 #define ADVAPI32_GET_PROC(func) \
162 p ## func = (void*)GetProcAddress(hadvapi32, #func);
165 static void InitFunctionPtrs(void)
167 hadvapi32
= GetModuleHandleA("advapi32.dll");
169 /* This function was introduced with Windows 2003 SP1 */
170 ADVAPI32_GET_PROC(RegGetValueA
)
171 ADVAPI32_GET_PROC(RegDeleteTreeA
)
174 /* delete key and all its subkeys */
175 static DWORD
delete_key( HKEY hkey
)
180 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
183 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
185 ret
= delete_key( tmp
);
190 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
191 RegDeleteKeyA( hkey
, "" );
195 static void setup_main_key(void)
197 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
199 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
202 static void test_hkey_main_Value_A(LPCSTR name
, LPCSTR string
,
205 DWORD ret
, type
, cbData
;
211 /* When successful RegQueryValueExA() leaves GLE as is,
212 * so we must reset it to detect unimplemented functions.
214 SetLastError(0xdeadbeef);
215 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
216 GLE
= GetLastError();
217 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%d\n", ret
, GLE
);
218 /* It is wrong for the Ansi version to not be implemented */
219 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
220 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
222 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
223 ok(type
== REG_SZ
, "RegQueryValueExA returned type %d\n", type
);
224 ok(cbData
== full_byte_len
|| cbData
== str_byte_len
/* Win9x */,
225 "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
227 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
228 memset(value
, 0xbd, cbData
+1);
230 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
231 GLE
= GetLastError();
232 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%d\n", ret
, GLE
);
235 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
236 ok(*value
== 0xbd || (cbData
== 1 && *value
== '\0') /* Win9x */,
237 "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
241 ok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA failed: %s/%d != %s/%d\n",
242 wine_debugstr_an((char*)value
, cbData
), cbData
,
243 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
244 ok(*(value
+cbData
) == 0xbd, "RegQueryValueExA overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
246 HeapFree(GetProcessHeap(), 0, value
);
249 static void test_hkey_main_Value_W(LPCWSTR name
, LPCWSTR string
,
252 DWORD ret
, type
, cbData
;
257 /* When successful RegQueryValueExW() leaves GLE as is,
258 * so we must reset it to detect unimplemented functions.
260 SetLastError(0xdeadbeef);
261 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
262 GLE
= GetLastError();
263 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExW failed: %d, GLE=%d\n", ret
, GLE
);
264 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
266 win_skip("RegQueryValueExW() is not implemented\n");
270 ok(type
== REG_SZ
, "RegQueryValueExW returned type %d\n", type
);
271 ok(cbData
== full_byte_len
,
272 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
274 /* Give enough space to overflow by one WCHAR */
275 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
276 memset(value
, 0xbd, cbData
+2);
278 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
279 GLE
= GetLastError();
280 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExW failed: %d, GLE=%d\n", ret
, GLE
);
283 ok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
284 wine_debugstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
285 wine_debugstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
287 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
288 ok(*(value
+cbData
) == 0xbd, "RegQueryValueExW overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
289 ok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
290 HeapFree(GetProcessHeap(), 0, value
);
293 static void test_set_value(void)
297 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
298 static const WCHAR name2W
[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
299 static const WCHAR emptyW
[] = {0};
300 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
301 static const WCHAR string2W
[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
302 static const WCHAR substring2W
[] = {'T','h','i','s',0};
304 static const char name1A
[] = "CleanSingleString";
305 static const char name2A
[] = "SomeIntraZeroedString";
306 static const char emptyA
[] = "";
307 static const char string1A
[] = "ThisNeverBreaks";
308 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
309 static const char substring2A
[] = "This";
313 /* Crashes on NT4, Windows 2000 and XP SP1 */
314 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
315 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
318 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
319 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
320 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
321 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
323 /* RegSetValueA ignores the size passed in */
324 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
325 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
326 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
327 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
329 /* stops at first null */
330 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
331 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
332 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
333 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
335 /* only REG_SZ is supported on NT*/
336 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
337 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
338 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
339 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
341 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
342 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
343 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
344 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
346 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
347 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
348 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
349 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
351 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
352 * Surprisingly enough we're supposed to get zero bytes out of it.
354 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
355 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
356 test_hkey_main_Value_A(name1A
, NULL
, 0);
357 test_hkey_main_Value_W(name1W
, NULL
, 0);
359 /* test RegSetValueExA with an empty string */
360 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
361 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
362 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
363 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
365 /* test RegSetValueExA with off-by-one size */
366 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
367 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
368 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
369 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
371 /* test RegSetValueExA with normal string */
372 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
373 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
374 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
375 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
377 /* test RegSetValueExA with intrazeroed string */
378 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
379 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
380 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
381 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
383 /* 9x doesn't support W-calls, so don't test them then */
384 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
388 /* Crashes on NT4, Windows 2000 and XP SP1 */
389 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
390 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
393 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
394 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
395 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
396 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
398 /* RegSetValueA ignores the size passed in */
399 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
400 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
401 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
402 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
404 /* stops at first null */
405 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
406 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
407 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
408 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
410 /* only REG_SZ is supported */
411 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
412 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
413 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
414 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
415 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
416 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
418 /* test RegSetValueExW with off-by-one size */
419 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
420 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
421 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
422 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
424 /* test RegSetValueExW with normal string */
425 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
426 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
427 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
428 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
430 /* test RegSetValueExW with intrazeroed string */
431 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
432 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
433 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
434 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
437 static void create_test_entries(void)
439 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
441 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
442 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
444 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
445 "RegSetValueExA failed\n");
446 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
447 "RegSetValueExA failed\n");
448 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
449 "RegSetValueExA failed\n");
450 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
451 "RegSetValueExA failed\n");
452 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
453 "RegSetValueExA failed\n");
454 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
455 "RegSetValueExA failed\n");
456 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
457 "RegSetValueExA failed\n");
460 static void test_enum_value(void)
464 char value
[20], data
[20];
465 WCHAR valueW
[20], dataW
[20];
466 DWORD val_count
, data_count
, type
;
467 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
468 static const WCHAR testW
[] = {'T','e','s','t',0};
469 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
471 /* create the working key for new 'Test' value */
472 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
473 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
475 /* check NULL data with zero length */
476 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
477 if (GetVersion() & 0x80000000)
478 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
480 ok( !res
, "RegSetValueExA returned %d\n", res
);
481 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
482 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
483 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
484 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
486 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
487 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
489 /* overflow both name and data */
493 strcpy( value
, "xxxxxxxxxx" );
494 strcpy( data
, "xxxxxxxxxx" );
495 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
496 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
497 ok( val_count
== 2, "val_count set to %d\n", val_count
);
498 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
499 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
500 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
501 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
507 strcpy( value
, "xxxxxxxxxx" );
508 strcpy( data
, "xxxxxxxxxx" );
509 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
510 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
511 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
512 ok( val_count
== 2 || val_count
== 3, "val_count set to %d\n", val_count
);
513 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
514 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
515 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
516 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
517 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
518 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ),
519 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
521 /* overflow empty name */
525 strcpy( value
, "xxxxxxxxxx" );
526 strcpy( data
, "xxxxxxxxxx" );
527 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
528 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
529 ok( val_count
== 0, "val_count set to %d\n", val_count
);
530 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
531 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
532 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
533 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
534 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ),
535 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
541 strcpy( value
, "xxxxxxxxxx" );
542 strcpy( data
, "xxxxxxxxxx" );
543 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
544 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
545 ok( val_count
== 20, "val_count set to %d\n", val_count
);
546 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
547 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
548 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
549 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
555 strcpy( value
, "xxxxxxxxxx" );
556 strcpy( data
, "xxxxxxxxxx" );
557 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
558 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
559 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
560 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
561 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
562 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
563 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
567 SetLastError(0xdeadbeef);
568 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
569 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
571 win_skip("RegSetValueExW is not implemented\n");
574 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
576 /* overflow both name and data */
580 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
581 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
582 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
583 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
584 ok( val_count
== 2, "val_count set to %d\n", val_count
);
585 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
586 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
587 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
588 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
594 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
595 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
596 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
597 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
598 ok( val_count
== 3, "val_count set to %d\n", val_count
);
599 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
600 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
601 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
602 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
608 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
609 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
610 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
611 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
612 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
613 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
614 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
615 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
616 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
622 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
623 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
624 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
625 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
626 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
627 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
628 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
629 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
630 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
633 RegDeleteKeyA(test_key
, "");
634 RegCloseKey(test_key
);
637 static void test_query_value_ex(void)
644 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
645 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
646 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
647 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
651 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
652 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
653 /* the type parameter is cleared on Win9x, but is set to a random value on
654 * NT, so don't do that test there. The size parameter is left untouched on Win9x
655 * but cleared on NT+, this can be tested on all platforms.
657 if (GetVersion() & 0x80000000)
659 ok(type
== 0, "type should have been set to 0 instead of 0x%x\n", type
);
660 ok(size
== 0xdeadbeef, "size should have been left untouched (0xdeadbeef)\n");
664 trace("test_query_value_ex: type set to: 0x%08x\n", type
);
665 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
668 size
= sizeof(buffer
);
669 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
670 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
671 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
674 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
675 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
678 static void test_get_value(void)
685 CHAR expanded
[] = "bar\\subdir1";
686 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
690 win_skip("RegGetValue not available on this platform\n");
694 /* Invalid parameter */
695 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
696 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
698 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
699 size
= type
= dw
= 0xdeadbeef;
700 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
701 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
702 ok(size
== 4, "size=%d\n", size
);
703 ok(type
== REG_DWORD
, "type=%d\n", type
);
704 ok(dw
== 0x12345678, "dw=%d\n", dw
);
706 /* Query by subkey-name */
707 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
708 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
710 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
711 size
= type
= dw
= 0xdeadbeef;
712 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
713 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
714 /* Although the function failed all values are retrieved */
715 ok(size
== 4, "size=%d\n", size
);
716 ok(type
== REG_DWORD
, "type=%d\n", type
);
717 ok(dw
== 0x12345678, "dw=%d\n", dw
);
719 /* Test RRF_ZEROONFAILURE */
720 type
= dw
= 0xdeadbeef; size
= 4;
721 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
722 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
723 /* Again all values are retrieved ... */
724 ok(size
== 4, "size=%d\n", size
);
725 ok(type
== REG_DWORD
, "type=%d\n", type
);
726 /* ... except the buffer, which is zeroed out */
727 ok(dw
== 0, "dw=%d\n", dw
);
729 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
730 type
= size
= 0xbadbeef;
731 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
732 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
733 ok(size
== 4, "size=%d\n", size
);
734 ok(type
== REG_DWORD
, "type=%d\n", type
);
736 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
737 size
= type
= dw
= 0xdeadbeef;
738 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
739 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
740 ok(size
== 4, "size=%d\n", size
);
741 ok(type
== REG_DWORD
, "type=%d\n", type
);
742 ok(dw
== 0x12345678, "dw=%d\n", dw
);
744 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
745 size
= type
= dw
= 0xdeadbeef;
746 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
747 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
748 ok(size
== 4, "size=%d\n", size
);
749 ok(type
== REG_BINARY
, "type=%d\n", type
);
750 ok(dw
== 0x12345678, "dw=%d\n", dw
);
752 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
753 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
754 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
755 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
756 ok(size
== 8, "size=%d\n", size
);
757 ok(type
== REG_BINARY
, "type=%d\n", type
);
758 ok(qw
[0] == 0x12345678 &&
759 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
761 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
762 type
= dw
= 0xdeadbeef; size
= 4;
763 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
764 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
765 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
766 ok(size
== 8, "size=%d\n", size
);
768 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
769 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
770 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
771 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
772 ok(size
== 8, "size=%d\n", size
);
773 ok(type
== REG_BINARY
, "type=%d\n", type
);
774 ok(qw
[0] == 0x12345678 &&
775 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
777 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
778 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
779 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
780 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
781 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
782 ok(type
== REG_SZ
, "type=%d\n", type
);
783 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
785 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
786 type
= 0xdeadbeef; size
= 0;
787 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
788 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
789 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
790 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
791 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
792 ok(type
== REG_SZ
, "type=%d\n", type
);
794 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
795 strcpy(buf
, sTestpath1
);
798 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
799 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
800 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
802 size
== 1, /* win2k3 */
804 ok(type
== REG_SZ
, "type=%d\n", type
);
805 ok(!strcmp(sTestpath1
, buf
) ||
807 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
809 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
810 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
811 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
812 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
813 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
814 ok(type
== REG_SZ
, "type=%d\n", type
);
815 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
817 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
819 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
820 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
821 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
822 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
823 (size
== strlen(sTestpath2
)+1),
824 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
826 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
827 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
828 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
829 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
830 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
831 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
832 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
833 ok(type
== REG_SZ
, "type=%d\n", type
);
834 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
836 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
837 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
838 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
839 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
840 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
841 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
842 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
843 ok(type
== REG_SZ
, "type=%d\n", type
);
844 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
846 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
847 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
848 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
849 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
850 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
851 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
852 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
854 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
856 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
857 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
858 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
859 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
860 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
862 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
863 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
864 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
866 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
867 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
868 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
870 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
871 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
872 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
873 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
874 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
875 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
876 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
877 ok(type
== REG_SZ
, "type=%d\n", type
);
878 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
881 static void test_reg_open_key(void)
884 HKEY hkResult
= NULL
;
885 HKEY hkPreserve
= NULL
;
887 /* successful open */
888 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
889 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
890 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
891 hkPreserve
= hkResult
;
893 /* these tests fail on Win9x, but we want to be compatible with NT, so
894 * run them if we can */
895 if (!(GetVersion() & 0x80000000))
897 /* open same key twice */
898 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
899 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
900 ok(hkResult
!= hkPreserve
, "epxected hkResult != hkPreserve\n");
901 ok(hkResult
!= NULL
, "hkResult != NULL\n");
902 RegCloseKey(hkResult
);
904 /* open nonexistent key
905 * check that hkResult is set to NULL
907 hkResult
= hkPreserve
;
908 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
909 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
910 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
912 /* open the same nonexistent key again to make sure the key wasn't created */
913 hkResult
= hkPreserve
;
914 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
915 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
916 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
918 /* send in NULL lpSubKey
919 * check that hkResult receives the value of hKey
921 hkResult
= hkPreserve
;
922 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
923 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
924 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
926 /* send empty-string in lpSubKey */
927 hkResult
= hkPreserve
;
928 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
929 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
930 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
932 /* send in NULL lpSubKey and NULL hKey
933 * hkResult is set to NULL
935 hkResult
= hkPreserve
;
936 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
937 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
938 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
941 /* only send NULL hKey
942 * the value of hkResult remains unchanged
944 hkResult
= hkPreserve
;
945 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
946 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
947 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
948 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
949 RegCloseKey(hkResult
);
951 /* send in NULL hkResult */
952 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
953 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
955 /* beginning backslash character */
956 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
957 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
958 ret
== ERROR_FILE_NOT_FOUND
/* Win9x,ME */
959 , "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
963 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
964 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
965 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
966 RegCloseKey(hkResult
);
969 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
970 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
971 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
972 RegCloseKey(hkResult
);
975 static void test_reg_create_key(void)
979 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
980 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
981 /* should succeed: all versions of Windows ignore the access rights
982 * to the parent handle */
983 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
984 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
987 RegDeleteKey(hkey2
, "");
988 RegDeleteKey(hkey1
, "");
990 /* beginning backslash character */
991 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
992 if (!(GetVersion() & 0x80000000))
993 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
995 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
996 RegDeleteKey(hkey1
, NULL
);
999 /* WOW64 flags - open an existing key */
1001 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1002 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1003 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1007 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1008 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1009 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1013 static void test_reg_close_key(void)
1018 /* successfully close key
1019 * hkHandle remains changed after call to RegCloseKey
1021 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1022 ret
= RegCloseKey(hkHandle
);
1023 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1025 /* try to close the key twice */
1026 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1027 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1028 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1030 /* try to close a NULL handle */
1031 ret
= RegCloseKey(NULL
);
1032 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1033 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1035 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1036 * win98 doesn't give a new handle when the same key is opened.
1037 * Not re-opening will make some next tests fail.
1039 if (hkey_main
== hkHandle
)
1041 trace("The main handle is most likely closed, so re-opening\n");
1042 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1046 static void test_reg_delete_key(void)
1050 ret
= RegDeleteKey(hkey_main
, NULL
);
1052 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1053 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1054 * Not re-creating will make some next tests fail.
1056 if (ret
== ERROR_SUCCESS
)
1058 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1059 " re-creating the main key\n");
1063 ok(ret
== ERROR_INVALID_PARAMETER
||
1064 ret
== ERROR_ACCESS_DENIED
||
1065 ret
== ERROR_BADKEY
, /* Win95 */
1069 static void test_reg_save_key(void)
1073 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1074 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1077 static void test_reg_load_key(void)
1082 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1083 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1085 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1086 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1088 RegCloseKey(hkHandle
);
1091 static void test_reg_unload_key(void)
1095 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1096 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1098 DeleteFile("saved_key");
1099 DeleteFile("saved_key.LOG");
1102 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1104 TOKEN_PRIVILEGES tp
;
1108 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1111 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1113 CloseHandle(hToken
);
1117 tp
.PrivilegeCount
= 1;
1118 tp
.Privileges
[0].Luid
= luid
;
1121 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1123 tp
.Privileges
[0].Attributes
= 0;
1125 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1126 if (GetLastError() != ERROR_SUCCESS
)
1128 CloseHandle(hToken
);
1132 CloseHandle(hToken
);
1136 /* tests that show that RegConnectRegistry and
1137 OpenSCManager accept computer names without the
1138 \\ prefix (what MSDN says). */
1139 static void test_regconnectregistry( void)
1141 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1142 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1143 DWORD len
= sizeof(compName
) ;
1149 SetLastError(0xdeadbeef);
1150 ret
= GetComputerNameA(compName
, &len
);
1151 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1154 lstrcpyA(netwName
, "\\\\");
1155 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1157 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1159 retl
== ERROR_DLL_INIT_FAILED
||
1160 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1161 "RegConnectRegistryA failed err = %d\n", retl
);
1162 if( !retl
) RegCloseKey( hkey
);
1164 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1166 retl
== ERROR_DLL_INIT_FAILED
||
1167 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1168 "RegConnectRegistryA failed err = %d\n", retl
);
1169 if( !retl
) RegCloseKey( hkey
);
1171 SetLastError(0xdeadbeef);
1172 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1173 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1175 win_skip("OpenSCManagerA is not implemented\n");
1179 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1180 CloseServiceHandle( schnd
);
1182 SetLastError(0xdeadbeef);
1183 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1184 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1185 CloseServiceHandle( schnd
);
1189 static void test_reg_query_value(void)
1196 static const WCHAR expected
[] = {'d','a','t','a',0};
1198 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1199 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1201 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1202 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1204 /* try an invalid hkey */
1205 SetLastError(0xdeadbeef);
1207 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1208 ok(ret
== ERROR_INVALID_HANDLE
||
1209 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1210 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1211 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1212 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1214 /* try a NULL hkey */
1215 SetLastError(0xdeadbeef);
1217 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1218 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1219 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1220 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1222 /* try a NULL value */
1224 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1225 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1226 ok(size
== 5, "Expected 5, got %d\n", size
);
1228 /* try a NULL size */
1229 SetLastError(0xdeadbeef);
1231 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1232 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1233 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1234 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1236 /* try a NULL value and size */
1237 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1238 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1240 /* try a size too small */
1241 SetLastError(0xdeadbeef);
1244 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1245 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1246 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1247 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1248 ok(size
== 5, "Expected 5, got %d\n", size
);
1250 /* successfully read the value using 'subkey' */
1252 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1253 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1254 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1255 ok(size
== 5, "Expected 5, got %d\n", size
);
1257 /* successfully read the value using the subkey key */
1259 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1260 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1261 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1262 ok(size
== 5, "Expected 5, got %d\n", size
);
1264 /* unicode - try size too small */
1265 SetLastError(0xdeadbeef);
1268 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1269 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1271 win_skip("RegQueryValueW is not implemented\n");
1274 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1275 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1276 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1277 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1279 /* unicode - try size in WCHARS */
1280 SetLastError(0xdeadbeef);
1281 size
= sizeof(valW
) / sizeof(WCHAR
);
1282 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1283 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1284 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1285 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1286 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1288 /* unicode - successfully read the value */
1289 size
= sizeof(valW
);
1290 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1291 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1292 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1293 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1295 /* unicode - set the value without a NULL terminator */
1296 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1297 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1299 /* unicode - read the unterminated value, value is terminated for us */
1300 memset(valW
, 'a', sizeof(valW
));
1301 size
= sizeof(valW
);
1302 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1303 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1304 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1305 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1308 RegDeleteKeyA(subkey
, "");
1309 RegCloseKey(subkey
);
1312 static void test_reg_delete_tree(void)
1314 CHAR buffer
[MAX_PATH
];
1315 HKEY subkey
, subkey2
;
1318 if(!pRegDeleteTreeA
) {
1319 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1323 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1324 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1325 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1326 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1327 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1328 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1329 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1330 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1331 ret
= RegCloseKey(subkey2
);
1332 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1334 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1335 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1336 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1337 "subkey2 was not deleted\n");
1339 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1340 "Default value of subkey not longer present\n");
1342 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1343 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1344 ret
= RegCloseKey(subkey2
);
1345 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1346 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1347 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1348 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1349 "subkey2 was not deleted\n");
1350 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1351 "Default value of subkey not longer present\n");
1353 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1354 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1355 ret
= RegCloseKey(subkey2
);
1356 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1357 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1358 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1359 ret
= RegCloseKey(subkey2
);
1360 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1361 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1362 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1363 ret
= pRegDeleteTreeA(subkey
, NULL
);
1364 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1365 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1366 "subkey was deleted\n");
1367 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1368 "subkey2 was not deleted\n");
1369 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1370 "subkey3 was not deleted\n");
1372 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1373 ok(ret
== ERROR_SUCCESS
,
1374 "Default value of subkey is not present\n");
1375 ok(!lstrlenA(buffer
),
1376 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1378 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1379 "Value is still present\n");
1381 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1382 ok(ret
== ERROR_FILE_NOT_FOUND
,
1383 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1386 START_TEST(registry
)
1388 /* Load pointers for functions that are not available in all Windows versions */
1393 create_test_entries();
1395 test_query_value_ex();
1397 test_reg_open_key();
1398 test_reg_create_key();
1399 test_reg_close_key();
1400 test_reg_delete_key();
1401 test_reg_query_value();
1403 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
1404 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
1405 set_privileges(SE_RESTORE_NAME
, TRUE
))
1407 test_reg_save_key();
1408 test_reg_load_key();
1409 test_reg_unload_key();
1411 set_privileges(SE_BACKUP_NAME
, FALSE
);
1412 set_privileges(SE_RESTORE_NAME
, FALSE
);
1415 test_reg_delete_tree();
1418 delete_key( hkey_main
);
1420 test_regconnectregistry();