test_amf.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <catch2/catch.hpp>
  2. #include "test_utils.hpp"
  3. #include "libslic3r/Model.hpp"
  4. #include "libslic3r/Format/AMF.hpp"
  5. #include "libslic3r/PrintConfig.hpp"
  6. using namespace Slic3r;
  7. using namespace std::literals::string_literals;
  8. SCENARIO("Reading deflated AMF files", "[AMF]") {
  9. auto _tmp_config = DynamicPrintConfig{};
  10. GIVEN("Compressed AMF file of a 20mm cube") {
  11. auto model {new Slic3r::Model()};
  12. WHEN("file is read") {
  13. bool result_code = load_amf(get_model_path("test_amf/20mmbox_deflated.amf"s).c_str(), &_tmp_config, model, false);
  14. THEN("Does not return false.") {
  15. REQUIRE(result_code == true);
  16. }
  17. THEN("Model object contains a single ModelObject.") {
  18. REQUIRE(model->objects.size() == 1);
  19. }
  20. }
  21. WHEN("single file is read with some subdirectories") {
  22. bool result_code = load_amf(get_model_path("test_amf/20mmbox_deflated-in_directories.amf"s).c_str(), &_tmp_config, model, false);
  23. THEN("Read returns false.") {
  24. REQUIRE(result_code == true);
  25. }
  26. THEN("Model object contains no ModelObjects.") {
  27. REQUIRE(model->objects.size() == 1);
  28. }
  29. }
  30. WHEN("file is read with multiple files in the archive") {
  31. bool result_code = load_amf(get_model_path("test_amf/20mmbox_deflated-mult_files.amf"s).c_str(), &_tmp_config, model, false);
  32. THEN("Read returns ture.") {
  33. REQUIRE(result_code == true);
  34. }
  35. THEN("Model object contains one ModelObject.") {
  36. REQUIRE(model->objects.size() == 1);
  37. }
  38. }
  39. delete model;
  40. }
  41. GIVEN("Uncompressed AMF file of a 20mm cube") {
  42. auto model {new Slic3r::Model()};
  43. WHEN("file is read") {
  44. bool result_code = load_amf(get_model_path("test_amf/20mmbox.amf"s).c_str(), &_tmp_config, model, false);
  45. THEN("Does not return false.") {
  46. REQUIRE(result_code == true);
  47. }
  48. THEN("Model object contains a single ModelObject.") {
  49. REQUIRE(model->objects.size() == 1);
  50. }
  51. }
  52. WHEN("nonexistant file is read") {
  53. bool result_code = load_amf(get_model_path("test_amf/20mmbox-doesnotexist.amf"s).c_str(), &_tmp_config, model, false);
  54. THEN("Read returns false.") {
  55. REQUIRE(result_code == false);
  56. }
  57. THEN("Model object contains no ModelObject.") {
  58. REQUIRE(model->objects.size() == 0);
  59. }
  60. }
  61. delete model;
  62. }
  63. }
  64. SCENARIO("Reading AMF file", "[AMF]") {
  65. auto _tmp_config = DynamicPrintConfig{};
  66. GIVEN("badly formed AMF file (missing vertices)") {
  67. auto model {new Slic3r::Model()};
  68. WHEN("AMF model is read") {
  69. auto ret = Slic3r::load_amf(get_model_path("test_amf/5061-malicious.amf").c_str(), &_tmp_config, model, false);
  70. THEN("read should return True") {
  71. REQUIRE(ret);
  72. }
  73. }
  74. delete model;
  75. }
  76. GIVEN("Ok formed AMF file") {
  77. auto model {new Slic3r::Model()};
  78. WHEN("AMF model is read") {
  79. std::cerr << "TEST_DATA_DIR/test_amf/read-amf.amf";
  80. auto ret = Slic3r::load_amf(get_model_path("test_amf/read-amf.amf").c_str(), &_tmp_config, model, false);
  81. THEN("read should return True") {
  82. REQUIRE(ret);
  83. }
  84. }
  85. delete model;
  86. }
  87. }