mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-07-31 01:22:05 +08:00
Add test to set string options.
This commit is contained in:
parent
7861037556
commit
932a238328
@ -54,6 +54,7 @@ SCENARIO("Config accessor functions perform as expected.") {
|
||||
REQUIRE(config->get<ConfigOptionInt>("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<ConfigOptionFloat>("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<ConfigOptionString>("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<ConfigOptionString>("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<ConfigOptionString>("octoprint_apikey").getString() == std::to_string(100.5));
|
||||
}
|
||||
}
|
||||
WHEN("An invalid option is requested during set (string).") {
|
||||
auto except_thrown {false};
|
||||
try {
|
||||
|
@ -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<ConfigOptionString*>(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<ConfigOptionFloats*>(this->optptr(opt_key, true))};
|
||||
ptr->deserialize(std::to_string(value), true);
|
||||
} break;
|
||||
case coString:
|
||||
{
|
||||
auto* ptr {dynamic_cast<ConfigOptionString*>(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<ConfigOptionFloats*>(this->optptr(opt_key, true))};
|
||||
ptr->deserialize(std::to_string(value), true);
|
||||
} break;
|
||||
case coString:
|
||||
{
|
||||
auto* ptr {dynamic_cast<ConfigOptionString*>(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.");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user