2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/test.h"
30 static HKEY hkey_main
;
32 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
33 static const char * sTestpath2
= "%FOO%\\subdir1";
35 /* delete key and all its subkeys */
36 static DWORD
delete_key( HKEY hkey
)
41 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
44 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
46 ret
= delete_key( tmp
);
51 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
52 RegDeleteKeyA( hkey
, "" );
56 static void setup_main_key(void)
58 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
60 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
63 static void create_test_entries(void)
65 DWORD qw
[2] = { 0x12345678, 0x87654321 };
67 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
68 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
70 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (LPBYTE
)sTestpath1
, strlen(sTestpath1
)+1),
71 "RegSetValueExA failed\n");
72 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (LPBYTE
)sTestpath1
, strlen(sTestpath1
)+1),
73 "RegSetValueExA failed\n");
74 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (LPBYTE
)sTestpath2
, strlen(sTestpath2
)+1),
75 "RegSetValueExA failed\n");
76 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (LPBYTE
)qw
, 4),
77 "RegSetValueExA failed\n");
78 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (LPBYTE
)qw
, 4),
79 "RegSetValueExA failed\n");
80 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (LPBYTE
)qw
, 8),
81 "RegSetValueExA failed\n");
84 static void test_enum_value(void)
88 char value
[20], data
[20];
89 WCHAR valueW
[20], dataW
[20];
90 DWORD val_count
, data_count
, type
;
91 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
92 static const WCHAR testW
[] = {'T','e','s','t',0};
93 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
95 /* create the working key for new 'Test' value */
96 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
97 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", res
);
99 /* check NULL data with zero length */
100 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
101 if (GetVersion() & 0x80000000)
102 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %ld\n", res
);
104 ok( !res
, "RegSetValueExA returned %ld\n", res
);
105 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
106 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %ld\n", res
);
107 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
108 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %ld\n", res
);
110 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (BYTE
*)"foobar", 7 );
111 ok( res
== 0, "RegSetValueExA failed error %ld\n", res
);
113 /* overflow both name and data */
117 strcpy( value
, "xxxxxxxxxx" );
118 strcpy( data
, "xxxxxxxxxx" );
119 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
120 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
121 ok( val_count
== 2, "val_count set to %ld\n", val_count
);
122 ok( data_count
== 7, "data_count set to %ld instead of 7\n", data_count
);
123 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
124 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
125 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
131 strcpy( value
, "xxxxxxxxxx" );
132 strcpy( data
, "xxxxxxxxxx" );
133 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
134 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
135 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
136 ok( val_count
== 2 || val_count
== 3, "val_count set to %ld\n", val_count
);
137 ok( data_count
== 7, "data_count set to %ld instead of 7\n", data_count
);
138 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
140 /* v5.1.2600.0 (XP Home) does not touch value or data in this case */
141 ok( !strcmp( value
, "Te" ), "value set to '%s' instead of 'Te'\n", value
);
142 ok( !strcmp( data
, "foobar" ), "data set to '%s' instead of 'foobar'\n", data
);
145 /* overflow empty name */
149 strcpy( value
, "xxxxxxxxxx" );
150 strcpy( data
, "xxxxxxxxxx" );
151 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
152 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
153 ok( val_count
== 0, "val_count set to %ld\n", val_count
);
154 ok( data_count
== 7, "data_count set to %ld instead of 7\n", data_count
);
155 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
156 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
158 /* v5.1.2600.0 (XP Home) does not touch data in this case */
159 ok( !strcmp( data
, "foobar" ), "data set to '%s' instead of 'foobar'\n", data
);
166 strcpy( value
, "xxxxxxxxxx" );
167 strcpy( data
, "xxxxxxxxxx" );
168 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
169 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
170 ok( val_count
== 20, "val_count set to %ld\n", val_count
);
171 ok( data_count
== 7, "data_count set to %ld instead of 7\n", data_count
);
172 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
173 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
174 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
180 strcpy( value
, "xxxxxxxxxx" );
181 strcpy( data
, "xxxxxxxxxx" );
182 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
183 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", res
);
184 ok( val_count
== 4, "val_count set to %ld instead of 4\n", val_count
);
185 ok( data_count
== 7, "data_count set to %ld instead of 7\n", data_count
);
186 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
187 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
188 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
193 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
194 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
196 ok( res
== 0, "RegSetValueExW failed error %ld\n", res
);
198 /* overflow both name and data */
202 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
203 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
204 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
205 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
206 ok( val_count
== 2, "val_count set to %ld\n", val_count
);
207 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count
);
208 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
209 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
210 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
216 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
217 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
218 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
219 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
220 ok( val_count
== 3, "val_count set to %ld\n", val_count
);
221 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count
);
222 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
223 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
224 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
230 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
231 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
232 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
233 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld\n", res
);
234 ok( val_count
== 4, "val_count set to %ld instead of 4\n", val_count
);
235 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count
);
236 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
237 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
238 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
244 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
245 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
246 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
247 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", res
);
248 ok( val_count
== 4, "val_count set to %ld instead of 4\n", val_count
);
249 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count
);
250 ok( type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
251 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
252 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
255 static void test_query_value_ex(void)
261 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
262 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
263 ok(size
== strlen(sTestpath1
) + 1, "(%ld,%ld)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
264 ok(type
== REG_SZ
, "type %ld is not REG_SZ\n", type
);
267 static void test_get_value(void)
270 DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
277 CHAR expanded
[] = "bar\\subdir1";
279 /* This function was introduced with Windows 2003 SP1 */
280 hadvapi32
= LoadLibraryA("advapi32.dll");
283 ok(0, "error=%ld\n", GetLastError());
286 pRegGetValueA
= (PVOID
)GetProcAddress(hadvapi32
, "RegGetValueA");
290 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
291 size
= type
= dw
= 0xdeadbeef;
292 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
293 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
294 ok(size
== 4, "size=%ld\n", size
);
295 ok(type
== REG_DWORD
, "type=%ld\n", type
);
296 ok(dw
== 0x12345678, "dw=%ld\n", dw
);
298 /* Query by subkey-name */
299 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
300 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
302 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
303 size
= type
= dw
= 0xdeadbeef;
304 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
305 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%ld\n", ret
);
306 /* Although the function failed all values are retrieved */
307 ok(size
== 4, "size=%ld\n", size
);
308 ok(type
== REG_DWORD
, "type=%ld\n", type
);
309 ok(dw
== 0x12345678, "dw=%ld\n", dw
);
311 /* Test RRF_ZEROONFAILURE */
312 type
= dw
= 0xdeadbeef; size
= 4;
313 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
314 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%ld\n", ret
);
315 /* Again all values are retrieved ... */
316 ok(size
== 4, "size=%ld\n", size
);
317 ok(type
== REG_DWORD
, "type=%ld\n", type
);
318 /* ... except the buffer, which is zeroed out */
319 ok(dw
== 0, "dw=%ld\n", dw
);
321 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
322 size
= type
= dw
= 0xdeadbeef;
323 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
324 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
325 ok(size
== 4, "size=%ld\n", size
);
326 ok(type
== REG_DWORD
, "type=%ld\n", type
);
327 ok(dw
== 0x12345678, "dw=%ld\n", dw
);
329 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
330 size
= type
= dw
= 0xdeadbeef;
331 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
332 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
333 ok(size
== 4, "size=%ld\n", size
);
334 ok(type
== REG_BINARY
, "type=%ld\n", type
);
335 ok(dw
== 0x12345678, "dw=%ld\n", dw
);
337 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
338 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
339 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
340 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%ld\n", ret
);
341 ok(size
== 8, "size=%ld\n", size
);
342 ok(type
== REG_BINARY
, "type=%ld\n", type
);
343 ok(qw
[0] == 0x12345678 &&
344 qw
[1] == 0x87654321, "qw={%ld,%ld}\n", qw
[0], qw
[1]);
346 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
347 type
= dw
= 0xdeadbeef; size
= 4;
348 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
349 ok(ret
== ERROR_MORE_DATA
, "ret=%ld\n", ret
);
350 ok(dw
== 0xdeadbeef, "dw=%ld\n", dw
);
351 ok(size
== 8, "size=%ld\n", size
);
353 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
354 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
355 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
356 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
357 ok(size
== 8, "size=%ld\n", size
);
358 ok(type
== REG_BINARY
, "type=%ld\n", type
);
359 ok(qw
[0] == 0x12345678 &&
360 qw
[1] == 0x87654321, "qw={%ld,%ld}\n", qw
[0], qw
[1]);
362 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
363 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
364 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
365 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
366 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%ld\n", strlen(sTestpath1
), size
);
367 ok(type
== REG_SZ
, "type=%ld\n", type
);
368 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
370 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
371 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
372 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
373 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
374 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%ld\n", strlen(sTestpath1
), size
);
375 ok(type
== REG_SZ
, "type=%ld\n", type
);
376 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
378 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
379 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
380 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
381 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
383 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded length + 1 here. */
384 ok(size
== strlen(expanded
)+1, "strlen(expanded)=%ld size=%ld\n", strlen(expanded
), size
);
386 ok(type
== REG_SZ
, "type=%ld\n", type
);
387 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
389 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
390 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
391 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
392 ok(ret
== ERROR_SUCCESS
, "ret=%ld\n", ret
);
393 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%ld\n", strlen(sTestpath1
), size
);
394 ok(type
== REG_EXPAND_SZ
, "type=%ld\n", type
);
395 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
397 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
398 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
399 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%ld\n", ret
);
401 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
402 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
403 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%ld\n", ret
);
406 static void test_reg_open_key(void)
409 HKEY hkResult
= NULL
;
410 HKEY hkPreserve
= NULL
;
412 /* successful open */
413 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
414 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
415 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
416 hkPreserve
= hkResult
;
418 /* these tests fail on Win9x, but we want to be compatible with NT, so
419 * run them if we can */
420 if (!(GetVersion() & 0x80000000))
422 /* open same key twice */
423 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
424 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
425 ok(hkResult
!= hkPreserve
, "epxected hkResult != hkPreserve\n");
426 ok(hkResult
!= NULL
, "hkResult != NULL\n");
427 RegCloseKey(hkResult
);
429 /* open nonexistent key
430 * check that hkResult is set to NULL
432 hkResult
= hkPreserve
;
433 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
434 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret
);
435 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
437 /* open the same nonexistent key again to make sure the key wasn't created */
438 hkResult
= hkPreserve
;
439 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
440 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret
);
441 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
443 /* send in NULL lpSubKey
444 * check that hkResult receives the value of hKey
446 hkResult
= hkPreserve
;
447 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
448 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
449 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
451 /* send empty-string in lpSubKey */
452 hkResult
= hkPreserve
;
453 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
454 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
455 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
457 /* send in NULL lpSubKey and NULL hKey
458 * hkResult is set to NULL
460 hkResult
= hkPreserve
;
461 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
462 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
463 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
466 /* only send NULL hKey
467 * the value of hkResult remains unchanged
469 hkResult
= hkPreserve
;
470 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
471 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
472 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret
);
473 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
474 RegCloseKey(hkResult
);
476 /* send in NULL hkResult */
477 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
478 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret
);
481 static void test_reg_create_key(void)
485 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
486 ok(!ret
, "RegCreateKeyExA failed with error %ld\n", ret
);
487 /* should succeed: all versions of Windows ignore the access rights
488 * to the parent handle */
489 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
490 ok(!ret
, "RegCreateKeyExA failed with error %ld\n", ret
);
493 RegDeleteKey(hkey2
, NULL
);
494 RegDeleteKey(hkey1
, NULL
);
497 static void test_reg_close_key(void)
502 /* successfully close key
503 * hkHandle remains changed after call to RegCloseKey
505 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
506 ret
= RegCloseKey(hkHandle
);
507 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
509 /* try to close the key twice */
510 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
511 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
512 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %ld\n", ret
);
514 /* try to close a NULL handle */
515 ret
= RegCloseKey(NULL
);
516 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
517 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret
);
520 static void test_reg_delete_key(void)
524 ret
= RegDeleteKey(hkey_main
, NULL
);
525 ok(ret
== ERROR_INVALID_PARAMETER
||
526 ret
== ERROR_ACCESS_DENIED
||
527 ret
== ERROR_BADKEY
, /* Win95 */
531 static void test_reg_save_key(void)
535 ret
= RegSaveKey(hkey_main
, "saved_key", NULL
);
536 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
539 static void test_reg_load_key(void)
544 ret
= RegLoadKey(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
545 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
547 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
548 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
550 RegCloseKey(hkHandle
);
553 static void test_reg_unload_key(void)
557 ret
= RegUnLoadKey(HKEY_LOCAL_MACHINE
, "Test");
558 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld\n", ret
);
560 DeleteFile("saved_key");
563 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
569 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
572 if(!LookupPrivilegeValue(NULL
, privilege
, &luid
))
578 tp
.PrivilegeCount
= 1;
579 tp
.Privileges
[0].Luid
= luid
;
582 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
584 tp
.Privileges
[0].Attributes
= 0;
586 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
587 if (GetLastError() != ERROR_SUCCESS
)
597 /* tests that show that RegConnectRegistry and
598 OpenSCManager accept computer names without the
599 \\ prefix (what MSDN says). */
600 static void test_regconnectregistry( void)
602 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
603 DWORD len
= sizeof(compName
) ;
609 ret
= GetComputerNameA(compName
, &len
);
610 ok( ret
, "GetComputerName failed err = %ld\n", GetLastError());
613 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
614 ok( !retl
, "RegConnectRegistryA failed err = %ld\n", retl
);
615 if( !retl
) RegCloseKey( hkey
);
617 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
618 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %ld\n", GetLastError());
619 CloseServiceHandle( schnd
);
626 create_test_entries();
628 test_query_value_ex();
631 test_reg_create_key();
632 test_reg_close_key();
633 test_reg_delete_key();
635 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
636 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
637 set_privileges(SE_RESTORE_NAME
, TRUE
))
641 test_reg_unload_key();
643 set_privileges(SE_BACKUP_NAME
, FALSE
);
644 set_privileges(SE_RESTORE_NAME
, FALSE
);
648 delete_key( hkey_main
);
650 test_regconnectregistry();