diff --git a/CHANGES.txt b/CHANGES.txt index 8147b6f..6c7d455 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,10 +19,12 @@ Updated: 23rd November 2024 23rd November 2024 - 0.26.0-alpha1 ================================== + * now uses `stlsoft::integral_traits<>` for integer test macros (in C++) to allow for custom integral types to be tested; * added terse forms of macros, available by including **xtests/terse-api.h**; * `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"`; - * updated **STLSoft** constructs, incl. macros; * minor improvements to project boilerplate files; + * minor tidying to CMake facilities; + * updated **STLSoft** constructs, incl. macros; 18th November 2024 - 0.25.4 diff --git a/CMakeLists.txt b/CMakeLists.txt index e60c8d8..100e064 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ # Purpose: Top-level CMake lists file for xTests # # Created: 9th October 2019 -# Updated: 17th November 2024 +# Updated: 23rd November 2024 # # ######################################################################## # @@ -76,6 +76,13 @@ if(MSVC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif(MSVC_USE_MT) +else(MSVC) + + if(MSVC_USE_MT) + + # this here just to absorb warning about not using `MSVC_USE_MT` (to + # enable **prepare_cmake.sh** to be simple) + endif(MSVC_USE_MT) endif(MSVC) diff --git a/HISTORY.md b/HISTORY.md index bb7bead..4624405 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,10 +4,12 @@ 23rd November 2024 - 0.26.0-alpha1 ---------------------------------- + * now uses `stlsoft::integral_traits<>` for integer test macros (in C++) to allow for custom integral types to be tested; * added terse forms of macros, available by including **xtests/terse-api.h**; * `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"`; - * updated **STLSoft** constructs, incl. macros; * minor improvements to project boilerplate files; + * minor tidying to CMake facilities; + * updated **STLSoft** constructs, incl. macros; 18th November 2024 - 0.25.4 diff --git a/include/xtests/xtests.h b/include/xtests/xtests.h index 750f863..c59291c 100644 --- a/include/xtests/xtests.h +++ b/include/xtests/xtests.h @@ -2,7 +2,7 @@ * File: xtests/xtests.h (formerly part of Synesis' internal test codebase) * * Purpose: Main header file for xTests, a simple unit/component-testing - * library. + * library for C and C++. * * Created: 20th June 1999 * Updated: 23rd November 2024 @@ -51,9 +51,9 @@ #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION # define XTESTS_VER_XTESTS_H_XTESTS_MAJOR 3 -# define XTESTS_VER_XTESTS_H_XTESTS_MINOR 44 +# define XTESTS_VER_XTESTS_H_XTESTS_MINOR 45 # define XTESTS_VER_XTESTS_H_XTESTS_REVISION 1 -# define XTESTS_VER_XTESTS_H_XTESTS_EDIT 380 +# define XTESTS_VER_XTESTS_H_XTESTS_EDIT 383 #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */ @@ -105,9 +105,9 @@ STLSOFT_VER >= 0x010c0000 # define XTESTS_STLSOFT_1_12_OR_LATER -#elif _STLSOFT_VER < 0x010b0159 +#elif _STLSOFT_VER < 0x010b015a -# error xTests requires version 1.11.1 alpha 25, or later, of STLSoft; download from https://github.com/synesissoftware/ +# error xTests requires version 1.11.1 alpha 26, or later, of STLSoft; obtain from https://github.com/synesissoftware/ #endif /* _STLSOFT_VER */ @@ -163,6 +163,9 @@ # include # endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */ # endif /* STLSOFT_MINIMUM_SAS_INCLUDES */ +# ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_TRAITS +# include +# endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_TRAITS */ # endif /* !_XTESTS_NO_CPP_API */ # if defined(STLSOFT_CF_EXCEPTION_SUPPORT) # include @@ -3537,8 +3540,8 @@ struct xtests_failure_reporter STLSOFT_STATIC_CAST(void, xtests_failure_reporter::xtests_report_failure_equal(file, line, function, expr, int(expected), int(actual), comp)); } }; - # ifdef STLSOFT_CF_SHORT_DISTINCT_INT_TYPE + template <> struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_sint16_t)> { @@ -3564,8 +3567,8 @@ struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_uint16_t)> } }; # endif /* STLSOFT_CF_SHORT_DISTINCT_INT_TYPE */ - # ifdef STLSOFT_CF_INT_DISTINCT_INT_TYPE + template <> struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_sint32_t)> { @@ -3617,8 +3620,8 @@ struct xtests_failure_reporter STLSOFT_STATIC_CAST(void, xtests_testFailed_ulong(file, line, function, expr, expected, actual, comp)); } }; - # ifdef STLSOFT_CF_64BIT_INT_SUPPORT + template <> struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_sint64_t)> { @@ -3646,20 +3649,6 @@ struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_uint64_t)> }; # endif /* STLSOFT_CF_64BIT_INT_SUPPORT */ -template <> -struct xtests_failure_reporter -{ - static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, int expected, int actual, xtests_comparison_t comp) - { -# ifndef _XTESTS_NO_NAMESPACE - using namespace ::xtests::c; -# endif /* _XTESTS_NO_NAMESPACE */ - - STLSOFT_STATIC_CAST(void, xtests_testFailed_boolean(file, line, function, expr, expected, actual, comp)); - } -}; - - template< typename T1 @@ -3718,6 +3707,7 @@ xtests_reportFailedIntegerComparison( _MSC_VER >= 1310 && \ !defined(_WIN64) && \ defined(_Wp64) + /* This special overload is to allow for cases such as: * * XTESTS_TEST_INTEGER_EQUAL(4u, sink.size()); @@ -3742,50 +3732,6 @@ xtests_reportFailedIntegerComparison( } # endif -inline -void -xtests_reportFailedIntegerComparison( - char const* file -, int line -, char const* function -, char const* expr -, bool expected -, bool actual -, xtests_comparison_t comp -) -{ -# ifndef _XTESTS_NO_NAMESPACE - using namespace ::xtests::c; -# endif /* _XTESTS_NO_NAMESPACE */ - -# if defined(STLSOFT_COMPILER_IS_BORLAND) - - xtests_integer_failure_reporter_selector::type::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp); -# else /* ? compiler */ - - typedef xtests_integer_failure_reporter_selector::type failure_reporter_t; - - failure_reporter_t::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp); -# endif /* compiler */ -} - -#if 0 -inline -void -xtests_reportFailedIntegerComparison( - char const* file -, int line -, char const* function -, char const* expr -, int expected -, bool actual -, xtests_comparison_t comp -) -{ - xtests_reportFailedIntegerComparison(file, line, function, expr, 0 != expected, actual, comp); -} -#endif /* 0 */ - inline void xtests_reportFailedFloatingPointComparison( @@ -3923,7 +3869,7 @@ template< > inline int -xtests_test_integer( +xtests_test_integer_( char const* file , int line , char const* function @@ -4006,6 +3952,34 @@ xtests_test_integer( return comparisonSucceeded; } +template< + typename I1 +, typename I2 +> +inline +int +xtests_test_integer( + char const* file +, int line +, char const* function +, char const* expr +, I1 const& expected +, I2 const& actual +, xtests_comparison_t comp +) +{ + return xtests_test_integer_( + file + , line + , function + , expr + , STLSOFT_NS_QUAL(integral_traits)::get_underlying_value(expected) + , STLSOFT_NS_QUAL(integral_traits)::get_underlying_value(actual) + , comp + ); +} + + struct boolean_test_must_involve_boolean_parameters {}; template @@ -4052,9 +4026,82 @@ xtests_test_boolean_( , STLSOFT_NS_QUAL(yes_type) ) { - bool const actual_as_bool = actual; +# ifndef _XTESTS_NO_NAMESPACE + using namespace ::xtests::c; +# endif /* _XTESTS_NO_NAMESPACE */ + + bool const actual_as_bool = !!actual; + + int comparisonSucceeded = false; + + switch (comp) + { + case xtestsComparisonEqual: + case xtestsComparisonApproxEqual: + + if (expected == actual_as_bool) + { + comparisonSucceeded = true; + } + break; + case xtestsComparisonNotEqual: + case xtestsComparisonApproxNotEqual: + + if (expected != actual_as_bool) + { + comparisonSucceeded = true; + } + break; +#if 0 /* NOTE: currently don't support ordering of `bool` */ + + case xtestsComparisonGreaterThan: + + if (actual_as_bool > expected) + { + comparisonSucceeded = true; + } + break; + case xtestsComparisonLessThan: + + if (actual_as_bool < expected) + { + comparisonSucceeded = true; + } + break; + case xtestsComparisonGreaterThanOrEqual: - return xtests_test_integer(file, line, function, expr, expected, actual_as_bool, comp); + if (actual_as_bool >= expected) + { + comparisonSucceeded = true; + } + break; + case xtestsComparisonLessThanOrEqual: + + if (actual_as_bool <= expected) + { + comparisonSucceeded = true; + } + break; +#endif + default: + + STLSOFT_MESSAGE_ASSERT("unrecognised enumerator", false); + case xtestsComparison_max_enumerator: + + xtests_abend("invalid test comparison type: test framework may be out of date!"); + break; + } + + if (comparisonSucceeded) + { + xtests_testPassed(file, line, function, expr); + } + else + { + STLSOFT_STATIC_CAST(void, xtests_testFailed_boolean(file, line, function, expr, expected, actual_as_bool, comp)); + } + + return comparisonSucceeded; } template @@ -4072,7 +4119,7 @@ xtests_test_boolean( { typedef ss_typename_type_k boolean_argument_traits::yesno_type yesno_t; - return xtests_test_boolean_(file, line, function, expr, expected, !!actual, comp, yesno_t()); + return xtests_test_boolean_(file, line, function, expr, expected, actual, comp, yesno_t()); } diff --git a/test/scratch/CMakeLists.txt b/test/scratch/CMakeLists.txt index 3721a3a..66e874c 100644 --- a/test/scratch/CMakeLists.txt +++ b/test/scratch/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(test.scratch.basics1) add_subdirectory(test.scratch.basics2) add_subdirectory(test.scratch.basics2.terse) +add_subdirectory(test.scratch.custom_integral_types) add_subdirectory(test.scratch.fail_all.1) add_subdirectory(test.scratch.integer_comparisons.c) add_subdirectory(test.scratch.setup.fail) diff --git a/test/scratch/test.scratch.custom_integral_types/CMakeLists.txt b/test/scratch/test.scratch.custom_integral_types/CMakeLists.txt new file mode 100644 index 0000000..5270b55 --- /dev/null +++ b/test/scratch/test.scratch.custom_integral_types/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.scratch.custom_integral_types entry.cpp) diff --git a/test/scratch/test.scratch.custom_integral_types/entry.cpp b/test/scratch/test.scratch.custom_integral_types/entry.cpp new file mode 100644 index 0000000..c8243d9 --- /dev/null +++ b/test/scratch/test.scratch.custom_integral_types/entry.cpp @@ -0,0 +1,120 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test.scratch.custom_integral_types/entry.cpp + * + * Purpose: Illustrates facility for comparing custom integral types. + * + * Created: 23rd November 2024 + * Updated: 23rd November 2024 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +#include + +/* xTests Header Files */ +#include + +/* STLSoft Header Files */ +#include + +/* Standard C++ Header Files */ + +/* Standard C Header Files */ +#include +#include + +#include + +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +namespace { + +static void test_int_wrapper(); +} /* anonymous namespace */ + + +/* ///////////////////////////////////////////////////////////////////////// + * types + */ + +struct int_wrapper +{ + int value; +}; + +namespace stlsoft { + + template<> + struct integral_traits + { + static + int + get_underlying_value( + int_wrapper const& iw + ) + { + return iw.value; + } + }; + +} /* namespace stlsoft */ + + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity; + + XTESTS_COMMANDLINE_PARSE_HELP(argc, argv); + XTESTS_COMMANDLINE_PARSE_VERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.scratch.custom_integral_types", verbosity)) + { + XTESTS_RUN_CASE(test_int_wrapper); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * function implementations + */ + +namespace { + +static void test_int_wrapper() +{ + { + int_wrapper lhs { 0 }; + int_wrapper rhs { 0 }; + + XTESTS_TEST_INTEGER_EQUAL(lhs, rhs); + } + + { + int_wrapper lhs { 0 }; + int_wrapper rhs { 1 }; + + XTESTS_TEST_INTEGER_GREATER_OR_EQUAL(lhs, rhs); + } + +} +} /* anonymous namespace */ + + +/* ///////////////////////////// end of file //////////////////////////// */ +