[ADVAPI32_WINETEST]: Sync with Wine 1.5.19.
[reactos.git] / rostests / winetests / advapi32 / registry.c
1 /*
2 * Unit tests for registry functions
3 *
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include "wine/test.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winternl.h"
29 #include "winreg.h"
30 #include "winsvc.h"
31 #include "winerror.h"
32 #include "aclapi.h"
33
34 static HKEY hkey_main;
35 static DWORD GLE;
36
37 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
38 static const char * sTestpath2 = "%FOO%\\subdir1";
39
40 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
41 static DWORD (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR);
42 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
43 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
44 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
45 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
46 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
47
48
49 /* Debugging functions from wine/libs/wine/debug.c */
50
51 /* allocate some tmp string space */
52 /* FIXME: this is not 100% thread-safe */
53 static char *get_temp_buffer( int size )
54 {
55 static char *list[32];
56 static UINT pos;
57 char *ret;
58 UINT idx;
59
60 idx = ++pos % (sizeof(list)/sizeof(list[0]));
61 if (list[idx])
62 ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
63 else
64 ret = HeapAlloc( GetProcessHeap(), 0, size );
65 if (ret) list[idx] = ret;
66 return ret;
67 }
68
69 static const char *wine_debugstr_an( const char *str, int n )
70 {
71 static const char hex[16] = "0123456789abcdef";
72 char *dst, *res;
73 size_t size;
74
75 if (!((ULONG_PTR)str >> 16))
76 {
77 if (!str) return "(null)";
78 res = get_temp_buffer( 6 );
79 sprintf( res, "#%04x", LOWORD(str) );
80 return res;
81 }
82 if (n == -1) n = strlen(str);
83 if (n < 0) n = 0;
84 size = 10 + min( 300, n * 4 );
85 dst = res = get_temp_buffer( size );
86 *dst++ = '"';
87 while (n-- > 0 && dst <= res + size - 9)
88 {
89 unsigned char c = *str++;
90 switch (c)
91 {
92 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
93 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
94 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
95 case '"': *dst++ = '\\'; *dst++ = '"'; break;
96 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
97 default:
98 if (c >= ' ' && c <= 126)
99 *dst++ = c;
100 else
101 {
102 *dst++ = '\\';
103 *dst++ = 'x';
104 *dst++ = hex[(c >> 4) & 0x0f];
105 *dst++ = hex[c & 0x0f];
106 }
107 }
108 }
109 *dst++ = '"';
110 if (n > 0)
111 {
112 *dst++ = '.';
113 *dst++ = '.';
114 *dst++ = '.';
115 }
116 *dst++ = 0;
117 return res;
118 }
119
120 #define ADVAPI32_GET_PROC(func) \
121 p ## func = (void*)GetProcAddress(hadvapi32, #func)
122
123 static void InitFunctionPtrs(void)
124 {
125 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
126 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
127 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
128
129 /* This function was introduced with Windows 2003 SP1 */
130 ADVAPI32_GET_PROC(RegGetValueA);
131 ADVAPI32_GET_PROC(RegDeleteTreeA);
132 ADVAPI32_GET_PROC(RegDeleteKeyExA);
133
134 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
135 pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
136 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
137 pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
138 }
139
140 /* delete key and all its subkeys */
141 static DWORD delete_key( HKEY hkey )
142 {
143 char name[MAX_PATH];
144 DWORD ret;
145
146 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
147 {
148 HKEY tmp;
149 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
150 {
151 ret = delete_key( tmp );
152 RegCloseKey( tmp );
153 }
154 if (ret) break;
155 }
156 if (ret != ERROR_NO_MORE_ITEMS) return ret;
157 RegDeleteKeyA( hkey, "" );
158 return 0;
159 }
160
161 static void setup_main_key(void)
162 {
163 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
164
165 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
166 }
167
168 #define lok ok_(__FILE__, line)
169 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
170 static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
171 DWORD full_byte_len)
172 {
173 DWORD ret, type, cbData;
174 DWORD str_byte_len;
175 BYTE* value;
176
177 type=0xdeadbeef;
178 cbData=0xdeadbeef;
179 /* When successful RegQueryValueExA() leaves GLE as is,
180 * so we must reset it to detect unimplemented functions.
181 */
182 SetLastError(0xdeadbeef);
183 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
184 GLE = GetLastError();
185 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret, GLE);
186 /* It is wrong for the Ansi version to not be implemented */
187 ok(GLE == 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE);
188 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
189
190 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
191 lok(type == REG_SZ, "RegQueryValueExA/1 returned type %d\n", type);
192 lok(cbData == full_byte_len, "cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
193
194 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
195 memset(value, 0xbd, cbData+1);
196 type=0xdeadbeef;
197 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
198 GLE = GetLastError();
199 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
200 if (!string)
201 {
202 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
203 lok(*value == 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
204 }
205 else
206 {
207 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
208 wine_debugstr_an((char*)value, cbData), cbData,
209 wine_debugstr_an(string, full_byte_len), full_byte_len);
210 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
211 }
212 HeapFree(GetProcessHeap(), 0, value);
213 }
214
215 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
216 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
217 DWORD full_byte_len)
218 {
219 DWORD ret, type, cbData;
220 BYTE* value;
221
222 type=0xdeadbeef;
223 cbData=0xdeadbeef;
224 /* When successful RegQueryValueExW() leaves GLE as is,
225 * so we must reset it to detect unimplemented functions.
226 */
227 SetLastError(0xdeadbeef);
228 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
229 GLE = GetLastError();
230 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
231 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
232 {
233 win_skip("RegQueryValueExW() is not implemented\n");
234 return;
235 }
236
237 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
238 lok(cbData == full_byte_len,
239 "cbData=%d instead of %d\n", cbData, full_byte_len);
240
241 /* Give enough space to overflow by one WCHAR */
242 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
243 memset(value, 0xbd, cbData+2);
244 type=0xdeadbeef;
245 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
246 GLE = GetLastError();
247 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
248 if (string)
249 {
250 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
251 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
252 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
253 }
254 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
255 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
256 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
257 HeapFree(GetProcessHeap(), 0, value);
258 }
259
260 static void test_set_value(void)
261 {
262 DWORD ret;
263
264 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
265 static const WCHAR name2W[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
266 static const WCHAR emptyW[] = {0};
267 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
268 static const WCHAR string2W[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
269 static const WCHAR substring2W[] = {'T','h','i','s',0};
270
271 static const char name1A[] = "CleanSingleString";
272 static const char name2A[] = "SomeIntraZeroedString";
273 static const char emptyA[] = "";
274 static const char string1A[] = "ThisNeverBreaks";
275 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
276 static const char substring2A[] = "This";
277
278 if (0)
279 {
280 /* Crashes on NT4, Windows 2000 and XP SP1 */
281 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
282 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
283 }
284
285 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
286 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
287 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
288 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
289
290 /* RegSetValueA ignores the size passed in */
291 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
292 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
293 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
294 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
295
296 /* stops at first null */
297 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
298 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
299 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
300 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
301
302 /* only REG_SZ is supported on NT*/
303 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
304 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
305
306 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
307 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
308
309 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
310 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
311
312 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
313 * Surprisingly enough we're supposed to get zero bytes out of it.
314 */
315 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
316 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
317 test_hkey_main_Value_A(name1A, NULL, 0);
318 test_hkey_main_Value_W(name1W, NULL, 0);
319
320 /* test RegSetValueExA with an empty string */
321 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
322 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
323 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
324 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
325
326 /* test RegSetValueExA with off-by-one size */
327 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
328 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
329 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
330 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
331
332 /* test RegSetValueExA with normal string */
333 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
334 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
335 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
336 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
337
338 /* test RegSetValueExA with intrazeroed string */
339 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
340 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
341 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
342 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
343
344 if (0)
345 {
346 /* Crashes on NT4, Windows 2000 and XP SP1 */
347 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
348 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
349
350 RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)1, 1);
351 RegSetValueExA(hkey_main, name2A, 0, REG_DWORD, (const BYTE *)1, 1);
352 }
353
354 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
355 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
356 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
357 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
358
359 ret = RegSetValueW(hkey_main, name1W, REG_SZ, string1W, sizeof(string1W));
360 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
361 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
362 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
363
364 /* RegSetValueW ignores the size passed in */
365 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
366 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
367 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
368 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
369
370 /* stops at first null */
371 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
372 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
373 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
374 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
375
376 /* only REG_SZ is supported */
377 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
378 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
379 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
380 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
381 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
382 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
383
384 /* test RegSetValueExW with off-by-one size */
385 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
386 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
387 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
388 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
389
390 /* test RegSetValueExW with normal string */
391 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
392 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
393 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
394 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
395
396 /* test RegSetValueExW with intrazeroed string */
397 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
398 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
399 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
400 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
401
402 /* test RegSetValueExW with data = 1 */
403 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)1, 1);
404 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
405 ret = RegSetValueExW(hkey_main, name2W, 0, REG_DWORD, (const BYTE *)1, 1);
406 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
407 }
408
409 static void create_test_entries(void)
410 {
411 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
412
413 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
414 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
415
416 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
417 "RegSetValueExA failed\n");
418 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
419 "RegSetValueExA failed\n");
420 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
421 "RegSetValueExA failed\n");
422 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
423 "RegSetValueExA failed\n");
424 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
425 "RegSetValueExA failed\n");
426 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
427 "RegSetValueExA failed\n");
428 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
429 "RegSetValueExA failed\n");
430 }
431
432 static void test_enum_value(void)
433 {
434 DWORD res;
435 HKEY test_key;
436 char value[20], data[20];
437 WCHAR valueW[20], dataW[20];
438 DWORD val_count, data_count, type;
439 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
440 static const WCHAR testW[] = {'T','e','s','t',0};
441 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
442
443 /* create the working key for new 'Test' value */
444 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
445 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
446
447 /* check NULL data with zero length */
448 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
449 if (GetVersion() & 0x80000000)
450 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
451 else
452 ok( !res, "RegSetValueExA returned %d\n", res );
453 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
454 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
455 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
456 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
457
458 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
459 ok( res == 0, "RegSetValueExA failed error %d\n", res );
460
461 /* overflow both name and data */
462 val_count = 2;
463 data_count = 2;
464 type = 1234;
465 strcpy( value, "xxxxxxxxxx" );
466 strcpy( data, "xxxxxxxxxx" );
467 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
468 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
469 ok( val_count == 2, "val_count set to %d\n", val_count );
470 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
471 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
472 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
473 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
474
475 /* overflow name */
476 val_count = 3;
477 data_count = 20;
478 type = 1234;
479 strcpy( value, "xxxxxxxxxx" );
480 strcpy( data, "xxxxxxxxxx" );
481 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
482 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
483 ok( val_count == 3, "val_count set to %d\n", val_count );
484 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
485 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
486 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
487 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
488 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
489 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
490 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
491
492 /* overflow empty name */
493 val_count = 0;
494 data_count = 20;
495 type = 1234;
496 strcpy( value, "xxxxxxxxxx" );
497 strcpy( data, "xxxxxxxxxx" );
498 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
499 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
500 ok( val_count == 0, "val_count set to %d\n", val_count );
501 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
502 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
503 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
504 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
505 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
506 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
507
508 /* overflow data */
509 val_count = 20;
510 data_count = 2;
511 type = 1234;
512 strcpy( value, "xxxxxxxxxx" );
513 strcpy( data, "xxxxxxxxxx" );
514 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
515 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
516 ok( val_count == 20, "val_count set to %d\n", val_count );
517 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
518 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
519 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
520 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
521
522 /* no overflow */
523 val_count = 20;
524 data_count = 20;
525 type = 1234;
526 strcpy( value, "xxxxxxxxxx" );
527 strcpy( data, "xxxxxxxxxx" );
528 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
529 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
530 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
531 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
532 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
533 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
534 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
535
536 /* Unicode tests */
537
538 SetLastError(0xdeadbeef);
539 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
540 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
541 {
542 win_skip("RegSetValueExW is not implemented\n");
543 goto cleanup;
544 }
545 ok( res == 0, "RegSetValueExW failed error %d\n", res );
546
547 /* overflow both name and data */
548 val_count = 2;
549 data_count = 2;
550 type = 1234;
551 memcpy( valueW, xxxW, sizeof(xxxW) );
552 memcpy( dataW, xxxW, sizeof(xxxW) );
553 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
554 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
555 ok( val_count == 2, "val_count set to %d\n", val_count );
556 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
557 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
558 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
559 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
560
561 /* overflow name */
562 val_count = 3;
563 data_count = 20;
564 type = 1234;
565 memcpy( valueW, xxxW, sizeof(xxxW) );
566 memcpy( dataW, xxxW, sizeof(xxxW) );
567 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
568 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
569 ok( val_count == 3, "val_count set to %d\n", val_count );
570 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
571 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
572 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
573 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
574
575 /* overflow data */
576 val_count = 20;
577 data_count = 2;
578 type = 1234;
579 memcpy( valueW, xxxW, sizeof(xxxW) );
580 memcpy( dataW, xxxW, sizeof(xxxW) );
581 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
582 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
583 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
584 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
585 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
586 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
587 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
588
589 /* no overflow */
590 val_count = 20;
591 data_count = 20;
592 type = 1234;
593 memcpy( valueW, xxxW, sizeof(xxxW) );
594 memcpy( dataW, xxxW, sizeof(xxxW) );
595 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
596 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
597 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
598 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
599 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
600 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
601 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
602
603 cleanup:
604 RegDeleteKeyA(test_key, "");
605 RegCloseKey(test_key);
606 }
607
608 static void test_query_value_ex(void)
609 {
610 DWORD ret;
611 DWORD size;
612 DWORD type;
613 BYTE buffer[10];
614
615 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
616 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
617 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
618 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
619
620 type = 0xdeadbeef;
621 size = 0xdeadbeef;
622 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
623 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
624 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
625
626 size = sizeof(buffer);
627 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
628 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
629 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
630
631 size = 4;
632 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
633 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
634 }
635
636 static void test_get_value(void)
637 {
638 DWORD ret;
639 DWORD size;
640 DWORD type;
641 DWORD dw, qw[2];
642 CHAR buf[80];
643 CHAR expanded[] = "bar\\subdir1";
644 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
645
646 if(!pRegGetValueA)
647 {
648 win_skip("RegGetValue not available on this platform\n");
649 return;
650 }
651
652 /* Invalid parameter */
653 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
654 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
655
656 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
657 size = type = dw = 0xdeadbeef;
658 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
659 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
660 ok(size == 4, "size=%d\n", size);
661 ok(type == REG_DWORD, "type=%d\n", type);
662 ok(dw == 0x12345678, "dw=%d\n", dw);
663
664 /* Query by subkey-name */
665 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
666 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
667
668 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
669 size = type = dw = 0xdeadbeef;
670 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
671 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
672 /* Although the function failed all values are retrieved */
673 ok(size == 4, "size=%d\n", size);
674 ok(type == REG_DWORD, "type=%d\n", type);
675 ok(dw == 0x12345678, "dw=%d\n", dw);
676
677 /* Test RRF_ZEROONFAILURE */
678 type = dw = 0xdeadbeef; size = 4;
679 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
680 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
681 /* Again all values are retrieved ... */
682 ok(size == 4, "size=%d\n", size);
683 ok(type == REG_DWORD, "type=%d\n", type);
684 /* ... except the buffer, which is zeroed out */
685 ok(dw == 0, "dw=%d\n", dw);
686
687 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
688 type = size = 0xbadbeef;
689 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
690 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
691 ok(size == 4, "size=%d\n", size);
692 ok(type == REG_DWORD, "type=%d\n", type);
693
694 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
695 size = type = dw = 0xdeadbeef;
696 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
697 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
698 ok(size == 4, "size=%d\n", size);
699 ok(type == REG_DWORD, "type=%d\n", type);
700 ok(dw == 0x12345678, "dw=%d\n", dw);
701
702 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
703 size = type = dw = 0xdeadbeef;
704 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
705 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
706 ok(size == 4, "size=%d\n", size);
707 ok(type == REG_BINARY, "type=%d\n", type);
708 ok(dw == 0x12345678, "dw=%d\n", dw);
709
710 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
711 qw[0] = qw[1] = size = type = 0xdeadbeef;
712 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
713 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
714 ok(size == 8, "size=%d\n", size);
715 ok(type == REG_BINARY, "type=%d\n", type);
716 ok(qw[0] == 0x12345678 &&
717 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
718
719 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
720 type = dw = 0xdeadbeef; size = 4;
721 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
722 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
723 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
724 ok(size == 8, "size=%d\n", size);
725
726 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
727 qw[0] = qw[1] = size = type = 0xdeadbeef;
728 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
729 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
730 ok(size == 8, "size=%d\n", size);
731 ok(type == REG_BINARY, "type=%d\n", type);
732 ok(qw[0] == 0x12345678 &&
733 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
734
735 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
736 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
737 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
738 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
739 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
740 ok(type == REG_SZ, "type=%d\n", type);
741 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
742
743 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
744 type = 0xdeadbeef; size = 0;
745 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
746 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
747 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
748 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
749 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
750 ok(type == REG_SZ, "type=%d\n", type);
751
752 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
753 strcpy(buf, sTestpath1);
754 type = 0xdeadbeef;
755 size = sizeof(buf);
756 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
757 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
758 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
759 ok(size == 0 ||
760 size == 1, /* win2k3 */
761 "size=%d\n", size);
762 ok(type == REG_SZ, "type=%d\n", type);
763 ok(!strcmp(sTestpath1, buf) ||
764 !strcmp(buf, ""),
765 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
766
767 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
768 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
769 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
770 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
771 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
772 ok(type == REG_SZ, "type=%d\n", type);
773 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
774
775 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
776 size = 0;
777 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
778 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
779 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
780 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
781 (size == strlen(sTestpath2)+1),
782 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
783
784 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
785 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
786 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
787 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
788 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
789 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
790 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
791 ok(type == REG_SZ, "type=%d\n", type);
792 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
793
794 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
795 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
796 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
797 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
798 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
799 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
800 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
801 ok(type == REG_SZ, "type=%d\n", type);
802 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
803
804 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
805 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
806 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
807 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
808 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
809 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
810 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
811
812 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
813 size = 0xbadbeef;
814 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
815 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
816 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
817 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
818 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
819
820 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
821 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
822 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
823
824 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
825 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
826 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
827
828 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
829 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
830 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
831 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
832 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
833 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
834 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
835 ok(type == REG_SZ, "type=%d\n", type);
836 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
837 }
838
839 static void test_reg_open_key(void)
840 {
841 DWORD ret = 0;
842 HKEY hkResult = NULL;
843 HKEY hkPreserve = NULL;
844 HKEY hkRoot64 = NULL;
845 HKEY hkRoot32 = NULL;
846 BOOL bRet;
847 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
848 PSID world_sid;
849 EXPLICIT_ACCESSA access;
850 PACL key_acl;
851 SECURITY_DESCRIPTOR *sd;
852
853 /* successful open */
854 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
855 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
856 ok(hkResult != NULL, "expected hkResult != NULL\n");
857 hkPreserve = hkResult;
858
859 /* open same key twice */
860 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
861 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
862 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
863 ok(hkResult != NULL, "hkResult != NULL\n");
864 RegCloseKey(hkResult);
865
866 /* open nonexistent key
867 * check that hkResult is set to NULL
868 */
869 hkResult = hkPreserve;
870 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
871 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
872 ok(hkResult == NULL, "expected hkResult == NULL\n");
873
874 /* open the same nonexistent key again to make sure the key wasn't created */
875 hkResult = hkPreserve;
876 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
877 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
878 ok(hkResult == NULL, "expected hkResult == NULL\n");
879
880 /* send in NULL lpSubKey
881 * check that hkResult receives the value of hKey
882 */
883 hkResult = hkPreserve;
884 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
885 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
886 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
887
888 /* send empty-string in lpSubKey */
889 hkResult = hkPreserve;
890 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
891 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
892 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
893
894 /* send in NULL lpSubKey and NULL hKey
895 * hkResult is set to NULL
896 */
897 hkResult = hkPreserve;
898 ret = RegOpenKeyA(NULL, NULL, &hkResult);
899 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
900 ok(hkResult == NULL, "expected hkResult == NULL\n");
901
902 /* only send NULL hKey
903 * the value of hkResult remains unchanged
904 */
905 hkResult = hkPreserve;
906 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
907 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
908 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
909 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
910 RegCloseKey(hkResult);
911
912 /* send in NULL hkResult */
913 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
914 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
915
916 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
917 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
918
919 ret = RegOpenKeyA(NULL, NULL, NULL);
920 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
921
922 /* beginning backslash character */
923 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
924 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
925 broken(ret == ERROR_SUCCESS), /* wow64 */
926 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
927 if (!ret) RegCloseKey(hkResult);
928
929 hkResult = NULL;
930 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
931 ok(ret == ERROR_SUCCESS || /* 2k/XP */
932 ret == ERROR_BAD_PATHNAME, /* NT */
933 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
934 RegCloseKey(hkResult);
935
936 /* WOW64 flags */
937 hkResult = NULL;
938 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
939 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
940 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
941 RegCloseKey(hkResult);
942
943 hkResult = NULL;
944 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
945 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
946 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
947 RegCloseKey(hkResult);
948
949 /* Try using WOW64 flags when opening a key with a DACL set to verify that
950 * the registry access check is performed correctly. Redirection isn't
951 * being tested, so the tests don't care about whether the process is
952 * running under WOW64. */
953 if (!pIsWow64Process)
954 {
955 win_skip("WOW64 flags are not recognized\n");
956 return;
957 }
958
959 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
960 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
961 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
962 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
963
964 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
965 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
966 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
967 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
968
969 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
970 0, 0, 0, 0, 0, 0, 0, &world_sid);
971 ok(bRet == TRUE,
972 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
973
974 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
975 access.grfAccessMode = SET_ACCESS;
976 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
977 access.Trustee.pMultipleTrustee = NULL;
978 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
979 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
980 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
981 access.Trustee.ptstrName = (char *)world_sid;
982
983 ret = SetEntriesInAclA(1, &access, NULL, &key_acl);
984 ok(ret == ERROR_SUCCESS,
985 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret, GetLastError());
986
987 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
988 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
989 ok(bRet == TRUE,
990 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
991
992 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
993 ok(bRet == TRUE,
994 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
995
996 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
997 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
998 ok(bRet == TRUE,
999 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1000
1001 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1002 ok(bRet == TRUE,
1003 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1004
1005 hkResult = NULL;
1006 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
1007 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1008 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1009 RegCloseKey(hkResult);
1010
1011 hkResult = NULL;
1012 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
1013 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1014 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1015 RegCloseKey(hkResult);
1016
1017 HeapFree(GetProcessHeap(), 0, sd);
1018 LocalFree(key_acl);
1019 FreeSid(world_sid);
1020 RegDeleteKeyA(hkRoot64, "");
1021 RegCloseKey(hkRoot64);
1022 RegDeleteKeyA(hkRoot32, "");
1023 RegCloseKey(hkRoot32);
1024 }
1025
1026 static void test_reg_create_key(void)
1027 {
1028 LONG ret;
1029 HKEY hkey1, hkey2;
1030 HKEY hkRoot64 = NULL;
1031 HKEY hkRoot32 = NULL;
1032 DWORD dwRet;
1033 BOOL bRet;
1034 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1035 PSID world_sid;
1036 EXPLICIT_ACCESSA access;
1037 PACL key_acl;
1038 SECURITY_DESCRIPTOR *sd;
1039
1040 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1041 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1042 /* should succeed: all versions of Windows ignore the access rights
1043 * to the parent handle */
1044 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
1045 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1046
1047 /* clean up */
1048 RegDeleteKey(hkey2, "");
1049 RegDeleteKey(hkey1, "");
1050 RegCloseKey(hkey2);
1051 RegCloseKey(hkey1);
1052
1053 /* test creation of volatile keys */
1054 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
1055 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1056 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1057 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE, "RegCreateKeyExA failed with error %d\n", ret);
1058 if (!ret) RegCloseKey( hkey2 );
1059 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1060 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1061 RegCloseKey(hkey2);
1062 /* should succeed if the key already exists */
1063 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1064 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1065
1066 /* clean up */
1067 RegDeleteKey(hkey2, "");
1068 RegDeleteKey(hkey1, "");
1069 RegCloseKey(hkey2);
1070 RegCloseKey(hkey1);
1071
1072 /* beginning backslash character */
1073 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1074 if (!(GetVersion() & 0x80000000))
1075 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1076 else {
1077 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1078 RegDeleteKey(hkey1, NULL);
1079 RegCloseKey(hkey1);
1080 }
1081
1082 /* WOW64 flags - open an existing key */
1083 hkey1 = NULL;
1084 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1085 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1086 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1087 RegCloseKey(hkey1);
1088
1089 hkey1 = NULL;
1090 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1091 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1092 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1093 RegCloseKey(hkey1);
1094
1095 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1096 * the registry access check is performed correctly. Redirection isn't
1097 * being tested, so the tests don't care about whether the process is
1098 * running under WOW64. */
1099 if (!pIsWow64Process)
1100 {
1101 win_skip("WOW64 flags are not recognized\n");
1102 return;
1103 }
1104
1105 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1106 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1107 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1108 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1109
1110 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1111 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1112 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1113 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1114
1115 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1116 0, 0, 0, 0, 0, 0, 0, &world_sid);
1117 ok(bRet == TRUE,
1118 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1119
1120 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1121 access.grfAccessMode = SET_ACCESS;
1122 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1123 access.Trustee.pMultipleTrustee = NULL;
1124 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1125 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1126 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1127 access.Trustee.ptstrName = (char *)world_sid;
1128
1129 dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
1130 ok(ret == ERROR_SUCCESS,
1131 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
1132
1133 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1134 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1135 ok(bRet == TRUE,
1136 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1137
1138 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1139 ok(bRet == TRUE,
1140 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1141
1142 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1143 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1144 ok(bRet == TRUE,
1145 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1146
1147 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1148 ok(bRet == TRUE,
1149 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1150
1151 hkey1 = NULL;
1152 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1153 KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
1154 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1155 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1156 RegCloseKey(hkey1);
1157
1158 hkey1 = NULL;
1159 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1160 KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
1161 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1162 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1163 RegCloseKey(hkey1);
1164
1165 HeapFree(GetProcessHeap(), 0, sd);
1166 LocalFree(key_acl);
1167 FreeSid(world_sid);
1168 RegDeleteKeyA(hkRoot64, "");
1169 RegCloseKey(hkRoot64);
1170 RegDeleteKeyA(hkRoot32, "");
1171 RegCloseKey(hkRoot32);
1172 }
1173
1174 static void test_reg_close_key(void)
1175 {
1176 DWORD ret = 0;
1177 HKEY hkHandle;
1178
1179 /* successfully close key
1180 * hkHandle remains changed after call to RegCloseKey
1181 */
1182 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1183 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1184 ret = RegCloseKey(hkHandle);
1185 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1186
1187 /* try to close the key twice */
1188 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1189 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1190 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1191
1192 /* try to close a NULL handle */
1193 ret = RegCloseKey(NULL);
1194 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1195 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1196
1197 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1198 * win98 doesn't give a new handle when the same key is opened.
1199 * Not re-opening will make some next tests fail.
1200 */
1201 if (hkey_main == hkHandle)
1202 {
1203 trace("The main handle is most likely closed, so re-opening\n");
1204 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1205 }
1206 }
1207
1208 static void test_reg_delete_key(void)
1209 {
1210 DWORD ret;
1211
1212 ret = RegDeleteKey(hkey_main, NULL);
1213
1214 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1215 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1216 * Not re-creating will make some next tests fail.
1217 */
1218 if (ret == ERROR_SUCCESS)
1219 {
1220 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1221 " re-creating the main key\n");
1222 setup_main_key();
1223 }
1224 else
1225 ok(ret == ERROR_INVALID_PARAMETER ||
1226 ret == ERROR_ACCESS_DENIED ||
1227 ret == ERROR_BADKEY, /* Win95 */
1228 "ret=%d\n", ret);
1229 }
1230
1231 static void test_reg_save_key(void)
1232 {
1233 DWORD ret;
1234
1235 ret = RegSaveKey(hkey_main, "saved_key", NULL);
1236 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1237 }
1238
1239 static void test_reg_load_key(void)
1240 {
1241 DWORD ret;
1242 HKEY hkHandle;
1243
1244 ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1245 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1246
1247 ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1248 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1249
1250 RegCloseKey(hkHandle);
1251 }
1252
1253 static void test_reg_unload_key(void)
1254 {
1255 DWORD ret;
1256
1257 ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
1258 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1259
1260 DeleteFile("saved_key");
1261 DeleteFile("saved_key.LOG");
1262 }
1263
1264 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1265 {
1266 TOKEN_PRIVILEGES tp;
1267 HANDLE hToken;
1268 LUID luid;
1269
1270 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1271 return FALSE;
1272
1273 if(!LookupPrivilegeValue(NULL, privilege, &luid))
1274 {
1275 CloseHandle(hToken);
1276 return FALSE;
1277 }
1278
1279 tp.PrivilegeCount = 1;
1280 tp.Privileges[0].Luid = luid;
1281
1282 if (set)
1283 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1284 else
1285 tp.Privileges[0].Attributes = 0;
1286
1287 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1288 if (GetLastError() != ERROR_SUCCESS)
1289 {
1290 CloseHandle(hToken);
1291 return FALSE;
1292 }
1293
1294 CloseHandle(hToken);
1295 return TRUE;
1296 }
1297
1298 /* tests that show that RegConnectRegistry and
1299 OpenSCManager accept computer names without the
1300 \\ prefix (what MSDN says). */
1301 static void test_regconnectregistry( void)
1302 {
1303 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1304 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1305 DWORD len = sizeof(compName) ;
1306 BOOL ret;
1307 LONG retl;
1308 HKEY hkey;
1309 SC_HANDLE schnd;
1310
1311 SetLastError(0xdeadbeef);
1312 ret = GetComputerNameA(compName, &len);
1313 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1314 if( !ret) return;
1315
1316 lstrcpyA(netwName, "\\\\");
1317 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1318
1319 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1320 ok( !retl ||
1321 retl == ERROR_DLL_INIT_FAILED ||
1322 retl == ERROR_BAD_NETPATH, /* some win2k */
1323 "RegConnectRegistryA failed err = %d\n", retl);
1324 if( !retl) RegCloseKey( hkey);
1325
1326 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1327 ok( !retl ||
1328 retl == ERROR_DLL_INIT_FAILED ||
1329 retl == ERROR_BAD_NETPATH, /* some win2k */
1330 "RegConnectRegistryA failed err = %d\n", retl);
1331 if( !retl) RegCloseKey( hkey);
1332
1333 SetLastError(0xdeadbeef);
1334 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1335 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1336 {
1337 win_skip("OpenSCManagerA is not implemented\n");
1338 return;
1339 }
1340
1341 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1342 CloseServiceHandle( schnd);
1343
1344 SetLastError(0xdeadbeef);
1345 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1346 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1347 CloseServiceHandle( schnd);
1348
1349 }
1350
1351 static void test_reg_query_value(void)
1352 {
1353 HKEY subkey;
1354 CHAR val[MAX_PATH];
1355 WCHAR valW[5];
1356 LONG size, ret;
1357
1358 static const WCHAR expected[] = {'d','a','t','a',0};
1359
1360 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1361 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1362
1363 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1364 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1365
1366 /* try an invalid hkey */
1367 SetLastError(0xdeadbeef);
1368 size = MAX_PATH;
1369 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1370 ok(ret == ERROR_INVALID_HANDLE ||
1371 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1372 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1373 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1374 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1375
1376 /* try a NULL hkey */
1377 SetLastError(0xdeadbeef);
1378 size = MAX_PATH;
1379 ret = RegQueryValueA(NULL, "subkey", val, &size);
1380 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1381 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1382 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1383
1384 /* try a NULL value */
1385 size = MAX_PATH;
1386 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1387 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1388 ok(size == 5, "Expected 5, got %d\n", size);
1389
1390 /* try a NULL size */
1391 SetLastError(0xdeadbeef);
1392 val[0] = '\0';
1393 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1394 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1395 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1396 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1397
1398 /* try a NULL value and size */
1399 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1400 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1401
1402 /* try a size too small */
1403 SetLastError(0xdeadbeef);
1404 val[0] = '\0';
1405 size = 1;
1406 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1407 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1408 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1409 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1410 ok(size == 5, "Expected 5, got %d\n", size);
1411
1412 /* successfully read the value using 'subkey' */
1413 size = MAX_PATH;
1414 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1415 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1416 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1417 ok(size == 5, "Expected 5, got %d\n", size);
1418
1419 /* successfully read the value using the subkey key */
1420 size = MAX_PATH;
1421 ret = RegQueryValueA(subkey, NULL, val, &size);
1422 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1423 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1424 ok(size == 5, "Expected 5, got %d\n", size);
1425
1426 /* unicode - try size too small */
1427 SetLastError(0xdeadbeef);
1428 valW[0] = '\0';
1429 size = 0;
1430 ret = RegQueryValueW(subkey, NULL, valW, &size);
1431 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1432 {
1433 win_skip("RegQueryValueW is not implemented\n");
1434 goto cleanup;
1435 }
1436 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1437 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1438 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1439 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1440
1441 /* unicode - try size in WCHARS */
1442 SetLastError(0xdeadbeef);
1443 size = sizeof(valW) / sizeof(WCHAR);
1444 ret = RegQueryValueW(subkey, NULL, valW, &size);
1445 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1446 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1447 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1448 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1449
1450 /* unicode - successfully read the value */
1451 size = sizeof(valW);
1452 ret = RegQueryValueW(subkey, NULL, valW, &size);
1453 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1454 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1455 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1456
1457 /* unicode - set the value without a NULL terminator */
1458 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1459 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1460
1461 /* unicode - read the unterminated value, value is terminated for us */
1462 memset(valW, 'a', sizeof(valW));
1463 size = sizeof(valW);
1464 ret = RegQueryValueW(subkey, NULL, valW, &size);
1465 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1466 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1467 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1468
1469 cleanup:
1470 RegDeleteKeyA(subkey, "");
1471 RegCloseKey(subkey);
1472 }
1473
1474 static void test_string_termination(void)
1475 {
1476 HKEY subkey;
1477 LSTATUS ret;
1478 static const char string[] = "FullString";
1479 char name[11];
1480 BYTE buffer[11];
1481 DWORD insize, outsize, nsize;
1482
1483 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
1484 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1485
1486 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1487 insize=sizeof(string)-1;
1488 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1489 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1490 outsize=insize;
1491 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1492 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
1493
1494 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1495 insize=sizeof(string)-2;
1496 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1497 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1498 outsize=0;
1499 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
1500 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1501 ok(outsize == insize, "wrong size %u != %u\n", outsize, insize);
1502
1503 /* RegQueryValueExA may return a string with no trailing '\0' */
1504 outsize=insize;
1505 memset(buffer, 0xbd, sizeof(buffer));
1506 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1507 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1508 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1509 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1510 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1511 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1512
1513 /* RegQueryValueExA adds a trailing '\0' if there is room */
1514 outsize=insize+1;
1515 memset(buffer, 0xbd, sizeof(buffer));
1516 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1517 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1518 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1519 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1520 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1521 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1522
1523 /* RegEnumValueA may return a string with no trailing '\0' */
1524 outsize=insize;
1525 memset(buffer, 0xbd, sizeof(buffer));
1526 nsize=sizeof(name);
1527 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1528 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1529 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1530 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1531 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1532 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1533 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1534
1535 /* RegEnumValueA adds a trailing '\0' if there is room */
1536 outsize=insize+1;
1537 memset(buffer, 0xbd, sizeof(buffer));
1538 nsize=sizeof(name);
1539 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1540 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1541 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1542 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1543 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1544 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1545 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1546
1547 RegDeleteKeyA(subkey, "");
1548 RegCloseKey(subkey);
1549 }
1550
1551 static void test_reg_delete_tree(void)
1552 {
1553 CHAR buffer[MAX_PATH];
1554 HKEY subkey, subkey2;
1555 LONG size, ret;
1556
1557 if(!pRegDeleteTreeA) {
1558 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1559 return;
1560 }
1561
1562 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1563 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1564 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1565 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1566 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1567 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1568 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
1569 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1570 ret = RegCloseKey(subkey2);
1571 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1572
1573 ret = pRegDeleteTreeA(subkey, "subkey2");
1574 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1575 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1576 "subkey2 was not deleted\n");
1577 size = MAX_PATH;
1578 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1579 "Default value of subkey not longer present\n");
1580
1581 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1582 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1583 ret = RegCloseKey(subkey2);
1584 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1585 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
1586 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1587 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1588 "subkey2 was not deleted\n");
1589 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1590 "Default value of subkey not longer present\n");
1591
1592 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1593 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1594 ret = RegCloseKey(subkey2);
1595 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1596 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
1597 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1598 ret = RegCloseKey(subkey2);
1599 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1600 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
1601 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1602 ret = pRegDeleteTreeA(subkey, NULL);
1603 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1604 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
1605 "subkey was deleted\n");
1606 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1607 "subkey2 was not deleted\n");
1608 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
1609 "subkey3 was not deleted\n");
1610 size = MAX_PATH;
1611 ret = RegQueryValueA(subkey, NULL, buffer, &size);
1612 ok(ret == ERROR_SUCCESS,
1613 "Default value of subkey is not present\n");
1614 ok(!lstrlenA(buffer),
1615 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
1616 size = MAX_PATH;
1617 ok(RegQueryValueA(subkey, "value", buffer, &size),
1618 "Value is still present\n");
1619
1620 ret = pRegDeleteTreeA(hkey_main, "not-here");
1621 ok(ret == ERROR_FILE_NOT_FOUND,
1622 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1623 }
1624
1625 static void test_rw_order(void)
1626 {
1627 HKEY hKey;
1628 DWORD dw = 0;
1629 static char keyname[] = "test_rw_order";
1630 char value_buf[2];
1631 DWORD values, value_len, value_name_max_len;
1632 LSTATUS ret;
1633
1634 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
1635 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
1636 if(ret != ERROR_SUCCESS) {
1637 skip("Couldn't create key. Skipping.\n");
1638 return;
1639 }
1640
1641 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1642 "RegSetValueExA for value \"A\" failed\n");
1643 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1644 "RegSetValueExA for value \"C\" failed\n");
1645 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1646 "RegSetValueExA for value \"D\" failed\n");
1647 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1648 "RegSetValueExA for value \"B\" failed\n");
1649
1650 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
1651 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
1652 ok(values == 4, "Expected 4 values, got %u\n", values);
1653
1654 /* Value enumeration preserves RegSetValueEx call order */
1655 value_len = 2;
1656 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1657 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
1658 value_len = 2;
1659 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1660 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
1661 value_len = 2;
1662 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1663 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
1664 value_len = 2;
1665 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1666 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
1667
1668 ok(!RegDeleteKey(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
1669 }
1670
1671 static void test_symlinks(void)
1672 {
1673 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1674 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1675 BYTE buffer[1024];
1676 UNICODE_STRING target_str;
1677 WCHAR *target;
1678 HKEY key, link;
1679 NTSTATUS status;
1680 DWORD target_len, type, len, dw, err;
1681
1682 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
1683 {
1684 win_skip( "Can't perform symlink tests\n" );
1685 return;
1686 }
1687
1688 pRtlFormatCurrentUserKeyPath( &target_str );
1689
1690 target_len = target_str.Length + sizeof(targetW);
1691 target = HeapAlloc( GetProcessHeap(), 0, target_len );
1692 memcpy( target, target_str.Buffer, target_str.Length );
1693 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
1694
1695 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1696 KEY_ALL_ACCESS, NULL, &link, NULL );
1697 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
1698
1699 /* REG_SZ is not allowed */
1700 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
1701 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1702 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
1703 (BYTE *)target, target_len - sizeof(WCHAR) );
1704 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1705 /* other values are not allowed */
1706 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
1707 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1708
1709 /* try opening the target through the link */
1710
1711 err = RegOpenKeyA( hkey_main, "link", &key );
1712 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
1713
1714 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1715 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1716
1717 dw = 0xbeef;
1718 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1719 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1720 RegCloseKey( key );
1721
1722 err = RegOpenKeyA( hkey_main, "link", &key );
1723 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1724
1725 len = sizeof(buffer);
1726 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1727 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1728 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1729
1730 len = sizeof(buffer);
1731 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1732 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1733
1734 /* REG_LINK can be created in non-link keys */
1735 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
1736 (BYTE *)target, target_len - sizeof(WCHAR) );
1737 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1738 len = sizeof(buffer);
1739 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1740 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1741 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1742 err = RegDeleteValueA( key, "SymbolicLinkValue" );
1743 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
1744
1745 RegCloseKey( key );
1746
1747 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1748 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1749
1750 len = sizeof(buffer);
1751 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1752 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1753 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1754
1755 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1756 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1757 RegCloseKey( key );
1758
1759 /* now open the symlink itself */
1760
1761 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
1762 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
1763 len = sizeof(buffer);
1764 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1765 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1766 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1767 RegCloseKey( key );
1768
1769 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
1770 KEY_ALL_ACCESS, NULL, &key, NULL );
1771 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1772 len = sizeof(buffer);
1773 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1774 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1775 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1776 RegCloseKey( key );
1777
1778 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1779 KEY_ALL_ACCESS, NULL, &key, NULL );
1780 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1781
1782 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
1783 KEY_ALL_ACCESS, NULL, &key, NULL );
1784 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1785
1786 err = RegDeleteKey( hkey_main, "target" );
1787 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
1788
1789 err = RegDeleteKey( hkey_main, "link" );
1790 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
1791
1792 status = pNtDeleteKey( link );
1793 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
1794 RegCloseKey( link );
1795
1796 HeapFree( GetProcessHeap(), 0, target );
1797 pRtlFreeUnicodeString( &target_str );
1798 }
1799
1800 static const DWORD ptr_size = 8 * sizeof(void*);
1801
1802 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
1803 {
1804 HKEY key;
1805 DWORD err, type, dw, len = sizeof(dw);
1806
1807 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
1808 if (err == ERROR_FILE_NOT_FOUND) return 0;
1809 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
1810
1811 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
1812 if (err == ERROR_FILE_NOT_FOUND)
1813 dw = 0;
1814 else
1815 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
1816 RegCloseKey( key );
1817 return dw;
1818 }
1819
1820 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
1821 {
1822 DWORD dw = get_key_value( root, name, flags );
1823 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
1824 }
1825 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1826
1827 static void test_redirection(void)
1828 {
1829 DWORD err, type, dw, len;
1830 HKEY key, root32, root64, key32, key64;
1831 BOOL is_vista = FALSE;
1832
1833 if (ptr_size != 64)
1834 {
1835 BOOL is_wow64;
1836 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
1837 {
1838 skip( "Not on Wow64, no redirection\n" );
1839 return;
1840 }
1841 }
1842
1843 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1844 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
1845 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1846
1847 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1848 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
1849 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1850
1851 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1852 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
1853 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1854
1855 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1856 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
1857 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1858
1859 dw = 64;
1860 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1861 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1862
1863 dw = 32;
1864 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1865 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1866
1867 dw = 0;
1868 len = sizeof(dw);
1869 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
1870 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1871 ok( dw == 32, "wrong value %u\n", dw );
1872
1873 dw = 0;
1874 len = sizeof(dw);
1875 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
1876 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1877 ok( dw == 64, "wrong value %u\n", dw );
1878
1879 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1880 KEY_ALL_ACCESS, NULL, &key, NULL );
1881 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1882
1883 if (ptr_size == 32)
1884 {
1885 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1886 /* the new (and simpler) Win7 mechanism doesn't */
1887 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1888 {
1889 trace( "using Vista-style Wow6432Node handling\n" );
1890 is_vista = TRUE;
1891 }
1892 check_key_value( key, "Wine\\Winetest", 0, 32 );
1893 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1894 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1895 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1896 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1897 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1898 }
1899 else
1900 {
1901 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
1902 {
1903 trace( "using Vista-style Wow6432Node handling\n" );
1904 is_vista = TRUE;
1905 }
1906 check_key_value( key, "Wine\\Winetest", 0, 64 );
1907 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1908 }
1909 RegCloseKey( key );
1910
1911 if (ptr_size == 32)
1912 {
1913 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1914 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1915 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1916 dw = get_key_value( key, "Wine\\Winetest", 0 );
1917 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1918 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1919 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1920 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1921 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
1922 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
1923 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1924 RegCloseKey( key );
1925
1926 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1927 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1928 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1929 check_key_value( key, "Wine\\Winetest", 0, 32 );
1930 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1931 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1932 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1933 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1934 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1935 RegCloseKey( key );
1936 }
1937
1938 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
1939 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1940 if (ptr_size == 64)
1941 {
1942 /* KEY_WOW64 flags have no effect on 64-bit */
1943 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1944 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1945 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1946 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1947 }
1948 else
1949 {
1950 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1951 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1952 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1953 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1954 }
1955
1956 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1957 KEY_ALL_ACCESS, NULL, &key, NULL );
1958 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1959 check_key_value( key, "Wine\\Winetest", 0, 32 );
1960 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1961 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1962 RegCloseKey( key );
1963
1964 if (ptr_size == 32)
1965 {
1966 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1967 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1968 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1969 dw = get_key_value( key, "Wine\\Winetest", 0 );
1970 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1971 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1972 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1973 RegCloseKey( key );
1974
1975 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1976 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1977 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1978 check_key_value( key, "Wine\\Winetest", 0, 32 );
1979 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1980 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1981 RegCloseKey( key );
1982 }
1983
1984 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1985 KEY_ALL_ACCESS, NULL, &key, NULL );
1986 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1987 check_key_value( key, "Winetest", 0, 32 );
1988 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1989 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
1990 RegCloseKey( key );
1991
1992 if (ptr_size == 32)
1993 {
1994 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1995 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1996 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1997 dw = get_key_value( key, "Winetest", 0 );
1998 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
1999 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2000 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2001 RegCloseKey( key );
2002
2003 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2004 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2005 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2006 check_key_value( key, "Winetest", 0, 32 );
2007 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2008 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2009 RegCloseKey( key );
2010 }
2011
2012 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2013 KEY_ALL_ACCESS, NULL, &key, NULL );
2014 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2015 check_key_value( key, "Winetest", 0, ptr_size );
2016 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
2017 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2018 if (ptr_size == 32) ok( dw == 32, "wrong value %u\n", dw );
2019 else todo_wine ok( dw == 32, "wrong value %u\n", dw );
2020 RegCloseKey( key );
2021
2022 if (ptr_size == 32)
2023 {
2024 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2025 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2026 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2027 dw = get_key_value( key, "Winetest", 0 );
2028 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2029 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
2030 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2031 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2032 RegCloseKey( key );
2033
2034 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2035 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2036 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2037 check_key_value( key, "Winetest", 0, 32 );
2038 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2039 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2040 RegCloseKey( key );
2041 }
2042
2043 if (pRegDeleteKeyExA)
2044 {
2045 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
2046 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2047 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2048 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2049 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2050 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
2051 }
2052 else
2053 {
2054 err = RegDeleteKeyA( key32, "" );
2055 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2056 err = RegDeleteKeyA( key64, "" );
2057 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2058 RegDeleteKeyA( key64, "" );
2059 RegDeleteKeyA( root64, "" );
2060 }
2061 RegCloseKey( key32 );
2062 RegCloseKey( key64 );
2063 RegCloseKey( root32 );
2064 RegCloseKey( root64 );
2065 }
2066
2067 static void test_classesroot(void)
2068 {
2069 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
2070 DWORD size = 8;
2071 DWORD type = REG_SZ;
2072 static CHAR buffer[8];
2073 LONG res;
2074
2075 /* create a key in the user's classes */
2076 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
2077 {
2078 delete_key( hkey );
2079 RegCloseKey( hkey );
2080 }
2081 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2082 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL );
2083 if (res == ERROR_ACCESS_DENIED)
2084 {
2085 skip("not enough privileges to add a user class\n");
2086 return;
2087 }
2088
2089 /* try to open that key in hkcr */
2090 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2091 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2092 todo_wine ok(res == ERROR_SUCCESS ||
2093 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2094 "test key not found in hkcr: %d\n", res);
2095 if (res)
2096 {
2097 skip("HKCR key merging not supported\n");
2098 delete_key( hkey );
2099 RegCloseKey( hkey );
2100 return;
2101 }
2102
2103 /* set a value in user's classes */
2104 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2105 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2106
2107 /* try to find the value in hkcr */
2108 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
2109 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2110 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2111
2112 /* modify the value in hkcr */
2113 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2114 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2115
2116 /* check if the value is also modified in user's classes */
2117 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
2118 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2119 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2120
2121 /* set a value in hkcr */
2122 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2123 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2124
2125 /* try to find the value in user's classes */
2126 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
2127 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2128 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2129
2130 /* modify the value in user's classes */
2131 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2132 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2133
2134 /* check if the value is also modified in hkcr */
2135 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
2136 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2137 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2138
2139 /* cleanup */
2140 delete_key( hkey );
2141 delete_key( hkcr );
2142 RegCloseKey( hkey );
2143 RegCloseKey( hkcr );
2144
2145 /* create a key in the hklm classes */
2146 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2147 {
2148 delete_key( hklm );
2149 RegCloseKey( hklm );
2150 }
2151 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
2152 KEY_ALL_ACCESS, NULL, &hklm, NULL );
2153 if (res == ERROR_ACCESS_DENIED)
2154 {
2155 skip("not enough privileges to add a system class\n");
2156 return;
2157 }
2158
2159 /* try to open that key in hkcr */
2160 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2161 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2162 ok(res == ERROR_SUCCESS,
2163 "test key not found in hkcr: %d\n", res);
2164 if (res)
2165 {
2166 delete_key( hklm );
2167 RegCloseKey( hklm );
2168 return;
2169 }
2170
2171 /* set a value in hklm classes */
2172 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2173 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2174
2175 /* try to find the value in hkcr */
2176 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2177 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2178 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2179
2180 /* modify the value in hkcr */
2181 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2182 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2183
2184 /* check that the value is not modified in hklm classes */
2185 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2186 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2187 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2188
2189 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2190 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2191
2192 /* try to open that key in hkcr */
2193 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2194 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2195 ok(res == ERROR_SUCCESS,
2196 "test key not found in hkcr: %d\n", res);
2197
2198 /* set a value in user's classes */
2199 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2200 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2201
2202 /* try to find the value in hkcr */
2203 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2204 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2205 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2206
2207 /* modify the value in hklm */
2208 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2209 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2210
2211 /* check that the value is not overwritten in hkcr or user's classes */
2212 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2213 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2214 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2215 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2216 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2217 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2218
2219 /* modify the value in hkcr */
2220 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2221 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2222
2223 /* check that the value is overwritten in hklm and user's classes */
2224 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2225 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2226 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2227 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2228 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2229 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2230
2231 /* create a subkey in hklm */
2232 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2233 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2234 /* try to open that subkey in hkcr */
2235 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2236 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2237
2238 /* set a value in hklm classes */
2239 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2240 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2241
2242 /* try to find the value in hkcr */
2243 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2244 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2245 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2246
2247 /* modify the value in hkcr */
2248 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2249 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2250
2251 /* check that the value is modified in hklm classes */
2252 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2253 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2254 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2255
2256 /* create a subkey in user's classes */
2257 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2258 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2259
2260 /* set a value in user's classes */
2261 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2262 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2263
2264 /* try to find the value in hkcr */
2265 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2266 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2267 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2268
2269 /* modify the value in hklm */
2270 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2271 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2272
2273 /* check that the value is not overwritten in hkcr or user's classes */
2274 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2275 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2276 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2277 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2278 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2279 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2280
2281 /* modify the value in hkcr */
2282 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2283 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2284
2285 /* check that the value is not overwritten in hklm, but in user's classes */
2286 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2287 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2288 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2289 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2290 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2291 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2292
2293 /* new subkey in hkcr */
2294 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
2295 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
2296 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2297 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2298
2299 /* try to open that new subkey in user's classes and hklm */
2300 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2301 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
2302 hklmsub2 = 0;
2303 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2304 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2305
2306 /* check that the value is present in hklm */
2307 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2308 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2309 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2310
2311 /* final cleanup */
2312 delete_key( hkey );
2313 delete_key( hklm );
2314 delete_key( hkcr );
2315 delete_key( hkeysub1 );
2316 delete_key( hklmsub1 );
2317 delete_key( hkcrsub1 );
2318 delete_key( hklmsub2 );
2319 delete_key( hkcrsub2 );
2320 RegCloseKey( hkey );
2321 RegCloseKey( hklm );
2322 RegCloseKey( hkcr );
2323 RegCloseKey( hkeysub1 );
2324 RegCloseKey( hklmsub1 );
2325 RegCloseKey( hkcrsub1 );
2326 RegCloseKey( hklmsub2 );
2327 RegCloseKey( hkcrsub2 );
2328 }
2329
2330 static void test_deleted_key(void)
2331 {
2332 HKEY hkey, hkey2;
2333 char value[20];
2334 DWORD val_count, type;
2335 LONG res;
2336
2337 /* Open the test key, then delete it while it's open */
2338 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
2339
2340 delete_key( hkey_main );
2341
2342 val_count = sizeof(value);
2343 type = 0;
2344 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
2345 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2346
2347 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
2348 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2349
2350 val_count = sizeof(value);
2351 type = 0;
2352 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
2353 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2354
2355 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
2356 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2357
2358 res = RegOpenKeyA( hkey, "test", &hkey2 );
2359 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2360 if (res == 0)
2361 RegCloseKey( hkey2 );
2362
2363 res = RegCreateKeyA( hkey, "test", &hkey2 );
2364 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2365 if (res == 0)
2366 RegCloseKey( hkey2 );
2367
2368 res = RegFlushKey( hkey );
2369 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2370
2371 RegCloseKey( hkey );
2372
2373 setup_main_key();
2374 }
2375
2376 static void test_delete_value(void)
2377 {
2378 LONG res;
2379 char longname[401];
2380
2381 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
2382 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2383
2384 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2385 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2386
2387 res = RegDeleteValueA( hkey_main, "test" );
2388 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2389
2390 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2391 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2392
2393 res = RegDeleteValueA( hkey_main, "test" );
2394 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2395
2396 memset(longname, 'a', 400);
2397 longname[400] = 0;
2398 res = RegDeleteValueA( hkey_main, longname );
2399 ok(res == ERROR_FILE_NOT_FOUND || broken(res == ERROR_MORE_DATA), /* nt4, win2k */
2400 "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2401 }
2402
2403 START_TEST(registry)
2404 {
2405 /* Load pointers for functions that are not available in all Windows versions */
2406 InitFunctionPtrs();
2407
2408 setup_main_key();
2409 test_set_value();
2410 create_test_entries();
2411 test_enum_value();
2412 test_query_value_ex();
2413 test_get_value();
2414 test_reg_open_key();
2415 test_reg_create_key();
2416 test_reg_close_key();
2417 test_reg_delete_key();
2418 test_reg_query_value();
2419 test_string_termination();
2420 test_symlinks();
2421 test_redirection();
2422 test_classesroot();
2423
2424 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2425 if (set_privileges(SE_BACKUP_NAME, TRUE) &&
2426 set_privileges(SE_RESTORE_NAME, TRUE))
2427 {
2428 test_reg_save_key();
2429 test_reg_load_key();
2430 test_reg_unload_key();
2431
2432 set_privileges(SE_BACKUP_NAME, FALSE);
2433 set_privileges(SE_RESTORE_NAME, FALSE);
2434 }
2435
2436 test_reg_delete_tree();
2437 test_rw_order();
2438 test_deleted_key();
2439 test_delete_value();
2440
2441 /* cleanup */
2442 delete_key( hkey_main );
2443
2444 test_regconnectregistry();
2445 }