From dad3b1edb9fe92577f9ce6040474c569bc241c82 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 15 Mar 2021 21:57:41 -0500 Subject: [PATCH] Add test_amf.cpp from Slic3r --- tests/data/README.md | 21 +++++++++++++++++ tests/data/test_amf/5061-malicious.amf | 20 ++++++++++++++++ tests/data/test_amf/read-amf.amf | 19 +++++++++++++++ tests/libslic3r/CMakeLists.txt | 2 ++ tests/libslic3r/test_amf.cpp | 32 ++++++++++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 tests/data/README.md create mode 100644 tests/data/test_amf/5061-malicious.amf create mode 100644 tests/data/test_amf/read-amf.amf create mode 100644 tests/libslic3r/test_amf.cpp diff --git a/tests/data/README.md b/tests/data/README.md new file mode 100644 index 000000000..a550097e3 --- /dev/null +++ b/tests/data/README.md @@ -0,0 +1,21 @@ +Directory containing test-specific input files that are not source code. + +--- + +Rules +=== +* Each folder shall be named for the test that it supports. + * `test_config` directory supports `test_config.cpp`, etc. +* If a specific test file is reused across multiple tests, it should go in the `common` directory. +* Each extra input file should be named in such a way that it is relevant to the specific feature of it. +* No files should have special characters in the name (unless those special characters are part of the test). +* No spaces should be in the file paths (again, unless testing the presence of spaces is part of the test). +* Input files that are 3D models should be as small/specific as possible. + * Do not add copyrighted models without permission from the copyright holder. + * Do not add NonCommercial models, these would need to be relicensed from the original holder. + * Add any necessary licensing or attributation information as `.license` + * Example: A CC-By-SA 3D model called `cool_statue_bro.stl` should have its attributation/license information included in a file called `cool_statue_bro.license` + * Any submitted files without an accompanying `.license` file are assumed to be licensed under [CC-By-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/us/). +* The author of a commit adding any extra input files asserts that, via the process of committing those files, that they + * have abided by the terms of all licensing agreements involved with the files added or + * are the author of the files in question and submit them to the Slic3r project under the terms of [CC-By-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/us/). diff --git a/tests/data/test_amf/5061-malicious.amf b/tests/data/test_amf/5061-malicious.amf new file mode 100644 index 000000000..ce814e321 --- /dev/null +++ b/tests/data/test_amf/5061-malicious.amf @@ -0,0 +1,20 @@ + + + Split Pyramid + John Smith + + + + 200 + 2.50.50 + + + Hard side + 999999212 + 002 + + + + + + diff --git a/tests/data/test_amf/read-amf.amf b/tests/data/test_amf/read-amf.amf new file mode 100644 index 000000000..f366b2be4 --- /dev/null +++ b/tests/data/test_amf/read-amf.amf @@ -0,0 +1,19 @@ + + + Split Pyramid + John Smith + + + + 200 + 2.50.50 + 3.52.50 + + + Hard side + 212 + 002 + + + + diff --git a/tests/libslic3r/CMakeLists.txt b/tests/libslic3r/CMakeLists.txt index 501af0c6f..eb12424dc 100644 --- a/tests/libslic3r/CMakeLists.txt +++ b/tests/libslic3r/CMakeLists.txt @@ -2,6 +2,7 @@ get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests.cpp + test_amf.cpp test_3mf.cpp test_aabbindirect.cpp test_clipper_offset.cpp @@ -22,6 +23,7 @@ add_executable(${_TEST_NAME}_tests test_timeutils.cpp ) + if (TARGET OpenVDB::openvdb) target_sources(${_TEST_NAME}_tests PRIVATE test_hollowing.cpp) endif() diff --git a/tests/libslic3r/test_amf.cpp b/tests/libslic3r/test_amf.cpp new file mode 100644 index 000000000..f9eddad3e --- /dev/null +++ b/tests/libslic3r/test_amf.cpp @@ -0,0 +1,32 @@ +#include +#include "test_utils.hpp" +#include "libslic3r/Model.hpp" +#include "libslic3r/Format/AMF.hpp" +#include "libslic3r/PrintConfig.hpp" + +using namespace Slic3r; +using namespace std::literals::string_literals; + + +SCENARIO("Reading AMF file") { + auto z = 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); + THEN("read should return True") { + REQUIRE(ret); + } + } + } + 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); + THEN("read should return True") { + REQUIRE(ret); + } + } + } +}