Skip to content

Commit

Permalink
vkconfig3: Add more configuration manager tests and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Jan 16, 2025
1 parent 5c65190 commit b94e4fb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 33 deletions.
10 changes: 0 additions & 10 deletions vkconfig_core/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,6 @@ void ConfigurationManager::RemoveConfiguration(const std::string &configuration_
this->SortConfigurations();
}

int ConfigurationManager::GetConfigurationIndex(const std::string &configuration_name) const {
for (std::size_t i = 0, n = this->available_configurations.size(); i < n; ++i) {
if (this->available_configurations[i].key == configuration_name) {
return static_cast<int>(i);
}
}

return -1;
}

Configuration *ConfigurationManager::FindConfiguration(const std::string &configuration_name) {
if (configuration_name.empty()) {
return nullptr;
Expand Down
5 changes: 3 additions & 2 deletions vkconfig_core/configuration_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ConfigurationManager : public Serialize {
Configuration& CreateConfiguration(const LayerManager& layers, const std::string& configuration_name);
Configuration& DuplicateConfiguration(const LayerManager& layers, const std::string& configuration_name);
void RemoveConfiguration(const std::string& configuration_name);
int GetConfigurationIndex(const std::string& configuration_name) const;

void RenameConfiguration(const std::string& old_configuration_name, const std::string& new_configuration_name);
bool ImportConfiguration(const LayerManager& layers, const Path& full_import_path, std::string& configuration_name);
Expand All @@ -74,9 +73,11 @@ class ConfigurationManager : public Serialize {
Path last_path_export_config = Get(Path::HOME);
Path last_path_export_settings = Get(Path::HOME) + "/vK_layer_settings.txt";

// Public for unit tests...
void LoadDefaultConfigurations(const LayerManager& layers);

private:
void LoadConfigurationsPath(const LayerManager& layers);
void LoadDefaultConfigurations(const LayerManager& layers);

std::map<std::string, int> removed_built_in_configuration;
};
3 changes: 3 additions & 0 deletions vkconfig_core/test/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@

<qresource prefix="/configurations">
<file alias="API dump.json">../configurations/3.0.0/API dump.json</file>
<file alias="Crash Diagnostic.json">../configurations/3.0.0/Crash Diagnostic.json</file>
<file alias="Disable All Vulkan Layers.json">../configurations/3.0.0/Disable All Vulkan Layers.json</file>
<file alias="Frame Capture.json">../configurations/3.0.0/Frame Capture.json</file>
<file alias="Log Loader Messages.json">../configurations/3.0.0/Log Loader Messages.json</file>
<file alias="Portability.json">../configurations/3.0.0/Portability.json</file>
<file alias="Synchronization.json">../configurations/3.0.0/Synchronization.json</file>
<file alias="Validation.json">../configurations/3.0.0/Validation.json</file>
Expand Down
18 changes: 18 additions & 0 deletions vkconfig_core/test/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,21 @@ TEST(test_configuration, Reorder_empty) {

EXPECT_EQ(configuration.parameters.size(), size);
}

TEST(test_configuration, IsDefault_True) {
LayerManager layers;
layers.LoadLayersFromPath(":/layers");

Configuration configuration;
const bool loaded = configuration.Load(":/configurations/Validation.json", layers);
EXPECT_TRUE(loaded);
EXPECT_TRUE(configuration.IsDefault());
}

TEST(test_configuration, IsDefault_False) {
LayerManager layers;
layers.LoadLayersFromPath(":/layers");

Configuration configuration = Configuration::Create(layers, "New Configuration");
EXPECT_FALSE(configuration.IsDefault());
}
91 changes: 71 additions & 20 deletions vkconfig_core/test/test_configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,84 @@ TEST(test_configuration_manager, sort) {
EXPECT_STREQ("Configuration B", configuration_manager.available_configurations[4].key.c_str());
}

TEST(test_configuration_manager, get_index) {
TEST(test_configuration_manager, default_configuration) {
LayerManager layer_manager;
layer_manager.LoadLayersFromPath(":/layers");

ConfigurationManager configuration_manager;
configuration_manager.LoadDefaultConfigurations(layer_manager);

configuration_manager.CreateConfiguration(layer_manager, "Configuration B");
EXPECT_EQ(1, configuration_manager.available_configurations.size());
EXPECT_EQ(0, configuration_manager.GetConfigurationIndex("Configuration B"));
EXPECT_EQ(configuration_manager.IsDefaultConfiguration("Validation"), true);
EXPECT_EQ(configuration_manager.IsDefaultConfiguration("Unknown"), false);
}

configuration_manager.CreateConfiguration(layer_manager, "Configuration A");
EXPECT_EQ(2, configuration_manager.available_configurations.size());
EXPECT_EQ(0, configuration_manager.GetConfigurationIndex("Configuration A"));
EXPECT_EQ(1, configuration_manager.GetConfigurationIndex("Configuration B"));
TEST(test_configuration_manager, RenameConfiguration) {
LayerManager layer_manager;
layer_manager.LoadLayersFromPath(":/layers");

configuration_manager.CreateConfiguration(layer_manager, "Configuration C");
EXPECT_EQ(3, configuration_manager.available_configurations.size());
EXPECT_EQ(0, configuration_manager.GetConfigurationIndex("Configuration A"));
EXPECT_EQ(1, configuration_manager.GetConfigurationIndex("Configuration B"));
EXPECT_EQ(2, configuration_manager.GetConfigurationIndex("Configuration C"));
ConfigurationManager configuration_manager;
configuration_manager.LoadDefaultConfigurations(layer_manager);

std::string configuration_a2_key = configuration_manager.CreateConfiguration(layer_manager, "Configuration A").key;
EXPECT_EQ(4, configuration_manager.available_configurations.size());
EXPECT_EQ(0, configuration_manager.GetConfigurationIndex("Configuration A"));
EXPECT_EQ(1, configuration_manager.GetConfigurationIndex("Configuration A (2)"));
EXPECT_EQ(2, configuration_manager.GetConfigurationIndex("Configuration B"));
EXPECT_EQ(3, configuration_manager.GetConfigurationIndex("Configuration C"));
const Configuration* configuration1 = configuration_manager.FindConfiguration("Validation");
EXPECT_TRUE(configuration1 != nullptr);

configuration_manager.RenameConfiguration("Validation", "ValidationAHKJDGKJ");
const Configuration* configuration2 = configuration_manager.FindConfiguration("Validation");
EXPECT_TRUE(configuration2 == nullptr);

const Configuration* configuration3 = configuration_manager.FindConfiguration("ValidationAHKJDGKJ");
EXPECT_TRUE(configuration3 != nullptr);
EXPECT_FALSE(configuration_manager.HasFile(*configuration3));

configuration_manager.RenameConfiguration("ValidationAHKJDGKJ", "Validation");
const Configuration* configuration4 = configuration_manager.FindConfiguration("Validation");
EXPECT_TRUE(configuration4 != nullptr);
}

TEST(test_configuration_manager, SaveConfiguration) {
LayerManager layer_manager;
layer_manager.LoadLayersFromPath(":/layers");

ConfigurationManager configuration_manager;
EXPECT_TRUE(configuration_manager.Empty());

configuration_manager.LoadDefaultConfigurations(layer_manager);
EXPECT_FALSE(configuration_manager.Empty());

configuration_manager.RenameConfiguration("Validation", "ValidationAHKJDGKJ");

std::vector<Configuration> available_configurations;
for (std::size_t i = 0, n = configuration_manager.available_configurations.size(); i < n; ++i) {
if (configuration_manager.available_configurations[i].key != "ValidationAHKJDGKJ") {
continue;
}
available_configurations.push_back(configuration_manager.available_configurations[i]);
}
std::swap(configuration_manager.available_configurations, available_configurations);

const Configuration* configuration = configuration_manager.FindConfiguration("ValidationAHKJDGKJ");
EXPECT_FALSE(configuration_manager.HasFile(*configuration));

configuration_manager.SaveAllConfigurations();
EXPECT_TRUE(configuration_manager.HasFile(*configuration));

configuration_manager.RemoveConfiguration("ValidationAHKJDGKJ");
}

TEST(test_configuration_manager, ExportImport) {
LayerManager layer_manager;
layer_manager.LoadLayersFromPath(":/layers");

ConfigurationManager configuration_manager;
configuration_manager.LoadDefaultConfigurations(layer_manager);
std::size_t count_init = configuration_manager.available_configurations.size();

configuration_manager.ExportConfiguration(layer_manager, Get(Path::HOME) + "ValidationExported.json", "Validation");

std::string configuration_name;
configuration_manager.ImportConfiguration(layer_manager, Get(Path::HOME) + "ValidationExported.json", configuration_name);
EXPECT_EQ(count_init + 1, configuration_manager.available_configurations.size());

EXPECT_EQ(-1, configuration_manager.GetConfigurationIndex("Configuration D"));
const Configuration* configuration = configuration_manager.FindConfiguration("Validation (Imported)");
EXPECT_TRUE(configuration != nullptr);
}
2 changes: 1 addition & 1 deletion vkconfig_core/test/test_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ TEST(test_path, get_path_home_sdk) {
TEST(test_path, collect_file_paths_success_set1) {
const std::vector<Path>& paths = CollectFilePaths(":/configurations/");

EXPECT_EQ(paths.size(), 5);
EXPECT_EQ(paths.size(), 8);
EXPECT_STREQ(Path(":/configurations/API dump.json").AbsolutePath().c_str(), paths[0].AbsolutePath().c_str());
}

Expand Down

0 comments on commit b94e4fb

Please sign in to comment.