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