mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-03 01:00:40 +08:00
Begin stubbing in Config interface and tests for interface.
This commit is contained in:
parent
5dbfc104b7
commit
ff7ed5bd60
@ -192,6 +192,7 @@ set(UI_TEST_SOURCES
|
|||||||
set(SLIC3R_TEST_SOURCES
|
set(SLIC3R_TEST_SOURCES
|
||||||
${TESTDIR}/test_harness.cpp
|
${TESTDIR}/test_harness.cpp
|
||||||
${TESTDIR}/libslic3r/test_trianglemesh.cpp
|
${TESTDIR}/libslic3r/test_trianglemesh.cpp
|
||||||
|
${TESTDIR}/libslic3r/test_config.cpp
|
||||||
)
|
)
|
||||||
add_executable(slic3r slic3r.cpp)
|
add_executable(slic3r slic3r.cpp)
|
||||||
#set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1)
|
#set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1)
|
||||||
|
100
src/test/libslic3r/test_config.cpp
Normal file
100
src/test/libslic3r/test_config.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
#include "Config.hpp"
|
||||||
|
|
||||||
|
using namespace Slic3r;
|
||||||
|
|
||||||
|
SCENARIO("Generic config validation performs as expected.", "[!mayfail]") {
|
||||||
|
GIVEN("A config generated from default options") {
|
||||||
|
auto config {Slic3r::Config::new_from_defaults()};
|
||||||
|
WHEN( "perimeter_extrusion_width is set to 250%, a valid value") {
|
||||||
|
config->set("perimeter_extrusion_width", "250\%");
|
||||||
|
THEN( "The config is read as valid.") {
|
||||||
|
REQUIRE(config->validate() == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN( "perimeter_extrusion_width is set to -10, an invalid value") {
|
||||||
|
config->set("perimeter_extrusion_width", -10);
|
||||||
|
THEN( "An exception is thrown.") {
|
||||||
|
auto except_thrown {false};
|
||||||
|
try {
|
||||||
|
config->validate();
|
||||||
|
} catch (const InvalidOptionValue& e) {
|
||||||
|
except_thrown = true;
|
||||||
|
}
|
||||||
|
REQUIRE(except_thrown == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SCENARIO("Config accessor functions perform as expected.", "[!mayfail]") {
|
||||||
|
GIVEN("A config generated from default options") {
|
||||||
|
auto config {Slic3r::Config::new_from_defaults()};
|
||||||
|
WHEN("A numeric option is set through the string interface") {
|
||||||
|
THEN("The underlying value is set correctly.") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("An integer-based option is set through the integer interface") {
|
||||||
|
THEN("The underlying value is set correctly.") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("An floating-point option is set through the integer interface") {
|
||||||
|
THEN("The underlying value is set correctly.") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("A floating-point option is set through the double interface") {
|
||||||
|
THEN("The underlying value is set correctly.") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("An integer-based option is set through the double interface") {
|
||||||
|
THEN("The underlying value is set, rounded to the nearest integer.") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("A numeric option is set to a non-numeric value.") {
|
||||||
|
auto except_thrown {false};
|
||||||
|
try {
|
||||||
|
config->set("perimeter_extrusion_width", "zzzz");
|
||||||
|
} catch (const InvalidOptionType& e) {
|
||||||
|
except_thrown = true;
|
||||||
|
}
|
||||||
|
THEN("An exception is thown.") {
|
||||||
|
REQUIRE(except_thrown == true);
|
||||||
|
}
|
||||||
|
THEN("The value does not change.") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("An invalid option is requested during set.") {
|
||||||
|
auto except_thrown {false};
|
||||||
|
try {
|
||||||
|
config->set("deadbeef_invalid_option", "1");
|
||||||
|
} catch (const InvalidOptionType& e) {
|
||||||
|
except_thrown = true;
|
||||||
|
}
|
||||||
|
THEN("An exception is thrown.") {
|
||||||
|
REQUIRE(except_thrown == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WHEN("An invalid option is requested during get.") {
|
||||||
|
auto except_thrown {false};
|
||||||
|
try {
|
||||||
|
config->get<std::string>("deadbeef_invalid_option", false);
|
||||||
|
} catch (const InvalidOptionType& e) {
|
||||||
|
except_thrown = true;
|
||||||
|
}
|
||||||
|
THEN("An exception is thrown.") {
|
||||||
|
REQUIRE(except_thrown == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SCENARIO("Config ini load/save interface", "[!mayfail]") {
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
@ -35,6 +35,27 @@ new_from_cli(const int& argc, const char* argv[])
|
|||||||
return std::make_shared<Config>();
|
return std::make_shared<Config>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Config::validate()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::set(const t_config_option_key& opt_key, const std::string& value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::set(const t_config_option_key& opt_key, const int value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::set(const t_config_option_key& opt_key, const double value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,16 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
/// Exception class for invalid (but correct type) option values.
|
||||||
|
/// Thrown by validate()
|
||||||
|
class InvalidOptionValue : public std::runtime_error {};
|
||||||
|
|
||||||
|
/// Exception class to handle config options that don't exist.
|
||||||
|
class InvalidConfigOption : public std::runtime_error {};
|
||||||
|
|
||||||
|
/// Exception class for type mismatches
|
||||||
|
class InvalidOptionType : public std::runtime_error {};
|
||||||
|
|
||||||
class Config;
|
class Config;
|
||||||
using config_ptr = std::shared_ptr<Config>;
|
using config_ptr = std::shared_ptr<Config>;
|
||||||
|
|
||||||
@ -31,6 +41,23 @@ public:
|
|||||||
T& get(const t_config_option_key& opt_key, bool create=false) {
|
T& get(const t_config_option_key& opt_key, bool create=false) {
|
||||||
return *(dynamic_cast<T*>(this->optptr(opt_key, create)));
|
return *(dynamic_cast<T*>(this->optptr(opt_key, create)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Function to parse value from a string to whatever opt_key is.
|
||||||
|
void set(const t_config_option_key& opt_key, const std::string& value);
|
||||||
|
|
||||||
|
/// Function to parse value from an integer to whatever opt_key is, if
|
||||||
|
/// opt_key is a numeric type. This will throw an exception and do
|
||||||
|
/// nothing if called with an incorrect type.
|
||||||
|
void set(const t_config_option_key& opt_key, const int value);
|
||||||
|
|
||||||
|
/// Function to parse value from an integer to whatever opt_key is, if
|
||||||
|
/// opt_key is a numeric type. This will throw an exception and do
|
||||||
|
/// nothing if called with an incorrect type.
|
||||||
|
void set(const t_config_option_key& opt_key, const double value);
|
||||||
|
|
||||||
|
/// Method to validate the different configuration options.
|
||||||
|
/// It will throw InvalidConfigOption exceptions on failure.
|
||||||
|
bool validate();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
Loading…
x
Reference in New Issue
Block a user