Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integral types #43

Merged
merged 9 commits into from
Nov 23, 2024
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Purpose: Top-level CMake lists file for xTests
#
# Created: 9th October 2019
# Updated: 17th November 2024
# Updated: 23rd November 2024
#
# ######################################################################## #

Expand Down Expand Up @@ -76,6 +76,13 @@ if(MSVC)

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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)


Expand Down
4 changes: 3 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
187 changes: 117 additions & 70 deletions include/xtests/xtests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */


Expand Down Expand Up @@ -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 */


Expand Down Expand Up @@ -163,6 +163,9 @@
# include <stlsoft/shims/access/string.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
# endif /* STLSOFT_MINIMUM_SAS_INCLUDES */
# ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_TRAITS
# include <stlsoft/traits/integral_traits.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_TRAITS */
# endif /* !_XTESTS_NO_CPP_API */
# if defined(STLSOFT_CF_EXCEPTION_SUPPORT)
# include <new>
Expand Down Expand Up @@ -3537,8 +3540,8 @@ struct xtests_failure_reporter<unsigned short>
STLSOFT_STATIC_CAST(void, xtests_failure_reporter<int>::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)>
{
Expand All @@ -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)>
{
Expand Down Expand Up @@ -3617,8 +3620,8 @@ struct xtests_failure_reporter<unsigned long>
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)>
{
Expand Down Expand Up @@ -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<bool>
{
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
Expand Down Expand Up @@ -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());
Expand All @@ -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<bool, bool>::type::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
# else /* ? compiler */

typedef xtests_integer_failure_reporter_selector<bool, bool>::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(
Expand Down Expand Up @@ -3923,7 +3869,7 @@ template<
>
inline
int
xtests_test_integer(
xtests_test_integer_(
char const* file
, int line
, char const* function
Expand Down Expand Up @@ -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)<I1>::get_underlying_value(expected)
, STLSOFT_NS_QUAL(integral_traits)<I2>::get_underlying_value(actual)
, comp
);
}


struct boolean_test_must_involve_boolean_parameters {};

template <typename T>
Expand Down Expand Up @@ -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<bool, bool>(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 <typename T>
Expand All @@ -4072,7 +4119,7 @@ xtests_test_boolean(
{
typedef ss_typename_type_k boolean_argument_traits<T>::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());
}


Expand Down
1 change: 1 addition & 0 deletions test/scratch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Loading