123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #include <catch2/catch.hpp>
- #include <test_utils.hpp>
- #include <libslic3r/GCode/Thumbnails.hpp>
- using namespace Slic3r;
- using namespace GCodeThumbnails;
- // Test Thumbnails lines
- static std::string empty_thumbnails()
- {
- return "";
- }
- static std::string valid_thumbnails()
- {
- return "160x120/PNG, 23x78/QOI, 230x780/JPG";
- }
- static std::string valid_thumbnails2()
- {
- return "160x120/PNG, 23x78/QOi, 320x240/PNg, 230x780/JPG";
- }
- static std::string out_of_range_thumbnail()
- {
- return "160x1200/PNG, 23x78/QOI, 320x240/PNG, 230x780/JPG";
- }
- static std::string out_of_range_thumbnail2()
- {
- return "160x120/PNG, 23x78/QOI, -320x240/PNG, 230x780/JPG";
- }
- static std::string invalid_ext_thumbnail()
- {
- return "160x120/PNk, 23x78/QOI, 320x240/PNG, 230x780/JPG";
- }
- static std::string invalid_ext_thumbnail2()
- {
- return "160x120/PNG, 23x78/QO, 320x240/PNG, 230x780/JPG";
- }
- static std::string invalid_val_thumbnail()
- {
- return "160x/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG";
- }
- static std::string invalid_val_thumbnail2()
- {
- return "x120/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG";
- }
- static std::string invalid_val_thumbnail3()
- {
- return "x/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG";
- }
- static std::string invalid_val_thumbnail4()
- {
- return "23*78/QOI, 320x240/PNG, 230x780/JPG";
- }
- TEST_CASE("Empty Thumbnails", "[Thumbnails]") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(empty_thumbnails());
- REQUIRE(errors == enum_bitmask<ThumbnailError>());
- REQUIRE(thumbnails.empty());
- }
- TEST_CASE("Valid Thumbnails", "[Thumbnails]") {
- SECTION("Test 1") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(valid_thumbnails());
- REQUIRE(errors == enum_bitmask<ThumbnailError>());
- REQUIRE(thumbnails.size() == 3);
- }
- SECTION("Test 2") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(valid_thumbnails2());
- REQUIRE(errors == enum_bitmask<ThumbnailError>());
- REQUIRE(thumbnails.size() == 4);
- }
- }
- TEST_CASE("Out of range Thumbnails", "[Thumbnails]") {
- SECTION("Test 1") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(out_of_range_thumbnail());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::OutOfRange));
- REQUIRE(thumbnails.size() == 3);
- }
- SECTION("Test 2") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(out_of_range_thumbnail2());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::OutOfRange));
- REQUIRE(thumbnails.size() == 3);
- }
- }
- TEST_CASE("Invalid extention Thumbnails", "[Thumbnails]") {
- SECTION("Test 1") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_ext_thumbnail());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::InvalidExt));
- REQUIRE(thumbnails.size() == 4);
- }
- SECTION("Test 2") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_ext_thumbnail2());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::InvalidExt));
- REQUIRE(thumbnails.size() == 4);
- }
- }
- TEST_CASE("Invalid value Thumbnails", "[Thumbnails]") {
- SECTION("Test 1") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::InvalidVal));
- REQUIRE(thumbnails.size() == 3);
- }
- SECTION("Test 2") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail2());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::InvalidVal));
- REQUIRE(thumbnails.size() == 3);
- }
- SECTION("Test 3") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail3());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::InvalidVal));
- REQUIRE(thumbnails.size() == 3);
- }
- SECTION("Test 4") {
- auto [thumbnails, errors] = make_and_check_thumbnail_list(invalid_val_thumbnail4());
- REQUIRE(errors != enum_bitmask<ThumbnailError>());
- REQUIRE(errors.has(ThumbnailError::InvalidVal));
- REQUIRE(thumbnails.size() == 2);
- }
- }
|