From 83bd4248cd770037ee9da699c2649618b155bacb Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 19 Jan 2016 21:24:15 +0000 Subject: [PATCH] Clear game messages when sorting Game messages should be cleared if sorting is successful. --- src/backend/plugin_sorter.cpp | 5 +++++ src/tests/backend/test_plugin_sorter.h | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/backend/plugin_sorter.cpp b/src/backend/plugin_sorter.cpp index a0eaa484..954fc01e 100644 --- a/src/backend/plugin_sorter.cpp +++ b/src/backend/plugin_sorter.cpp @@ -152,6 +152,11 @@ namespace loot { BOOST_LOG_TRIVIAL(info) << '\t' << graph[vertex].Name(); plugins.push_back(graph[vertex]); } + + // Clear any existing game-specific messages, as these only relate to + // state that has been changed by sorting. + game.ClearMessages(); + return plugins; } diff --git a/src/tests/backend/test_plugin_sorter.h b/src/tests/backend/test_plugin_sorter.h index a8d8a772..e988b43a 100644 --- a/src/tests/backend/test_plugin_sorter.h +++ b/src/tests/backend/test_plugin_sorter.h @@ -91,6 +91,29 @@ TEST_F(PluginSorter, Sort) { EXPECT_TRUE(std::equal(begin(sorted), end(sorted), begin(expectedSortedOrder))); } +TEST_F(PluginSorter, sortingShouldClearExistingGameMessages) { + ASSERT_NO_THROW(game.LoadPlugins(false)); + game.AppendMessage(loot::Message(loot::Message::say, "1")); + ASSERT_FALSE(game.GetMessages().empty()); + + loot::PluginSorter ps; + std::list sorted = ps.Sort(game, loot::Language::english, callback); + EXPECT_TRUE(game.GetMessages().empty()); +} + +TEST_F(PluginSorter, failedSortShouldNotClearExistingGameMessages) { + ASSERT_NO_THROW(game.LoadPlugins(false)); + loot::PluginMetadata plugin("Blank.esm"); + plugin.LoadAfter({loot::File("Blank - Master Dependent.esm")}); + game.GetUserlist().AddPlugin(plugin); + game.AppendMessage(loot::Message(loot::Message::say, "1")); + ASSERT_FALSE(game.GetMessages().empty()); + + loot::PluginSorter ps; + EXPECT_ANY_THROW(ps.Sort(game, loot::Language::english, callback)); + EXPECT_FALSE(game.GetMessages().empty()); +} + TEST_F(PluginSorter, Sort_HeadersOnly) { ASSERT_NO_THROW(game.LoadPlugins(true));