Implemented PluginSorter class tests.

This commit is contained in:
Oliver Hamlet
2015-07-13 16:47:15 +01:00
parent e33e6981d4
commit fd9400091b
+159 -2
View File
@@ -28,10 +28,167 @@ along with LOOT. If not, see
#include "backend/plugin_sorter.h"
#include "tests/fixtures.h"
class PluginSorter : public SkyrimTest {};
class PluginSorter : 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));
callback = [](const std::string&) {};
}
loot::Game game;
std::function<void(const std::string&)> callback;
};
TEST_F(PluginSorter, Sort_NoPlugins) {
loot::PluginSorter ps;
std::list<loot::Plugin> sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_TRUE(sorted.empty());
}
TEST_F(PluginSorter, Sort) {
FAIL() << "Test is unimplemented";
ASSERT_NO_THROW(game.LoadPlugins(false));
loot::PluginSorter ps;
std::list<loot::Plugin> sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_EQ(std::list<loot::Plugin>({
loot::Plugin("Skyrim.esm"),
loot::Plugin("Blank.esm"),
loot::Plugin("Blank - Different.esm"),
loot::Plugin("Blank - Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esm"),
loot::Plugin("Blank.esp"),
loot::Plugin("Blank - Different.esp"),
loot::Plugin("Blank - Master Dependent.esp"),
loot::Plugin("Blank - Different Master Dependent.esp"),
loot::Plugin("Blank - Plugin Dependent.esp"),
loot::Plugin("Blank - Different Plugin Dependent.esp"),
}), sorted);
// Check stability.
sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_EQ(std::list<loot::Plugin>({
loot::Plugin("Skyrim.esm"),
loot::Plugin("Blank.esm"),
loot::Plugin("Blank - Different.esm"),
loot::Plugin("Blank - Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esm"),
loot::Plugin("Blank.esp"),
loot::Plugin("Blank - Different.esp"),
loot::Plugin("Blank - Master Dependent.esp"),
loot::Plugin("Blank - Different Master Dependent.esp"),
loot::Plugin("Blank - Plugin Dependent.esp"),
loot::Plugin("Blank - Different Plugin Dependent.esp"),
}), sorted);
}
TEST_F(PluginSorter, Sort_HeadersOnly) {
ASSERT_NO_THROW(game.LoadPlugins(true));
loot::PluginSorter ps;
std::list<loot::Plugin> sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_EQ(std::list<loot::Plugin>({
loot::Plugin("Skyrim.esm"),
loot::Plugin("Blank.esm"),
loot::Plugin("Blank - Different.esm"),
loot::Plugin("Blank - Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esm"),
loot::Plugin("Blank.esp"),
loot::Plugin("Blank - Different.esp"),
loot::Plugin("Blank - Master Dependent.esp"),
loot::Plugin("Blank - Different Master Dependent.esp"),
loot::Plugin("Blank - Plugin Dependent.esp"),
loot::Plugin("Blank - Different Plugin Dependent.esp"),
}), sorted);
}
TEST_F(PluginSorter, Sort_WithPriority) {
ASSERT_NO_THROW(game.LoadPlugins(false));
loot::Plugin plugin("Blank - Different Master Dependent.esp");
plugin.Priority(-1100000);
game.userlist.AddPlugin(plugin);
loot::PluginSorter ps;
std::list<loot::Plugin> sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_EQ(std::list<loot::Plugin>({
loot::Plugin("Skyrim.esm"),
loot::Plugin("Blank.esm"),
loot::Plugin("Blank - Different.esm"),
loot::Plugin("Blank - Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esp"),
loot::Plugin("Blank.esp"),
loot::Plugin("Blank - Different.esp"),
loot::Plugin("Blank - Master Dependent.esp"),
loot::Plugin("Blank - Plugin Dependent.esp"),
loot::Plugin("Blank - Different Plugin Dependent.esp"),
}), sorted);
}
TEST_F(PluginSorter, Sort_WithLoadAfter) {
ASSERT_NO_THROW(game.LoadPlugins(false));
loot::Plugin plugin("Blank.esp");
plugin.LoadAfter({
loot::File("Blank - Different.esp"),
loot::File("Blank - Different Plugin Dependent.esp"),
});
game.userlist.AddPlugin(plugin);
loot::PluginSorter ps;
std::list<loot::Plugin> sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_EQ(std::list<loot::Plugin>({
loot::Plugin("Skyrim.esm"),
loot::Plugin("Blank.esm"),
loot::Plugin("Blank - Different.esm"),
loot::Plugin("Blank - Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esm"),
loot::Plugin("Blank - Different.esp"),
loot::Plugin("Blank - Master Dependent.esp"),
loot::Plugin("Blank - Different Master Dependent.esp"),
loot::Plugin("Blank - Different Plugin Dependent.esp"),
loot::Plugin("Blank.esp"),
loot::Plugin("Blank - Plugin Dependent.esp"),
}), sorted);
}
TEST_F(PluginSorter, Sort_WithRequirements) {
ASSERT_NO_THROW(game.LoadPlugins(false));
loot::Plugin plugin("Blank.esp");
plugin.Reqs({
loot::File("Blank - Different.esp"),
loot::File("Blank - Different Plugin Dependent.esp"),
});
game.userlist.AddPlugin(plugin);
loot::PluginSorter ps;
std::list<loot::Plugin> sorted = ps.Sort(game, loot::Language::english, callback);
EXPECT_EQ(std::list<loot::Plugin>({
loot::Plugin("Skyrim.esm"),
loot::Plugin("Blank.esm"),
loot::Plugin("Blank - Different.esm"),
loot::Plugin("Blank - Master Dependent.esm"),
loot::Plugin("Blank - Different Master Dependent.esm"),
loot::Plugin("Blank - Different.esp"),
loot::Plugin("Blank - Master Dependent.esp"),
loot::Plugin("Blank - Different Master Dependent.esp"),
loot::Plugin("Blank - Different Plugin Dependent.esp"),
loot::Plugin("Blank.esp"),
loot::Plugin("Blank - Plugin Dependent.esp"),
}), sorted);
}
TEST_F(PluginSorter, Sort_HasCycle) {
ASSERT_NO_THROW(game.LoadPlugins(false));
loot::Plugin plugin("Blank.esm");
plugin.LoadAfter({loot::File("Blank - Master Dependent.esm")});
game.userlist.AddPlugin(plugin);
loot::PluginSorter ps;
EXPECT_ANY_THROW(ps.Sort(game, loot::Language::english, callback));
}
#endif