[ADVAPI32_APITEST]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 1 Oct 2016 14:41:41 +0000 (14:41 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 1 Oct 2016 14:41:41 +0000 (14:41 +0000)
- Add a test for RegEnumKeyExW showing that it should return ERROR_MORE_DATA instead of ERROR_BUFFER_OVERFLOW when the name buffer is too small. Based on a patch by Doug Lyons.
CORE-12030

svn path=/trunk/; revision=72876

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

index 6a86af3..f0ecb85 100644 (file)
@@ -7,6 +7,7 @@ list(APPEND SOURCE
     IsTextUnicode.c
     LockDatabase.c
     QueryServiceConfig2.c
+    RegEnumKey.c
     RegEnumValueW.c
     RegQueryInfoKey.c
     RtlEncryptMemory.c
diff --git a/rostests/apitests/advapi32/RegEnumKey.c b/rostests/apitests/advapi32/RegEnumKey.c
new file mode 100644 (file)
index 0000000..23ba958
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * PROJECT:         ReactOS API tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Test for the RegEnumKey API
+ * PROGRAMMER:      Thomas Faber & Doug Lyons
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <winreg.h>
+
+START_TEST(RegEnumKey)
+{
+    LONG ErrorCode;
+    HKEY TestKey;
+    HKEY hKey;
+    WCHAR nameBuf[4];
+    DWORD nameLen;
+
+    /* Base key for our test */
+    ErrorCode = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS_apitest", 0, NULL, 0, KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hKey, NULL);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+
+    /* Create 1 char subkey */
+    ErrorCode = RegCreateKeyExW(hKey, L"1", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    RegCloseKey(TestKey);
+
+    /* Enumerate first key with space for 1 char */
+    nameLen = 1;
+    FillMemory(nameBuf, sizeof(nameBuf), 0x55);
+    ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_MORE_DATA);
+    ok_hex(nameBuf[0], 0x5555);
+    ok_hex(nameBuf[1], 0x5555);
+    ok_dec(nameLen, 1);
+
+    /* Enumerate first key with space for 2 chars */
+    nameLen = 2;
+    FillMemory(nameBuf, sizeof(nameBuf), 0x55);
+    ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    ok_hex(nameBuf[0], L'1');
+    ok_hex(nameBuf[1], 0);
+    ok_hex(nameBuf[2], 0x5555);
+    ok_dec(nameLen, 1);
+
+    /* Delete the subkey */
+    ErrorCode = RegDeleteKeyW(hKey, L"1");
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+
+    /* Create 2 char subkey */
+    ErrorCode = RegCreateKeyExW(hKey, L"12", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    RegCloseKey(TestKey);
+
+    /* Enumerate first key with space for 2 chars */
+    FillMemory(nameBuf, sizeof(nameBuf), 0x55);
+    nameLen = 2;
+    ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_MORE_DATA);
+    ok_hex(nameBuf[0], 0x5555);
+    ok_hex(nameBuf[1], 0x5555);
+    ok(nameLen == 2, "nameLen = %ld, expected 2\n", nameLen);
+
+    /* Enumerate first key with space for 3 chars */
+    FillMemory(nameBuf, sizeof(nameBuf), 0x55);
+    nameLen = 3;
+    ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    ok_hex(nameBuf[0], L'1');
+    ok_hex(nameBuf[1], L'2');
+    ok_hex(nameBuf[2], 0);
+    ok_hex(nameBuf[3], 0x5555);
+    ok(nameLen == 2, "nameLen = %ld, expected 2\n", nameLen);
+
+    /* Delete the subkey */
+    ErrorCode = RegDeleteKeyW(hKey, L"12");
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+
+    /* Delete our parent key */
+    ErrorCode = RegDeleteKeyW(hKey, L"");
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    RegCloseKey(hKey);
+}
index a44cbb9..76a2079 100644 (file)
@@ -10,6 +10,7 @@ extern void func_HKEY_CLASSES_ROOT(void);
 extern void func_IsTextUnicode(void);
 extern void func_LockDatabase(void);
 extern void func_QueryServiceConfig2(void);
+extern void func_RegEnumKey(void);
 extern void func_RegEnumValueW(void);
 extern void func_RegQueryInfoKey(void);
 extern void func_RtlEncryptMemory(void);
@@ -24,6 +25,7 @@ const struct test winetest_testlist[] =
     { "IsTextUnicode" , func_IsTextUnicode },
     { "LockDatabase" , func_LockDatabase },
     { "QueryServiceConfig2", func_QueryServiceConfig2 },
+    { "RegEnumKey", func_RegEnumKey },
     { "RegEnumValueW", func_RegEnumValueW },
     { "RegQueryInfoKey", func_RegQueryInfoKey },
     { "RtlEncryptMemory", func_RtlEncryptMemory },