[ADVAPI32_APITEST]: Rename the 'LockDatabase' test to 'LockServiceDatabase' to better...
[reactos.git] / rostests / apitests / advapi32 / HKEY_CLASSES_ROOT.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for the HKEY_CLASSES_ROOT key
5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <winreg.h>
12 #include <ndk/rtlfuncs.h>
13 #include <ndk/cmfuncs.h>
14 #include <ndk/cmtypes.h>
15
16 #define IS_HKCR(hk) (((UINT_PTR)hk & 3) == 2)
17
18 /* HKCU and HKLM system paths */
19 static UNICODE_STRING HKLM_ClassesPath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\Classes");
20 static UNICODE_STRING HKCU_ClassesPath;
21
22 static
23 LONG
24 DeleteSubKey(HKEY hKey, LPWSTR Root, LPWSTR SubKey)
25 {
26 HKEY RootKey;
27 LONG ErrorCode;
28
29 ErrorCode = RegOpenKeyExW(
30 hKey,
31 Root,
32 0,
33 MAXIMUM_ALLOWED,
34 &RootKey);
35 ok_dec(ErrorCode, ERROR_SUCCESS);
36 ErrorCode = RegDeleteKeyW(RootKey, SubKey);
37 RegCloseKey(RootKey);
38
39 return ErrorCode;
40 }
41
42 static
43 void
44 GetKeyName(HKEY hKey, PUNICODE_STRING KeyName)
45 {
46 UNICODE_STRING InfoName;
47 PKEY_NAME_INFORMATION NameInformation;
48 ULONG InfoLength;
49 NTSTATUS Status;
50
51 /* Get info length */
52 InfoLength = 0;
53 Status = NtQueryKey(hKey, KeyNameInformation, NULL, 0, &InfoLength);
54 ok_ntstatus(Status, STATUS_BUFFER_TOO_SMALL);
55
56 /* Get it for real */
57 NameInformation = RtlAllocateHeap(RtlGetProcessHeap(), 0, InfoLength);
58 ok(NameInformation != NULL, "\n");
59
60 Status = NtQueryKey(hKey, KeyNameInformation, NameInformation, InfoLength, &InfoLength);
61 ok_ntstatus(Status, STATUS_SUCCESS);
62
63 InfoName.Buffer = NameInformation->Name;
64 InfoName.Length = NameInformation->NameLength;
65 InfoName.MaximumLength = InfoName.Length;
66
67 RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, &InfoName, KeyName);
68
69 RtlFreeHeap(RtlGetProcessHeap(), 0, NameInformation);
70 }
71
72 static void _test_key_deleted(HKEY hKey, BOOL Deleted, ULONG LineNumber)
73 {
74 DWORD ErrorCode = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
75 if (Deleted)
76 ok_(__FILE__, LineNumber)(ErrorCode == ERROR_KEY_DELETED, "\n");
77 else
78 ok_(__FILE__, LineNumber)(ErrorCode == ERROR_SUCCESS, "\n");
79 }
80 #define ok_key_deleted(hKey) _test_key_deleted(hKey, TRUE, __LINE__)
81 #define ok_key_not_deleted(hKey) _test_key_deleted(hKey, FALSE, __LINE__)
82
83 static void _test_key_name(HKEY hKey, PUNICODE_STRING Prefix, LPCWSTR Name, ULONG LineNumber)
84 {
85 UNICODE_STRING ExpectedName, KeyName;
86 WCHAR Buffer[1024];
87
88 ExpectedName.Length = 0;
89 ExpectedName.MaximumLength = sizeof(Buffer);
90 ExpectedName.Buffer = Buffer;
91
92 RtlAppendUnicodeStringToString(&ExpectedName, Prefix);
93 RtlAppendUnicodeToString(&ExpectedName, L"\\");
94 RtlAppendUnicodeToString(&ExpectedName, Name);
95
96 GetKeyName(hKey, &KeyName);
97
98 ok_(__FILE__, LineNumber)(RtlCompareUnicodeString(&KeyName, &ExpectedName, TRUE) == 0,
99 "Key name is %.*S, expected %.*S\n",
100 KeyName.Length, KeyName.Buffer,
101 ExpectedName.Length, ExpectedName.Buffer);
102
103 RtlFreeUnicodeString(&KeyName);
104 }
105
106 #define ok_key_name(hKey, Prefix, Name) _test_key_name(hKey, Prefix, Name, __LINE__)
107
108 static
109 void
110 Test_CreateOpenKey(void)
111 {
112 HKEY MachineKey, MachineSubKey;
113 HKEY UserKey, UserSubKey;
114 HKEY ClassesRootKey, ClassesRootSubKey;
115 DWORD ErrorCode;
116 DWORD Disposition;
117
118 /* First create a subkey in HKLM */
119 ErrorCode = RegCreateKeyExW(
120 HKEY_LOCAL_MACHINE,
121 L"Software\\Classes\\Apitest_HKLM",
122 0,
123 NULL,
124 0,
125 MAXIMUM_ALLOWED,
126 NULL,
127 &MachineKey,
128 NULL);
129
130 if (ErrorCode == ERROR_ACCESS_DENIED)
131 {
132 win_skip("Please run those tests with Administrator rights\n");
133 return;
134 }
135
136 ok_dec(ErrorCode, ERROR_SUCCESS);
137 ok(!IS_HKCR(MachineKey), "\n");
138
139 /* Open it in HKCR */
140 ErrorCode = RegOpenKeyExW(
141 HKEY_CLASSES_ROOT,
142 L"Apitest_HKLM",
143 0,
144 MAXIMUM_ALLOWED,
145 &ClassesRootKey);
146 ok_dec(ErrorCode, ERROR_SUCCESS);
147 ok(IS_HKCR(ClassesRootKey), "\n");
148 ok_key_name(ClassesRootKey, &HKLM_ClassesPath, L"Apitest_HKLM");
149
150 /* Try opening it in HKCU */
151 UserKey = (HKEY)0xCAFEF00D;
152 ErrorCode = RegOpenKeyExW(
153 HKEY_CURRENT_USER,
154 L"Software\\Classes\\Apitest_HKLM",
155 0,
156 MAXIMUM_ALLOWED,
157 &UserKey);
158 ok_dec(ErrorCode, ERROR_FILE_NOT_FOUND);
159 ok_hdl(UserKey, NULL);
160
161 /* Cleanup */
162 RegCloseKey(ClassesRootKey);
163 RegCloseKey(MachineKey);
164 ErrorCode = DeleteSubKey(HKEY_LOCAL_MACHINE, L"Software\\Classes", L"Apitest_HKLM");
165 ok_dec(ErrorCode, ERROR_SUCCESS);
166
167 /* Try creating in HKCR */
168 ErrorCode = RegCreateKeyExW(
169 HKEY_CLASSES_ROOT,
170 L"Apitest_HKCR",
171 0,
172 NULL,
173 0,
174 MAXIMUM_ALLOWED,
175 NULL,
176 &ClassesRootKey,
177 NULL);
178 ok_dec(ErrorCode, ERROR_SUCCESS);
179 ok(IS_HKCR(ClassesRootKey), "\n");
180 ok_key_name(ClassesRootKey, &HKLM_ClassesPath, L"Apitest_HKCR");
181
182 /* It should be present in HKLM */
183 ErrorCode = RegOpenKeyExW(
184 HKEY_LOCAL_MACHINE,
185 L"Software\\Classes\\Apitest_HKCR",
186 0,
187 MAXIMUM_ALLOWED,
188 &MachineKey);
189 ok_dec(ErrorCode, ERROR_SUCCESS);
190 ok(!IS_HKCR(MachineKey), "\n");
191
192 /* But not in HKCU */
193 UserKey = (HKEY)0xCAFEF00D;
194 ErrorCode = RegOpenKeyExW(
195 HKEY_CURRENT_USER,
196 L"Software\\Classes\\Apitest_HKCR",
197 0,
198 MAXIMUM_ALLOWED,
199 &UserKey);
200 ok_dec(ErrorCode, ERROR_FILE_NOT_FOUND);
201 ok_hdl(UserKey, NULL);
202
203 /* This must delete the one in HKLM */
204 ErrorCode = RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKCR");
205 ok_dec(ErrorCode, ERROR_SUCCESS);
206 ok_key_deleted(ClassesRootKey);
207 ok_key_deleted(MachineKey);
208 RegCloseKey(ClassesRootKey);
209 RegCloseKey(MachineKey);
210
211 /* Test that it is really not present anymore */
212 MachineKey = (HKEY)0xCAFEF00D;
213 ErrorCode = RegOpenKeyExW(
214 HKEY_LOCAL_MACHINE,
215 L"Software\\Classes\\Apitest_HKCR",
216 0,
217 MAXIMUM_ALLOWED,
218 &MachineKey);
219 ok_dec(ErrorCode, ERROR_FILE_NOT_FOUND);
220 ok_hdl(MachineKey, NULL);
221
222 /* Try creating in HKCU */
223 ErrorCode = RegCreateKeyExW(
224 HKEY_CURRENT_USER,
225 L"Software\\Classes\\Apitest_HKCU",
226 0,
227 NULL,
228 0,
229 MAXIMUM_ALLOWED,
230 NULL,
231 &UserKey,
232 NULL);
233 ok_dec(ErrorCode, ERROR_SUCCESS);
234 ok(!IS_HKCR(UserKey), "\n");
235
236 /* Try opening it in HKCR */
237 ErrorCode = RegOpenKeyExW(
238 HKEY_CLASSES_ROOT,
239 L"Apitest_HKCU",
240 0,
241 MAXIMUM_ALLOWED,
242 &ClassesRootKey);
243 ok_dec(ErrorCode, ERROR_SUCCESS);
244 ok(IS_HKCR(ClassesRootKey), "\n");
245 ok_key_name(ClassesRootKey, &HKCU_ClassesPath, L"Apitest_HKCU");
246
247 /* And in HKLM */
248 ErrorCode = RegOpenKeyExW(
249 HKEY_LOCAL_MACHINE,
250 L"Software\\Classes\\Apitest_HKCU",
251 0,
252 MAXIMUM_ALLOWED,
253 &MachineKey);
254 ok_dec(ErrorCode, ERROR_FILE_NOT_FOUND);
255 ok_hdl(MachineKey, NULL);
256
257 ErrorCode = RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKCU");
258 ok_dec(ErrorCode, ERROR_SUCCESS);
259 ok_key_deleted(ClassesRootKey);
260 ok_key_deleted(UserKey);
261 RegCloseKey(ClassesRootKey);
262 RegCloseKey(UserKey);
263
264 /* Test that it is really not present anymore */
265 UserKey = (HKEY)0xCAFEF00D;
266 ErrorCode = RegOpenKeyExW(
267 HKEY_CURRENT_USER,
268 L"Software\\Classes\\Apitest_HKCU",
269 0,
270 MAXIMUM_ALLOWED,
271 &UserKey);
272 ok_dec(ErrorCode, ERROR_FILE_NOT_FOUND);
273 ok_hdl(UserKey, NULL);
274
275 /* Try creating in both HKLM and HKCU */
276 ErrorCode = RegCreateKeyExW(
277 HKEY_CURRENT_USER,
278 L"Software\\Classes\\Apitest_HKLM_HKCU",
279 0,
280 NULL,
281 0,
282 MAXIMUM_ALLOWED,
283 NULL,
284 &UserKey,
285 NULL);
286 ok_dec(ErrorCode, ERROR_SUCCESS);
287 ok(!IS_HKCR(UserKey), "\n");
288
289 ErrorCode = RegCreateKeyExW(
290 HKEY_LOCAL_MACHINE,
291 L"Software\\Classes\\Apitest_HKLM_HKCU",
292 0,
293 NULL,
294 0,
295 MAXIMUM_ALLOWED,
296 NULL,
297 &MachineKey,
298 NULL);
299 ok_dec(ErrorCode, ERROR_SUCCESS);
300 ok(!IS_HKCR(MachineKey), "\n");
301
302 /* Open it in HKCR */
303 ErrorCode = RegOpenKeyExW(
304 HKEY_CLASSES_ROOT,
305 L"Apitest_HKLM_HKCU",
306 0,
307 MAXIMUM_ALLOWED,
308 &ClassesRootKey);
309 ok_dec(ErrorCode, ERROR_SUCCESS);
310 ok(IS_HKCR(ClassesRootKey), "\n");
311 /* Verify it has opened the HKCU one */
312 ok_key_name(ClassesRootKey, &HKCU_ClassesPath, L"Apitest_HKLM_HKCU");
313
314 /* Try the same thing, but this time with RegCreateKeyEx API */
315 RegCloseKey(ClassesRootKey);
316 ErrorCode = RegCreateKeyExW(
317 HKEY_CLASSES_ROOT,
318 L"Apitest_HKLM_HKCU",
319 0,
320 NULL,
321 0,
322 MAXIMUM_ALLOWED,
323 NULL,
324 &ClassesRootKey,
325 &Disposition);
326 ok_dec(ErrorCode, ERROR_SUCCESS);
327 ok(IS_HKCR(ClassesRootKey), "\n");
328 /* Verify it has opened the HKCU one */
329 ok_key_name(ClassesRootKey, &HKCU_ClassesPath, L"Apitest_HKLM_HKCU");
330 ok_hex(Disposition, REG_OPENED_EXISTING_KEY);
331
332 /* Deleting it from HKCR first deletes the one in HKCU */
333 ErrorCode = RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKLM_HKCU");
334 ok_dec(ErrorCode, ERROR_SUCCESS);
335 ok_key_deleted(UserKey);
336 ok_key_deleted(ClassesRootKey);
337 ok_key_not_deleted(MachineKey);
338
339 RegCloseKey(UserKey);
340 RegCloseKey(ClassesRootKey);
341
342 /* This deletes it from HKLM this time */
343 ErrorCode = RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKLM_HKCU");
344 ok_dec(ErrorCode, ERROR_SUCCESS);
345 ok_key_deleted(MachineKey);
346 RegCloseKey(MachineKey);
347
348 /* See what happens with subkeys */
349 ErrorCode = RegCreateKeyExW(
350 HKEY_LOCAL_MACHINE,
351 L"Software\\Classes\\Apitest_HKLM",
352 0,
353 NULL,
354 0,
355 MAXIMUM_ALLOWED,
356 NULL,
357 &MachineKey,
358 NULL);
359 ok_dec(ErrorCode, ERROR_SUCCESS);
360 ok(!IS_HKCR(MachineKey), "\n");
361
362 /* Open it in HKCR */
363 ErrorCode = RegOpenKeyExW(
364 HKEY_CLASSES_ROOT,
365 L"Apitest_HKLM",
366 0,
367 MAXIMUM_ALLOWED,
368 &ClassesRootKey);
369 ok_dec(ErrorCode, ERROR_SUCCESS);
370 ok(IS_HKCR(ClassesRootKey), "\n");
371 ok_key_name(ClassesRootKey, &HKLM_ClassesPath, L"Apitest_HKLM");
372
373 /* Create a corresponding subkey in HKCU */
374 ErrorCode = RegCreateKeyExW(
375 HKEY_CURRENT_USER,
376 L"Software\\Classes\\Apitest_HKLM\\HKCU_Subkey",
377 0,
378 NULL,
379 0,
380 MAXIMUM_ALLOWED,
381 NULL,
382 &UserSubKey,
383 NULL);
384 ok_dec(ErrorCode, ERROR_SUCCESS);
385 ok(!IS_HKCR(UserSubKey), "\n");
386
387 /* Open it as an HKCR subkey */
388 ErrorCode = RegOpenKeyExW(
389 ClassesRootKey,
390 L"HKCU_Subkey",
391 0,
392 MAXIMUM_ALLOWED,
393 &ClassesRootSubKey);
394 ok_dec(ErrorCode, ERROR_SUCCESS);
395 ok(IS_HKCR(ClassesRootSubKey), "\n");
396 ok_key_name(ClassesRootSubKey, &HKCU_ClassesPath, L"Apitest_HKLM\\HKCU_Subkey");
397
398 /* Try the same thing, but this time with RegCreateKeyEx API */
399 RegCloseKey(ClassesRootSubKey);
400 ErrorCode = RegCreateKeyExW(
401 ClassesRootKey,
402 L"HKCU_Subkey",
403 0,
404 NULL,
405 0,
406 MAXIMUM_ALLOWED,
407 NULL,
408 &ClassesRootSubKey,
409 &Disposition);
410 ok_dec(ErrorCode, ERROR_SUCCESS);
411 ok(IS_HKCR(ClassesRootSubKey), "\n");
412 /* Verify it has opened the HKCU one */
413 ok_key_name(ClassesRootSubKey, &HKCU_ClassesPath, L"Apitest_HKLM\\HKCU_Subkey");
414 ok_hex(Disposition, REG_OPENED_EXISTING_KEY);
415
416 /* This one now exists */
417 ErrorCode = RegOpenKeyExW(
418 HKEY_CURRENT_USER,
419 L"Software\\Classes\\Apitest_HKLM",
420 0,
421 MAXIMUM_ALLOWED,
422 &UserKey);
423 ok_dec(ErrorCode, ERROR_SUCCESS);
424 ok(!IS_HKCR(UserKey), "\n");
425
426 /* Delete */
427 ErrorCode = RegDeleteKeyW(UserKey, L"HKCU_Subkey");
428 ok_dec(ErrorCode, ERROR_SUCCESS);
429 ok_key_deleted(UserSubKey);
430 ok_key_deleted(ClassesRootSubKey);
431 RegCloseKey(UserSubKey);
432 RegCloseKey(ClassesRootSubKey);
433
434 /* See what this deletes */
435 RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKLM");
436 ok_key_deleted(UserKey);
437 RegCloseKey(UserKey);
438 ok_key_not_deleted(ClassesRootKey);
439 ok_key_not_deleted(MachineKey);
440
441 /* Once again */
442 RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKLM");
443 ok_key_deleted(ClassesRootKey);
444 ok_key_deleted(MachineKey);
445 RegCloseKey(ClassesRootKey);
446 RegCloseKey(MachineKey);
447
448 /* Same, but with HKCU first */
449 ErrorCode = RegCreateKeyExW(
450 HKEY_CURRENT_USER,
451 L"Software\\Classes\\Apitest_HKCU",
452 0,
453 NULL,
454 0,
455 MAXIMUM_ALLOWED,
456 NULL,
457 &UserKey,
458 NULL);
459 ok_dec(ErrorCode, ERROR_SUCCESS);
460 ok(!IS_HKCR(UserKey), "\n");
461
462 /* Open it in HKCR */
463 ErrorCode = RegOpenKeyExW(
464 HKEY_CLASSES_ROOT,
465 L"Apitest_HKCU",
466 0,
467 MAXIMUM_ALLOWED,
468 &ClassesRootKey);
469 ok_dec(ErrorCode, ERROR_SUCCESS);
470 ok(IS_HKCR(ClassesRootKey), "\n");
471 ok_key_name(ClassesRootKey, &HKCU_ClassesPath, L"Apitest_HKCU");
472
473 /* Try creating a subkey with this HKCR handle, which points to a subkey in HKCU. */
474 ErrorCode = RegCreateKeyExW(
475 ClassesRootKey,
476 L"HKCR_Subkey",
477 0,
478 NULL,
479 0,
480 MAXIMUM_ALLOWED,
481 NULL,
482 &ClassesRootSubKey,
483 NULL);
484 ok_dec(ErrorCode, ERROR_SUCCESS);
485 ok(IS_HKCR(ClassesRootSubKey), "\n");
486 /* It is in fact created in HKLM */
487 ok_key_name(ClassesRootSubKey, &HKLM_ClassesPath, L"Apitest_HKCU\\HKCR_Subkey");
488 /* Let's see if we can delete it */
489 RegDeleteKeyW(ClassesRootKey, L"HKCR_Subkey");
490 ok_key_deleted(ClassesRootSubKey);
491 RegCloseKey(ClassesRootSubKey);
492
493 /* Create a corresponding subkey in HKLM */
494 ErrorCode = RegCreateKeyExW(
495 HKEY_LOCAL_MACHINE,
496 L"Software\\Classes\\Apitest_HKCU\\HKLM_Subkey",
497 0,
498 NULL,
499 0,
500 MAXIMUM_ALLOWED,
501 NULL,
502 &MachineSubKey,
503 NULL);
504 ok_dec(ErrorCode, ERROR_SUCCESS);
505 ok(!IS_HKCR(MachineSubKey), "\n");
506
507 /* Open it from the HKCR handle (which is still pointing to HKCU) */
508 ok_key_name(ClassesRootKey, &HKCU_ClassesPath, L"Apitest_HKCU");
509 ErrorCode = RegOpenKeyExW(
510 ClassesRootKey,
511 L"HKLM_Subkey",
512 0,
513 MAXIMUM_ALLOWED,
514 &ClassesRootSubKey);
515 ok_dec(ErrorCode, ERROR_SUCCESS);
516 ok(IS_HKCR(ClassesRootSubKey), "\n");
517 ok_key_name(ClassesRootSubKey, &HKLM_ClassesPath, L"Apitest_HKCU\\HKLM_Subkey");
518
519 /* This one now exists */
520 ErrorCode = RegOpenKeyExW(
521 HKEY_LOCAL_MACHINE,
522 L"Software\\Classes\\Apitest_HKCU",
523 0,
524 MAXIMUM_ALLOWED,
525 &MachineKey);
526 ok_dec(ErrorCode, ERROR_SUCCESS);
527 ok(!IS_HKCR(MachineKey), "\n");
528
529 /* Delete this subkey */
530 ErrorCode = RegDeleteKeyW(MachineKey, L"HKLM_Subkey");
531 ok_dec(ErrorCode, ERROR_SUCCESS);
532 ok_key_deleted(MachineSubKey);
533 ok_key_deleted(ClassesRootSubKey);
534
535 /* Create another subkey, this time from HKCU */
536 ErrorCode = RegCreateKeyExW(
537 HKEY_CURRENT_USER,
538 L"Software\\Classes\\Apitest_HKCU\\HKCU_Subkey",
539 0,
540 NULL,
541 0,
542 MAXIMUM_ALLOWED,
543 NULL,
544 &UserSubKey,
545 NULL);
546 ok_dec(ErrorCode, ERROR_SUCCESS);
547 ok(!IS_HKCR(UserSubKey), "\n");
548
549 /* And try creating it again as a subkey of this HKCR handle (which points to HKCU). */
550 ok_key_name(ClassesRootKey, &HKCU_ClassesPath, L"Apitest_HKCU");
551 ErrorCode = RegCreateKeyExW(
552 ClassesRootKey,
553 L"HKCU_Subkey",
554 0,
555 NULL,
556 0,
557 MAXIMUM_ALLOWED,
558 NULL,
559 &ClassesRootSubKey,
560 &Disposition);
561 ok_dec(ErrorCode, ERROR_SUCCESS);
562 ok(IS_HKCR(ClassesRootSubKey), "\n");
563 /* This time the one in HKCU is opened */
564 ok_key_name(ClassesRootSubKey, &HKCU_ClassesPath, L"Apitest_HKCU\\HKCU_Subkey");
565 ok_hex(Disposition, REG_OPENED_EXISTING_KEY);
566 /* Let's see if we can delete it */
567 RegDeleteKeyW(ClassesRootKey, L"HKCU_Subkey");
568 ok_key_deleted(ClassesRootSubKey);
569 RegCloseKey(ClassesRootSubKey);
570 ok_key_deleted(UserSubKey);
571 RegCloseKey(UserSubKey);
572
573 RegCloseKey(MachineSubKey);
574 RegCloseKey(ClassesRootSubKey);
575
576 /* See what this deletes */
577 RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKCU");
578 ok_key_deleted(UserKey);
579 RegCloseKey(UserKey);
580 ok_key_deleted(ClassesRootKey);
581 RegCloseKey(UserKey);
582 ok_key_not_deleted(MachineKey);
583
584 /* Once again */
585 RegDeleteKeyW(HKEY_CLASSES_ROOT, L"Apitest_HKCU");
586 ok_key_deleted(MachineKey);
587 RegCloseKey(MachineKey);
588 }
589
590 static
591 void
592 Test_DuplicateHandle(void)
593 {
594 HKEY KeyHandle, DupHandle;
595 DWORD ErrorCode;
596 BOOL Duplicated;
597
598 ErrorCode = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_READ, &KeyHandle);
599 ok_dec(ErrorCode, ERROR_SUCCESS);
600 ok(IS_HKCR(KeyHandle), "\n");
601
602 Duplicated = DuplicateHandle(GetCurrentProcess(), KeyHandle, GetCurrentProcess(), (PHANDLE)&DupHandle, 0, 0, DUPLICATE_SAME_ACCESS);
603 ok(Duplicated, "\n");
604 ok(DupHandle != NULL, "\n");
605 ok(!IS_HKCR(DupHandle), "\n");
606
607 RegCloseKey(KeyHandle);
608 RegCloseKey(DupHandle);
609 }
610
611 START_TEST(HKEY_CLASSES_ROOT)
612 {
613 HKEY UserKey;
614 LONG ErrorCode;
615
616 /* Get HKCU real key name */
617 ErrorCode = RegOpenKeyExW(
618 HKEY_CURRENT_USER,
619 L"Software\\Classes",
620 0,
621 KEY_READ,
622 &UserKey);
623 ok_dec(ErrorCode, ERROR_SUCCESS);
624 GetKeyName(UserKey, &HKCU_ClassesPath);
625 RegCloseKey(UserKey);
626
627 Test_CreateOpenKey();
628 Test_DuplicateHandle();
629 }