From d1c307fade1dd83dbdb0e48d94c1895abea2f454 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 19 Mar 2021 16:36:13 -0500 Subject: [PATCH] Add basic file read tests for deflated AMF support. --- tests/libslic3r/test_amf.cpp | 66 +++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/tests/libslic3r/test_amf.cpp b/tests/libslic3r/test_amf.cpp index f9eddad3e..48cb9d0d1 100644 --- a/tests/libslic3r/test_amf.cpp +++ b/tests/libslic3r/test_amf.cpp @@ -7,26 +7,84 @@ using namespace Slic3r; using namespace std::literals::string_literals; +SCENARIO("Reading deflated AMF files", "[AMF]") { + auto _tmp_config = DynamicPrintConfig{}; + GIVEN("Compressed AMF file of a 20mm cube") { + auto model {new Slic3r::Model()}; + WHEN("file is read") { + bool result_code = load_amf(get_model_path("test_amf/20mmbox_deflated.amf"s).c_str(), &_tmp_config, model, false); + THEN("Does not return false.") { + REQUIRE(result_code == true); + } + THEN("Model object contains a single ModelObject.") { + REQUIRE(model->objects.size() == 1); + } + } + WHEN("single file is read with some subdirectories") { + bool result_code = load_amf(get_model_path("test_amf/20mmbox_deflated-in_directories.amf"s).c_str(), &_tmp_config, model, false); + THEN("Read returns false.") { + REQUIRE(result_code == true); + } + THEN("Model object contains no ModelObjects.") { + REQUIRE(model->objects.size() == 1); + } + } + WHEN("file is read with multiple files in the archive") { + bool result_code = load_amf(get_model_path("test_amf/20mmbox_deflated-mult_files.amf"s).c_str(), &_tmp_config, model, false); + THEN("Read returns ture.") { + REQUIRE(result_code == true); + } + THEN("Model object contains one ModelObject.") { + REQUIRE(model->objects.size() == 1); + } + } + delete model; + } + GIVEN("Uncompressed AMF file of a 20mm cube") { + auto model {new Slic3r::Model()}; + WHEN("file is read") { + bool result_code = load_amf(get_model_path("test_amf/20mmbox.amf"s).c_str(), &_tmp_config, model, false); + THEN("Does not return false.") { + REQUIRE(result_code == true); + } + THEN("Model object contains a single ModelObject.") { + REQUIRE(model->objects.size() == 1); + } + } + WHEN("nonexistant file is read") { + bool result_code = load_amf(get_model_path("test_amf/20mmbox-doesnotexist.amf"s).c_str(), &_tmp_config, model, false); + THEN("Read returns false.") { + REQUIRE(result_code == false); + } + THEN("Model object contains no ModelObject.") { + REQUIRE(model->objects.size() == 0); + } + } + delete model; + } +} -SCENARIO("Reading AMF file") { - auto z = DynamicPrintConfig{}; +SCENARIO("Reading AMF file", "[AMF]") { + auto _tmp_config = DynamicPrintConfig{}; GIVEN("badly formed AMF file (missing vertices)") { auto model {new Slic3r::Model()}; WHEN("AMF model is read") { - auto ret = Slic3r::load_amf(get_model_path("test_amf/5061-malicious.amf").c_str(), &z, model, false); + auto ret = Slic3r::load_amf(get_model_path("test_amf/5061-malicious.amf").c_str(), &_tmp_config, model, false); THEN("read should return True") { REQUIRE(ret); } } + delete model; } GIVEN("Ok formed AMF file") { auto model {new Slic3r::Model()}; WHEN("AMF model is read") { std::cerr << "TEST_DATA_DIR/test_amf/read-amf.amf"; - auto ret = Slic3r::load_amf(get_model_path("test_amf/read-amf.amf").c_str(), &z, model, false); + auto ret = Slic3r::load_amf(get_model_path("test_amf/read-amf.amf").c_str(), &_tmp_config, model, false); THEN("read should return True") { REQUIRE(ret); } } + delete model; } }