Skip to content

Commit

Permalink
vkconfig3: Add tests for setting presets
Browse files Browse the repository at this point in the history
Change-Id: I83f0e642531ebd3c88c0bfaf96db7c87ae30e385
  • Loading branch information
christophe-lunarg committed Dec 16, 2024
1 parent cd0913b commit aa41e92
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vkconfig_core/test/layers/VK_LAYER_LUNARG_test_04.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"settings": [
{
"key": "int_required_only",
"value": 75
"value": 76
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion vkconfig_core/test/layers/VK_LAYER_LUNARG_test_07.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"type": "INT",
"label": "Integer",
"description": "Integer Description",
"default": 82
"default": 75
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/test/test_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

#include <regex>

inline SettingMetaString* InstantiateString(Layer& layer, const std::string& key) {
static SettingMetaString* InstantiateString(Layer& layer, const std::string& key) {
return static_cast<SettingMetaString*>(layer.Instantiate(layer.settings, key, SETTING_STRING));
}

std::map<Path, std::string> Dummy() { return std::map<Path, std::string>(); }
static std::map<Path, std::string> Dummy() { return std::map<Path, std::string>(); }

TEST(test_layer, collect_settings) {
Layer layer;
Expand Down
64 changes: 63 additions & 1 deletion vkconfig_core/test/test_layer_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
#include "../layer.h"
#include "../layer_preset.h"
#include "../setting_string.h"
#include "../setting_int.h"
#include "../util.h"

#include <gtest/gtest.h>

inline SettingMetaString* InstantiateString(Layer& layer, const std::string& key) {
static std::map<Path, std::string> Dummy() { return std::map<Path, std::string>(); }

static SettingMetaString* InstantiateString(Layer& layer, const std::string& key) {
return static_cast<SettingMetaString*>(layer.Instantiate(layer.settings, key, SETTING_STRING));
}

Expand Down Expand Up @@ -61,3 +64,62 @@ TEST(test_layer_preset, has_preset) {
preset_settings.push_back(presetC);
EXPECT_EQ(false, HasPreset(layer_settings, preset_settings));
}

TEST(test_layer_preset, find_preset_index_no_preset) {
Layer layer;
const LayerLoadStatus load_loaded = layer.Load(":/layers/VK_LAYER_LUNARG_test_03.json", LAYER_TYPE_EXPLICIT, false, Dummy());
EXPECT_EQ(load_loaded, LAYER_LOAD_ADDED);

SettingDataSet layer_settings;
::CollectDefaultSettingData(layer.settings, layer_settings);

int index = layer.FindPresetIndex(layer_settings);
EXPECT_EQ(index, Layer::NO_PRESET);
}

TEST(test_layer_preset, find_preset_index_empty) {
Layer layer;
const LayerLoadStatus load_loaded = layer.Load(":/layers/VK_LAYER_LUNARG_test_04.json", LAYER_TYPE_EXPLICIT, false, Dummy());
EXPECT_EQ(load_loaded, LAYER_LOAD_ADDED);

SettingDataSet layer_settings;
int index = layer.FindPresetIndex(layer_settings);
EXPECT_EQ(index, Layer::NO_PRESET);
}

TEST(test_layer_preset, find_preset_index_found) {
Layer layer;
const LayerLoadStatus load_loaded = layer.Load(":/layers/VK_LAYER_LUNARG_test_04.json", LAYER_TYPE_EXPLICIT, false, Dummy());
EXPECT_EQ(load_loaded, LAYER_LOAD_ADDED);

SettingDataSet layer_settings;
::CollectDefaultSettingData(layer.settings, layer_settings);
SettingDataInt& setting = static_cast<SettingDataInt&>(*layer_settings[0]);

int indexDefault = layer.FindPresetIndex(layer_settings);
EXPECT_EQ(indexDefault, Layer::NO_PRESET);

setting.value = 75;
int index75 = layer.FindPresetIndex(layer_settings);
EXPECT_EQ(index75, 0);

setting.value = 76;
int index76 = layer.FindPresetIndex(layer_settings);
EXPECT_EQ(index76, 1);

setting.value = 99;
int index99 = layer.FindPresetIndex(layer_settings);
EXPECT_EQ(index99, Layer::NO_PRESET);
}

TEST(test_layer_preset, find_preset_index_missing_value) {
Layer layer;
const LayerLoadStatus load_loaded = layer.Load(":/layers/VK_LAYER_LUNARG_test_07.json", LAYER_TYPE_EXPLICIT, false, Dummy());
EXPECT_EQ(load_loaded, LAYER_LOAD_ADDED);

SettingDataSet layer_settings;
::CollectDefaultSettingData(layer.settings, layer_settings);

int index = layer.FindPresetIndex(layer_settings); // missing preset values are ignored
EXPECT_EQ(index, 0);
}

0 comments on commit aa41e92

Please sign in to comment.