2019-10-18 09:53:19 +00:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
|
|
|
#include "libslic3r/PrintConfig.hpp"
|
2021-05-10 10:18:30 +00:00
|
|
|
#include "libslic3r/LocalesUtils.hpp"
|
2019-10-18 09:53:19 +00:00
|
|
|
|
2021-09-24 09:32:10 +00:00
|
|
|
#include <cereal/types/polymorphic.hpp>
|
|
|
|
#include <cereal/types/string.hpp>
|
|
|
|
#include <cereal/types/vector.hpp>
|
|
|
|
#include <cereal/archives/binary.hpp>
|
|
|
|
|
2019-10-18 09:53:19 +00:00
|
|
|
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") {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config.set_deserialize_strict("perimeter_extrusion_width", "250%");
|
2019-10-18 09:53:19 +00:00
|
|
|
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);
|
|
|
|
THEN( "Validate returns error") {
|
|
|
|
REQUIRE(! config.validate().empty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN( "perimeters is set to -10, an invalid value") {
|
|
|
|
config.set("perimeters", -10);
|
|
|
|
THEN( "Validate returns error") {
|
|
|
|
REQUIRE(! config.validate().empty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENARIO("Config accessor functions perform as expected.", "[Config]") {
|
|
|
|
GIVEN("A config generated from default options") {
|
|
|
|
Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
|
|
|
|
WHEN("A boolean option is set to a boolean value") {
|
|
|
|
REQUIRE_NOTHROW(config.set("gcode_comments", true));
|
|
|
|
THEN("The underlying value is set correctly.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionBool>("gcode_comments")->getBool() == true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A boolean option is set to a string value representing a 0 or 1") {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
CHECK_NOTHROW(config.set_deserialize_strict("gcode_comments", "1"));
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("The underlying value is set correctly.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionBool>("gcode_comments")->getBool() == true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A boolean option is set to a string value representing something other than 0 or 1") {
|
|
|
|
THEN("A BadOptionTypeException exception is thrown.") {
|
|
|
|
REQUIRE_THROWS_AS(config.set("gcode_comments", "Z"), BadOptionTypeException);
|
|
|
|
}
|
|
|
|
AND_THEN("Value is unchanged.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionBool>("gcode_comments")->getBool() == false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A boolean option is set to an int value") {
|
|
|
|
THEN("A BadOptionTypeException exception is thrown.") {
|
|
|
|
REQUIRE_THROWS_AS(config.set("gcode_comments", 1), BadOptionTypeException);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A numeric option is set from serialized string") {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config.set_deserialize_strict("bed_temperature", "100");
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("The underlying value is set correctly.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionInts>("bed_temperature")->get_at(0) == 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
WHEN("An floating-point option is set through the integer interface") {
|
|
|
|
config.set("perimeter_speed", 10);
|
|
|
|
THEN("The underlying value is set correctly.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionFloat>("perimeter_speed")->getFloat() == 10.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A floating-point option is set through the double interface") {
|
|
|
|
config.set("perimeter_speed", 5.5);
|
|
|
|
THEN("The underlying value is set correctly.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionFloat>("perimeter_speed")->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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A numeric option is set to a non-numeric value.") {
|
|
|
|
THEN("A BadOptionTypeException exception is thown.") {
|
2021-06-29 13:41:47 +00:00
|
|
|
REQUIRE_THROWS_AS(config.set_deserialize_strict("perimeter_speed", "zzzz"), BadOptionValueException);
|
2019-10-18 09:53:19 +00:00
|
|
|
}
|
|
|
|
THEN("The value does not change.") {
|
|
|
|
REQUIRE(config.opt<ConfigOptionFloat>("perimeter_speed")->getFloat() == 60.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A string option is set through the string interface") {
|
2020-10-29 11:39:03 +00:00
|
|
|
config.set("end_gcode", "100");
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("The underlying value is set correctly.") {
|
2020-10-29 11:39:03 +00:00
|
|
|
REQUIRE(config.opt<ConfigOptionString>("end_gcode")->value == "100");
|
2019-10-18 09:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A string option is set through the integer interface") {
|
2020-10-29 11:39:03 +00:00
|
|
|
config.set("end_gcode", 100);
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("The underlying value is set correctly.") {
|
2020-10-29 11:39:03 +00:00
|
|
|
REQUIRE(config.opt<ConfigOptionString>("end_gcode")->value == "100");
|
2019-10-18 09:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A string option is set through the double interface") {
|
2020-10-29 11:39:03 +00:00
|
|
|
config.set("end_gcode", 100.5);
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("The underlying value is set correctly.") {
|
2021-05-10 10:18:30 +00:00
|
|
|
REQUIRE(config.opt<ConfigOptionString>("end_gcode")->value == float_to_string_decimal_point(100.5));
|
2019-10-18 09:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A float or percent is set as a percent through the string interface.") {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config.set_deserialize_strict("first_layer_extrusion_width", "100%");
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("Value and percent flag are 100/true") {
|
|
|
|
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_width");
|
|
|
|
REQUIRE(tmp->percent == true);
|
|
|
|
REQUIRE(tmp->value == 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("A float or percent is set as a float through the string interface.") {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config.set_deserialize_strict("first_layer_extrusion_width", "100");
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("Value and percent flag are 100/false") {
|
|
|
|
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_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);
|
|
|
|
THEN("Value and percent flag are 100/false") {
|
|
|
|
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_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);
|
|
|
|
THEN("Value and percent flag are 100.5/false") {
|
|
|
|
auto tmp = config.opt<ConfigOptionFloatOrPercent>("first_layer_extrusion_width");
|
|
|
|
REQUIRE(tmp->percent == false);
|
|
|
|
REQUIRE(tmp->value == 100.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("An invalid option is requested during set.") {
|
|
|
|
THEN("A BadOptionTypeException exception is thrown.") {
|
|
|
|
REQUIRE_THROWS_AS(config.set("deadbeef_invalid_option", 1), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.set("deadbeef_invalid_option", 1.0), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.set("deadbeef_invalid_option", "1"), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.set("deadbeef_invalid_option", true), UnknownOptionException);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("An invalid option is requested during get.") {
|
|
|
|
THEN("A UnknownOptionException exception is thrown.") {
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionString>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionFloat>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionInt>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionBool>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("An invalid option is requested during opt.") {
|
|
|
|
THEN("A UnknownOptionException exception is thrown.") {
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionString>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionFloat>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionInt>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
REQUIRE_THROWS_AS(config.option_throw<ConfigOptionBool>("deadbeef_invalid_option", false), UnknownOptionException);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("getFloat called on an option that has been set.") {
|
|
|
|
config.set("layer_height", 0.5);
|
|
|
|
THEN("The set value is returned.") {
|
|
|
|
REQUIRE(config.opt_float("layer_height") == 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENARIO("Config ini load/save interface", "[Config]") {
|
|
|
|
WHEN("new_from_ini is called") {
|
|
|
|
Slic3r::DynamicPrintConfig config;
|
|
|
|
std::string path = std::string(TEST_DATA_DIR) + "/test_config/new_from_ini.ini";
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config.load_from_ini(path, ForwardCompatibilitySubstitutionRule::Disable);
|
2019-10-18 09:53:19 +00:00
|
|
|
THEN("Config object contains ini file options.") {
|
|
|
|
REQUIRE(config.option_throw<ConfigOptionStrings>("filament_colour", false)->values.size() == 1);
|
|
|
|
REQUIRE(config.option_throw<ConfigOptionStrings>("filament_colour", false)->values.front() == "#ABCD");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-24 09:32:10 +00:00
|
|
|
|
|
|
|
SCENARIO("DynamicPrintConfig serialization", "[Config]") {
|
|
|
|
WHEN("DynamicPrintConfig is serialized and deserialized") {
|
|
|
|
FullPrintConfig full_print_config;
|
|
|
|
DynamicPrintConfig cfg;
|
|
|
|
cfg.apply(full_print_config, false);
|
|
|
|
|
|
|
|
std::string serialized;
|
|
|
|
try {
|
|
|
|
std::ostringstream ss;
|
|
|
|
cereal::BinaryOutputArchive oarchive(ss);
|
|
|
|
oarchive(cfg);
|
|
|
|
serialized = ss.str();
|
2021-10-21 07:55:12 +00:00
|
|
|
} catch (std::runtime_error &e) {
|
2021-09-24 09:32:10 +00:00
|
|
|
e.what();
|
|
|
|
}
|
|
|
|
|
|
|
|
THEN("Config object contains ini file options.") {
|
|
|
|
DynamicPrintConfig cfg2;
|
|
|
|
try {
|
|
|
|
std::stringstream ss(serialized);
|
|
|
|
cereal::BinaryInputArchive iarchive(ss);
|
|
|
|
iarchive(cfg2);
|
2021-10-21 07:55:12 +00:00
|
|
|
} catch (std::runtime_error &e) {
|
2021-09-24 09:32:10 +00:00
|
|
|
e.what();
|
|
|
|
}
|
|
|
|
REQUIRE(cfg == cfg2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|