https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6289183dcd72673cac232…
commit 6289183dcd72673cac232f15c7b636a84d9afb28
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Jul 25 21:12:33 2024 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Jul 31 11:41:23 2024 +0200
[SETUPLIB_UNITTEST] Add unit-tests for the setuplib (#7187)
---
base/setup/lib/CMakeLists.txt | 6 ++
base/setup/lib/unittests/CMakeLists.txt | 17 ++++
base/setup/lib/unittests/IsValidInstallDirectory.c | 110 +++++++++++++++++++++
base/setup/lib/unittests/precomp.h | 29 ++++++
base/setup/lib/unittests/testlist.c | 10 ++
5 files changed, 172 insertions(+)
diff --git a/base/setup/lib/CMakeLists.txt b/base/setup/lib/CMakeLists.txt
index cc79ec83ef8..acd7cd5e01a 100644
--- a/base/setup/lib/CMakeLists.txt
+++ b/base/setup/lib/CMakeLists.txt
@@ -33,3 +33,9 @@ list(APPEND SOURCE
add_library(setuplib ${SOURCE})
add_pch(setuplib precomp.h SOURCE)
add_dependencies(setuplib xdk) # psdk
+
+
+## Unit-tests
+if(ENABLE_ROSTESTS)
+ add_subdirectory(unittests)
+endif()
diff --git a/base/setup/lib/unittests/CMakeLists.txt
b/base/setup/lib/unittests/CMakeLists.txt
new file mode 100644
index 00000000000..199e31e2dd1
--- /dev/null
+++ b/base/setup/lib/unittests/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+PROJECT(setuplib_unittest)
+
+include_directories(${REACTOS_SOURCE_DIR}/modules/rostests/apitests/include)
+
+list(APPEND TEST_SOURCE
+ IsValidInstallDirectory.c
+ testlist.c
+ precomp.h)
+
+add_executable(setuplib_unittest ${TEST_SOURCE})
+
+target_link_libraries(setuplib_unittest setuplib ${PSEH_LIB})
+set_module_type(setuplib_unittest win32cui)
+add_importlibs(setuplib_unittest msvcrt kernel32 ntdll)
+#add_pch(setuplib_unittest precomp.h TEST_SOURCE)
+add_rostests_file(TARGET setuplib_unittest)
diff --git a/base/setup/lib/unittests/IsValidInstallDirectory.c
b/base/setup/lib/unittests/IsValidInstallDirectory.c
new file mode 100644
index 00000000000..c7f3a599271
--- /dev/null
+++ b/base/setup/lib/unittests/IsValidInstallDirectory.c
@@ -0,0 +1,110 @@
+/*
+ * PROJECT: ReactOS Setup Library - Unit-tests
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Test for IsValidInstallDirectory
+ * COPYRIGHT: Copyright 2024 Hermès Bélusca-Maïto
<hermes.belusca-maito(a)reactos.org>
+ */
+
+#include "precomp.h"
+
+//
+// FIXME: Temporary symbols defined to make linking work.
+// They will be defined to something once INF file testing is implemented.
+//
+pSpInfCloseInfFile SpInfCloseInfFile = NULL;
+pSpInfFindFirstLine SpInfFindFirstLine = NULL;
+pSpInfFindNextLine SpInfFindNextLine = NULL;
+pSpInfGetFieldCount SpInfGetFieldCount = NULL;
+pSpInfGetBinaryField SpInfGetBinaryField = NULL;
+pSpInfGetIntField SpInfGetIntField = NULL;
+pSpInfGetMultiSzField SpInfGetMultiSzField = NULL;
+pSpInfGetStringField SpInfGetStringField = NULL;
+pSpInfGetField SpInfGetField = NULL;
+pSpInfOpenInfFile SpInfOpenInfFile = NULL;
+
+BOOLEAN IsUnattendedSetup = FALSE;
+HANDLE ProcessHeap;
+
+
+START_TEST(IsValidInstallDirectory)
+{
+ static const struct
+ {
+ PCWSTR path;
+ BOOLEAN result;
+ } tests[] =
+ {
+ { L"", FALSE },
+ { L" ", FALSE },
+ { L"\\", FALSE },
+ { L"\\\\", FALSE },
+ { L".", FALSE },
+ { L"..", FALSE },
+ { L"...", FALSE },
+ { L"....", FALSE },
+ { L" WINNT", FALSE },
+ { L"WINNT ", FALSE },
+ { L".WINNT", FALSE },
+ { L"..WINNT", FALSE },
+ { L"W.INNT", FALSE },
+ { L"WI.NNT", TRUE },
+ { L"WIN.NT", TRUE },
+ { L"WINNT.", TRUE },
+ { L"WINNT..", FALSE },
+ { L"WINNT. ", FALSE },
+ { L"WINNT.e e", FALSE },
+ { L"WIN^`NT", FALSE },
+
+ { L"WINNT", TRUE },
+ { L"\\WINNT", TRUE },
+ { L"\\WINNT\\", TRUE },
+ { L"\\WINNT\\.", FALSE },
+ { L"WIN\\NT", TRUE },
+ { L"WIN\\NT.", TRUE },
+ { L"\\WIN\\NT\\", TRUE },
+ { L"\\WIN\\NT.\\", TRUE },
+ { L"\\WIN.\\NT52", TRUE },
+ { L"\\WIN\\.\\NT52", FALSE },
+ { L"\\WIN\\..\\NT52", FALSE },
+ { L"\\WIN\\...\\NT52", FALSE },
+ { L"\\WIN\\....\\NT52", FALSE },
+
+ { L"win.nt.5", FALSE },
+ { L"win.ntX5", FALSE },
+ { L"winn.tX5", TRUE },
+ { L"winnt.X5", TRUE },
+ { L"winntX.5", TRUE },
+ { L"winntX5.", TRUE },
+ { L"filenamee.xte", FALSE },
+ { L"filenamee.xt", FALSE },
+ { L"filename.ext", TRUE },
+ { L"file.ame.ext", FALSE },
+ { L"filenam.eext", FALSE },
+
+ { L"1 3 5 7 .abc", FALSE },
+ { L"12345678. c", FALSE },
+ { L"123456789.a", FALSE },
+ { L"12345.abcd", FALSE },
+ { L"12345.ab d", FALSE },
+ { L".abc", FALSE },
+ { L"12.abc.d", FALSE },
+ { L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE },
+ };
+
+#define BOOL_TO_STR(b) ((b) ? "TRUE" : "FALSE")
+
+ ProcessHeap = GetProcessHeap();
+
+ UINT i;
+ for (i = 0; i < _countof(tests); ++i)
+ {
+ BOOLEAN ret = IsValidInstallDirectory(tests[i].path);
+ ok(ret == tests[i].result,
+ "Unexpected result for '%S', got %s, expected %s\n",
+ tests[i].path, BOOL_TO_STR(ret), BOOL_TO_STR(tests[i].result));
+ }
+
+#undef BOOL_TO_STR
+}
+
+/* EOF */
diff --git a/base/setup/lib/unittests/precomp.h b/base/setup/lib/unittests/precomp.h
new file mode 100644
index 00000000000..8cb8823d5ec
--- /dev/null
+++ b/base/setup/lib/unittests/precomp.h
@@ -0,0 +1,29 @@
+/*
+ * PROJECT: ReactOS Setup Library - Unit-tests
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Precompiled header
+ * COPYRIGHT: Copyright 2024 Hermès Bélusca-Maïto
<hermes.belusca-maito(a)reactos.org>
+ */
+
+#pragma once
+
+#include <apitest.h>
+
+/* C Headers */
+#include <stdio.h>
+
+/* PSDK/NDK */
+#define WIN32_NO_STATUS
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+
+#include <windef.h>
+#include <winbase.h>
+//#include <strsafe.h>
+
+#define NTOS_MODE_USER
+#include <ndk/rtlfuncs.h>
+
+#include <../setuplib.h>
+
+/* EOF */
diff --git a/base/setup/lib/unittests/testlist.c b/base/setup/lib/unittests/testlist.c
new file mode 100644
index 00000000000..f2600910505
--- /dev/null
+++ b/base/setup/lib/unittests/testlist.c
@@ -0,0 +1,10 @@
+#define STANDALONE
+#include <apitest.h>
+
+extern void func_IsValidInstallDirectory(void);
+
+const struct test winetest_testlist[] =
+{
+ { "IsValidInstallDirectory", func_IsValidInstallDirectory },
+ { 0, 0 }
+};