fix: Compare Presets crash on filaments with different variant counts (#16176)

This commit is contained in:
Kris Austin
2026-10-05 21:20:12 -03:00
committed by GitHub
parent fefedb66c4
commit 9e5bfc272c
3 changed files with 45 additions and 0 deletions
@@ -0,0 +1,40 @@
#include <catch2/catch_test_macros.hpp>
#include <string>
#include "libslic3r/Config.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "slic3r/GUI/ConfigValueFormatter.hpp"
using namespace Slic3r;
using namespace Slic3r::GUI;
TEST_CASE("An enum vector index past the end of the vector reads as undefined", "[ConfigValueFormatter][Regression]")
{
const std::string key = "filament_retract_lift_enforce";
const ConfigOptionDef* def = print_config_def.get(key);
DynamicPrintConfig config;
config.set_key_value(key, new ConfigOptionEnumsGenericNullable(def->enum_keys_map, 1, ConfigOptionEnumsGenericNullable::nil_value()));
CHECK(get_string_value(key + "#1", config) == "Undefined");
}
TEST_CASE("An enum vector index inside the vector reads as its label", "[ConfigValueFormatter]")
{
const std::string key = "filament_retract_lift_enforce";
const ConfigOptionDef* def = print_config_def.get(key);
DynamicPrintConfig config;
config.set_key_value(key, new ConfigOptionEnumsGenericNullable(def->enum_keys_map, 1, def->enum_keys_map->at("Top Only")));
CHECK(get_string_value(key + "#0", config).utf8_string() == "Top Only");
}
TEST_CASE("An enum value outside the label list reads as undefined", "[ConfigValueFormatter]")
{
const std::string key = "filament_retract_lift_enforce";
const ConfigOptionDef* def = print_config_def.get(key);
DynamicPrintConfig config;
config.set_key_value(key, new ConfigOptionEnumsGenericNullable(def->enum_keys_map, 1, int(def->enum_labels.size())));
CHECK(get_string_value(key + "#0", config) == "Undefined");
}