From 540f5f775ea8ac3cf58f5a0219bedbf3ce5ddb50 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 23 Dec 2024 21:32:32 +0100 Subject: [PATCH] vkconfig3: Add mode unit tests --- vkconfig_core/executable.cpp | 8 ++++++-- vkconfig_core/executable_manager.cpp | 4 ++-- vkconfig_core/test/test_executable.cpp | 26 ++++++++++++++++++++++++ vkconfig_core/test/test_layer_preset.cpp | 6 +++--- vkconfig_core/test/test_parameter.cpp | 10 +-------- vkconfig_gui/settings_tree.cpp | 1 - 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/vkconfig_core/executable.cpp b/vkconfig_core/executable.cpp index 5a77d71da1..606b8438d8 100644 --- a/vkconfig_core/executable.cpp +++ b/vkconfig_core/executable.cpp @@ -152,7 +152,7 @@ DefaultPath GetDefaultExecutablePath(const std::string& executable_key) { Executable::Executable() {} Executable::Executable(const DefaultExecutable& default_executable) { - const DefaultPath& default_paths = GetDefaultExecutablePath(default_executable.key); + const DefaultPath& default_paths = ::GetDefaultExecutablePath(default_executable.key); if (default_paths.executable_path.Empty()) { Executable(); // application could not be found.. } @@ -228,7 +228,11 @@ bool Executable::HasActiveOptions() const { Path Executable::GetLocalLayersSettingsPath() const { assert(this->GetActiveOptions() != nullptr); - return this->GetActiveOptions()->working_folder + "/vk_layer_settings.txt"; + if (this->GetActiveOptions()->working_folder.Empty()) { + return this->path.AbsoluteDir() + "/vk_layer_settings.txt"; + } else { + return this->GetActiveOptions()->working_folder + "/vk_layer_settings.txt"; + } } void Executable::AddOptions(const ExecutableOptions& options) { diff --git a/vkconfig_core/executable_manager.cpp b/vkconfig_core/executable_manager.cpp index daedf1f1ae..e82c6d35ef 100644 --- a/vkconfig_core/executable_manager.cpp +++ b/vkconfig_core/executable_manager.cpp @@ -312,8 +312,8 @@ Executable* ExecutableManager::GetExecutable(std::size_t executable_index) { std::vector ExecutableManager::CreateDefaultExecutables() const { std::vector new_executables; - for (std::size_t name_index = 0, name_count = std::size(defaults_executables); name_index < name_count; ++name_index) { - const Executable executable(defaults_executables[name_index]); + for (std::size_t name_index = 0, name_count = std::size(::defaults_executables); name_index < name_count; ++name_index) { + const Executable executable(::defaults_executables[name_index]); if (executable.path.Empty()) { continue; diff --git a/vkconfig_core/test/test_executable.cpp b/vkconfig_core/test/test_executable.cpp index 7db61840a1..32cdd007aa 100644 --- a/vkconfig_core/test/test_executable.cpp +++ b/vkconfig_core/test/test_executable.cpp @@ -107,6 +107,8 @@ TEST(test_executable, add) { ExecutableOptions executable_options; executable_options.label = "Pouet Options"; + executable_options.working_folder = + "."; // set it otherwise GetLocalLayersSettingsPath will use the executable absolute directory executable.AddOptions(executable_options); EXPECT_EQ(2, executable.GetOptions().size()); @@ -114,4 +116,28 @@ TEST(test_executable, add) { executable.SetActiveOptions("Pouet Options"); EXPECT_STREQ("Pouet Options", executable.GetActiveOptionsName().c_str()); + + Path path = executable.GetLocalLayersSettingsPath(); + EXPECT_STREQ(path.AbsolutePath().c_str(), Path("./vk_layer_settings.txt").AbsolutePath().c_str()); + + executable.GetActiveOptions()->working_folder.Clear(); + Path path2 = executable.GetLocalLayersSettingsPath(); + // When working_folder is not set, use the executable absolute directory + EXPECT_STREQ(path.AbsoluteDir().c_str(), executable.path.AbsoluteDir().c_str()); +} + +TEST(test_executable, GetDefaultExecutablePath) { + DefaultExecutable default_executable{"vkcube", "/vkcube", "--suppress_popups", "vkcube launcher options"}; + Executable executable(default_executable); + + EXPECT_EQ(1, executable.GetOptions().size()); + EXPECT_STREQ(executable.path.RelativePath().c_str(), Path("${VULKAN_BIN}\\vkcube.exe").RelativePath().c_str()); + EXPECT_STREQ(executable.configuration.c_str(), "Validation"); + EXPECT_EQ(executable.enabled, true); + EXPECT_STREQ(executable.GetActiveOptionsName().c_str(), "vkcube launcher options"); + const ExecutableOptions* options = executable.GetActiveOptions(); + EXPECT_STREQ(options->working_folder.RelativePath().c_str(), Path("${VULKAN_BIN}").RelativePath().c_str()); + EXPECT_STREQ(options->args[0].c_str(), "--suppress_popups"); + EXPECT_TRUE(options->envs.empty()); + EXPECT_STREQ(options->log_file.RelativePath().c_str(), Path("${VK_HOME}/vkcube.txt").RelativePath().c_str()); } diff --git a/vkconfig_core/test/test_layer_preset.cpp b/vkconfig_core/test/test_layer_preset.cpp index 8614eea741..ce6163e524 100644 --- a/vkconfig_core/test/test_layer_preset.cpp +++ b/vkconfig_core/test/test_layer_preset.cpp @@ -38,9 +38,9 @@ TEST(test_layer_preset, has_preset) { SettingDataSetConst preset_settings; SettingDataSet layer_settings; - SettingMetaString* metaA = InstantiateString(layer, "KeyA"); - SettingMetaString* metaB = InstantiateString(layer, "KeyB"); - SettingMetaString* metaC = InstantiateString(layer, "KeyC"); + SettingMetaString* metaA = ::InstantiateString(layer, "KeyA"); + SettingMetaString* metaB = ::InstantiateString(layer, "KeyB"); + SettingMetaString* metaC = ::InstantiateString(layer, "KeyC"); EXPECT_EQ(false, ::HasPreset(layer_settings, preset_settings)); diff --git a/vkconfig_core/test/test_parameter.cpp b/vkconfig_core/test/test_parameter.cpp index ccd567909e..d9d97dd30d 100644 --- a/vkconfig_core/test/test_parameter.cpp +++ b/vkconfig_core/test/test_parameter.cpp @@ -216,15 +216,7 @@ TEST(test_parameter, order_parameter_manual_partial) { parameters[0].type = LAYER_TYPE_IMPLICIT; parameters[1].builtin = LAYER_BUILTIN_UNORDERED; - /* - for (std::size_t i = 0, n = parameters.size(); i < n; ++i) { - if (i == 7) { - continue; - } - - parameters[i].overridden_rank = static_cast(i); - } - */ + ::OrderParameter(parameters, layers); EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing"); diff --git a/vkconfig_gui/settings_tree.cpp b/vkconfig_gui/settings_tree.cpp index d6e5c6f393..21b5e7baa4 100644 --- a/vkconfig_gui/settings_tree.cpp +++ b/vkconfig_gui/settings_tree.cpp @@ -221,7 +221,6 @@ void SettingsTreeManager::BuildTreeItem(QTreeWidgetItem *parent, const SettingMe const SettingMetaGroup &meta = static_cast(meta_object); WidgetSettingGroup *widget = new WidgetSettingGroup(this->ui->configurations_settings, item, meta, parameter->settings); - this->connect(widget, SIGNAL(itemChanged()), this, SLOT(OnSettingChanged())); } break; case SETTING_BOOL: case SETTING_BOOL_NUMERIC_DEPRECATED: {