Moved a commented out test for DynamicPrintConfig serialization

/ deserialization into a living unit test.
This commit is contained in:
Vojtech Bubnik 2021-09-24 11:32:10 +02:00
parent 60d8a7b301
commit 6c37955d75
2 changed files with 35 additions and 40 deletions

View file

@ -1102,43 +1102,3 @@ bool Stack::temp_snapshot_active() const { return pimpl->temp_snapshot_active();
} // namespace UndoRedo
} // namespace Slic3r
//FIXME we should have unit tests for testing serialization of basic types as DynamicPrintConfig.
#if 0
#include "libslic3r/Config.hpp"
#include "libslic3r/PrintConfig.hpp"
namespace Slic3r {
bool test_dynamic_print_config_serialization() {
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();
} catch (std::runtime_error e) {
e.what();
}
DynamicPrintConfig cfg2;
try {
std::stringstream ss(serialized);
cereal::BinaryInputArchive iarchive(ss);
iarchive(cfg2);
} catch (std::runtime_error e) {
e.what();
}
if (cfg == cfg2) {
printf("Yes!\n");
return true;
}
printf("No!\n");
return false;
}
} // namespace Slic3r
#endif

View file

@ -3,6 +3,11 @@
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/LocalesUtils.hpp"
#include <cereal/types/polymorphic.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/vector.hpp>
#include <cereal/archives/binary.hpp>
using namespace Slic3r;
SCENARIO("Generic config validation performs as expected.", "[Config]") {
@ -202,3 +207,33 @@ SCENARIO("Config ini load/save interface", "[Config]") {
}
}
}
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();
} catch (std::runtime_error e) {
e.what();
}
THEN("Config object contains ini file options.") {
DynamicPrintConfig cfg2;
try {
std::stringstream ss(serialized);
cereal::BinaryInputArchive iarchive(ss);
iarchive(cfg2);
} catch (std::runtime_error e) {
e.what();
}
REQUIRE(cfg == cfg2);
}
}
}