mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Update GUI tests to use the LOOT API
This commit is contained in:
+2
-3
@@ -478,8 +478,8 @@ target_link_libraries(LOOT ${CEF_LIBRARIES} loot_common ${LOOT_GUI_LIBS})
|
||||
|
||||
# Build application tests.
|
||||
add_executable (gui_tests ${LOOT_GUI_TESTS_SRC} ${LOOT_GUI_TESTS_HEADERS})
|
||||
add_dependencies (gui_tests loot_common GTest testing-metadata testing-plugins)
|
||||
target_link_libraries(gui_tests loot_common ${GTEST_LIBRARIES})
|
||||
add_dependencies (gui_tests loot_api GTest testing-metadata testing-plugins)
|
||||
target_link_libraries(gui_tests loot_api ${GTEST_LIBRARIES})
|
||||
|
||||
##############################
|
||||
# Set Target-Specific Flags
|
||||
@@ -499,7 +499,6 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
set_target_properties (loot_common PROPERTIES COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS} LOOT_STATIC")
|
||||
set_target_properties (tests PROPERTIES COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS} LOOT_STATIC")
|
||||
set_target_properties (LOOT PROPERTIES COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS} LOOT_STATIC")
|
||||
set_target_properties (gui_tests PROPERTIES COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS} LOOT_STATIC")
|
||||
IF (BUILD_SHARED_LIBS)
|
||||
set_target_properties (loot_api PROPERTIES COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS} LOOT_EXPORT")
|
||||
ELSE ()
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "gui/loot_app.h"
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <include/cef_browser.h>
|
||||
#include <include/cef_task.h>
|
||||
|
||||
+68
-45
@@ -62,43 +62,25 @@ namespace gui {
|
||||
Game::Game(const GameSettings& gameSettings,
|
||||
const boost::filesystem::path& lootDataPath,
|
||||
const boost::filesystem::path& localDataPath) :
|
||||
loot::Game(gameSettings.Type(), gameSettings.GamePath(), localDataPath),
|
||||
GameSettings(gameSettings),
|
||||
lootDataPath_(lootDataPath),
|
||||
pluginsFullyLoaded_(false) {}
|
||||
gameHandle_(CreateGameHandle(gameSettings.Type(), gameSettings.GamePath().string(), localDataPath.string())),
|
||||
pluginsFullyLoaded_(false) {
|
||||
gameHandle_->IdentifyMainMasterFile(gameSettings.Master());
|
||||
}
|
||||
|
||||
bool Game::IsInstalled() {
|
||||
try {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Checking if game \"" << Name() << "\" is installed.";
|
||||
if (!GamePath().empty() && fs::exists(GamePath() / "Data" / Master()))
|
||||
return true;
|
||||
bool Game::IsInstalled(const GameSettings& gameSettings) {
|
||||
auto gamePath = DetectGamePath(gameSettings);
|
||||
|
||||
if (fs::exists(fs::path("..") / "Data" / Master())) {
|
||||
SetGamePath("..");
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string path;
|
||||
std::string key_parent = fs::path(RegistryKey()).parent_path().string();
|
||||
std::string key_name = fs::path(RegistryKey()).filename().string();
|
||||
path = RegKeyStringValue("HKEY_LOCAL_MACHINE", key_parent, key_name);
|
||||
if (!path.empty() && fs::exists(fs::path(path) / "Data" / Master())) {
|
||||
SetGamePath(path);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
} catch (std::exception &e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Error while checking if game \"" << Name() << "\" is installed: " << e.what();
|
||||
}
|
||||
|
||||
return false;
|
||||
return !gamePath.empty();
|
||||
}
|
||||
|
||||
void Game::Init() {
|
||||
BOOST_LOG_TRIVIAL(info) << "Initialising filesystem-related data for game: " << Name();
|
||||
|
||||
if (!this->IsInstalled()) {
|
||||
SetGamePath(DetectGamePath(*this));
|
||||
|
||||
if (GamePath().empty()) {
|
||||
throw GameDetectionError("Game path could not be detected.");
|
||||
}
|
||||
|
||||
@@ -111,8 +93,14 @@ void Game::Init() {
|
||||
throw FileAccessError((boost::format("Could not create LOOT folder for game. Details: %1%") % e.what()).str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loot::Game::Init();
|
||||
std::shared_ptr<const PluginInterface> Game::GetPlugin(const std::string & name) const {
|
||||
return gameHandle_->GetPlugin(name);
|
||||
}
|
||||
|
||||
std::set<std::shared_ptr<const PluginInterface>> Game::GetPlugins() const {
|
||||
return gameHandle_->GetLoadedPlugins();
|
||||
}
|
||||
|
||||
void Game::RedatePlugins() {
|
||||
@@ -121,7 +109,7 @@ void Game::RedatePlugins() {
|
||||
return;
|
||||
}
|
||||
|
||||
vector<string> loadorder = GetLoadOrder();
|
||||
vector<string> loadorder = gameHandle_->GetLoadOrder();
|
||||
if (!loadorder.empty()) {
|
||||
time_t lastTime = 0;
|
||||
for (const auto &pluginName : loadorder) {
|
||||
@@ -152,7 +140,7 @@ void Game::LoadAllInstalledPlugins(bool headersOnly) {
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Scanning for plugins in " << this->DataPath();
|
||||
for (fs::directory_iterator it(this->DataPath()); it != fs::directory_iterator(); ++it) {
|
||||
if (fs::is_regular_file(it->status()) && Plugin::IsValid(it->path().filename().string(), *this)) {
|
||||
if (fs::is_regular_file(it->status()) && gameHandle_->IsValidPlugin(it->path().filename().string())) {
|
||||
string name = it->path().filename().string();
|
||||
BOOST_LOG_TRIVIAL(info) << "Found plugin: " << name;
|
||||
|
||||
@@ -160,7 +148,7 @@ void Game::LoadAllInstalledPlugins(bool headersOnly) {
|
||||
}
|
||||
}
|
||||
|
||||
LoadPlugins(plugins, Master(), headersOnly);
|
||||
gameHandle_->LoadPlugins(plugins, headersOnly);
|
||||
|
||||
pluginsFullyLoaded_ = !headersOnly;
|
||||
}
|
||||
@@ -169,22 +157,31 @@ bool Game::ArePluginsFullyLoaded() const {
|
||||
return pluginsFullyLoaded_;
|
||||
}
|
||||
|
||||
boost::filesystem::path Game::DataPath() const {
|
||||
if (GamePath().empty())
|
||||
throw std::logic_error("Cannot get data path from empty game path");
|
||||
return GamePath() / "Data";
|
||||
}
|
||||
|
||||
fs::path Game::MasterlistPath() const {
|
||||
if (lootDataPath_.empty() || FolderName().empty())
|
||||
return "";
|
||||
else
|
||||
return lootDataPath_ / FolderName() / "masterlist.yaml";
|
||||
return lootDataPath_ / FolderName() / "masterlist.yaml";
|
||||
}
|
||||
|
||||
fs::path Game::UserlistPath() const {
|
||||
if (lootDataPath_.empty() || FolderName().empty())
|
||||
return "";
|
||||
else
|
||||
return lootDataPath_ / FolderName() / "userlist.yaml";
|
||||
return lootDataPath_ / FolderName() / "userlist.yaml";
|
||||
}
|
||||
|
||||
std::vector<std::string> Game::GetLoadOrder() const {
|
||||
return gameHandle_->GetLoadOrder();
|
||||
}
|
||||
|
||||
void Game::SetLoadOrder(const std::vector<std::string>& loadOrder) {
|
||||
BackupLoadOrder(GetLoadOrder(), lootDataPath_ / FolderName());
|
||||
gameHandle_->SetLoadOrder(loadOrder);
|
||||
}
|
||||
|
||||
short Game::GetActiveLoadOrderIndex(const std::string & pluginName) const {
|
||||
return GetActiveLoadOrderIndex(pluginName, GetLoadOrder());
|
||||
return GetActiveLoadOrderIndex(pluginName, gameHandle_->GetLoadOrder());
|
||||
}
|
||||
|
||||
short Game::GetActiveLoadOrderIndex(const std::string & pluginName, const std::vector<std::string>& loadOrder) const {
|
||||
@@ -192,7 +189,7 @@ short Game::GetActiveLoadOrderIndex(const std::string & pluginName, const std::v
|
||||
// given plugin is encountered. If the plugin isn't active or in the load
|
||||
// order, return -1.
|
||||
|
||||
if (!IsPluginActive(pluginName))
|
||||
if (!gameHandle_->IsPluginActive(pluginName))
|
||||
return -1;
|
||||
|
||||
short numberOfActivePlugins = 0;
|
||||
@@ -200,15 +197,41 @@ short Game::GetActiveLoadOrderIndex(const std::string & pluginName, const std::v
|
||||
if (boost::iequals(plugin, pluginName))
|
||||
return numberOfActivePlugins;
|
||||
|
||||
if (IsPluginActive(plugin))
|
||||
if (gameHandle_->IsPluginActive(plugin))
|
||||
++numberOfActivePlugins;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
boost::filesystem::path Game::DetectGamePath(const GameSettings & gameSettings) {
|
||||
try {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Checking if game \"" << gameSettings.Name() << "\" is installed.";
|
||||
if (!gameSettings.GamePath().empty() && fs::exists(gameSettings.GamePath() / "Data" / gameSettings.Master()))
|
||||
return gameSettings.GamePath();
|
||||
|
||||
if (fs::exists(fs::path("..") / "Data" / gameSettings.Master())) {
|
||||
return "..";
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string path;
|
||||
std::string key_parent = fs::path(gameSettings.RegistryKey()).parent_path().string();
|
||||
std::string key_name = fs::path(gameSettings.RegistryKey()).filename().string();
|
||||
path = RegKeyStringValue("HKEY_LOCAL_MACHINE", key_parent, key_name);
|
||||
if (!path.empty() && fs::exists(fs::path(path) / "Data" / gameSettings.Master())) {
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
} catch (std::exception &e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Error while checking if game \"" << gameSettings.Name() << "\" is installed: " << e.what();
|
||||
}
|
||||
|
||||
return boost::filesystem::path();
|
||||
}
|
||||
|
||||
void Game::BackupLoadOrder(const std::vector<std::string>& loadOrder,
|
||||
const boost::filesystem::path & backupDirectory) {
|
||||
const boost::filesystem::path& backupDirectory) {
|
||||
const int maxBackupIndex = 2;
|
||||
boost::format filenameFormat = boost::format("loadorder.bak.%1%");
|
||||
|
||||
@@ -265,4 +288,4 @@ std::string Game::RegKeyStringValue(const std::string& keyStr, const std::string
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-7
@@ -29,12 +29,12 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "backend/game/game.h"
|
||||
#include "gui/state/game_settings.h"
|
||||
#include "loot/api.h"
|
||||
|
||||
namespace loot {
|
||||
namespace gui {
|
||||
class Game : public loot::Game, public GameSettings {
|
||||
class Game : public GameSettings {
|
||||
public:
|
||||
Game(const GameSettings& gameSettings,
|
||||
const boost::filesystem::path& lootDataPath,
|
||||
@@ -42,29 +42,37 @@ public:
|
||||
|
||||
using GameSettings::Type;
|
||||
|
||||
bool IsInstalled(); //Sets gamePath if the current value is not valid and a valid path is found.
|
||||
static bool IsInstalled(const GameSettings& gameSettings);
|
||||
void Init();
|
||||
|
||||
std::shared_ptr<const PluginInterface> GetPlugin(const std::string& name) const;
|
||||
std::set<std::shared_ptr<const PluginInterface>> GetPlugins() const;
|
||||
|
||||
void RedatePlugins(); //Change timestamps to match load order (Skyrim only).
|
||||
|
||||
void LoadAllInstalledPlugins(bool headersOnly); //Loads all installed plugins.
|
||||
bool ArePluginsFullyLoaded() const; // Checks if the game's plugins have already been loaded.
|
||||
|
||||
boost::filesystem::path DataPath() const;
|
||||
boost::filesystem::path MasterlistPath() const;
|
||||
boost::filesystem::path UserlistPath() const;
|
||||
|
||||
std::vector<std::string> GetLoadOrder() const;
|
||||
void SetLoadOrder(const std::vector<std::string>& loadOrder);
|
||||
|
||||
short GetActiveLoadOrderIndex(const std::string & pluginName) const;
|
||||
short GetActiveLoadOrderIndex(const std::string & pluginName, const std::vector<std::string>& loadOrder) const;
|
||||
|
||||
static void BackupLoadOrder(const std::vector<std::string>& loadOrder,
|
||||
const boost::filesystem::path& backupDirectory);
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
std::string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value);
|
||||
static std::string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value);
|
||||
#endif
|
||||
static boost::filesystem::path DetectGamePath(const GameSettings& gameSettings);
|
||||
static void BackupLoadOrder(const std::vector<std::string>& loadOrder,
|
||||
const boost::filesystem::path& backupDirectory);
|
||||
|
||||
const boost::filesystem::path lootDataPath_;
|
||||
|
||||
std::shared_ptr<GameInterface> gameHandle_;
|
||||
bool pluginsFullyLoaded_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ using std::vector;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace loot {
|
||||
LootState::LootState() : unappliedChangeCounter_(0), currentGame_(games_.end()) {}
|
||||
LootState::LootState() : unappliedChangeCounter_(0), currentGame_(installedGames_.end()) {}
|
||||
|
||||
void LootState::load(YAML::Node& settings) {
|
||||
lock_guard<mutex> guard(mutex_);
|
||||
@@ -71,9 +71,9 @@ void LootState::load(YAML::Node& settings) {
|
||||
std::unordered_set<string> newGameFolders;
|
||||
BOOST_LOG_TRIVIAL(trace) << "Updating existing games and adding new games.";
|
||||
for (const auto &gameSettings : getGameSettings()) {
|
||||
auto pos = find(games_.begin(), games_.end(), gameSettings);
|
||||
auto pos = find(installedGames_.begin(), installedGames_.end(), gameSettings);
|
||||
|
||||
if (pos != games_.end()) {
|
||||
if (pos != installedGames_.end()) {
|
||||
pos->SetName(gameSettings.Name())
|
||||
.SetMaster(gameSettings.Master())
|
||||
.SetRepoURL(gameSettings.RepoURL())
|
||||
@@ -81,8 +81,10 @@ void LootState::load(YAML::Node& settings) {
|
||||
.SetGamePath(gameSettings.GamePath())
|
||||
.SetRegistryKey(gameSettings.RegistryKey());
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Adding new game entry for: " << gameSettings.FolderName();
|
||||
games_.push_back(gui::Game(gameSettings, LootPaths::getLootDataPath()));
|
||||
if (gui::Game::IsInstalled(gameSettings)) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Adding new installed game entry for: " << gameSettings.FolderName();
|
||||
installedGames_.push_back(gui::Game(gameSettings, LootPaths::getLootDataPath()));
|
||||
}
|
||||
}
|
||||
|
||||
newGameFolders.insert(gameSettings.FolderName());
|
||||
@@ -91,23 +93,22 @@ void LootState::load(YAML::Node& settings) {
|
||||
// Remove deleted games. As the current game is stored using its index,
|
||||
// removing an earlier game may invalidate it.
|
||||
BOOST_LOG_TRIVIAL(trace) << "Removing deleted games.";
|
||||
for (auto it = games_.begin(); it != games_.end();) {
|
||||
for (auto it = installedGames_.begin(); it != installedGames_.end();) {
|
||||
if (newGameFolders.find(it->FolderName()) == newGameFolders.end()) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Removing game: " << it->FolderName();
|
||||
it = games_.erase(it);
|
||||
it = installedGames_.erase(it);
|
||||
} else
|
||||
++it;
|
||||
}
|
||||
|
||||
if (currentGame_ == end(games_)) {
|
||||
if (currentGame_ == end(installedGames_)) {
|
||||
selectGame("");
|
||||
}
|
||||
|
||||
if (currentGame_ != end(games_)) {
|
||||
if (currentGame_ != end(installedGames_)) {
|
||||
// Re-initialise the current game in case the game path setting was changed.
|
||||
currentGame_->Init();
|
||||
// Update game path in settings object.
|
||||
storeGameSettings(toGameSettings(games_));
|
||||
updateCurrentGamePathSetting();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +185,13 @@ void LootState::init(const std::string& cmdLineGame) {
|
||||
|
||||
//Detect installed games.
|
||||
BOOST_LOG_TRIVIAL(debug) << "Detecting installed games.";
|
||||
games_ = toGames(getGameSettings());
|
||||
installedGames_.clear();
|
||||
for (const auto& gameSettings : getGameSettings()) {
|
||||
if (gui::Game::IsInstalled(gameSettings)) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Adding new installed game entry for: " << gameSettings.FolderName();
|
||||
installedGames_.push_back(gui::Game(gameSettings, LootPaths::getLootDataPath()));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BOOST_LOG_TRIVIAL(debug) << "Selecting game.";
|
||||
@@ -192,8 +199,7 @@ void LootState::init(const std::string& cmdLineGame) {
|
||||
BOOST_LOG_TRIVIAL(debug) << "Game selected is " << currentGame_->Name();
|
||||
BOOST_LOG_TRIVIAL(debug) << "Initialising game-specific settings.";
|
||||
currentGame_->Init();
|
||||
// Update game path in settings object.
|
||||
storeGameSettings(toGameSettings(games_));
|
||||
updateCurrentGamePathSetting();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what();
|
||||
initErrors_.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str());
|
||||
@@ -214,13 +220,11 @@ void LootState::changeGame(const std::string& newGameFolder) {
|
||||
lock_guard<mutex> guard(mutex_);
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << "Changing current game to that with folder: " << newGameFolder;
|
||||
currentGame_ = find_if(games_.begin(), games_.end(), [&](const gui::Game& game) {
|
||||
currentGame_ = find_if(installedGames_.begin(), installedGames_.end(), [&](const gui::Game& game) {
|
||||
return boost::iequals(newGameFolder, game.FolderName());
|
||||
});
|
||||
currentGame_->Init();
|
||||
|
||||
// Update game path in settings object.
|
||||
storeGameSettings(toGameSettings(games_));
|
||||
updateCurrentGamePathSetting();
|
||||
BOOST_LOG_TRIVIAL(debug) << "New game is " << currentGame_->Name();
|
||||
}
|
||||
|
||||
@@ -230,11 +234,10 @@ gui::Game& LootState::getCurrentGame() {
|
||||
return *currentGame_;
|
||||
}
|
||||
|
||||
std::vector<std::string> LootState::getInstalledGames() {
|
||||
std::vector<std::string> LootState::getInstalledGames() const {
|
||||
vector<string> installedGames;
|
||||
for (auto &game : games_) {
|
||||
if (game.IsInstalled())
|
||||
installedGames.push_back(game.FolderName());
|
||||
for (const auto &game : installedGames_) {
|
||||
installedGames.push_back(game.FolderName());
|
||||
}
|
||||
return installedGames;
|
||||
}
|
||||
@@ -262,18 +265,16 @@ void LootState::selectGame(std::string preferredGame) {
|
||||
}
|
||||
|
||||
// Get iterator to preferred game.
|
||||
currentGame_ = find_if(begin(games_), end(games_), [&](gui::Game& game) {
|
||||
return (preferredGame.empty() || preferredGame == game.FolderName()) && game.IsInstalled();
|
||||
currentGame_ = find_if(begin(installedGames_), end(installedGames_), [&](gui::Game& game) {
|
||||
return preferredGame.empty() || preferredGame == game.FolderName();
|
||||
});
|
||||
// If the preferred game cannot be found, get the first installed game.
|
||||
if (currentGame_ == end(games_)) {
|
||||
currentGame_ = find_if(begin(games_), end(games_), [](gui::Game& game) {
|
||||
return game.IsInstalled();
|
||||
});
|
||||
if (currentGame_ == end(installedGames_)) {
|
||||
currentGame_ = begin(installedGames_);
|
||||
}
|
||||
|
||||
// If no game can be selected, throw an exception.
|
||||
if (currentGame_ == end(games_)) {
|
||||
if (currentGame_ == end(installedGames_)) {
|
||||
throw GameDetectionError("None of the supported games were detected.");
|
||||
}
|
||||
}
|
||||
@@ -286,6 +287,19 @@ void LootState::enableDebugLogging(bool enable) {
|
||||
}
|
||||
}
|
||||
|
||||
void LootState::updateCurrentGamePathSetting() {
|
||||
auto gameSettings = getGameSettings();
|
||||
auto pos = find_if(begin(gameSettings), end(gameSettings), [&](const GameSettings& game) {
|
||||
return boost::iequals(currentGame_->Name(), game.FolderName());
|
||||
});
|
||||
if (pos == end(gameSettings)) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Could not find the settings for the current game (" << currentGame_->Name() << ")";
|
||||
} else {
|
||||
pos->SetGamePath(currentGame_->GamePath());
|
||||
storeGameSettings(gameSettings);
|
||||
}
|
||||
}
|
||||
|
||||
std::list<gui::Game> LootState::toGames(const std::vector<GameSettings>& settings) {
|
||||
std::list<gui::Game> games;
|
||||
for (const auto& element : settings) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
void changeGame(const std::string& newGameFolder);
|
||||
|
||||
// Get the folder names of the installed games.
|
||||
std::vector<std::string> getInstalledGames();
|
||||
std::vector<std::string> getInstalledGames() const;
|
||||
|
||||
bool hasUnappliedChanges() const;
|
||||
void incrementUnappliedChangeCounter();
|
||||
@@ -53,10 +53,12 @@ private:
|
||||
void selectGame(std::string cmdLineGame);
|
||||
void enableDebugLogging(bool enable);
|
||||
|
||||
void updateCurrentGamePathSetting();
|
||||
|
||||
static std::list<gui::Game> toGames(const std::vector<GameSettings>& settings);
|
||||
static std::vector<GameSettings> toGameSettings(const std::list<gui::Game>& games);
|
||||
|
||||
std::list<gui::Game> games_;
|
||||
std::list<gui::Game> installedGames_;
|
||||
std::list<gui::Game>::iterator currentGame_;
|
||||
std::vector<std::string> initErrors_;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/log/core.hpp>
|
||||
|
||||
#include "tests/gui/state/game_test.h"
|
||||
|
||||
@@ -48,24 +48,20 @@ protected:
|
||||
blankDifferentMasterDependentEsp,
|
||||
blankPluginDependentEsp,
|
||||
}),
|
||||
loadOrderBackupFile0(localPath / "loadorder.bak.0"),
|
||||
loadOrderBackupFile1(localPath / "loadorder.bak.1"),
|
||||
loadOrderBackupFile2(localPath / "loadorder.bak.2"),
|
||||
loadOrderBackupFile3(localPath / "loadorder.bak.3") {}
|
||||
loadOrderBackupFile0("loadorder.bak.0"),
|
||||
loadOrderBackupFile1("loadorder.bak.1"),
|
||||
loadOrderBackupFile2("loadorder.bak.2"),
|
||||
loadOrderBackupFile3("loadorder.bak.3") {}
|
||||
|
||||
void TearDown() {
|
||||
CommonGameTestFixture::TearDown();
|
||||
|
||||
boost::filesystem::remove(loadOrderBackupFile0);
|
||||
boost::filesystem::remove(loadOrderBackupFile1);
|
||||
boost::filesystem::remove(loadOrderBackupFile2);
|
||||
}
|
||||
|
||||
std::vector<std::string> loadOrderToSet_;
|
||||
const boost::filesystem::path loadOrderBackupFile0;
|
||||
const boost::filesystem::path loadOrderBackupFile1;
|
||||
const boost::filesystem::path loadOrderBackupFile2;
|
||||
const boost::filesystem::path loadOrderBackupFile3;
|
||||
const std::string loadOrderBackupFile0;
|
||||
const std::string loadOrderBackupFile1;
|
||||
const std::string loadOrderBackupFile2;
|
||||
const std::string loadOrderBackupFile3;
|
||||
};
|
||||
|
||||
// Pass an empty first argument, as it's a prefix for the test instantation,
|
||||
@@ -103,37 +99,32 @@ TEST_P(GameTest, constructingFromGameSettingsShouldUseTheirValues) {
|
||||
EXPECT_EQ(lootDataPath / "folder" / "userlist.yaml", game.UserlistPath());
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// Testing on Windows will find real game installs in the Registry, so cannot
|
||||
// test autodetection fully unless on Linux.
|
||||
TEST_P(GameTest, constructingShouldThrowOnLinuxIfGamePathIsNotGiven) {
|
||||
EXPECT_THROW(Game(GameSettings(GetParam()), "", localPath), std::system_error);
|
||||
}
|
||||
|
||||
TEST_P(GameTest, constructingShouldThrowOnLinuxIfLocalPathIsNotGiven) {
|
||||
auto settings = GameSettings(GetParam()).SetGamePath(dataPath.parent_path());
|
||||
EXPECT_THROW(Game(settings, lootDataPath), std::system_error);
|
||||
}
|
||||
#else
|
||||
TEST_P(GameTest, constructingShouldNotThrowOnWindowsIfLocalPathIsNotGiven) {
|
||||
auto settings = GameSettings(GetParam()).SetGamePath(dataPath.parent_path());
|
||||
EXPECT_NO_THROW(Game(settings, lootDataPath, ""));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_P(GameTest, isInstalledShouldBeFalseIfGamePathIsNotSet) {
|
||||
Game game = Game(GameSettings(GetParam()), "", localPath);
|
||||
EXPECT_FALSE(game.IsInstalled());
|
||||
EXPECT_FALSE(Game::IsInstalled(GameSettings(GetParam())));
|
||||
}
|
||||
|
||||
TEST_P(GameTest, isInstalledShouldBeTrueIfGamePathIsValid) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
|
||||
EXPECT_TRUE(game.IsInstalled());
|
||||
EXPECT_TRUE(Game::IsInstalled(GameSettings(GetParam()).SetGamePath(dataPath.parent_path())));
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// 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(GameSettings(GetParam()), "");
|
||||
EXPECT_THROW(game.Init(), GameDetectionError);
|
||||
}
|
||||
|
||||
TEST_P(GameTest, initShouldThrowOnLinuxIfLocalPathIsNotGiven) {
|
||||
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(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
|
||||
|
||||
EXPECT_NO_THROW(game.Init());
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_P(GameTest, initShouldNotCreateAGameFolderIfTheLootDataPathIsEmpty) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
|
||||
|
||||
@@ -158,15 +149,6 @@ TEST_P(GameTest, initShouldNotThrowIfGameAndLocalPathsAreNotEmpty) {
|
||||
EXPECT_NO_THROW(game.Init());
|
||||
}
|
||||
|
||||
TEST_P(GameTest, redatePluginsShouldThrowIfTheGameHasNotYetBeenInitialisedForSkyrimAndNotForOtherGames) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
|
||||
|
||||
if (GetParam() == GameType::tes5 || GetParam() == GameType::tes5se)
|
||||
EXPECT_THROW(game.RedatePlugins(), std::system_error);
|
||||
else
|
||||
EXPECT_NO_THROW(game.RedatePlugins());
|
||||
}
|
||||
|
||||
TEST_P(GameTest, redatePluginsShouldRedatePluginsForSkyrimAndSkyrimSEAndDoNothingForOtherGames) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), "", localPath);
|
||||
game.Init();
|
||||
@@ -271,31 +253,39 @@ TEST_P(GameTest, GetActiveLoadOrderIndexShouldReturnTheLoadOrderIndexOmittingIna
|
||||
EXPECT_EQ(2, index);
|
||||
}
|
||||
|
||||
TEST_P(GameTest, backupLoadOrderShouldCreateABackupOfTheCurrentLoadOrder) {
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile0));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile1));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile2));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile3));
|
||||
TEST_P(GameTest, setLoadOrderShouldCreateABackupOfTheCurrentLoadOrder) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), lootDataPath, localPath);
|
||||
game.Init();
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile0));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile1));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile2));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile3));
|
||||
|
||||
EXPECT_TRUE(boost::filesystem::exists(loadOrderBackupFile0));
|
||||
EXPECT_FALSE(boost::filesystem::exists(loadOrderBackupFile1));
|
||||
EXPECT_FALSE(boost::filesystem::exists(loadOrderBackupFile2));
|
||||
EXPECT_FALSE(boost::filesystem::exists(loadOrderBackupFile3));
|
||||
auto initialLoadOrder = getLoadOrder();
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
auto loadOrder = readFileLines(loadOrderBackupFile0);
|
||||
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile0));
|
||||
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile1));
|
||||
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile2));
|
||||
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile3));
|
||||
|
||||
EXPECT_EQ(loadOrderToSet_, loadOrder);
|
||||
auto loadOrder = readFileLines(lootDataPath / game.FolderName() / loadOrderBackupFile0);
|
||||
|
||||
EXPECT_EQ(initialLoadOrder, loadOrder);
|
||||
}
|
||||
|
||||
TEST_P(GameTest, backupLoadOrderShouldRollOverExistingBackups) {
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile0));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile1));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile2));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile3));
|
||||
TEST_P(GameTest, setLoadOrderShouldRollOverExistingBackups) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), lootDataPath, localPath);
|
||||
game.Init();
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile0));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile1));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile2));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile3));
|
||||
|
||||
auto initialLoadOrder = getLoadOrder();
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
auto firstSetLoadOrder = loadOrderToSet_;
|
||||
|
||||
@@ -304,27 +294,31 @@ TEST_P(GameTest, backupLoadOrderShouldRollOverExistingBackups) {
|
||||
loadOrderToSet_[9] = blankPluginDependentEsp;
|
||||
loadOrderToSet_[10] = blankDifferentMasterDependentEsp;
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
EXPECT_TRUE(boost::filesystem::exists(loadOrderBackupFile0));
|
||||
EXPECT_TRUE(boost::filesystem::exists(loadOrderBackupFile1));
|
||||
EXPECT_FALSE(boost::filesystem::exists(loadOrderBackupFile2));
|
||||
EXPECT_FALSE(boost::filesystem::exists(loadOrderBackupFile3));
|
||||
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile0));
|
||||
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile1));
|
||||
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile2));
|
||||
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile3));
|
||||
|
||||
auto loadOrder = readFileLines(loadOrderBackupFile0);
|
||||
EXPECT_EQ(loadOrderToSet_, loadOrder);
|
||||
|
||||
loadOrder = readFileLines(loadOrderBackupFile1);
|
||||
auto loadOrder = readFileLines(lootDataPath / game.FolderName() / loadOrderBackupFile0);
|
||||
EXPECT_EQ(firstSetLoadOrder, loadOrder);
|
||||
|
||||
loadOrder = readFileLines(lootDataPath / game.FolderName() / loadOrderBackupFile1);
|
||||
EXPECT_EQ(initialLoadOrder, loadOrder);
|
||||
}
|
||||
|
||||
TEST_P(GameTest, backupLoadOrderShouldKeepUpToThreeBackups) {
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile0));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile1));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile2));
|
||||
ASSERT_FALSE(boost::filesystem::exists(loadOrderBackupFile3));
|
||||
TEST_P(GameTest, setLoadOrderShouldKeepUpToThreeBackups) {
|
||||
Game game = Game(GameSettings(GetParam()).SetGamePath(dataPath.parent_path()), lootDataPath, localPath);
|
||||
game.Init();
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile0));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile1));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile2));
|
||||
ASSERT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile3));
|
||||
|
||||
auto initialLoadOrder = getLoadOrder();
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
auto firstSetLoadOrder = loadOrderToSet_;
|
||||
|
||||
@@ -333,7 +327,7 @@ TEST_P(GameTest, backupLoadOrderShouldKeepUpToThreeBackups) {
|
||||
loadOrderToSet_[9] = blankPluginDependentEsp;
|
||||
loadOrderToSet_[10] = blankDifferentMasterDependentEsp;
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
auto secondSetLoadOrder = loadOrderToSet_;
|
||||
|
||||
@@ -342,30 +336,30 @@ TEST_P(GameTest, backupLoadOrderShouldKeepUpToThreeBackups) {
|
||||
loadOrderToSet_[7] = blankMasterDependentEsp;
|
||||
loadOrderToSet_[8] = blankEsp;
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
auto thirdSetLoadOrder = loadOrderToSet_;
|
||||
|
||||
ASSERT_NE(blankMasterDependentEsm, loadOrderToSet_[7]);
|
||||
ASSERT_NE(blankDifferentEsm, loadOrderToSet_[8]);
|
||||
loadOrderToSet_[7] = blankMasterDependentEsm;
|
||||
loadOrderToSet_[8] = blankDifferentEsm;
|
||||
ASSERT_NE(blankDifferentMasterDependentEsm, loadOrderToSet_[3]);
|
||||
ASSERT_NE(blankDifferentEsm, loadOrderToSet_[4]);
|
||||
loadOrderToSet_[3] = blankDifferentMasterDependentEsm;
|
||||
loadOrderToSet_[4] = blankDifferentEsm;
|
||||
|
||||
ASSERT_NO_THROW(Game::BackupLoadOrder(loadOrderToSet_, localPath));
|
||||
ASSERT_NO_THROW(game.SetLoadOrder(loadOrderToSet_));
|
||||
|
||||
EXPECT_TRUE(boost::filesystem::exists(loadOrderBackupFile0));
|
||||
EXPECT_TRUE(boost::filesystem::exists(loadOrderBackupFile1));
|
||||
EXPECT_TRUE(boost::filesystem::exists(loadOrderBackupFile2));
|
||||
EXPECT_FALSE(boost::filesystem::exists(loadOrderBackupFile3));
|
||||
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile0));
|
||||
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile1));
|
||||
EXPECT_TRUE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile2));
|
||||
EXPECT_FALSE(boost::filesystem::exists(lootDataPath / game.FolderName() / loadOrderBackupFile3));
|
||||
|
||||
auto loadOrder = readFileLines(loadOrderBackupFile0);
|
||||
EXPECT_EQ(loadOrderToSet_, loadOrder);
|
||||
|
||||
loadOrder = readFileLines(loadOrderBackupFile1);
|
||||
auto loadOrder = readFileLines(lootDataPath / game.FolderName() / loadOrderBackupFile0);
|
||||
EXPECT_EQ(thirdSetLoadOrder, loadOrder);
|
||||
|
||||
loadOrder = readFileLines(loadOrderBackupFile2);
|
||||
loadOrder = readFileLines(lootDataPath / game.FolderName() / loadOrderBackupFile1);
|
||||
EXPECT_EQ(secondSetLoadOrder, loadOrder);
|
||||
|
||||
loadOrder = readFileLines(lootDataPath / game.FolderName() / loadOrderBackupFile2);
|
||||
EXPECT_EQ(firstSetLoadOrder, loadOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user