Remove LootPaths references from Game

Pass the paths when constructing a Game instead.
This commit is contained in:
Oliver Hamlet
2017-02-06 18:01:55 +00:00
parent 7abe1b15f1
commit 355eb3fd2f
18 changed files with 161 additions and 201 deletions
+2 -2
View File
@@ -33,9 +33,9 @@
namespace loot {
ApiDatabase::ApiDatabase(const GameType game, const std::string& gamePath, const std::string& gameLocalDataPath)
: game_(Game(GameType(game))) {
: game_(Game(GameSettings(GameType(game)), "", gameLocalDataPath)) {
game_.SetGamePath(gamePath);
game_.Init(false, gameLocalDataPath);
game_.Init();
}
///////////////////////////////////
+17 -14
View File
@@ -32,7 +32,6 @@
#include <boost/locale.hpp>
#include <boost/log/trivial.hpp>
#include "backend/app/loot_paths.h"
#include "loot/exception/file_access_error.h"
#include "loot/exception/game_detection_error.h"
#include "backend/helpers/helpers.h"
@@ -58,7 +57,13 @@ using std::vector;
namespace fs = boost::filesystem;
namespace loot {
Game::Game(const GameSettings& gameSettings) : GameSettings(gameSettings), pluginsFullyLoaded_(false) {
Game::Game(const GameSettings& gameSettings,
const boost::filesystem::path& lootDataPath,
const boost::filesystem::path& localDataPath) :
GameSettings(gameSettings),
lootDataPath_(lootDataPath),
localDataPath_(localDataPath),
pluginsFullyLoaded_(false) {
this->SetName(gameSettings.Name())
.SetMaster(gameSettings.Master())
.SetRepoURL(gameSettings.RepoURL())
@@ -67,8 +72,6 @@ Game::Game(const GameSettings& gameSettings) : GameSettings(gameSettings), plugi
.SetRegistryKey(gameSettings.RegistryKey());
}
Game::Game(const GameType gameType, const std::string& folder) : GameSettings(gameType, folder), pluginsFullyLoaded_(false) {}
bool Game::IsInstalled() {
try {
BOOST_LOG_TRIVIAL(trace) << "Checking if game \"" << Name() << "\" is installed.";
@@ -97,24 +100,24 @@ bool Game::IsInstalled() {
return false;
}
void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppData) {
void Game::Init() {
BOOST_LOG_TRIVIAL(info) << "Initialising filesystem-related data for game: " << Name();
if (!this->IsInstalled()) {
throw GameDetectionError("Game path could not be detected.");
}
if (createFolder) {
if (!lootDataPath_.empty()) {
//Make sure that the LOOT game path exists.
try {
if (!fs::exists(LootPaths::getLootDataPath() / FolderName()))
fs::create_directories(LootPaths::getLootDataPath() / FolderName());
if (!fs::exists(lootDataPath_ / FolderName()))
fs::create_directories(lootDataPath_ / FolderName());
} catch (fs::filesystem_error& e) {
throw FileAccessError((boost::format("Could not create LOOT folder for game. Details: %1%") % e.what()).str());
}
}
LoadOrderHandler::Init(*this, gameLocalAppData);
LoadOrderHandler::Init(*this, localDataPath_);
}
void Game::RedatePlugins() {
@@ -278,23 +281,23 @@ std::vector<std::string> Game::GetLoadOrder() const {
}
void Game::SetLoadOrder(const std::vector<std::string>& loadOrder) const {
BackupLoadOrder(loadOrder_, LootPaths::getLootDataPath() / FolderName());
BackupLoadOrder(loadOrder_, lootDataPath_ / FolderName());
LoadOrderHandler::SetLoadOrder(loadOrder);
loadOrder_ = loadOrder;
}
fs::path Game::MasterlistPath() const {
if (FolderName().empty())
if (lootDataPath_.empty() || FolderName().empty())
return "";
else
return LootPaths::getLootDataPath() / FolderName() / "masterlist.yaml";
return lootDataPath_ / FolderName() / "masterlist.yaml";
}
fs::path Game::UserlistPath() const {
if (FolderName().empty())
if (lootDataPath_.empty() || FolderName().empty())
return "";
else
return LootPaths::getLootDataPath() / FolderName() / "userlist.yaml";
return lootDataPath_ / FolderName() / "userlist.yaml";
}
#ifdef _WIN32
+7 -3
View File
@@ -36,11 +36,12 @@
namespace loot {
class Game : public GameSettings, public LoadOrderHandler, public GameCache {
public:
Game(const GameSettings& gameSettings);
Game(const GameType gameType, const std::string& lootFolder = "");
Game(const GameSettings& gameSettings,
const boost::filesystem::path& lootDataPath,
const boost::filesystem::path& localDataPath = "");
bool IsInstalled(); //Sets gamePath if the current value is not valid and a valid path is found.
void Init(bool createFolder, const boost::filesystem::path& gameLocalAppData = "");
void Init();
void RedatePlugins(); //Change timestamps to match load order (Skyrim only).
@@ -64,6 +65,9 @@ private:
std::string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value);
#endif
const boost::filesystem::path lootDataPath_;
const boost::filesystem::path localDataPath_;
bool pluginsFullyLoaded_;
mutable std::vector<std::string> loadOrder_;
};
-1
View File
@@ -28,7 +28,6 @@
#include <boost/locale.hpp>
#include <boost/log/trivial.hpp>
#include "backend/app/loot_paths.h"
#include "backend/helpers/helpers.h"
namespace fs = boost::filesystem;
+1 -1
View File
@@ -38,7 +38,7 @@ namespace loot {
class GameSettings {
public:
GameSettings();
GameSettings(const GameType gameType, const std::string& lootFolder = "");
explicit GameSettings(const GameType gameType, const std::string& lootFolder = "");
bool IsRepoBranchOldDefault() const;
+20 -15
View File
@@ -69,22 +69,22 @@ void LootState::load(YAML::Node& settings) {
// Update existing games, add new games.
std::unordered_set<string> newGameFolders;
BOOST_LOG_TRIVIAL(trace) << "Updating existing games and adding new games.";
for (const auto &game : getGameSettings()) {
auto pos = find(games_.begin(), games_.end(), game);
for (const auto &gameSettings : getGameSettings()) {
auto pos = find(games_.begin(), games_.end(), gameSettings);
if (pos != games_.end()) {
pos->SetName(game.Name())
.SetMaster(game.Master())
.SetRepoURL(game.RepoURL())
.SetRepoBranch(game.RepoBranch())
.SetGamePath(game.GamePath())
.SetRegistryKey(game.RegistryKey());
pos->SetName(gameSettings.Name())
.SetMaster(gameSettings.Master())
.SetRepoURL(gameSettings.RepoURL())
.SetRepoBranch(gameSettings.RepoBranch())
.SetGamePath(gameSettings.GamePath())
.SetRegistryKey(gameSettings.RegistryKey());
} else {
BOOST_LOG_TRIVIAL(trace) << "Adding new game entry for: " << game.FolderName();
games_.push_back(game);
BOOST_LOG_TRIVIAL(trace) << "Adding new game entry for: " << gameSettings.FolderName();
games_.push_back(Game(gameSettings, LootPaths::getLootDataPath()));
}
newGameFolders.insert(game.FolderName());
newGameFolders.insert(gameSettings.FolderName());
}
// Remove deleted games. As the current game is stored using its index,
@@ -104,7 +104,7 @@ void LootState::load(YAML::Node& settings) {
if (currentGame_ != end(games_)) {
// Re-initialise the current game in case the game path setting was changed.
currentGame_->Init(true);
currentGame_->Init();
// Update game path in settings object.
storeGameSettings(toGameSettings(games_));
}
@@ -190,7 +190,7 @@ void LootState::init(const std::string& cmdLineGame) {
selectGame(cmdLineGame);
BOOST_LOG_TRIVIAL(debug) << "Game selected is " << currentGame_->Name();
BOOST_LOG_TRIVIAL(debug) << "Initialising game-specific settings.";
currentGame_->Init(true);
currentGame_->Init();
// Update game path in settings object.
storeGameSettings(toGameSettings(games_));
} catch (std::exception& e) {
@@ -216,7 +216,7 @@ void LootState::changeGame(const std::string& newGameFolder) {
currentGame_ = find_if(games_.begin(), games_.end(), [&](const Game& game) {
return boost::iequals(newGameFolder, game.FolderName());
});
currentGame_->Init(true);
currentGame_->Init();
// Update game path in settings object.
storeGameSettings(toGameSettings(games_));
@@ -286,7 +286,12 @@ void LootState::enableDebugLogging(bool enable) {
}
std::list<Game> LootState::toGames(const std::vector<GameSettings>& settings) {
return std::list<Game>(settings.begin(), settings.end());
std::list<Game> games;
for (const auto& element : settings) {
games.push_back(Game(element, LootPaths::getLootDataPath()));
}
return games;
}
std::vector<GameSettings> LootState::toGameSettings(const std::list<Game>& games) {
+1 -19
View File
@@ -37,11 +37,7 @@ protected:
GameCacheTest() :
condition("Condition"),
conditionLowercase("condition"),
game_(GetParam()) {}
void initialiseGame() {
game_.SetGamePath(dataPath.parent_path());
}
game_(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), lootDataPath, localPath) {}
Game game_;
GameCache cache_;
@@ -60,8 +56,6 @@ INSTANTIATE_TEST_CASE_P(,
GameType::tes5));
TEST_P(GameCacheTest, copyConstructorShouldCopyCachedData) {
initialiseGame();
cache_.CacheCondition(condition, true);
cache_.AddPlugin(Plugin(game_, blankEsm, true));
Message expectedMessage(MessageType::say, "1");
@@ -76,8 +70,6 @@ TEST_P(GameCacheTest, copyConstructorShouldCopyCachedData) {
}
TEST_P(GameCacheTest, assignmentOperatorShouldCopyCachedData) {
initialiseGame();
cache_.CacheCondition(condition, true);
cache_.AddPlugin(Plugin(game_, blankEsm, true));
Message expectedMessage(MessageType::say, "1");
@@ -108,15 +100,11 @@ TEST_P(GameCacheTest, gettingANonCachedConditionShouldReturnAFalseFalsePair) {
}
TEST_P(GameCacheTest, addingAPluginThatDoesNotExistShouldSucceed) {
initialiseGame();
cache_.AddPlugin(Plugin(game_, blankEsm, true));
EXPECT_EQ(blankEsm, cache_.GetPlugin(blankEsm).Name());
}
TEST_P(GameCacheTest, addingAPluginThatIsAlreadyCachedShouldOverwriteExistingEntry) {
initialiseGame();
cache_.AddPlugin(Plugin(game_, blankEsm, true));
EXPECT_EQ(0, cache_.GetPlugin(blankEsm).Crc());
@@ -129,8 +117,6 @@ TEST_P(GameCacheTest, gettingAPluginThatIsNotCachedShouldThrow) {
}
TEST_P(GameCacheTest, gettingAPluginShouldBeCaseInsensitive) {
initialiseGame();
cache_.AddPlugin(Plugin(game_, blankEsm, true));
EXPECT_EQ(blankEsm, cache_.GetPlugin(blankEsm).Name());
}
@@ -140,8 +126,6 @@ TEST_P(GameCacheTest, gettingPluginsShouldReturnAnEmptySetIfNoPluginsHaveBeenCac
}
TEST_P(GameCacheTest, gettingPluginsShouldReturnASetOfCachedPluginsIfPluginsHaveBeenCached) {
initialiseGame();
cache_.AddPlugin(Plugin(game_, blankEsm, true));
cache_.AddPlugin(Plugin(game_, blankMasterDependentEsm, true));
@@ -168,8 +152,6 @@ TEST_P(GameCacheTest, clearingCachedPluginsShouldNotThrowIfNoPluginsAreCached) {
}
TEST_P(GameCacheTest, clearingCachedPluginsShouldClearAnyCachedPlugins) {
initialiseGame();
cache_.AddPlugin(Plugin(game_, blankEsm, true));
cache_.ClearCachedPlugins();
@@ -27,7 +27,6 @@ along with LOOT. If not, see
#include "backend/game/game_settings.h"
#include "backend/app/loot_paths.h"
#include "tests/common_game_test_fixture.h"
namespace loot {
+81 -98
View File
@@ -27,22 +27,12 @@ along with LOOT. If not, see
#include "backend/game/game.h"
#include "backend/app/loot_paths.h"
#include "loot/exception/game_detection_error.h"
#include "tests/backend/game/load_order_handler_test.h"
namespace loot {
namespace test {
class GameTest : public CommonGameTestFixture {
protected:
#ifndef _WIN32
void TearDown() {
CommonGameTestFixture::TearDown();
ASSERT_NO_THROW(boost::filesystem::remove_all(LootPaths::getLootDataPath()));
}
#endif
};
class GameTest : public CommonGameTestFixture {};
// Pass an empty first argument, as it's a prefix for the test instantation,
// but we only have the one so no prefix is necessary.
@@ -64,7 +54,7 @@ TEST_P(GameTest, constructingFromGameSettingsShouldUseTheirValues) {
settings.SetRepoURL("foo");
settings.SetRepoBranch("foo");
settings.SetGamePath(localPath);
Game game = Game(settings);
Game game = Game(settings, lootDataPath, localPath);
EXPECT_EQ(GetParam(), game.Type());
EXPECT_EQ(settings.Name(), game.Name());
@@ -75,28 +65,27 @@ TEST_P(GameTest, constructingFromGameSettingsShouldUseTheirValues) {
EXPECT_EQ(settings.RepoBranch(), game.RepoBranch());
EXPECT_EQ(settings.GamePath(), game.GamePath());
EXPECT_EQ(LootPaths::getLootDataPath() / "folder" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(LootPaths::getLootDataPath() / "folder" / "userlist.yaml", game.UserlistPath());
EXPECT_EQ(lootDataPath / "folder" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(lootDataPath / "folder" / "userlist.yaml", game.UserlistPath());
}
TEST_P(GameTest, constructingFromIdAndFolderShouldPassThemToGameSettingsConstructor) {
GameSettings settings = GameSettings(GetParam(), "folder");
Game game = Game(GetParam(), "folder");
Game game = Game(settings, lootDataPath, localPath);
EXPECT_EQ(settings.Type(), game.Type());
EXPECT_EQ(settings.FolderName(), game.FolderName());
EXPECT_EQ(LootPaths::getLootDataPath() / "folder" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(LootPaths::getLootDataPath() / "folder" / "userlist.yaml", game.UserlistPath());
EXPECT_EQ(lootDataPath / "folder" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(lootDataPath / "folder" / "userlist.yaml", game.UserlistPath());
}
TEST_P(GameTest, isInstalledShouldBeFalseIfGamePathIsNotSet) {
Game game = Game(GetParam());
Game game = Game(GameSettings(GetParam()), "", localPath);
EXPECT_FALSE(game.IsInstalled());
}
TEST_P(GameTest, isInstalledShouldBeTrueIfGamePathIsValid) {
Game game = Game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_TRUE(game.IsInstalled());
}
@@ -104,55 +93,58 @@ TEST_P(GameTest, isInstalledShouldBeTrueIfGamePathIsValid) {
// Testing on Windows will find real game installs in the Registry, so cannot
// test autodetection fully unless on Linux.
TEST_P(GameTest, initShouldThrowOnLinuxIfGamePathIsNotGiven) {
Game game = Game(GetParam());
EXPECT_THROW(game.Init(false), GameDetectionError);
EXPECT_THROW(game.Init(true), GameDetectionError);
EXPECT_THROW(game.Init(false, localPath), GameDetectionError);
EXPECT_THROW(game.Init(true, localPath), GameDetectionError);
Game game = Game(GameSettings(GetParam()), "");
EXPECT_THROW(game.Init(), GameDetectionError);
game = Game(GameSettings(GetParam()), lootDataPath);
EXPECT_THROW(game.Init(), GameDetectionError);
game = Game(GameSettings(GetParam()), "", localPath);
EXPECT_THROW(game.Init(), GameDetectionError);
game = Game(GameSettings(GetParam()), lootDataPath, localPath);
EXPECT_THROW(game.Init(), GameDetectionError);
}
TEST_P(GameTest, initShouldThrowOnLinuxIfLocalPathIsNotGiven) {
Game game = Game(GetParam()).SetGamePath(dataPath.parent_path());
ASSERT_FALSE(boost::filesystem::exists(LootPaths::getLootDataPath() / game.FolderName()));
EXPECT_THROW(game.Init(false), std::system_error);
}
// Testing on Windows will find real LOOT installs, and they shouldn't be
// interfered with.
TEST_P(GameTest, initShouldNotCreateAGameFolderIfTheCreateFolderArgumentIsFalse) {
Game game = Game(GetParam()).SetGamePath(dataPath.parent_path());
ASSERT_FALSE(boost::filesystem::exists(LootPaths::getLootDataPath() / game.FolderName()));
EXPECT_NO_THROW(game.Init(false, localPath));
EXPECT_FALSE(boost::filesystem::exists(LootPaths::getLootDataPath() / game.FolderName()));
}
TEST_P(GameTest, initShouldCreateAGameFolderIfTheCreateFolderArgumentIsTrue) {
Game game = Game(GetParam()).SetGamePath(dataPath.parent_path());
ASSERT_FALSE(boost::filesystem::exists(LootPaths::getLootDataPath() / game.FolderName()));
EXPECT_NO_THROW(game.Init(true, localPath));
EXPECT_TRUE(boost::filesystem::exists(LootPaths::getLootDataPath() / game.FolderName()));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), lootDataPath);
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName()));
EXPECT_THROW(game.Init(), std::system_error);
}
#else
TEST_P(GameTest, initShouldNotThrowOnWindowsIfLocalPathIsNotGiven) {
Game game = Game(GetParam()).SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "");
EXPECT_NO_THROW(game.Init(false));
EXPECT_NO_THROW(game.Init());
}
#endif
TEST_P(GameTest, initShouldNotThrowIfGameAndLocalPathsAreGiven) {
Game game = Game(GetParam()).SetGamePath(dataPath.parent_path());
TEST_P(GameTest, initShouldNotCreateAGameFolderIfTheLootDataPathIsEmpty) {
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "");
EXPECT_NO_THROW(game.Init(false, localPath));
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName()));
EXPECT_NO_THROW(game.Init());
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName()));
}
TEST_P(GameTest, initShouldCreateAGameFolderIfTheCreateFolderArgumentIsTrue) {
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), lootDataPath, localPath);
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName()));
EXPECT_NO_THROW(game.Init());
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName()));
}
TEST_P(GameTest, initShouldNotThrowIfGameAndLocalPathsAreNotEmpty) {
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_NO_THROW(game.Init());
}
TEST_P(GameTest, redatePluginsShouldThrowIfTheGameHasNotYetBeenInitialisedForSkyrimAndNotForOtherGames) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
if (GetParam() == GameType::tes5 || GetParam() == GameType::tes5se)
EXPECT_THROW(game.RedatePlugins(), std::system_error);
@@ -161,9 +153,8 @@ TEST_P(GameTest, redatePluginsShouldThrowIfTheGameHasNotYetBeenInitialisedForSky
}
TEST_P(GameTest, redatePluginsShouldRedatePluginsForSkyrimAndSkyrimSEAndDoNothingForOtherGames) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
game.Init(false, localPath);
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
std::vector<std::pair<std::string, bool>> loadOrder = getInitialLoadOrder();
@@ -189,8 +180,7 @@ TEST_P(GameTest, redatePluginsShouldRedatePluginsForSkyrimAndSkyrimSEAndDoNothin
}
TEST_P(GameTest, loadAllInstalledPluginsWithHeadersOnlyTrueShouldLoadTheHeadersOfAllInstalledPlugins) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_NO_THROW(game.LoadAllInstalledPlugins(true));
EXPECT_EQ(11, game.GetPlugins().size());
@@ -205,8 +195,7 @@ TEST_P(GameTest, loadAllInstalledPluginsWithHeadersOnlyTrueShouldLoadTheHeadersO
}
TEST_P(GameTest, loadAllInstalledPluginsWithHeadersOnlyFalseShouldFullyLoadAllInstalledPlugins) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_NO_THROW(game.LoadAllInstalledPlugins(false));
EXPECT_EQ(11, game.GetPlugins().size());
@@ -221,13 +210,13 @@ TEST_P(GameTest, loadAllInstalledPluginsWithHeadersOnlyFalseShouldFullyLoadAllIn
}
TEST_P(GameTest, pluginsShouldNotBeFullyLoadedByDefault) {
EXPECT_FALSE(Game(GameSettings()).ArePluginsFullyLoaded());
EXPECT_FALSE(Game(GetParam(), "folder").ArePluginsFullyLoaded());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_FALSE(game.ArePluginsFullyLoaded());
}
TEST_P(GameTest, pluginsShouldNotBeFullyLoadedAfterLoadingHeadersOnly) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(true));
@@ -235,8 +224,7 @@ TEST_P(GameTest, pluginsShouldNotBeFullyLoadedAfterLoadingHeadersOnly) {
}
TEST_P(GameTest, pluginsShouldBeFullyLoadedAfterFullyLoadingThem) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(false));
@@ -244,84 +232,80 @@ TEST_P(GameTest, pluginsShouldBeFullyLoadedAfterFullyLoadingThem) {
}
TEST_P(GameTest, shouldThrowIfCheckingIfPluginThatIsntLoadedIsActiveAndGameHasNotBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_THROW(game.IsPluginActive(blankEsm), std::system_error);
}
TEST_P(GameTest, shouldShowBlankEsmAsActiveIfItHasNotBeenLoadedAndTheGameHasBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
EXPECT_TRUE(game.IsPluginActive(blankEsm));
}
TEST_P(GameTest, shouldShowBlankEspAsInactiveIfItHasNotBeenLoadedAndTheGameHasBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
EXPECT_FALSE(game.IsPluginActive(blankEsp));
}
TEST_P(GameTest, shouldShowBlankEsmAsInactiveIfItsHeaderHasBeenLoadedAndGameHasNotBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(true));
EXPECT_FALSE(game.IsPluginActive(blankEsm));
}
TEST_P(GameTest, shouldShowBlankEspAsInactiveIfItsHeaderHasBeenLoadedAndGameHasNotBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(true));
EXPECT_FALSE(game.IsPluginActive(blankEsp));
}
TEST_P(GameTest, shouldShowBlankEsmAsActiveIfItsHeaderHasBeenLoadedAndTheGameHasBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(true));
EXPECT_TRUE(game.IsPluginActive(blankEsm));
}
TEST_P(GameTest, shouldShowBlankEspAsInactiveIfItsHeaderHasBeenLoadedAndTheGameHasBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(true));
EXPECT_FALSE(game.IsPluginActive(blankEsp));
}
TEST_P(GameTest, shouldShowBlankEsmAsActiveIfItHasBeenFullyLoadedAndTheGameHasBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(false));
EXPECT_TRUE(game.IsPluginActive(blankEsm));
}
TEST_P(GameTest, shouldShowBlankEspAsInactiveIfItHasBeenFullyLoadedAndTheGameHasBeenInitialised) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
ASSERT_NO_THROW(game.LoadAllInstalledPlugins(false));
EXPECT_FALSE(game.IsPluginActive(blankEsp));
}
TEST_P(GameTest, GetActiveLoadOrderIndexShouldReturnNegativeOneForAPluginThatIsNotActive) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
short index = game.GetActiveLoadOrderIndex(blankEsp);
@@ -329,9 +313,8 @@ TEST_P(GameTest, GetActiveLoadOrderIndexShouldReturnNegativeOneForAPluginThatIsN
}
TEST_P(GameTest, GetActiveLoadOrderIndexShouldReturnTheLoadOrderIndexOmittingInactivePlugins) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
short index = game.GetActiveLoadOrderIndex(masterFile);
EXPECT_EQ(0, index);
+4 -11
View File
@@ -27,7 +27,6 @@ along with LOOT. If not, see
#include "backend/masterlist.h"
#include "backend/app/loot_paths.h"
#include "tests/common_game_test_fixture.h"
namespace loot {
@@ -44,18 +43,12 @@ protected:
ASSERT_FALSE(boost::filesystem::exists(masterlistPath));
ASSERT_FALSE(boost::filesystem::exists(localPath / ".git"));
ASSERT_NO_THROW(boost::filesystem::create_directories(LootPaths::getLootDataPath() / Game(GetParam()).FolderName()));
}
void TearDown() {
CommonGameTestFixture::TearDown();
ASSERT_NO_THROW(boost::filesystem::remove(masterlistPath));
ASSERT_NO_THROW(boost::filesystem::remove_all(localPath / ".git"));
ASSERT_NO_THROW(boost::filesystem::remove(LootPaths::getLootDataPath() / Game(GetParam()).FolderName() / "masterlist.yaml"));
ASSERT_NO_THROW(boost::filesystem::remove_all(LootPaths::getLootDataPath() / Game(GetParam()).FolderName() / ".git"));
}
const std::string repoUrl;
@@ -77,11 +70,11 @@ INSTANTIATE_TEST_CASE_P(,
GameType::tes5se));
TEST_P(MasterlistTest, updateWithGameParameterShouldReturnTrueIfNoMasterlistExists) {
Game game(GetParam());
Game game(GameSettings(GetParam()), lootDataPath, localPath);
game.SetGamePath(dataPath.parent_path());
game.SetRepoURL(repoUrl);
game.SetRepoBranch(repoBranch);
ASSERT_NO_THROW(game.Init(false, localPath));
ASSERT_NO_THROW(game.Init());
// This may fail on Windows if a 'real' LOOT install is also present.
Masterlist masterlist;
@@ -90,11 +83,11 @@ TEST_P(MasterlistTest, updateWithGameParameterShouldReturnTrueIfNoMasterlistExis
}
TEST_P(MasterlistTest, updateWithGameParameterShouldReturnFalseIfAnUpToDateMasterlistExists) {
Game game(GetParam());
Game game(GameSettings(GetParam()), lootDataPath, localPath);
game.SetGamePath(dataPath.parent_path());
game.SetRepoURL(repoUrl);
game.SetRepoBranch(repoBranch);
ASSERT_NO_THROW(game.Init(false, localPath));
ASSERT_NO_THROW(game.Init());
// This may fail on Windows if a 'real' LOOT install is also present.
Masterlist masterlist;
@@ -37,7 +37,7 @@ protected:
ConditionGrammarTest() :
resourcePath(dataPath / "resource" / "detail" / "resource.txt"),
game_(Game(GetParam()).SetGamePath(dataPath.parent_path())),
game_(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath),
result_(false),
success_(false) {}
@@ -507,7 +507,7 @@ TEST_P(ConditionGrammarTest, aVersionLessThanOrEqualToConditionForAPluginWithNoV
}
TEST_P(ConditionGrammarTest, aVersionGreaterThanOrEqualToConditionWithAnActualPluginVersionEqualToTheGivenVersionShouldEvaluateToTrue) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
ASSERT_NO_THROW(game_.LoadAllInstalledPlugins(true));
Grammar grammar(&game_);
@@ -553,7 +553,7 @@ TEST_P(ConditionGrammarTest, aVersionGreaterThanOrEqualToConditionForAPluginWith
}
TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsActiveShouldEvaluateToTrue) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("active(\"" + blankEsm + "\")");
@@ -568,7 +568,7 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsActiveShouldEvalu
}
TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsNotActiveShouldEvaluateToFalse) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("active(\"" + blankEsp + "\")");
@@ -583,7 +583,7 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsNotActiveShouldEv
}
TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingAnActivePluginShouldEvaluateToTrue) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("active(\"Blank\\.esm\")");
@@ -598,7 +598,7 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingAnActivePluginSh
}
TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingNoActivePluginsShouldEvaluateToFalse) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("active(\"Blank\\.esp\")");
@@ -613,7 +613,7 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingNoActivePluginsS
}
TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingMoreThanOnePluginThatIsActiveShouldEvaluateToTrue) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("many_active(\"Blank( - Different Master Dependent)?\\.es(m|p)\")");
@@ -628,7 +628,7 @@ TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingMoreThanOnePl
}
TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingOnlyOnePluginThatIsActiveShouldEvaluateToFalse) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("many_active(\"Blank\\.esm\")");
@@ -643,7 +643,7 @@ TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingOnlyOnePlugin
}
TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingNoPluginsThatAreActiveShouldEvaluateToFalse) {
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
Grammar grammar(&game_);
std::string condition("many_active(\"Blank\\.esp\")");
@@ -69,31 +69,27 @@ TEST_P(ConditionalMetadataTest, isConditionalShouldBeTrueForANonEmptyConditionSt
}
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnTrueForAnEmptyCondition) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
EXPECT_TRUE(conditionalMetadata_.EvalCondition(game));
}
TEST_P(ConditionalMetadataTest, evalConditionShouldThrowForAnInvalidCondition) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
conditionalMetadata_ = ConditionalMetadata("condition");
EXPECT_THROW(conditionalMetadata_.EvalCondition(game), ConditionSyntaxError);
}
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnTrueForAConditionThatIsTrue) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
conditionalMetadata_ = ConditionalMetadata("file(\"" + blankEsm + "\")");
EXPECT_TRUE(conditionalMetadata_.EvalCondition(game));
}
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnFalseForAConditionThatIsFalse) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
conditionalMetadata_ = ConditionalMetadata("file(\"" + missingEsp + "\")");
EXPECT_FALSE(conditionalMetadata_.EvalCondition(game));
@@ -145,24 +145,21 @@ TEST_P(PluginCleaningDataTest, LessThanOperatorShouldCompareCrcValues) {
}
TEST_P(PluginCleaningDataTest, evalConditionShouldBeTrueIfTheCrcGivenMatchesTheRealPluginCrc) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
PluginCleaningData dirtyInfo(blankEsmCrc, "cleaner", info_, 2, 10, 30);
EXPECT_TRUE(dirtyInfo.EvalCondition(game, blankEsm));
}
TEST_P(PluginCleaningDataTest, evalConditionShouldBeFalseIfTheCrcGivenDoesNotMatchTheRealPluginCrc) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
PluginCleaningData dirtyInfo(0xDEADBEEF, "cleaner", info_, 2, 10, 30);
EXPECT_FALSE(dirtyInfo.EvalCondition(game, blankEsm));
}
TEST_P(PluginCleaningDataTest, evalConditionShouldBeFalseIfAnEmptyPluginFilenameIsGiven) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
PluginCleaningData dirtyInfo;
EXPECT_FALSE(dirtyInfo.EvalCondition(game, ""));
@@ -657,8 +657,7 @@ TEST_P(PluginMetadataTest, simpleMessagesShouldReturnMessagesAsSimpleMessages) {
}
TEST_P(PluginMetadataTest, evalAllConditionsShouldEvaluateAllMetadataConditions) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
PluginMetadata plugin(blankEsm);
+2 -3
View File
@@ -284,9 +284,8 @@ TEST_P(MetadataListTest, erasePluginShouldRemoveStoredMetadataForTheGivenPlugin)
}
TEST_P(MetadataListTest, evalAllConditionsShouldEvaluateTheConditionsForThePluginsStoredInTeMetadataList) {
Game game(GetParam());
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
Game game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
game.Init();
MetadataList metadataList;
ASSERT_NO_THROW(metadataList.Load(metadataPath));
@@ -34,13 +34,12 @@ namespace loot {
namespace test {
class PluginSorterTest : public CommonGameTestFixture {
protected:
PluginSorterTest() : game_(GetParam()) {}
PluginSorterTest() : game_(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath) {}
inline virtual void SetUp() {
CommonGameTestFixture::SetUp();
game_.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game_.Init(false, localPath));
ASSERT_NO_THROW(game_.Init());
}
Game game_;
+4 -5
View File
@@ -37,15 +37,14 @@ protected:
PluginTest() :
emptyFile("EmptyFile.esm"),
nonPluginFile("NotAPlugin.esm"),
blankArchive("Blank" + Game(GetParam()).GetArchiveFileExtension()),
blankSuffixArchive("Blank - Different - suffix" + Game(GetParam()).GetArchiveFileExtension()),
game_(GetParam()) {}
game_(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath),
blankArchive("Blank" + game_.GetArchiveFileExtension()),
blankSuffixArchive("Blank - Different - suffix" + game_.GetArchiveFileExtension()) {}
void SetUp() {
CommonGameTestFixture::SetUp();
game_.SetGamePath(dataPath.parent_path());
game_.Init(false, localPath);
game_.Init();
// Write out an empty file.
boost::filesystem::ofstream out(dataPath / emptyFile);
+3
View File
@@ -43,6 +43,7 @@ protected:
missingPath("./missing"),
dataPath(getPluginsPath()),
localPath(getLocalPath()),
lootDataPath("./local/LOOT"),
masterFile(getMasterFile()),
missingEsp("Blank.missing.esp"),
blankEsm("Blank.esm"),
@@ -91,6 +92,7 @@ protected:
void TearDown() {
ASSERT_NO_THROW(boost::filesystem::remove_all(localPath));
ASSERT_NO_THROW(boost::filesystem::remove_all(lootDataPath));
ASSERT_NO_THROW(boost::filesystem::remove(dataPath / masterFile));
@@ -171,6 +173,7 @@ protected:
const boost::filesystem::path missingPath;
const boost::filesystem::path dataPath;
const boost::filesystem::path localPath;
const boost::filesystem::path lootDataPath;
const std::string masterFile;
const std::string missingEsp;