added test for preset; added constructor for default preset.

This commit is contained in:
Joseph Lenox 2018-11-11 00:42:52 -06:00 committed by Joseph Lenox
parent d645f669bf
commit 0f76496b2e
3 changed files with 121 additions and 1 deletions

View File

@ -89,7 +89,9 @@ public:
bool operator==(const wxString& _name) const { return this->operator==(_name.ToStdString()); }
bool operator==(const std::string& _name) const { return _name.compare(this->name) == 0; }
/// Constructor for adding a file-backed
Preset(std::string load_dir, std::string filename, preset_t p);
Preset(bool is_default, wxString name, preset_t p) : group(p), name(name), external(false), default_preset(is_default) {};
private:
/// store to keep config options for this preset
@ -103,7 +105,7 @@ private:
config_ptr _dirty_config { nullptr };
/// Underlying filename for this preset config
wxFileName _file {};
wxFileName _file {wxFileName()};
/// All the options owned by the corresponding editor
t_config_option_keys _group_keys() const;

View File

@ -0,0 +1,116 @@
#include <catch.hpp>
#include "Preset.hpp"
#include "Config.hpp"
#include <test_options.hpp>
using namespace Slic3r::GUI;
using namespace std::literals::string_literals;
SCENARIO( "Preset construction" ) {
GIVEN("A preset file with at least one configuration") {
WHEN( "Preset is constructed." ) {
Preset item {std::string(testfile_dir) + "test_preset", "preset_load_numeric.ini"s, preset_t::Print};
THEN("Name is preset_load_numeric") {
REQUIRE(item.name == "preset_load_numeric"s);
}
THEN("group is Print") {
REQUIRE(item.group == preset_t::Print);
}
THEN("preset default is false.") {
REQUIRE(item.default_preset == false);
}
}
}
GIVEN("A default preset construction") {
WHEN( "Preset is constructed." ) {
Preset item {true, "- default -", preset_t::Print};
THEN("Name is - default -") {
REQUIRE(item.name == "- default -"s);
}
THEN("group is Print") {
REQUIRE(item.group == preset_t::Print);
}
THEN("preset default is true.") {
REQUIRE(item.default_preset == true);
}
THEN("file_exists() is false") {
REQUIRE(item.file_exists() == false);
}
}
}
}
SCENARIO( "Preset loading" ) {
GIVEN("A preset file with a config item that has adaptive_slicing = 1") {
Preset item {std::string(testfile_dir) + "test_preset", "preset_load_numeric.ini"s, preset_t::Print};
THEN("file_exists() returns true") {
REQUIRE(item.file_exists() == true);
}
config_ptr ref;
WHEN("The preset file with one item is loaded") {
ref = item.load_config();
THEN("Config is not dirty.") {
REQUIRE(item.dirty() == false);
}
THEN("adaptive_slicing = 1 in the preset config") {
REQUIRE(item.dirty_config().get<ConfigOptionBool>("adaptive_slicing").getBool() == true);
}
}
auto config { Slic3r::Config::new_from_defaults() };
ref = item.load_config();
WHEN("Option is changed in the config via loading a config") {
// precondition: adaptive_slicing is still true
REQUIRE(item.dirty_config().get<ConfigOptionBool>("adaptive_slicing").getBool() == true);
// precondition: default option for adaptice_slicing is false
REQUIRE(config->get<ConfigOptionBool>("adaptive_slicing").getBool() == false);
ref->apply(config);
THEN("Config is dirty.") {
REQUIRE(item.dirty() == true);
}
THEN("adaptive_slicing = 0 in the preset config") {
REQUIRE(item.dirty_config().get<ConfigOptionBool>("adaptive_slicing").getBool() == false);
}
THEN("subsequent calls yield the same reference") {
REQUIRE(item.load_config() == ref);
}
}
}
GIVEN("A preset file with a config item that has adaptive_slicing = 1 and default_preset = true") {
Preset item {std::string(testfile_dir) + "test_preset", "preset_load_numeric.ini"s, preset_t::Print};
item.default_preset = true;
config_ptr ref;
WHEN("The preset file with one item is loaded") {
ref = item.load_config();
THEN("Config is not dirty.") {
REQUIRE(item.dirty() == false);
}
THEN("adaptive_slicing = 0 in the preset config") {
REQUIRE(item.dirty_config().get<ConfigOptionBool>("adaptive_slicing").getBool() == false);
}
THEN("loaded is true") {
REQUIRE(item.loaded() == true);
}
THEN("subsequent calls yield the same reference") {
REQUIRE(item.load_config() == ref);
}
}
ref = item.load_config();
WHEN("Option is changed in the config") {
ref->set("adaptive_slicing", true);
THEN("Config is dirty.") {
REQUIRE(item.dirty() == true);
}
THEN("adaptive_slicing = 1 in the preset config") {
REQUIRE(item.dirty_config().get<ConfigOptionBool>("adaptive_slicing").getBool() == true);
}
}
}
GIVEN("An invalid preset file") {
Preset item {std::string(testfile_dir) + "test_preset", "___invalid__preset_load_numeric.ini"s, preset_t::Print};
THEN("file_exists() returns false") {
REQUIRE(item.file_exists() == false);
}
THEN("loaded is false") {
REQUIRE(item.loaded() == false);
}
}
}

View File

@ -0,0 +1,2 @@
# generated by joseph lenox
adaptive_slicing = 1