From 33c4c814033a9683ebc482aa192cb35adc74bcb1 Mon Sep 17 00:00:00 2001 From: flagarde Date: Wed, 8 May 2024 18:51:36 +0800 Subject: [PATCH] Fixes --- .github/workflows/pre-commit.yml | 2 +- .pre-commit-config.yaml | 10 +- include/khaos/CompareVersionMacros.h | 5 +- include/khaos/KhaosVersion.h.in | 11 +- include/khaos/VersionMacros.h | 37 ++----- tests/CompareVersionMacros.test.cpp | 148 +++++++++++++-------------- tests/KhaosVersion.test.cpp | 7 +- tests/VersionMacros.test.cpp | 10 +- 8 files changed, 102 insertions(+), 128 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 74d1655..de0670e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -20,7 +20,7 @@ jobs: - name: 🔧 Configure run: cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=ON -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_NUMBER_JOBS=2 -DCMAKE_NUMBER_JOBS_TESTS=1 - + - uses: pre-commit/action@v3.0.1 - uses: pre-commit-ci/lite-action@v1.0.2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 643c0b2..a4507f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -85,15 +85,15 @@ repos: - id: cmake-lint args: [--config=.cmake-linter.yml] -- repo: repo: https://github.com/Takishima/cmake-pre-commit-hooks +- repo: https://github.com/Takishima/cmake-pre-commit-hooks rev: v1.8.0 hooks: - id: clang-tidy args: [-Bbuild, --config=] - - id: cppcheck-conda - args: [-Bbuild, --suppressions-list=.cppcheck] - - id: include-what-you-use-conda - args: [-Bbuild, -p, build, --jobs, '10'] + #- id: cppcheck-conda + # args: [-Bbuild, --suppressions-list=.cppcheck] + #- id: include-what-you-use-conda + # args: [-Bbuild, -p, build, --jobs, '10'] - repo: https://gitlab.com/daverona/pre-commit/cpp rev: 0.8.0 diff --git a/include/khaos/CompareVersionMacros.h b/include/khaos/CompareVersionMacros.h index 93d54e1..b5c6540 100644 --- a/include/khaos/CompareVersionMacros.h +++ b/include/khaos/CompareVersionMacros.h @@ -19,16 +19,17 @@ */ /** \hideinitializer - * \brief Check the \b version with \b major, \b minor, \b patch using the operator \b op + * \brief Check the \b version with \b major, \b minor, \b patch, \b tweak using the operator \b op * \param[in] version version to compare. * \param[in] op operator =, !=, >=, <= >, < . * \param[in] major major part. * \param[in] minor minor part. * \param[in] patch patch part. + * \param[in] tweak tweak part. * * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. */ -#define CHECK_VERSION(version, op, major, minor, patch) ((KHAOS_VERSION_##version##_PRIVATE())op(SET_VERSION(major, minor, patch))) +#define CHECK_VERSION(version, op, major, minor, patch, tweak) ((KHAOS_VERSION_##version##_PRIVATE())op(SET_VERSION(major, minor, patch, tweak))) /** \hideinitializer * \brief Check the \b versiona with \b versionb using the operator \b op diff --git a/include/khaos/KhaosVersion.h.in b/include/khaos/KhaosVersion.h.in index a84f882..d06b583 100644 --- a/include/khaos/KhaosVersion.h.in +++ b/include/khaos/KhaosVersion.h.in @@ -26,16 +26,7 @@ \note Use #GET_VERSION_MAJOR(Khaos), #GET_VERSION_MINOR(Khaos), #GET_VERSION_PATCH(Khaos) to parse it. */ /* clang-format off */ -#define KHAOS_VERSION_Khaos_PRIVATE() SET_VERSION(@Khaos_VERSION_MAJOR@UL,@Khaos_VERSION_MINOR@UL,@Khaos_VERSION_PATCH@UL) -/* clang-format on */ - -/*! - \brief Khaos version tweak. \hideinitializer - \returns Khaos version tweak in integer literal UL form. - \note Use #GET_VERSION_TWEAK(Khaos) to parse it. -*/ -/* clang-format off */ -#define KHAOS_VERSION_Khaos_TWEAK_PRIVATE() SET_VERSION_TWEAK(@Khaos_VERSION_TWEAK@UL) +#define KHAOS_VERSION_Khaos_PRIVATE() SET_VERSION(@Khaos_VERSION_MAJOR@ULL,@Khaos_VERSION_MINOR@ULL,@Khaos_VERSION_PATCH@ULL,@Khaos_VERSION_TWEAK@ULL) /* clang-format on */ #endif /* KHAOS_KHAOSVERSION_H_ */ diff --git a/include/khaos/VersionMacros.h b/include/khaos/VersionMacros.h index 8c2c390..e29b50d 100644 --- a/include/khaos/VersionMacros.h +++ b/include/khaos/VersionMacros.h @@ -1,9 +1,6 @@ #ifndef KHAOS_VERSIONMACROS_H_ #define KHAOS_VERSIONMACROS_H_ -#include "khaos/CompareVersionMacros.h" -#include "khaos/KhaosVersion.h" - /** \file VersionMacros.h * \copyright 2022 flagarde * \brief Define macros to set, get versions. @@ -20,11 +17,12 @@ /** \hideinitializer * \brief Set standard version numbers. - * \param[in] major The major number can be in the [0,255] range. - * \param[in] minor The minor number can be in the [0,255] range. + * \param[in] major The major number can be in the [0,65535] range. + * \param[in] minor The minor number can be in the [0,65535] range. * \param[in] patch The patch number can be in the [0,65535] range. + * \param[in] tweak The tweak number can be in the [0,65535] range. * - * \remarks The number range is designed to allow for a (8,8,16) triplet; Which fits within a 32 bit value. + * \remarks The number range is designed to allow for a (16,16,16,16) quadruplet; Which fits within a 64 bit value. * * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. * \note Values can be specified in any base. As the defined value is an constant expression. @@ -32,25 +30,10 @@ * \warning Values over the ranges are truncated (modulo). * \warning The name of the macro must be of the form KHAOS_VERSION_name_PRIVATE() to be able to be parsed by the Khaos library. * \code{.cpp} - * #define KHAOS_VERSION_myversion_PRIVATE() SET_VERSION(2,3,4) - * \endcode - */ -#define SET_VERSION(major, minor, patch) ((((major)*1UL % 256) << 24) + (((minor)*1UL % 256) << 16) + ((patch)*1UL % 65536)) - -/** \hideinitializer - * \brief Set standard tweak (build) numbers. - * \param[in] tweak The tweak number can be in the [0,9999] range. - * - * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. - * \note Values can be specified in any base. As the defined value is an constant expression. - * \note The implementation enforces the individual ranges for the major, minor, and patch numbers. - * \warning Values over the ranges are truncated (modulo). - * \warning The name of the macro must be of the form KHAOS_name_VERSION_TWEAK_PRIVATE() to be able to be parsed by the Khaos library. - * \code{.cpp} - * #define KHAOS_VERSION_myversion_TWEAK_PRIVATE() SET_VERSION_TWEAK(10) + * #define KHAOS_VERSION_myversion_PRIVATE() SET_VERSION(2,3,4,5) * \endcode */ -#define SET_VERSION_TWEAK(tweak) ((tweak)*1UL % 65536) +#define SET_VERSION(major, minor, patch, tweak) ((((major)*1ULL % 65536) << 48) + (((minor)*1ULL % 65536) << 32) + (((patch)*1ULL % 65536) << 16) + ((tweak)*1ULL % 65536)) /** \hideinitializer * \brief Get standard major version numbers. @@ -58,7 +41,7 @@ * * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. */ -#define GET_VERSION_MAJOR(version) (((KHAOS_VERSION_##version##_PRIVATE()) * 1UL >> 24) % 256) +#define GET_VERSION_MAJOR(version) ((((KHAOS_VERSION_##version##_PRIVATE()) * 1ULL) >> 48) % 65536) /** \hideinitializer * \brief Get standard minor version numbers. @@ -66,7 +49,7 @@ * * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. */ -#define GET_VERSION_MINOR(version) (((KHAOS_VERSION_##version##_PRIVATE()) * 1UL >> 16) % 256) +#define GET_VERSION_MINOR(version) ((((KHAOS_VERSION_##version##_PRIVATE()) * 1ULL) >> 32) % 65536) /** \hideinitializer * \brief Get standard patch version numbers. @@ -74,7 +57,7 @@ * * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. */ -#define GET_VERSION_PATCH(version) ((KHAOS_VERSION_##version##_PRIVATE()) * 1UL % 65536) +#define GET_VERSION_PATCH(version) ((((KHAOS_VERSION_##version##_PRIVATE()) * 1ULL) >> 16) % 65536) /** \hideinitializer * \brief Get standard tweak version numbers. @@ -82,6 +65,6 @@ * * \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values. */ -#define GET_VERSION_TWEAK(version) ((KHAOS_VERSION_##version##_TWEAK_PRIVATE()) * 1UL % 65536) +#define GET_VERSION_TWEAK(version) (((KHAOS_VERSION_##version##_PRIVATE()) * 1ULL) % 65536) #endif /* KHAOS_VERSIONMACROS_H_ */ diff --git a/tests/CompareVersionMacros.test.cpp b/tests/CompareVersionMacros.test.cpp index 7ce87bf..905828e 100644 --- a/tests/CompareVersionMacros.test.cpp +++ b/tests/CompareVersionMacros.test.cpp @@ -11,127 +11,127 @@ TEST_CASE("Test CHECK_VERSION(x,>,major,minor,patch)") { - CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR, MINOR, PATCH)); - CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR, MINOR, PATCH + 1)); - CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR, MINOR + 1, PATCH)); - CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR + 1, MINOR, PATCH)); -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); + CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR, MINOR, PATCH, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR, MINOR, PATCH + 1, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR, MINOR + 1, PATCH, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, >, MAJOR + 1, MINOR, PATCH, TWEAK)); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1) - CHECK_EQ(1, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE } TEST_CASE("Test CHECK_VERSION(x,>=,major,minor,patch)") { - CHECK_EQ(1, CHECK_VERSION(Khaos, >=, MAJOR, MINOR, PATCH)); - CHECK_EQ(0, CHECK_VERSION(Khaos, >=, MAJOR, MINOR, PATCH + 1)); - CHECK_EQ(0, CHECK_VERSION(Khaos, >=, MAJOR, MINOR + 1, PATCH)); - CHECK_EQ(0, CHECK_VERSION(Khaos, >=, MAJOR + 1, MINOR, PATCH)); -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); + CHECK_EQ(1, CHECK_VERSION(Khaos, >=, MAJOR, MINOR, PATCH, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, >=, MAJOR, MINOR, PATCH + 1, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, >=, MAJOR, MINOR + 1, PATCH, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, >=, MAJOR + 1, MINOR, PATCH, TWEAK)); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1) - CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, >=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE } TEST_CASE("Test CHECK_VERSION(x,==,major,minor,patch)") { - CHECK_EQ(1, CHECK_VERSION(Khaos, ==, MAJOR, MINOR, PATCH)); - CHECK_EQ(0, CHECK_VERSION(Khaos, ==, MAJOR, MINOR, PATCH + 1)); - CHECK_EQ(0, CHECK_VERSION(Khaos, ==, MAJOR, MINOR + 1, PATCH)); - CHECK_EQ(0, CHECK_VERSION(Khaos, ==, MAJOR + 1, MINOR, PATCH)); -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); + CHECK_EQ(1, CHECK_VERSION(Khaos, ==, MAJOR, MINOR, PATCH, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, ==, MAJOR, MINOR, PATCH + 1, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, ==, MAJOR, MINOR + 1, PATCH, TWEAK)); + CHECK_EQ(0, CHECK_VERSION(Khaos, ==, MAJOR + 1, MINOR, PATCH, TWEAK)); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1) - CHECK_EQ(0, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, ==, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE } TEST_CASE("Test CHECK_VERSION(x,<=,major,minor,patch)") { - CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR, MINOR, PATCH)); - CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR, MINOR, PATCH + 1)); - CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR, MINOR + 1, PATCH)); - CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR + 1, MINOR, PATCH)); -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); + CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR, MINOR, PATCH, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR, MINOR, PATCH + 1, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR, MINOR + 1, PATCH, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, <=, MAJOR + 1, MINOR, PATCH, TWEAK)); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1) - CHECK_EQ(0, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE } TEST_CASE("Test CHECK_VERSION(x,<,major,minor,patch)") { - CHECK_EQ(0, CHECK_VERSION(Khaos, <, MAJOR, MINOR, PATCH)); - CHECK_EQ(1, CHECK_VERSION(Khaos, <, MAJOR, MINOR, PATCH + 1)); - CHECK_EQ(1, CHECK_VERSION(Khaos, <, MAJOR, MINOR + 1, PATCH)); - CHECK_EQ(1, CHECK_VERSION(Khaos, <, MAJOR + 1, MINOR, PATCH)); -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); + CHECK_EQ(0, CHECK_VERSION(Khaos, <, MAJOR, MINOR, PATCH, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, <, MAJOR, MINOR, PATCH + 1, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, <, MAJOR, MINOR + 1, PATCH, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, <, MAJOR + 1, MINOR, PATCH, TWEAK)); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1) - CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, <, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE } TEST_CASE("Test CHECK_VERSION(x,!=,major,minor,patch)") { - CHECK_EQ(0, CHECK_VERSION(Khaos, !=, MAJOR, MINOR, PATCH)); - CHECK_EQ(1, CHECK_VERSION(Khaos, !=, MAJOR, MINOR, PATCH + 1)); - CHECK_EQ(1, CHECK_VERSION(Khaos, !=, MAJOR, MINOR + 1, PATCH)); - CHECK_EQ(1, CHECK_VERSION(Khaos, !=, MAJOR + 1, MINOR, PATCH)); -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) - CHECK_EQ(0, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); + CHECK_EQ(0, CHECK_VERSION(Khaos, !=, MAJOR, MINOR, PATCH, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, !=, MAJOR, MINOR, PATCH + 1, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, !=, MAJOR, MINOR + 1, PATCH, TWEAK)); + CHECK_EQ(1, CHECK_VERSION(Khaos, !=, MAJOR + 1, MINOR, PATCH, TWEAK)); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) + CHECK_EQ(0, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1) - CHECK_EQ(1, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH + 1, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR, MINOR + 1, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) - CHECK_EQ(1, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos))); +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) + CHECK_EQ(1, CHECK_VERSION(Test, !=, GET_VERSION_MAJOR(Khaos), GET_VERSION_MINOR(Khaos), GET_VERSION_PATCH(Khaos), GET_VERSION_TWEAK(Khaos))); #undef KHAOS_VERSION_Test_PRIVATE } /* Test CHECK_VERSIONS */ -#define KHAOS_VERSION_Test1_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH) -#define KHAOS_VERSION_Test2_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH) +#define KHAOS_VERSION_Test1_PRIVATE() SET_VERSION(MAJOR, MINOR, PATCH, TWEAK) +#define KHAOS_VERSION_Test2_PRIVATE() SET_VERSION(MAJOR + 1, MINOR, PATCH, TWEAK) TEST_CASE("Test CHECK_VERSIONS(x,>,y)") { CHECK_EQ(0, CHECK_VERSIONS(Test1, >, Test2)); } TEST_CASE("Test CHECK_VERSIONS(x,>=,y)") { CHECK_EQ(0, CHECK_VERSIONS(Test1, >=, Test2)); } diff --git a/tests/KhaosVersion.test.cpp b/tests/KhaosVersion.test.cpp index c3ee525..0f88b73 100644 --- a/tests/KhaosVersion.test.cpp +++ b/tests/KhaosVersion.test.cpp @@ -1,11 +1,10 @@ /* Copyright 2022 flagarde */ - #include "khaos/KhaosVersion.h" +#include + // NOLINTBEGIN #include "doctest/doctest.h" // NOLINTEND -TEST_CASE("Test KHAOS_VERSION") { CHECK_EQ((((MAJOR) % 100) * 10000000) + (((MINOR) % 100) * 100000) + ((PATCH) % 100000), KHAOS_VERSION_Khaos_PRIVATE()); } - -TEST_CASE("Test KHAOS_VERSION_TWEAK") { CHECK_EQ(static_cast(TWEAK), static_cast(KHAOS_VERSION_Khaos_TWEAK_PRIVATE())); } +TEST_CASE("Test KHAOS_VERSION") { CHECK_EQ((((MAJOR) % 65536) * pow(2, 48)) + (((MINOR) % 65536) * pow(2, 32)) + (((PATCH) % 65536) * pow(2, 16)) + ((TWEAK) % 65536), KHAOS_VERSION_Khaos_PRIVATE()); } diff --git a/tests/VersionMacros.test.cpp b/tests/VersionMacros.test.cpp index 4f12646..0293463 100644 --- a/tests/VersionMacros.test.cpp +++ b/tests/VersionMacros.test.cpp @@ -2,14 +2,14 @@ #include "khaos/VersionMacros.h" +#include "khaos/KhaosVersion.h" + // NOLINTBEGIN #include "doctest/doctest.h" // NOLINTEND -#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(2, 3, 4) -#define KHAOS_VERSION_Test2_PRIVATE() SET_VERSION(256, 256, 65536) /* Should be seen as 0.0.0 */ -#define KHAOS_VERSION_Test_TWEAK_PRIVATE() SET_VERSION_TWEAK(5) -#define KHAOS_VERSION_Test2_TWEAK_PRIVATE() SET_VERSION_TWEAK(65536) /* Should be seen as 0 */ +#define KHAOS_VERSION_Test_PRIVATE() SET_VERSION(2, 3, 4, 5) +#define KHAOS_VERSION_Test2_PRIVATE() SET_VERSION(65536, 65536, 65536, 65536) /* Should be seen as 0.0.0.0 */ TEST_CASE("Test GET_VERSION_MAJOR(x)") { @@ -40,4 +40,4 @@ TEST_CASE("Test GET_VERSION_TWEAK(x)") } #undef KHAOS_VERSION_Test_PRIVATE -#undef KHAOS_VERSION_Test_TWEAK_PRIVATE +#undef KHAOS_VERSION_Test_PRIVATE2