Skip to content

Commit

Permalink
Fix running tests using ctest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jan 15, 2025
1 parent 7442a16 commit aac3f68
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 64 deletions.
4 changes: 2 additions & 2 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 13 additions & 14 deletions src/tests/api/internals/bsa_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -143,7 +142,7 @@ class GetAssetsInBethesdaArchive_BA2Version
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(
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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());
Expand Down
19 changes: 15 additions & 4 deletions src/tests/api/internals/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,29 @@ 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);
}

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));
}
Expand All @@ -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
Expand Down
70 changes: 44 additions & 26 deletions src/tests/api/internals/plugin_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ class PluginTest : public CommonGameTestFixture {
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) {
Expand Down Expand Up @@ -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));
}
Expand All @@ -795,30 +799,45 @@ 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");
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));
}

#ifdef _WIN32
TEST(equivalent, shouldReturnTrueIfGivenCaseInsensitivelyEqualPathsThatExist) {
auto upper = std::filesystem::path("LICENSE");
auto lower = std::filesystem::path("license");
TEST(equivalent, shouldReturnFalseIfGivenCaseInsensitivelyUnequalThatExist) {
auto path1 = std::filesystem::path("./testing-plugins/LICENSE");
auto path2 = std::filesystem::path("./testing-plugins/README.md");

EXPECT_TRUE(loot::equivalent(lower, upper));
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));
}

TEST(equivalent,
shouldReturnFalseIfGivenCaseInsensitivelyEqualPathsThatDoNotExist) {
auto upper = std::filesystem::path("LICENSE2");
auto lower = std::filesystem::path("license2");
#ifdef _WIN32
TEST(equivalent, shouldReturnTrueIfGivenCaseInsensitivelyEqualPathsThatExist) {
auto upper = std::filesystem::path("./testing-plugins/LICENSE");
auto lower = std::filesystem::path("./testing-plugins/license");

EXPECT_FALSE(loot::equivalent(lower, upper));
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(
Expand All @@ -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));
}
Expand Down
19 changes: 1 addition & 18 deletions src/tests/common_game_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -278,17 +277,7 @@ class CommonGameTestFixture : public ::testing::TestWithParam<GameType> {
}

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) {
Expand Down Expand Up @@ -473,12 +462,6 @@ class CommonGameTestFixture : public ::testing::TestWithParam<GameType> {
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;
}
};
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/tests/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit aac3f68

Please sign in to comment.