Skip to content

Commit

Permalink
#5430: Add test cases covering GlobalColourSchemeManager().foreachSch…
Browse files Browse the repository at this point in the history
…eme()
  • Loading branch information
codereader committed Nov 23, 2020
1 parent b99b128 commit 26b41da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 1 addition & 2 deletions include/icolourscheme.h
Expand Up @@ -64,11 +64,10 @@ class IColourSchemeManager :
// greebo: Returns the named colour, returns <0,0,0> if not found
virtual Vector3 getColour(const std::string& colourName) = 0;

virtual void saveScheme(const std::string& name) = 0;
virtual void deleteScheme(const std::string& name) = 0;
virtual void copyScheme(const std::string& fromName, const std::string& toName) = 0;

// Loads/Saves all the schemes from the registry
// Loads/Saves all the schemes from/to the registry
virtual void loadColourSchemes() = 0;
virtual void saveColourSchemes() = 0;

Expand Down
6 changes: 4 additions & 2 deletions radiantcore/settings/ColourSchemeManager.h
Expand Up @@ -28,7 +28,7 @@ class ColourSchemeManager :
void setActive(const std::string& name) override;

// Returns the requested colour from the currently active scheme
Vector3 getColour(const std::string& colourName);
Vector3 getColour(const std::string& colourName);

ColourScheme& getActiveScheme() override;
ColourScheme& getColourScheme(const std::string& name) override;
Expand All @@ -38,7 +38,6 @@ class ColourSchemeManager :
void saveColourSchemes();

// Saves the specified scheme into the registry
void saveScheme(const std::string& name) override;
void deleteScheme(const std::string& name) override;
void copyScheme(const std::string& fromName, const std::string& toName) override;

Expand All @@ -49,6 +48,9 @@ class ColourSchemeManager :
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
void shutdownModule() override;

private:
void saveScheme(const std::string& name);
};

} // namespace
26 changes: 26 additions & 0 deletions test/ColourSchemes.cpp
Expand Up @@ -438,4 +438,30 @@ TEST_F(ColourSchemeTestWithUserColours, RestoreChangedColourFromRegistry)
EXPECT_NE(GlobalColourSchemeManager().getColourScheme(SCHEME_DARKRADIANT_DEFAULT).getColour("default_brush").getColour(), newValue);
}

TEST_F(ColourSchemeTestWithUserColours, ForeachScheme)
{
// Use a vector to record visited nodes to catch duplicate names
std::vector<std::string> visitedSchemes;
GlobalColourSchemeManager().foreachScheme([&](const std::string& name, colours::IColourScheme&)
{
visitedSchemes.push_back(name);
});

std::set<std::string> expectedSchemeNames = {
SCHEME_DARKRADIANT_DEFAULT,
SCHEME_QE3,
SCHEME_BLACK_AND_GREEN,
SCHEME_MAYA_MAX,
SCHEME_SUPER_MAL,
"MyMaya" // custom theme
};

EXPECT_EQ(expectedSchemeNames.size(), visitedSchemes.size());

for (auto expectedScheme : expectedSchemeNames)
{
EXPECT_EQ(std::count(visitedSchemes.begin(), visitedSchemes.end(), expectedScheme), 1);
}
}

}

0 comments on commit 26b41da

Please sign in to comment.