[NTDLL_APITEST]
authorJérôme Gardou <jerome.gardou@reactos.org>
Mon, 29 Sep 2014 16:21:53 +0000 (16:21 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Mon, 29 Sep 2014 16:21:53 +0000 (16:21 +0000)
 - Add tests for NtQueryKey(KeyNameInformation)
[ADVAPI32_APITEST]
 - Don't be so generous and claim back my code.
@Thomas: If you ever find out how buggy it is, feel free to claim it back. ;-)

svn path=/trunk/; revision=64394

rostests/apitests/advapi32/HKEY_CLASSES_ROOT.c
rostests/apitests/ntdll/CMakeLists.txt
rostests/apitests/ntdll/NtQueryKey.c [new file with mode: 0644]
rostests/apitests/ntdll/testlist.c

index a0e8845..bc3b648 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * PROJECT:         ReactOS api tests
  * LICENSE:         GPLv2+ - See COPYING in the top level directory
- * PURPOSE:         Test for CreateService
- * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
+ * PURPOSE:         Test for the HKEY_CLASSES_ROOT key
+ * PROGRAMMER:      Jérôme Gardou <jerome.gardou@reactos.org>
  */
 
 #include <apitest.h>
index 03309b8..57bb305 100644 (file)
@@ -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 (file)
index 0000000..b94cf85
--- /dev/null
@@ -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 <jerome.gardou@reactos.org>
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <ndk/rtlfuncs.h>
+#include <ndk/cmfuncs.h>
+#include <ndk/cmtypes.h>
+#include <ndk/obfuncs.h>
+
+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();
+}
index 69fc3db..365c7d4 100644 (file)
@@ -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},