Fix running tests using ctest

This commit is contained in:
Oliver Hamlet
2025-01-15 18:13:54 +00:00
parent 7442a16706
commit aac3f68a4c
6 changed files with 110 additions and 67 deletions
+2 -2
View File
@@ -226,9 +226,9 @@ endif()
add_custom_command(TARGET libloot_internals_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${testing-plugins_SOURCE_DIR}
$<TARGET_FILE_DIR:libloot_internals_tests>)
${CMAKE_CURRENT_BINARY_DIR}/testing-plugins)
add_custom_command(TARGET libloot_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${testing-plugins_SOURCE_DIR}
$<TARGET_FILE_DIR:libloot_tests>)
${CMAKE_CURRENT_BINARY_DIR}/testing-plugins)
+13 -14
View File
@@ -34,7 +34,7 @@ along with LOOT. If not, see
namespace loot::test {
TEST(GetAssetsInBethesdaArchive, shouldSupportV103BSAs) {
const auto path = std::filesystem::u8path("./Oblivion/Data/Blank.bsa");
const auto path = getSourceArchivesPath(GameType::tes4) / "Blank.bsa";
const auto assets = GetAssetsInBethesdaArchive(path);
@@ -51,7 +51,7 @@ TEST(GetAssetsInBethesdaArchive, shouldSupportV103BSAs) {
}
TEST(GetAssetsInBethesdaArchive, shouldSupportV104BSAs) {
const auto path = std::filesystem::u8path("./Skyrim/Data/Blank.bsa");
const auto path = getSourceArchivesPath(GameType::tes5) / "Blank.bsa";
const auto assets = GetAssetsInBethesdaArchive(path);
@@ -68,7 +68,7 @@ TEST(GetAssetsInBethesdaArchive, shouldSupportV104BSAs) {
}
TEST(GetAssetsInBethesdaArchive, shouldSupportV105BSAs) {
const auto path = std::filesystem::u8path("./SkyrimSE/Data/Blank.bsa");
const auto path = getSourceArchivesPath(GameType::tes5se) / "Blank.bsa";
const auto assets = GetAssetsInBethesdaArchive(path);
@@ -91,8 +91,7 @@ TEST(GetAssetsInBethesdaArchive, shouldThrowIfFileCannotBeOpened) {
}
TEST(GetAssetsInBethesdaArchive, shouldSupportGeneralBA2s) {
const auto path =
std::filesystem::u8path("./Fallout 4/Data/Blank - Main.ba2");
const auto path = getSourceArchivesPath(GameType::fo4) / "Blank - Main.ba2";
const uint64_t folderHash =
std::hash<std::string>{}("dev\\git\\testing-plugins");
const uint64_t fileHash = std::hash<std::string>{}("license.txt");
@@ -115,7 +114,7 @@ TEST(GetAssetsInBethesdaArchive, shouldSupportGeneralBA2s) {
TEST(GetAssetsInBethesdaArchive, shouldSupportTextureBA2s) {
const auto path =
std::filesystem::u8path("./Fallout 4/Data/Blank - Textures.ba2");
getSourceArchivesPath(GameType::fo4) / "Blank - Textures.ba2";
const uint64_t folderHash =
std::hash<std::string>{}("dev\\git\\testing-plugins");
const uint64_t fileHash = std::hash<std::string>{}("blank.dds");
@@ -143,7 +142,7 @@ protected:
std::filesystem::create_directories(path.parent_path());
const auto sourcePath =
std::filesystem::u8path("./Fallout 4/Data/Blank - Main.ba2");
getSourceArchivesPath(GameType::fo4) / "Blank - Main.ba2";
std::filesystem::copy(sourcePath, path);
std::fstream stream(
@@ -178,7 +177,7 @@ TEST_P(GetAssetsInBethesdaArchive_BA2Version, shouldSupportBA2Version) {
TEST(GetAssetsInBethesdaArchives, shouldSkipFilesThatCannotBeRead) {
std::vector<std::filesystem::path> paths(
{std::filesystem::u8path("invalid.bsa"),
std::filesystem::u8path("./Skyrim/Data/Blank.bsa")});
getSourceArchivesPath(GameType::tes5) / "Blank.bsa"});
const auto assets = GetAssetsInBethesdaArchives(paths);
@@ -196,9 +195,9 @@ TEST(GetAssetsInBethesdaArchives, shouldSkipFilesThatCannotBeRead) {
TEST(GetAssetsInBethesdaArchives, shouldCombineAssetsFromEachLoadedArchive) {
std::vector<std::filesystem::path> paths(
{std::filesystem::u8path("./Oblivion/Data/Blank.bsa"),
std::filesystem::u8path("./Skyrim/Data/Blank.bsa"),
std::filesystem::u8path("./SkyrimSE/Data/Blank.bsa")});
{getSourceArchivesPath(GameType::tes4) / "Blank.bsa",
getSourceArchivesPath(GameType::tes5) / "Blank.bsa",
getSourceArchivesPath(GameType::tes5se) / "Blank.bsa"});
const auto assets = GetAssetsInBethesdaArchives(paths);
@@ -221,7 +220,7 @@ TEST(GetAssetsInBethesdaArchives, shouldCombineAssetsFromEachLoadedArchive) {
}
TEST(DoAssetsIntersect, shouldReturnTrueIfTheSameFileExistsInTheSameFolder) {
const auto path = std::filesystem::u8path("./Oblivion/Data/Blank.bsa");
const auto path = getSourceArchivesPath(GameType::tes4) / "Blank.bsa";
const auto assets = GetAssetsInBethesdaArchive(path);
@@ -230,10 +229,10 @@ TEST(DoAssetsIntersect, shouldReturnTrueIfTheSameFileExistsInTheSameFolder) {
TEST(DoAssetsIntersect,
shouldReturnFalseIfTheSameFileExistsInDifferentFolders) {
const auto path1 = std::filesystem::u8path("./Oblivion/Data/Blank.bsa");
const auto path1 = getSourceArchivesPath(GameType::tes4) / "Blank.bsa";
const auto assets1 = GetAssetsInBethesdaArchive(path1);
const auto path2 = std::filesystem::u8path("./Skyrim/Data/Blank.bsa");
const auto path2 = getSourceArchivesPath(GameType::tes5) / "Blank.bsa";
const auto assets2 = GetAssetsInBethesdaArchive(path2);
EXPECT_EQ(*assets2.at(0x2E01002E).begin(), *assets1.at(0).begin());
+15 -4
View File
@@ -162,6 +162,8 @@ TEST(Filesystem, equalityShouldBeCaseSensitive) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license");
ASSERT_NE(lower.u8string(), upper.u8string());
EXPECT_NE(lower, upper);
}
@@ -169,14 +171,20 @@ TEST(Filesystem, equivalentShouldRequireThatBothPathsExist) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license2");
ASSERT_FALSE(std::filesystem::exists(upper));
ASSERT_FALSE(std::filesystem::exists(lower));
EXPECT_THROW(std::ignore = std::filesystem::equivalent(lower, upper),
std::filesystem::filesystem_error);
}
#ifdef _WIN32
TEST(Filesystem, equivalentShouldBeCaseInsensitive) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license");
auto upper = std::filesystem::path("./testing-plugins/LICENSE");
auto lower = std::filesystem::path("./testing-plugins/license");
ASSERT_TRUE(std::filesystem::exists(upper));
ASSERT_TRUE(std::filesystem::exists(lower));
EXPECT_TRUE(std::filesystem::equivalent(lower, upper));
}
@@ -194,12 +202,15 @@ TEST(
}
#else
TEST(Filesystem, equivalentShouldBeCaseSensitive) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license");
auto upper = std::filesystem::path("./testing-plugins/LICENSE");
auto lower = std::filesystem::path("./testing-plugins/license");
std::ofstream out(lower);
out.close();
ASSERT_TRUE(std::filesystem::exists(upper));
ASSERT_TRUE(std::filesystem::exists(lower));
EXPECT_FALSE(std::filesystem::equivalent(lower, upper));
}
#endif
+47 -29
View File
@@ -76,12 +76,13 @@ protected:
std::filesystem::path blankMasterDependentArchive;
if (GetParam() == GameType::fo4 || GetParam() == GameType::fo4vr ||
GetParam() == GameType::starfield) {
copyPlugin("./Fallout 4/Data", "Blank - Main.ba2");
copyPlugin("./Fallout 4/Data", "Blank - Textures.ba2");
copyPlugin(getSourceArchivesPath(GetParam()), "Blank - Main.ba2");
copyPlugin(getSourceArchivesPath(GetParam()), "Blank - Textures.ba2");
blankMasterDependentArchive = "Blank - Master Dependent - Main.ba2";
std::filesystem::copy_file("./Fallout 4/Data/Blank - Main.ba2",
dataPath / blankMasterDependentArchive);
std::filesystem::copy_file(
getSourceArchivesPath(GetParam()) / "Blank - Main.ba2",
dataPath / blankMasterDependentArchive);
ASSERT_TRUE(
std::filesystem::exists(dataPath / blankMasterDependentArchive));
} else if (GetParam() == GameType::tes3) {
@@ -785,8 +786,11 @@ TEST_P(
}
TEST(equivalent, shouldReturnTrueIfGivenEqualPathsThatExist) {
auto path1 = std::filesystem::path("LICENSE");
auto path2 = std::filesystem::path("LICENSE");
auto path1 = std::filesystem::path("./testing-plugins/LICENSE");
auto path2 = std::filesystem::path("./testing-plugins/LICENSE");
ASSERT_EQ(path1, path2);
ASSERT_TRUE(std::filesystem::exists(path1));
EXPECT_TRUE(loot::equivalent(path1, path2));
}
@@ -795,32 +799,47 @@ TEST(equivalent, shouldReturnTrueIfGivenEqualPathsThatDoNotExist) {
auto path1 = std::filesystem::path("LICENSE2");
auto path2 = std::filesystem::path("LICENSE2");
ASSERT_EQ(path1, path2);
ASSERT_FALSE(std::filesystem::exists(path1));
EXPECT_TRUE(loot::equivalent(path1, path2));
}
TEST(equivalent, shouldReturnFalseIfPathsAreNotCaseInsensitivelyEqual) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license2");
EXPECT_FALSE(loot::equivalent(lower, upper));
}
#ifdef _WIN32
TEST(equivalent, shouldReturnTrueIfGivenCaseInsensitivelyEqualPathsThatExist) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license");
EXPECT_TRUE(loot::equivalent(lower, upper));
}
TEST(equivalent,
shouldReturnFalseIfGivenCaseInsensitivelyEqualPathsThatDoNotExist) {
auto upper = std::filesystem::path("LICENSE2");
auto lower = std::filesystem::path("license2");
ASSERT_TRUE(boost::iequals(upper.u8string(), lower.u8string()));
ASSERT_FALSE(std::filesystem::exists(upper));
ASSERT_FALSE(std::filesystem::exists(lower));
EXPECT_FALSE(loot::equivalent(lower, upper));
}
TEST(equivalent, shouldReturnFalseIfGivenCaseInsensitivelyUnequalThatExist) {
auto path1 = std::filesystem::path("./testing-plugins/LICENSE");
auto path2 = std::filesystem::path("./testing-plugins/README.md");
ASSERT_FALSE(boost::iequals(path1.u8string(), path2.u8string()));
ASSERT_TRUE(std::filesystem::exists(path1));
ASSERT_TRUE(std::filesystem::exists(path2));
EXPECT_FALSE(loot::equivalent(path1, path2));
}
#ifdef _WIN32
TEST(equivalent, shouldReturnTrueIfGivenCaseInsensitivelyEqualPathsThatExist) {
auto upper = std::filesystem::path("./testing-plugins/LICENSE");
auto lower = std::filesystem::path("./testing-plugins/license");
ASSERT_TRUE(boost::iequals(upper.u8string(), lower.u8string()));
ASSERT_TRUE(std::filesystem::exists(upper));
ASSERT_TRUE(std::filesystem::exists(lower));
EXPECT_TRUE(loot::equivalent(lower, upper));
}
TEST(
equivalent,
shouldReturnTrueIfEqualPathsHaveCharactersThatAreUnrepresentableInTheSystemMultiByteCodePage) {
@@ -844,16 +863,15 @@ TEST(
}
#else
TEST(equivalent, shouldReturnFalseIfGivenCaseInsensitivelyEqualPathsThatExist) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license");
auto upper = std::filesystem::path("./testing-plugins/LICENSE");
auto lower = std::filesystem::path("./testing-plugins/license");
EXPECT_FALSE(loot::equivalent(lower, upper));
}
std::ofstream out(lower);
out.close();
TEST(equivalent,
shouldReturnFalseIfGivenCaseInsensitivelyEqualPathsThatDoNotExist) {
auto upper = std::filesystem::path("LICENSE2");
auto lower = std::filesystem::path("license2");
ASSERT_TRUE(boost::iequals(upper.u8string(), lower.u8string()));
ASSERT_TRUE(std::filesystem::exists(upper));
ASSERT_TRUE(std::filesystem::exists(lower));
EXPECT_FALSE(loot::equivalent(lower, upper));
}
+1 -18
View File
@@ -34,7 +34,6 @@ along with LOOT. If not, see
#include <map>
#include "loot/enum/game_type.h"
#include "tests/test_helpers.h"
namespace loot {
@@ -278,17 +277,7 @@ protected:
}
std::filesystem::path getSourcePluginsPath() const {
using std::filesystem::absolute;
if (GetParam() == GameType::tes3)
return absolute("./Morrowind/Data Files");
else if (GetParam() == GameType::tes4)
return absolute("./Oblivion/Data");
else if (GetParam() == GameType::starfield)
return absolute("./Starfield/Data");
else if (supportsLightPlugins(GetParam()))
return absolute("./SkyrimSE/Data");
else
return absolute("./Skyrim/Data");
return loot::test::getSourcePluginsPath(GetParam());
}
void touch(const std::filesystem::path& path) {
@@ -473,12 +462,6 @@ private:
return gameType == GameType::tes3 || gameType == GameType::tes4 ||
gameType == GameType::fo3 || gameType == GameType::fonv;
}
static bool supportsLightPlugins(GameType gameType) {
return gameType == GameType::tes5se || gameType == GameType::tes5vr ||
gameType == GameType::fo4 || gameType == GameType::fo4vr ||
gameType == GameType::starfield;
}
};
}
}
+32
View File
@@ -29,7 +29,39 @@ along with LOOT. If not, see
#include <random>
#include <string>
#include "loot/enum/game_type.h"
namespace loot::test {
bool supportsLightPlugins(GameType gameType) {
return gameType == GameType::tes5se || gameType == GameType::tes5vr ||
gameType == GameType::fo4 || gameType == GameType::fo4vr ||
gameType == GameType::starfield;
}
std::filesystem::path getSourcePluginsPath(GameType gameType) {
using std::filesystem::absolute;
if (gameType == GameType::tes3) {
return absolute("./testing-plugins/Morrowind/Data Files");
} else if (gameType == GameType::tes4) {
return absolute("./testing-plugins/Oblivion/Data");
} else if (gameType == GameType::starfield) {
return absolute("./testing-plugins/Starfield/Data");
} else if (supportsLightPlugins(gameType)) {
return absolute("./testing-plugins/SkyrimSE/Data");
} else {
return absolute("./testing-plugins/Skyrim/Data");
}
}
std::filesystem::path getSourceArchivesPath(GameType gameType) {
if (gameType == GameType::fo4 || gameType == GameType::fo4vr ||
gameType == GameType::starfield) {
return "./testing-plugins/Fallout 4/Data";
} else {
return getSourcePluginsPath(gameType);
}
}
std::filesystem::path getRootTestPath() {
std::random_device randomDevice;
std::default_random_engine prng(randomDevice());