mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Improve GameCache tests
This commit is contained in:
+1
-1
@@ -236,7 +236,7 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/test_api.h"
|
||||
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game_cache.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_cache_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game_settings.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_load_order_handler.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/test_git_helper.h"
|
||||
|
||||
+80
-72
@@ -27,157 +27,165 @@ along with LOOT. If not, see
|
||||
|
||||
#include "backend/game/game_cache.h"
|
||||
|
||||
#include "tests/fixtures.h"
|
||||
#include "tests/base_game_test.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
class GameCacheTest : public SkyrimTest {
|
||||
class GameCacheTest : public BaseGameTest {
|
||||
protected:
|
||||
GameCacheTest() :
|
||||
condition("Condition"),
|
||||
conditionLowercase("condition") {}
|
||||
|
||||
void initialiseGame() {
|
||||
game = Game(GetParam());
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
}
|
||||
|
||||
Game game;
|
||||
GameCache cache;
|
||||
|
||||
const std::string condition;
|
||||
const std::string conditionLowercase;
|
||||
};
|
||||
|
||||
TEST_F(GameCacheTest, copyConstructorShouldCopyCachedData) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
// Pass an empty first argument, as it's a prefix for the test instantation,
|
||||
// but we only have the one so no prefix is necessary.
|
||||
// Just test with one game because if it works for one it will work for them
|
||||
// all.
|
||||
INSTANTIATE_TEST_CASE_P(,
|
||||
GameCacheTest,
|
||||
::testing::Values(
|
||||
Game::tes5));
|
||||
|
||||
cache.CacheCondition("True Condition", true);
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
TEST_P(GameCacheTest, copyConstructorShouldCopyCachedData) {
|
||||
initialiseGame();
|
||||
|
||||
cache.CacheCondition(condition, true);
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
Message expectedMessage(Message::say, "1");
|
||||
cache.AppendMessage(expectedMessage);
|
||||
cache.SetLoadOrderSorted(true);
|
||||
|
||||
GameCache otherCache(cache);
|
||||
EXPECT_EQ(std::make_pair(true, true), otherCache.GetCachedCondition("true Condition"));
|
||||
EXPECT_EQ("Blank.esm", otherCache.GetPlugin("Blank.esm").Name());
|
||||
EXPECT_EQ(std::make_pair(true, true), otherCache.GetCachedCondition(conditionLowercase));
|
||||
EXPECT_EQ(blankEsm, otherCache.GetPlugin(blankEsm).Name());
|
||||
ASSERT_EQ(1, otherCache.GetMessages().size());
|
||||
EXPECT_EQ(expectedMessage, otherCache.GetMessages()[0]);
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, assignmentOperatorShouldCopyCachedData) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
TEST_P(GameCacheTest, assignmentOperatorShouldCopyCachedData) {
|
||||
initialiseGame();
|
||||
|
||||
cache.CacheCondition("True Condition", true);
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
cache.CacheCondition(condition, true);
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
Message expectedMessage(Message::say, "1");
|
||||
cache.AppendMessage(expectedMessage);
|
||||
cache.SetLoadOrderSorted(true);
|
||||
|
||||
GameCache otherCache = cache;
|
||||
EXPECT_EQ(std::make_pair(true, true), otherCache.GetCachedCondition("true Condition"));
|
||||
EXPECT_EQ("Blank.esm", otherCache.GetPlugin("Blank.esm").Name());
|
||||
EXPECT_EQ(std::make_pair(true, true), otherCache.GetCachedCondition(conditionLowercase));
|
||||
EXPECT_EQ(blankEsm, otherCache.GetPlugin(blankEsm).Name());
|
||||
ASSERT_EQ(1, otherCache.GetMessages().size());
|
||||
EXPECT_EQ(expectedMessage, otherCache.GetMessages()[0]);
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingATrueConditionShouldReturnATrueTruePair) {
|
||||
EXPECT_NO_THROW(cache.CacheCondition("True Condition", true));
|
||||
TEST_P(GameCacheTest, gettingATrueConditionShouldReturnATrueTruePair) {
|
||||
EXPECT_NO_THROW(cache.CacheCondition(condition, true));
|
||||
|
||||
EXPECT_EQ(std::make_pair(true, true), cache.GetCachedCondition("true Condition"));
|
||||
EXPECT_EQ(std::make_pair(true, true), cache.GetCachedCondition(conditionLowercase));
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingAFalseConditionShouldReturnAFalseTruePair) {
|
||||
EXPECT_NO_THROW(cache.CacheCondition("False Condition", false));
|
||||
TEST_P(GameCacheTest, gettingAFalseConditionShouldReturnAFalseTruePair) {
|
||||
EXPECT_NO_THROW(cache.CacheCondition(condition, false));
|
||||
|
||||
EXPECT_EQ(std::make_pair(false, true), cache.GetCachedCondition("false Condition"));
|
||||
EXPECT_EQ(std::make_pair(false, true), cache.GetCachedCondition(conditionLowercase));
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingANonCachedConditionShouldReturnAFalseFalsePair) {
|
||||
EXPECT_EQ(std::make_pair(false, false), cache.GetCachedCondition("true missing Condition"));
|
||||
TEST_P(GameCacheTest, gettingANonCachedConditionShouldReturnAFalseFalsePair) {
|
||||
EXPECT_EQ(std::make_pair(false, false), cache.GetCachedCondition(condition));
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, addingAPluginThatDoesNotExistShouldSucceed) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
TEST_P(GameCacheTest, addingAPluginThatDoesNotExistShouldSucceed) {
|
||||
initialiseGame();
|
||||
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
EXPECT_EQ("Blank.esm", cache.GetPlugin("Blank.esm").Name());
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
EXPECT_EQ(blankEsm, cache.GetPlugin(blankEsm).Name());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, addingAPluginThatIsAlreadyCachedShouldOverwriteExistingEntry) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
TEST_P(GameCacheTest, addingAPluginThatIsAlreadyCachedShouldOverwriteExistingEntry) {
|
||||
initialiseGame();
|
||||
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
EXPECT_EQ(0, cache.GetPlugin("Blank.esm").Crc());
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
EXPECT_EQ(0, cache.GetPlugin(blankEsm).Crc());
|
||||
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", false));
|
||||
EXPECT_EQ(0x187BE342, cache.GetPlugin("Blank.esm").Crc());
|
||||
cache.AddPlugin(Plugin(game, blankEsm, false));
|
||||
EXPECT_EQ(blankEsmCrc, cache.GetPlugin(blankEsm).Crc());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingAPluginThatIsNotCachedShouldThrow) {
|
||||
EXPECT_ANY_THROW(cache.GetPlugin("Blank.esm"));
|
||||
TEST_P(GameCacheTest, gettingAPluginThatIsNotCachedShouldThrow) {
|
||||
EXPECT_ANY_THROW(cache.GetPlugin(blankEsm));
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingAPluginShouldBeCaseInsensitive) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
TEST_P(GameCacheTest, gettingAPluginShouldBeCaseInsensitive) {
|
||||
initialiseGame();
|
||||
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
EXPECT_EQ("Blank.esm", cache.GetPlugin("blanK.esm").Name());
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
EXPECT_EQ(blankEsm, cache.GetPlugin(blankEsm).Name());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingPluginsShouldReturnAnEmptySetIfNoPluginsHaveBeenCached) {
|
||||
TEST_P(GameCacheTest, gettingPluginsShouldReturnAnEmptySetIfNoPluginsHaveBeenCached) {
|
||||
EXPECT_TRUE(cache.GetPlugins().empty());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, gettingPluginsShouldReturnASetOfCachedPluginsIfPluginsHaveBeenCached) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
TEST_P(GameCacheTest, gettingPluginsShouldReturnASetOfCachedPluginsIfPluginsHaveBeenCached) {
|
||||
initialiseGame();
|
||||
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
cache.AddPlugin(Plugin(game, "Blank - Master Dependent.esp", true));
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
cache.AddPlugin(Plugin(game, blankMasterDependentEsm, true));
|
||||
|
||||
EXPECT_EQ(std::set<Plugin>({
|
||||
Plugin(game, "Blank.esm", true),
|
||||
Plugin(game, "Blank - Master Dependent.esp", true),
|
||||
Plugin(game, blankEsm, true),
|
||||
Plugin(game, blankMasterDependentEsm, true),
|
||||
}), cache.GetPlugins());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, clearingCachedConditionsShouldNotThrowIfNoConditionsAreCached) {
|
||||
TEST_P(GameCacheTest, clearingCachedConditionsShouldNotThrowIfNoConditionsAreCached) {
|
||||
EXPECT_NO_THROW(cache.ClearCachedConditions());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, clearingCachedConditionsShouldClearAnyCachedConditions) {
|
||||
EXPECT_NO_THROW(cache.CacheCondition("True Condition", true));
|
||||
TEST_P(GameCacheTest, clearingCachedConditionsShouldClearAnyCachedConditions) {
|
||||
EXPECT_NO_THROW(cache.CacheCondition(condition, true));
|
||||
|
||||
EXPECT_NO_THROW(cache.ClearCachedConditions());
|
||||
|
||||
EXPECT_EQ(std::make_pair(false, false), cache.GetCachedCondition("true Condition"));
|
||||
EXPECT_EQ(std::make_pair(false, false), cache.GetCachedCondition(conditionLowercase));
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, clearingCachedPluginsShouldNotThrowIfNoPluginsAreCached) {
|
||||
TEST_P(GameCacheTest, clearingCachedPluginsShouldNotThrowIfNoPluginsAreCached) {
|
||||
EXPECT_NO_THROW(cache.ClearCachedPlugins());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, clearingCachedPluginsShouldClearAnyCachedPlugins) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
TEST_P(GameCacheTest, clearingCachedPluginsShouldClearAnyCachedPlugins) {
|
||||
initialiseGame();
|
||||
|
||||
cache.AddPlugin(Plugin(game, "Blank.esm", true));
|
||||
cache.AddPlugin(Plugin(game, blankEsm, true));
|
||||
cache.ClearCachedPlugins();
|
||||
|
||||
EXPECT_TRUE(cache.GetPlugins().empty());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, aMessageShouldBeCachedByDefault) {
|
||||
TEST_P(GameCacheTest, aMessageShouldBeCachedByDefault) {
|
||||
ASSERT_EQ(1, cache.GetMessages().size());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, settingLoadOrderSortedToTrueShouldSupressDefaultCachedMessage) {
|
||||
TEST_P(GameCacheTest, settingLoadOrderSortedToTrueShouldSupressDefaultCachedMessage) {
|
||||
cache.SetLoadOrderSorted(true);
|
||||
|
||||
ASSERT_TRUE(cache.GetMessages().empty());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, settingLoadOrderSortedToFalseShouldReverseTheDefaultCachedMessageSuppression) {
|
||||
TEST_P(GameCacheTest, settingLoadOrderSortedToFalseShouldReverseTheDefaultCachedMessageSuppression) {
|
||||
auto expectedMessages = cache.GetMessages();
|
||||
cache.SetLoadOrderSorted(true);
|
||||
cache.SetLoadOrderSorted(false);
|
||||
@@ -185,7 +193,7 @@ namespace loot {
|
||||
ASSERT_EQ(expectedMessages, cache.GetMessages());
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, appendingMessagesShouldStoreThemInTheGivenOrder) {
|
||||
TEST_P(GameCacheTest, appendingMessagesShouldStoreThemInTheGivenOrder) {
|
||||
std::vector<Message> messages({
|
||||
Message(Message::say, "1"),
|
||||
Message(Message::error, "2"),
|
||||
@@ -198,7 +206,7 @@ namespace loot {
|
||||
EXPECT_EQ(messages[1], cache.GetMessages()[1]);
|
||||
}
|
||||
|
||||
TEST_F(GameCacheTest, clearingMessagesShouldRemoveAllAppendedMessages) {
|
||||
TEST_P(GameCacheTest, clearingMessagesShouldRemoveAllAppendedMessages) {
|
||||
std::vector<Message> messages({
|
||||
Message(Message::say, "1"),
|
||||
Message(Message::error, "2"),
|
||||
+1
-1
@@ -42,7 +42,7 @@
|
||||
#include "api/loot_write_minimal_list_test.h"
|
||||
#include "api/test_api.h"
|
||||
#include "backend/game/game_test.h"
|
||||
#include "backend/game/test_game_cache.h"
|
||||
#include "backend/game/game_cache_test.h"
|
||||
#include "backend/game/test_game_settings.h"
|
||||
#include "backend/game/test_load_order_handler.h"
|
||||
#include "backend/helpers/test_git_helper.h"
|
||||
|
||||
Reference in New Issue
Block a user