QIDISlicer1.0.0

This commit is contained in:
sunsets
2023-06-10 10:14:12 +08:00
parent f2e20e1a90
commit b4cd486f2d
3475 changed files with 1973675 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
add_executable(${_TEST_NAME}_tests
${_TEST_NAME}_tests_main.cpp
slic3r_jobs_tests.cpp
slic3r_version_tests.cpp
)
# mold linker for successful linking needs also to link TBB library and link it before libslic3r.
target_link_libraries(${_TEST_NAME}_tests test_common TBB::tbb TBB::tbbmalloc libslic3r_gui libslic3r)
if (MSVC)
target_link_libraries(${_TEST_NAME}_tests Setupapi.lib)
endif ()
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
if (WIN32)
qidislicer_copy_dlls(${_TEST_NAME}_tests)
endif()
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
set(_catch_args "exclude:[NotWorking]")
list(APPEND _catch_args "${CATCH_EXTRA_ARGS}")
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${_catch_args})

View File

@@ -0,0 +1,165 @@
#include "catch2/catch.hpp"
#include <chrono>
#include <thread>
#include "slic3r/GUI/Jobs/BoostThreadWorker.hpp"
#include "slic3r/GUI/Jobs/UIThreadWorker.hpp"
#include "slic3r/GUI/Jobs/ProgressIndicator.hpp"
struct Progress: Slic3r::ProgressIndicator {
int range = 100;
int pr = 0;
std::string statustxt;
void set_range(int r) override { range = r; }
void set_cancel_callback(CancelFn = CancelFn()) override {}
void set_progress(int p) override { pr = p; }
void set_status_text(const char *txt) override { statustxt = txt; }
int get_range() const override { return range; }
};
using TestClasses = std::tuple< Slic3r::GUI::UIThreadWorker, Slic3r::GUI::BoostThreadWorker >;
TEMPLATE_LIST_TEST_CASE("Empty worker should not do anything", "[Jobs]", TestClasses) {
TestType worker{std::make_unique<Progress>()};
REQUIRE(worker.is_idle());
worker.wait_for_current_job();
worker.process_events();
REQUIRE(worker.is_idle());
}
TEMPLATE_LIST_TEST_CASE("nullptr job should be ignored", "[Jobs]", TestClasses) {
TestType worker{std::make_unique<Progress>()};
worker.push(nullptr);
REQUIRE(worker.is_idle());
}
TEMPLATE_LIST_TEST_CASE("State should not be idle while running a job", "[Jobs]", TestClasses) {
using namespace Slic3r;
using namespace Slic3r::GUI;
TestType worker{std::make_unique<Progress>(), "worker_thread"};
queue_job(worker, [&worker](Job::Ctl &ctl) {
ctl.call_on_main_thread([&worker] {
REQUIRE(!worker.is_idle());
}).wait();
});
worker.wait_for_idle();
REQUIRE(worker.is_idle());
}
TEMPLATE_LIST_TEST_CASE("Status messages should be received by the main thread during job execution", "[Jobs]", TestClasses) {
using namespace Slic3r;
using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>();
TestType worker{pri};
queue_job(worker, [](Job::Ctl &ctl){
for (int s = 0; s <= 100; ++s) {
ctl.update_status(s, "Running");
}
});
worker.wait_for_idle();
REQUIRE(pri->pr == 100);
REQUIRE(pri->statustxt == "Running");
}
TEMPLATE_LIST_TEST_CASE("Cancellation should be recognized be the worker", "[Jobs]", TestClasses) {
using namespace Slic3r;
using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>();
TestType worker{pri};
queue_job(
worker,
[](Job::Ctl &ctl) {
for (int s = 0; s <= 100; ++s) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
ctl.update_status(s, "Running");
if (ctl.was_canceled()) break;
}
},
[](bool cancelled, std::exception_ptr &) { // finalize
REQUIRE(cancelled == true);
});
std::this_thread::sleep_for(std::chrono::milliseconds(1));
worker.cancel();
worker.wait_for_current_job();
REQUIRE(pri->pr != 100);
}
TEMPLATE_LIST_TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]", TestClasses) {
using namespace Slic3r;
using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>();
TestType worker{pri};
std::array<bool, 4> jobres = {false, false, false, false};
queue_job(worker, [&jobres](Job::Ctl &) {
jobres[0] = true;
// FIXME: the long wait time is needed to prevent fail in MSVC
// where the sleep_for function is behaving stupidly.
// see https://developercommunity.visualstudio.com/t/bogus-stdthis-threadsleep-for-implementation/58530
std::this_thread::sleep_for(std::chrono::seconds(1));
});
queue_job(worker, [&jobres](Job::Ctl &) {
jobres[1] = true;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
});
queue_job(worker, [&jobres](Job::Ctl &) {
jobres[2] = true;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
});
queue_job(worker, [&jobres](Job::Ctl &) {
jobres[3] = true;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
});
// wait until the first job's half time to be sure, the cancel is made
// during the first job's execution.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
worker.cancel_all();
REQUIRE(jobres[0] == true);
REQUIRE(jobres[1] == false);
REQUIRE(jobres[2] == false);
REQUIRE(jobres[3] == false);
}
TEMPLATE_LIST_TEST_CASE("Exception should be properly forwarded to finalize()", "[Jobs]", TestClasses) {
using namespace Slic3r;
using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>();
TestType worker{pri};
queue_job(
worker, [](Job::Ctl &) { throw std::runtime_error("test"); },
[](bool /*canceled*/, std::exception_ptr &eptr) {
REQUIRE(eptr != nullptr);
try {
std::rethrow_exception(eptr);
} catch (std::runtime_error &e) {
REQUIRE(std::string(e.what()) == "test");
}
eptr = nullptr;
});
worker.wait_for_idle();
REQUIRE(worker.is_idle());
}

View File

@@ -0,0 +1,83 @@
#include "catch2/catch.hpp"
#include "slic3r/Config/Version.hpp"
TEST_CASE("Check parsing and comparing of config versions", "[Version]") {
using namespace Slic3r;
GUI::Config::Version v;
v.config_version = *Semver::parse("1.1.2");
v.min_slic3r_version = *Semver::parse("1.38.0");
v.max_slic3r_version = Semver::inf();
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.38.0")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha")));
// Test the prerelease status.
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0")));
v.config_version = *Semver::parse("1.1.2-alpha");
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
v.config_version = *Semver::parse("1.1.2-alpha1");
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
v.config_version = *Semver::parse("1.1.2-beta");
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
v.config_version = *Semver::parse("1.1.2-rc");
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-rc")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
v.config_version = *Semver::parse("1.1.2-rc2");
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-rc")));
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
// Test the upper boundary.
v.config_version = *Semver::parse("1.1.2");
v.max_slic3r_version = *Semver::parse("1.39.3-beta1");
REQUIRE(v.is_slic3r_supported(*Semver::parse("1.38.0")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha1")));
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha")));
}

View File

@@ -0,0 +1,60 @@
#include <catch_main.hpp>
#include "slic3r/Utils/Http.hpp"
TEST_CASE("Check SSL certificates paths", "[Http][NotWorking]") {
Slic3r::Http g = Slic3r::Http::get("https://github.com/");
unsigned status = 0;
g.on_error([&status](std::string, std::string, unsigned http_status) {
status = http_status;
});
g.on_complete([&status](std::string /* body */, unsigned http_status){
status = http_status;
});
g.perform_sync();
REQUIRE(status == 200);
}
TEST_CASE("Http digest authentication", "[Http][NotWorking]") {
Slic3r::Http g = Slic3r::Http::get("https://jigsaw.w3.org/HTTP/Digest/");
g.auth_digest("guest", "guest");
unsigned status = 0;
g.on_error([&status](std::string, std::string, unsigned http_status) {
status = http_status;
});
g.on_complete([&status](std::string /* body */, unsigned http_status){
status = http_status;
});
g.perform_sync();
REQUIRE(status == 200);
}
TEST_CASE("Http basic authentication", "[Http][NotWorking]") {
Slic3r::Http g = Slic3r::Http::get("https://jigsaw.w3.org/HTTP/Basic/");
g.auth_basic("guest", "guest");
unsigned status = 0;
g.on_error([&status](std::string, std::string, unsigned http_status) {
status = http_status;
});
g.on_complete([&status](std::string /* body */, unsigned http_status){
status = http_status;
});
g.perform_sync();
REQUIRE(status == 200);
}