Improve free function helpers tests

This commit is contained in:
Oliver Hamlet
2016-03-24 11:53:28 +00:00
parent 8f170b8a69
commit 714f9640cc
4 changed files with 34 additions and 16 deletions
+1 -1
View File
@@ -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"
@@ -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));
}
}
+12 -7
View File
@@ -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 <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
@@ -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;
+1 -1
View File
@@ -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"