mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[SETUPLIB_UNITTEST] Add unit-tests for the setuplib (#7187)
This commit is contained in:
parent
785cc21598
commit
6289183dcd
5 changed files with 172 additions and 0 deletions
|
@ -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()
|
||||
|
|
17
base/setup/lib/unittests/CMakeLists.txt
Normal file
17
base/setup/lib/unittests/CMakeLists.txt
Normal file
|
@ -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)
|
110
base/setup/lib/unittests/IsValidInstallDirectory.c
Normal file
110
base/setup/lib/unittests/IsValidInstallDirectory.c
Normal file
|
@ -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@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 */
|
29
base/setup/lib/unittests/precomp.h
Normal file
29
base/setup/lib/unittests/precomp.h
Normal file
|
@ -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@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 */
|
10
base/setup/lib/unittests/testlist.c
Normal file
10
base/setup/lib/unittests/testlist.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#define STANDALONE
|
||||
#include <apitest.h>
|
||||
|
||||
extern void func_IsValidInstallDirectory(void);
|
||||
|
||||
const struct test winetest_testlist[] =
|
||||
{
|
||||
{ "IsValidInstallDirectory", func_IsValidInstallDirectory },
|
||||
{ 0, 0 }
|
||||
};
|
Loading…
Reference in a new issue