From 49c817c40b32a6c2eb776a9742552767ec33074f Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 30 Sep 2022 13:45:30 +0200 Subject: [PATCH] Resurrected an old test case for parsing and comparing config version numbers --- src/slic3r/Config/Version.cpp | 75 +------------------ tests/slic3rutils/CMakeLists.txt | 1 + tests/slic3rutils/slic3r_version_tests.cpp | 83 ++++++++++++++++++++++ 3 files changed, 85 insertions(+), 74 deletions(-) create mode 100644 tests/slic3rutils/slic3r_version_tests.cpp diff --git a/src/slic3r/Config/Version.cpp b/src/slic3r/Config/Version.cpp index 04ce05ab5..1de709078 100644 --- a/src/slic3r/Config/Version.cpp +++ b/src/slic3r/Config/Version.cpp @@ -69,80 +69,7 @@ bool Version::is_current_slic3r_downgrade() const { return Slic3r::SEMVER < min_slic3r_version; } -#if 0 -//TODO: This test should be moved to a unit test, once we have C++ unit tests in place. -static int version_test() -{ - 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(); - assert(v.is_slic3r_supported(*Semver::parse("1.38.0"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha"))); - // Test the prerelease status. - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0"))); - v.config_version = *Semver::parse("1.1.2-alpha"); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0"))); - v.config_version = *Semver::parse("1.1.2-alpha1"); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0"))); - v.config_version = *Semver::parse("1.1.2-beta"); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0"))); - v.config_version = *Semver::parse("1.1.2-rc"); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.39.0"))); - v.config_version = *Semver::parse("1.1.2-rc2"); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc"))); - assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2"))); - assert(! 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"); - assert(v.is_slic3r_supported(*Semver::parse("1.38.0"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha1"))); - assert(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha"))); - return 0; -} -static int version_test_run = version_test(); -#endif + inline char* left_trim(char *c) { diff --git a/tests/slic3rutils/CMakeLists.txt b/tests/slic3rutils/CMakeLists.txt index e9fcf84f1..892e7a8a7 100644 --- a/tests/slic3rutils/CMakeLists.txt +++ b/tests/slic3rutils/CMakeLists.txt @@ -2,6 +2,7 @@ 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. diff --git a/tests/slic3rutils/slic3r_version_tests.cpp b/tests/slic3rutils/slic3r_version_tests.cpp new file mode 100644 index 000000000..14f4f5dc0 --- /dev/null +++ b/tests/slic3rutils/slic3r_version_tests.cpp @@ -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"))); +}