diff --git a/src/test/libslic3r/test_config.cpp b/src/test/libslic3r/test_config.cpp index b8d7005d4..17a4ac2a1 100644 --- a/src/test/libslic3r/test_config.cpp +++ b/src/test/libslic3r/test_config.cpp @@ -54,6 +54,7 @@ SCENARIO("Config accessor functions perform as expected.") { REQUIRE(config->get("bed_temperature").getInt() == 100); } } + WHEN("An integer-based option is set through the integer interface") { config->set("bed_temperature", 100); THEN("The underlying value is set correctly.") { @@ -92,6 +93,24 @@ SCENARIO("Config accessor functions perform as expected.") { REQUIRE(config->get("perimeter_speed").getFloat() == 60.0); } } + WHEN("A string option is set through the string interface") { + config->set("octoprint_apikey", "100"); + THEN("The underlying value is set correctly.") { + REQUIRE(config->get("octoprint_apikey").getString() == "100"); + } + } + WHEN("A string option is set through the integer interface") { + config->set("octoprint_apikey", 100); + THEN("The underlying value is set correctly.") { + REQUIRE(config->get("octoprint_apikey").getString() == "100"); + } + } + WHEN("A string option is set through the double interface") { + config->set("octoprint_apikey", 100.5); + THEN("The underlying value is set correctly.") { + REQUIRE(config->get("octoprint_apikey").getString() == std::to_string(100.5)); + } + } WHEN("An invalid option is requested during set (string).") { auto except_thrown {false}; try { diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 3eb6e252a..c91f27440 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -127,12 +127,19 @@ Config::set(const t_config_option_key& opt_key, const std::string& value) throw InvalidOptionValue(std::string(opt_key) + std::string(" set with invalid value.")); } } break; + case coString: + { + auto* ptr {dynamic_cast(this->optptr(opt_key, true))}; + if (!ptr->deserialize(value) ) { + throw InvalidOptionValue(std::string(opt_key) + std::string(" set with invalid value.")); + } + } break; default: Slic3r::Log::warn("Config::set", "Unknown set type."); } - } catch (std::invalid_argument &e) { + } catch (std::invalid_argument e) { throw InvalidOptionValue(std::string(opt_key) + std::string(" set with invalid value.")); - } catch (std::out_of_range &e) { + } catch (std::out_of_range e) { throw InvalidOptionType(std::string(opt_key) + std::string(" is an invalid Slic3r option.")); } } @@ -168,6 +175,13 @@ Config::set(const t_config_option_key& opt_key, const int value) auto* ptr {dynamic_cast(this->optptr(opt_key, true))}; ptr->deserialize(std::to_string(value), true); } break; + case coString: + { + auto* ptr {dynamic_cast(this->optptr(opt_key, true))}; + if (!ptr->deserialize(std::to_string(value)) ) { + throw InvalidOptionValue(std::string(opt_key) + std::string(" set with invalid value.")); + } + } break; default: Slic3r::Log::warn("Config::set", "Unknown set type."); } @@ -208,6 +222,13 @@ Config::set(const t_config_option_key& opt_key, const double value) auto* ptr {dynamic_cast(this->optptr(opt_key, true))}; ptr->deserialize(std::to_string(value), true); } break; + case coString: + { + auto* ptr {dynamic_cast(this->optptr(opt_key, true))}; + if (!ptr->deserialize(std::to_string(value)) ) { + throw InvalidOptionValue(std::string(opt_key) + std::string(" set with invalid value.")); + } + } break; default: Slic3r::Log::warn("Config::set", "Unknown set type."); }