https://git.reactos.org/?p=reactos.git;a=commitdiff;h=092e2457548f53da15d6b…
commit 092e2457548f53da15d6be7e01022180ae0aefc9
Author: Serge Gautherie <32623169+SergeGautherie(a)users.noreply.github.com>
AuthorDate: Sat Jul 4 15:24:13 2020 +0200
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Jul 4 15:24:13 2020 +0200
[UTILDLL_APITEST] Create 'CachedGetUserFromSid()' test (#2954)
---
modules/rostests/apitests/CMakeLists.txt | 1 +
modules/rostests/apitests/utildll/CMakeLists.txt | 11 +++
.../apitests/utildll/CachedGetUserFromSid.c | 94 ++++++++++++++++++++++
modules/rostests/apitests/utildll/testlist.c | 10 +++
4 files changed, 116 insertions(+)
diff --git a/modules/rostests/apitests/CMakeLists.txt
b/modules/rostests/apitests/CMakeLists.txt
index 59bdeb46832..c0a6e85ad17 100644
--- a/modules/rostests/apitests/CMakeLists.txt
+++ b/modules/rostests/apitests/CMakeLists.txt
@@ -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
index 00000000000..f16e7f59fd8
--- /dev/null
+++ b/modules/rostests/apitests/utildll/CMakeLists.txt
@@ -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
index 00000000000..04a5ad75e14
--- /dev/null
+++ b/modules/rostests/apitests/utildll/CachedGetUserFromSid.c
@@ -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(a)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
index 00000000000..a5b45cd6bf1
--- /dev/null
+++ b/modules/rostests/apitests/utildll/testlist.c
@@ -0,0 +1,10 @@
+#define STANDALONE
+#include <apitest.h>
+
+extern void func_CachedGetUserFromSid(void);
+
+const struct test winetest_testlist[] =
+{
+ { "CachedGetUserFromSid", func_CachedGetUserFromSid },
+ { 0, 0 }
+};