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]));
56 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
58 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
59 if (ret
) list
[idx
] = ret
;
63 static const char *wine_debugstr_an( const char *str
, int n
)
65 static const char hex
[16] = "0123456789abcdef";
69 if (!((ULONG_PTR
)str
>> 16))
71 if (!str
) return "(null)";
72 res
= get_temp_buffer( 6 );
73 sprintf( res
, "#%04x", LOWORD(str
) );
76 if (n
== -1) n
= strlen(str
);
78 size
= 10 + min( 300, n
* 4 );
79 dst
= res
= get_temp_buffer( size
);
81 while (n
-- > 0 && dst
<= res
+ size
- 9)
83 unsigned char c
= *str
++;
86 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
87 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
88 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
89 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
90 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
92 if (c
>= ' ' && c
<= 126)
98 *dst
++ = hex
[(c
>> 4) & 0x0f];
99 *dst
++ = hex
[c
& 0x0f];
114 static const char *wine_debugstr_wn( const WCHAR
*str
, int n
)
121 if (!str
) return "(null)";
122 res
= get_temp_buffer( 6 );
123 sprintf( res
, "#%04x", LOWORD(str
) );
126 if (n
== -1) n
= lstrlenW(str
);
128 size
= 12 + min( 300, n
* 5);
129 dst
= res
= get_temp_buffer( n
* 5 + 7 );
132 while (n
-- > 0 && dst
<= res
+ size
- 10)
137 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
138 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
139 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
140 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
141 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
143 if (c
>= ' ' && c
<= 126)
148 sprintf(dst
,"%04x",c
);
165 #define ADVAPI32_GET_PROC(func) \
166 p ## func = (void*)GetProcAddress(hadvapi32, #func);
169 static void InitFunctionPtrs(void)
171 hadvapi32
= GetModuleHandleA("advapi32.dll");
173 /* This function was introduced with Windows 2003 SP1 */
174 ADVAPI32_GET_PROC(RegGetValueA
)
175 ADVAPI32_GET_PROC(RegDeleteTreeA
)
178 /* delete key and all its subkeys */
179 static DWORD
delete_key( HKEY hkey
)
184 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
187 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
189 ret
= delete_key( tmp
);
194 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
195 RegDeleteKeyA( hkey
, "" );
199 static void setup_main_key(void)
201 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
203 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
206 #define lok ok_(__FILE__, line)
207 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
208 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
211 DWORD ret
, type
, cbData
;
217 /* When successful RegQueryValueExA() leaves GLE as is,
218 * so we must reset it to detect unimplemented functions.
220 SetLastError(0xdeadbeef);
221 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
222 GLE
= GetLastError();
223 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
224 /* It is wrong for the Ansi version to not be implemented */
225 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
226 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
228 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
229 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
230 lok(cbData
== full_byte_len
|| cbData
== str_byte_len
/* Win9x */,
231 "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
233 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
234 memset(value
, 0xbd, cbData
+1);
236 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
237 GLE
= GetLastError();
238 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
241 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
242 lok(*value
== 0xbd || (cbData
== 1 && *value
== '\0') /* Win9x */,
243 "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
247 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
248 wine_debugstr_an((char*)value
, cbData
), cbData
,
249 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
250 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
252 HeapFree(GetProcessHeap(), 0, value
);
255 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
256 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
259 DWORD ret
, type
, cbData
;
264 /* When successful RegQueryValueExW() leaves GLE as is,
265 * so we must reset it to detect unimplemented functions.
267 SetLastError(0xdeadbeef);
268 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
269 GLE
= GetLastError();
270 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
271 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
273 win_skip("RegQueryValueExW() is not implemented\n");
277 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
278 lok(cbData
== full_byte_len
,
279 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
281 /* Give enough space to overflow by one WCHAR */
282 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
283 memset(value
, 0xbd, cbData
+2);
285 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
286 GLE
= GetLastError();
287 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
290 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
291 wine_debugstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
292 wine_debugstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
294 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
295 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
296 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
297 HeapFree(GetProcessHeap(), 0, value
);
300 static void test_set_value(void)
304 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
305 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};
306 static const WCHAR emptyW
[] = {0};
307 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
308 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};
309 static const WCHAR substring2W
[] = {'T','h','i','s',0};
311 static const char name1A
[] = "CleanSingleString";
312 static const char name2A
[] = "SomeIntraZeroedString";
313 static const char emptyA
[] = "";
314 static const char string1A
[] = "ThisNeverBreaks";
315 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
316 static const char substring2A
[] = "This";
320 /* Crashes on NT4, Windows 2000 and XP SP1 */
321 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
322 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
325 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
326 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
327 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
328 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
330 /* RegSetValueA ignores the size passed in */
331 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
332 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
333 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
334 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
336 /* stops at first null */
337 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
338 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
339 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
340 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
342 /* only REG_SZ is supported on NT*/
343 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
344 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
345 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
346 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
348 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
349 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
350 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
351 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
353 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
354 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
355 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
356 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
358 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
359 * Surprisingly enough we're supposed to get zero bytes out of it.
361 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
362 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
363 test_hkey_main_Value_A(name1A
, NULL
, 0);
364 test_hkey_main_Value_W(name1W
, NULL
, 0);
366 /* test RegSetValueExA with an empty string */
367 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
368 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
369 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
370 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
372 /* test RegSetValueExA with off-by-one size */
373 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
374 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
375 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
376 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
378 /* test RegSetValueExA with normal string */
379 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
380 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
381 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
382 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
384 /* test RegSetValueExA with intrazeroed string */
385 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
386 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
387 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
388 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
390 /* 9x doesn't support W-calls, so don't test them then */
391 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
395 /* Crashes on NT4, Windows 2000 and XP SP1 */
396 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
397 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
400 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
401 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
402 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
403 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
405 /* RegSetValueA ignores the size passed in */
406 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
407 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
408 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
409 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
411 /* stops at first null */
412 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
413 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
414 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
415 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
417 /* only REG_SZ is supported */
418 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
419 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
420 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
421 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
422 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
423 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
425 /* test RegSetValueExW with off-by-one size */
426 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
427 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
428 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
429 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
431 /* test RegSetValueExW with normal string */
432 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
433 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
434 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
435 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
437 /* test RegSetValueExW with intrazeroed string */
438 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
439 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
440 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
441 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
444 static void create_test_entries(void)
446 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
448 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
449 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
451 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
452 "RegSetValueExA failed\n");
453 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
454 "RegSetValueExA failed\n");
455 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
456 "RegSetValueExA failed\n");
457 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
458 "RegSetValueExA failed\n");
459 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
460 "RegSetValueExA failed\n");
461 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
462 "RegSetValueExA failed\n");
463 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
464 "RegSetValueExA failed\n");
467 static void test_enum_value(void)
471 char value
[20], data
[20];
472 WCHAR valueW
[20], dataW
[20];
473 DWORD val_count
, data_count
, type
;
474 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
475 static const WCHAR testW
[] = {'T','e','s','t',0};
476 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
478 /* create the working key for new 'Test' value */
479 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
480 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
482 /* check NULL data with zero length */
483 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
484 if (GetVersion() & 0x80000000)
485 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
487 ok( !res
, "RegSetValueExA returned %d\n", res
);
488 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
489 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
490 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
491 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
493 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
494 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
496 /* overflow both name and data */
500 strcpy( value
, "xxxxxxxxxx" );
501 strcpy( data
, "xxxxxxxxxx" );
502 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
503 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
504 ok( val_count
== 2, "val_count set to %d\n", val_count
);
505 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
506 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
507 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
508 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
514 strcpy( value
, "xxxxxxxxxx" );
515 strcpy( data
, "xxxxxxxxxx" );
516 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
517 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
518 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
519 ok( val_count
== 2 || val_count
== 3, "val_count set to %d\n", val_count
);
520 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
521 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
522 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
523 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
524 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
525 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ),
526 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
528 /* overflow empty name */
532 strcpy( value
, "xxxxxxxxxx" );
533 strcpy( data
, "xxxxxxxxxx" );
534 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
535 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
536 ok( val_count
== 0, "val_count set to %d\n", val_count
);
537 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
538 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
539 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
540 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
541 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ),
542 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
548 strcpy( value
, "xxxxxxxxxx" );
549 strcpy( data
, "xxxxxxxxxx" );
550 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
551 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
552 ok( val_count
== 20, "val_count set to %d\n", val_count
);
553 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
554 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
555 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
556 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
562 strcpy( value
, "xxxxxxxxxx" );
563 strcpy( data
, "xxxxxxxxxx" );
564 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
565 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
566 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
567 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
568 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
569 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
570 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
574 SetLastError(0xdeadbeef);
575 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
576 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
578 win_skip("RegSetValueExW is not implemented\n");
581 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
583 /* overflow both name and data */
587 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
588 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
589 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
590 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
591 ok( val_count
== 2, "val_count set to %d\n", val_count
);
592 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
593 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
594 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
595 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
601 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
602 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
603 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
604 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
605 ok( val_count
== 3, "val_count set to %d\n", val_count
);
606 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
607 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
608 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
609 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
615 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
616 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
617 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
618 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
619 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
620 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
621 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
622 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
623 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
629 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
630 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
631 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
632 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
633 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
634 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
635 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
636 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
637 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
640 RegDeleteKeyA(test_key
, "");
641 RegCloseKey(test_key
);
644 static void test_query_value_ex(void)
651 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
652 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
653 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
654 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
658 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
659 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
660 /* the type parameter is cleared on Win9x, but is set to a random value on
661 * NT, so don't do that test there. The size parameter is left untouched on Win9x
662 * but cleared on NT+, this can be tested on all platforms.
664 if (GetVersion() & 0x80000000)
666 ok(type
== 0, "type should have been set to 0 instead of 0x%x\n", type
);
667 ok(size
== 0xdeadbeef, "size should have been left untouched (0xdeadbeef)\n");
671 trace("test_query_value_ex: type set to: 0x%08x\n", type
);
672 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
675 size
= sizeof(buffer
);
676 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
677 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
678 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
681 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
682 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
685 static void test_get_value(void)
692 CHAR expanded
[] = "bar\\subdir1";
693 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
697 win_skip("RegGetValue not available on this platform\n");
701 /* Invalid parameter */
702 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
703 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
705 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
706 size
= type
= dw
= 0xdeadbeef;
707 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
708 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
709 ok(size
== 4, "size=%d\n", size
);
710 ok(type
== REG_DWORD
, "type=%d\n", type
);
711 ok(dw
== 0x12345678, "dw=%d\n", dw
);
713 /* Query by subkey-name */
714 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
715 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
717 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
718 size
= type
= dw
= 0xdeadbeef;
719 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
720 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
721 /* Although the function failed all values are retrieved */
722 ok(size
== 4, "size=%d\n", size
);
723 ok(type
== REG_DWORD
, "type=%d\n", type
);
724 ok(dw
== 0x12345678, "dw=%d\n", dw
);
726 /* Test RRF_ZEROONFAILURE */
727 type
= dw
= 0xdeadbeef; size
= 4;
728 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
729 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
730 /* Again all values are retrieved ... */
731 ok(size
== 4, "size=%d\n", size
);
732 ok(type
== REG_DWORD
, "type=%d\n", type
);
733 /* ... except the buffer, which is zeroed out */
734 ok(dw
== 0, "dw=%d\n", dw
);
736 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
737 type
= size
= 0xbadbeef;
738 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
739 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
740 ok(size
== 4, "size=%d\n", size
);
741 ok(type
== REG_DWORD
, "type=%d\n", type
);
743 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
744 size
= type
= dw
= 0xdeadbeef;
745 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
746 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
747 ok(size
== 4, "size=%d\n", size
);
748 ok(type
== REG_DWORD
, "type=%d\n", type
);
749 ok(dw
== 0x12345678, "dw=%d\n", dw
);
751 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
752 size
= type
= dw
= 0xdeadbeef;
753 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
754 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
755 ok(size
== 4, "size=%d\n", size
);
756 ok(type
== REG_BINARY
, "type=%d\n", type
);
757 ok(dw
== 0x12345678, "dw=%d\n", dw
);
759 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
760 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
761 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
762 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
763 ok(size
== 8, "size=%d\n", size
);
764 ok(type
== REG_BINARY
, "type=%d\n", type
);
765 ok(qw
[0] == 0x12345678 &&
766 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
768 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
769 type
= dw
= 0xdeadbeef; size
= 4;
770 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
771 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
772 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
773 ok(size
== 8, "size=%d\n", size
);
775 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
776 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
777 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
778 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
779 ok(size
== 8, "size=%d\n", size
);
780 ok(type
== REG_BINARY
, "type=%d\n", type
);
781 ok(qw
[0] == 0x12345678 &&
782 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
784 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
785 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
786 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
787 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
788 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
789 ok(type
== REG_SZ
, "type=%d\n", type
);
790 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
792 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
793 type
= 0xdeadbeef; size
= 0;
794 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
795 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
796 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
797 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
798 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
799 ok(type
== REG_SZ
, "type=%d\n", type
);
801 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
802 strcpy(buf
, sTestpath1
);
805 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
806 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
807 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
809 size
== 1, /* win2k3 */
811 ok(type
== REG_SZ
, "type=%d\n", type
);
812 ok(!strcmp(sTestpath1
, buf
) ||
814 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
816 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
817 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
818 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
819 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
820 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
821 ok(type
== REG_SZ
, "type=%d\n", type
);
822 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
824 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
826 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
827 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
828 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
829 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
830 (size
== strlen(sTestpath2
)+1),
831 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
833 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
834 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
835 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
836 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
837 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
838 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
839 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
840 ok(type
== REG_SZ
, "type=%d\n", type
);
841 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
843 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
844 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
845 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
846 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
847 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
848 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
849 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
850 ok(type
== REG_SZ
, "type=%d\n", type
);
851 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
853 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
854 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
855 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
856 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
857 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
858 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
859 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
861 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
863 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
864 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
865 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
866 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
867 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
869 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
870 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
871 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
873 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
874 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
875 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
877 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
878 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
879 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
880 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
881 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
882 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
883 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
884 ok(type
== REG_SZ
, "type=%d\n", type
);
885 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
888 static void test_reg_open_key(void)
891 HKEY hkResult
= NULL
;
892 HKEY hkPreserve
= NULL
;
894 /* successful open */
895 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
896 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
897 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
898 hkPreserve
= hkResult
;
900 /* these tests fail on Win9x, but we want to be compatible with NT, so
901 * run them if we can */
902 if (!(GetVersion() & 0x80000000))
904 /* open same key twice */
905 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
906 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
907 ok(hkResult
!= hkPreserve
, "epxected hkResult != hkPreserve\n");
908 ok(hkResult
!= NULL
, "hkResult != NULL\n");
909 RegCloseKey(hkResult
);
911 /* open nonexistent key
912 * check that hkResult is set to NULL
914 hkResult
= hkPreserve
;
915 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
916 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
917 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
919 /* open the same nonexistent key again to make sure the key wasn't created */
920 hkResult
= hkPreserve
;
921 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
922 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
923 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
925 /* send in NULL lpSubKey
926 * check that hkResult receives the value of hKey
928 hkResult
= hkPreserve
;
929 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
930 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
931 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
933 /* send empty-string in lpSubKey */
934 hkResult
= hkPreserve
;
935 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
936 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
937 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
939 /* send in NULL lpSubKey and NULL hKey
940 * hkResult is set to NULL
942 hkResult
= hkPreserve
;
943 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
944 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
945 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
948 /* only send NULL hKey
949 * the value of hkResult remains unchanged
951 hkResult
= hkPreserve
;
952 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
953 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
954 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
955 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
956 RegCloseKey(hkResult
);
958 /* send in NULL hkResult */
959 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
960 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
962 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
963 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
965 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
966 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
968 /* beginning backslash character */
969 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
970 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
971 ret
== ERROR_FILE_NOT_FOUND
/* Win9x,ME */
972 , "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
975 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
976 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
977 ret
== ERROR_BAD_PATHNAME
|| /* NT */
978 ret
== ERROR_FILE_NOT_FOUND
/* Win9x,ME */
979 , "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
980 RegCloseKey(hkResult
);
984 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
985 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
986 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
987 RegCloseKey(hkResult
);
990 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
991 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
992 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
993 RegCloseKey(hkResult
);
996 static void test_reg_create_key(void)
1000 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1001 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1002 /* should succeed: all versions of Windows ignore the access rights
1003 * to the parent handle */
1004 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1005 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1008 RegDeleteKey(hkey2
, "");
1009 RegDeleteKey(hkey1
, "");
1011 /* beginning backslash character */
1012 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1013 if (!(GetVersion() & 0x80000000))
1014 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1016 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1017 RegDeleteKey(hkey1
, NULL
);
1020 /* WOW64 flags - open an existing key */
1022 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1023 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1024 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1028 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1029 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1030 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1034 static void test_reg_close_key(void)
1039 /* successfully close key
1040 * hkHandle remains changed after call to RegCloseKey
1042 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1043 ret
= RegCloseKey(hkHandle
);
1044 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1046 /* try to close the key twice */
1047 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1048 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1049 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1051 /* try to close a NULL handle */
1052 ret
= RegCloseKey(NULL
);
1053 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1054 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1056 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1057 * win98 doesn't give a new handle when the same key is opened.
1058 * Not re-opening will make some next tests fail.
1060 if (hkey_main
== hkHandle
)
1062 trace("The main handle is most likely closed, so re-opening\n");
1063 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1067 static void test_reg_delete_key(void)
1071 ret
= RegDeleteKey(hkey_main
, NULL
);
1073 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1074 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1075 * Not re-creating will make some next tests fail.
1077 if (ret
== ERROR_SUCCESS
)
1079 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1080 " re-creating the main key\n");
1084 ok(ret
== ERROR_INVALID_PARAMETER
||
1085 ret
== ERROR_ACCESS_DENIED
||
1086 ret
== ERROR_BADKEY
, /* Win95 */
1090 static void test_reg_save_key(void)
1094 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1095 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1098 static void test_reg_load_key(void)
1103 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1104 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1106 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1107 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1109 RegCloseKey(hkHandle
);
1112 static void test_reg_unload_key(void)
1116 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1117 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1119 DeleteFile("saved_key");
1120 DeleteFile("saved_key.LOG");
1123 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1125 TOKEN_PRIVILEGES tp
;
1129 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1132 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1134 CloseHandle(hToken
);
1138 tp
.PrivilegeCount
= 1;
1139 tp
.Privileges
[0].Luid
= luid
;
1142 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1144 tp
.Privileges
[0].Attributes
= 0;
1146 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1147 if (GetLastError() != ERROR_SUCCESS
)
1149 CloseHandle(hToken
);
1153 CloseHandle(hToken
);
1157 /* tests that show that RegConnectRegistry and
1158 OpenSCManager accept computer names without the
1159 \\ prefix (what MSDN says). */
1160 static void test_regconnectregistry( void)
1162 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1163 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1164 DWORD len
= sizeof(compName
) ;
1170 SetLastError(0xdeadbeef);
1171 ret
= GetComputerNameA(compName
, &len
);
1172 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1175 lstrcpyA(netwName
, "\\\\");
1176 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1178 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1180 retl
== ERROR_DLL_INIT_FAILED
||
1181 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1182 "RegConnectRegistryA failed err = %d\n", retl
);
1183 if( !retl
) RegCloseKey( hkey
);
1185 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1187 retl
== ERROR_DLL_INIT_FAILED
||
1188 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1189 "RegConnectRegistryA failed err = %d\n", retl
);
1190 if( !retl
) RegCloseKey( hkey
);
1192 SetLastError(0xdeadbeef);
1193 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1194 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1196 win_skip("OpenSCManagerA is not implemented\n");
1200 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1201 CloseServiceHandle( schnd
);
1203 SetLastError(0xdeadbeef);
1204 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1205 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1206 CloseServiceHandle( schnd
);
1210 static void test_reg_query_value(void)
1217 static const WCHAR expected
[] = {'d','a','t','a',0};
1219 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1220 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1222 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1223 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1225 /* try an invalid hkey */
1226 SetLastError(0xdeadbeef);
1228 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1229 ok(ret
== ERROR_INVALID_HANDLE
||
1230 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1231 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1232 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1233 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1235 /* try a NULL hkey */
1236 SetLastError(0xdeadbeef);
1238 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1239 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1240 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1241 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1243 /* try a NULL value */
1245 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1246 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1247 ok(size
== 5, "Expected 5, got %d\n", size
);
1249 /* try a NULL size */
1250 SetLastError(0xdeadbeef);
1252 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1253 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1254 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1255 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1257 /* try a NULL value and size */
1258 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1259 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1261 /* try a size too small */
1262 SetLastError(0xdeadbeef);
1265 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1266 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1267 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1268 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1269 ok(size
== 5, "Expected 5, got %d\n", size
);
1271 /* successfully read the value using 'subkey' */
1273 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1274 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1275 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1276 ok(size
== 5, "Expected 5, got %d\n", size
);
1278 /* successfully read the value using the subkey key */
1280 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1281 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1282 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1283 ok(size
== 5, "Expected 5, got %d\n", size
);
1285 /* unicode - try size too small */
1286 SetLastError(0xdeadbeef);
1289 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1290 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1292 win_skip("RegQueryValueW is not implemented\n");
1295 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1296 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1297 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1298 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1300 /* unicode - try size in WCHARS */
1301 SetLastError(0xdeadbeef);
1302 size
= sizeof(valW
) / sizeof(WCHAR
);
1303 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1304 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1305 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1306 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1307 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1309 /* unicode - successfully read the value */
1310 size
= sizeof(valW
);
1311 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1312 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1313 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1314 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1316 /* unicode - set the value without a NULL terminator */
1317 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1318 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1320 /* unicode - read the unterminated value, value is terminated for us */
1321 memset(valW
, 'a', sizeof(valW
));
1322 size
= sizeof(valW
);
1323 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1324 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1325 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1326 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1329 RegDeleteKeyA(subkey
, "");
1330 RegCloseKey(subkey
);
1333 static void test_string_termination(void)
1337 static const char string
[] = "FullString";
1340 DWORD insize
, outsize
, nsize
;
1342 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1343 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1345 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1346 insize
=sizeof(string
)-1;
1347 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1348 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1350 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1351 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1353 /* Off-by-two RegSetValueExA -> no trailing '\0', except on Win9x */
1354 insize
=sizeof(string
)-2;
1355 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1356 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1358 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1359 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1360 ok(outsize
== insize
|| broken(outsize
== sizeof(string
)) /* Win9x */,
1361 "wrong size %u != %u\n", outsize
, insize
);
1363 if (outsize
== insize
)
1365 /* RegQueryValueExA may return a string with no trailing '\0' */
1367 memset(buffer
, 0xbd, sizeof(buffer
));
1368 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1369 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1370 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1371 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1372 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1373 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1375 /* RegQueryValueExA adds a trailing '\0' if there is room */
1377 memset(buffer
, 0xbd, sizeof(buffer
));
1378 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1379 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1380 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1381 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1382 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1383 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1385 /* RegEnumValueA may return a string with no trailing '\0' */
1387 memset(buffer
, 0xbd, sizeof(buffer
));
1389 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1390 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1391 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1392 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1393 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1394 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1395 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1397 /* RegEnumValueA adds a trailing '\0' if there is room */
1399 memset(buffer
, 0xbd, sizeof(buffer
));
1401 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1402 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1403 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1404 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1405 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1406 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1407 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1410 RegDeleteKeyA(subkey
, "");
1411 RegCloseKey(subkey
);
1414 static void test_reg_delete_tree(void)
1416 CHAR buffer
[MAX_PATH
];
1417 HKEY subkey
, subkey2
;
1420 if(!pRegDeleteTreeA
) {
1421 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1425 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1426 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1427 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1428 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1429 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1430 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1431 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1432 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1433 ret
= RegCloseKey(subkey2
);
1434 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1436 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1437 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1438 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1439 "subkey2 was not deleted\n");
1441 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1442 "Default value of subkey not longer present\n");
1444 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1445 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1446 ret
= RegCloseKey(subkey2
);
1447 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1448 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1449 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1450 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1451 "subkey2 was not deleted\n");
1452 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1453 "Default value of subkey not longer present\n");
1455 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1456 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1457 ret
= RegCloseKey(subkey2
);
1458 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1459 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1460 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1461 ret
= RegCloseKey(subkey2
);
1462 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1463 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1464 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1465 ret
= pRegDeleteTreeA(subkey
, NULL
);
1466 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1467 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1468 "subkey was deleted\n");
1469 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1470 "subkey2 was not deleted\n");
1471 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1472 "subkey3 was not deleted\n");
1474 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1475 ok(ret
== ERROR_SUCCESS
,
1476 "Default value of subkey is not present\n");
1477 ok(!lstrlenA(buffer
),
1478 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1480 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1481 "Value is still present\n");
1483 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1484 ok(ret
== ERROR_FILE_NOT_FOUND
,
1485 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1488 static void test_rw_order(void)
1492 static char keyname
[] = "test_rw_order";
1494 DWORD values
, value_len
, value_name_max_len
;
1497 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1498 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1499 if(ret
!= ERROR_SUCCESS
) {
1500 skip("Couldn't create key. Skipping.\n");
1504 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1505 "RegSetValueExA for value \"A\" failed\n");
1506 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1507 "RegSetValueExA for value \"C\" failed\n");
1508 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1509 "RegSetValueExA for value \"D\" failed\n");
1510 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1511 "RegSetValueExA for value \"B\" failed\n");
1513 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1514 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1515 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1517 /* Value enumeration preserves RegSetValueEx call order */
1519 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1520 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1522 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1523 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1525 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1526 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1528 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1529 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1531 ok(!RegDeleteKey(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1534 START_TEST(registry
)
1536 /* Load pointers for functions that are not available in all Windows versions */
1541 create_test_entries();
1543 test_query_value_ex();
1545 test_reg_open_key();
1546 test_reg_create_key();
1547 test_reg_close_key();
1548 test_reg_delete_key();
1549 test_reg_query_value();
1550 test_string_termination();
1552 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
1553 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
1554 set_privileges(SE_RESTORE_NAME
, TRUE
))
1556 test_reg_save_key();
1557 test_reg_load_key();
1558 test_reg_unload_key();
1560 set_privileges(SE_BACKUP_NAME
, FALSE
);
1561 set_privileges(SE_RESTORE_NAME
, FALSE
);
1564 test_reg_delete_tree();
1568 delete_key( hkey_main
);
1570 test_regconnectregistry();