test_thumbnails_input_string.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include <catch2/catch.hpp>
  2. #include <test_utils.hpp>
  3. #include <libslic3r/GCode/Thumbnails.hpp>
  4. using namespace Slic3r;
  5. using namespace GCodeThumbnails;
  6. // Test Thumbnails lines
  7. static std::string empty_thumbnails()
  8. {
  9. return "";
  10. }
  11. static std::string valid_thumbnails()
  12. {
  13. return "160x120/PNG, 23x78/QOI, 230x780/JPG";
  14. }
  15. static std::string valid_thumbnails2()
  16. {
  17. return "160x120/PNG, 23x78/QOi, 320x240/PNg, 230x780/JPG";
  18. }
  19. static std::string out_of_range_thumbnail()
  20. {
  21. return "160x1200/PNG, 23x78/QOI, 320x240/PNG, 230x780/JPG";
  22. }
  23. static std::string out_of_range_thumbnail2()
  24. {
  25. return "160x120/PNG, 23x78/QOI, -320x240/PNG, 230x780/JPG";
  26. }
  27. static std::string invalid_ext_thumbnail()
  28. {
  29. return "160x120/PNk, 23x78/QOI, 320x240/PNG, 230x780/JPG";
  30. }
  31. static std::string invalid_ext_thumbnail2()
  32. {
  33. return "160x120/PNG, 23x78/QO, 320x240/PNG, 230x780/JPG";
  34. }
  35. static std::string invalid_val_thumbnail()
  36. {
  37. return "160x/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG";
  38. }
  39. static std::string invalid_val_thumbnail2()
  40. {
  41. return "x120/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG";
  42. }
  43. static std::string invalid_val_thumbnail3()
  44. {
  45. return "x/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG";
  46. }
  47. static std::string invalid_val_thumbnail4()
  48. {
  49. return "23*78/QOI, 320x240/PNG, 230x780/JPG";
  50. }
  51. TEST_CASE("Empty Thumbnails", "[Thumbnails]") {
  52. auto [thumbnails, errors] = make_and_check_thumbnail_list(empty_thumbnails());
  53. REQUIRE(errors == enum_bitmask<ThumbnailError>());
  54. REQUIRE(thumbnails.empty());
  55. }
  56. TEST_CASE("Valid Thumbnails", "[Thumbnails]") {
  57. SECTION("Test 1") {
  58. auto [thumbnails, errors] = make_and_check_thumbnail_list(valid_thumbnails());
  59. REQUIRE(errors == enum_bitmask<ThumbnailError>());
  60. REQUIRE(thumbnails.size() == 3);
  61. }
  62. SECTION("Test 2") {
  63. auto [thumbnails, errors] = make_and_check_thumbnail_list(valid_thumbnails2());
  64. REQUIRE(errors == enum_bitmask<ThumbnailError>());
  65. REQUIRE(thumbnails.size() == 4);
  66. }
  67. }
  68. TEST_CASE("Out of range Thumbnails", "[Thumbnails]") {
  69. SECTION("Test 1") {
  70. auto [thumbnails, errors] = make_and_check_thumbnail_list(out_of_range_thumbnail());
  71. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  72. REQUIRE(errors.has(ThumbnailError::OutOfRange));
  73. REQUIRE(thumbnails.size() == 3);
  74. }
  75. SECTION("Test 2") {
  76. auto [thumbnails, errors] = make_and_check_thumbnail_list(out_of_range_thumbnail2());
  77. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  78. REQUIRE(errors.has(ThumbnailError::OutOfRange));
  79. REQUIRE(thumbnails.size() == 3);
  80. }
  81. }
  82. TEST_CASE("Invalid extention Thumbnails", "[Thumbnails]") {
  83. SECTION("Test 1") {
  84. auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_ext_thumbnail());
  85. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  86. REQUIRE(errors.has(ThumbnailError::InvalidExt));
  87. REQUIRE(thumbnails.size() == 4);
  88. }
  89. SECTION("Test 2") {
  90. auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_ext_thumbnail2());
  91. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  92. REQUIRE(errors.has(ThumbnailError::InvalidExt));
  93. REQUIRE(thumbnails.size() == 4);
  94. }
  95. }
  96. TEST_CASE("Invalid value Thumbnails", "[Thumbnails]") {
  97. SECTION("Test 1") {
  98. auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail());
  99. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  100. REQUIRE(errors.has(ThumbnailError::InvalidVal));
  101. REQUIRE(thumbnails.size() == 3);
  102. }
  103. SECTION("Test 2") {
  104. auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail2());
  105. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  106. REQUIRE(errors.has(ThumbnailError::InvalidVal));
  107. REQUIRE(thumbnails.size() == 3);
  108. }
  109. SECTION("Test 3") {
  110. auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail3());
  111. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  112. REQUIRE(errors.has(ThumbnailError::InvalidVal));
  113. REQUIRE(thumbnails.size() == 3);
  114. }
  115. SECTION("Test 4") {
  116. auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail4());
  117. REQUIRE(errors != enum_bitmask<ThumbnailError>());
  118. REQUIRE(errors.has(ThumbnailError::InvalidVal));
  119. REQUIRE(thumbnails.size() == 2);
  120. }
  121. }