[UTILDLL_APITEST] Create 'CachedGetUserFromSid()' test (#2954)
authorSerge Gautherie <32623169+SergeGautherie@users.noreply.github.com>
Sat, 4 Jul 2020 13:24:13 +0000 (15:24 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Jul 2020 13:24:13 +0000 (15:24 +0200)
modules/rostests/apitests/CMakeLists.txt
modules/rostests/apitests/utildll/CMakeLists.txt [new file with mode: 0644]
modules/rostests/apitests/utildll/CachedGetUserFromSid.c [new file with mode: 0644]
modules/rostests/apitests/utildll/testlist.c [new file with mode: 0644]

index 59bdeb4..c0a6e85 100644 (file)
@@ -45,6 +45,7 @@ add_subdirectory(psapi)
 add_subdirectory(user32)
 add_subdirectory(user32_dynamic)
 add_subdirectory(userenv)
+add_subdirectory(utildll)
 add_subdirectory(uxtheme)
 if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
     add_subdirectory(win32u)
diff --git a/modules/rostests/apitests/utildll/CMakeLists.txt b/modules/rostests/apitests/utildll/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f16e7f5
--- /dev/null
@@ -0,0 +1,11 @@
+
+list(APPEND SOURCE
+    CachedGetUserFromSid.c)
+
+add_executable(utildll_apitest
+    ${SOURCE}
+    testlist.c)
+
+set_module_type(utildll_apitest win32cui)
+add_importlibs(utildll_apitest msvcrt kernel32)
+add_rostests_file(TARGET utildll_apitest)
diff --git a/modules/rostests/apitests/utildll/CachedGetUserFromSid.c b/modules/rostests/apitests/utildll/CachedGetUserFromSid.c
new file mode 100644 (file)
index 0000000..04a5ad7
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * PROJECT:     ReactOS API Tests
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     Tests for CachedGetUserFromSid
+ * COPYRIGHT:   Copyright 2020 Serge Gautherie <reactos-git_serge_171003@gautherie.fr>
+ */
+
+#include <apitest.h>
+
+#include <lmcons.h>
+#include <wchar.h>
+
+static VOID (WINAPI *pCachedGetUserFromSid)(PSID pSid, LPWSTR pUserName, PULONG pcwcUserName);
+
+static void test_Sid_Null(void)
+{
+    const WCHAR szUserNameFromNull[] = L"(unknown)";
+    const ULONG cchUserNameFromNull = (ULONG)wcslen(szUserNameFromNull);
+
+    WCHAR szUserName[UNLEN + 1];
+    ULONG cchUserName;
+
+    // First, full success case, to load result into cache.
+    // Otherwise, expect misbehavior/corruption/crash!
+    // Same issues with 'NULL' or '0' arguments.
+    // Behavior changed on NT6.0 then NT6.1+...
+
+    wmemset(szUserName, L'?', _countof(szUserName));
+    cchUserName = _countof(szUserName);
+    pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
+    ok(cchUserName == cchUserNameFromNull, "cchUserName: expected %lu, got %lu\n", cchUserNameFromNull, cchUserName);
+    ok(wcscmp(szUserName, szUserNameFromNull) == 0, "szUserName: expected \"%S\", got \"%.*S\"\n", szUserNameFromNull, (int)cchUserName, szUserName);
+
+    wmemset(szUserName, L'?', _countof(szUserName));
+    cchUserName = 1;
+    pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
+    ok(cchUserName == 0, "cchUserName: expected 0, got %lu\n", cchUserName);
+    ok(szUserName[0] == UNICODE_NULL, "szUserName: missing UNICODE_NULL, got \"%.*S\"\n", (int)cchUserName, szUserName);
+
+    wmemset(szUserName, L'?', _countof(szUserName));
+    cchUserName = 2;
+    pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
+    ok(cchUserName == 1, "cchUserName: expected 0, got %lu\n", cchUserName);
+    ok(szUserName[1] == UNICODE_NULL, "szUserName: missing UNICODE_NULL, got \"%.*S\"\n", (int)cchUserName, szUserName);
+    ok(wcsncmp(szUserName, szUserNameFromNull, 1) == 0, "szUserName: expected \"%.*S\", got \"%.*S\"\n", 1, szUserNameFromNull, (int)cchUserName, szUserName);
+
+    wmemset(szUserName, L'?', _countof(szUserName));
+    cchUserName = cchUserNameFromNull;
+    pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
+    ok(cchUserName == cchUserNameFromNull - 1, "cchUserName: expected %lu, got %lu\n", cchUserNameFromNull - 1, cchUserName);
+    ok(szUserName[cchUserNameFromNull - 1] == UNICODE_NULL, "szUserName: missing UNICODE_NULL, got \"%.*S\"\n", (int)cchUserName, szUserName);
+    ok(wcsncmp(szUserName, szUserNameFromNull, cchUserNameFromNull - 1) == 0, "szUserName: expected \"%.*S\", got \"%.*S\"\n", (int)cchUserNameFromNull - 1, szUserNameFromNull, (int)cchUserName, szUserName);
+
+    wmemset(szUserName, L'?', _countof(szUserName));
+    cchUserName = cchUserNameFromNull + 1;
+    pCachedGetUserFromSid(NULL, szUserName, &cchUserName);
+    ok(cchUserName == cchUserNameFromNull, "cchUserName: expected %lu, got %lu\n", cchUserNameFromNull, cchUserName);
+    ok(wcscmp(szUserName, szUserNameFromNull) == 0, "szUserName: expected \"%S\", got \"%.*S\"\n", szUserNameFromNull, (int)cchUserName, szUserName);
+}
+
+START_TEST(CachedGetUserFromSid)
+{
+    const char szFunction[] = "CachedGetUserFromSid";
+
+    // TODO: Dynamically checking, until ReactOS implements this dll.
+    HMODULE hModule = LoadLibraryW(L"utildll.dll");
+    DWORD dwLE = GetLastError();
+
+    if (!hModule)
+    {
+        ok(FALSE, "LoadLibraryW(\"%S\") failed! (dwLE = %lu)\n", L"utildll.dll", dwLE);
+
+        skip("No DLL\n");
+        return;
+    }
+
+    void *pFunction = (void *)GetProcAddress(hModule, szFunction);
+    dwLE = GetLastError();
+
+    if (!pFunction)
+    {
+        ok(FALSE, "GetProcAddress(\"%s\") failed! (dwLE = %lu)\n", szFunction, dwLE);
+
+        skip("No function\n");
+        FreeLibrary(hModule);
+        return;
+    }
+
+    pCachedGetUserFromSid = pFunction;
+
+    test_Sid_Null();
+
+    FreeLibrary(hModule);
+}
diff --git a/modules/rostests/apitests/utildll/testlist.c b/modules/rostests/apitests/utildll/testlist.c
new file mode 100644 (file)
index 0000000..a5b45cd
--- /dev/null
@@ -0,0 +1,10 @@
+#define STANDALONE
+#include <apitest.h>
+
+extern void func_CachedGetUserFromSid(void);
+
+const struct test winetest_testlist[] =
+{
+    { "CachedGetUserFromSid", func_CachedGetUserFromSid },
+    { 0, 0 }
+};