[ADVAPI32_APITEST]
authorJérôme Gardou <jerome.gardou@reactos.org>
Thu, 2 Oct 2014 17:31:06 +0000 (17:31 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Thu, 2 Oct 2014 17:31:06 +0000 (17:31 +0000)
 - Add a few tests for RegEnumValueW

svn path=/trunk/; revision=64468

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

index a9a95fa..f148e22 100644 (file)
@@ -4,6 +4,7 @@ list(APPEND SOURCE
     HKEY_CLASSES_ROOT.c
     LockDatabase.c
     QueryServiceConfig2.c
+    RegEnumValueW.c
     RtlEncryptMemory.c
     SaferIdentifyLevel.c
     testlist.c)
diff --git a/rostests/apitests/advapi32/RegEnumValueW.c b/rostests/apitests/advapi32/RegEnumValueW.c
new file mode 100644 (file)
index 0000000..51da24b
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Test for the RegGetvalueW API
+ * PROGRAMMER:      Jérôme Gardou <jerome.gardou@reactos.org>
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <winreg.h>
+
+START_TEST(RegEnumValueW)
+{
+    LONG ErrorCode;
+    HKEY TestKey;
+    ULONG Data;
+    DWORD NameLength, DataLength;
+    DWORD DataType;
+    WCHAR NameBuffer[7];
+
+    /* Create our Test Key */
+    ErrorCode = RegCreateKeyW( HKEY_CURRENT_USER, L"Software\\ReactOS_apitest", &TestKey );
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+
+    /* All NULL is invalid */
+    ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+
+    /* Asking for the buffer length is not enough. */
+    NameLength = 8;
+    ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+
+    /* Or maybe it is, you just have to nicely ask */
+    NameLength = 0;
+    ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+
+    /* Name buffer alone is also prohibited */
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, NULL, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+
+    /* You need to ask for both a minima */
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_NO_MORE_ITEMS);
+
+    /* What if I only want to know the value type ? */
+    ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, &DataType, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+
+    /* Set a value */
+    Data = 0xF00DF00D;
+    ErrorCode = RegSetValueExW(TestKey, L"Value1", 0, REG_BINARY, (LPBYTE)&Data, sizeof(Data));
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+
+    /* Try various combinations of Arguments */
+    NameLength = 7;
+    ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+    /* Provide a buffer this time */
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    /* This doesn't include the NULL terminator */
+    ok_dec(NameLength, 6);
+    /* But the string is NULL terminated */
+    ok_hex(NameBuffer[6], L'\0');
+    ok(wcscmp(NameBuffer, L"Value1") == 0, "%S\n", NameBuffer);
+
+    /* See if skipping the NULL value is a problem */
+    NameLength = 6;
+    memset(NameBuffer, 0xBA, sizeof(NameBuffer));
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_MORE_DATA);
+    /* In fact, this is unchanged */
+    ok_dec(NameLength, 6);
+    /* And the string is untouched */
+    ok_hex(NameBuffer[6], 0xBABA);
+    ok_hex(NameBuffer[5], 0xBABA);
+    ok_hex(NameBuffer[4], 0xBABA);
+    ok_hex(NameBuffer[3], 0xBABA);
+    ok_hex(NameBuffer[2], 0xBABA);
+    ok_hex(NameBuffer[1], 0xBABA);
+    ok_hex(NameBuffer[0], 0xBABA);
+
+    /* Of course, anything smaller is an outrage */
+    NameLength = 5;
+    memset(NameBuffer, 0xBA, sizeof(NameBuffer));
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
+    ok_dec(ErrorCode, ERROR_MORE_DATA);
+    /* Untouched... */
+    ok_dec(NameLength, 5);
+    /* And the string is untouched */
+    ok_hex(NameBuffer[6], 0xBABA);
+    ok_hex(NameBuffer[5], 0xBABA);
+    ok_hex(NameBuffer[4], 0xBABA);
+    ok_hex(NameBuffer[3], 0xBABA);
+    ok_hex(NameBuffer[2], 0xBABA);
+    ok_hex(NameBuffer[1], 0xBABA);
+    ok_hex(NameBuffer[0], 0xBABA);
+
+    /* Of course, asking for data without caring for the name would be strange... */
+    DataLength = 0;
+    ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, NULL, NULL, NULL, &DataLength);
+    ok_dec(ErrorCode, ERROR_INVALID_PARAMETER);
+
+    DataLength = 0;
+    NameLength = 7;
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, NULL, &DataLength);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    ok_dec(DataLength, sizeof(Data));
+    ok_hex(DataType, REG_BINARY);
+
+    /* Same, but this time with NULL data buffer and non-zero data size */
+    DataLength = 2;
+    NameLength = 7;
+    DataType = 0x01234567;
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, NULL, &DataLength);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    ok_dec(DataLength, sizeof(Data));
+    ok_hex(DataType, REG_BINARY);
+
+    /* Same, but this time with data buffer and shrunk data size */
+    DataLength = 2;
+    Data = 0;
+    DataType = 0x01234567;
+    NameLength = 7;
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, (LPBYTE)&Data, &DataLength);
+    ok_dec(ErrorCode, ERROR_MORE_DATA);
+    ok_dec(DataLength, sizeof(Data));
+    ok_hex(Data, 0);
+    ok_hex(DataType, REG_BINARY);
+
+    /* Put the right parameters */
+    DataLength = sizeof(Data);
+    NameLength = 7;
+    Data = 0;
+    DataType = 0x01234567;
+    ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, (LPBYTE)&Data, &DataLength);
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    ok_dec(DataLength, sizeof(Data));
+    ok_hex(Data, 0xF00DF00D);
+    ok_hex(DataType, REG_BINARY);
+
+    /* Delete the key */
+    ErrorCode = RegDeleteKeyW(TestKey, L"");
+    ok_dec(ErrorCode, ERROR_SUCCESS);
+    RegCloseKey(TestKey);
+}
+
index 7dc9681..80ad3d3 100644 (file)
@@ -7,6 +7,7 @@ extern void func_CreateService(void);
 extern void func_HKEY_CLASSES_ROOT(void);
 extern void func_LockDatabase(void);
 extern void func_QueryServiceConfig2(void);
+extern void func_RegEnumValueW(void);
 extern void func_RtlEncryptMemory(void);
 extern void func_SaferIdentifyLevel(void);
 
@@ -16,6 +17,7 @@ const struct test winetest_testlist[] =
     { "HKEY_CLASSES_ROOT", func_HKEY_CLASSES_ROOT },
     { "LockDatabase" , func_LockDatabase },
     { "QueryServiceConfig2", func_QueryServiceConfig2 },
+    { "RegEnumValueW", func_RegEnumValueW},
     { "RtlEncryptMemory", func_RtlEncryptMemory },
     { "SaferIdentifyLevel", func_SaferIdentifyLevel },