From 69a04751f4051e1ac38d0e6bd5b45e135b2591bc Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 1 Apr 2022 16:23:53 +0200 Subject: [PATCH] #5927: Fixup unit tests --- test/ColourSchemes.cpp | 28 +++++++++++++++++++--------- test/Favourites.cpp | 7 +++++-- test/Settings.cpp | 4 +++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/test/ColourSchemes.cpp b/test/ColourSchemes.cpp index f3cd76343c..05b5960e91 100644 --- a/test/ColourSchemes.cpp +++ b/test/ColourSchemes.cpp @@ -6,6 +6,7 @@ #include "os/path.h" #include "string/convert.h" #include "xmlutil/Document.h" +#include "settings/SettingsManager.h" namespace test { @@ -29,7 +30,8 @@ class ColourSchemeTest : schemeFilePath /= "settings/"; schemeFilePath /= schemeFile; - fs::path targetFile = _context.getSettingsPath(); + settings::SettingsManager manager(_context); + fs::path targetFile = manager.getCurrentVersionSettingsFolder(); targetFile /= "colours.xml"; fs::remove(targetFile); @@ -71,7 +73,8 @@ class ColourSchemeTestWithEmptySettings : void preStartup() override { // Kill any colours.xml file present in the settings folder before regular SetUp - fs::path coloursFile = _context.getSettingsPath(); + settings::SettingsManager manager(_context); + fs::path coloursFile = manager.getCurrentVersionSettingsFolder(); coloursFile /= "colours.xml"; fs::remove(coloursFile); @@ -182,7 +185,8 @@ TEST_F(ColourSchemeTestWithEmptySettings, ActiveSchemePersisted) GlobalRegistry().saveToDisk(); // Check the XML files if the active flag was set - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; xml::Document doc(savedColoursFile); @@ -216,7 +220,8 @@ TEST_F(ColourSchemeTestWithEmptySettings, SystemThemeColourChangePersisted) GlobalRegistry().saveToDisk(); // Check the XML files if the colour was set - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; auto savedScheme = loadSchemeFromXml(SCHEME_DARKRADIANT_DEFAULT, savedColoursFile); @@ -237,7 +242,8 @@ TEST_F(ColourSchemeTestWithEmptySettings, CopiedSchemePersisted) GlobalRegistry().saveToDisk(); // Check the XML files if the colour was set - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; auto savedCopiedScheme = loadSchemeFromXml(newSchemeName, savedColoursFile); @@ -276,7 +282,8 @@ TEST_F(ColourSchemeTestWithIncompleteScheme, SchemeUpgrade) GlobalColourSchemeManager().saveColourSchemes(); GlobalRegistry().saveToDisk(); - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; auto savedScheme = loadSchemeFromXml(SCHEME_SUPER_MAL, savedColoursFile); @@ -331,7 +338,8 @@ TEST_F(ColourSchemeTestWithUserColours, SavedUserSchemesAreNotReadOnly) GlobalColourSchemeManager().saveColourSchemes(); GlobalRegistry().saveToDisk(); - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; std::set readOnlySchemes = { @@ -369,7 +377,8 @@ TEST_F(ColourSchemeTestWithUserColours, ColourChangePersisted) GlobalRegistry().saveToDisk(); // Check the XML files if the colour was set - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; auto savedDefaultScheme = loadSchemeFromXml(SCHEME_DARKRADIANT_DEFAULT, savedColoursFile); @@ -391,7 +400,8 @@ TEST_F(ColourSchemeTestWithUserColours, DeleteUserTheme) GlobalRegistry().saveToDisk(); // Check the XML files if the scheme was actually removed - std::string savedColoursFile = _context.getSettingsPath() + "colours.xml"; + settings::SettingsManager manager(_context); + std::string savedColoursFile = manager.getCurrentVersionSettingsFolder() + "colours.xml"; EXPECT_TRUE(fs::exists(savedColoursFile)) << "Could not find saved colours file: " << savedColoursFile; xml::Document doc(savedColoursFile); diff --git a/test/Favourites.cpp b/test/Favourites.cpp index 0690cabcf0..2fd5488805 100644 --- a/test/Favourites.cpp +++ b/test/Favourites.cpp @@ -2,6 +2,7 @@ #include "ifavourites.h" #include "iregistry.h" +#include "settings/SettingsManager.h" namespace test { @@ -19,7 +20,8 @@ class FavouritesTest : sourcePath /= "settings/"; sourcePath /= userXmlFile; - fs::path targetPath = _context.getSettingsPath(); + settings::SettingsManager manager(_context); + fs::path targetPath = manager.getCurrentVersionSettingsFolder(); targetPath /= "user.xml"; fs::remove(targetPath); @@ -157,7 +159,8 @@ TEST_F(FavouritesTest, FavouritesArePersisted) checkAfterShutdown = [&]() { - fs::path userXml = _context.getSettingsPath(); + settings::SettingsManager manager(_context); + fs::path userXml = manager.getCurrentVersionSettingsFolder(); userXml /= "user.xml"; xml::Document doc(userXml.string()); diff --git a/test/Settings.cpp b/test/Settings.cpp index 786d3b7107..c1c5563c9e 100644 --- a/test/Settings.cpp +++ b/test/Settings.cpp @@ -46,7 +46,9 @@ TEST(MajorMinorVersionTest, ParseFromString) // Invalid expressions EXPECT_THROW(settings::MajorMinorVersion("11.a100.1"), std::invalid_argument); - EXPECT_THROW(settings::MajorMinorVersion("11.1"), std::invalid_argument); + EXPECT_THROW(settings::MajorMinorVersion("11"), std::invalid_argument); + EXPECT_THROW(settings::MajorMinorVersion("11..6"), std::invalid_argument); + EXPECT_THROW(settings::MajorMinorVersion("11.a"), std::invalid_argument); EXPECT_THROW(settings::MajorMinorVersion("x.y"), std::invalid_argument); EXPECT_THROW(settings::MajorMinorVersion("2_3_7"), std::invalid_argument); EXPECT_THROW(settings::MajorMinorVersion("10.8.9-"), std::invalid_argument);