a0e8845e53f42c2a42e82ced907375b7336959d2
[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 CreateService
5 * PROGRAMMER: Thomas Faber <thomas.faber@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 > 0 && ((UINT_PTR)hk & 3) == 2)
17
18 static
19 void
20 Test_KeyInformation(void)
21 {
22 HKEY KeyHandle;
23 DWORD ErrorCode;
24 NTSTATUS Status;
25 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\Classes\\CLSID");
26 UNICODE_STRING InfoName;
27 CHAR Buffer[FIELD_OFFSET(KEY_NAME_INFORMATION, Name[512])];
28 PKEY_NAME_INFORMATION NameInfo = (PKEY_NAME_INFORMATION)Buffer;
29 ULONG ResultLength;
30
31
32 ErrorCode = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_READ, &KeyHandle);
33 ok_dec(ErrorCode, ERROR_SUCCESS);
34 ok(IS_HKCR(KeyHandle), "\n");
35
36 Status = NtQueryKey(KeyHandle, KeyNameInformation, NameInfo, sizeof(Buffer), &ResultLength);
37 ok_ntstatus(Status, STATUS_SUCCESS);
38 RtlInitUnicodeString(&InfoName, NameInfo->Name);
39 InfoName.Length = NameInfo->NameLength;
40 ok(RtlCompareUnicodeString(&KeyName, &InfoName, TRUE) == 0, "%.*S\n", InfoName.Length, InfoName.Buffer);
41
42 RegCloseKey(KeyHandle);
43 }
44
45 static
46 void
47 Test_DuplicateHandle(void)
48 {
49 HKEY KeyHandle, DupHandle;
50 DWORD ErrorCode;
51 BOOL Duplicated;
52 NTSTATUS Status;
53 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\Classes\\CLSID");
54 UNICODE_STRING InfoName;
55 CHAR Buffer[FIELD_OFFSET(KEY_NAME_INFORMATION, Name[512])];
56 PKEY_NAME_INFORMATION NameInfo = (PKEY_NAME_INFORMATION)Buffer;
57 ULONG ResultLength;
58
59
60 ErrorCode = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_READ, &KeyHandle);
61 ok_dec(ErrorCode, ERROR_SUCCESS);
62 ok(IS_HKCR(KeyHandle), "\n");
63
64 Duplicated = DuplicateHandle(GetCurrentProcess(), KeyHandle, GetCurrentProcess(), (PHANDLE)&DupHandle, 0, 0, DUPLICATE_SAME_ACCESS);
65 ok(Duplicated, "\n");
66 ok(DupHandle != NULL, "\n");
67 ok(!IS_HKCR(DupHandle), "\n");
68
69 Status = NtQueryKey(DupHandle, KeyNameInformation, NameInfo, sizeof(Buffer), &ResultLength);
70 ok_ntstatus(Status, STATUS_SUCCESS);
71 RtlInitUnicodeString(&InfoName, NameInfo->Name);
72 InfoName.Length = NameInfo->NameLength;
73 ok(RtlCompareUnicodeString(&KeyName, &InfoName, TRUE) == 0, "%S\n", NameInfo->Name);
74
75 RegCloseKey(KeyHandle);
76 RegCloseKey(DupHandle);
77 }
78
79 START_TEST(HKEY_CLASSES_ROOT)
80 {
81 Test_KeyInformation();
82 Test_DuplicateHandle();
83 }