From 714f9640cc90d875e28b537ab9a0942e5aae1029 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 24 Mar 2016 11:52:54 +0000 Subject: [PATCH] Improve free function helpers tests --- CMakeLists.txt | 2 +- .../{test_helpers.h => helpers_test.h} | 27 ++++++++++++++----- src/tests/base_game_test.h | 19 ++++++++----- src/tests/main.cpp | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) rename src/tests/backend/helpers/{test_helpers.h => helpers_test.h} (52%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19af5db1..951cbf92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,7 +240,7 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_settings_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/load_order_handler_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/git_helper_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/test_helpers.h" + "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/helpers_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/test_language.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/test_version.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/test_yaml_set_helpers.h" diff --git a/src/tests/backend/helpers/test_helpers.h b/src/tests/backend/helpers/helpers_test.h similarity index 52% rename from src/tests/backend/helpers/test_helpers.h rename to src/tests/backend/helpers/helpers_test.h index cceea1cc..d8b6b80f 100644 --- a/src/tests/backend/helpers/test_helpers.h +++ b/src/tests/backend/helpers/helpers_test.h @@ -27,22 +27,35 @@ along with LOOT. If not, see #include "backend/helpers/helpers.h" #include "backend/error.h" -#include "tests/fixtures.h" + +#include "tests/base_game_test.h" namespace loot { namespace test { - class GetCrc32Test : public SkyrimTest {}; + class GetCrc32Test : public BaseGameTest {}; - TEST_F(GetCrc32Test, MissingFile) { - EXPECT_THROW(GetCrc32(dataPath / "Blank.missing.esp"), error); + // Pass an empty first argument, as it's a prefix for the test instantation, + // but we only have the one so no prefix is necessary. + // Just test with one game because if it works for one it will work for them + // all. + INSTANTIATE_TEST_CASE_P(, + GetCrc32Test, + ::testing::Values( + GameSettings::tes5)); + + TEST_P(GetCrc32Test, gettingTheCrcOfAMissingFileShouldThrow) { + EXPECT_THROW(GetCrc32(dataPath / missingEsp), error); } - TEST_F(GetCrc32Test, ValidFile) { - EXPECT_EQ(0x24F0E2A1, GetCrc32(dataPath / "Blank.esp")); + TEST_P(GetCrc32Test, gettingTheCrcOfAFileShouldReturnTheCorrectValue) { + EXPECT_EQ(blankEsmCrc, GetCrc32(dataPath / blankEsm)); } - TEST(IntToHexString, PositiveAndZeroValues) { + TEST(IntToHexString, intToHexStringShouldOutputANonZeroPositiveIntegerCorrectly) { EXPECT_EQ("14", IntToHexString(20)); + } + + TEST(IntToHexString, intToHexStringShouldOutputZeroCorrectly) { EXPECT_EQ("0", IntToHexString(0)); } } diff --git a/src/tests/base_game_test.h b/src/tests/base_game_test.h index 73bfbd68..d5a683c5 100644 --- a/src/tests/base_game_test.h +++ b/src/tests/base_game_test.h @@ -25,6 +25,8 @@ along with LOOT. If not, see #ifndef LOOT_TEST_BASE_GAME_TEST #define LOOT_TEST_BASE_GAME_TEST +#include "backend/game/game_settings.h" + #include #include #include @@ -41,6 +43,7 @@ namespace loot { dataPath(getPluginsPath()), localPath(getLocalPath()), masterFile(getMasterFile()), + missingEsp("Blank.missing.esp"), blankEsm("Blank.esm"), blankDifferentEsm("Blank - Different.esm"), blankMasterDependentEsm("Blank - Master Dependent.esm"), @@ -58,6 +61,7 @@ namespace loot { ASSERT_TRUE(boost::filesystem::exists(localPath)); ASSERT_FALSE(boost::filesystem::exists(missingPath)); + ASSERT_FALSE(boost::filesystem::exists(dataPath / missingEsp)); ASSERT_TRUE(boost::filesystem::exists(dataPath / blankEsm)); ASSERT_TRUE(boost::filesystem::exists(dataPath / blankDifferentEsm)); @@ -139,6 +143,7 @@ namespace loot { const boost::filesystem::path localPath; const std::string masterFile; + const std::string missingEsp; const std::string blankEsm; const std::string blankDifferentEsm; const std::string blankMasterDependentEsm; @@ -154,34 +159,34 @@ namespace loot { private: inline boost::filesystem::path getLocalPath() const { - if (GetParam() == loot_game_tes4) + if (GetParam() == GameSettings::tes4) return "./local/Oblivion"; else return "./local/Skyrim"; } inline boost::filesystem::path getPluginsPath() const { - if (GetParam() == loot_game_tes4) + if (GetParam() == GameSettings::tes4) return "./Oblivion/Data"; else return "./Skyrim/Data"; } inline std::string getMasterFile() const { - if (GetParam() == loot_game_tes4) + if (GetParam() == GameSettings::tes4) return "Oblivion.esm"; - else if (GetParam() == loot_game_tes5) + else if (GetParam() == GameSettings::tes5) return "Skyrim.esm"; - else if (GetParam() == loot_game_fo3) + else if (GetParam() == GameSettings::fo3) return "Fallout3.esm"; - else if (GetParam() == loot_game_fonv) + else if (GetParam() == GameSettings::fonv) return "FalloutNV.esm"; else return "Fallout4.esm"; } inline uint32_t getBlankEsmCrc() const { - if (GetParam() == loot_game_tes4) + if (GetParam() == GameSettings::tes4) return 0x374E2A6F; else return 0x187BE342; diff --git a/src/tests/main.cpp b/src/tests/main.cpp index bf8c7199..267e06a2 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -46,7 +46,7 @@ #include "backend/game/game_settings_test.h" #include "backend/game/load_order_handler_test.h" #include "backend/helpers/git_helper_test.h" -#include "backend/helpers/test_helpers.h" +#include "backend/helpers/helpers_test.h" #include "backend/helpers/test_language.h" #include "backend/helpers/test_version.h" #include "backend/helpers/test_yaml_set_helpers.h"