test_amf.cpp 3.8 KB

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