Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vkconfig3: Add more unit tests #2221

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions vkconfig_core/executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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..
}
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 3 additions & 29 deletions vkconfig_core/executable_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool ExecutableManager::AppendExecutable(const Path& executable_path) {

bool ExecutableManager::RemoveExecutable() {
if (this->data.empty()) {
return true;
return false;
}

std::size_t executable_index = static_cast<std::size_t>(this->GetActiveExecutableIndex());
Expand Down Expand Up @@ -312,8 +312,8 @@ Executable* ExecutableManager::GetExecutable(std::size_t executable_index) {
std::vector<Executable> ExecutableManager::CreateDefaultExecutables() const {
std::vector<Executable> 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;
Expand Down Expand Up @@ -342,29 +342,3 @@ std::vector<Executable> ExecutableManager::RemoveMissingExecutables(const std::v

return valid_applications;
}

bool ExecutableManager::HasIncompatiblePerExecutables(const Executable& executable,
std::vector<Executable>& imcompatible_executables) const {
for (std::size_t i = 0, n = this->data.size(); i < n; ++i) {
if (executable.path == this->data[i].path) {
continue;
}

if (executable.GetActiveOptions()->working_folder == this->data[i].GetActiveOptions()->working_folder) {
imcompatible_executables.push_back(this->data[i]);
}
}

return !imcompatible_executables.empty();
}

bool ExecutableManager::HasIncompatiblePerExecutables(std::vector<Executable>& imcompatible_executables) const {
for (std::size_t i = 0, n = this->data.size(); i < n; ++i) {
bool incompatible = this->HasIncompatiblePerExecutables(this->data[i], imcompatible_executables);
if (incompatible) {
imcompatible_executables.push_back(this->data[i]);
}
}

return !imcompatible_executables.empty();
}
3 changes: 0 additions & 3 deletions vkconfig_core/executable_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class ExecutableManager : public Serialize {
// Search for all the applications in the list, an remove the application which executable can't be found
std::vector<Executable> RemoveMissingExecutables(const std::vector<Executable>& executables) const;

bool HasIncompatiblePerExecutables(const Executable& executable, std::vector<Executable>& imcompatible_executables) const;
bool HasIncompatiblePerExecutables(std::vector<Executable>& imcompatible_executables) const;

bool launcher_clear_on_launch = true;
Path last_path_executable = ::Get(Path::HOME);

Expand Down
68 changes: 68 additions & 0 deletions vkconfig_core/test/test_executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,79 @@ 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());

EXPECT_STREQ("Default Options", executable.GetActiveOptionsName().c_str());

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) {
std::string saved = qgetenv("VULKAN_SDK").toStdString();
qunsetenv("VULKAN_SDK");

DefaultExecutable default_executable{"vkcube", "/vkcube", "--suppress_popups", "vkcube launcher options"};
const DefaultPath& default_paths = ::GetDefaultExecutablePath(default_executable.key);
#if defined(_WIN32)
EXPECT_STREQ(default_paths.executable_path.RelativePath().c_str(), Path(".\\vkcube.exe").RelativePath().c_str());
#elif defined(__linux__)
EXPECT_STREQ(default_paths.executable_path.RelativePath().c_str(), Path(".\\vkcube").RelativePath().c_str());
#elif defined(__APPLE__)
EXPECT_STREQ(default_paths.executable_path.RelativePath().c_str(),
Path("/Applications/vkcube.app/Contents/MacOS/vkcube").RelativePath().c_str());
#endif

#if defined(_WIN32) || defined(__linux__)
EXPECT_STREQ(default_paths.working_folder.RelativePath().c_str(), Path(".").RelativePath().c_str());
#elif defined(__APPLE__)
EXPECT_STREQ(default_paths.working_folder.RelativePath().c_str(),
Path("/Applications/vkcube.app/Contents/MacOS").RelativePath().c_str());
#endif

qputenv("VULKAN_SDK", saved.c_str());
}

TEST(test_executable, DefaultExecutable) {
std::string saved = qgetenv("VULKAN_SDK").toStdString();
qunsetenv("VULKAN_SDK");

DefaultExecutable default_executable{"vkcube", "/vkcube", "--suppress_popups", "vkcube launcher options"};
Executable executable(default_executable);

EXPECT_EQ(1, executable.GetOptions().size());
#if defined(_WIN32)
EXPECT_STREQ(executable.path.RelativePath().c_str(), Path(".\\vkcube.exe").RelativePath().c_str());
#elif defined(__linux__)
EXPECT_STREQ(executable.path.RelativePath().c_str(), Path(".\\vkcube").RelativePath().c_str());
#elif defined(__APPLE__)
EXPECT_STREQ(executable.path.RelativePath().c_str(),
Path("/Applications/vkcube.app/Contents/MacOS/vkcube").RelativePath().c_str());
#endif
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();
#if defined(_WIN32) || defined(__linux__)
EXPECT_STREQ(options->working_folder.RelativePath().c_str(), Path(".").RelativePath().c_str());
#elif defined(__APPLE__)
EXPECT_STREQ(options->working_folder.RelativePath().c_str(),
Path("/Applications/vkcube.app/Contents/MacOS").RelativePath().c_str());
#endif
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());

qputenv("VULKAN_SDK", saved.c_str());
}
52 changes: 52 additions & 0 deletions vkconfig_core/test/test_executable_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,58 @@ TEST(test_executable_manager, reset_default_applications_no_sdk) {
EXPECT_TRUE(options2[0].log_file.RelativePath().find("${VK_HOME}") != std::string::npos);
}

TEST(test_executable_manager, active_executable) {
qunsetenv("VULKAN_SDK");

ExecutableManager executable_manager;
executable_manager.Reset();

EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), 0);
EXPECT_EQ(executable_manager.GetExecutable(executable_manager.GetActiveExecutableIndex()),
executable_manager.GetActiveExecutable());

executable_manager.SetActiveExecutable(1);
EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), 1);
EXPECT_EQ(executable_manager.GetExecutable(executable_manager.GetActiveExecutableIndex()),
executable_manager.GetActiveExecutable());

const Executable* executable = executable_manager.GetActiveExecutable();
Path saved_path = executable->path;

EXPECT_TRUE(executable_manager.RemoveExecutable());

executable_manager.RenameActiveExecutable(saved_path);
EXPECT_STREQ(saved_path.AbsolutePath().c_str(), executable_manager.GetActiveExecutable()->path.AbsolutePath().c_str());
}

TEST(test_executable_manager, remove_executable) {
qunsetenv("VULKAN_SDK");

ExecutableManager executable_manager;
executable_manager.Reset();

EXPECT_EQ(3, executable_manager.GetExecutables().size());

EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), 0);

executable_manager.SetActiveExecutable(2);
EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), 2);

EXPECT_TRUE(executable_manager.RemoveExecutable());
EXPECT_EQ(2, executable_manager.GetExecutables().size());
EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), 0);

EXPECT_TRUE(executable_manager.RemoveExecutable());
EXPECT_EQ(1, executable_manager.GetExecutables().size());
EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), 0);

EXPECT_TRUE(executable_manager.RemoveExecutable());
EXPECT_EQ(0, executable_manager.GetExecutables().size());
EXPECT_EQ(executable_manager.GetActiveExecutableIndex(), -1);

EXPECT_FALSE(executable_manager.RemoveExecutable());
}

TEST(test_executable_manager, remove_missing_applications) {
ExecutableManager executable_manager;

Expand Down
6 changes: 3 additions & 3 deletions vkconfig_core/test/test_layer_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
10 changes: 1 addition & 9 deletions vkconfig_core/test/test_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(i);
}
*/

::OrderParameter(parameters, layers);

EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing");
Expand Down
1 change: 0 additions & 1 deletion vkconfig_gui/settings_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ void SettingsTreeManager::BuildTreeItem(QTreeWidgetItem *parent, const SettingMe
const SettingMetaGroup &meta = static_cast<const SettingMetaGroup &>(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: {
Expand Down
Loading