diff --git a/rostests/apitests/advapi32/HKEY_CLASSES_ROOT.c b/rostests/apitests/advapi32/HKEY_CLASSES_ROOT.c index a0e8845e53f..bc3b64830ec 100644 --- a/rostests/apitests/advapi32/HKEY_CLASSES_ROOT.c +++ b/rostests/apitests/advapi32/HKEY_CLASSES_ROOT.c @@ -1,8 +1,8 @@ /* * PROJECT: ReactOS api tests * LICENSE: GPLv2+ - See COPYING in the top level directory - * PURPOSE: Test for CreateService - * PROGRAMMER: Thomas Faber + * PURPOSE: Test for the HKEY_CLASSES_ROOT key + * PROGRAMMER: Jérôme Gardou */ #include diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index 03309b83c16..57bb3056167 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND SOURCE NtMapViewOfSection.c NtMutant.c NtProtectVirtualMemory.c + NtQueryKey.c NtQuerySystemEnvironmentValue.c NtQueryVolumeInformationFile.c NtSaveKey.c diff --git a/rostests/apitests/ntdll/NtQueryKey.c b/rostests/apitests/ntdll/NtQueryKey.c new file mode 100644 index 00000000000..b94cf852fdd --- /dev/null +++ b/rostests/apitests/ntdll/NtQueryKey.c @@ -0,0 +1,99 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Tests for the NtQueryKey API + * PROGRAMMER: Jérôme Gardou + */ + +#include + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +static +void +Test_KeyNameInformation(void) +{ + UNICODE_STRING HKLM_Name = RTL_CONSTANT_STRING(L"\\Registry\\Machine"); + UNICODE_STRING HKLM_Software_Name = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software"); + UNICODE_STRING Software_Name = RTL_CONSTANT_STRING(L"Software"); + UNICODE_STRING InfoName; + HANDLE HKLM_Key, HKLM_Software_Key; + PKEY_NAME_INFORMATION NameInformation; + ULONG InfoLength; + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS Status; + + /* Open the HKCU key */ + InitializeObjectAttributes(&ObjectAttributes, + &HKLM_Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtOpenKey(&HKLM_Key, KEY_READ, &ObjectAttributes); + ok_ntstatus(Status, STATUS_SUCCESS); + + /* Get the name info length */ + InfoLength = 0; + Status = NtQueryKey(HKLM_Key, KeyNameInformation, NULL, 0, &InfoLength); + ok_ntstatus(Status, STATUS_BUFFER_TOO_SMALL); + ok_size_t(InfoLength, FIELD_OFFSET(KEY_NAME_INFORMATION, Name[HKLM_Name.Length/sizeof(WCHAR)])); + + /* Get it for real */ + NameInformation = RtlAllocateHeap(RtlGetProcessHeap(), 0, InfoLength); + ok(NameInformation != NULL, "\n"); + + Status = NtQueryKey(HKLM_Key, KeyNameInformation, NameInformation, InfoLength, &InfoLength); + ok_ntstatus(Status, STATUS_SUCCESS); + ok_size_t(InfoLength, FIELD_OFFSET(KEY_NAME_INFORMATION, Name[HKLM_Name.Length/sizeof(WCHAR)])); + ok_size_t(NameInformation->NameLength, HKLM_Name.Length); + + RtlInitUnicodeString(&InfoName, NameInformation->Name); + InfoName.Length = NameInformation->NameLength; + ok(RtlCompareUnicodeString(&InfoName, &HKLM_Name, TRUE) == 0, "%.*S\n", + InfoName.Length, InfoName.Buffer); + + RtlFreeHeap(RtlGetProcessHeap(), 0, NameInformation); + + /* Open one subkey */ + InitializeObjectAttributes(&ObjectAttributes, + &Software_Name, + OBJ_CASE_INSENSITIVE, + HKLM_Key, + NULL); + Status = NtOpenKey(&HKLM_Software_Key, KEY_READ, &ObjectAttributes); + ok_ntstatus(Status, STATUS_SUCCESS); + + /* Get the name info length */ + InfoLength = 0; + Status = NtQueryKey(HKLM_Software_Key, KeyNameInformation, NULL, 0, &InfoLength); + ok_ntstatus(Status, STATUS_BUFFER_TOO_SMALL); + ok_size_t(InfoLength, FIELD_OFFSET(KEY_NAME_INFORMATION, Name[HKLM_Software_Name.Length/sizeof(WCHAR)])); + + /* Get it for real */ + NameInformation = RtlAllocateHeap(RtlGetProcessHeap(), 0, InfoLength); + ok(NameInformation != NULL, "\n"); + + Status = NtQueryKey(HKLM_Software_Key, KeyNameInformation, NameInformation, InfoLength, &InfoLength); + ok_ntstatus(Status, STATUS_SUCCESS); + ok_size_t(InfoLength, FIELD_OFFSET(KEY_NAME_INFORMATION, Name[HKLM_Software_Name.Length/sizeof(WCHAR)])); + ok_size_t(NameInformation->NameLength, HKLM_Software_Name.Length); + + RtlInitUnicodeString(&InfoName, NameInformation->Name); + InfoName.Length = NameInformation->NameLength; + ok(RtlCompareUnicodeString(&InfoName, &HKLM_Software_Name, TRUE) == 0, "%.*S\n", + InfoName.Length, InfoName.Buffer); + + RtlFreeHeap(RtlGetProcessHeap(), 0, NameInformation); + + NtClose(HKLM_Software_Key); + NtClose(HKLM_Key); +} + +START_TEST(NtQueryKey) +{ + Test_KeyNameInformation(); +} diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index 69fc3db2920..365c7d4e7f2 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -13,6 +13,7 @@ extern void func_NtFreeVirtualMemory(void); extern void func_NtMapViewOfSection(void); extern void func_NtMutant(void); extern void func_NtProtectVirtualMemory(void); +extern void func_NtQueryKey(void); extern void func_NtQuerySystemEnvironmentValue(void); extern void func_NtQueryVolumeInformationFile(void); extern void func_NtSaveKey(void); @@ -44,6 +45,7 @@ const struct test winetest_testlist[] = { "NtMapViewOfSection", func_NtMapViewOfSection }, { "NtMutant", func_NtMutant }, { "NtProtectVirtualMemory", func_NtProtectVirtualMemory }, + { "NtQueryKey", func_NtQueryKey }, { "NtQuerySystemEnvironmentValue", func_NtQuerySystemEnvironmentValue }, { "NtQueryVolumeInformationFile", func_NtQueryVolumeInformationFile }, { "NtSaveKey", func_NtSaveKey},