Reimplement game IDs as game type enums

This required some changes to how the test fixtures are implemented.
This commit is contained in:
Oliver Hamlet
2016-07-13 20:49:51 +01:00
parent 8265ca916e
commit e1924a69ec
33 changed files with 343 additions and 242 deletions
+9 -10
View File
@@ -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})
+6 -5
View File
@@ -42,6 +42,7 @@
#include <boost/log/core.hpp>
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<unsigned int>(GameType::tes4);
const unsigned int loot_game_tes5 = static_cast<unsigned int>(GameType::tes5);
const unsigned int loot_game_fo3 = static_cast<unsigned int>(GameType::fo3);
const unsigned int loot_game_fonv = static_cast<unsigned int>(GameType::fonv);
const unsigned int loot_game_fo4 = static_cast<unsigned int>(GameType::fo4);
// LOOT message types.
const unsigned int loot_message_say = static_cast<unsigned int>(loot::Message::Type::say);
+1 -1
View File
@@ -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);
}
+17 -17
View File
@@ -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<vector<GameSettings>>();
// 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");
}
+1 -1
View File
@@ -212,7 +212,7 @@ namespace loot {
std::lock_guard<std::mutex> 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.
+3 -3
View File
@@ -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<string> loadorder = GetLoadOrder();
+2 -2
View File
@@ -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 = "");
+15 -22
View File
@@ -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()
+17 -22
View File
@@ -34,18 +34,20 @@
#include <libespm/GameId.h>
#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<std::string>() == loot::GameSettings(loot::GameSettings::tes4).FolderName())
rhs = loot::GameSettings(loot::GameSettings::tes4, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameSettings::tes5).FolderName())
rhs = loot::GameSettings(loot::GameSettings::tes5, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameSettings::fo3).FolderName())
rhs = loot::GameSettings(loot::GameSettings::fo3, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameSettings::fonv).FolderName())
rhs = loot::GameSettings(loot::GameSettings::fonv, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameSettings::fo4).FolderName())
rhs = loot::GameSettings(loot::GameSettings::fo4, node["folder"].as<std::string>());
if (node["type"].as<std::string>() == loot::GameSettings(loot::GameType::tes4).FolderName())
rhs = loot::GameSettings(loot::GameType::tes4, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameType::tes5).FolderName())
rhs = loot::GameSettings(loot::GameType::tes5, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameType::fo3).FolderName())
rhs = loot::GameSettings(loot::GameType::fo3, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameType::fonv).FolderName())
rhs = loot::GameSettings(loot::GameType::fonv, node["folder"].as<std::string>());
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameType::fo4).FolderName())
rhs = loot::GameSettings(loot::GameType::fo4, node["folder"].as<std::string>());
else
throw RepresentationException(node.Mark(), "bad conversion: invalid value for 'type' key in 'game settings' object");
+39
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+10 -10
View File
@@ -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;
+2 -2
View File
@@ -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) {
+6 -6
View File
@@ -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<Plugin> 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
+7 -4
View File
@@ -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<unsigned int>,
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));
+11 -4
View File
@@ -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 <climits>
namespace loot {
namespace test {
class loot_create_db_test : public BaseGameTest {
class loot_create_db_test :
public ::testing::TestWithParam<unsigned int>,
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));
}
+7 -7
View File
@@ -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<unsigned int>(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");
+28 -28
View File
@@ -47,12 +47,12 @@ namespace loot {
TEST_F(LootSettingsTest, defaultConstructorShouldSetDefaultValues) {
const std::string currentVersion = LootVersion::string();
const std::vector<GameSettings> 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<GameSettings> 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<GameSettings> games({
GameSettings(GameSettings::tes4).SetName("Game Name"),
GameSettings(GameType::tes4).SetName("Game Name"),
});
const std::map<std::string, bool> filters({
{"hideBashTags", false},
@@ -188,7 +188,7 @@ namespace loot {
const std::string Language = "fr";
const std::string LastGame = "Skyrim";
const std::vector<GameSettings> 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<GameSettings> Games({
GameSettings(GameSettings::tes4).SetName("Old Game Name"),
GameSettings(GameType::tes4).SetName("Old Game Name"),
});
const std::vector<GameSettings> 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<GameSettings> games({GameSettings(GameSettings::tes4)});
const std::vector<GameSettings> games({GameSettings(GameType::tes4)});
YAML::Node inputYaml;
inputYaml["games"] = games;
@@ -279,7 +279,7 @@ namespace loot {
}
TEST_F(LootSettingsTest, loadingFromYamlShouldNotUpgradeNonDefaultGameRepositoryBranches) {
const std::vector<GameSettings> games({GameSettings(GameSettings::tes4)});
const std::vector<GameSettings> games({GameSettings(GameType::tes4)});
YAML::Node inputYaml;
inputYaml["games"] = games;
@@ -291,28 +291,28 @@ namespace loot {
}
TEST_F(LootSettingsTest, loadingFromYamlShouldAddMissingBaseGames) {
const std::vector<GameSettings> games({GameSettings(GameSettings::tes4)});
const std::vector<GameSettings> games({GameSettings(GameType::tes4)});
YAML::Node inputYaml;
inputYaml["games"] = games;
settings.load(inputYaml);
const std::vector<GameSettings> 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(GameSettings::tes5)});
const std::vector<GameSettings> gameSettings({GameSettings(GameType::tes5)});
settings.storeGameSettings(gameSettings);
EXPECT_EQ(gameSettings, settings.getGameSettings());
@@ -434,7 +434,7 @@ namespace loot {
{"right", 4},
});
const std::vector<GameSettings> games({
GameSettings(GameSettings::tes4).SetName("Game Name"),
GameSettings(GameType::tes4).SetName("Game Name"),
});
const std::map<std::string, bool> filters({
{"hideBashTags", false},
+58
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#ifndef LOOT_TEST_BASE_GAME_TEST
#define LOOT_TEST_BASE_GAME_TEST
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>
#include <map>
#include <unordered_set>
#include "tests/common_game_test_fixture.h"
namespace loot {
namespace test {
class BaseGameTest :
public ::testing::TestWithParam<GameType>,
public CommonGameTestFixture {
protected:
BaseGameTest() :
CommonGameTestFixture(static_cast<unsigned int>(GetParam())) {}
inline virtual void SetUp() {
setUp();
}
inline virtual void TearDown() {
tearDown();
}
};
}
}
#endif
+2 -2
View File
@@ -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();
+18 -18
View File
@@ -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<GameSettings>();
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<GameSettings>();
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());

Some files were not shown because too many files have changed in this diff Show More