Skip to content

Commit

Permalink
#5927: Implement SettingsManager constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 1, 2022
1 parent c9e2cb2 commit 9190754
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 12 additions & 3 deletions libs/settings/SettingsManager.h
Expand Up @@ -5,6 +5,8 @@
#include "imodule.h"

#include "MajorMinorVersion.h"
#include "os/dir.h"
#include "os/path.h"

namespace settings
{
Expand Down Expand Up @@ -34,10 +36,17 @@ class SettingsManager
SettingsManager(const IApplicationContext& context, const std::string& currentVersion) :
_context(context),
_currentVersion(currentVersion)
{}
{
// Set up the path to the current version
_currentVersionSettingsFolder = os::standardPathWithSlash(context.getSettingsPath() + _currentVersion.toString());

// Make sure the output folder exists
os::makeDirectory(_currentVersionSettingsFolder);
}

// Returns the output path where all settings files for the current version can be saved to.
// This is usually the same as IApplicationContext::getSettingsPath()/"major.minor"/
// Returns the output path (including trailing slash) where all settings files
// for the current version can be saved to.
// Matches the pattern IApplicationContext::getSettingsPath()/"major.minor"/
const std::string& getCurrentVersionSettingsFolder() const
{
return _currentVersionSettingsFolder;
Expand Down
12 changes: 6 additions & 6 deletions test/Settings.cpp
Expand Up @@ -151,22 +151,22 @@ namespace

void testSettingsPathCreation(const IApplicationContext& context, const std::string& versionString)
{
// Set up a manager and check if it created the settings output folder
auto manager = versionString.empty() ?
std::make_unique<settings::SettingsManager>(context) :
std::make_unique<settings::SettingsManager>(context, versionString);

settings::MajorMinorVersion version(versionString.empty() ? RADIANT_VERSION : versionString);

auto expectedFolder = os::standardPathWithSlash(context.getSettingsPath() + version.toString());

// Let's assume the folder doesn't exist yet
EXPECT_FALSE(fs::is_directory(expectedFolder)) << "The output path " << expectedFolder << " already exists";

// Set up a manager and check if it created the settings output folder
auto manager = versionString.empty() ?
std::make_unique<settings::SettingsManager>(context) :
std::make_unique<settings::SettingsManager>(context, versionString);

EXPECT_EQ(manager->getCurrentVersionSettingsFolder(), expectedFolder) << "Output folder is not what we expected";
EXPECT_TRUE(fs::is_directory(expectedFolder)) << "Manager should have created the path " << expectedFolder;

fs::remove_all(expectedFolder);
os::removeDirectory(expectedFolder);
}

}
Expand Down

0 comments on commit 9190754

Please sign in to comment.