Namespace C++ tests and rename test fixture classes

Tests are now in the loot::tests namespace, and test fixture class names
now end in Test to prevent name conflicts with the classes they test.
This commit is contained in:
Oliver Hamlet
2016-03-22 20:04:16 +00:00
parent 939ca1f1dd
commit 4ab442679d
26 changed files with 5302 additions and 5227 deletions
+545 -540
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+43 -43
View File
@@ -31,120 +31,120 @@ along with LOOT. If not, see
namespace loot {
namespace test {
class GameCache : public SkyrimTest {
class GameCacheTest : public SkyrimTest {
protected:
loot::GameCache cache;
GameCache cache;
};
TEST_F(GameCache, copyConstructorShouldCopyCachedData) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, copyConstructorShouldCopyCachedData) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.CacheCondition("True Condition", true);
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
Message expectedMessage(Message::say, "1");
cache.AppendMessage(expectedMessage);
cache.SetLoadOrderSorted(true);
loot::GameCache otherCache(cache);
GameCache otherCache(cache);
EXPECT_EQ(std::make_pair(true, true), otherCache.GetCachedCondition("true Condition"));
EXPECT_EQ("Blank.esm", otherCache.GetPlugin("Blank.esm").Name());
ASSERT_EQ(1, otherCache.GetMessages().size());
EXPECT_EQ(expectedMessage, otherCache.GetMessages()[0]);
}
TEST_F(GameCache, assignmentOperatorShouldCopyCachedData) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, assignmentOperatorShouldCopyCachedData) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.CacheCondition("True Condition", true);
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
Message expectedMessage(Message::say, "1");
cache.AppendMessage(expectedMessage);
cache.SetLoadOrderSorted(true);
loot::GameCache otherCache = cache;
GameCache otherCache = cache;
EXPECT_EQ(std::make_pair(true, true), otherCache.GetCachedCondition("true Condition"));
EXPECT_EQ("Blank.esm", otherCache.GetPlugin("Blank.esm").Name());
ASSERT_EQ(1, otherCache.GetMessages().size());
EXPECT_EQ(expectedMessage, otherCache.GetMessages()[0]);
}
TEST_F(GameCache, gettingATrueConditionShouldReturnATrueTruePair) {
TEST_F(GameCacheTest, gettingATrueConditionShouldReturnATrueTruePair) {
EXPECT_NO_THROW(cache.CacheCondition("True Condition", true));
EXPECT_EQ(std::make_pair(true, true), cache.GetCachedCondition("true Condition"));
}
TEST_F(GameCache, gettingAFalseConditionShouldReturnAFalseTruePair) {
TEST_F(GameCacheTest, gettingAFalseConditionShouldReturnAFalseTruePair) {
EXPECT_NO_THROW(cache.CacheCondition("False Condition", false));
EXPECT_EQ(std::make_pair(false, true), cache.GetCachedCondition("false Condition"));
}
TEST_F(GameCache, gettingANonCachedConditionShouldReturnAFalseFalsePair) {
TEST_F(GameCacheTest, gettingANonCachedConditionShouldReturnAFalseFalsePair) {
EXPECT_EQ(std::make_pair(false, false), cache.GetCachedCondition("true missing Condition"));
}
TEST_F(GameCache, addingAPluginThatDoesNotExistShouldSucceed) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, addingAPluginThatDoesNotExistShouldSucceed) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
EXPECT_EQ("Blank.esm", cache.GetPlugin("Blank.esm").Name());
}
TEST_F(GameCache, addingAPluginThatIsAlreadyCachedShouldOverwriteExistingEntry) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, addingAPluginThatIsAlreadyCachedShouldOverwriteExistingEntry) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
EXPECT_EQ(0, cache.GetPlugin("Blank.esm").Crc());
cache.AddPlugin(loot::Plugin(game, "Blank.esm", false));
cache.AddPlugin(Plugin(game, "Blank.esm", false));
EXPECT_EQ(0x187BE342, cache.GetPlugin("Blank.esm").Crc());
}
TEST_F(GameCache, gettingAPluginThatIsNotCachedShouldThrow) {
TEST_F(GameCacheTest, gettingAPluginThatIsNotCachedShouldThrow) {
EXPECT_ANY_THROW(cache.GetPlugin("Blank.esm"));
}
TEST_F(GameCache, gettingAPluginShouldBeCaseInsensitive) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, gettingAPluginShouldBeCaseInsensitive) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
EXPECT_EQ("Blank.esm", cache.GetPlugin("blanK.esm").Name());
}
TEST_F(GameCache, gettingPluginsShouldReturnAnEmptySetIfNoPluginsHaveBeenCached) {
TEST_F(GameCacheTest, gettingPluginsShouldReturnAnEmptySetIfNoPluginsHaveBeenCached) {
EXPECT_TRUE(cache.GetPlugins().empty());
}
TEST_F(GameCache, gettingPluginsShouldReturnASetOfCachedPluginsIfPluginsHaveBeenCached) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, gettingPluginsShouldReturnASetOfCachedPluginsIfPluginsHaveBeenCached) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(loot::Plugin(game, "Blank - Master Dependent.esp", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank - Master Dependent.esp", true));
EXPECT_EQ(std::set<loot::Plugin>({
loot::Plugin(game, "Blank.esm", true),
loot::Plugin(game, "Blank - Master Dependent.esp", true),
EXPECT_EQ(std::set<Plugin>({
Plugin(game, "Blank.esm", true),
Plugin(game, "Blank - Master Dependent.esp", true),
}), cache.GetPlugins());
}
TEST_F(GameCache, clearingCachedConditionsShouldNotThrowIfNoConditionsAreCached) {
TEST_F(GameCacheTest, clearingCachedConditionsShouldNotThrowIfNoConditionsAreCached) {
EXPECT_NO_THROW(cache.ClearCachedConditions());
}
TEST_F(GameCache, clearingCachedConditionsShouldClearAnyCachedConditions) {
TEST_F(GameCacheTest, clearingCachedConditionsShouldClearAnyCachedConditions) {
EXPECT_NO_THROW(cache.CacheCondition("True Condition", true));
EXPECT_NO_THROW(cache.ClearCachedConditions());
@@ -152,32 +152,32 @@ namespace loot {
EXPECT_EQ(std::make_pair(false, false), cache.GetCachedCondition("true Condition"));
}
TEST_F(GameCache, clearingCachedPluginsShouldNotThrowIfNoPluginsAreCached) {
TEST_F(GameCacheTest, clearingCachedPluginsShouldNotThrowIfNoPluginsAreCached) {
EXPECT_NO_THROW(cache.ClearCachedPlugins());
}
TEST_F(GameCache, clearingCachedPluginsShouldClearAnyCachedPlugins) {
loot::Game game(loot::Game::tes5);
TEST_F(GameCacheTest, clearingCachedPluginsShouldClearAnyCachedPlugins) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
cache.AddPlugin(loot::Plugin(game, "Blank.esm", true));
cache.AddPlugin(Plugin(game, "Blank.esm", true));
cache.ClearCachedPlugins();
EXPECT_TRUE(cache.GetPlugins().empty());
}
TEST_F(GameCache, aMessageShouldBeCachedByDefault) {
TEST_F(GameCacheTest, aMessageShouldBeCachedByDefault) {
ASSERT_EQ(1, cache.GetMessages().size());
}
TEST_F(GameCache, settingLoadOrderSortedToTrueShouldSupressDefaultCachedMessage) {
TEST_F(GameCacheTest, settingLoadOrderSortedToTrueShouldSupressDefaultCachedMessage) {
cache.SetLoadOrderSorted(true);
ASSERT_TRUE(cache.GetMessages().empty());
}
TEST_F(GameCache, settingLoadOrderSortedToFalseShouldReverseTheDefaultCachedMessageSuppression) {
TEST_F(GameCacheTest, settingLoadOrderSortedToFalseShouldReverseTheDefaultCachedMessageSuppression) {
auto expectedMessages = cache.GetMessages();
cache.SetLoadOrderSorted(true);
cache.SetLoadOrderSorted(false);
@@ -185,7 +185,7 @@ namespace loot {
ASSERT_EQ(expectedMessages, cache.GetMessages());
}
TEST_F(GameCache, appendingMessagesShouldStoreThemInTheGivenOrder) {
TEST_F(GameCacheTest, appendingMessagesShouldStoreThemInTheGivenOrder) {
std::vector<Message> messages({
Message(Message::say, "1"),
Message(Message::error, "2"),
@@ -198,7 +198,7 @@ namespace loot {
EXPECT_EQ(messages[1], cache.GetMessages()[1]);
}
TEST_F(GameCache, clearingMessagesShouldRemoveAllAppendedMessages) {
TEST_F(GameCacheTest, clearingMessagesShouldRemoveAllAppendedMessages) {
std::vector<Message> messages({
Message(Message::say, "1"),
Message(Message::error, "2"),
+191 -187
View File
@@ -29,226 +29,230 @@ along with LOOT. If not, see
#include "backend/game/game_settings.h"
#include "tests/fixtures.h"
class GameSettings : public SkyrimTest {};
namespace loot {
namespace test {
class GameSettingsTest : public SkyrimTest {};
TEST_F(GameSettings, ConstructorsAndDataAccess) {
loot::GameSettings game;
TEST_F(GameSettingsTest, ConstructorsAndDataAccess) {
GameSettings game;
EXPECT_EQ(loot::GameSettings::autodetect, game.Id());
EXPECT_EQ("", game.Name());
EXPECT_EQ("", game.FolderName());
EXPECT_EQ("", game.Master());
EXPECT_EQ("", game.RegistryKey());
EXPECT_EQ("", game.RepoURL());
EXPECT_EQ("", game.RepoBranch());
EXPECT_EQ(GameSettings::autodetect, game.Id());
EXPECT_EQ("", game.Name());
EXPECT_EQ("", game.FolderName());
EXPECT_EQ("", game.Master());
EXPECT_EQ("", game.RegistryKey());
EXPECT_EQ("", game.RepoURL());
EXPECT_EQ("", game.RepoBranch());
EXPECT_EQ("", game.GamePath());
EXPECT_EQ("", game.DataPath());
EXPECT_EQ("", game.MasterlistPath());
EXPECT_EQ("", game.UserlistPath());
EXPECT_EQ("", game.GamePath());
EXPECT_EQ("", game.DataPath());
EXPECT_EQ("", game.MasterlistPath());
EXPECT_EQ("", game.UserlistPath());
game = loot::GameSettings(loot::GameSettings::tes5);
game = GameSettings(GameSettings::tes5);
EXPECT_EQ(loot::GameSettings::tes5, game.Id());
EXPECT_EQ("TES V: Skyrim", game.Name());
EXPECT_EQ("Skyrim", game.FolderName());
EXPECT_EQ("Skyrim.esm", game.Master());
EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey());
EXPECT_EQ("https://github.com/loot/skyrim.git", game.RepoURL());
// Repo branch changes between LOOT versions, so don't check an exact value.
EXPECT_NE("", game.RepoBranch());
EXPECT_EQ(GameSettings::tes5, game.Id());
EXPECT_EQ("TES V: Skyrim", game.Name());
EXPECT_EQ("Skyrim", game.FolderName());
EXPECT_EQ("Skyrim.esm", game.Master());
EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey());
EXPECT_EQ("https://github.com/loot/skyrim.git", game.RepoURL());
// Repo branch changes between LOOT versions, so don't check an exact value.
EXPECT_NE("", game.RepoBranch());
EXPECT_EQ("", game.GamePath());
EXPECT_EQ("", game.DataPath());
EXPECT_EQ(loot::g_path_local / "Skyrim" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(loot::g_path_local / "Skyrim" / "userlist.yaml", game.UserlistPath());
EXPECT_EQ("", game.GamePath());
EXPECT_EQ("", game.DataPath());
EXPECT_EQ(g_path_local / "Skyrim" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(g_path_local / "Skyrim" / "userlist.yaml", game.UserlistPath());
game = loot::GameSettings(loot::GameSettings::tes5, "folder");
game = GameSettings(GameSettings::tes5, "folder");
EXPECT_EQ(loot::GameSettings::tes5, game.Id());
EXPECT_EQ("TES V: Skyrim", game.Name());
EXPECT_EQ("folder", game.FolderName());
EXPECT_EQ("Skyrim.esm", game.Master());
EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey());
EXPECT_EQ("https://github.com/loot/skyrim.git", game.RepoURL());
// Repo branch changes between LOOT versions, so don't check an exact value.
EXPECT_NE("", game.RepoBranch());
EXPECT_EQ(GameSettings::tes5, game.Id());
EXPECT_EQ("TES V: Skyrim", game.Name());
EXPECT_EQ("folder", game.FolderName());
EXPECT_EQ("Skyrim.esm", game.Master());
EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey());
EXPECT_EQ("https://github.com/loot/skyrim.git", game.RepoURL());
// Repo branch changes between LOOT versions, so don't check an exact value.
EXPECT_NE("", game.RepoBranch());
EXPECT_EQ("", game.GamePath());
EXPECT_EQ("", game.DataPath());
EXPECT_EQ(loot::g_path_local / "folder" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(loot::g_path_local / "folder" / "userlist.yaml", game.UserlistPath());
}
EXPECT_EQ("", game.GamePath());
EXPECT_EQ("", game.DataPath());
EXPECT_EQ(g_path_local / "folder" / "masterlist.yaml", game.MasterlistPath());
EXPECT_EQ(g_path_local / "folder" / "userlist.yaml", game.UserlistPath());
}
TEST_F(GameSettings, IsInstalled) {
loot::GameSettings game;
EXPECT_FALSE(game.IsInstalled());
TEST_F(GameSettingsTest, IsInstalled) {
GameSettings game;
EXPECT_FALSE(game.IsInstalled());
game = loot::GameSettings(loot::GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
EXPECT_TRUE(game.IsInstalled());
EXPECT_EQ(dataPath.parent_path(), game.GamePath());
game = GameSettings(GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
EXPECT_TRUE(game.IsInstalled());
EXPECT_EQ(dataPath.parent_path(), game.GamePath());
game = loot::GameSettings(loot::GameSettings::fo3);
EXPECT_FALSE(game.IsInstalled());
}
game = GameSettings(GameSettings::fo3);
EXPECT_FALSE(game.IsInstalled());
}
TEST_F(GameSettings, EqualityOperators) {
loot::GameSettings game1, game2;
EXPECT_TRUE(game1 == game2);
TEST_F(GameSettingsTest, EqualityOperators) {
GameSettings game1, game2;
EXPECT_TRUE(game1 == game2);
game1 = loot::GameSettings(loot::GameSettings::tes5);
game2 = loot::GameSettings(loot::GameSettings::tes5);
EXPECT_TRUE(game1 == game2);
game1 = GameSettings(GameSettings::tes5);
game2 = GameSettings(GameSettings::tes5);
EXPECT_TRUE(game1 == game2);
game1 = loot::GameSettings(loot::GameSettings::tes5, "game1")
.SetMaster("master1")
.SetRegistryKey("key1")
.SetRepoURL("url1")
.SetRepoBranch("branch1")
.SetGamePath("path1");
game2 = loot::GameSettings(loot::GameSettings::tes5, "game2")
.SetMaster("master2")
.SetRegistryKey("key2")
.SetRepoURL("url2")
.SetRepoBranch("branch2")
.SetGamePath("path2");
EXPECT_TRUE(game1 == game2);
game1 = GameSettings(GameSettings::tes5, "game1")
.SetMaster("master1")
.SetRegistryKey("key1")
.SetRepoURL("url1")
.SetRepoBranch("branch1")
.SetGamePath("path1");
game2 = GameSettings(GameSettings::tes5, "game2")
.SetMaster("master2")
.SetRegistryKey("key2")
.SetRepoURL("url2")
.SetRepoBranch("branch2")
.SetGamePath("path2");
EXPECT_TRUE(game1 == game2);
game1 = loot::GameSettings(loot::GameSettings::tes4)
.SetName("name");
game2 = loot::GameSettings(loot::GameSettings::tes5)
.SetName("name");
EXPECT_TRUE(game1 == game2);
game1 = GameSettings(GameSettings::tes4)
.SetName("name");
game2 = GameSettings(GameSettings::tes5)
.SetName("name");
EXPECT_TRUE(game1 == game2);
game1 = loot::GameSettings(loot::GameSettings::tes4);
game2 = loot::GameSettings(loot::GameSettings::tes5);
EXPECT_FALSE(game1 == game2);
}
game1 = GameSettings(GameSettings::tes4);
game2 = GameSettings(GameSettings::tes5);
EXPECT_FALSE(game1 == game2);
}
TEST_F(GameSettings, SetName) {
loot::GameSettings game;
game.SetName("name");
EXPECT_EQ("name", game.Name());
}
TEST_F(GameSettingsTest, SetName) {
GameSettings game;
game.SetName("name");
EXPECT_EQ("name", game.Name());
}
TEST_F(GameSettings, SetMaster) {
loot::GameSettings game;
game.SetMaster("master");
EXPECT_EQ("master", game.Master());
}
TEST_F(GameSettingsTest, SetMaster) {
GameSettings game;
game.SetMaster("master");
EXPECT_EQ("master", game.Master());
}
TEST_F(GameSettings, SetRegistryKey) {
loot::GameSettings game;
game.SetRegistryKey("key");
EXPECT_EQ("key", game.RegistryKey());
}
TEST_F(GameSettingsTest, SetRegistryKey) {
GameSettings game;
game.SetRegistryKey("key");
EXPECT_EQ("key", game.RegistryKey());
}
TEST_F(GameSettings, SetRepoURL) {
loot::GameSettings game;
game.SetRepoURL("url");
EXPECT_EQ("url", game.RepoURL());
}
TEST_F(GameSettingsTest, SetRepoURL) {
GameSettings game;
game.SetRepoURL("url");
EXPECT_EQ("url", game.RepoURL());
}
TEST_F(GameSettings, SetRepoBranch) {
loot::GameSettings game;
game.SetRepoBranch("branch");
EXPECT_EQ("branch", game.RepoBranch());
}
TEST_F(GameSettingsTest, SetRepoBranch) {
GameSettings game;
game.SetRepoBranch("branch");
EXPECT_EQ("branch", game.RepoBranch());
}
TEST_F(GameSettings, SetGamePath) {
loot::GameSettings game;
game.SetGamePath("path");
EXPECT_EQ("path", game.GamePath().string());
EXPECT_EQ(boost::filesystem::path("path") / "Data", game.DataPath());
}
TEST_F(GameSettingsTest, SetGamePath) {
GameSettings game;
game.SetGamePath("path");
EXPECT_EQ("path", game.GamePath().string());
EXPECT_EQ(boost::filesystem::path("path") / "Data", game.DataPath());
}
TEST_F(GameSettings, YamlEmitter) {
loot::GameSettings game(loot::GameSettings::tes5, "folder1");
game.SetName("name1")
.SetMaster("master1")
.SetRegistryKey("key1")
.SetRepoURL("url1")
.SetRepoBranch("branch1")
.SetGamePath("path1");
TEST_F(GameSettingsTest, YamlEmitter) {
GameSettings game(GameSettings::tes5, "folder1");
game.SetName("name1")
.SetMaster("master1")
.SetRegistryKey("key1")
.SetRepoURL("url1")
.SetRepoBranch("branch1")
.SetGamePath("path1");
YAML::Emitter e;
e << game;
EXPECT_STREQ("type: 'Skyrim'\n"
"folder: 'folder1'\n"
"name: 'name1'\n"
"master: 'master1'\n"
"repo: 'url1'\n"
"branch: 'branch1'\n"
"path: 'path1'\n"
"registry: 'key1'", e.c_str());
}
YAML::Emitter e;
e << game;
EXPECT_STREQ("type: 'Skyrim'\n"
"folder: 'folder1'\n"
"name: 'name1'\n"
"master: 'master1'\n"
"repo: 'url1'\n"
"branch: 'branch1'\n"
"path: 'path1'\n"
"registry: 'key1'", e.c_str());
}
TEST_F(GameSettings, YamlEncode) {
loot::GameSettings game(loot::GameSettings::tes5, "folder1");
game.SetName("name1")
.SetMaster("master1")
.SetRegistryKey("key1")
.SetRepoURL("url1")
.SetRepoBranch("branch1")
.SetGamePath("path1");
TEST_F(GameSettingsTest, YamlEncode) {
GameSettings game(GameSettings::tes5, "folder1");
game.SetName("name1")
.SetMaster("master1")
.SetRegistryKey("key1")
.SetRepoURL("url1")
.SetRepoBranch("branch1")
.SetGamePath("path1");
YAML::Node node;
node = game;
EXPECT_EQ("Skyrim", node["type"].as<std::string>());
EXPECT_EQ("folder1", node["folder"].as<std::string>());
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_EQ("master1", node["master"].as<std::string>());
EXPECT_EQ("url1", node["repo"].as<std::string>());
EXPECT_EQ("branch1", node["branch"].as<std::string>());
EXPECT_EQ("path1", node["path"].as<std::string>());
EXPECT_EQ("key1", node["registry"].as<std::string>());
}
YAML::Node node;
node = game;
EXPECT_EQ("Skyrim", node["type"].as<std::string>());
EXPECT_EQ("folder1", node["folder"].as<std::string>());
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_EQ("master1", node["master"].as<std::string>());
EXPECT_EQ("url1", node["repo"].as<std::string>());
EXPECT_EQ("branch1", node["branch"].as<std::string>());
EXPECT_EQ("path1", node["path"].as<std::string>());
EXPECT_EQ("key1", node["registry"].as<std::string>());
}
TEST_F(GameSettings, YamlDecode) {
YAML::Node node = YAML::Load("type: 'Skyrim'\n"
"folder: 'folder1'\n"
"name: 'name1'\n"
"master: 'master1'\n"
"repo: 'url1'\n"
"branch: 'branch1'\n"
"path: 'path1'\n"
"registry: 'key1'");
TEST_F(GameSettingsTest, YamlDecode) {
YAML::Node node = YAML::Load("type: 'Skyrim'\n"
"folder: 'folder1'\n"
"name: 'name1'\n"
"master: 'master1'\n"
"repo: 'url1'\n"
"branch: 'branch1'\n"
"path: 'path1'\n"
"registry: 'key1'");
loot::GameSettings game = node.as<loot::GameSettings>();
EXPECT_EQ(loot::GameSettings::tes5, game.Id());
EXPECT_EQ("name1", game.Name());
EXPECT_EQ("folder1", game.FolderName());
EXPECT_EQ("master1", game.Master());
EXPECT_EQ("key1", game.RegistryKey());
EXPECT_EQ("url1", game.RepoURL());
EXPECT_EQ("branch1", game.RepoBranch());
EXPECT_EQ("path1", game.GamePath());
GameSettings game = node.as<GameSettings>();
EXPECT_EQ(GameSettings::tes5, game.Id());
EXPECT_EQ("name1", game.Name());
EXPECT_EQ("folder1", game.FolderName());
EXPECT_EQ("master1", game.Master());
EXPECT_EQ("key1", game.RegistryKey());
EXPECT_EQ("url1", game.RepoURL());
EXPECT_EQ("branch1", game.RepoBranch());
EXPECT_EQ("path1", game.GamePath());
node = YAML::Load("type: 'Invalid'\n");
EXPECT_ANY_THROW(node.as<loot::GameSettings>());
node = YAML::Load("type: 'Invalid'\n");
EXPECT_ANY_THROW(node.as<GameSettings>());
node = YAML::Load("scalar");
EXPECT_ANY_THROW(node.as<loot::GameSettings>());
node = YAML::Load("scalar");
EXPECT_ANY_THROW(node.as<GameSettings>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<loot::GameSettings>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<GameSettings>());
// Test inheritance of unspecified settings.
node = YAML::Load("type: 'Skyrim'\n"
"folder: 'folder1'\n"
"master: 'master1'\n"
"repo: 'url1'\n"
"branch: 'branch1'\n");
// Test inheritance of unspecified settings.
node = YAML::Load("type: 'Skyrim'\n"
"folder: 'folder1'\n"
"master: 'master1'\n"
"repo: 'url1'\n"
"branch: 'branch1'\n");
game = node.as<loot::GameSettings>();
EXPECT_EQ(loot::GameSettings::tes5, game.Id());
EXPECT_EQ("TES V: Skyrim", game.Name());
EXPECT_EQ("folder1", game.FolderName());
EXPECT_EQ("master1", game.Master());
EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey());
EXPECT_EQ("url1", game.RepoURL());
EXPECT_EQ("branch1", game.RepoBranch());
EXPECT_EQ("", game.GamePath());
game = node.as<GameSettings>();
EXPECT_EQ(GameSettings::tes5, game.Id());
EXPECT_EQ("TES V: Skyrim", game.Name());
EXPECT_EQ("folder1", game.FolderName());
EXPECT_EQ("master1", game.Master());
EXPECT_EQ("Software\\Bethesda Softworks\\Skyrim\\Installed Path", game.RegistryKey());
EXPECT_EQ("url1", game.RepoURL());
EXPECT_EQ("branch1", game.RepoBranch());
EXPECT_EQ("", game.GamePath());
}
}
}
#endif
@@ -30,113 +30,117 @@ along with LOOT. If not, see
#include "tests/fixtures.h"
class LoadOrderHandler : public SkyrimTest {};
namespace loot {
namespace test {
class LoadOrderHandlerTest : public SkyrimTest {};
TEST_F(LoadOrderHandler, Constructors) {
loot::LoadOrderHandler * loh = nullptr;
EXPECT_NO_THROW(loh = new loot::LoadOrderHandler);
EXPECT_NO_THROW(delete loh);
}
TEST_F(LoadOrderHandlerTest, Constructors) {
LoadOrderHandler * loh = nullptr;
EXPECT_NO_THROW(loh = new LoadOrderHandler);
EXPECT_NO_THROW(delete loh);
}
TEST_F(LoadOrderHandler, Init) {
// Should throw for invalid game settings ID.
loot::LoadOrderHandler loh;
loot::GameSettings game(loot::GameSettings::autodetect);
EXPECT_THROW(loh.Init(game), loot::error);
EXPECT_THROW(loh.Init(game), loot::error);
EXPECT_THROW(loh.Init(game, localPath), loot::error);
EXPECT_THROW(loh.Init(game, localPath), loot::error);
TEST_F(LoadOrderHandlerTest, Init) {
// Should throw for invalid game settings ID.
LoadOrderHandler loh;
GameSettings game(GameSettings::autodetect);
EXPECT_THROW(loh.Init(game), error);
EXPECT_THROW(loh.Init(game), error);
EXPECT_THROW(loh.Init(game, localPath), error);
EXPECT_THROW(loh.Init(game, localPath), error);
// Should throw an exception if no game path has been set.
game = loot::GameSettings(loot::GameSettings::tes5);
EXPECT_THROW(loh.Init(game), loot::error);
EXPECT_THROW(loh.Init(game), loot::error);
EXPECT_THROW(loh.Init(game, localPath), loot::error);
EXPECT_THROW(loh.Init(game, localPath), loot::error);
// Should throw an exception if no game path has been set.
game = GameSettings(GameSettings::tes5);
EXPECT_THROW(loh.Init(game), error);
EXPECT_THROW(loh.Init(game), error);
EXPECT_THROW(loh.Init(game, localPath), error);
EXPECT_THROW(loh.Init(game, localPath), error);
#ifndef _WIN32
// Should throw on Linux if no game local app data path is given.
game = loot::GameSettings(loot::GameSettings::tes5)
.SetGamePath(dataPath.parent_path());
EXPECT_THROW(loh.Init(game), loot::error);
game = GameSettings(GameSettings::tes5)
.SetGamePath(dataPath.parent_path());
EXPECT_THROW(loh.Init(game), error);
#endif
game = loot::GameSettings(loot::GameSettings::tes5)
.SetGamePath(dataPath.parent_path());
EXPECT_NO_THROW(loh.Init(game, localPath));
}
game = GameSettings(GameSettings::tes5)
.SetGamePath(dataPath.parent_path());
EXPECT_NO_THROW(loh.Init(game, localPath));
}
TEST_F(LoadOrderHandler, IsPluginActive) {
loot::LoadOrderHandler loh;
loot::GameSettings game(loot::GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
TEST_F(LoadOrderHandlerTest, IsPluginActive) {
LoadOrderHandler loh;
GameSettings game(GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
EXPECT_THROW(loh.IsPluginActive("Skyrim.esm"), loot::error);
EXPECT_THROW(loh.IsPluginActive("Skyrim.esm"), error);
ASSERT_NO_THROW(loh.Init(game, localPath));
ASSERT_NO_THROW(loh.Init(game, localPath));
EXPECT_TRUE(loh.IsPluginActive("Skyrim.esm"));
EXPECT_TRUE(loh.IsPluginActive("Blank.esm"));
EXPECT_TRUE(loh.IsPluginActive("Blank - Different Master Dependent.esp"));
EXPECT_FALSE(loh.IsPluginActive("Blank.esp"));
}
EXPECT_TRUE(loh.IsPluginActive("Skyrim.esm"));
EXPECT_TRUE(loh.IsPluginActive("Blank.esm"));
EXPECT_TRUE(loh.IsPluginActive("Blank - Different Master Dependent.esp"));
EXPECT_FALSE(loh.IsPluginActive("Blank.esp"));
}
TEST_F(LoadOrderHandler, GetLoadOrder) {
loot::LoadOrderHandler loh;
loot::GameSettings game(loot::GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(loh.Init(game, localPath));
TEST_F(LoadOrderHandlerTest, GetLoadOrder) {
LoadOrderHandler loh;
GameSettings game(GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(loh.Init(game, localPath));
std::list<std::string> expected({
"Skyrim.esm",
"Blank.esm",
"Blank - Different.esm",
"Blank - Master Dependent.esm",
"Blank - Different Master Dependent.esm",
"Blank.esp",
"Blank - Different.esp",
"Blank - Master Dependent.esp",
"Blank - Different Master Dependent.esp",
"Blank - Plugin Dependent.esp",
"Blank - Different Plugin Dependent.esp"
});
std::list<std::string> expected({
"Skyrim.esm",
"Blank.esm",
"Blank - Different.esm",
"Blank - Master Dependent.esm",
"Blank - Different Master Dependent.esm",
"Blank.esp",
"Blank - Different.esp",
"Blank - Master Dependent.esp",
"Blank - Different Master Dependent.esp",
"Blank - Plugin Dependent.esp",
"Blank - Different Plugin Dependent.esp"
});
EXPECT_EQ(expected, loh.GetLoadOrder());
}
EXPECT_EQ(expected, loh.GetLoadOrder());
}
TEST_F(LoadOrderHandler, SetLoadOrder) {
loot::LoadOrderHandler loh;
loot::GameSettings game(loot::GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(loh.Init(game, localPath));
TEST_F(LoadOrderHandlerTest, SetLoadOrder) {
LoadOrderHandler loh;
GameSettings game(GameSettings::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(loh.Init(game, localPath));
std::list<std::string> loadOrder({
"Skyrim.esm",
"Blank.esm",
"Blank - Master Dependent.esm",
"Blank - Different.esm",
"Blank - Different Master Dependent.esm",
"Blank - Different.esp",
"Blank - Different Plugin Dependent.esp",
"Blank.esp",
"Blank - Master Dependent.esp",
"Blank - Different Master Dependent.esp",
"Blank - Plugin Dependent.esp",
});
std::list<std::string> loadOrder({
"Skyrim.esm",
"Blank.esm",
"Blank - Master Dependent.esm",
"Blank - Different.esm",
"Blank - Different Master Dependent.esm",
"Blank - Different.esp",
"Blank - Different Plugin Dependent.esp",
"Blank.esp",
"Blank - Master Dependent.esp",
"Blank - Different Master Dependent.esp",
"Blank - Plugin Dependent.esp",
});
EXPECT_NO_THROW(loh.SetLoadOrder(loadOrder));
EXPECT_NO_THROW(loh.SetLoadOrder(loadOrder));
std::list<std::string> actual;
boost::filesystem::ifstream in(localPath / "loadorder.txt");
while (in) {
std::string line;
std::getline(in, line);
std::list<std::string> actual;
boost::filesystem::ifstream in(localPath / "loadorder.txt");
while (in) {
std::string line;
std::getline(in, line);
if (!line.empty())
actual.push_back(line);
if (!line.empty())
actual.push_back(line);
}
EXPECT_EQ(loadOrder, actual);
}
}
EXPECT_EQ(loadOrder, actual);
}
#endif
+94 -92
View File
@@ -29,107 +29,109 @@ along with LOOT. If not, see
#include "backend/helpers/git_helper.h"
#include "tests/fixtures.h"
using loot::GitHelper;
namespace loot {
namespace test {
#ifdef _WIN32
boost::filesystem::path parentRepoRoot = boost::filesystem::current_path().parent_path().parent_path();
boost::filesystem::path parentRepoRoot = boost::filesystem::current_path().parent_path().parent_path();
#else
boost::filesystem::path parentRepoRoot = boost::filesystem::current_path().parent_path();
boost::filesystem::path parentRepoRoot = boost::filesystem::current_path().parent_path();
#endif
TEST(GitHelper, ConstructorAndDestructor) {
GitHelper * git = new GitHelper();
EXPECT_EQ(nullptr, git->repo);
TEST(GitHelper, ConstructorAndDestructor) {
GitHelper * git = new GitHelper();
EXPECT_EQ(nullptr, git->repo);
EXPECT_EQ(2, git_libgit2_init());
delete git;
EXPECT_EQ(0, git_libgit2_shutdown());
}
EXPECT_EQ(2, git_libgit2_init());
delete git;
EXPECT_EQ(0, git_libgit2_shutdown());
}
TEST(GitHelper, Call) {
GitHelper git;
EXPECT_NO_THROW(git.Call(0));
EXPECT_THROW(git.Call(1), loot::error);
EXPECT_THROW(git.Call(-1), loot::error);
}
TEST(GitHelper, Call) {
GitHelper git;
EXPECT_NO_THROW(git.Call(0));
EXPECT_THROW(git.Call(1), error);
EXPECT_THROW(git.Call(-1), error);
}
TEST(GitHelper, SetErrorMessage) {
GitHelper git;
git.SetErrorMessage("test message");
TEST(GitHelper, SetErrorMessage) {
GitHelper git;
git.SetErrorMessage("test message");
try {
git.Call(1);
ADD_FAILURE() << "An exception should have been thrown.";
try {
git.Call(1);
ADD_FAILURE() << "An exception should have been thrown.";
}
catch (error& e) {
EXPECT_NE(nullptr, strstr(e.what(), "test message"));
}
}
TEST(GitHelper, Free) {
// Initialise buffer member, it's simplest to test with.
GitHelper git;
git_buf_set(&git.buf, "foo", 4);
EXPECT_NE(nullptr, git.buf.ptr);
EXPECT_EQ(4, git.buf.size);
git.Free();
EXPECT_EQ(nullptr, git.buf.ptr);
EXPECT_EQ(0, git.buf.size);
}
TEST(GitHelper, IsRepository) {
GitHelper git;
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot));
EXPECT_TRUE(git.IsRepository(parentRepoRoot));
EXPECT_FALSE(git.IsRepository(boost::filesystem::current_path()));
}
class IsFileDifferentTest : public ::testing::Test {
inline virtual void SetUp() {
GitHelper git;
ASSERT_TRUE(git.IsRepository(parentRepoRoot));
ASSERT_FALSE(git.IsRepository(boost::filesystem::current_path()));
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "README.md"));
// Create a backup of CONTRIBUTING.md.
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_FALSE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
ASSERT_NO_THROW(boost::filesystem::copy(parentRepoRoot / "CONTRIBUTING.md", parentRepoRoot / "CONTRIBUTING.md.copy"));
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
// Edit CONTRIBUTING.md
boost::filesystem::ofstream out(parentRepoRoot / "CONTRIBUTING.md");
out.close();
}
inline virtual void TearDown() {
// Restore original CONTRIBUTING.md
ASSERT_NO_THROW(boost::filesystem::remove(parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_NO_THROW(boost::filesystem::rename(parentRepoRoot / "CONTRIBUTING.md.copy", parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_FALSE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
}
};
TEST_F(IsFileDifferentTest, InvalidRepository) {
EXPECT_THROW(IsFileDifferent(boost::filesystem::current_path(), "README.md"), error);
}
TEST_F(IsFileDifferentTest, SameFile) {
EXPECT_FALSE(IsFileDifferent(parentRepoRoot, "README.md"));
}
TEST_F(IsFileDifferentTest, NewFile) {
// New files not in the index are not tracked by Git, so aren't considered
// different.
EXPECT_FALSE(IsFileDifferent(parentRepoRoot, "CONTRIBUTING.md.copy"));
}
TEST_F(IsFileDifferentTest, DifferentFile) {
EXPECT_TRUE(IsFileDifferent(parentRepoRoot, "CONTRIBUTING.md"));
}
}
catch (loot::error& e) {
EXPECT_NE(nullptr, strstr(e.what(), "test message"));
}
}
TEST(GitHelper, Free) {
// Initialise buffer member, it's simplest to test with.
GitHelper git;
git_buf_set(&git.buf, "foo", 4);
EXPECT_NE(nullptr, git.buf.ptr);
EXPECT_EQ(4, git.buf.size);
git.Free();
EXPECT_EQ(nullptr, git.buf.ptr);
EXPECT_EQ(0, git.buf.size);
}
TEST(GitHelper, IsRepository) {
GitHelper git;
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot));
EXPECT_TRUE(git.IsRepository(parentRepoRoot));
EXPECT_FALSE(git.IsRepository(boost::filesystem::current_path()));
}
class IsFileDifferent : public ::testing::Test {
inline virtual void SetUp() {
GitHelper git;
ASSERT_TRUE(git.IsRepository(parentRepoRoot));
ASSERT_FALSE(git.IsRepository(boost::filesystem::current_path()));
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "README.md"));
// Create a backup of CONTRIBUTING.md.
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_FALSE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
ASSERT_NO_THROW(boost::filesystem::copy(parentRepoRoot / "CONTRIBUTING.md", parentRepoRoot / "CONTRIBUTING.md.copy"));
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
// Edit CONTRIBUTING.md
boost::filesystem::ofstream out(parentRepoRoot / "CONTRIBUTING.md");
out.close();
}
inline virtual void TearDown() {
// Restore original CONTRIBUTING.md
ASSERT_NO_THROW(boost::filesystem::remove(parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_NO_THROW(boost::filesystem::rename(parentRepoRoot / "CONTRIBUTING.md.copy", parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md"));
ASSERT_FALSE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
}
};
TEST_F(IsFileDifferent, InvalidRepository) {
EXPECT_THROW(loot::IsFileDifferent(boost::filesystem::current_path(), "README.md"), loot::error);
}
TEST_F(IsFileDifferent, SameFile) {
EXPECT_FALSE(loot::IsFileDifferent(parentRepoRoot, "README.md"));
}
TEST_F(IsFileDifferent, NewFile) {
// New files not in the index are not tracked by Git, so aren't considered
// different.
EXPECT_FALSE(loot::IsFileDifferent(parentRepoRoot, "CONTRIBUTING.md.copy"));
}
TEST_F(IsFileDifferent, DifferentFile) {
EXPECT_TRUE(loot::IsFileDifferent(parentRepoRoot, "CONTRIBUTING.md"));
}
#endif
+14 -10
View File
@@ -29,19 +29,23 @@ along with LOOT. If not, see
#include "backend/error.h"
#include "tests/fixtures.h"
class GetCrc32 : public SkyrimTest {};
namespace loot {
namespace test {
class GetCrc32Test : public SkyrimTest {};
TEST_F(GetCrc32, MissingFile) {
EXPECT_THROW(loot::GetCrc32(dataPath / "Blank.missing.esp"), loot::error);
}
TEST_F(GetCrc32Test, MissingFile) {
EXPECT_THROW(GetCrc32(dataPath / "Blank.missing.esp"), error);
}
TEST_F(GetCrc32, ValidFile) {
EXPECT_EQ(0x24F0E2A1, loot::GetCrc32(dataPath / "Blank.esp"));
}
TEST_F(GetCrc32Test, ValidFile) {
EXPECT_EQ(0x24F0E2A1, GetCrc32(dataPath / "Blank.esp"));
}
TEST(IntToHexString, PositiveAndZeroValues) {
EXPECT_EQ("14", loot::IntToHexString(20));
EXPECT_EQ("0", loot::IntToHexString(0));
TEST(IntToHexString, PositiveAndZeroValues) {
EXPECT_EQ("14", IntToHexString(20));
EXPECT_EQ("0", IntToHexString(0));
}
}
}
#endif
+51 -49
View File
@@ -28,61 +28,63 @@ along with LOOT. If not, see
#include "backend/helpers/language.h"
#include "tests/fixtures.h"
using loot::Language;
namespace loot {
namespace test {
TEST(Language, ConstructorsAndDataAccess) {
// Test English code and locale.
Language lang(Language::english);
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
TEST(Language, ConstructorsAndDataAccess) {
// Test English code and locale.
Language lang(Language::english);
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
lang = Language("en");
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
lang = Language("en");
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
// Test code and locale for a couple of other languages, in case English
// is wrongly being used for everything. No point testing all languages,
// because that would just be copying the class code.
lang = Language(Language::polish);
EXPECT_EQ(Language::polish, lang.Code());
EXPECT_EQ("Polski", lang.Name());
EXPECT_EQ("pl", lang.Locale());
// Test code and locale for a couple of other languages, in case English
// is wrongly being used for everything. No point testing all languages,
// because that would just be copying the class code.
lang = Language(Language::polish);
EXPECT_EQ(Language::polish, lang.Code());
EXPECT_EQ("Polski", lang.Name());
EXPECT_EQ("pl", lang.Locale());
lang = Language("de");
EXPECT_EQ(Language::german, lang.Code());
EXPECT_EQ("Deutsch", lang.Name());
EXPECT_EQ("de", lang.Locale());
lang = Language("de");
EXPECT_EQ(Language::german, lang.Code());
EXPECT_EQ("Deutsch", lang.Name());
EXPECT_EQ("de", lang.Locale());
// Test that invalid values get treated as English.
lang = Language(1000);
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
// Test that invalid values get treated as English.
lang = Language(1000);
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
lang = Language("foo");
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
}
lang = Language("foo");
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
}
TEST(Language, Codes) {
// Check that all the expected codes are given.
std::vector<unsigned int> codes = {
Language::english,
Language::spanish,
Language::russian,
Language::french,
Language::chinese,
Language::polish,
Language::brazilian_portuguese,
Language::finnish,
Language::german,
Language::danish,
Language::korean
};
EXPECT_EQ(Language::Codes, codes);
TEST(Language, Codes) {
// Check that all the expected codes are given.
std::vector<unsigned int> codes = {
Language::english,
Language::spanish,
Language::russian,
Language::french,
Language::chinese,
Language::polish,
Language::brazilian_portuguese,
Language::finnish,
Language::german,
Language::danish,
Language::korean
};
EXPECT_EQ(Language::Codes, codes);
}
}
}
#endif
@@ -28,92 +28,96 @@ along with LOOT. If not, see
#include "backend/helpers/yaml_set_helpers.h"
#include "tests/fixtures.h"
TEST(set, YamlEncode) {
YAML::Node node;
std::set<std::string> stringSet({"a", "b", "c"});
node = stringSet;
EXPECT_EQ("a", node[0].as<std::string>());
EXPECT_EQ("b", node[1].as<std::string>());
EXPECT_EQ("c", node[2].as<std::string>());
}
namespace loot {
namespace test {
TEST(set, YamlEncode) {
YAML::Node node;
std::set<std::string> stringSet({"a", "b", "c"});
node = stringSet;
EXPECT_EQ("a", node[0].as<std::string>());
EXPECT_EQ("b", node[1].as<std::string>());
EXPECT_EQ("c", node[2].as<std::string>());
}
TEST(set, YamlDecode) {
YAML::Node node;
std::set<std::string> stringSet;
TEST(set, YamlDecode) {
YAML::Node node;
std::set<std::string> stringSet;
node = YAML::Load("[a, b, c]");
stringSet = node.as<std::set<std::string>>();
EXPECT_EQ(stringSet.begin(), stringSet.find("a"));
EXPECT_EQ(++stringSet.begin(), stringSet.find("b"));
EXPECT_EQ(--stringSet.end(), stringSet.find("c"));
node = YAML::Load("[a, b, c]");
stringSet = node.as<std::set<std::string>>();
EXPECT_EQ(stringSet.begin(), stringSet.find("a"));
EXPECT_EQ(++stringSet.begin(), stringSet.find("b"));
EXPECT_EQ(--stringSet.end(), stringSet.find("c"));
node = YAML::Load("[a, b, c, c]");
EXPECT_ANY_THROW(node.as<std::set<std::string>>());
}
node = YAML::Load("[a, b, c, c]");
EXPECT_ANY_THROW(node.as<std::set<std::string>>());
}
TEST(set, YamlEmitter) {
std::set<std::string> stringSet({"a", "b", "c"});
YAML::Emitter e1;
e1 << stringSet;
EXPECT_STREQ("- a\n- b\n- c", e1.c_str());
}
TEST(set, YamlEmitter) {
std::set<std::string> stringSet({"a", "b", "c"});
YAML::Emitter e1;
e1 << stringSet;
EXPECT_STREQ("- a\n- b\n- c", e1.c_str());
}
bool nodeContains(const std::string& value, const YAML::Node& node) {
for (const auto& element : node) {
if (element.as<std::string>() == value)
return true;
bool nodeContains(const std::string& value, const YAML::Node& node) {
for (const auto& element : node) {
if (element.as<std::string>() == value)
return true;
}
return false;
}
TEST(unordered_set, YamlEncode) {
YAML::Node node;
std::unordered_set<std::string> stringSet({"a", "b", "c"});
node = stringSet;
// Check that the values are all present in the node.
EXPECT_PRED2(nodeContains, "a", node);
EXPECT_PRED2(nodeContains, "b", node);
EXPECT_PRED2(nodeContains, "c", node);
}
TEST(unordered_set, YAMLDecode) {
YAML::Node node;
std::unordered_set<std::string> stringSet;
node = YAML::Load("[a, b, c]");
stringSet = node.as<std::unordered_set<std::string>>();
EXPECT_EQ(1, stringSet.count("a"));
EXPECT_EQ(1, stringSet.count("b"));
EXPECT_EQ(1, stringSet.count("c"));
node = YAML::Load("[a, b, c, c]");
EXPECT_ANY_THROW(node.as<std::unordered_set<std::string>>());
}
bool sequenceOf(const char val1,
const char val2,
const char val3,
const std::string& seq) {
if (seq.substr(0, 2) != "- "
|| seq.substr(3, 3) != "\n- "
|| seq.substr(7, 3) != "\n- ")
return false;
std::list<char> values({val1, val2, val3});
std::list<char> found({seq[2], seq[6], seq[10]});
values.sort();
found.sort();
return values == found;
}
TEST(unordered_set, YamlEmitter) {
std::unordered_set<std::string> stringSet({"a", "b", "c"});
YAML::Emitter e1;
e1 << stringSet;
ASSERT_EQ(11, e1.size());
EXPECT_PRED4(sequenceOf, 'a', 'b', 'c', e1.c_str());
}
}
return false;
}
TEST(unordered_set, YamlEncode) {
YAML::Node node;
std::unordered_set<std::string> stringSet({"a", "b", "c"});
node = stringSet;
// Check that the values are all present in the node.
EXPECT_PRED2(nodeContains, "a", node);
EXPECT_PRED2(nodeContains, "b", node);
EXPECT_PRED2(nodeContains, "c", node);
}
TEST(unordered_set, YAMLDecode) {
YAML::Node node;
std::unordered_set<std::string> stringSet;
node = YAML::Load("[a, b, c]");
stringSet = node.as<std::unordered_set<std::string>>();
EXPECT_EQ(1, stringSet.count("a"));
EXPECT_EQ(1, stringSet.count("b"));
EXPECT_EQ(1, stringSet.count("c"));
node = YAML::Load("[a, b, c, c]");
EXPECT_ANY_THROW(node.as<std::unordered_set<std::string>>());
}
bool sequenceOf(const char val1,
const char val2,
const char val3,
const std::string& seq) {
if (seq.substr(0, 2) != "- "
|| seq.substr(3, 3) != "\n- "
|| seq.substr(7, 3) != "\n- ")
return false;
std::list<char> values({val1, val2, val3});
std::list<char> found({seq[2], seq[6], seq[10]});
values.sort();
found.sort();
return values == found;
}
TEST(unordered_set, YamlEmitter) {
std::unordered_set<std::string> stringSet({"a", "b", "c"});
YAML::Emitter e1;
e1 << stringSet;
ASSERT_EQ(11, e1.size());
EXPECT_PRED4(sequenceOf, 'a', 'b', 'c', e1.c_str());
}
#endif
File diff suppressed because it is too large Load Diff
@@ -29,58 +29,62 @@ along with LOOT. If not, see
#include "backend/metadata/conditional_metadata.h"
#include "tests/fixtures.h"
class ConditionalMetadata : public SkyrimTest {};
namespace loot {
namespace test {
class ConditionalMetadataTest : public SkyrimTest {};
TEST_F(ConditionalMetadata, ConstructorAndDataAccess) {
loot::ConditionalMetadata cm;
EXPECT_EQ("", cm.Condition());
TEST_F(ConditionalMetadataTest, ConstructorAndDataAccess) {
ConditionalMetadata cm;
EXPECT_EQ("", cm.Condition());
cm = loot::ConditionalMetadata("condition");
EXPECT_EQ("condition", cm.Condition());
}
cm = ConditionalMetadata("condition");
EXPECT_EQ("condition", cm.Condition());
}
TEST_F(ConditionalMetadata, IsConditional) {
loot::ConditionalMetadata cm;
EXPECT_FALSE(cm.IsConditional());
TEST_F(ConditionalMetadataTest, IsConditional) {
ConditionalMetadata cm;
EXPECT_FALSE(cm.IsConditional());
cm = loot::ConditionalMetadata("condition");
EXPECT_TRUE(cm.IsConditional());
}
cm = ConditionalMetadata("condition");
EXPECT_TRUE(cm.IsConditional());
}
TEST_F(ConditionalMetadata, EvalCondition) {
loot::Game game(loot::Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
TEST_F(ConditionalMetadataTest, EvalCondition) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
loot::ConditionalMetadata cm;
EXPECT_TRUE(cm.EvalCondition(game));
ConditionalMetadata cm;
EXPECT_TRUE(cm.EvalCondition(game));
cm = loot::ConditionalMetadata("condition");
EXPECT_THROW(cm.EvalCondition(game), loot::error);
cm = ConditionalMetadata("condition");
EXPECT_THROW(cm.EvalCondition(game), error);
cm = loot::ConditionalMetadata("file(\"Blank.esm\")");
EXPECT_TRUE(cm.EvalCondition(game));
cm = ConditionalMetadata("file(\"Blank.esm\")");
EXPECT_TRUE(cm.EvalCondition(game));
cm = loot::ConditionalMetadata("file(\"Blank.missing.esm\")");
EXPECT_FALSE(cm.EvalCondition(game));
}
cm = ConditionalMetadata("file(\"Blank.missing.esm\")");
EXPECT_FALSE(cm.EvalCondition(game));
}
TEST_F(ConditionalMetadata, ParseCondition) {
loot::ConditionalMetadata cm;
EXPECT_NO_THROW(cm.ParseCondition());
TEST_F(ConditionalMetadataTest, ParseCondition) {
ConditionalMetadata cm;
EXPECT_NO_THROW(cm.ParseCondition());
cm = loot::ConditionalMetadata("condition");
EXPECT_THROW(cm.ParseCondition(), loot::error);
cm = ConditionalMetadata("condition");
EXPECT_THROW(cm.ParseCondition(), error);
// Check that invalid regex also throws.
cm = loot::ConditionalMetadata("regex(\"RagnvaldBook(Farengar(+Ragnvald)?)?\\.esp\")");
EXPECT_THROW(cm.ParseCondition(), loot::error);
// Check that invalid regex also throws.
cm = ConditionalMetadata("regex(\"RagnvaldBook(Farengar(+Ragnvald)?)?\\.esp\")");
EXPECT_THROW(cm.ParseCondition(), error);
cm = loot::ConditionalMetadata("file(\"Blank.esm\")");
EXPECT_NO_THROW(cm.ParseCondition());
cm = ConditionalMetadata("file(\"Blank.esm\")");
EXPECT_NO_THROW(cm.ParseCondition());
cm = loot::ConditionalMetadata("file(\"Blank.missing.esm\")");
EXPECT_NO_THROW(cm.ParseCondition());
cm = ConditionalMetadata("file(\"Blank.missing.esm\")");
EXPECT_NO_THROW(cm.ParseCondition());
}
}
}
#endif
+121 -119
View File
@@ -28,151 +28,153 @@ along with LOOT. If not, see
#include "backend/metadata/file.h"
#include "tests/fixtures.h"
using loot::File;
namespace loot {
namespace test {
TEST(File, ConstructorsAndDataAccess) {
File file;
EXPECT_EQ("", file.Name());
EXPECT_EQ("", file.DisplayName());
EXPECT_EQ("", file.Condition());
TEST(File, ConstructorsAndDataAccess) {
File file;
EXPECT_EQ("", file.Name());
EXPECT_EQ("", file.DisplayName());
EXPECT_EQ("", file.Condition());
file = File("name");
EXPECT_EQ("name", file.Name());
EXPECT_EQ("name", file.DisplayName());
EXPECT_EQ("", file.Condition());
file = File("name");
EXPECT_EQ("name", file.Name());
EXPECT_EQ("name", file.DisplayName());
EXPECT_EQ("", file.Condition());
file = File("name", "display");
EXPECT_EQ("name", file.Name());
EXPECT_EQ("display", file.DisplayName());
EXPECT_EQ("", file.Condition());
file = File("name", "display");
EXPECT_EQ("name", file.Name());
EXPECT_EQ("display", file.DisplayName());
EXPECT_EQ("", file.Condition());
// Not a valid condition, but not evaluating it in this test.
file = File("name", "display", "condition");
EXPECT_EQ("name", file.Name());
EXPECT_EQ("display", file.DisplayName());
EXPECT_EQ("condition", file.Condition());
}
// Not a valid condition, but not evaluating it in this test.
file = File("name", "display", "condition");
EXPECT_EQ("name", file.Name());
EXPECT_EQ("display", file.DisplayName());
EXPECT_EQ("condition", file.Condition());
}
TEST(File, EqualityOperator) {
File file1, file2;
EXPECT_TRUE(file1 == file2);
TEST(File, EqualityOperator) {
File file1, file2;
EXPECT_TRUE(file1 == file2);
// Not valid conditions, but not evaluating them in this test.
file1 = File("name", "display1", "condition1");
file2 = File("name", "display2", "condition2");
EXPECT_TRUE(file1 == file2);
// Not valid conditions, but not evaluating them in this test.
file1 = File("name", "display1", "condition1");
file2 = File("name", "display2", "condition2");
EXPECT_TRUE(file1 == file2);
file1 = File("name1");
file2 = File("name2");
EXPECT_FALSE(file1 == file2);
}
file1 = File("name1");
file2 = File("name2");
EXPECT_FALSE(file1 == file2);
}
TEST(File, LessThanOperator) {
File file1, file2;
EXPECT_FALSE(file1 < file2);
EXPECT_FALSE(file2 < file1);
TEST(File, LessThanOperator) {
File file1, file2;
EXPECT_FALSE(file1 < file2);
EXPECT_FALSE(file2 < file1);
file1 = File("name", "display1", "condition1");
file2 = File("name", "display2", "condition2");
EXPECT_FALSE(file1 < file2);
EXPECT_FALSE(file2 < file1);
file1 = File("name", "display1", "condition1");
file2 = File("name", "display2", "condition2");
EXPECT_FALSE(file1 < file2);
EXPECT_FALSE(file2 < file1);
file1 = File("name1");
file2 = File("name2");
EXPECT_TRUE(file1 < file2);
EXPECT_FALSE(file2 < file1);
}
file1 = File("name1");
file2 = File("name2");
EXPECT_TRUE(file1 < file2);
EXPECT_FALSE(file2 < file1);
}
TEST(File, YamlEmitter) {
File file("name1", "display1", "condition1");
TEST(File, YamlEmitter) {
File file("name1", "display1", "condition1");
YAML::Emitter e1;
e1 << file;
EXPECT_STREQ("name: 'name1'\ncondition: 'condition1'\ndisplay: 'display1'", e1.c_str());
YAML::Emitter e1;
e1 << file;
EXPECT_STREQ("name: 'name1'\ncondition: 'condition1'\ndisplay: 'display1'", e1.c_str());
file = File("name1");
YAML::Emitter e2;
e2 << file;
EXPECT_STREQ("'name1'", e2.c_str());
file = File("name1");
YAML::Emitter e2;
e2 << file;
EXPECT_STREQ("'name1'", e2.c_str());
file = File("name1", "", "condition1");
YAML::Emitter e3;
e3 << file;
EXPECT_STREQ("name: 'name1'\ncondition: 'condition1'", e3.c_str());
file = File("name1", "", "condition1");
YAML::Emitter e3;
e3 << file;
EXPECT_STREQ("name: 'name1'\ncondition: 'condition1'", e3.c_str());
file = File("name1", "display1");
YAML::Emitter e4;
e4 << file;
EXPECT_STREQ("name: 'name1'\ndisplay: 'display1'", e4.c_str());
file = File("name1", "display1");
YAML::Emitter e4;
e4 << file;
EXPECT_STREQ("name: 'name1'\ndisplay: 'display1'", e4.c_str());
file = File("name1", "name1");
YAML::Emitter e5;
e5 << file;
EXPECT_STREQ("'name1'", e5.c_str());
file = File("name1", "name1");
YAML::Emitter e5;
e5 << file;
EXPECT_STREQ("'name1'", e5.c_str());
file = File("name1", "name1", "condition1");
YAML::Emitter e6;
e6 << file;
EXPECT_STREQ("name: 'name1'\ncondition: 'condition1'", e6.c_str());
}
file = File("name1", "name1", "condition1");
YAML::Emitter e6;
e6 << file;
EXPECT_STREQ("name: 'name1'\ncondition: 'condition1'", e6.c_str());
}
TEST(File, YamlEncode) {
File file("name1", "display1", "condition1");
YAML::Node node;
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_EQ("display1", node["display"].as<std::string>());
EXPECT_EQ("condition1", node["condition"].as<std::string>());
TEST(File, YamlEncode) {
File file("name1", "display1", "condition1");
YAML::Node node;
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_EQ("display1", node["display"].as<std::string>());
EXPECT_EQ("condition1", node["condition"].as<std::string>());
file = File("name1");
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_FALSE(node["display"]);
EXPECT_FALSE(node["condition"]);
file = File("name1");
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_FALSE(node["display"]);
EXPECT_FALSE(node["condition"]);
file = File("name1", "name1");
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_FALSE(node["display"]);
EXPECT_FALSE(node["condition"]);
file = File("name1", "name1");
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_FALSE(node["display"]);
EXPECT_FALSE(node["condition"]);
file = File("name1", "display1");
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_EQ("display1", node["display"].as<std::string>());
EXPECT_FALSE(node["condition"]);
}
file = File("name1", "display1");
node = file;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_EQ("display1", node["display"].as<std::string>());
EXPECT_FALSE(node["condition"]);
}
TEST(File, YamlDecode) {
YAML::Node node = YAML::Load("{name: name1, display: display1, condition: 'file(\"Foo.esp\")'}");
File file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("display1", file.DisplayName());
EXPECT_EQ("file(\"Foo.esp\")", file.Condition());
TEST(File, YamlDecode) {
YAML::Node node = YAML::Load("{name: name1, display: display1, condition: 'file(\"Foo.esp\")'}");
File file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("display1", file.DisplayName());
EXPECT_EQ("file(\"Foo.esp\")", file.Condition());
node = YAML::Load("name1");
file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("name1", file.DisplayName());
EXPECT_EQ("", file.Condition());
node = YAML::Load("name1");
file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("name1", file.DisplayName());
EXPECT_EQ("", file.Condition());
node = YAML::Load("{name: name1, display: display1}");
file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("display1", file.DisplayName());
EXPECT_EQ("", file.Condition());
node = YAML::Load("{name: name1, display: display1}");
file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("display1", file.DisplayName());
EXPECT_EQ("", file.Condition());
node = YAML::Load("{name: name1, condition: 'file(\"Foo.esp\")'}");
file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("name1", file.DisplayName());
EXPECT_EQ("file(\"Foo.esp\")", file.Condition());
node = YAML::Load("{name: name1, condition: 'file(\"Foo.esp\")'}");
file = node.as<File>();
EXPECT_EQ("name1", file.Name());
EXPECT_EQ("name1", file.DisplayName());
EXPECT_EQ("file(\"Foo.esp\")", file.Condition());
node = YAML::Load("{name: name1, condition: invalid}");
EXPECT_THROW(node.as<File>(), YAML::RepresentationException);
node = YAML::Load("{name: name1, condition: invalid}");
EXPECT_THROW(node.as<File>(), YAML::RepresentationException);
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<File>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<File>());
}
}
}
#endif
+77 -75
View File
@@ -28,100 +28,102 @@ along with LOOT. If not, see
#include "backend/metadata/location.h"
#include "tests/fixtures.h"
using loot::Location;
namespace loot {
namespace test {
TEST(Location, ConstructorsAndDataAccess) {
Location loc;
EXPECT_EQ("", loc.URL());
TEST(Location, ConstructorsAndDataAccess) {
Location loc;
EXPECT_EQ("", loc.URL());
loc = Location("http://www.example.com");
EXPECT_EQ("http://www.example.com", loc.URL());
loc = Location("http://www.example.com");
EXPECT_EQ("http://www.example.com", loc.URL());
loc = Location("http://www.example.com", "example");
EXPECT_EQ("http://www.example.com", loc.URL());
EXPECT_EQ("example", loc.Name());
}
loc = Location("http://www.example.com", "example");
EXPECT_EQ("http://www.example.com", loc.URL());
EXPECT_EQ("example", loc.Name());
}
TEST(Location, EqualityOperator) {
Location loc1, loc2;
EXPECT_TRUE(loc1 == loc2);
TEST(Location, EqualityOperator) {
Location loc1, loc2;
EXPECT_TRUE(loc1 == loc2);
loc1 = Location("http://www.example.com");
loc2 = Location("HTTP://WWW.EXAMPLE.COM");
EXPECT_TRUE(loc1 == loc2);
loc1 = Location("http://www.example.com");
loc2 = Location("HTTP://WWW.EXAMPLE.COM");
EXPECT_TRUE(loc1 == loc2);
loc1 = Location("http://www.example.com", "example1");
loc2 = Location("http://www.example.com", "example2");
EXPECT_TRUE(loc1 == loc2);
loc1 = Location("http://www.example.com", "example1");
loc2 = Location("http://www.example.com", "example2");
EXPECT_TRUE(loc1 == loc2);
loc1 = Location("http://www.example1.com");
loc2 = Location("http://www.example2.com");
EXPECT_FALSE(loc1 == loc2);
}
loc1 = Location("http://www.example1.com");
loc2 = Location("http://www.example2.com");
EXPECT_FALSE(loc1 == loc2);
}
TEST(Location, LessThanOperator) {
Location loc1, loc2;
EXPECT_FALSE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
TEST(Location, LessThanOperator) {
Location loc1, loc2;
EXPECT_FALSE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
loc1 = Location("http://www.example.com");
loc2 = Location("HTTP://WWW.EXAMPLE.COM");
EXPECT_FALSE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
loc1 = Location("http://www.example.com");
loc2 = Location("HTTP://WWW.EXAMPLE.COM");
EXPECT_FALSE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
loc1 = Location("http://www.example.com", "example1");
loc2 = Location("http://www.example.com", "example2");
EXPECT_FALSE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
loc1 = Location("http://www.example.com", "example1");
loc2 = Location("http://www.example.com", "example2");
EXPECT_FALSE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
loc1 = Location("http://www.example1.com");
loc2 = Location("http://www.example2.com");
EXPECT_TRUE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
}
loc1 = Location("http://www.example1.com");
loc2 = Location("http://www.example2.com");
EXPECT_TRUE(loc1 < loc2);
EXPECT_FALSE(loc2 < loc1);
}
TEST(Location, YamlEmitter) {
Location loc("http://www.example.com");
YAML::Emitter e1;
e1 << loc;
EXPECT_STREQ("'http://www.example.com'", e1.c_str());
TEST(Location, YamlEmitter) {
Location loc("http://www.example.com");
YAML::Emitter e1;
e1 << loc;
EXPECT_STREQ("'http://www.example.com'", e1.c_str());
loc = Location("http://www.example.com", "example");
YAML::Emitter e2;
e2 << loc;
EXPECT_STREQ("link: 'http://www.example.com'\nname: 'example'", e2.c_str());
}
loc = Location("http://www.example.com", "example");
YAML::Emitter e2;
e2 << loc;
EXPECT_STREQ("link: 'http://www.example.com'\nname: 'example'", e2.c_str());
}
TEST(Location, YamlEncode) {
YAML::Node node;
TEST(Location, YamlEncode) {
YAML::Node node;
Location loc("http://www.example.com");
node = loc;
EXPECT_EQ("http://www.example.com", node["link"].as<std::string>());
EXPECT_FALSE(node["name"]);
Location loc("http://www.example.com");
node = loc;
EXPECT_EQ("http://www.example.com", node["link"].as<std::string>());
EXPECT_FALSE(node["name"]);
loc = Location("http://www.example.com", "example");
node = loc;
EXPECT_EQ("http://www.example.com", node["link"].as<std::string>());
EXPECT_EQ("example", node["name"].as<std::string>());
}
loc = Location("http://www.example.com", "example");
node = loc;
EXPECT_EQ("http://www.example.com", node["link"].as<std::string>());
EXPECT_EQ("example", node["name"].as<std::string>());
}
TEST(Location, YamlDecode) {
YAML::Node node;
Location loc;
TEST(Location, YamlDecode) {
YAML::Node node;
Location loc;
node = YAML::Load("http://www.example.com");
loc = node.as<Location>();
EXPECT_EQ("http://www.example.com", loc.URL());
EXPECT_EQ("", loc.Name());
node = YAML::Load("http://www.example.com");
loc = node.as<Location>();
EXPECT_EQ("http://www.example.com", loc.URL());
EXPECT_EQ("", loc.Name());
node = YAML::Load("{link: http://www.example.com, name: example}");
loc = node.as<Location>();
EXPECT_EQ("http://www.example.com", loc.URL());
EXPECT_EQ("example", loc.Name());
node = YAML::Load("{link: http://www.example.com, name: example}");
loc = node.as<Location>();
EXPECT_EQ("http://www.example.com", loc.URL());
EXPECT_EQ("example", loc.Name());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<Location>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<Location>());
}
}
}
#endif
File diff suppressed because it is too large Load Diff
@@ -28,84 +28,85 @@ along with LOOT. If not, see
#include "backend/metadata/message_content.h"
#include "tests/fixtures.h"
using loot::Language;
using loot::MessageContent;
namespace loot {
namespace test {
TEST(MessageContent, ConstructorsAndDataAccess) {
MessageContent mc;
EXPECT_EQ("", mc.Str());
EXPECT_EQ(Language::english, mc.Language());
TEST(MessageContent, ConstructorsAndDataAccess) {
MessageContent mc;
EXPECT_EQ("", mc.Str());
EXPECT_EQ(Language::english, mc.Language());
mc = MessageContent("content", Language::french);
EXPECT_EQ("content", mc.Str());
EXPECT_EQ(Language::french, mc.Language());
}
mc = MessageContent("content", Language::french);
EXPECT_EQ("content", mc.Str());
EXPECT_EQ(Language::french, mc.Language());
}
TEST(MessageContent, EqualityOperator) {
MessageContent mc1, mc2;
EXPECT_TRUE(mc1 == mc2);
TEST(MessageContent, EqualityOperator) {
MessageContent mc1, mc2;
EXPECT_TRUE(mc1 == mc2);
mc1 = MessageContent("content", Language::french);
mc2 = MessageContent("Content", Language::french);
EXPECT_TRUE(mc1 == mc2);
mc1 = MessageContent("content", Language::french);
mc2 = MessageContent("Content", Language::french);
EXPECT_TRUE(mc1 == mc2);
mc1 = MessageContent("content1", Language::french);
mc2 = MessageContent("content2", Language::french);
EXPECT_FALSE(mc1 == mc2);
mc1 = MessageContent("content1", Language::french);
mc2 = MessageContent("content2", Language::french);
EXPECT_FALSE(mc1 == mc2);
mc1 = MessageContent("content", Language::english);
mc2 = MessageContent("Content", Language::french);
EXPECT_TRUE(mc1 == mc2);
}
mc1 = MessageContent("content", Language::english);
mc2 = MessageContent("Content", Language::french);
EXPECT_TRUE(mc1 == mc2);
}
TEST(MessageContent, LessThanOperator) {
MessageContent mc1, mc2;
EXPECT_FALSE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
TEST(MessageContent, LessThanOperator) {
MessageContent mc1, mc2;
EXPECT_FALSE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
mc1 = MessageContent("content", Language::french);
mc2 = MessageContent("Content", Language::french);
EXPECT_FALSE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
mc1 = MessageContent("content", Language::french);
mc2 = MessageContent("Content", Language::french);
EXPECT_FALSE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
mc1 = MessageContent("content", Language::english);
mc2 = MessageContent("content", Language::french);
EXPECT_FALSE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
mc1 = MessageContent("content", Language::english);
mc2 = MessageContent("content", Language::french);
EXPECT_FALSE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
mc1 = MessageContent("content1", Language::english);
mc2 = MessageContent("content2", Language::english);
EXPECT_TRUE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
}
mc1 = MessageContent("content1", Language::english);
mc2 = MessageContent("content2", Language::english);
EXPECT_TRUE(mc1 < mc2);
EXPECT_FALSE(mc2 < mc1);
}
TEST(MessageContent, YamlEmitter) {
MessageContent mc("content", Language::french);
YAML::Emitter e1;
e1 << mc;
EXPECT_STREQ("lang: fr\nstr: 'content'", e1.c_str());
}
TEST(MessageContent, YamlEmitter) {
MessageContent mc("content", Language::french);
YAML::Emitter e1;
e1 << mc;
EXPECT_STREQ("lang: fr\nstr: 'content'", e1.c_str());
}
TEST(MessageContent, YamlEncode) {
YAML::Node node;
TEST(MessageContent, YamlEncode) {
YAML::Node node;
MessageContent mc("content", Language::french);
node = mc;
EXPECT_EQ("content", node["str"].as<std::string>());
EXPECT_EQ("fr", node["lang"].as<std::string>());
}
MessageContent mc("content", Language::french);
node = mc;
EXPECT_EQ("content", node["str"].as<std::string>());
EXPECT_EQ("fr", node["lang"].as<std::string>());
}
TEST(MessageContent, YamlDecode) {
YAML::Node node = YAML::Load("{str: content, lang: de}");
MessageContent mc = node.as<MessageContent>();
EXPECT_EQ("content", mc.Str());
EXPECT_EQ(Language::german, mc.Language());
TEST(MessageContent, YamlDecode) {
YAML::Node node = YAML::Load("{str: content, lang: de}");
MessageContent mc = node.as<MessageContent>();
EXPECT_EQ("content", mc.Str());
EXPECT_EQ(Language::german, mc.Language());
node = YAML::Load("scalar");
EXPECT_ANY_THROW(node.as<MessageContent>());
node = YAML::Load("scalar");
EXPECT_ANY_THROW(node.as<MessageContent>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<MessageContent>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<MessageContent>());
}
}
}
#endif
@@ -28,212 +28,216 @@ along with LOOT. If not, see
#include "backend/metadata/plugin_dirty_info.h"
#include "tests/fixtures.h"
class PluginDirtyInfo : public SkyrimTest {};
namespace loot {
namespace test {
class PluginDirtyInfoTest : public SkyrimTest {};
TEST_F(PluginDirtyInfo, ConstructorsAndDataAccess) {
loot::PluginDirtyInfo info;
EXPECT_EQ(0, info.CRC());
EXPECT_EQ(0, info.ITMs());
EXPECT_EQ(0, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("", info.CleaningUtility());
TEST_F(PluginDirtyInfoTest, ConstructorsAndDataAccess) {
PluginDirtyInfo info;
EXPECT_EQ(0, info.CRC());
EXPECT_EQ(0, info.ITMs());
EXPECT_EQ(0, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("", info.CleaningUtility());
info = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(10, info.DeletedRefs());
EXPECT_EQ(30, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
}
info = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(10, info.DeletedRefs());
EXPECT_EQ(30, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
}
TEST_F(PluginDirtyInfo, MessageOutput) {
loot::Message message;
TEST_F(PluginDirtyInfoTest, MessageOutput) {
Message message;
message = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records, 10 deleted references and 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records, 10 deleted references and 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 0, 0, 0, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 0, 0, 0, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 0, 10, 30, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 10 deleted references and 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 0, 10, 30, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 10 deleted references and 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 0, 0, 30, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 0, 0, 30, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 0, 10, 0, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 10 deleted references. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 0, 10, 0, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 10 deleted references. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 2, 0, 30, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records and 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 2, 0, 30, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records and 30 deleted navmeshes. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 2, 0, 0, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = PluginDirtyInfo(0x12345678, 2, 0, 0, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records. Clean with cleaner.", message.ChooseContent(Language::any).Str());
message = loot::PluginDirtyInfo(0x12345678, 2, 10, 0, "cleaner").AsMessage();
EXPECT_EQ(loot::Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records and 10 deleted references. Clean with cleaner.", message.ChooseContent(Language::any).Str());
}
message = PluginDirtyInfo(0x12345678, 2, 10, 0, "cleaner").AsMessage();
EXPECT_EQ(Message::warn, message.Type());
EXPECT_EQ("Contains 2 ITM records and 10 deleted references. Clean with cleaner.", message.ChooseContent(Language::any).Str());
}
TEST_F(PluginDirtyInfo, EqualityOperator) {
loot::PluginDirtyInfo info1, info2;
EXPECT_TRUE(info1 == info2);
TEST_F(PluginDirtyInfoTest, EqualityOperator) {
PluginDirtyInfo info1, info2;
EXPECT_TRUE(info1 == info2);
info1 = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner1");
info2 = loot::PluginDirtyInfo(0x12345678, 4, 20, 60, "cleaner2");
EXPECT_TRUE(info1 == info2);
info1 = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner1");
info2 = PluginDirtyInfo(0x12345678, 4, 20, 60, "cleaner2");
EXPECT_TRUE(info1 == info2);
info1 = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
info2 = loot::PluginDirtyInfo(0x87654321, 2, 10, 30, "cleaner");
EXPECT_FALSE(info1 == info2);
}
info1 = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
info2 = PluginDirtyInfo(0x87654321, 2, 10, 30, "cleaner");
EXPECT_FALSE(info1 == info2);
}
TEST_F(PluginDirtyInfo, LessThanOperator) {
loot::PluginDirtyInfo info1, info2;
EXPECT_FALSE(info1 < info2);
EXPECT_FALSE(info2 < info1);
TEST_F(PluginDirtyInfoTest, LessThanOperator) {
PluginDirtyInfo info1, info2;
EXPECT_FALSE(info1 < info2);
EXPECT_FALSE(info2 < info1);
info1 = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner1");
info2 = loot::PluginDirtyInfo(0x12345678, 4, 20, 60, "cleaner2");
EXPECT_FALSE(info1 < info2);
EXPECT_FALSE(info2 < info1);
info1 = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner1");
info2 = PluginDirtyInfo(0x12345678, 4, 20, 60, "cleaner2");
EXPECT_FALSE(info1 < info2);
EXPECT_FALSE(info2 < info1);
info1 = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
info2 = loot::PluginDirtyInfo(0x87654321, 2, 10, 30, "cleaner");
EXPECT_TRUE(info1 < info2);
EXPECT_FALSE(info2 < info1);
}
info1 = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
info2 = PluginDirtyInfo(0x87654321, 2, 10, 30, "cleaner");
EXPECT_TRUE(info1 < info2);
EXPECT_FALSE(info2 < info1);
}
TEST_F(PluginDirtyInfo, EvalConditionTrue) {
loot::Game game(loot::Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
TEST_F(PluginDirtyInfoTest, EvalConditionTrue) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
loot::PluginDirtyInfo dirtyInfo = loot::PluginDirtyInfo(0x24F0E2A1, 2, 10, 30, "cleaner");
EXPECT_TRUE(dirtyInfo.EvalCondition(game, "Blank.esp"));
}
PluginDirtyInfo dirtyInfo = PluginDirtyInfo(0x24F0E2A1, 2, 10, 30, "cleaner");
EXPECT_TRUE(dirtyInfo.EvalCondition(game, "Blank.esp"));
}
TEST_F(PluginDirtyInfo, EvalConditionFalse) {
loot::Game game(loot::Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
TEST_F(PluginDirtyInfoTest, EvalConditionFalse) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
loot::PluginDirtyInfo dirtyInfo;
EXPECT_FALSE(dirtyInfo.EvalCondition(game, ""));
PluginDirtyInfo dirtyInfo;
EXPECT_FALSE(dirtyInfo.EvalCondition(game, ""));
dirtyInfo = loot::PluginDirtyInfo(0xDEADBEEF, 2, 10, 30, "cleaner");
EXPECT_FALSE(dirtyInfo.EvalCondition(game, "Blank.esp"));
}
dirtyInfo = PluginDirtyInfo(0xDEADBEEF, 2, 10, 30, "cleaner");
EXPECT_FALSE(dirtyInfo.EvalCondition(game, "Blank.esp"));
}
TEST_F(PluginDirtyInfo, YamlEmitter) {
loot::PluginDirtyInfo info;
TEST_F(PluginDirtyInfoTest, YamlEmitter) {
PluginDirtyInfo info;
info = loot::PluginDirtyInfo(0x12345678, 0, 0, 0, "cleaner");
YAML::Emitter e1;
e1 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'", e1.c_str());
info = PluginDirtyInfo(0x12345678, 0, 0, 0, "cleaner");
YAML::Emitter e1;
e1 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'", e1.c_str());
info = loot::PluginDirtyInfo(0x12345678, 2, 0, 0, "cleaner");
YAML::Emitter e2;
e2 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'\nitm: 2", e2.c_str());
info = PluginDirtyInfo(0x12345678, 2, 0, 0, "cleaner");
YAML::Emitter e2;
e2 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'\nitm: 2", e2.c_str());
info = loot::PluginDirtyInfo(0x12345678, 2, 10, 0, "cleaner");
YAML::Emitter e3;
e3 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'\nitm: 2\nudr: 10", e3.c_str());
info = PluginDirtyInfo(0x12345678, 2, 10, 0, "cleaner");
YAML::Emitter e3;
e3 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'\nitm: 2\nudr: 10", e3.c_str());
info = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
YAML::Emitter e4;
e4 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'\nitm: 2\nudr: 10\nnav: 30", e4.c_str());
}
info = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
YAML::Emitter e4;
e4 << info;
EXPECT_STREQ("crc: 0x12345678\nutil: 'cleaner'\nitm: 2\nudr: 10\nnav: 30", e4.c_str());
}
TEST_F(PluginDirtyInfo, YamlEncode) {
YAML::Node node;
loot::PluginDirtyInfo info;
TEST_F(PluginDirtyInfoTest, YamlEncode) {
YAML::Node node;
PluginDirtyInfo info;
info = loot::PluginDirtyInfo(0x12345678, 0, 0, 0, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_FALSE(node["itm"]);
EXPECT_FALSE(node["udr"]);
EXPECT_FALSE(node["nav"]);
info = PluginDirtyInfo(0x12345678, 0, 0, 0, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_FALSE(node["itm"]);
EXPECT_FALSE(node["udr"]);
EXPECT_FALSE(node["nav"]);
info = loot::PluginDirtyInfo(0x12345678, 2, 0, 0, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_EQ(2, node["itm"].as<unsigned int>());
EXPECT_FALSE(node["udr"]);
EXPECT_FALSE(node["nav"]);
info = PluginDirtyInfo(0x12345678, 2, 0, 0, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_EQ(2, node["itm"].as<unsigned int>());
EXPECT_FALSE(node["udr"]);
EXPECT_FALSE(node["nav"]);
info = loot::PluginDirtyInfo(0x12345678, 2, 10, 0, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_EQ(2, node["itm"].as<unsigned int>());
EXPECT_EQ(10, node["udr"].as<unsigned int>());
EXPECT_FALSE(node["nav"]);
info = PluginDirtyInfo(0x12345678, 2, 10, 0, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_EQ(2, node["itm"].as<unsigned int>());
EXPECT_EQ(10, node["udr"].as<unsigned int>());
EXPECT_FALSE(node["nav"]);
info = loot::PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_EQ(2, node["itm"].as<unsigned int>());
EXPECT_EQ(10, node["udr"].as<unsigned int>());
EXPECT_EQ(30, node["nav"].as<unsigned int>());
}
info = PluginDirtyInfo(0x12345678, 2, 10, 30, "cleaner");
node = info;
EXPECT_EQ(0x12345678, node["crc"].as<uint32_t>());
EXPECT_EQ("cleaner", node["util"].as<std::string>());
EXPECT_EQ(2, node["itm"].as<unsigned int>());
EXPECT_EQ(10, node["udr"].as<unsigned int>());
EXPECT_EQ(30, node["nav"].as<unsigned int>());
}
TEST_F(PluginDirtyInfo, YamlDecode) {
YAML::Node node;
loot::PluginDirtyInfo info;
TEST_F(PluginDirtyInfoTest, YamlDecode) {
YAML::Node node;
PluginDirtyInfo info;
node = YAML::Load("{crc: 0x12345678, util: cleaner}");
info = node.as<loot::PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(0, info.ITMs());
EXPECT_EQ(0, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner}");
info = node.as<PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(0, info.ITMs());
EXPECT_EQ(0, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner, itm: 2}");
info = node.as<loot::PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(0, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner, itm: 2}");
info = node.as<PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(0, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner, itm: 2, udr: 10}");
info = node.as<loot::PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(10, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner, itm: 2, udr: 10}");
info = node.as<PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(10, info.DeletedRefs());
EXPECT_EQ(0, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner, itm: 2, udr: 10, nav: 30}");
info = node.as<loot::PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(10, info.DeletedRefs());
EXPECT_EQ(30, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("{crc: 0x12345678, util: cleaner, itm: 2, udr: 10, nav: 30}");
info = node.as<PluginDirtyInfo>();
EXPECT_EQ(0x12345678, info.CRC());
EXPECT_EQ(2, info.ITMs());
EXPECT_EQ(10, info.DeletedRefs());
EXPECT_EQ(30, info.DeletedNavmeshes());
EXPECT_EQ("cleaner", info.CleaningUtility());
node = YAML::Load("scalar");
EXPECT_ANY_THROW(node.as<loot::PluginDirtyInfo>());
node = YAML::Load("scalar");
EXPECT_ANY_THROW(node.as<PluginDirtyInfo>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<loot::PluginDirtyInfo>());
node = YAML::Load("[0, 1, 2]");
EXPECT_ANY_THROW(node.as<PluginDirtyInfo>());
}
}
}
#endif
File diff suppressed because it is too large Load Diff
+121 -119
View File
@@ -28,153 +28,155 @@ along with LOOT. If not, see
#include "backend/metadata/tag.h"
#include "tests/fixtures.h"
using loot::Tag;
namespace loot {
namespace test {
TEST(Tag, ConstructorsAndDataAccess) {
Tag tag;
EXPECT_EQ("", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
TEST(Tag, ConstructorsAndDataAccess) {
Tag tag;
EXPECT_EQ("", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
tag = Tag("name");
EXPECT_EQ("name", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
tag = Tag("name");
EXPECT_EQ("name", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
tag = Tag("name", false);
EXPECT_EQ("name", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
tag = Tag("name", false);
EXPECT_EQ("name", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
// Not a valid condition, but not evaluating it in this test.
tag = Tag("name", false, "condition");
EXPECT_EQ("name", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("condition", tag.Condition());
}
// Not a valid condition, but not evaluating it in this test.
tag = Tag("name", false, "condition");
EXPECT_EQ("name", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("condition", tag.Condition());
}
TEST(Tag, EqualityOperator) {
Tag tag1, tag2;
EXPECT_TRUE(tag1 == tag2);
TEST(Tag, EqualityOperator) {
Tag tag1, tag2;
EXPECT_TRUE(tag1 == tag2);
// Not valid conditions, but not evaluating them in this test.
tag1 = Tag("name", true, "condition1");
tag2 = Tag("name", true, "condition2");
EXPECT_TRUE(tag1 == tag2);
// Not valid conditions, but not evaluating them in this test.
tag1 = Tag("name", true, "condition1");
tag2 = Tag("name", true, "condition2");
EXPECT_TRUE(tag1 == tag2);
tag1 = Tag("name");
tag2 = Tag("Name");
EXPECT_TRUE(tag1 == tag2);
tag1 = Tag("name");
tag2 = Tag("Name");
EXPECT_TRUE(tag1 == tag2);
tag1 = Tag("name", true);
tag2 = Tag("name", false);
EXPECT_FALSE(tag1 == tag2);
tag1 = Tag("name", true);
tag2 = Tag("name", false);
EXPECT_FALSE(tag1 == tag2);
tag1 = Tag("name1");
tag2 = Tag("name2");
EXPECT_FALSE(tag1 == tag2);
}
tag1 = Tag("name1");
tag2 = Tag("name2");
EXPECT_FALSE(tag1 == tag2);
}
TEST(Tag, LessThanOperator) {
Tag tag1, tag2;
EXPECT_FALSE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
TEST(Tag, LessThanOperator) {
Tag tag1, tag2;
EXPECT_FALSE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name", true, "condition1");
tag2 = Tag("name", true, "condition2");
EXPECT_FALSE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name", true, "condition1");
tag2 = Tag("name", true, "condition2");
EXPECT_FALSE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name");
tag2 = Tag("Name");
EXPECT_FALSE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name");
tag2 = Tag("Name");
EXPECT_FALSE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name1");
tag2 = Tag("name2");
EXPECT_TRUE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name1");
tag2 = Tag("name2");
EXPECT_TRUE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
tag1 = Tag("name", true);
tag2 = Tag("name", false);
EXPECT_TRUE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
}
tag1 = Tag("name", true);
tag2 = Tag("name", false);
EXPECT_TRUE(tag1 < tag2);
EXPECT_FALSE(tag2 < tag1);
}
TEST(Tag, YamlEmitter) {
Tag tag("name1");
YAML::Emitter e1;
e1 << tag;
EXPECT_STREQ("name1", e1.c_str());
TEST(Tag, YamlEmitter) {
Tag tag("name1");
YAML::Emitter e1;
e1 << tag;
EXPECT_STREQ("name1", e1.c_str());
tag = Tag("name1", false);
YAML::Emitter e2;
e2 << tag;
EXPECT_STREQ("-name1", e2.c_str());
tag = Tag("name1", false);
YAML::Emitter e2;
e2 << tag;
EXPECT_STREQ("-name1", e2.c_str());
tag = Tag("name1", true, "condition1");
YAML::Emitter e3;
e3 << tag;
EXPECT_STREQ("name: name1\ncondition: 'condition1'", e3.c_str());
tag = Tag("name1", true, "condition1");
YAML::Emitter e3;
e3 << tag;
EXPECT_STREQ("name: name1\ncondition: 'condition1'", e3.c_str());
tag = Tag("name1", false, "condition1");
YAML::Emitter e4;
e4 << tag;
EXPECT_STREQ("name: -name1\ncondition: 'condition1'", e4.c_str());
}
tag = Tag("name1", false, "condition1");
YAML::Emitter e4;
e4 << tag;
EXPECT_STREQ("name: -name1\ncondition: 'condition1'", e4.c_str());
}
TEST(Tag, YamlEncode) {
YAML::Node node;
TEST(Tag, YamlEncode) {
YAML::Node node;
Tag tag("name1");
node = tag;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_FALSE(node["condition"]);
Tag tag("name1");
node = tag;
EXPECT_EQ("name1", node["name"].as<std::string>());
EXPECT_FALSE(node["condition"]);
tag = Tag("name1", false);
node = tag;
EXPECT_EQ("-name1", node["name"].as<std::string>());
EXPECT_FALSE(node["condition"]);
tag = Tag("name1", false);
node = tag;
EXPECT_EQ("-name1", node["name"].as<std::string>());
EXPECT_FALSE(node["condition"]);
tag = Tag("name1", false, "condition1");
node = tag;
EXPECT_EQ("-name1", node["name"].as<std::string>());
EXPECT_EQ("condition1", node["condition"].as<std::string>());
}
tag = Tag("name1", false, "condition1");
node = tag;
EXPECT_EQ("-name1", node["name"].as<std::string>());
EXPECT_EQ("condition1", node["condition"].as<std::string>());
}
TEST(Tag, YamlDecode) {
YAML::Node node;
Tag tag;
TEST(Tag, YamlDecode) {
YAML::Node node;
Tag tag;
node = YAML::Load("name1");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
node = YAML::Load("name1");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
node = YAML::Load("-name1");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
node = YAML::Load("-name1");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
node = YAML::Load("{name: -name1}");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
node = YAML::Load("{name: -name1}");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_FALSE(tag.IsAddition());
EXPECT_EQ("", tag.Condition());
node = YAML::Load("{name: name1, condition: 'file(\"Foo.esp\")'}");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("file(\"Foo.esp\")", tag.Condition());
node = YAML::Load("{name: name1, condition: 'file(\"Foo.esp\")'}");
tag = node.as<Tag>();
EXPECT_EQ("name1", tag.Name());
EXPECT_TRUE(tag.IsAddition());
EXPECT_EQ("file(\"Foo.esp\")", tag.Condition());
node = YAML::Load("{name: name1, condition: invalid}");
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
node = YAML::Load("{name: name1, condition: invalid}");
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
node = YAML::Load("[0, 1, 2]");
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
node = YAML::Load("[0, 1, 2]");
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
}
}
}
#endif
+223 -219
View File
@@ -28,227 +28,231 @@ along with LOOT. If not, see
#include "backend/plugin/plugin.h"
#include "tests/fixtures.h"
class Plugin : public SkyrimTest {
protected:
inline virtual void SetUp() {
SkyrimTest::SetUp();
namespace loot {
namespace test {
class PluginTest : public SkyrimTest {
protected:
inline virtual void SetUp() {
SkyrimTest::SetUp();
game = loot::Game(loot::Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
game = Game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
ASSERT_NO_THROW(game.Init(false, localPath));
}
Game game;
};
TEST_F(PluginTest, ConstructorsAndDataAccess) {
Plugin plugin(game, "Blank.esm", true);
EXPECT_EQ("Blank.esm", plugin.Name());
EXPECT_TRUE(plugin.getFormIds().empty());
EXPECT_TRUE(plugin.getMasters().empty());
EXPECT_TRUE(plugin.isMasterFile());
EXPECT_FALSE(plugin.IsEmpty());
EXPECT_EQ("v5.0", plugin.getDescription());
EXPECT_EQ(0, plugin.Crc());
plugin = Plugin(game, "Blank.esm", false);
EXPECT_EQ("Blank.esm", plugin.Name());
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF2),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF3),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF4),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF5),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF6),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF7),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF8),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF9),
}), plugin.getFormIds());
EXPECT_TRUE(plugin.getMasters().empty());
EXPECT_TRUE(plugin.isMasterFile());
EXPECT_FALSE(plugin.IsEmpty());
EXPECT_EQ("v5.0", plugin.getDescription());
EXPECT_EQ(0x187BE342, plugin.Crc());
plugin = Plugin(game, "Blank - Master Dependent.esp", false);
EXPECT_EQ("Blank - Master Dependent.esp", plugin.Name());
EXPECT_FALSE(plugin.IsEmpty());
EXPECT_FALSE(plugin.isMasterFile());
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank - Master Dependent.esp", std::vector<std::string>(), 0xCE9),
libespm::FormId("Blank - Master Dependent.esp", std::vector<std::string>(), 0xCEA),
}), plugin.getFormIds());
EXPECT_EQ(std::vector<std::string>({
"Blank.esm"
}), plugin.getMasters());
EXPECT_EQ("", plugin.getDescription());
EXPECT_EQ(0x832152DC, plugin.Crc());
}
TEST_F(PluginTest, LoadsArchive) {
EXPECT_FALSE(Plugin(game, "Blank - Different.esm", true).LoadsArchive());
EXPECT_FALSE(Plugin(game, "Blank\\.esm", true).LoadsArchive());
EXPECT_TRUE(Plugin(game, "Blank.esm", true).LoadsArchive());
}
TEST_F(PluginTest, IsValid) {
EXPECT_TRUE(Plugin::IsValid("Blank.esm", game));
EXPECT_FALSE(Plugin::IsValid("NotAPlugin.esm", game));
EXPECT_FALSE(Plugin::IsValid("EmptyFile.esm", game));
}
TEST_F(PluginTest, IsActive) {
Plugin plugin(game, "Blank.esm", true);
EXPECT_TRUE(plugin.IsActive());
plugin = Plugin(game, "Blank.esp", true);
EXPECT_FALSE(plugin.IsActive());
}
TEST_F(PluginTest, EqualityOperator) {
Plugin plugin1(game, "Blank.esm", true);
Plugin plugin2(game, "blank.esm", true);
EXPECT_TRUE(plugin1 == plugin2);
EXPECT_TRUE(plugin2 == plugin1);
plugin2 = Plugin(game, "Blank.esp", true);
EXPECT_FALSE(plugin1 == plugin2);
EXPECT_FALSE(plugin2 == plugin1);
plugin2 = Plugin(game, "Blan.\\.esm", true);
EXPECT_TRUE(plugin1 == plugin2);
EXPECT_TRUE(plugin2 == plugin1);
plugin1 = Plugin(game, "Blan.esm", true);
EXPECT_FALSE(plugin1 == plugin2);
EXPECT_FALSE(plugin2 == plugin1);
plugin1 = Plugin(game, "Blan.\\.esm", true);
EXPECT_TRUE(plugin1 == plugin2);
EXPECT_TRUE(plugin2 == plugin1);
plugin1 = Plugin(game, "Blan(k|p).esm", true);
EXPECT_FALSE(plugin1 == plugin2);
EXPECT_FALSE(plugin2 == plugin1);
}
TEST_F(PluginTest, InequalityOperator) {
Plugin plugin1(game, "Blank.esm", true);
Plugin plugin2(game, "blank.esm", true);
EXPECT_FALSE(plugin1 != plugin2);
EXPECT_FALSE(plugin2 != plugin1);
plugin2 = Plugin(game, "Blank.esp", true);
EXPECT_TRUE(plugin1 != plugin2);
EXPECT_TRUE(plugin2 != plugin1);
plugin2 = Plugin(game, "Blan.\\.esm", true);
EXPECT_FALSE(plugin1 != plugin2);
EXPECT_FALSE(plugin2 != plugin1);
plugin1 = Plugin(game, "Blan.esm", true);
EXPECT_TRUE(plugin1 != plugin2);
EXPECT_TRUE(plugin2 != plugin1);
plugin1 = Plugin(game, "Blan.\\.esm", true);
EXPECT_FALSE(plugin1 != plugin2);
EXPECT_FALSE(plugin2 != plugin1);
plugin1 = Plugin(game, "Blan(k|p).esm", true);
EXPECT_TRUE(plugin1 != plugin2);
EXPECT_TRUE(plugin2 != plugin1);
}
TEST_F(PluginTest, DoFormIDsOverlap) {
Plugin plugin1(game, "Blank.esm", true);
Plugin plugin2(game, "blank.esm", true);
EXPECT_FALSE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_FALSE(plugin2.DoFormIDsOverlap(plugin1));
plugin1 = Plugin(game, "Blank.esm", true);
plugin2 = Plugin(game, "Blank - Master Dependent.esm", true);
EXPECT_FALSE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_FALSE(plugin2.DoFormIDsOverlap(plugin1));
plugin1 = Plugin(game, "Blank.esm", false);
plugin2 = Plugin(game, "Blank.esp", false);
EXPECT_FALSE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_FALSE(plugin2.DoFormIDsOverlap(plugin1));
plugin1 = Plugin(game, "Blank.esm", false);
plugin2 = Plugin(game, "Blank - Master Dependent.esm", false);
EXPECT_TRUE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_TRUE(plugin2.DoFormIDsOverlap(plugin1));
}
TEST_F(PluginTest, OverlapFormIDs) {
Plugin plugin1(game, "Blank.esm", true);
Plugin plugin2(game, "blank.esm", true);
EXPECT_TRUE(plugin1.OverlapFormIDs(plugin2).empty());
EXPECT_TRUE(plugin2.OverlapFormIDs(plugin1).empty());
plugin1 = Plugin(game, "Blank.esm", true);
plugin2 = Plugin(game, "Blank - Master Dependent.esm", true);
EXPECT_TRUE(plugin1.OverlapFormIDs(plugin2).empty());
EXPECT_TRUE(plugin2.OverlapFormIDs(plugin1).empty());
plugin1 = Plugin(game, "Blank.esm", false);
plugin2 = Plugin(game, "Blank.esp", false);
EXPECT_TRUE(plugin1.OverlapFormIDs(plugin2).empty());
EXPECT_TRUE(plugin2.OverlapFormIDs(plugin1).empty());
plugin1 = Plugin(game, "Blank.esm", false);
plugin2 = Plugin(game, "Blank - Master Dependent.esm", false);
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF2),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF3),
}), plugin1.OverlapFormIDs(plugin2));
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF2),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF3),
}), plugin2.OverlapFormIDs(plugin1));
}
TEST_F(PluginTest, CheckInstallValidity) {
Plugin plugin(game, "Blank.esm", false);
plugin.Reqs({
File("Blank.missing.esm"),
File("Blank.esp"),
File("Blank - Master Dependent.esm"),
});
plugin.Incs({
File("Blank - Different.esm"),
File("Skyrim.esm"),
});
plugin.DirtyInfo({
PluginDirtyInfo(0x187BE342, 0, 1, 2, "utility1"),
PluginDirtyInfo(0xDEADBEEF, 0, 5, 10, "utility2"),
});
EXPECT_TRUE(plugin.CheckInstallValidity(game));
EXPECT_EQ(std::list<Message>({
Message(Message::error, "This plugin requires \"Blank.missing.esm\" to be installed, but it is missing."),
Message(Message::error, "This plugin is incompatible with \"Skyrim.esm\", but both are present."),
PluginDirtyInfo(0x187BE342, 0, 1, 2, "utility1").AsMessage(),
PluginDirtyInfo(0xDEADBEEF, 0, 5, 10, "utility2").AsMessage(),
}), plugin.Messages());
plugin = Plugin(game, "Blank - Different Master Dependent.esp", false);
EXPECT_FALSE(plugin.CheckInstallValidity(game));
EXPECT_EQ(std::list<Message>({
Message(Message::error, "This plugin requires \"Blank - Different.esm\" to be active, but it is inactive."),
}), plugin.Messages());
plugin = Plugin(game, "Blank - Different Master Dependent.esp", false);
plugin.Tags({Tag("Filter")});
EXPECT_FALSE(plugin.CheckInstallValidity(game));
EXPECT_TRUE(plugin.Messages().empty());
}
}
loot::Game game;
};
TEST_F(Plugin, ConstructorsAndDataAccess) {
loot::Plugin plugin(game, "Blank.esm", true);
EXPECT_EQ("Blank.esm", plugin.Name());
EXPECT_TRUE(plugin.getFormIds().empty());
EXPECT_TRUE(plugin.getMasters().empty());
EXPECT_TRUE(plugin.isMasterFile());
EXPECT_FALSE(plugin.IsEmpty());
EXPECT_EQ("v5.0", plugin.getDescription());
EXPECT_EQ(0, plugin.Crc());
plugin = loot::Plugin(game, "Blank.esm", false);
EXPECT_EQ("Blank.esm", plugin.Name());
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF2),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF3),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF4),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF5),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF6),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF7),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF8),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF9),
}), plugin.getFormIds());
EXPECT_TRUE(plugin.getMasters().empty());
EXPECT_TRUE(plugin.isMasterFile());
EXPECT_FALSE(plugin.IsEmpty());
EXPECT_EQ("v5.0", plugin.getDescription());
EXPECT_EQ(0x187BE342, plugin.Crc());
plugin = loot::Plugin(game, "Blank - Master Dependent.esp", false);
EXPECT_EQ("Blank - Master Dependent.esp", plugin.Name());
EXPECT_FALSE(plugin.IsEmpty());
EXPECT_FALSE(plugin.isMasterFile());
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank - Master Dependent.esp", std::vector<std::string>(), 0xCE9),
libespm::FormId("Blank - Master Dependent.esp", std::vector<std::string>(), 0xCEA),
}), plugin.getFormIds());
EXPECT_EQ(std::vector<std::string>({
"Blank.esm"
}), plugin.getMasters());
EXPECT_EQ("", plugin.getDescription());
EXPECT_EQ(0x832152DC, plugin.Crc());
}
TEST_F(Plugin, LoadsArchive) {
EXPECT_FALSE(loot::Plugin(game, "Blank - Different.esm", true).LoadsArchive());
EXPECT_FALSE(loot::Plugin(game, "Blank\\.esm", true).LoadsArchive());
EXPECT_TRUE(loot::Plugin(game, "Blank.esm", true).LoadsArchive());
}
TEST_F(Plugin, IsValid) {
EXPECT_TRUE(loot::Plugin::IsValid("Blank.esm", game));
EXPECT_FALSE(loot::Plugin::IsValid("NotAPlugin.esm", game));
EXPECT_FALSE(loot::Plugin::IsValid("EmptyFile.esm", game));
}
TEST_F(Plugin, IsActive) {
loot::Plugin plugin(game, "Blank.esm", true);
EXPECT_TRUE(plugin.IsActive());
plugin = loot::Plugin(game, "Blank.esp", true);
EXPECT_FALSE(plugin.IsActive());
}
TEST_F(Plugin, EqualityOperator) {
loot::Plugin plugin1(game, "Blank.esm", true);
loot::Plugin plugin2(game, "blank.esm", true);
EXPECT_TRUE(plugin1 == plugin2);
EXPECT_TRUE(plugin2 == plugin1);
plugin2 = loot::Plugin(game, "Blank.esp", true);
EXPECT_FALSE(plugin1 == plugin2);
EXPECT_FALSE(plugin2 == plugin1);
plugin2 = loot::Plugin(game, "Blan.\\.esm", true);
EXPECT_TRUE(plugin1 == plugin2);
EXPECT_TRUE(plugin2 == plugin1);
plugin1 = loot::Plugin(game, "Blan.esm", true);
EXPECT_FALSE(plugin1 == plugin2);
EXPECT_FALSE(plugin2 == plugin1);
plugin1 = loot::Plugin(game, "Blan.\\.esm", true);
EXPECT_TRUE(plugin1 == plugin2);
EXPECT_TRUE(plugin2 == plugin1);
plugin1 = loot::Plugin(game, "Blan(k|p).esm", true);
EXPECT_FALSE(plugin1 == plugin2);
EXPECT_FALSE(plugin2 == plugin1);
}
TEST_F(Plugin, InequalityOperator) {
loot::Plugin plugin1(game, "Blank.esm", true);
loot::Plugin plugin2(game, "blank.esm", true);
EXPECT_FALSE(plugin1 != plugin2);
EXPECT_FALSE(plugin2 != plugin1);
plugin2 = loot::Plugin(game, "Blank.esp", true);
EXPECT_TRUE(plugin1 != plugin2);
EXPECT_TRUE(plugin2 != plugin1);
plugin2 = loot::Plugin(game, "Blan.\\.esm", true);
EXPECT_FALSE(plugin1 != plugin2);
EXPECT_FALSE(plugin2 != plugin1);
plugin1 = loot::Plugin(game, "Blan.esm", true);
EXPECT_TRUE(plugin1 != plugin2);
EXPECT_TRUE(plugin2 != plugin1);
plugin1 = loot::Plugin(game, "Blan.\\.esm", true);
EXPECT_FALSE(plugin1 != plugin2);
EXPECT_FALSE(plugin2 != plugin1);
plugin1 = loot::Plugin(game, "Blan(k|p).esm", true);
EXPECT_TRUE(plugin1 != plugin2);
EXPECT_TRUE(plugin2 != plugin1);
}
TEST_F(Plugin, DoFormIDsOverlap) {
loot::Plugin plugin1(game, "Blank.esm", true);
loot::Plugin plugin2(game, "blank.esm", true);
EXPECT_FALSE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_FALSE(plugin2.DoFormIDsOverlap(plugin1));
plugin1 = loot::Plugin(game, "Blank.esm", true);
plugin2 = loot::Plugin(game, "Blank - Master Dependent.esm", true);
EXPECT_FALSE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_FALSE(plugin2.DoFormIDsOverlap(plugin1));
plugin1 = loot::Plugin(game, "Blank.esm", false);
plugin2 = loot::Plugin(game, "Blank.esp", false);
EXPECT_FALSE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_FALSE(plugin2.DoFormIDsOverlap(plugin1));
plugin1 = loot::Plugin(game, "Blank.esm", false);
plugin2 = loot::Plugin(game, "Blank - Master Dependent.esm", false);
EXPECT_TRUE(plugin1.DoFormIDsOverlap(plugin2));
EXPECT_TRUE(plugin2.DoFormIDsOverlap(plugin1));
}
TEST_F(Plugin, OverlapFormIDs) {
loot::Plugin plugin1(game, "Blank.esm", true);
loot::Plugin plugin2(game, "blank.esm", true);
EXPECT_TRUE(plugin1.OverlapFormIDs(plugin2).empty());
EXPECT_TRUE(plugin2.OverlapFormIDs(plugin1).empty());
plugin1 = loot::Plugin(game, "Blank.esm", true);
plugin2 = loot::Plugin(game, "Blank - Master Dependent.esm", true);
EXPECT_TRUE(plugin1.OverlapFormIDs(plugin2).empty());
EXPECT_TRUE(plugin2.OverlapFormIDs(plugin1).empty());
plugin1 = loot::Plugin(game, "Blank.esm", false);
plugin2 = loot::Plugin(game, "Blank.esp", false);
EXPECT_TRUE(plugin1.OverlapFormIDs(plugin2).empty());
EXPECT_TRUE(plugin2.OverlapFormIDs(plugin1).empty());
plugin1 = loot::Plugin(game, "Blank.esm", false);
plugin2 = loot::Plugin(game, "Blank - Master Dependent.esm", false);
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF2),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF3),
}), plugin1.OverlapFormIDs(plugin2));
EXPECT_EQ(std::set<libespm::FormId>({
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF0),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF1),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF2),
libespm::FormId("Blank.esm", std::vector<std::string>(), 0xCF3),
}), plugin2.OverlapFormIDs(plugin1));
}
TEST_F(Plugin, CheckInstallValidity) {
loot::Plugin plugin(game, "Blank.esm", false);
plugin.Reqs({
loot::File("Blank.missing.esm"),
loot::File("Blank.esp"),
loot::File("Blank - Master Dependent.esm"),
});
plugin.Incs({
loot::File("Blank - Different.esm"),
loot::File("Skyrim.esm"),
});
plugin.DirtyInfo({
loot::PluginDirtyInfo(0x187BE342, 0, 1, 2, "utility1"),
loot::PluginDirtyInfo(0xDEADBEEF, 0, 5, 10, "utility2"),
});
EXPECT_TRUE(plugin.CheckInstallValidity(game));
EXPECT_EQ(std::list<loot::Message>({
loot::Message(loot::Message::error, "This plugin requires \"Blank.missing.esm\" to be installed, but it is missing."),
loot::Message(loot::Message::error, "This plugin is incompatible with \"Skyrim.esm\", but both are present."),
loot::PluginDirtyInfo(0x187BE342, 0, 1, 2, "utility1").AsMessage(),
loot::PluginDirtyInfo(0xDEADBEEF, 0, 5, 10, "utility2").AsMessage(),
}), plugin.Messages());
plugin = loot::Plugin(game, "Blank - Different Master Dependent.esp", false);
EXPECT_FALSE(plugin.CheckInstallValidity(game));
EXPECT_EQ(std::list<loot::Message>({
loot::Message(loot::Message::error, "This plugin requires \"Blank - Different.esm\" to be active, but it is inactive."),
}), plugin.Messages());
plugin = loot::Plugin(game, "Blank - Different Master Dependent.esp", false);
plugin.Tags({loot::Tag("Filter")});
EXPECT_FALSE(plugin.CheckInstallValidity(game));
EXPECT_TRUE(plugin.Messages().empty());
}
#endif
+103 -99
View File
@@ -28,125 +28,129 @@ along with LOOT. If not, see
#include "backend/masterlist.h"
#include "tests/fixtures.h"
class Masterlist : public SkyrimTest {};
namespace loot {
namespace test {
class MasterlistTest : public SkyrimTest {};
TEST_F(Masterlist, Update_Game) {
loot::Game game(loot::Game::tes5);
game.SetGamePath(dataPath.parent_path());
game.SetRepoURL("https://github.com/loot/testing-metadata.git");
game.SetRepoBranch("master");
ASSERT_NO_THROW(game.Init(false, localPath));
TEST_F(MasterlistTest, Update_Game) {
Game game(Game::tes5);
game.SetGamePath(dataPath.parent_path());
game.SetRepoURL("https://github.com/loot/testing-metadata.git");
game.SetRepoBranch("master");
ASSERT_NO_THROW(game.Init(false, localPath));
// This may fail on Windows if a 'real' LOOT install is also present.
loot::Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(game));
EXPECT_TRUE(boost::filesystem::exists(game.MasterlistPath()));
// This may fail on Windows if a 'real' LOOT install is also present.
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(game));
EXPECT_TRUE(boost::filesystem::exists(game.MasterlistPath()));
EXPECT_FALSE(masterlist.Update(game));
EXPECT_TRUE(boost::filesystem::exists(game.MasterlistPath()));
}
EXPECT_FALSE(masterlist.Update(game));
EXPECT_TRUE(boost::filesystem::exists(game.MasterlistPath()));
}
TEST_F(Masterlist, Update_NonGame_InvalidPath) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(";//\?",
"https://github.com/loot/testing-metadata.git",
"master"));
}
TEST_F(MasterlistTest, Update_NonGame_InvalidPath) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(";//\?",
"https://github.com/loot/testing-metadata.git",
"master"));
}
TEST_F(Masterlist, Update_NonGame_EmptyPath) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update("",
"https://github.com/loot/testing-metadata.git",
"master"));
}
TEST_F(MasterlistTest, Update_NonGame_EmptyPath) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update("",
"https://github.com/loot/testing-metadata.git",
"master"));
}
TEST_F(Masterlist, Update_NonGame_InvalidBranch) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"missing-branch"));
}
TEST_F(MasterlistTest, Update_NonGame_InvalidBranch) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"missing-branch"));
}
TEST_F(Masterlist, Update_NonGame_EmptyBranch) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
""));
}
TEST_F(MasterlistTest, Update_NonGame_EmptyBranch) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
""));
}
TEST_F(Masterlist, Update_NonGame_InvalidUrl) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"https://github.com/loot/does-not-exist.git",
"master"));
}
TEST_F(MasterlistTest, Update_NonGame_InvalidUrl) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"https://github.com/loot/does-not-exist.git",
"master"));
}
TEST_F(Masterlist, Update_NonGame_EmptyUrl) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"",
"master"));
}
TEST_F(MasterlistTest, Update_NonGame_EmptyUrl) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.Update(masterlistPath,
"",
"master"));
}
TEST_F(Masterlist, Update_NonGame) {
loot::Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
TEST_F(MasterlistTest, Update_NonGame) {
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
EXPECT_FALSE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
}
EXPECT_FALSE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
}
TEST_F(Masterlist, GetInfo_NoMasterlist) {
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.GetInfo(masterlistPath, false));
}
TEST_F(MasterlistTest, GetInfo_NoMasterlist) {
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.GetInfo(masterlistPath, false));
}
TEST_F(Masterlist, GetInfo_NoRepository) {
ASSERT_NO_THROW(boost::filesystem::copy("./testing-metadata/masterlist.yaml", masterlistPath));
TEST_F(MasterlistTest, GetInfo_NoRepository) {
ASSERT_NO_THROW(boost::filesystem::copy("./testing-metadata/masterlist.yaml", masterlistPath));
loot::Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.GetInfo(masterlistPath, false));
}
Masterlist masterlist;
EXPECT_ANY_THROW(masterlist.GetInfo(masterlistPath, false));
}
TEST_F(Masterlist, GetInfo_LongID) {
loot::Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
TEST_F(MasterlistTest, GetInfo_LongID) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
loot::Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(40, info.revision.length());
EXPECT_EQ(10, info.date.length());
}
Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(40, info.revision.length());
EXPECT_EQ(10, info.date.length());
}
TEST_F(Masterlist, GetInfo_ShortID) {
loot::Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
TEST_F(MasterlistTest, GetInfo_ShortID) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
loot::Masterlist::Info info = masterlist.GetInfo(masterlistPath, true);
EXPECT_GE((unsigned)40, info.revision.length());
EXPECT_LE((unsigned)7, info.revision.length());
EXPECT_EQ(10, info.date.length());
}
Masterlist::Info info = masterlist.GetInfo(masterlistPath, true);
EXPECT_GE((unsigned)40, info.revision.length());
EXPECT_LE((unsigned)7, info.revision.length());
EXPECT_EQ(10, info.date.length());
}
TEST_F(Masterlist, GetInfo_Edited) {
loot::Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
boost::filesystem::ofstream out(masterlistPath);
out.close();
TEST_F(MasterlistTest, GetInfo_Edited) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
boost::filesystem::ofstream out(masterlistPath);
out.close();
loot::Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(49, info.revision.length());
EXPECT_EQ(" (edited)", info.revision.substr(40));
EXPECT_EQ(19, info.date.length());
EXPECT_EQ(" (edited)", info.date.substr(10));
Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(49, info.revision.length());
EXPECT_EQ(" (edited)", info.revision.substr(40));
EXPECT_EQ(19, info.date.length());
EXPECT_EQ(" (edited)", info.date.substr(10));
}
}
}
#endif

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