2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Tests for the NtQueryKey API
5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12 #include <ndk/cmfuncs.h>
13 #include <ndk/cmtypes.h>
14 #include <ndk/obfuncs.h>
18 Test_KeyNameInformation(void)
20 UNICODE_STRING HKLM_Name
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine");
21 UNICODE_STRING HKLM_Software_Name
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software");
22 UNICODE_STRING Software_Name
= RTL_CONSTANT_STRING(L
"Software");
23 UNICODE_STRING InfoName
;
24 HANDLE HKLM_Key
, HKLM_Software_Key
;
25 PKEY_NAME_INFORMATION NameInformation
;
27 OBJECT_ATTRIBUTES ObjectAttributes
;
30 /* Open the HKCU key */
31 InitializeObjectAttributes(&ObjectAttributes
,
36 Status
= NtOpenKey(&HKLM_Key
, KEY_READ
, &ObjectAttributes
);
37 ok_ntstatus(Status
, STATUS_SUCCESS
);
39 /* Get the name info length */
41 Status
= NtQueryKey(HKLM_Key
, KeyNameInformation
, NULL
, 0, &InfoLength
);
42 ok_ntstatus(Status
, STATUS_BUFFER_TOO_SMALL
);
43 ok_size_t(InfoLength
, FIELD_OFFSET(KEY_NAME_INFORMATION
, Name
[HKLM_Name
.Length
/sizeof(WCHAR
)]));
46 NameInformation
= RtlAllocateHeap(RtlGetProcessHeap(), 0, InfoLength
);
47 ok(NameInformation
!= NULL
, "\n");
49 Status
= NtQueryKey(HKLM_Key
, KeyNameInformation
, NameInformation
, InfoLength
, &InfoLength
);
50 ok_ntstatus(Status
, STATUS_SUCCESS
);
51 ok_size_t(InfoLength
, FIELD_OFFSET(KEY_NAME_INFORMATION
, Name
[HKLM_Name
.Length
/sizeof(WCHAR
)]));
52 ok_size_t(NameInformation
->NameLength
, HKLM_Name
.Length
);
54 RtlInitUnicodeString(&InfoName
, NameInformation
->Name
);
55 InfoName
.Length
= NameInformation
->NameLength
;
56 ok(RtlCompareUnicodeString(&InfoName
, &HKLM_Name
, TRUE
) == 0, "%.*S\n",
57 InfoName
.Length
, InfoName
.Buffer
);
59 RtlFreeHeap(RtlGetProcessHeap(), 0, NameInformation
);
62 InitializeObjectAttributes(&ObjectAttributes
,
67 Status
= NtOpenKey(&HKLM_Software_Key
, KEY_READ
, &ObjectAttributes
);
68 ok_ntstatus(Status
, STATUS_SUCCESS
);
70 /* Get the name info length */
72 Status
= NtQueryKey(HKLM_Software_Key
, KeyNameInformation
, NULL
, 0, &InfoLength
);
73 ok_ntstatus(Status
, STATUS_BUFFER_TOO_SMALL
);
74 ok_size_t(InfoLength
, FIELD_OFFSET(KEY_NAME_INFORMATION
, Name
[HKLM_Software_Name
.Length
/sizeof(WCHAR
)]));
77 NameInformation
= RtlAllocateHeap(RtlGetProcessHeap(), 0, InfoLength
);
78 ok(NameInformation
!= NULL
, "\n");
80 Status
= NtQueryKey(HKLM_Software_Key
, KeyNameInformation
, NameInformation
, InfoLength
, &InfoLength
);
81 ok_ntstatus(Status
, STATUS_SUCCESS
);
82 ok_size_t(InfoLength
, FIELD_OFFSET(KEY_NAME_INFORMATION
, Name
[HKLM_Software_Name
.Length
/sizeof(WCHAR
)]));
83 ok_size_t(NameInformation
->NameLength
, HKLM_Software_Name
.Length
);
85 RtlInitUnicodeString(&InfoName
, NameInformation
->Name
);
86 InfoName
.Length
= NameInformation
->NameLength
;
87 ok(RtlCompareUnicodeString(&InfoName
, &HKLM_Software_Name
, TRUE
) == 0, "%.*S\n",
88 InfoName
.Length
, InfoName
.Buffer
);
90 RtlFreeHeap(RtlGetProcessHeap(), 0, NameInformation
);
92 NtClose(HKLM_Software_Key
);
96 START_TEST(NtQueryKey
)
98 Test_KeyNameInformation();