Get libslic3r tests closer to passing

I can't get geometry tests to do anything useful. I've added extra
output, but it hasn't helped me figure out why they don't work
yet. That's also probably the last broken 3mf test doesn't work.

The config tests were mostly broken because of config name changes.

The placeholder_parser tests have some things that may-or-may-not
still apply to Orca.
This commit is contained in:
Cory Cross
2025-09-29 11:32:10 -07:00
parent 99863163b2
commit 87c9b92a1c
7 changed files with 157 additions and 112 deletions

View File

@@ -1,6 +1,7 @@
#include <catch2/catch.hpp>
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/PrintConfigConstants.hpp"
#include "libslic3r/LocalesUtils.hpp"
#include <cereal/types/polymorphic.hpp>
@@ -13,23 +14,23 @@ using namespace Slic3r;
SCENARIO("Generic config validation performs as expected.", "[Config]") {
GIVEN("A config generated from default options") {
Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
WHEN( "perimeter_extrusion_width is set to 250%, a valid value") {
config.set_deserialize_strict("perimeter_extrusion_width", "250%");
WHEN( "outer_wall_line_width is set to 250%, a valid value") {
config.set_deserialize_strict("outer_wall_line_width", "250%");
THEN( "The config is read as valid.") {
REQUIRE(config.validate().empty());
}
}
WHEN( "perimeter_extrusion_width is set to -10, an invalid value") {
config.set("perimeter_extrusion_width", -10);
WHEN( "outer_wall_line_width is set to -10, an invalid value") {
config.set("outer_wall_line_width", -10);
THEN( "Validate returns error") {
REQUIRE(! config.validate().empty());
REQUIRE_FALSE(config.validate().empty());
}
}
WHEN( "perimeters is set to -10, an invalid value") {
config.set("perimeters", -10);
WHEN( "wall_loops is set to -10, an invalid value") {
config.set("wall_loops", -10);
THEN( "Validate returns error") {
REQUIRE(! config.validate().empty());
REQUIRE_FALSE(config.validate().empty());
}
}
}
@@ -64,95 +65,115 @@ SCENARIO("Config accessor functions perform as expected.", "[Config]") {
}
}
WHEN("A numeric option is set from serialized string") {
config.set_deserialize_strict("bed_temperature", "100");
config.set_deserialize_strict("raft_layers", "20");
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionInts>("bed_temperature")->get_at(0) == 100);
REQUIRE(config.opt<ConfigOptionInt>("raft_layers")->getInt() == 20);
}
}
#if 0
//FIXME better design accessors for vector elements.
WHEN("An integer-based option is set through the integer interface") {
config.set("bed_temperature", 100);
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionInts>("bed_temperature")->get_at(0) == 100);
}
WHEN("An integer-based option is set through the integer interface") {
config.set("raft_layers", 100);
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionInt>("raft_layers")->getInt() == 100);
}
}
#endif
WHEN("An floating-point option is set through the integer interface") {
config.set("perimeter_speed", 10);
config.set("default_acceleration", 10);
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionFloat>("perimeter_speed")->getFloat() == 10.0);
REQUIRE(config.opt<ConfigOptionFloat>("default_acceleration")->getFloat() == 10.0);
}
}
WHEN("A floating-point option is set through the double interface") {
config.set("perimeter_speed", 5.5);
config.set("default_acceleration", 5.5);
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionFloat>("perimeter_speed")->getFloat() == 5.5);
REQUIRE(config.opt<ConfigOptionFloat>("default_acceleration")->getFloat() == 5.5);
}
}
WHEN("An integer-based option is set through the double interface") {
THEN("A BadOptionTypeException exception is thrown.") {
REQUIRE_THROWS_AS(config.set("bed_temperature", 5.5), BadOptionTypeException);
REQUIRE_THROWS_AS(config.set("top_shell_layers", 5.5), BadOptionTypeException);
}
}
WHEN("A numeric option is set to a non-numeric value.") {
THEN("A BadOptionTypeException exception is thown.") {
REQUIRE_THROWS_AS(config.set_deserialize_strict("perimeter_speed", "zzzz"), BadOptionValueException);
auto prev_value = config.opt<ConfigOptionFloat>("default_acceleration")->getFloat();
THEN("A BadOptionTypeException exception is thrown.") {
REQUIRE_THROWS_AS(config.set_deserialize_strict("default_acceleration", "zzzz"), BadOptionValueException);
}
THEN("The value does not change.") {
REQUIRE(config.opt<ConfigOptionFloat>("perimeter_speed")->getFloat() == 60.0);
REQUIRE(config.opt<ConfigOptionFloat>("default_acceleration")->getFloat() == prev_value);
}
}
WHEN("A string option is set through the string interface") {
config.set("end_gcode", "100");
config.set("machine_end_gcode", "100");
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionString>("end_gcode")->value == "100");
REQUIRE(config.opt<ConfigOptionString>("machine_end_gcode")->value == "100");
}
}
WHEN("A string option is set through the integer interface") {
config.set("end_gcode", 100);
config.set("machine_end_gcode", 100);
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionString>("end_gcode")->value == "100");
REQUIRE(config.opt<ConfigOptionString>("machine_end_gcode")->value == "100");
}
}
WHEN("A string option is set through the double interface") {
config.set("end_gcode", 100.5);
config.set("machine_end_gcode", 100.5);
THEN("The underlying value is set correctly.") {
REQUIRE(config.opt<ConfigOptionString>("end_gcode")->value == float_to_string_decimal_point(100.5));
REQUIRE(config.opt<ConfigOptionString>("machine_end_gcode")->value == float_to_string_decimal_point(100.5));
}
}
WHEN("A float or percent is set as a percent through the string interface.") {
config.set_deserialize_strict("first_layer_extrusion_width", "100%");
config.set_deserialize_strict("initial_layer_line_width", "100%");
THEN("Value and percent flag are 100/true") {
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_width");
auto tmp = config.opt<ConfigOptionFloatOrPercent>("initial_layer_line_width");
REQUIRE(tmp->percent == true);
REQUIRE(tmp->value == 100);
}
}
WHEN("A float or percent is set as a float through the string interface.") {
config.set_deserialize_strict("first_layer_extrusion_width", "100");
config.set_deserialize_strict("initial_layer_line_width", "100");
THEN("Value and percent flag are 100/false") {
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_width");
auto tmp = config.opt<ConfigOptionFloatOrPercent>("initial_layer_line_width");
REQUIRE(tmp->percent == false);
REQUIRE(tmp->value == 100);
}
}
WHEN("A float or percent is set as a float through the int interface.") {
config.set("first_layer_extrusion_width", 100);
config.set("initial_layer_line_width", 100);
THEN("Value and percent flag are 100/false") {
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_width");
auto tmp = config.opt<ConfigOptionFloatOrPercent>("initial_layer_line_width");
REQUIRE(tmp->percent == false);
REQUIRE(tmp->value == 100);
}
}
WHEN("A float or percent is set as a float through the double interface.") {
config.set("first_layer_extrusion_width", 100.5);
config.set("initial_layer_line_width", 100.5);
THEN("Value and percent flag are 100.5/false") {
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_width");
auto tmp = config.opt<ConfigOptionFloatOrPercent>("initial_layer_line_width");
REQUIRE(tmp->percent == false);
REQUIRE(tmp->value == 100.5);
}
}
WHEN("A numeric vector is set from serialized string") {
config.set_deserialize_strict("temperature_vitrification", "10,20");
THEN("The underlying value is set correctly.") {
CHECK(config.opt<ConfigOptionInts>("temperature_vitrification")->get_at(0) == 10);
CHECK(config.opt<ConfigOptionInts>("temperature_vitrification")->get_at(1) == 20);
}
}
// FIXME: Design better accessors for vector elements
// The following isn't supported and probably shouldn't be:
// WHEN("An integer-based vector option is set through the integer interface") {
// config.set("temperature_vitrification", 100);
// THEN("The underlying value is set correctly.") {
// REQUIRE(config.opt<ConfigOptionInts>("temperature_vitrification")->get_at(0) == 100);
// }
// }
WHEN("An integer-based vector option is set through the set_key_value interface") {
config.set_key_value("temperature_vitrification", new ConfigOptionInts{10,20});
THEN("The underlying value is set correctly.") {
CHECK(config.opt<ConfigOptionInts>("temperature_vitrification")->get_at(0) == 10);
CHECK(config.opt<ConfigOptionInts>("temperature_vitrification")->get_at(1) == 20);
}
}
WHEN("An invalid option is requested during set.") {
THEN("A BadOptionTypeException exception is thrown.") {
REQUIRE_THROWS_AS(config.set("deadbeef_invalid_option", 1), UnknownOptionException);
@@ -181,16 +202,16 @@ SCENARIO("Config accessor functions perform as expected.", "[Config]") {
WHEN("getX called on an unset option.") {
THEN("The default is returned.") {
REQUIRE(config.opt_float("layer_height") == 0.3);
REQUIRE(config.opt_int("raft_layers") == 0);
REQUIRE(config.opt_bool("support_material") == false);
REQUIRE(config.opt_float("layer_height") == INITIAL_LAYER_HEIGHT);
REQUIRE(config.opt_int("raft_layers") == INITIAL_RAFT_LAYERS);
REQUIRE(config.opt_bool("reduce_crossing_wall") == INITIAL_REDUCE_CROSSING_WALL);
}
}
WHEN("getFloat called on an option that has been set.") {
config.set("layer_height", 0.5);
WHEN("opt_float called on an option that has been set.") {
config.set("layer_height", INITIAL_LAYER_HEIGHT*2);
THEN("The set value is returned.") {
REQUIRE(config.opt_float("layer_height") == 0.5);
REQUIRE(config.opt_float("layer_height") == INITIAL_LAYER_HEIGHT*2);
}
}
}