Sync to trunk head(r38096)
[reactos.git] / rostests / winetests / advapi32 / registry.c
1 /*
2 * Unit tests for registry functions
3 *
4 * Copyright (c) 2002 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "winsvc.h"
29 #include "winerror.h"
30
31 static HKEY hkey_main;
32 static DWORD GLE;
33
34 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
35 static const char * sTestpath2 = "%FOO%\\subdir1";
36
37 static HMODULE hadvapi32;
38 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
39 static DWORD (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR);
40
41
42
43 /* Debugging functions from wine/libs/wine/debug.c */
44
45 /* allocate some tmp string space */
46 /* FIXME: this is not 100% thread-safe */
47 static char *get_temp_buffer( int size )
48 {
49 static char *list[32];
50 static long pos;
51 char *ret;
52 int idx;
53
54 idx = ++pos % (sizeof(list)/sizeof(list[0]));
55 if ((ret = realloc( list[idx], size ))) list[idx] = ret;
56 return ret;
57 }
58
59 static const char *wine_debugstr_an( const char *str, int n )
60 {
61 static const char hex[16] = "0123456789abcdef";
62 char *dst, *res;
63 size_t size;
64
65 if (!((ULONG_PTR)str >> 16))
66 {
67 if (!str) return "(null)";
68 res = get_temp_buffer( 6 );
69 sprintf( res, "#%04x", LOWORD(str) );
70 return res;
71 }
72 if (n == -1) n = strlen(str);
73 if (n < 0) n = 0;
74 size = 10 + min( 300, n * 4 );
75 dst = res = get_temp_buffer( size );
76 *dst++ = '"';
77 while (n-- > 0 && dst <= res + size - 9)
78 {
79 unsigned char c = *str++;
80 switch (c)
81 {
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;
87 default:
88 if (c >= ' ' && c <= 126)
89 *dst++ = c;
90 else
91 {
92 *dst++ = '\\';
93 *dst++ = 'x';
94 *dst++ = hex[(c >> 4) & 0x0f];
95 *dst++ = hex[c & 0x0f];
96 }
97 }
98 }
99 *dst++ = '"';
100 if (n > 0)
101 {
102 *dst++ = '.';
103 *dst++ = '.';
104 *dst++ = '.';
105 }
106 *dst++ = 0;
107 return res;
108 }
109
110 static const char *wine_debugstr_wn( const WCHAR *str, int n )
111 {
112 char *dst, *res;
113 size_t size;
114
115 if (!HIWORD(str))
116 {
117 if (!str) return "(null)";
118 res = get_temp_buffer( 6 );
119 sprintf( res, "#%04x", LOWORD(str) );
120 return res;
121 }
122 if (n == -1) n = lstrlenW(str);
123 if (n < 0) n = 0;
124 size = 12 + min( 300, n * 5);
125 dst = res = get_temp_buffer( n * 5 + 7 );
126 *dst++ = 'L';
127 *dst++ = '"';
128 while (n-- > 0 && dst <= res + size - 10)
129 {
130 WCHAR c = *str++;
131 switch (c)
132 {
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;
138 default:
139 if (c >= ' ' && c <= 126)
140 *dst++ = (char)c;
141 else
142 {
143 *dst++ = '\\';
144 sprintf(dst,"%04x",c);
145 dst+=4;
146 }
147 }
148 }
149 *dst++ = '"';
150 if (n > 0)
151 {
152 *dst++ = '.';
153 *dst++ = '.';
154 *dst++ = '.';
155 }
156 *dst = 0;
157 return res;
158 }
159
160
161 #define ADVAPI32_GET_PROC(func) \
162 p ## func = (void*)GetProcAddress(hadvapi32, #func); \
163 if(!p ## func) \
164 trace("GetProcAddress(%s) failed\n", #func);
165
166 static void InitFunctionPtrs(void)
167 {
168 hadvapi32 = GetModuleHandleA("advapi32.dll");
169
170 /* This function was introduced with Windows 2003 SP1 */
171 ADVAPI32_GET_PROC(RegGetValueA)
172 ADVAPI32_GET_PROC(RegDeleteTreeA)
173 }
174
175 /* delete key and all its subkeys */
176 static DWORD delete_key( HKEY hkey )
177 {
178 char name[MAX_PATH];
179 DWORD ret;
180
181 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
182 {
183 HKEY tmp;
184 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
185 {
186 ret = delete_key( tmp );
187 RegCloseKey( tmp );
188 }
189 if (ret) break;
190 }
191 if (ret != ERROR_NO_MORE_ITEMS) return ret;
192 RegDeleteKeyA( hkey, "" );
193 return 0;
194 }
195
196 static void setup_main_key(void)
197 {
198 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
199
200 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
201 }
202
203 static void test_hkey_main_Value_A(LPCSTR name, LPCSTR string,
204 DWORD full_byte_len)
205 {
206 DWORD ret, type, cbData;
207 DWORD str_byte_len;
208 LPSTR value;
209 static const char nA[]={'N', 0};
210
211 type=0xdeadbeef;
212 cbData=0xdeadbeef;
213 /* When successful RegQueryValueExA() leaves GLE as is,
214 * so we must reset it to detect unimplemented functions.
215 */
216 SetLastError(0xdeadbeef);
217 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
218 GLE = GetLastError();
219 ok(ret == ERROR_SUCCESS, "RegQueryValueExA 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;
223
224 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
225 ok(type == REG_SZ, "RegQueryValueExA returned type %d\n", type);
226 ok(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);
228
229 value = HeapAlloc(GetProcessHeap(), 0, (cbData+2)*sizeof(*value));
230 strcpy(value, nA);
231 type=0xdeadbeef;
232 ret = RegQueryValueExA(hkey_main, name, NULL, &type, (BYTE*)value, &cbData);
233 GLE = GetLastError();
234 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%d\n", ret, GLE);
235 if (!string)
236 {
237 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
238 ok(strcmp(value, nA) == 0 || (cbData == 1 && *value == '\0') /* Win9x */,
239 "RegQueryValueExA failed: '%s' != '%s'\n", value, string);
240 }
241 else
242 {
243 ok(memcmp(value, string, cbData) == 0, "RegQueryValueExA failed: %s/%d != %s/%d\n",
244 wine_debugstr_an(value, cbData), cbData,
245 wine_debugstr_an(string, full_byte_len), full_byte_len);
246 }
247 HeapFree(GetProcessHeap(), 0, value);
248 }
249
250 static void test_hkey_main_Value_W(LPCWSTR name, LPCWSTR string,
251 DWORD full_byte_len)
252 {
253 DWORD ret, type, cbData;
254 LPWSTR value;
255 static const WCHAR nW[]={'N', 0};
256
257 type=0xdeadbeef;
258 cbData=0xdeadbeef;
259 /* When successful RegQueryValueExW() leaves GLE as is,
260 * so we must reset it to detect unimplemented functions.
261 */
262 SetLastError(0xdeadbeef);
263 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
264 GLE = GetLastError();
265 ok(ret == ERROR_SUCCESS, "RegQueryValueExW failed: %d, GLE=%d\n", ret, GLE);
266 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
267
268 ok(type == REG_SZ, "RegQueryValueExW returned type %d\n", type);
269 ok(cbData == full_byte_len,
270 "cbData=%d instead of %d\n", cbData, full_byte_len);
271
272 value = HeapAlloc(GetProcessHeap(), 0, (cbData+2)*sizeof(*value));
273 lstrcpyW(value, nW);
274 type=0xdeadbeef;
275 ret = RegQueryValueExW(hkey_main, name, NULL, &type, (BYTE*)value, &cbData);
276 GLE = GetLastError();
277 ok(ret == ERROR_SUCCESS, "RegQueryValueExW failed: %d, GLE=%d\n", ret, GLE);
278 if (!string)
279 {
280 /* When cbData == 0, RegQueryValueExW() should not modify the buffer */
281 string=nW;
282 }
283 ok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
284 wine_debugstr_wn(value, cbData / sizeof(WCHAR)), cbData,
285 wine_debugstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
286 HeapFree(GetProcessHeap(), 0, value);
287 }
288
289 static void test_set_value(void)
290 {
291 DWORD ret;
292
293 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
294 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};
295 static const WCHAR emptyW[] = {0};
296 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
297 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};
298 static const WCHAR substring2W[] = {'T','h','i','s',0};
299
300 static const char name1A[] = "CleanSingleString";
301 static const char name2A[] = "SomeIntraZeroedString";
302 static const char emptyA[] = "";
303 static const char string1A[] = "ThisNeverBreaks";
304 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
305 static const char substring2A[] = "This";
306
307 if (0)
308 {
309 /* Crashes on NT4, Windows 2000 and XP SP1 */
310 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
311 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
312 }
313
314 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
315 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
316 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
317 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
318
319 /* RegSetValueA ignores the size passed in */
320 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
321 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
322 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
323 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
324
325 /* stops at first null */
326 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
327 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
328 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
329 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
330
331 /* only REG_SZ is supported */
332 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
333 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
334 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
335 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
336 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
337 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
338
339 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
340 * Surprisingly enough we're supposed to get zero bytes out of it.
341 */
342 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
343 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
344 test_hkey_main_Value_A(name1A, NULL, 0);
345 test_hkey_main_Value_W(name1W, NULL, 0);
346
347 /* test RegSetValueExA with an empty string */
348 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
349 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
350 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
351 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
352
353 /* test RegSetValueExA with off-by-one size */
354 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
355 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
356 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
357 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
358
359 /* test RegSetValueExA with normal string */
360 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
361 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
362 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
363 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
364
365 /* test RegSetValueExA with intrazeroed string */
366 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
367 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
368 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
369 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
370
371 /* 9x doesn't support W-calls, so don't test them then */
372 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
373
374 if (0)
375 {
376 /* Crashes on NT4, Windows 2000 and XP SP1 */
377 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
378 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
379 }
380
381 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
382 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
383 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
384 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
385
386 /* RegSetValueA ignores the size passed in */
387 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
388 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
389 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
390 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
391
392 /* stops at first null */
393 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
394 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
395 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
396 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
397
398 /* only REG_SZ is supported */
399 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
400 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
401 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
402 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
403 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
404 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
405
406 /* test RegSetValueExW with off-by-one size */
407 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
408 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
409 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
410 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
411
412 /* test RegSetValueExW with normal string */
413 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
414 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
415 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
416 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
417
418 /* test RegSetValueExW with intrazeroed string */
419 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
420 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
421 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
422 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
423 }
424
425 static void create_test_entries(void)
426 {
427 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
428
429 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
430 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
431
432 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
433 "RegSetValueExA failed\n");
434 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
435 "RegSetValueExA failed\n");
436 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, NULL, 0),
437 "RegSetValueExA failed\n");
438 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
439 "RegSetValueExA failed\n");
440 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
441 "RegSetValueExA failed\n");
442 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
443 "RegSetValueExA failed\n");
444 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
445 "RegSetValueExA failed\n");
446 }
447
448 static void test_enum_value(void)
449 {
450 DWORD res;
451 HKEY test_key;
452 char value[20], data[20];
453 WCHAR valueW[20], dataW[20];
454 DWORD val_count, data_count, type;
455 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
456 static const WCHAR testW[] = {'T','e','s','t',0};
457 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
458
459 /* create the working key for new 'Test' value */
460 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
461 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
462
463 /* check NULL data with zero length */
464 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
465 if (GetVersion() & 0x80000000)
466 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
467 else
468 ok( !res, "RegSetValueExA returned %d\n", res );
469 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
470 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
471 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
472 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
473
474 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
475 ok( res == 0, "RegSetValueExA failed error %d\n", res );
476
477 /* overflow both name and data */
478 val_count = 2;
479 data_count = 2;
480 type = 1234;
481 strcpy( value, "xxxxxxxxxx" );
482 strcpy( data, "xxxxxxxxxx" );
483 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
484 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
485 ok( val_count == 2, "val_count set to %d\n", val_count );
486 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
487 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
488 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
489 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
490
491 /* overflow name */
492 val_count = 3;
493 data_count = 20;
494 type = 1234;
495 strcpy( value, "xxxxxxxxxx" );
496 strcpy( data, "xxxxxxxxxx" );
497 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
498 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
499 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
500 ok( val_count == 2 || val_count == 3, "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 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
504 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
505 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
506 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ),
507 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
508
509 /* overflow empty name */
510 val_count = 0;
511 data_count = 20;
512 type = 1234;
513 strcpy( value, "xxxxxxxxxx" );
514 strcpy( data, "xxxxxxxxxx" );
515 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
516 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
517 ok( val_count == 0, "val_count set to %d\n", val_count );
518 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
519 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
520 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
521 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
522 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ),
523 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
524
525 /* overflow data */
526 val_count = 20;
527 data_count = 2;
528 type = 1234;
529 strcpy( value, "xxxxxxxxxx" );
530 strcpy( data, "xxxxxxxxxx" );
531 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
532 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
533 ok( val_count == 20, "val_count set to %d\n", val_count );
534 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
535 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
536 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
537 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
538
539 /* no overflow */
540 val_count = 20;
541 data_count = 20;
542 type = 1234;
543 strcpy( value, "xxxxxxxxxx" );
544 strcpy( data, "xxxxxxxxxx" );
545 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
546 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
547 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
548 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
549 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
550 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
551 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
552
553 /* Unicode tests */
554
555 SetLastError(0xdeadbeef);
556 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
557 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
558 {
559 skip("RegSetValueExW is not implemented\n");
560 goto cleanup;
561 }
562 ok( res == 0, "RegSetValueExW failed error %d\n", res );
563
564 /* overflow both name and data */
565 val_count = 2;
566 data_count = 2;
567 type = 1234;
568 memcpy( valueW, xxxW, sizeof(xxxW) );
569 memcpy( dataW, xxxW, sizeof(xxxW) );
570 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
571 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
572 ok( val_count == 2, "val_count set to %d\n", val_count );
573 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
574 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
575 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
576 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
577
578 /* overflow name */
579 val_count = 3;
580 data_count = 20;
581 type = 1234;
582 memcpy( valueW, xxxW, sizeof(xxxW) );
583 memcpy( dataW, xxxW, sizeof(xxxW) );
584 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
585 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
586 ok( val_count == 3, "val_count set to %d\n", val_count );
587 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
588 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
589 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
590 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
591
592 /* overflow data */
593 val_count = 20;
594 data_count = 2;
595 type = 1234;
596 memcpy( valueW, xxxW, sizeof(xxxW) );
597 memcpy( dataW, xxxW, sizeof(xxxW) );
598 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
599 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
600 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
601 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
602 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
603 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
604 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
605
606 /* no overflow */
607 val_count = 20;
608 data_count = 20;
609 type = 1234;
610 memcpy( valueW, xxxW, sizeof(xxxW) );
611 memcpy( dataW, xxxW, sizeof(xxxW) );
612 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
613 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
614 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
615 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
616 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
617 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
618 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
619
620 cleanup:
621 RegDeleteKeyA(test_key, "");
622 RegCloseKey(test_key);
623 }
624
625 static void test_query_value_ex(void)
626 {
627 DWORD ret;
628 DWORD size;
629 DWORD type;
630 BYTE buffer[10];
631
632 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
633 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
634 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
635 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
636
637 type = 0xdeadbeef;
638 size = 0xdeadbeef;
639 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
640 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
641 /* the type parameter is cleared on Win9x, but is set to a random value on
642 * NT, so don't do that test there. The size parameter is left untouched on Win9x
643 * but cleared on NT+, this can be tested on all platforms.
644 */
645 if (GetVersion() & 0x80000000)
646 {
647 ok(type == 0, "type should have been set to 0 instead of 0x%x\n", type);
648 ok(size == 0xdeadbeef, "size should have been left untouched (0xdeadbeef)\n");
649 }
650 else
651 {
652 trace("test_query_value_ex: type set to: 0x%08x\n", type);
653 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
654 }
655
656 size = sizeof(buffer);
657 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
658 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
659 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
660
661 size = 4;
662 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
663 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
664 }
665
666 static void test_get_value(void)
667 {
668 DWORD ret;
669 DWORD size;
670 DWORD type;
671 DWORD dw, qw[2];
672 CHAR buf[80];
673 CHAR expanded[] = "bar\\subdir1";
674 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
675
676 if(!pRegGetValueA)
677 {
678 skip("RegGetValue not available on this platform\n");
679 return;
680 }
681
682 /* Invalid parameter */
683 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
684 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
685
686 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
687 size = type = dw = 0xdeadbeef;
688 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
689 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
690 ok(size == 4, "size=%d\n", size);
691 ok(type == REG_DWORD, "type=%d\n", type);
692 ok(dw == 0x12345678, "dw=%d\n", dw);
693
694 /* Query by subkey-name */
695 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
696 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
697
698 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
699 size = type = dw = 0xdeadbeef;
700 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
701 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
702 /* Although the function failed all values are retrieved */
703 ok(size == 4, "size=%d\n", size);
704 ok(type == REG_DWORD, "type=%d\n", type);
705 ok(dw == 0x12345678, "dw=%d\n", dw);
706
707 /* Test RRF_ZEROONFAILURE */
708 type = dw = 0xdeadbeef; size = 4;
709 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
710 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
711 /* Again all values are retrieved ... */
712 ok(size == 4, "size=%d\n", size);
713 ok(type == REG_DWORD, "type=%d\n", type);
714 /* ... except the buffer, which is zeroed out */
715 ok(dw == 0, "dw=%d\n", dw);
716
717 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
718 type = size = 0xbadbeef;
719 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
720 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
721 ok(size == 4, "size=%d\n", size);
722 ok(type == REG_DWORD, "type=%d\n", type);
723
724 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
725 size = type = dw = 0xdeadbeef;
726 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
727 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
728 ok(size == 4, "size=%d\n", size);
729 ok(type == REG_DWORD, "type=%d\n", type);
730 ok(dw == 0x12345678, "dw=%d\n", dw);
731
732 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
733 size = type = dw = 0xdeadbeef;
734 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
735 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
736 ok(size == 4, "size=%d\n", size);
737 ok(type == REG_BINARY, "type=%d\n", type);
738 ok(dw == 0x12345678, "dw=%d\n", dw);
739
740 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
741 qw[0] = qw[1] = size = type = 0xdeadbeef;
742 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
743 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
744 ok(size == 8, "size=%d\n", size);
745 ok(type == REG_BINARY, "type=%d\n", type);
746 ok(qw[0] == 0x12345678 &&
747 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
748
749 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
750 type = dw = 0xdeadbeef; size = 4;
751 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
752 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
753 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
754 ok(size == 8, "size=%d\n", size);
755
756 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
757 qw[0] = qw[1] = size = type = 0xdeadbeef;
758 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
759 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
760 ok(size == 8, "size=%d\n", size);
761 ok(type == REG_BINARY, "type=%d\n", type);
762 ok(qw[0] == 0x12345678 &&
763 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
764
765 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
766 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
767 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
768 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
769 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
770 ok(type == REG_SZ, "type=%d\n", type);
771 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
772
773 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
774 type = 0xdeadbeef; size = 0;
775 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
776 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
777 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
778 ok(size == strlen(sTestpath1)+1 || size == strlen(sTestpath1)+2,
779 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
780 ok(type == REG_SZ, "type=%d\n", type);
781
782 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
783 strcpy(buf, sTestpath1);
784 type = 0xdeadbeef;
785 size = sizeof(buf);
786 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
787 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
788 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
789 ok(size == 0 ||
790 size == 1, /* win2k3 */
791 "size=%d\n", size);
792 ok(type == REG_SZ, "type=%d\n", type);
793 ok(!strcmp(sTestpath1, buf) ||
794 !strcmp(buf, ""),
795 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
796
797 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
798 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
799 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
800 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
801 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
802 ok(type == REG_SZ, "type=%d\n", type);
803 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
804
805 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
806 size = 0;
807 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
808 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
809 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
810 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
811 (size == strlen(sTestpath2)+1),
812 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
813
814 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
815 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
816 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
817 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
818 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
819 ok((size == strlen(expanded)+1) || (size == strlen(sTestpath1)+1),
820 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
821 ok(type == REG_SZ, "type=%d\n", type);
822 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
823
824 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
825 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
826 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
827 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
828 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
829 ok((size == strlen(expanded2)+1) || (size == strlen(sTestpath2)+1),
830 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
831 ok(type == REG_SZ, "type=%d\n", type);
832 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
833
834 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
835 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
836 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
837 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
838 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
839 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
840 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
841
842 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
843 size = 0xbadbeef;
844 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
845 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
846 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
847 ok(size == strlen(sTestpath1)+1 || size == strlen(sTestpath1)+2,
848 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
849
850 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
851 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
852 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
853
854 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
855 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
856 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
857 }
858
859 static void test_reg_open_key(void)
860 {
861 DWORD ret = 0;
862 HKEY hkResult = NULL;
863 HKEY hkPreserve = NULL;
864
865 /* successful open */
866 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
867 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
868 ok(hkResult != NULL, "expected hkResult != NULL\n");
869 hkPreserve = hkResult;
870
871 /* these tests fail on Win9x, but we want to be compatible with NT, so
872 * run them if we can */
873 if (!(GetVersion() & 0x80000000))
874 {
875 /* open same key twice */
876 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
877 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
878 ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
879 ok(hkResult != NULL, "hkResult != NULL\n");
880 RegCloseKey(hkResult);
881
882 /* open nonexistent key
883 * check that hkResult is set to NULL
884 */
885 hkResult = hkPreserve;
886 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
887 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
888 ok(hkResult == NULL, "expected hkResult == NULL\n");
889
890 /* open the same nonexistent key again to make sure the key wasn't created */
891 hkResult = hkPreserve;
892 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
893 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
894 ok(hkResult == NULL, "expected hkResult == NULL\n");
895
896 /* send in NULL lpSubKey
897 * check that hkResult receives the value of hKey
898 */
899 hkResult = hkPreserve;
900 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
901 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
902 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
903
904 /* send empty-string in lpSubKey */
905 hkResult = hkPreserve;
906 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
907 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
908 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
909
910 /* send in NULL lpSubKey and NULL hKey
911 * hkResult is set to NULL
912 */
913 hkResult = hkPreserve;
914 ret = RegOpenKeyA(NULL, NULL, &hkResult);
915 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
916 ok(hkResult == NULL, "expected hkResult == NULL\n");
917 }
918
919 /* only send NULL hKey
920 * the value of hkResult remains unchanged
921 */
922 hkResult = hkPreserve;
923 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
924 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
925 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
926 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
927 RegCloseKey(hkResult);
928
929 /* send in NULL hkResult */
930 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
931 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
932
933 /* beginning backslash character */
934 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
935 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
936 ret == ERROR_FILE_NOT_FOUND /* Win9x,ME */
937 , "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
938 }
939
940 static void test_reg_create_key(void)
941 {
942 LONG ret;
943 HKEY hkey1, hkey2;
944 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
945 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
946 /* should succeed: all versions of Windows ignore the access rights
947 * to the parent handle */
948 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
949 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
950
951 /* clean up */
952 RegDeleteKey(hkey2, "");
953 RegDeleteKey(hkey1, "");
954
955 /* beginning backslash character */
956 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
957 if (!(GetVersion() & 0x80000000))
958 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
959 else {
960 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
961 RegDeleteKey(hkey1, NULL);
962 }
963 }
964
965 static void test_reg_close_key(void)
966 {
967 DWORD ret = 0;
968 HKEY hkHandle;
969
970 /* successfully close key
971 * hkHandle remains changed after call to RegCloseKey
972 */
973 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
974 ret = RegCloseKey(hkHandle);
975 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
976
977 /* try to close the key twice */
978 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
979 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
980 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
981
982 /* try to close a NULL handle */
983 ret = RegCloseKey(NULL);
984 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
985 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
986
987 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
988 * win98 doesn't give a new handle when the same key is opened.
989 * Not re-opening will make some next tests fail.
990 */
991 if (hkey_main == hkHandle)
992 {
993 trace("The main handle is most likely closed, so re-opening\n");
994 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
995 }
996 }
997
998 static void test_reg_delete_key(void)
999 {
1000 DWORD ret;
1001
1002 ret = RegDeleteKey(hkey_main, NULL);
1003
1004 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1005 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1006 * Not re-creating will make some next tests fail.
1007 */
1008 if (ret == ERROR_SUCCESS)
1009 {
1010 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1011 " re-creating the main key\n");
1012 setup_main_key();
1013 }
1014 else
1015 ok(ret == ERROR_INVALID_PARAMETER ||
1016 ret == ERROR_ACCESS_DENIED ||
1017 ret == ERROR_BADKEY, /* Win95 */
1018 "ret=%d\n", ret);
1019 }
1020
1021 static void test_reg_save_key(void)
1022 {
1023 DWORD ret;
1024
1025 ret = RegSaveKey(hkey_main, "saved_key", NULL);
1026 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1027 }
1028
1029 static void test_reg_load_key(void)
1030 {
1031 DWORD ret;
1032 HKEY hkHandle;
1033
1034 ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1035 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1036
1037 ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1038 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1039
1040 RegCloseKey(hkHandle);
1041 }
1042
1043 static void test_reg_unload_key(void)
1044 {
1045 DWORD ret;
1046
1047 ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
1048 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1049
1050 DeleteFile("saved_key");
1051 DeleteFile("saved_key.LOG");
1052 }
1053
1054 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1055 {
1056 TOKEN_PRIVILEGES tp;
1057 HANDLE hToken;
1058 LUID luid;
1059
1060 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1061 return FALSE;
1062
1063 if(!LookupPrivilegeValue(NULL, privilege, &luid))
1064 {
1065 CloseHandle(hToken);
1066 return FALSE;
1067 }
1068
1069 tp.PrivilegeCount = 1;
1070 tp.Privileges[0].Luid = luid;
1071
1072 if (set)
1073 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1074 else
1075 tp.Privileges[0].Attributes = 0;
1076
1077 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1078 if (GetLastError() != ERROR_SUCCESS)
1079 {
1080 CloseHandle(hToken);
1081 return FALSE;
1082 }
1083
1084 CloseHandle(hToken);
1085 return TRUE;
1086 }
1087
1088 /* tests that show that RegConnectRegistry and
1089 OpenSCManager accept computer names without the
1090 \\ prefix (what MSDN says). */
1091 static void test_regconnectregistry( void)
1092 {
1093 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1094 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1095 DWORD len = sizeof(compName) ;
1096 BOOL ret;
1097 LONG retl;
1098 HKEY hkey;
1099 SC_HANDLE schnd;
1100
1101 SetLastError(0xdeadbeef);
1102 ret = GetComputerNameA(compName, &len);
1103 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1104 if( !ret) return;
1105
1106 lstrcpyA(netwName, "\\\\");
1107 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1108
1109 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1110 ok( !retl ||
1111 retl == ERROR_DLL_INIT_FAILED ||
1112 retl == ERROR_BAD_NETPATH, /* some win2k */
1113 "RegConnectRegistryA failed err = %d\n", retl);
1114 if( !retl) RegCloseKey( hkey);
1115
1116 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1117 ok( !retl ||
1118 retl == ERROR_DLL_INIT_FAILED ||
1119 retl == ERROR_BAD_NETPATH, /* some win2k */
1120 "RegConnectRegistryA failed err = %d\n", retl);
1121 if( !retl) RegCloseKey( hkey);
1122
1123 SetLastError(0xdeadbeef);
1124 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1125 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1126 {
1127 skip("OpenSCManagerA is not implemented\n");
1128 return;
1129 }
1130
1131 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1132 CloseServiceHandle( schnd);
1133
1134 SetLastError(0xdeadbeef);
1135 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1136 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1137 CloseServiceHandle( schnd);
1138
1139 }
1140
1141 static void test_reg_query_value(void)
1142 {
1143 HKEY subkey;
1144 CHAR val[MAX_PATH];
1145 WCHAR valW[5];
1146 LONG size, ret;
1147
1148 static const WCHAR expected[] = {'d','a','t','a',0};
1149
1150 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1151 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1152
1153 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1154 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1155
1156 /* try an invalid hkey */
1157 SetLastError(0xdeadbeef);
1158 size = MAX_PATH;
1159 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1160 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1161 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1162 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1163
1164 /* try a NULL hkey */
1165 SetLastError(0xdeadbeef);
1166 size = MAX_PATH;
1167 ret = RegQueryValueA(NULL, "subkey", val, &size);
1168 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1169 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1170 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1171
1172 /* try a NULL value */
1173 size = MAX_PATH;
1174 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1175 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1176 ok(size == 5, "Expected 5, got %d\n", size);
1177
1178 /* try a NULL size */
1179 SetLastError(0xdeadbeef);
1180 val[0] = '\0';
1181 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1182 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1183 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1184 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1185
1186 /* try a NULL value and size */
1187 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1188 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1189
1190 /* try a size too small */
1191 SetLastError(0xdeadbeef);
1192 val[0] = '\0';
1193 size = 1;
1194 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1195 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1196 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1197 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1198 ok(size == 5, "Expected 5, got %d\n", size);
1199
1200 /* successfully read the value using 'subkey' */
1201 size = MAX_PATH;
1202 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1203 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1204 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1205 ok(size == 5, "Expected 5, got %d\n", size);
1206
1207 /* successfully read the value using the subkey key */
1208 size = MAX_PATH;
1209 ret = RegQueryValueA(subkey, NULL, val, &size);
1210 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1211 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1212 ok(size == 5, "Expected 5, got %d\n", size);
1213
1214 /* unicode - try size too small */
1215 SetLastError(0xdeadbeef);
1216 valW[0] = '\0';
1217 size = 0;
1218 ret = RegQueryValueW(subkey, NULL, valW, &size);
1219 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1220 {
1221 skip("RegQueryValueW is not implemented\n");
1222 goto cleanup;
1223 }
1224 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1225 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1226 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1227 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1228
1229 /* unicode - try size in WCHARS */
1230 SetLastError(0xdeadbeef);
1231 size = sizeof(valW) / sizeof(WCHAR);
1232 ret = RegQueryValueW(subkey, NULL, valW, &size);
1233 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1234 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1235 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1236 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1237
1238 /* unicode - successfully read the value */
1239 size = sizeof(valW);
1240 ret = RegQueryValueW(subkey, NULL, valW, &size);
1241 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1242 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1243 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1244
1245 /* unicode - set the value without a NULL terminator */
1246 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1247 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1248
1249 /* unicode - read the unterminated value, value is terminated for us */
1250 memset(valW, 'a', sizeof(valW));
1251 size = sizeof(valW);
1252 ret = RegQueryValueW(subkey, NULL, valW, &size);
1253 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1254 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1255 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1256
1257 cleanup:
1258 RegDeleteKeyA(subkey, "");
1259 RegCloseKey(subkey);
1260 }
1261
1262 static void test_reg_delete_tree(void)
1263 {
1264 CHAR buffer[MAX_PATH];
1265 HKEY subkey, subkey2;
1266 LONG size, ret;
1267
1268 if(!pRegDeleteTreeA) {
1269 skip("Skipping RegDeleteTreeA tests, function not present\n");
1270 return;
1271 }
1272
1273 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1274 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1275 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1276 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1277 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1278 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1279 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
1280 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1281 ret = RegCloseKey(subkey2);
1282 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1283
1284 ret = pRegDeleteTreeA(subkey, "subkey2");
1285 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1286 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1287 "subkey2 was not deleted\n");
1288 size = MAX_PATH;
1289 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1290 "Default value of subkey not longer present\n");
1291
1292 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1293 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1294 ret = RegCloseKey(subkey2);
1295 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1296 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
1297 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1298 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1299 "subkey2 was not deleted\n");
1300 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1301 "Default value of subkey not longer present\n");
1302
1303 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1304 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1305 ret = RegCloseKey(subkey2);
1306 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1307 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
1308 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1309 ret = RegCloseKey(subkey2);
1310 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1311 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
1312 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1313 ret = pRegDeleteTreeA(subkey, NULL);
1314 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1315 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
1316 "subkey was deleted\n");
1317 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1318 "subkey2 was not deleted\n");
1319 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
1320 "subkey3 was not deleted\n");
1321 size = MAX_PATH;
1322 ret = RegQueryValueA(subkey, NULL, buffer, &size);
1323 ok(ret == ERROR_SUCCESS,
1324 "Default value of subkey is not present\n");
1325 ok(!lstrlenA(buffer),
1326 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
1327 size = MAX_PATH;
1328 ok(RegQueryValueA(subkey, "value", buffer, &size),
1329 "Value is still present\n");
1330
1331 ret = pRegDeleteTreeA(hkey_main, "not-here");
1332 ok(ret == ERROR_FILE_NOT_FOUND,
1333 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1334 }
1335
1336 START_TEST(registry)
1337 {
1338 /* Load pointers for functions that are not available in all Windows versions */
1339 InitFunctionPtrs();
1340
1341 setup_main_key();
1342 test_set_value();
1343 create_test_entries();
1344 test_enum_value();
1345 test_query_value_ex();
1346 test_get_value();
1347 test_reg_open_key();
1348 test_reg_create_key();
1349 test_reg_close_key();
1350 test_reg_delete_key();
1351 test_reg_query_value();
1352
1353 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
1354 if (set_privileges(SE_BACKUP_NAME, TRUE) &&
1355 set_privileges(SE_RESTORE_NAME, TRUE))
1356 {
1357 test_reg_save_key();
1358 test_reg_load_key();
1359 test_reg_unload_key();
1360
1361 set_privileges(SE_BACKUP_NAME, FALSE);
1362 set_privileges(SE_RESTORE_NAME, FALSE);
1363 }
1364
1365 test_reg_delete_tree();
1366
1367 /* cleanup */
1368 delete_key( hkey_main );
1369
1370 test_regconnectregistry();
1371 }