Skip to content

Commit

Permalink
#5927: Fixup unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 1, 2022
1 parent b98a5e8 commit 69a0475
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
28 changes: 19 additions & 9 deletions test/ColourSchemes.cpp
Expand Up @@ -6,6 +6,7 @@
#include "os/path.h"
#include "string/convert.h"
#include "xmlutil/Document.h"
#include "settings/SettingsManager.h"

namespace test
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<std::string> readOnlySchemes = {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions test/Favourites.cpp
Expand Up @@ -2,6 +2,7 @@

#include "ifavourites.h"
#include "iregistry.h"
#include "settings/SettingsManager.h"

namespace test
{
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion test/Settings.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 69a0475

Please sign in to comment.