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 #define lok ok_(__FILE__, line)
203 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
204 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
207 DWORD ret
, type
, cbData
;
213 /* When successful RegQueryValueExA() leaves GLE as is,
214 * so we must reset it to detect unimplemented functions.
216 SetLastError(0xdeadbeef);
217 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
218 GLE
= GetLastError();
219 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
220 /* It is wrong for the Ansi version to not be implemented */
221 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
222 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
224 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
225 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
226 lok(cbData
== full_byte_len
|| cbData
== str_byte_len
/* Win9x */,
227 "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
229 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
230 memset(value
, 0xbd, cbData
+1);
232 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
233 GLE
= GetLastError();
234 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
237 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
238 lok(*value
== 0xbd || (cbData
== 1 && *value
== '\0') /* Win9x */,
239 "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
243 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
244 wine_debugstr_an((char*)value
, cbData
), cbData
,
245 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
246 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
248 HeapFree(GetProcessHeap(), 0, value
);
251 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
252 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
255 DWORD ret
, type
, cbData
;
260 /* When successful RegQueryValueExW() leaves GLE as is,
261 * so we must reset it to detect unimplemented functions.
263 SetLastError(0xdeadbeef);
264 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
265 GLE
= GetLastError();
266 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
267 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
269 win_skip("RegQueryValueExW() is not implemented\n");
273 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
274 lok(cbData
== full_byte_len
,
275 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
277 /* Give enough space to overflow by one WCHAR */
278 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
279 memset(value
, 0xbd, cbData
+2);
281 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
282 GLE
= GetLastError();
283 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
286 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
287 wine_debugstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
288 wine_debugstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
290 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
291 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
292 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
293 HeapFree(GetProcessHeap(), 0, value
);
296 static void test_set_value(void)
300 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
301 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};
302 static const WCHAR emptyW
[] = {0};
303 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
304 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};
305 static const WCHAR substring2W
[] = {'T','h','i','s',0};
307 static const char name1A
[] = "CleanSingleString";
308 static const char name2A
[] = "SomeIntraZeroedString";
309 static const char emptyA
[] = "";
310 static const char string1A
[] = "ThisNeverBreaks";
311 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
312 static const char substring2A
[] = "This";
316 /* Crashes on NT4, Windows 2000 and XP SP1 */
317 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
318 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
321 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
322 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
323 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
324 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
326 /* RegSetValueA ignores the size passed in */
327 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
328 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
329 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
330 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
332 /* stops at first null */
333 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
334 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
335 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
336 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
338 /* only REG_SZ is supported on NT*/
339 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
340 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
341 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
342 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
344 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
345 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
346 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
347 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
349 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
350 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
351 ok(ret
== ERROR_INVALID_PARAMETER
|| broken(ret
== ERROR_SUCCESS
),
352 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret
);
354 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
355 * Surprisingly enough we're supposed to get zero bytes out of it.
357 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
358 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
359 test_hkey_main_Value_A(name1A
, NULL
, 0);
360 test_hkey_main_Value_W(name1W
, NULL
, 0);
362 /* test RegSetValueExA with an empty string */
363 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
364 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
365 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
366 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
368 /* test RegSetValueExA with off-by-one size */
369 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
370 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
371 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
372 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
374 /* test RegSetValueExA with normal string */
375 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
376 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
377 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
378 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
380 /* test RegSetValueExA with intrazeroed string */
381 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
382 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
383 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
384 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
386 /* 9x doesn't support W-calls, so don't test them then */
387 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
391 /* Crashes on NT4, Windows 2000 and XP SP1 */
392 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
393 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
396 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
397 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
398 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
399 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
401 /* RegSetValueA ignores the size passed in */
402 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
403 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
404 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
405 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
407 /* stops at first null */
408 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
409 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
410 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
411 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
413 /* only REG_SZ is supported */
414 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
415 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
416 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
417 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
418 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
419 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
421 /* test RegSetValueExW with off-by-one size */
422 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
423 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
424 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
425 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
427 /* test RegSetValueExW with normal string */
428 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
429 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
430 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
431 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
433 /* test RegSetValueExW with intrazeroed string */
434 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
435 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
436 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
437 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
440 static void create_test_entries(void)
442 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
444 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
445 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
447 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
448 "RegSetValueExA failed\n");
449 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
450 "RegSetValueExA failed\n");
451 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
452 "RegSetValueExA failed\n");
453 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
454 "RegSetValueExA failed\n");
455 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
456 "RegSetValueExA failed\n");
457 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
458 "RegSetValueExA failed\n");
459 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
460 "RegSetValueExA failed\n");
463 static void test_enum_value(void)
467 char value
[20], data
[20];
468 WCHAR valueW
[20], dataW
[20];
469 DWORD val_count
, data_count
, type
;
470 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
471 static const WCHAR testW
[] = {'T','e','s','t',0};
472 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
474 /* create the working key for new 'Test' value */
475 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
476 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
478 /* check NULL data with zero length */
479 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
480 if (GetVersion() & 0x80000000)
481 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
483 ok( !res
, "RegSetValueExA returned %d\n", res
);
484 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
485 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
486 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
487 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
489 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
490 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
492 /* overflow both name and data */
496 strcpy( value
, "xxxxxxxxxx" );
497 strcpy( data
, "xxxxxxxxxx" );
498 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
499 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
500 ok( val_count
== 2, "val_count set to %d\n", val_count
);
501 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
502 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
503 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
504 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
510 strcpy( value
, "xxxxxxxxxx" );
511 strcpy( data
, "xxxxxxxxxx" );
512 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
513 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
514 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
515 ok( val_count
== 2 || val_count
== 3, "val_count set to %d\n", val_count
);
516 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
517 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
518 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
519 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
520 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
521 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ),
522 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
524 /* overflow empty name */
528 strcpy( value
, "xxxxxxxxxx" );
529 strcpy( data
, "xxxxxxxxxx" );
530 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
531 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
532 ok( val_count
== 0, "val_count set to %d\n", val_count
);
533 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
534 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
535 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
536 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
537 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ),
538 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
544 strcpy( value
, "xxxxxxxxxx" );
545 strcpy( data
, "xxxxxxxxxx" );
546 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
547 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
548 ok( val_count
== 20, "val_count set to %d\n", val_count
);
549 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
550 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
551 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
552 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
558 strcpy( value
, "xxxxxxxxxx" );
559 strcpy( data
, "xxxxxxxxxx" );
560 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
561 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
562 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
563 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
564 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
565 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
566 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
570 SetLastError(0xdeadbeef);
571 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
572 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
574 win_skip("RegSetValueExW is not implemented\n");
577 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
579 /* overflow both name and data */
583 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
584 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
585 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
586 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
587 ok( val_count
== 2, "val_count set to %d\n", val_count
);
588 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
589 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
590 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
591 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
597 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
598 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
599 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
600 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
601 ok( val_count
== 3, "val_count set to %d\n", val_count
);
602 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
603 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
604 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
605 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
611 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
612 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
613 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
614 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
615 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
616 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
617 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
618 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
619 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
625 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
626 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
627 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
628 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
629 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
630 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
631 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
632 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
633 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
636 RegDeleteKeyA(test_key
, "");
637 RegCloseKey(test_key
);
640 static void test_query_value_ex(void)
647 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
648 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
649 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
650 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
654 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
655 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
656 /* the type parameter is cleared on Win9x, but is set to a random value on
657 * NT, so don't do that test there. The size parameter is left untouched on Win9x
658 * but cleared on NT+, this can be tested on all platforms.
660 if (GetVersion() & 0x80000000)
662 ok(type
== 0, "type should have been set to 0 instead of 0x%x\n", type
);
663 ok(size
== 0xdeadbeef, "size should have been left untouched (0xdeadbeef)\n");
667 trace("test_query_value_ex: type set to: 0x%08x\n", type
);
668 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
671 size
= sizeof(buffer
);
672 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
673 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
674 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
677 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
678 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
681 static void test_get_value(void)
688 CHAR expanded
[] = "bar\\subdir1";
689 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
693 win_skip("RegGetValue not available on this platform\n");
697 /* Invalid parameter */
698 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
699 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
701 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
702 size
= type
= dw
= 0xdeadbeef;
703 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
704 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
705 ok(size
== 4, "size=%d\n", size
);
706 ok(type
== REG_DWORD
, "type=%d\n", type
);
707 ok(dw
== 0x12345678, "dw=%d\n", dw
);
709 /* Query by subkey-name */
710 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
711 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
713 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
714 size
= type
= dw
= 0xdeadbeef;
715 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
716 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
717 /* Although the function failed all values are retrieved */
718 ok(size
== 4, "size=%d\n", size
);
719 ok(type
== REG_DWORD
, "type=%d\n", type
);
720 ok(dw
== 0x12345678, "dw=%d\n", dw
);
722 /* Test RRF_ZEROONFAILURE */
723 type
= dw
= 0xdeadbeef; size
= 4;
724 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
725 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
726 /* Again all values are retrieved ... */
727 ok(size
== 4, "size=%d\n", size
);
728 ok(type
== REG_DWORD
, "type=%d\n", type
);
729 /* ... except the buffer, which is zeroed out */
730 ok(dw
== 0, "dw=%d\n", dw
);
732 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
733 type
= size
= 0xbadbeef;
734 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
735 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
736 ok(size
== 4, "size=%d\n", size
);
737 ok(type
== REG_DWORD
, "type=%d\n", type
);
739 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
740 size
= type
= dw
= 0xdeadbeef;
741 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
742 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
743 ok(size
== 4, "size=%d\n", size
);
744 ok(type
== REG_DWORD
, "type=%d\n", type
);
745 ok(dw
== 0x12345678, "dw=%d\n", dw
);
747 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
748 size
= type
= dw
= 0xdeadbeef;
749 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
750 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
751 ok(size
== 4, "size=%d\n", size
);
752 ok(type
== REG_BINARY
, "type=%d\n", type
);
753 ok(dw
== 0x12345678, "dw=%d\n", dw
);
755 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
756 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
757 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
758 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
759 ok(size
== 8, "size=%d\n", size
);
760 ok(type
== REG_BINARY
, "type=%d\n", type
);
761 ok(qw
[0] == 0x12345678 &&
762 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
764 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
765 type
= dw
= 0xdeadbeef; size
= 4;
766 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
767 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
768 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
769 ok(size
== 8, "size=%d\n", size
);
771 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
772 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
773 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
774 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
775 ok(size
== 8, "size=%d\n", size
);
776 ok(type
== REG_BINARY
, "type=%d\n", type
);
777 ok(qw
[0] == 0x12345678 &&
778 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
780 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
781 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
782 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
783 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
784 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
785 ok(type
== REG_SZ
, "type=%d\n", type
);
786 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
788 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
789 type
= 0xdeadbeef; size
= 0;
790 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
791 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
792 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
793 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
794 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
795 ok(type
== REG_SZ
, "type=%d\n", type
);
797 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
798 strcpy(buf
, sTestpath1
);
801 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
802 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
803 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
805 size
== 1, /* win2k3 */
807 ok(type
== REG_SZ
, "type=%d\n", type
);
808 ok(!strcmp(sTestpath1
, buf
) ||
810 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
812 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
813 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
814 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
815 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
816 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
817 ok(type
== REG_SZ
, "type=%d\n", type
);
818 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
820 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
822 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
823 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
824 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
825 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
826 (size
== strlen(sTestpath2
)+1),
827 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
829 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
830 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
831 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
832 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
833 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
834 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
835 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
836 ok(type
== REG_SZ
, "type=%d\n", type
);
837 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
839 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
840 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
841 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
842 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
843 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
844 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
845 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
846 ok(type
== REG_SZ
, "type=%d\n", type
);
847 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
849 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
850 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
851 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
852 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
853 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
854 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
855 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
857 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
859 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
860 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
861 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
862 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
863 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
865 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
866 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
867 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
869 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
870 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
871 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
873 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
874 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
875 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
876 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
877 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
878 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
879 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
880 ok(type
== REG_SZ
, "type=%d\n", type
);
881 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
884 static void test_reg_open_key(void)
887 HKEY hkResult
= NULL
;
888 HKEY hkPreserve
= NULL
;
890 /* successful open */
891 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
892 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
893 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
894 hkPreserve
= hkResult
;
896 /* these tests fail on Win9x, but we want to be compatible with NT, so
897 * run them if we can */
898 if (!(GetVersion() & 0x80000000))
900 /* open same key twice */
901 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
902 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
903 ok(hkResult
!= hkPreserve
, "epxected hkResult != hkPreserve\n");
904 ok(hkResult
!= NULL
, "hkResult != NULL\n");
905 RegCloseKey(hkResult
);
907 /* open nonexistent key
908 * check that hkResult is set to NULL
910 hkResult
= hkPreserve
;
911 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
912 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
913 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
915 /* open the same nonexistent key again to make sure the key wasn't created */
916 hkResult
= hkPreserve
;
917 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
918 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
919 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
921 /* send in NULL lpSubKey
922 * check that hkResult receives the value of hKey
924 hkResult
= hkPreserve
;
925 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
926 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
927 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
929 /* send empty-string in lpSubKey */
930 hkResult
= hkPreserve
;
931 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
932 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
933 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
935 /* send in NULL lpSubKey and NULL hKey
936 * hkResult is set to NULL
938 hkResult
= hkPreserve
;
939 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
940 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
941 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
944 /* only send NULL hKey
945 * the value of hkResult remains unchanged
947 hkResult
= hkPreserve
;
948 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
949 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
950 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
951 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
952 RegCloseKey(hkResult
);
954 /* send in NULL hkResult */
955 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
956 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
958 /* beginning backslash character */
959 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
960 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
961 ret
== ERROR_FILE_NOT_FOUND
/* Win9x,ME */
962 , "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
966 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
967 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
968 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
969 RegCloseKey(hkResult
);
972 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
973 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
974 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
975 RegCloseKey(hkResult
);
978 static void test_reg_create_key(void)
982 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
983 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
984 /* should succeed: all versions of Windows ignore the access rights
985 * to the parent handle */
986 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
987 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
990 RegDeleteKey(hkey2
, "");
991 RegDeleteKey(hkey1
, "");
993 /* beginning backslash character */
994 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
995 if (!(GetVersion() & 0x80000000))
996 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
998 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
999 RegDeleteKey(hkey1
, NULL
);
1002 /* WOW64 flags - open an existing key */
1004 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1005 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1006 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1010 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1011 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1012 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1016 static void test_reg_close_key(void)
1021 /* successfully close key
1022 * hkHandle remains changed after call to RegCloseKey
1024 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1025 ret
= RegCloseKey(hkHandle
);
1026 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1028 /* try to close the key twice */
1029 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1030 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1031 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1033 /* try to close a NULL handle */
1034 ret
= RegCloseKey(NULL
);
1035 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1036 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1038 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1039 * win98 doesn't give a new handle when the same key is opened.
1040 * Not re-opening will make some next tests fail.
1042 if (hkey_main
== hkHandle
)
1044 trace("The main handle is most likely closed, so re-opening\n");
1045 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1049 static void test_reg_delete_key(void)
1053 ret
= RegDeleteKey(hkey_main
, NULL
);
1055 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1056 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1057 * Not re-creating will make some next tests fail.
1059 if (ret
== ERROR_SUCCESS
)
1061 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1062 " re-creating the main key\n");
1066 ok(ret
== ERROR_INVALID_PARAMETER
||
1067 ret
== ERROR_ACCESS_DENIED
||
1068 ret
== ERROR_BADKEY
, /* Win95 */
1072 static void test_reg_save_key(void)
1076 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
1077 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1080 static void test_reg_load_key(void)
1085 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1086 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1088 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1089 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1091 RegCloseKey(hkHandle
);
1094 static void test_reg_unload_key(void)
1098 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
1099 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1101 DeleteFile("saved_key");
1102 DeleteFile("saved_key.LOG");
1105 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1107 TOKEN_PRIVILEGES tp
;
1111 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1114 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
1116 CloseHandle(hToken
);
1120 tp
.PrivilegeCount
= 1;
1121 tp
.Privileges
[0].Luid
= luid
;
1124 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1126 tp
.Privileges
[0].Attributes
= 0;
1128 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1129 if (GetLastError() != ERROR_SUCCESS
)
1131 CloseHandle(hToken
);
1135 CloseHandle(hToken
);
1139 /* tests that show that RegConnectRegistry and
1140 OpenSCManager accept computer names without the
1141 \\ prefix (what MSDN says). */
1142 static void test_regconnectregistry( void)
1144 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1145 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1146 DWORD len
= sizeof(compName
) ;
1152 SetLastError(0xdeadbeef);
1153 ret
= GetComputerNameA(compName
, &len
);
1154 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1157 lstrcpyA(netwName
, "\\\\");
1158 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1160 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1162 retl
== ERROR_DLL_INIT_FAILED
||
1163 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1164 "RegConnectRegistryA failed err = %d\n", retl
);
1165 if( !retl
) RegCloseKey( hkey
);
1167 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1169 retl
== ERROR_DLL_INIT_FAILED
||
1170 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1171 "RegConnectRegistryA failed err = %d\n", retl
);
1172 if( !retl
) RegCloseKey( hkey
);
1174 SetLastError(0xdeadbeef);
1175 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1176 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1178 win_skip("OpenSCManagerA is not implemented\n");
1182 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1183 CloseServiceHandle( schnd
);
1185 SetLastError(0xdeadbeef);
1186 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1187 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1188 CloseServiceHandle( schnd
);
1192 static void test_reg_query_value(void)
1199 static const WCHAR expected
[] = {'d','a','t','a',0};
1201 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1202 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1204 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1205 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1207 /* try an invalid hkey */
1208 SetLastError(0xdeadbeef);
1210 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1211 ok(ret
== ERROR_INVALID_HANDLE
||
1212 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1213 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1214 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1215 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1217 /* try a NULL hkey */
1218 SetLastError(0xdeadbeef);
1220 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1221 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1222 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1223 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1225 /* try a NULL value */
1227 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1228 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1229 ok(size
== 5, "Expected 5, got %d\n", size
);
1231 /* try a NULL size */
1232 SetLastError(0xdeadbeef);
1234 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1235 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1236 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1237 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1239 /* try a NULL value and size */
1240 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1241 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1243 /* try a size too small */
1244 SetLastError(0xdeadbeef);
1247 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1248 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1249 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1250 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1251 ok(size
== 5, "Expected 5, got %d\n", size
);
1253 /* successfully read the value using 'subkey' */
1255 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1256 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1257 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1258 ok(size
== 5, "Expected 5, got %d\n", size
);
1260 /* successfully read the value using the subkey key */
1262 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1263 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1264 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1265 ok(size
== 5, "Expected 5, got %d\n", size
);
1267 /* unicode - try size too small */
1268 SetLastError(0xdeadbeef);
1271 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1272 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1274 win_skip("RegQueryValueW is not implemented\n");
1277 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1278 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1279 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1280 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1282 /* unicode - try size in WCHARS */
1283 SetLastError(0xdeadbeef);
1284 size
= sizeof(valW
) / sizeof(WCHAR
);
1285 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1286 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1287 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1288 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1289 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1291 /* unicode - successfully read the value */
1292 size
= sizeof(valW
);
1293 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1294 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1295 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1296 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1298 /* unicode - set the value without a NULL terminator */
1299 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1300 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1302 /* unicode - read the unterminated value, value is terminated for us */
1303 memset(valW
, 'a', sizeof(valW
));
1304 size
= sizeof(valW
);
1305 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1306 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1307 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1308 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1311 RegDeleteKeyA(subkey
, "");
1312 RegCloseKey(subkey
);
1315 static void test_string_termination(void)
1319 static const char string
[] = "FullString";
1322 DWORD insize
, outsize
, nsize
;
1324 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1325 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1327 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1328 insize
=sizeof(string
)-1;
1329 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1330 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1332 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1333 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1335 /* Off-by-two RegSetValueExA -> no trailing '\0', except on Win9x */
1336 insize
=sizeof(string
)-2;
1337 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1338 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1340 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1341 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1342 ok(outsize
== insize
|| broken(outsize
== sizeof(string
)) /* Win9x */,
1343 "wrong size %u != %u\n", outsize
, insize
);
1345 if (outsize
== insize
)
1347 /* RegQueryValueExA may return a string with no trailing '\0' */
1349 memset(buffer
, 0xbd, sizeof(buffer
));
1350 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1351 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1352 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1353 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1354 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1355 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1357 /* RegQueryValueExA adds a trailing '\0' if there is room */
1359 memset(buffer
, 0xbd, sizeof(buffer
));
1360 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1361 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1362 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1363 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1364 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1365 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1367 /* RegEnumValueA may return a string with no trailing '\0' */
1369 memset(buffer
, 0xbd, sizeof(buffer
));
1371 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1372 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1373 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1374 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1375 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1376 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1377 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1379 /* RegEnumValueA adds a trailing '\0' if there is room */
1381 memset(buffer
, 0xbd, sizeof(buffer
));
1383 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1384 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1385 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1386 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1387 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1388 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1389 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1392 RegDeleteKeyA(subkey
, "");
1393 RegCloseKey(subkey
);
1396 static void test_reg_delete_tree(void)
1398 CHAR buffer
[MAX_PATH
];
1399 HKEY subkey
, subkey2
;
1402 if(!pRegDeleteTreeA
) {
1403 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1407 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1408 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1409 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1410 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1411 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1412 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1413 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1414 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1415 ret
= RegCloseKey(subkey2
);
1416 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1418 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1419 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1420 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1421 "subkey2 was not deleted\n");
1423 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1424 "Default value of subkey not longer present\n");
1426 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1427 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1428 ret
= RegCloseKey(subkey2
);
1429 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1430 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1431 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1432 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1433 "subkey2 was not deleted\n");
1434 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1435 "Default value of subkey not longer present\n");
1437 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1438 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1439 ret
= RegCloseKey(subkey2
);
1440 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1441 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1442 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1443 ret
= RegCloseKey(subkey2
);
1444 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1445 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1446 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1447 ret
= pRegDeleteTreeA(subkey
, NULL
);
1448 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1449 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1450 "subkey was deleted\n");
1451 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1452 "subkey2 was not deleted\n");
1453 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1454 "subkey3 was not deleted\n");
1456 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1457 ok(ret
== ERROR_SUCCESS
,
1458 "Default value of subkey is not present\n");
1459 ok(!lstrlenA(buffer
),
1460 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1462 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1463 "Value is still present\n");
1465 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1466 ok(ret
== ERROR_FILE_NOT_FOUND
,
1467 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1470 START_TEST(registry
)
1472 /* Load pointers for functions that are not available in all Windows versions */
1477 create_test_entries();
1479 test_query_value_ex();
1481 test_reg_open_key();
1482 test_reg_create_key();
1483 test_reg_close_key();
1484 test_reg_delete_key();
1485 test_reg_query_value();
1486 test_string_termination();
1488 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
1489 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
1490 set_privileges(SE_RESTORE_NAME
, TRUE
))
1492 test_reg_save_key();
1493 test_reg_load_key();
1494 test_reg_unload_key();
1496 set_privileges(SE_BACKUP_NAME
, FALSE
);
1497 set_privileges(SE_RESTORE_NAME
, FALSE
);
1500 test_reg_delete_tree();
1503 delete_key( hkey_main
);
1505 test_regconnectregistry();