mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-01-30 23:48:44 +03:00
PRUSA 2.7.0
This commit is contained in:
13
tests/thumbnails/CMakeLists.txt
Normal file
13
tests/thumbnails/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
|
||||
|
||||
add_executable(${_TEST_NAME}_tests
|
||||
${_TEST_NAME}_tests_main.cpp
|
||||
test_thumbnails_input_string.cpp
|
||||
test_thumbnails_ini_string.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
||||
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${CATCH_EXTRA_ARGS})
|
||||
235
tests/thumbnails/test_thumbnails_ini_string.cpp
Normal file
235
tests/thumbnails/test_thumbnails_ini_string.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
|
||||
#include <libslic3r/GCode/Thumbnails.hpp>
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace GCodeThumbnails;
|
||||
|
||||
|
||||
static std::string empty_thumbnails()
|
||||
{
|
||||
return "thumbnails = \n"
|
||||
"thumbnails_format = ";
|
||||
}
|
||||
|
||||
static std::string valid_thumbnails()
|
||||
{
|
||||
return "thumbnails = 160x120/JPG, 23x78/QOI, 230x780/JPG\n"
|
||||
"thumbnails_format = JPG";
|
||||
}
|
||||
|
||||
static std::string valid_thumbnails2()
|
||||
{
|
||||
return "thumbnails = 160x120/PNG, 23x78/QOi, 320x240/PNg, 230x780/JPG\n"
|
||||
"thumbnails_format = pnG";
|
||||
}
|
||||
|
||||
static std::string valid_thumbnails3()
|
||||
{
|
||||
return "thumbnails = 160x120/JPG, 23x78/QOI, 230x780/JPG";
|
||||
}
|
||||
|
||||
static std::string old_valid_thumbnails()
|
||||
{
|
||||
return "thumbnails = 160x120\n"
|
||||
"thumbnails_format = JPG";
|
||||
}
|
||||
|
||||
static std::string old_valid_thumbnails2()
|
||||
{
|
||||
return "thumbnails = 160x120, 23x78, 320x240\n"
|
||||
"thumbnails_format = PNG";
|
||||
}
|
||||
|
||||
static std::string old_invalid_thumbnails()
|
||||
{
|
||||
return "thumbnails = 160x\n"
|
||||
"thumbnails_format = JPG";
|
||||
}
|
||||
|
||||
static std::string old_invalid_thumbnails2()
|
||||
{
|
||||
return "thumbnails = 160x120, 23*78, 320x240\n"
|
||||
"thumbnails_format = PNG";
|
||||
}
|
||||
|
||||
static std::string out_of_range_thumbnails()
|
||||
{
|
||||
return "thumbnails = 1160x1200/PNG, 23x78/QOI, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = PNG";
|
||||
}
|
||||
|
||||
static std::string out_of_range_thumbnails2()
|
||||
{
|
||||
return "thumbnails = 1160x120/PNG, 23x78/QOI, -320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = PNG";
|
||||
}
|
||||
|
||||
static std::string invalid_ext_thumbnails()
|
||||
{
|
||||
return "thumbnails = 1160x120/PNk, 23x78/QOI, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = QOI";
|
||||
}
|
||||
|
||||
static std::string invalid_ext_thumbnails2()
|
||||
{
|
||||
return "thumbnails = 1160x120/PNG, 23x78/QO, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = PNG";
|
||||
}
|
||||
|
||||
static std::string invalid_val_thumbnails()
|
||||
{
|
||||
return "thumbnails = 1160x/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = JPG";
|
||||
}
|
||||
|
||||
static std::string invalid_val_thumbnails2()
|
||||
{
|
||||
return "thumbnails = x120/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = PNG";
|
||||
}
|
||||
|
||||
static std::string invalid_val_thumbnails3()
|
||||
{
|
||||
return "thumbnails = 1x/PNg, 23x78/QOI, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = qoi";
|
||||
}
|
||||
|
||||
static std::string invalid_val_thumbnails4()
|
||||
{
|
||||
return "thumbnails = 123*78/QOI, 320x240/PNG, 230x780/JPG\n"
|
||||
"thumbnails_format = jpG";
|
||||
}
|
||||
|
||||
static DynamicPrintConfig thumbnails_config()
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.apply_only(FullPrintConfig::defaults() , { "thumbnails", "thumbnails_format" });
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
TEST_CASE("Validate Empty Thumbnails", "[Thumbnails in Config]") {
|
||||
DynamicPrintConfig config = thumbnails_config();
|
||||
|
||||
auto test_loaded_config = [](DynamicPrintConfig& config) {
|
||||
REQUIRE(config.opt<ConfigOptionString>("thumbnails")->empty());
|
||||
REQUIRE(config.option("thumbnails_format")->getInt() == (int)GCodeThumbnailsFormat::PNG);
|
||||
};
|
||||
|
||||
SECTION("Load empty init_data") {
|
||||
REQUIRE_NOTHROW(config.load_from_ini_string("", Enable));
|
||||
test_loaded_config(config);
|
||||
}
|
||||
|
||||
SECTION("Load empty format and empty thumbnails") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(empty_thumbnails(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Validate New Thumbnails", "[Thumbnails in Config]") {
|
||||
|
||||
DynamicPrintConfig config = thumbnails_config();
|
||||
|
||||
auto test_loaded_config = [](DynamicPrintConfig& config, GCodeThumbnailsFormat format) {
|
||||
REQUIRE(!config.opt<ConfigOptionString>("thumbnails")->empty());
|
||||
REQUIRE(config.option("thumbnails_format")->getInt() == (int)format);
|
||||
};
|
||||
|
||||
SECTION("Test 1 (valid)") {
|
||||
REQUIRE_NOTHROW(config.load_from_ini_string(valid_thumbnails(), Enable));
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::JPG);
|
||||
}
|
||||
|
||||
SECTION("Test 2 (valid)") {
|
||||
REQUIRE_NOTHROW(config.load_from_ini_string(valid_thumbnails2(), Enable));
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
SECTION("Test 3 (valid)") {
|
||||
REQUIRE_NOTHROW(config.load_from_ini_string(valid_thumbnails3(), Enable));
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
|
||||
SECTION("Test 1 (out_of_range)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(out_of_range_thumbnails(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
SECTION("Test 2 (out_of_range)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(out_of_range_thumbnails2(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
|
||||
SECTION("Test 1 (invalid_ext)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(invalid_ext_thumbnails(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::QOI);
|
||||
}
|
||||
|
||||
SECTION("Test 2 (invalid_ext)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(invalid_ext_thumbnails2(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
|
||||
SECTION("Test 1 (invalid_val)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(invalid_val_thumbnails(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::JPG);
|
||||
}
|
||||
|
||||
SECTION("Test 2 (invalid_val)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(invalid_val_thumbnails2(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
SECTION("Test 3 (invalid_val)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(invalid_val_thumbnails3(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
SECTION("Test 4 (invalid_val)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(invalid_val_thumbnails4(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Validate Old Thumbnails", "[Thumbnails in Config]") {
|
||||
|
||||
DynamicPrintConfig config = thumbnails_config();
|
||||
|
||||
auto test_loaded_config = [](DynamicPrintConfig& config, GCodeThumbnailsFormat format) {
|
||||
REQUIRE(!config.opt<ConfigOptionString>("thumbnails")->empty());
|
||||
REQUIRE(config.option("thumbnails_format")->getInt() == (int)format);
|
||||
};
|
||||
|
||||
SECTION("Test 1 (valid)") {
|
||||
REQUIRE_NOTHROW(config.load_from_ini_string(old_valid_thumbnails(), Enable));
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::JPG);
|
||||
}
|
||||
|
||||
SECTION("Test 2 (valid)") {
|
||||
REQUIRE_NOTHROW(config.load_from_ini_string(old_valid_thumbnails2(), Enable));
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
|
||||
SECTION("Test 1 (invalid)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(old_invalid_thumbnails(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::JPG);
|
||||
}
|
||||
|
||||
SECTION("Test 2 (invalid)") {
|
||||
REQUIRE_THROWS_AS(config.load_from_ini_string(old_invalid_thumbnails2(), Enable), BadOptionValueException);
|
||||
test_loaded_config(config, GCodeThumbnailsFormat::PNG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
152
tests/thumbnails/test_thumbnails_input_string.cpp
Normal file
152
tests/thumbnails/test_thumbnails_input_string.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
1
tests/thumbnails/thumbnails_tests_main.cpp
Normal file
1
tests/thumbnails/thumbnails_tests_main.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <catch_main.hpp>
|
||||
Reference in New Issue
Block a user