From e1924a69ecf1388f79f5b6fe218b9c71581d115f Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 12 Jul 2016 17:25:12 +0100 Subject: [PATCH] Reimplement game IDs as game type enums This required some changes to how the test fixtures are implemented. --- CMakeLists.txt | 19 +++--- src/api/api.cpp | 11 ++-- src/api/loot_db.cpp | 2 +- src/backend/app/loot_settings.cpp | 34 +++++------ src/backend/app/loot_state.cpp | 2 +- src/backend/game/game.cpp | 6 +- src/backend/game/game.h | 4 +- src/backend/game/game_settings.cpp | 37 +++++------- src/backend/game/game_settings.h | 39 ++++++------- src/backend/game/game_type.h | 39 +++++++++++++ src/backend/game/load_order_handler.cpp | 20 +++---- src/backend/plugin/plugin.cpp | 4 +- src/gui/query_handler.cpp | 12 ++-- src/tests/api/api_game_operations_test.h | 11 ++-- src/tests/api/loot_create_db_test.h | 15 +++-- src/tests/api/loot_db_test.h | 14 ++--- src/tests/backend/app/loot_settings_test.h | 56 +++++++++--------- src/tests/backend/base_game_test.h | 58 +++++++++++++++++++ src/tests/backend/game/game_cache_test.h | 4 +- src/tests/backend/game/game_settings_test.h | 36 ++++++------ src/tests/backend/game/game_test.h | 20 +++---- .../backend/game/load_order_handler_test.h | 16 ++--- src/tests/backend/helpers/helpers_test.h | 4 +- src/tests/backend/masterlist_test.h | 12 ++-- .../backend/metadata/condition_grammar_test.h | 12 ++-- .../metadata/conditional_metadata_test.h | 12 ++-- src/tests/backend/metadata/message_test.h | 4 +- .../backend/metadata/plugin_dirty_info_test.h | 4 +- .../backend/metadata/plugin_metadata_test.h | 4 +- src/tests/backend/metadata_list_test.h | 4 +- src/tests/backend/plugin/plugin_sorter_test.h | 4 +- src/tests/backend/plugin/plugin_test.h | 18 +++--- ...game_test.h => common_game_test_fixture.h} | 48 ++++++++------- 33 files changed, 343 insertions(+), 242 deletions(-) create mode 100644 src/backend/game/game_type.h create mode 100644 src/tests/backend/base_game_test.h rename src/tests/{base_game_test.h => common_game_test_fixture.h} (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 073015d6..1da7eb62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/app/loot_paths.h" "${CMAKE_SOURCE_DIR}/src/backend/game/game.h" "${CMAKE_SOURCE_DIR}/src/backend/game/game_cache.h" "${CMAKE_SOURCE_DIR}/src/backend/game/game_settings.h" + "${CMAKE_SOURCE_DIR}/src/backend/game/game_type.h" "${CMAKE_SOURCE_DIR}/src/backend/game/load_order_handler.h" "${CMAKE_SOURCE_DIR}/src/backend/metadata_list.h" "${CMAKE_SOURCE_DIR}/src/backend/masterlist.h" @@ -236,17 +237,14 @@ set (LOOT_TESTS_SRC ${LOOT_SRC} "${CMAKE_SOURCE_DIR}/src/api/loot_db.cpp" "${CMAKE_SOURCE_DIR}/src/tests/backend/main.cpp") -set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/printers.h" - - # Testing this here rather than as part of the API tests +set (LOOT_TESTS_HEADERS # Testing this here rather than as part of the API tests # because it tests internal code and requires internal # linking. "${CMAKE_SOURCE_DIR}/src/tests/api/loot_db_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/backend/app/loot_paths_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/app/loot_settings_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/app/loot_state_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/backend/base_game_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_cache_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_settings_test.h" @@ -268,13 +266,13 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/plugin/plugin_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/plugin/plugin_sorter_test.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/masterlist_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/backend/metadata_list_test.h") + "${CMAKE_SOURCE_DIR}/src/tests/backend/metadata_list_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/common_game_test_fixture.h" + "${CMAKE_SOURCE_DIR}/src/tests/printers.h") set(LOOT_API_TESTS_SRC "${CMAKE_SOURCE_DIR}/src/tests/api/main.cpp") -set(LOOT_API_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h" - - "${CMAKE_SOURCE_DIR}/src/tests/api/api_game_operations_test.h" +set(LOOT_API_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/api/api_game_operations_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/loot_apply_load_order_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/loot_create_db_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/loot_eval_lists_test.h" @@ -287,7 +285,8 @@ set(LOOT_API_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/loot_sort_plugins_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/loot_update_masterlist_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/loot_write_minimal_list_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/api/test_api.h") + "${CMAKE_SOURCE_DIR}/src/tests/api/test_api.h" + "${CMAKE_SOURCE_DIR}/src/tests/common_game_test_fixture.h") source_group("Header Files\\backend" FILES ${LOOT_HEADERS}) source_group("Header Files\\gui" FILES ${LOOT_GUI_HEADERS}) diff --git a/src/api/api.cpp b/src/api/api.cpp index 0a9eb95a..db64eb5f 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -42,6 +42,7 @@ #include using loot::Error; +using loot::GameType; const unsigned int loot_ok = Error::asUnsignedInt(Error::Code::ok); const unsigned int loot_error_liblo_error = Error::asUnsignedInt(Error::Code::liblo_error); @@ -60,11 +61,11 @@ const unsigned int loot_error_sorting_error = Error::asUnsignedInt(Error::Code:: const unsigned int loot_return_max = loot_error_sorting_error; // The following are the games identifiers used by the API. -const unsigned int loot_game_tes4 = loot::Game::tes4; -const unsigned int loot_game_tes5 = loot::Game::tes5; -const unsigned int loot_game_fo3 = loot::Game::fo3; -const unsigned int loot_game_fonv = loot::Game::fonv; -const unsigned int loot_game_fo4 = loot::Game::fo4; +const unsigned int loot_game_tes4 = static_cast(GameType::tes4); +const unsigned int loot_game_tes5 = static_cast(GameType::tes5); +const unsigned int loot_game_fo3 = static_cast(GameType::fo3); +const unsigned int loot_game_fonv = static_cast(GameType::fonv); +const unsigned int loot_game_fo4 = static_cast(GameType::fo4); // LOOT message types. const unsigned int loot_message_say = static_cast(loot::Message::Type::say); diff --git a/src/api/loot_db.cpp b/src/api/loot_db.cpp index 312535cd..c9aff9ff 100644 --- a/src/api/loot_db.cpp +++ b/src/api/loot_db.cpp @@ -27,7 +27,7 @@ #include "../backend/error.h" loot_db::loot_db(const unsigned int clientGame, const std::string& gamePath, const boost::filesystem::path& gameLocalDataPath) - : Game(clientGame) { + : Game(loot::GameType(clientGame)) { this->SetGamePath(gamePath); this->Init(false, gameLocalDataPath); } diff --git a/src/backend/app/loot_settings.cpp b/src/backend/app/loot_settings.cpp index 960b2073..268deda7 100644 --- a/src/backend/app/loot_settings.cpp +++ b/src/backend/app/loot_settings.cpp @@ -36,12 +36,12 @@ namespace loot { LootSettings::LootSettings() : gameSettings({ - GameSettings(GameSettings::tes4), - GameSettings(GameSettings::tes5), - GameSettings(GameSettings::fo3), - GameSettings(GameSettings::fonv), - GameSettings(GameSettings::fo4), - GameSettings(GameSettings::tes4, "Nehrim") + GameSettings(GameType::tes4), + GameSettings(GameType::tes5), + GameSettings(GameType::fo3), + GameSettings(GameType::fonv), + GameSettings(GameType::fo4), + GameSettings(GameType::tes4, "Nehrim") .SetName("Nehrim - At Fate's Edge") .SetMaster("Nehrim.esm") .SetRegistryKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Nehrim - At Fate's Edge_is1\\InstallLocation"), @@ -83,20 +83,20 @@ namespace loot { gameSettings = settings["games"].as>(); // If a base game isn't in the settings, add it. - if (find(begin(gameSettings), end(gameSettings), GameSettings(GameSettings::tes4)) == end(gameSettings)) - gameSettings.push_back(GameSettings(GameSettings::tes4)); + if (find(begin(gameSettings), end(gameSettings), GameSettings(GameType::tes4)) == end(gameSettings)) + gameSettings.push_back(GameSettings(GameType::tes4)); - if (find(begin(gameSettings), end(gameSettings), GameSettings(GameSettings::tes5)) == end(gameSettings)) - gameSettings.push_back(GameSettings(GameSettings::tes5)); + if (find(begin(gameSettings), end(gameSettings), GameSettings(GameType::tes5)) == end(gameSettings)) + gameSettings.push_back(GameSettings(GameType::tes5)); - if (find(begin(gameSettings), end(gameSettings), GameSettings(GameSettings::fo3)) == end(gameSettings)) - gameSettings.push_back(GameSettings(GameSettings::fo3)); + if (find(begin(gameSettings), end(gameSettings), GameSettings(GameType::fo3)) == end(gameSettings)) + gameSettings.push_back(GameSettings(GameType::fo3)); - if (find(begin(gameSettings), end(gameSettings), GameSettings(GameSettings::fonv)) == end(gameSettings)) - gameSettings.push_back(GameSettings(GameSettings::fonv)); + if (find(begin(gameSettings), end(gameSettings), GameSettings(GameType::fonv)) == end(gameSettings)) + gameSettings.push_back(GameSettings(GameType::fonv)); - if (find(begin(gameSettings), end(gameSettings), GameSettings(GameSettings::fo4)) == end(gameSettings)) - gameSettings.push_back(GameSettings(GameSettings::fo4)); + if (find(begin(gameSettings), end(gameSettings), GameSettings(GameType::fo4)) == end(gameSettings)) + gameSettings.push_back(GameSettings(GameType::fo4)); } if (settings["filters"]) @@ -275,7 +275,7 @@ namespace loot { if (!yaml["Games"]) { // Update existing default branch, if the default // repositories are used. - if (settings.RepoURL() == GameSettings(settings.Id()).RepoURL() + if (settings.RepoURL() == GameSettings(settings.Type()).RepoURL() && oldDefaultBranches.count(settings.RepoBranch()) == 1) { settings.SetRepoBranch("v0.8"); } diff --git a/src/backend/app/loot_state.cpp b/src/backend/app/loot_state.cpp index ba6d007f..69bc12f5 100644 --- a/src/backend/app/loot_state.cpp +++ b/src/backend/app/loot_state.cpp @@ -212,7 +212,7 @@ namespace loot { std::lock_guard guard(mutex); BOOST_LOG_TRIVIAL(debug) << "Changing current game to that with folder: " << newGameFolder; - _currentGame = find(_games.begin(), _games.end(), Game(Game::autodetect, newGameFolder)); + _currentGame = find(_games.begin(), _games.end(), Game(GameType::autodetect, newGameFolder)); _currentGame->Init(true); // Update game path in settings object. diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index 7275f1fe..ffc7ac28 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -51,10 +51,10 @@ namespace loot { .SetRegistryKey(gameSettings.RegistryKey()); } - Game::Game(const unsigned int gameCode, const std::string& folder) : GameSettings(gameCode, folder), _pluginsFullyLoaded(false) {} + Game::Game(const GameType gameType, const std::string& folder) : GameSettings(gameType, folder), _pluginsFullyLoaded(false) {} void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppData) { - if (Id() != Game::tes4 && Id() != Game::tes5 && Id() != Game::fo3 && Id() != Game::fonv && Id() != Game::fo4) { + if (Type() != GameType::tes4 && Type() != GameType::tes5 && Type() != GameType::fo3 && Type() != GameType::fonv && Type() != GameType::fo4) { throw Error(Error::Code::invalid_args, lc::translate("Invalid game ID supplied.").str()); } @@ -81,7 +81,7 @@ namespace loot { } void Game::RedatePlugins() { - if (Id() != tes5) + if (Type() != GameType::tes5) return; list loadorder = GetLoadOrder(); diff --git a/src/backend/game/game.h b/src/backend/game/game.h index f5229058..ed59ab6b 100644 --- a/src/backend/game/game.h +++ b/src/backend/game/game.h @@ -37,9 +37,9 @@ namespace loot { class Game : public GameSettings, public LoadOrderHandler, public GameCache { public: //Game functions. - Game(); //Sets game to LOOT_Game::autodetect, with all other vars being empty. + Game(); //Sets game to GameType::autodetect, with all other vars being empty. Game(const GameSettings& gameSettings); - Game(const unsigned int baseGameCode, const std::string& lootFolder = ""); + Game(const GameType gameType, const std::string& lootFolder = ""); void Init(bool createFolder, const boost::filesystem::path& gameLocalAppData = ""); diff --git a/src/backend/game/game_settings.cpp b/src/backend/game/game_settings.cpp index 7fa51054..6dfc76b5 100644 --- a/src/backend/game/game_settings.cpp +++ b/src/backend/game/game_settings.cpp @@ -37,17 +37,10 @@ namespace fs = boost::filesystem; namespace lc = boost::locale; namespace loot { - const unsigned int GameSettings::autodetect = 0; - const unsigned int GameSettings::tes4 = 1; - const unsigned int GameSettings::tes5 = 2; - const unsigned int GameSettings::fo3 = 3; - const unsigned int GameSettings::fonv = 4; - const unsigned int GameSettings::fo4 = 5; + GameSettings::GameSettings() : type_(GameType::autodetect) {} - GameSettings::GameSettings() : _id(GameSettings::autodetect) {} - - GameSettings::GameSettings(const unsigned int gameCode, const std::string& folder) : _id(gameCode) { - if (Id() == GameSettings::tes4) { + GameSettings::GameSettings(const GameType gameType, const std::string& folder) : type_(gameType) { + if (Type() == GameType::tes4) { _name = "TES IV: Oblivion"; _registryKey = "Software\\Bethesda Softworks\\Oblivion\\Installed Path"; _lootFolderName = "Oblivion"; @@ -55,7 +48,7 @@ namespace loot { _repositoryURL = "https://github.com/loot/oblivion.git"; _repositoryBranch = "v0.8"; } - else if (Id() == GameSettings::tes5) { + else if (Type() == GameType::tes5) { _name = "TES V: Skyrim"; _registryKey = "Software\\Bethesda Softworks\\Skyrim\\Installed Path"; _lootFolderName = "Skyrim"; @@ -63,7 +56,7 @@ namespace loot { _repositoryURL = "https://github.com/loot/skyrim.git"; _repositoryBranch = "v0.8"; } - else if (Id() == GameSettings::fo3) { + else if (Type() == GameType::fo3) { _name = "Fallout 3"; _registryKey = "Software\\Bethesda Softworks\\Fallout3\\Installed Path"; _lootFolderName = "Fallout3"; @@ -71,7 +64,7 @@ namespace loot { _repositoryURL = "https://github.com/loot/fallout3.git"; _repositoryBranch = "v0.8"; } - else if (Id() == GameSettings::fonv) { + else if (Type() == GameType::fonv) { _name = "Fallout: New Vegas"; _registryKey = "Software\\Bethesda Softworks\\FalloutNV\\Installed Path"; _lootFolderName = "FalloutNV"; @@ -79,7 +72,7 @@ namespace loot { _repositoryURL = "https://github.com/loot/falloutnv.git"; _repositoryBranch = "v0.8"; } - else if (Id() == GameSettings::fo4) { + else if (Type() == GameType::fo4) { _name = "Fallout 4"; _registryKey = "Software\\Bethesda Softworks\\Fallout4\\Installed Path"; _lootFolderName = "Fallout4"; @@ -125,18 +118,18 @@ namespace loot { return (boost::iequals(_name, rhs.Name()) || boost::iequals(_lootFolderName, rhs.FolderName())); } - unsigned int GameSettings::Id() const { - return _id; + GameType GameSettings::Type() const { + return type_; } libespm::GameId GameSettings::LibespmId() const { - if (_id == GameSettings::tes4) + if (type_ == GameType::tes4) return libespm::GameId::OBLIVION; - else if (_id == GameSettings::tes5) + else if (type_ == GameType::tes5) return libespm::GameId::SKYRIM; - else if (_id == GameSettings::fo3) + else if (type_ == GameType::fo3) return libespm::GameId::FALLOUT3; - else if (_id == GameSettings::fonv) + else if (type_ == GameType::fonv) return libespm::GameId::FALLOUTNV; else return libespm::GameId::FALLOUT4; @@ -192,7 +185,7 @@ namespace loot { } std::string GameSettings::GetArchiveFileExtension() const { - if (_id == GameSettings::fo4) + if (type_ == GameType::fo4) return ".ba2"; else return ".bsa"; @@ -238,7 +231,7 @@ namespace loot { namespace YAML { Emitter& operator << (Emitter& out, const loot::GameSettings& rhs) { out << BeginMap - << Key << "type" << Value << YAML::SingleQuoted << loot::GameSettings(rhs.Id()).FolderName() + << Key << "type" << Value << YAML::SingleQuoted << loot::GameSettings(rhs.Type()).FolderName() << Key << "folder" << Value << YAML::SingleQuoted << rhs.FolderName() << Key << "name" << Value << YAML::SingleQuoted << rhs.Name() << Key << "master" << Value << YAML::SingleQuoted << rhs.Master() diff --git a/src/backend/game/game_settings.h b/src/backend/game/game_settings.h index bd611a54..a45c66c0 100644 --- a/src/backend/game/game_settings.h +++ b/src/backend/game/game_settings.h @@ -34,18 +34,20 @@ #include +#include "backend/game/game_type.h" + namespace loot { class GameSettings { public: //Game functions. - GameSettings(); //Sets game to LOOT_Game::autodetect, with all other vars being empty. - GameSettings(const unsigned int baseGameCode, const std::string& lootFolder = ""); + GameSettings(); //Sets game to LOOT_GameType::autodetect, with all other vars being empty. + GameSettings(const GameType gameType, const std::string& lootFolder = ""); bool IsInstalled(); //Sets gamePath if the current value is not valid and a valid path is found. bool operator == (const GameSettings& rhs) const; //Compares names and folder names. - unsigned int Id() const; + GameType Type() const; libespm::GameId LibespmId() const; std::string Name() const; //Returns the game's name, eg. "TES IV: Oblivion". std::string FolderName() const; @@ -67,15 +69,8 @@ namespace loot { GameSettings& SetRepoURL(const std::string& repositoryURL); GameSettings& SetRepoBranch(const std::string& repositoryBranch); GameSettings& SetGamePath(const boost::filesystem::path& path); - - static const unsigned int autodetect; - static const unsigned int tes4; - static const unsigned int tes5; - static const unsigned int fo3; - static const unsigned int fonv; - static const unsigned int fo4; private: - unsigned int _id; + GameType type_; std::string _name; std::string _masterFile; @@ -95,7 +90,7 @@ namespace YAML { static Node encode(const loot::GameSettings& rhs) { Node node; - node["type"] = loot::GameSettings(rhs.Id()).FolderName(); + node["type"] = loot::GameSettings(rhs.Type()).FolderName(); node["name"] = rhs.Name(); node["folder"] = rhs.FolderName(); node["master"] = rhs.Master(); @@ -115,16 +110,16 @@ namespace YAML { if (!node["type"]) throw RepresentationException(node.Mark(), "bad conversion: 'type' key missing from 'game settings' object"); - if (node["type"].as() == loot::GameSettings(loot::GameSettings::tes4).FolderName()) - rhs = loot::GameSettings(loot::GameSettings::tes4, node["folder"].as()); - else if (node["type"].as() == loot::GameSettings(loot::GameSettings::tes5).FolderName()) - rhs = loot::GameSettings(loot::GameSettings::tes5, node["folder"].as()); - else if (node["type"].as() == loot::GameSettings(loot::GameSettings::fo3).FolderName()) - rhs = loot::GameSettings(loot::GameSettings::fo3, node["folder"].as()); - else if (node["type"].as() == loot::GameSettings(loot::GameSettings::fonv).FolderName()) - rhs = loot::GameSettings(loot::GameSettings::fonv, node["folder"].as()); - else if (node["type"].as() == loot::GameSettings(loot::GameSettings::fo4).FolderName()) - rhs = loot::GameSettings(loot::GameSettings::fo4, node["folder"].as()); + if (node["type"].as() == loot::GameSettings(loot::GameType::tes4).FolderName()) + rhs = loot::GameSettings(loot::GameType::tes4, node["folder"].as()); + else if (node["type"].as() == loot::GameSettings(loot::GameType::tes5).FolderName()) + rhs = loot::GameSettings(loot::GameType::tes5, node["folder"].as()); + else if (node["type"].as() == loot::GameSettings(loot::GameType::fo3).FolderName()) + rhs = loot::GameSettings(loot::GameType::fo3, node["folder"].as()); + else if (node["type"].as() == loot::GameSettings(loot::GameType::fonv).FolderName()) + rhs = loot::GameSettings(loot::GameType::fonv, node["folder"].as()); + else if (node["type"].as() == loot::GameSettings(loot::GameType::fo4).FolderName()) + rhs = loot::GameSettings(loot::GameType::fo4, node["folder"].as()); else throw RepresentationException(node.Mark(), "bad conversion: invalid value for 'type' key in 'game settings' object"); diff --git a/src/backend/game/game_type.h b/src/backend/game/game_type.h new file mode 100644 index 00000000..9961ecda --- /dev/null +++ b/src/backend/game/game_type.h @@ -0,0 +1,39 @@ +/* LOOT + +A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and +Fallout: New Vegas. + +Copyright (C) 2012-2016 WrinklyNinja + +This file is part of LOOT. + +LOOT is free software: you can redistribute +it and/or modify it under the terms of the GNU General Public License +as published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +LOOT is distributed in the hope that it will +be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LOOT. If not, see +. +*/ + +#ifndef LOOT_BACKEND_GAME_GAME_TYPE +#define LOOT_BACKEND_GAME_GAME_TYPE + +namespace loot { + enum struct GameType : unsigned int { + autodetect = 0, + tes4 = 1, + tes5 = 2, + fo3 = 3, + fonv = 4, + fo4 = 5, + }; +} + +#endif diff --git a/src/backend/game/load_order_handler.cpp b/src/backend/game/load_order_handler.cpp index f52f8f6f..ca629bbc 100644 --- a/src/backend/game/load_order_handler.cpp +++ b/src/backend/game/load_order_handler.cpp @@ -42,11 +42,11 @@ namespace loot { } void LoadOrderHandler::Init(const GameSettings& game, const boost::filesystem::path& gameLocalAppData) { - if (game.Id() != GameSettings::tes4 - && game.Id() != GameSettings::tes5 - && game.Id() != GameSettings::fo3 - && game.Id() != GameSettings::fonv - && game.Id() != GameSettings::fo4) { + if (game.Type() != GameType::tes4 + && game.Type() != GameType::tes5 + && game.Type() != GameType::fo3 + && game.Type() != GameType::fonv + && game.Type() != GameType::fo4) { throw Error(Error::Code::invalid_args, lc::translate("Unsupported game ID supplied.").str()); } @@ -67,15 +67,15 @@ namespace loot { } int ret; - if (game.Id() == GameSettings::tes4) + if (game.Type() == GameType::tes4) ret = lo_create_handle(&_gh, LIBLO_GAME_TES4, game.GamePath().string().c_str(), gameLocalDataPath); - else if (game.Id() == GameSettings::tes5) + else if (game.Type() == GameType::tes5) ret = lo_create_handle(&_gh, LIBLO_GAME_TES5, game.GamePath().string().c_str(), gameLocalDataPath); - else if (game.Id() == GameSettings::fo3) + else if (game.Type() == GameType::fo3) ret = lo_create_handle(&_gh, LIBLO_GAME_FO3, game.GamePath().string().c_str(), gameLocalDataPath); - else if (game.Id() == GameSettings::fonv) + else if (game.Type() == GameType::fonv) ret = lo_create_handle(&_gh, LIBLO_GAME_FNV, game.GamePath().string().c_str(), gameLocalDataPath); - else if (game.Id() == GameSettings::fo4) + else if (game.Type() == GameType::fo4) ret = lo_create_handle(&_gh, LIBLO_GAME_FO4, game.GamePath().string().c_str(), gameLocalDataPath); else ret = LIBLO_ERROR_INVALID_ARGS; diff --git a/src/backend/plugin/plugin.cpp b/src/backend/plugin/plugin.cpp index d8ea6381..a07ea38b 100644 --- a/src/backend/plugin/plugin.cpp +++ b/src/backend/plugin/plugin.cpp @@ -94,11 +94,11 @@ namespace loot { // Get whether the plugin loads an archive (BSA/BA2) or not. const string archiveExtension = game.GetArchiveFileExtension(); - if (game.Id() == Game::tes5) { + if (game.Type() == GameType::tes5) { // Skyrim plugins only load BSAs that exactly match their basename. _loadsArchive = boost::filesystem::exists(game.DataPath() / (Name().substr(0, Name().length() - 4) + archiveExtension)); } - else if (game.Id() != Game::tes4 || boost::iends_with(Name(), ".esp")) { + else if (game.Type() != GameType::tes4 || boost::iends_with(Name(), ".esp")) { //Oblivion .esp files and FO3, FNV, FO4 plugins can load archives which begin with the plugin basename. string basename = Name().substr(0, Name().length() - 4); for (boost::filesystem::directory_iterator it(game.DataPath()); it != boost::filesystem::directory_iterator(); ++it) { diff --git a/src/gui/query_handler.cpp b/src/gui/query_handler.cpp index ce6db71d..1a1850ac 100644 --- a/src/gui/query_handler.cpp +++ b/src/gui/query_handler.cpp @@ -592,11 +592,11 @@ namespace loot { std::string QueryHandler::GetGameTypes() { BOOST_LOG_TRIVIAL(info) << "Getting LOOT's supported game types."; YAML::Node temp; - temp.push_back(Game(Game::tes4).FolderName()); - temp.push_back(Game(Game::tes5).FolderName()); - temp.push_back(Game(Game::fo3).FolderName()); - temp.push_back(Game(Game::fonv).FolderName()); - temp.push_back(Game(Game::fo4).FolderName()); + temp.push_back(Game(GameType::tes4).FolderName()); + temp.push_back(Game(GameType::tes5).FolderName()); + temp.push_back(Game(GameType::fo3).FolderName()); + temp.push_back(Game(GameType::fonv).FolderName()); + temp.push_back(Game(GameType::fo4).FolderName()); return JSON::stringify(temp); } @@ -915,7 +915,7 @@ namespace loot { list plugins = sorter.Sort(_lootState.CurrentGame(), _lootState.getLanguage().GetCode()); // If TESV or FO4, check if load order has been changed. - if ((_lootState.CurrentGame().Id() == Game::tes5 || _lootState.CurrentGame().Id() == Game::fo4) + if ((_lootState.CurrentGame().Type() == GameType::tes5 || _lootState.CurrentGame().Type() == GameType::fo4) && equal(begin(plugins), end(plugins), begin(_lootState.CurrentGame().GetLoadOrder()))) { // Load order has not been changed, set it without asking for // user input because there are no changes to accept and some diff --git a/src/tests/api/api_game_operations_test.h b/src/tests/api/api_game_operations_test.h index 3216f91f..be8f3158 100644 --- a/src/tests/api/api_game_operations_test.h +++ b/src/tests/api/api_game_operations_test.h @@ -25,13 +25,16 @@ along with LOOT. If not, see #ifndef LOOT_TEST_API_GAME_OPERATIONS_TEST #define LOOT_TEST_API_GAME_OPERATIONS_TEST -#include "../base_game_test.h" +#include "tests/common_game_test_fixture.h" namespace loot { namespace test { - class ApiGameOperationsTest : public BaseGameTest { + class ApiGameOperationsTest : + public ::testing::TestWithParam, + public CommonGameTestFixture { protected: ApiGameOperationsTest() : + CommonGameTestFixture(GetParam()), db(nullptr), masterlistPath(localPath / "masterlist.yaml"), noteMessage("Do not clean ITM records, they are intentional and required for the mod to function."), @@ -39,7 +42,7 @@ namespace loot { errorMessage("Obsolete. Remove this and install Enhanced Weather.") {} inline virtual void SetUp() { - BaseGameTest::SetUp(); + setUp(); ASSERT_FALSE(boost::filesystem::exists(masterlistPath)); @@ -47,7 +50,7 @@ namespace loot { } inline virtual void TearDown() { - BaseGameTest::TearDown(); + tearDown(); ASSERT_NO_THROW(loot_destroy_db(db)); diff --git a/src/tests/api/loot_create_db_test.h b/src/tests/api/loot_create_db_test.h index 09434741..f8f070aa 100644 --- a/src/tests/api/loot_create_db_test.h +++ b/src/tests/api/loot_create_db_test.h @@ -26,19 +26,26 @@ along with LOOT. If not, see #define LOOT_TEST_LOOT_CREATE_DB #include "../include/loot/api.h" -#include "tests/base_game_test.h" +#include "tests/common_game_test_fixture.h" #include namespace loot { namespace test { - class loot_create_db_test : public BaseGameTest { + class loot_create_db_test : + public ::testing::TestWithParam, + public CommonGameTestFixture { protected: loot_create_db_test() : + CommonGameTestFixture(GetParam()), db(nullptr) {} - inline virtual void TearDown() { - BaseGameTest::TearDown(); + void SetUp() { + setUp(); + } + + void TearDown() { + tearDown(); ASSERT_NO_THROW(loot_destroy_db(db)); } diff --git a/src/tests/api/loot_db_test.h b/src/tests/api/loot_db_test.h index 79b9b866..aa63ac92 100644 --- a/src/tests/api/loot_db_test.h +++ b/src/tests/api/loot_db_test.h @@ -27,7 +27,7 @@ along with LOOT. If not, see #include "api/loot_db.h" #include "backend/game/game_settings.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -39,7 +39,7 @@ namespace loot { virtual void SetUp() { BaseGameTest::SetUp(); - db = new loot_db(GetParam(), dataPath.parent_path().string().c_str(), localPath.string().c_str()); + db = new loot_db(static_cast(GetParam()), dataPath.parent_path().string().c_str(), localPath.string().c_str()); } inline virtual void TearDown() { @@ -56,11 +56,11 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, loot_db_test, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(loot_db_test, settingRevisionIdStringShouldCopyIt) { db->setRevisionIdString("id"); diff --git a/src/tests/backend/app/loot_settings_test.h b/src/tests/backend/app/loot_settings_test.h index cc498ba5..0484d91b 100644 --- a/src/tests/backend/app/loot_settings_test.h +++ b/src/tests/backend/app/loot_settings_test.h @@ -47,12 +47,12 @@ namespace loot { TEST_F(LootSettingsTest, defaultConstructorShouldSetDefaultValues) { const std::string currentVersion = LootVersion::string(); const std::vector expectedGameSettings({ - GameSettings(GameSettings::tes4), - GameSettings(GameSettings::tes5), - GameSettings(GameSettings::fo3), - GameSettings(GameSettings::fonv), - GameSettings(GameSettings::fo4), - GameSettings(GameSettings::tes4, "Nehrim") + GameSettings(GameType::tes4), + GameSettings(GameType::tes5), + GameSettings(GameType::fo3), + GameSettings(GameType::fonv), + GameSettings(GameType::fo4), + GameSettings(GameType::tes4, "Nehrim") .SetName("Nehrim - At Fate's Edge") .SetMaster("Nehrim.esm") .SetRegistryKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Nehrim - At Fate's Edge_is1\\InstallLocation"), @@ -74,37 +74,37 @@ namespace loot { const std::vector actualGameSettings = settings.getGameSettings(); EXPECT_EQ(expectedGameSettings, actualGameSettings); - EXPECT_EQ(expectedGameSettings[0].Id(), actualGameSettings[0].Id()); + EXPECT_EQ(expectedGameSettings[0].Type(), actualGameSettings[0].Type()); EXPECT_EQ(expectedGameSettings[0].Master(), actualGameSettings[0].Master()); EXPECT_EQ(expectedGameSettings[0].RegistryKey(), actualGameSettings[0].RegistryKey()); EXPECT_EQ(expectedGameSettings[0].RepoURL(), actualGameSettings[0].RepoURL()); EXPECT_EQ(expectedGameSettings[0].RepoBranch(), actualGameSettings[0].RepoBranch()); - EXPECT_EQ(expectedGameSettings[1].Id(), actualGameSettings[1].Id()); + EXPECT_EQ(expectedGameSettings[1].Type(), actualGameSettings[1].Type()); EXPECT_EQ(expectedGameSettings[1].Master(), actualGameSettings[1].Master()); EXPECT_EQ(expectedGameSettings[1].RegistryKey(), actualGameSettings[1].RegistryKey()); EXPECT_EQ(expectedGameSettings[1].RepoURL(), actualGameSettings[1].RepoURL()); EXPECT_EQ(expectedGameSettings[1].RepoBranch(), actualGameSettings[1].RepoBranch()); - EXPECT_EQ(expectedGameSettings[2].Id(), actualGameSettings[2].Id()); + EXPECT_EQ(expectedGameSettings[2].Type(), actualGameSettings[2].Type()); EXPECT_EQ(expectedGameSettings[2].Master(), actualGameSettings[2].Master()); EXPECT_EQ(expectedGameSettings[2].RegistryKey(), actualGameSettings[2].RegistryKey()); EXPECT_EQ(expectedGameSettings[2].RepoURL(), actualGameSettings[2].RepoURL()); EXPECT_EQ(expectedGameSettings[2].RepoBranch(), actualGameSettings[2].RepoBranch()); - EXPECT_EQ(expectedGameSettings[3].Id(), actualGameSettings[3].Id()); + EXPECT_EQ(expectedGameSettings[3].Type(), actualGameSettings[3].Type()); EXPECT_EQ(expectedGameSettings[3].Master(), actualGameSettings[3].Master()); EXPECT_EQ(expectedGameSettings[3].RegistryKey(), actualGameSettings[3].RegistryKey()); EXPECT_EQ(expectedGameSettings[3].RepoURL(), actualGameSettings[3].RepoURL()); EXPECT_EQ(expectedGameSettings[3].RepoBranch(), actualGameSettings[3].RepoBranch()); - EXPECT_EQ(expectedGameSettings[4].Id(), actualGameSettings[4].Id()); + EXPECT_EQ(expectedGameSettings[4].Type(), actualGameSettings[4].Type()); EXPECT_EQ(expectedGameSettings[4].Master(), actualGameSettings[4].Master()); EXPECT_EQ(expectedGameSettings[4].RegistryKey(), actualGameSettings[4].RegistryKey()); EXPECT_EQ(expectedGameSettings[4].RepoURL(), actualGameSettings[4].RepoURL()); EXPECT_EQ(expectedGameSettings[4].RepoBranch(), actualGameSettings[4].RepoBranch()); - EXPECT_EQ(expectedGameSettings[5].Id(), actualGameSettings[5].Id()); + EXPECT_EQ(expectedGameSettings[5].Type(), actualGameSettings[5].Type()); EXPECT_EQ(expectedGameSettings[5].Master(), actualGameSettings[5].Master()); EXPECT_EQ(expectedGameSettings[5].RegistryKey(), actualGameSettings[5].RegistryKey()); EXPECT_EQ(expectedGameSettings[5].RepoURL(), actualGameSettings[5].RepoURL()); @@ -135,7 +135,7 @@ namespace loot { {"right", 4}, }); const std::vector games({ - GameSettings(GameSettings::tes4).SetName("Game Name"), + GameSettings(GameType::tes4).SetName("Game Name"), }); const std::map filters({ {"hideBashTags", false}, @@ -188,7 +188,7 @@ namespace loot { const std::string Language = "fr"; const std::string LastGame = "Skyrim"; const std::vector Games({ - GameSettings(GameSettings::tes4).SetName("Game Name"), + GameSettings(GameType::tes4).SetName("Game Name"), }); YAML::Node inputYaml; @@ -229,10 +229,10 @@ namespace loot { const std::string LastGame = "Skyrim"; const std::string lastGame = "auto"; const std::vector Games({ - GameSettings(GameSettings::tes4).SetName("Old Game Name"), + GameSettings(GameType::tes4).SetName("Old Game Name"), }); const std::vector games({ - GameSettings(GameSettings::fo3).SetName("Game Name"), + GameSettings(GameType::fo3).SetName("Game Name"), }); YAML::Node inputYaml; @@ -267,7 +267,7 @@ namespace loot { } TEST_F(LootSettingsTest, loadingFromYamlShouldUpgradeOldDefaultGameRepositoryBranches) { - const std::vector games({GameSettings(GameSettings::tes4)}); + const std::vector games({GameSettings(GameType::tes4)}); YAML::Node inputYaml; inputYaml["games"] = games; @@ -279,7 +279,7 @@ namespace loot { } TEST_F(LootSettingsTest, loadingFromYamlShouldNotUpgradeNonDefaultGameRepositoryBranches) { - const std::vector games({GameSettings(GameSettings::tes4)}); + const std::vector games({GameSettings(GameType::tes4)}); YAML::Node inputYaml; inputYaml["games"] = games; @@ -291,28 +291,28 @@ namespace loot { } TEST_F(LootSettingsTest, loadingFromYamlShouldAddMissingBaseGames) { - const std::vector games({GameSettings(GameSettings::tes4)}); + const std::vector games({GameSettings(GameType::tes4)}); YAML::Node inputYaml; inputYaml["games"] = games; settings.load(inputYaml); const std::vector expectedGameSettings({ - GameSettings(GameSettings::tes4), - GameSettings(GameSettings::tes5), - GameSettings(GameSettings::fo3), - GameSettings(GameSettings::fonv), - GameSettings(GameSettings::fo4), + GameSettings(GameType::tes4), + GameSettings(GameType::tes5), + GameSettings(GameType::fo3), + GameSettings(GameType::fonv), + GameSettings(GameType::fo4), }); EXPECT_EQ(expectedGameSettings, settings.getGameSettings()); } TEST_F(LootSettingsTest, loadingFromYamlShouldSkipUnrecognisedGames) { YAML::Node inputYaml; - inputYaml["games"][0] = GameSettings(GameSettings::tes4); + inputYaml["games"][0] = GameSettings(GameType::tes4); inputYaml["games"][0]["type"] = "Foobar"; inputYaml["games"][0]["name"] = "Foobar"; - inputYaml["games"][1] = GameSettings(GameSettings::tes5).SetName("Game Name"); + inputYaml["games"][1] = GameSettings(GameType::tes5).SetName("Game Name"); settings.load(inputYaml); @@ -385,7 +385,7 @@ namespace loot { } TEST_F(LootSettingsTest, storeGameSettingsShouldReplaceExistingGameSettings) { - const std::vector gameSettings({GameSettings(GameSettings::tes5)}); + const std::vector gameSettings({GameSettings(GameType::tes5)}); settings.storeGameSettings(gameSettings); EXPECT_EQ(gameSettings, settings.getGameSettings()); @@ -434,7 +434,7 @@ namespace loot { {"right", 4}, }); const std::vector games({ - GameSettings(GameSettings::tes4).SetName("Game Name"), + GameSettings(GameType::tes4).SetName("Game Name"), }); const std::map filters({ {"hideBashTags", false}, diff --git a/src/tests/backend/base_game_test.h b/src/tests/backend/base_game_test.h new file mode 100644 index 00000000..a2ad839c --- /dev/null +++ b/src/tests/backend/base_game_test.h @@ -0,0 +1,58 @@ +/* LOOT + +A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and +Fallout: New Vegas. + +Copyright (C) 2013-2016 WrinklyNinja + +This file is part of LOOT. + +LOOT is free software: you can redistribute +it and/or modify it under the terms of the GNU General Public License +as published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +LOOT is distributed in the hope that it will +be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LOOT. If not, see +. +*/ + +#ifndef LOOT_TEST_BASE_GAME_TEST +#define LOOT_TEST_BASE_GAME_TEST + +#include +#include +#include +#include + +#include +#include + +#include "tests/common_game_test_fixture.h" + +namespace loot { + namespace test { + class BaseGameTest : + public ::testing::TestWithParam, + public CommonGameTestFixture { + protected: + BaseGameTest() : + CommonGameTestFixture(static_cast(GetParam())) {} + + inline virtual void SetUp() { + setUp(); + } + + inline virtual void TearDown() { + tearDown(); + } + }; + } +} + +#endif diff --git a/src/tests/backend/game/game_cache_test.h b/src/tests/backend/game/game_cache_test.h index 1c08cedc..fee9a18a 100644 --- a/src/tests/backend/game/game_cache_test.h +++ b/src/tests/backend/game/game_cache_test.h @@ -27,7 +27,7 @@ along with LOOT. If not, see #include "backend/game/game_cache.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -56,7 +56,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, GameCacheTest, ::testing::Values( - Game::tes5)); + GameType::tes5)); TEST_P(GameCacheTest, copyConstructorShouldCopyCachedData) { initialiseGame(); diff --git a/src/tests/backend/game/game_settings_test.h b/src/tests/backend/game/game_settings_test.h index 7ac48483..944d529c 100644 --- a/src/tests/backend/game/game_settings_test.h +++ b/src/tests/backend/game/game_settings_test.h @@ -28,7 +28,7 @@ along with LOOT. If not, see #include "backend/app/loot_paths.h" #include "backend/game/game_settings.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -44,10 +44,10 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, GameSettingsTest, ::testing::Values( - GameSettings::tes5)); + GameType::tes5)); TEST_P(GameSettingsTest, defaultConstructorShouldInitialiseIdToAutodetectAndAllOtherSettingsToEmptyStrings) { - EXPECT_EQ(GameSettings::autodetect, game.Id()); + EXPECT_EQ(GameType::autodetect, game.Type()); EXPECT_EQ("", game.Name()); EXPECT_EQ("", game.FolderName()); EXPECT_EQ("", game.Master()); @@ -62,9 +62,9 @@ namespace loot { } TEST_P(GameSettingsTest, idConstructorShouldInitialiseSettingsToDefaultsForThatGame) { - game = GameSettings(GameSettings::tes5); + game = GameSettings(GameType::tes5); - EXPECT_EQ(GameSettings::tes5, game.Id()); + EXPECT_EQ(GameType::tes5, game.Type()); EXPECT_EQ("TES V: Skyrim", game.Name()); EXPECT_EQ("Skyrim", game.FolderName()); EXPECT_EQ("Skyrim.esm", game.Master()); @@ -80,7 +80,7 @@ namespace loot { } TEST_P(GameSettingsTest, idConstructorShouldSetGameFolderIfGiven) { - game = GameSettings(GameSettings::tes5, "folder"); + game = GameSettings(GameType::tes5, "folder"); EXPECT_EQ("folder", game.FolderName()); EXPECT_EQ(LootPaths::getLootDataPath() / "folder" / "masterlist.yaml", game.MasterlistPath()); @@ -93,19 +93,19 @@ namespace loot { } TEST_P(GameSettingsTest, isInstalledShouldBeTrueIfGamePathIsValid) { - game = GameSettings(GameSettings::tes5); + game = GameSettings(GameType::tes5); game.SetGamePath(dataPath.parent_path()); EXPECT_TRUE(game.IsInstalled()); } TEST_P(GameSettingsTest, gameSettingsWithTheSameIdsShouldBeEqual) { - GameSettings game1 = GameSettings(GameSettings::tes5, "game1") + GameSettings game1 = GameSettings(GameType::tes5, "game1") .SetMaster("master1") .SetRegistryKey("key1") .SetRepoURL("url1") .SetRepoBranch("branch1") .SetGamePath("path1"); - GameSettings game2 = GameSettings(GameSettings::tes5, "game2") + GameSettings game2 = GameSettings(GameType::tes5, "game2") .SetMaster("master2") .SetRegistryKey("key2") .SetRepoURL("url2") @@ -116,23 +116,23 @@ namespace loot { } TEST_P(GameSettingsTest, gameSettingsWithTheSameNameShouldBeEqual) { - GameSettings game1 = GameSettings(GameSettings::tes4) + GameSettings game1 = GameSettings(GameType::tes4) .SetName("name"); - GameSettings game2 = GameSettings(GameSettings::tes5) + GameSettings game2 = GameSettings(GameType::tes5) .SetName("name"); EXPECT_TRUE(game1 == game2); } TEST_P(GameSettingsTest, gameSettingsWithDifferentIdsAndNamesShouldNotBeEqual) { - GameSettings game1 = GameSettings(GameSettings::tes4); - GameSettings game2 = GameSettings(GameSettings::tes5); + GameSettings game1 = GameSettings(GameType::tes4); + GameSettings game2 = GameSettings(GameType::tes5); EXPECT_FALSE(game1 == game2); } TEST_P(GameSettingsTest, getArchiveFileExtensionShouldReturnDotBa2IfGameIdIsFallout4) { - GameSettings game(GameSettings::fo4); + GameSettings game(GameType::fo4); EXPECT_EQ(".ba2", game.GetArchiveFileExtension()); } @@ -181,7 +181,7 @@ namespace loot { } TEST_P(GameSettingsTest, emittingYamlShouldSerialiseDataCorrectly) { - GameSettings game(GameSettings::tes5, "folder1"); + GameSettings game(GameType::tes5, "folder1"); game.SetName("name1") .SetMaster("master1") .SetRegistryKey("key1") @@ -202,7 +202,7 @@ namespace loot { } TEST_P(GameSettingsTest, encodingAsYamlShouldConvertDataCorrectly) { - GameSettings game(GameSettings::tes5, "folder1"); + GameSettings game(GameType::tes5, "folder1"); game.SetName("name1") .SetMaster("master1") .SetRegistryKey("key1") @@ -233,7 +233,7 @@ namespace loot { "registry: 'key1'"); GameSettings game = node.as(); - EXPECT_EQ(GameSettings::tes5, game.Id()); + EXPECT_EQ(GameType::tes5, game.Type()); EXPECT_EQ("name1", game.Name()); EXPECT_EQ("folder1", game.FolderName()); EXPECT_EQ("master1", game.Master()); @@ -267,7 +267,7 @@ namespace loot { "branch: 'branch1'\n"); game = node.as(); - EXPECT_EQ(GameSettings::tes5, game.Id()); + EXPECT_EQ(GameType::tes5, game.Type()); EXPECT_EQ("TES V: Skyrim", game.Name()); EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey()); EXPECT_EQ("", game.GamePath()); diff --git a/src/tests/backend/game/game_test.h b/src/tests/backend/game/game_test.h index 9df12557..d7d8abff 100644 --- a/src/tests/backend/game/game_test.h +++ b/src/tests/backend/game/game_test.h @@ -49,17 +49,17 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, GameTest, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(GameTest, defaultConstructorShouldConstructWithDefaultGameSettings) { GameSettings settings; Game game; - EXPECT_EQ(settings.Id(), game.Id()); + EXPECT_EQ(settings.Type(), game.Type()); EXPECT_EQ(settings.FolderName(), game.FolderName()); } @@ -73,7 +73,7 @@ namespace loot { settings.SetGamePath(localPath); Game game = Game(settings); - EXPECT_EQ(GetParam(), game.Id()); + EXPECT_EQ(GetParam(), game.Type()); EXPECT_EQ(settings.Name(), game.Name()); EXPECT_EQ(settings.FolderName(), game.FolderName()); EXPECT_EQ(settings.Master(), game.Master()); @@ -88,7 +88,7 @@ namespace loot { GameSettings settings = GameSettings(GetParam(), "folder"); Game game = Game(GetParam(), "folder"); - EXPECT_EQ(settings.Id(), game.Id()); + EXPECT_EQ(settings.Type(), game.Type()); EXPECT_EQ(settings.FolderName(), game.FolderName()); } @@ -154,7 +154,7 @@ namespace loot { Game game(GetParam()); game.SetGamePath(dataPath.parent_path()); - if (GetParam() == Game::tes5) + if (GetParam() == GameType::tes5) EXPECT_THROW(game.RedatePlugins(), Error); else EXPECT_NO_THROW(game.RedatePlugins()); @@ -180,7 +180,7 @@ namespace loot { EXPECT_NO_THROW(game.RedatePlugins()); time_t interval = 60; - if (GetParam() != Game::tes5) + if (GetParam() != GameType::tes5) interval *= -1; for (size_t i = 0; i < loadOrder.size(); ++i) { EXPECT_EQ(time + i * interval, boost::filesystem::last_write_time(dataPath / loadOrder[i].first)); diff --git a/src/tests/backend/game/load_order_handler_test.h b/src/tests/backend/game/load_order_handler_test.h index a5edd79d..b9b825b9 100644 --- a/src/tests/backend/game/load_order_handler_test.h +++ b/src/tests/backend/game/load_order_handler_test.h @@ -28,7 +28,7 @@ along with LOOT. If not, see #include "backend/error.h" #include "backend/game/load_order_handler.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -42,14 +42,14 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, LoadOrderHandlerTest, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(LoadOrderHandlerTest, initShouldThrowForAnInvalidGameId) { - GameSettings game(GameSettings::autodetect); + GameSettings game(GameType::autodetect); game.SetGamePath(dataPath.parent_path()); EXPECT_THROW(loh.Init(game), Error); @@ -147,7 +147,7 @@ namespace loot { }); EXPECT_NO_THROW(loh.SetLoadOrder(loadOrder)); - if (GetParam() == GameSettings::fo4) + if (GetParam() == GameType::fo4) loadOrder.erase(begin(loadOrder)); EXPECT_EQ(loadOrder, getLoadOrder()); diff --git a/src/tests/backend/helpers/helpers_test.h b/src/tests/backend/helpers/helpers_test.h index dffb7da9..4b4814ce 100644 --- a/src/tests/backend/helpers/helpers_test.h +++ b/src/tests/backend/helpers/helpers_test.h @@ -28,7 +28,7 @@ along with LOOT. If not, see #include "backend/helpers/helpers.h" #include "backend/error.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -41,7 +41,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, GetCrc32Test, ::testing::Values( - GameSettings::tes5)); + GameType::tes5)); TEST_P(GetCrc32Test, gettingTheCrcOfAMissingFileShouldThrow) { EXPECT_THROW(GetCrc32(dataPath / missingEsp), Error); diff --git a/src/tests/backend/masterlist_test.h b/src/tests/backend/masterlist_test.h index 54519c0c..00c7bfb4 100644 --- a/src/tests/backend/masterlist_test.h +++ b/src/tests/backend/masterlist_test.h @@ -27,7 +27,7 @@ along with LOOT. If not, see #include "backend/masterlist.h" #include "backend/app/loot_paths.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -68,11 +68,11 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, MasterlistTest, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(MasterlistTest, updateWithGameParameterShouldReturnTrueIfNoMasterlistExists) { Game game(GetParam()); diff --git a/src/tests/backend/metadata/condition_grammar_test.h b/src/tests/backend/metadata/condition_grammar_test.h index b53194e2..75654af0 100644 --- a/src/tests/backend/metadata/condition_grammar_test.h +++ b/src/tests/backend/metadata/condition_grammar_test.h @@ -27,7 +27,7 @@ along with LOOT. If not, see #include "backend/error.h" #include "backend/metadata/condition_grammar.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -70,11 +70,11 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, ConditionGrammarTest, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(ConditionGrammarTest, parsingInvalidSyntaxShouldThrow) { Grammar grammar(nullptr); diff --git a/src/tests/backend/metadata/conditional_metadata_test.h b/src/tests/backend/metadata/conditional_metadata_test.h index a960e217..f24297a0 100644 --- a/src/tests/backend/metadata/conditional_metadata_test.h +++ b/src/tests/backend/metadata/conditional_metadata_test.h @@ -27,7 +27,7 @@ along with LOOT. If not, see #include "backend/error.h" #include "backend/metadata/conditional_metadata.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -41,11 +41,11 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, ConditionalMetadataTest, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(ConditionalMetadataTest, defaultConstructorShouldSetEmptyConditionString) { EXPECT_TRUE(conditionalMetadata.Condition().empty()); diff --git a/src/tests/backend/metadata/message_test.h b/src/tests/backend/metadata/message_test.h index db7fb3be..0f6bd7f6 100644 --- a/src/tests/backend/metadata/message_test.h +++ b/src/tests/backend/metadata/message_test.h @@ -27,7 +27,7 @@ along with LOOT. If not, see #include "backend/game/game.h" #include "backend/metadata/message.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -42,7 +42,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, MessageTest, ::testing::Values( - GameSettings::tes4)); + GameType::tes4)); TEST_P(MessageTest, defaultConstructorShouldCreateNoteWithNoContent) { Message message; diff --git a/src/tests/backend/metadata/plugin_dirty_info_test.h b/src/tests/backend/metadata/plugin_dirty_info_test.h index bd6910fa..d2150e1e 100644 --- a/src/tests/backend/metadata/plugin_dirty_info_test.h +++ b/src/tests/backend/metadata/plugin_dirty_info_test.h @@ -26,7 +26,7 @@ along with LOOT. If not, see #define LOOT_TEST_BACKEND_METADATA_PLUGIN_DIRTY_INFO #include "backend/metadata/plugin_dirty_info.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -37,7 +37,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, PluginDirtyInfoTest, ::testing::Values( - GameSettings::tes4)); + GameType::tes4)); TEST_P(PluginDirtyInfoTest, defaultConstructorShouldLeaveAllCountsAtZeroAndTheUtilityStringEmpty) { PluginDirtyInfo info; diff --git a/src/tests/backend/metadata/plugin_metadata_test.h b/src/tests/backend/metadata/plugin_metadata_test.h index 72d1166b..eac2f038 100644 --- a/src/tests/backend/metadata/plugin_metadata_test.h +++ b/src/tests/backend/metadata/plugin_metadata_test.h @@ -26,7 +26,7 @@ along with LOOT. If not, see #define LOOT_TEST_F_BACKEND_METADATA_PLUGIN_METADATA #include "backend/metadata/plugin_metadata.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -37,7 +37,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, PluginMetadataTest, ::testing::Values( - GameSettings::tes5)); + GameType::tes5)); TEST_P(PluginMetadataTest, defaultConstructorShouldLeaveNameEmptyAndEnableMetadataAndLeaveAllOtherFieldsAtTheirDefaults) { PluginMetadata plugin; diff --git a/src/tests/backend/metadata_list_test.h b/src/tests/backend/metadata_list_test.h index 4611df8a..db61cf94 100644 --- a/src/tests/backend/metadata_list_test.h +++ b/src/tests/backend/metadata_list_test.h @@ -28,7 +28,7 @@ along with LOOT. If not, see #include "backend/metadata_list.h" #include "backend/game/game.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -79,7 +79,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, MetadataListTest, ::testing::Values( - GameSettings::tes4)); + GameType::tes4)); TEST_P(MetadataListTest, loadShouldLoadGlobalMessages) { MetadataList metadataList; diff --git a/src/tests/backend/plugin/plugin_sorter_test.h b/src/tests/backend/plugin/plugin_sorter_test.h index 40946b01..bff2ea76 100644 --- a/src/tests/backend/plugin/plugin_sorter_test.h +++ b/src/tests/backend/plugin/plugin_sorter_test.h @@ -26,7 +26,7 @@ along with LOOT. If not, see #define LOOT_TEST_BACKEND_PLUGIN_SORTER #include "backend/plugin/plugin_sorter.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -48,7 +48,7 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, PluginSorterTest, ::testing::Values( - GameSettings::tes4)); + GameType::tes4)); TEST_P(PluginSorterTest, sortingWithNoLoadedPluginsShouldReturnAnEmptyList) { PluginSorter sorter; diff --git a/src/tests/backend/plugin/plugin_test.h b/src/tests/backend/plugin/plugin_test.h index 96a61d65..79f27674 100644 --- a/src/tests/backend/plugin/plugin_test.h +++ b/src/tests/backend/plugin/plugin_test.h @@ -26,7 +26,7 @@ along with LOOT. If not, see #define LOOT_TEST_BACKEND_PLUGIN #include "backend/plugin/plugin.h" -#include "tests/base_game_test.h" +#include "tests/backend/base_game_test.h" namespace loot { namespace test { @@ -85,11 +85,11 @@ namespace loot { INSTANTIATE_TEST_CASE_P(, PluginTest, ::testing::Values( - GameSettings::tes4, - GameSettings::tes5, - GameSettings::fo3, - GameSettings::fonv, - GameSettings::fo4)); + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4)); TEST_P(PluginTest, loadingHeaderOnlyShouldReadHeaderData) { Plugin plugin(game, blankEsm, true); @@ -147,7 +147,7 @@ namespace loot { TEST_P(PluginTest, loadsArchiveForAnArchiveThatExactlyMatchesAnEsmFileBasenameShouldReturnTrueForAllGamesExceptOblivion) { bool loadsArchive = Plugin(game, blankEsm, true).LoadsArchive(); - if (GetParam() == Game::tes4) + if (GetParam() == GameType::tes4) EXPECT_FALSE(loadsArchive); else EXPECT_TRUE(loadsArchive); @@ -160,7 +160,7 @@ namespace loot { TEST_P(PluginTest, loadsArchiveForAnArchiveWithAFilenameWhichStartsWithTheEsmFileBasenameShouldReturnTrueForAllGamesExceptOblivionAndSkyrim) { bool loadsArchive = Plugin(game, blankDifferentEsm, true).LoadsArchive(); - if (GetParam() == Game::tes4 || GetParam() == Game::tes5) + if (GetParam() == GameType::tes4 || GetParam() == GameType::tes5) EXPECT_FALSE(loadsArchive); else EXPECT_TRUE(loadsArchive); @@ -169,7 +169,7 @@ namespace loot { TEST_P(PluginTest, loadsArchiveForAnArchiveWithAFilenameWhichStartsWithTheEspFileBasenameShouldReturnTrueForAllGamesExceptSkyrim) { bool loadsArchive = Plugin(game, blankDifferentEsp, true).LoadsArchive(); - if (GetParam() == Game::tes5) + if (GetParam() == GameType::tes5) EXPECT_FALSE(loadsArchive); else EXPECT_TRUE(loadsArchive); diff --git a/src/tests/base_game_test.h b/src/tests/common_game_test_fixture.h similarity index 89% rename from src/tests/base_game_test.h rename to src/tests/common_game_test_fixture.h index 131970d4..b210e085 100644 --- a/src/tests/base_game_test.h +++ b/src/tests/common_game_test_fixture.h @@ -22,8 +22,8 @@ along with LOOT. If not, see . */ -#ifndef LOOT_TEST_BASE_GAME_TEST -#define LOOT_TEST_BASE_GAME_TEST +#ifndef LOOT_TESTS_COMMON_GAME_TEST_FIXTURE +#define LOOT_TESTS_COMMON_GAME_TEST_FIXTURE #include #include @@ -35,9 +35,10 @@ along with LOOT. If not, see namespace loot { namespace test { - class BaseGameTest : public ::testing::TestWithParam { + class CommonGameTestFixture { protected: - BaseGameTest() : + CommonGameTestFixture(unsigned int gameType) : + gameType_(gameType), missingPath("./missing"), dataPath(getPluginsPath()), localPath(getLocalPath()), @@ -55,7 +56,7 @@ namespace loot { blankDifferentPluginDependentEsp("Blank - Different Plugin Dependent.esp"), blankEsmCrc(getBlankEsmCrc()) {} - inline virtual void SetUp() { + void setUp() { ASSERT_NO_THROW(boost::filesystem::create_directories(localPath)); ASSERT_TRUE(boost::filesystem::exists(localPath)); @@ -87,7 +88,7 @@ namespace loot { ASSERT_TRUE(boost::filesystem::exists(dataPath / (blankMasterDependentEsm + ".ghost"))); } - inline virtual void TearDown() { + void tearDown() { ASSERT_NO_THROW(boost::filesystem::remove_all(localPath)); ASSERT_NO_THROW(boost::filesystem::remove(dataPath / masterFile)); @@ -98,9 +99,9 @@ namespace loot { ASSERT_FALSE(boost::filesystem::exists(dataPath / (blankMasterDependentEsm + ".ghost"))); } - inline std::list getLoadOrder() { + std::list getLoadOrder() { std::list actual; - if (isLoadOrderTimestampBased(GetParam())) { + if (isLoadOrderTimestampBased(gameType_)) { std::map loadOrder; for (boost::filesystem::directory_iterator it(dataPath); it != boost::filesystem::directory_iterator(); ++it) { if (boost::filesystem::is_regular_file(it->status())) { @@ -114,7 +115,7 @@ namespace loot { for (const auto& plugin : loadOrder) actual.push_back(plugin.second); } - else if (GetParam() == tes5) { + else if (gameType_ == tes5) { boost::filesystem::ifstream in(localPath / "loadorder.txt"); while (in) { std::string line; @@ -158,6 +159,11 @@ namespace loot { }); } + private: + // This needs to be here to ensure the correct initialisation order. + const unsigned int gameType_; + + protected: const boost::filesystem::path missingPath; const boost::filesystem::path dataPath; const boost::filesystem::path localPath; @@ -185,51 +191,51 @@ namespace loot { static const unsigned int fo4 = 5; inline boost::filesystem::path getLocalPath() const { - if (GetParam() == tes4) + if (gameType_ == tes4) return "./local/Oblivion"; else return "./local/Skyrim"; } inline boost::filesystem::path getPluginsPath() const { - if (GetParam() == tes4) + if (gameType_ == tes4) return "./Oblivion/Data"; else return "./Skyrim/Data"; } inline std::string getMasterFile() const { - if (GetParam() == tes4) + if (gameType_ == tes4) return "Oblivion.esm"; - else if (GetParam() == tes5) + else if (gameType_ == tes5) return "Skyrim.esm"; - else if (GetParam() == fo3) + else if (gameType_ == fo3) return "Fallout3.esm"; - else if (GetParam() == fonv) + else if (gameType_ == fonv) return "FalloutNV.esm"; else return "Fallout4.esm"; } inline uint32_t getBlankEsmCrc() const { - if (GetParam() == tes4) + if (gameType_ == tes4) return 0x374E2A6F; else return 0x187BE342; } - inline void setLoadOrder(const std::vector>& loadOrder) const { + void setLoadOrder(const std::vector>& loadOrder) const { boost::filesystem::ofstream out(localPath / "plugins.txt"); for (const auto &plugin : loadOrder) { - if (GetParam() == fo4 && plugin.second) + if (gameType_ == fo4 && plugin.second) out << '*'; - else if (GetParam() != fo4 && !plugin.second) + else if (gameType_ != fo4 && !plugin.second) continue; out << plugin.first << std::endl; } - if (isLoadOrderTimestampBased(GetParam())) { + if (isLoadOrderTimestampBased(gameType_)) { time_t modificationTime = time(NULL); // Current time. for (const auto &plugin : loadOrder) { if (boost::filesystem::exists(dataPath / boost::filesystem::path(plugin.first + ".ghost"))) { @@ -241,7 +247,7 @@ namespace loot { modificationTime += 60; } } - else if (GetParam() == tes5) { + else if (gameType_ == tes5) { boost::filesystem::ofstream out(localPath / "loadorder.txt"); for (const auto &plugin : loadOrder) out << plugin.first << std::endl;