Skip to content

Commit e74a0b8

Browse files
Integral types (#43)
* ~ simplified and separated (C++) implementation of `bool` tests * ~ simplified and separated (C++) implementation of `bool` tests * ~ updated **STLSoft** constructs, incl. macros * ~ layout * - dead code * Merged 'msq' into 'int-types' Squashed commit of the following: commit 1083e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:40:31 2024 +1100 ~ commit commit cf1e7e3 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:37:33 2024 +1100 Environment variable (for verbosity) (#41) * Merged 'env-edits' into 'env' Squashed commit of the following: commit c536d64742d96df26887394185d625ac029a306c Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:20:56 2024 +1100 ~ updated **STLSoft** constructs, incl. macros commit 2a4a1636607aefc948ecd708ba48dac84dfe2e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:25:09 2024 +1100 ~ layout * ~ preparatory changes * `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"` commit 6620ce6 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:35:44 2024 +1100 ~ improved boilerplate (#39) * ~ now uses `stlsoft::integral_traits<>` for integer test macros (in C++) to allow for custom integral types to be tested * Merged 'dev' into 'int-types' Squashed commit of the following: commit 97fc966 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 17:00:52 2024 +1100 Terse macros (#42) * ~ ignores * ~ all scratch-test entry-point source file names standardised * + added terse forms of macros, available by including **xtests/terse-api.h** * Merged 'env-edits' into 'env' Squashed commit of the following: commit c536d64742d96df26887394185d625ac029a306c Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:20:56 2024 +1100 ~ updated **STLSoft** constructs, incl. macros commit 2a4a1636607aefc948ecd708ba48dac84dfe2e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:25:09 2024 +1100 ~ layout * ~ preparatory changes * ~ boilerplate * Merged 'dev' into 'terse-macros' Squashed commit of the following: commit 1083e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:40:31 2024 +1100 ~ commit commit cf1e7e3 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:37:33 2024 +1100 Environment variable (for verbosity) (#41) * Merged 'env-edits' into 'env' Squashed commit of the following: commit c536d64742d96df26887394185d625ac029a306c Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:20:56 2024 +1100 ~ updated **STLSoft** constructs, incl. macros commit 2a4a1636607aefc948ecd708ba48dac84dfe2e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:25:09 2024 +1100 ~ layout * ~ preparatory changes * `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"` commit 6620ce6 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:35:44 2024 +1100 ~ improved boilerplate (#39) --------- Co-authored-by: Matt Wilson <[email protected]> commit 1083e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:40:31 2024 +1100 ~ commit commit cf1e7e3 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:37:33 2024 +1100 Environment variable (for verbosity) (#41) * Merged 'env-edits' into 'env' Squashed commit of the following: commit c536d64742d96df26887394185d625ac029a306c Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:20:56 2024 +1100 ~ updated **STLSoft** constructs, incl. macros commit 2a4a1636607aefc948ecd708ba48dac84dfe2e94 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 10:25:09 2024 +1100 ~ layout * ~ preparatory changes * `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"` commit 6620ce6 Author: Matt Wilson <[email protected]> Date: Sat Nov 23 16:35:44 2024 +1100 ~ improved boilerplate (#39) --------- Co-authored-by: Matt Wilson <[email protected]>
1 parent 97fc966 commit e74a0b8

File tree

7 files changed

+254
-73
lines changed

7 files changed

+254
-73
lines changed

CHANGES.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ Updated: 23rd November 2024
1919
23rd November 2024 - 0.26.0-alpha1
2020
==================================
2121

22+
* now uses `stlsoft::integral_traits<>` for integer test macros (in C++) to allow for custom integral types to be tested;
2223
* added terse forms of macros, available by including **xtests/terse-api.h**;
2324
* `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"`;
24-
* updated **STLSoft** constructs, incl. macros;
2525
* minor improvements to project boilerplate files;
26+
* minor tidying to CMake facilities;
27+
* updated **STLSoft** constructs, incl. macros;
2628

2729

2830
18th November 2024 - 0.25.4

CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Purpose: Top-level CMake lists file for xTests
66
#
77
# Created: 9th October 2019
8-
# Updated: 17th November 2024
8+
# Updated: 23rd November 2024
99
#
1010
# ######################################################################## #
1111

@@ -76,6 +76,13 @@ if(MSVC)
7676

7777
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
7878
endif(MSVC_USE_MT)
79+
else(MSVC)
80+
81+
if(MSVC_USE_MT)
82+
83+
# this here just to absorb warning about not using `MSVC_USE_MT` (to
84+
# enable **prepare_cmake.sh** to be simple)
85+
endif(MSVC_USE_MT)
7986
endif(MSVC)
8087

8188

HISTORY.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
23rd November 2024 - 0.26.0-alpha1
55
----------------------------------
66

7+
* now uses `stlsoft::integral_traits<>` for integer test macros (in C++) to allow for custom integral types to be tested;
78
* added terse forms of macros, available by including **xtests/terse-api.h**;
89
* `XTESTS_COMMANDLINE_PARSE_VERBOSITY()` now also recognises, if the command-line argument `"--verbosity= . . ."` is not found, the enviroment variables `"XTESTS_VERBOSITY"` and `"TEST_VERBOSITY"`;
9-
* updated **STLSoft** constructs, incl. macros;
1010
* minor improvements to project boilerplate files;
11+
* minor tidying to CMake facilities;
12+
* updated **STLSoft** constructs, incl. macros;
1113

1214

1315
18th November 2024 - 0.25.4

include/xtests/xtests.h

+117-70
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* File: xtests/xtests.h (formerly part of Synesis' internal test codebase)
33
*
44
* Purpose: Main header file for xTests, a simple unit/component-testing
5-
* library.
5+
* library for C and C++.
66
*
77
* Created: 20th June 1999
88
* Updated: 23rd November 2024
@@ -51,9 +51,9 @@
5151

5252
#ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
5353
# define XTESTS_VER_XTESTS_H_XTESTS_MAJOR 3
54-
# define XTESTS_VER_XTESTS_H_XTESTS_MINOR 44
54+
# define XTESTS_VER_XTESTS_H_XTESTS_MINOR 45
5555
# define XTESTS_VER_XTESTS_H_XTESTS_REVISION 1
56-
# define XTESTS_VER_XTESTS_H_XTESTS_EDIT 380
56+
# define XTESTS_VER_XTESTS_H_XTESTS_EDIT 383
5757
#endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
5858

5959

@@ -105,9 +105,9 @@
105105
STLSOFT_VER >= 0x010c0000
106106

107107
# define XTESTS_STLSOFT_1_12_OR_LATER
108-
#elif _STLSOFT_VER < 0x010b0159
108+
#elif _STLSOFT_VER < 0x010b015a
109109

110-
# error xTests requires version 1.11.1 alpha 25, or later, of STLSoft; download from https://github.com/synesissoftware/
110+
# error xTests requires version 1.11.1 alpha 26, or later, of STLSoft; obtain from https://github.com/synesissoftware/
111111
#endif /* _STLSOFT_VER */
112112

113113

@@ -163,6 +163,9 @@
163163
# include <stlsoft/shims/access/string.hpp>
164164
# endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
165165
# endif /* STLSOFT_MINIMUM_SAS_INCLUDES */
166+
# ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_TRAITS
167+
# include <stlsoft/traits/integral_traits.hpp>
168+
# endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_TRAITS */
166169
# endif /* !_XTESTS_NO_CPP_API */
167170
# if defined(STLSOFT_CF_EXCEPTION_SUPPORT)
168171
# include <new>
@@ -3537,8 +3540,8 @@ struct xtests_failure_reporter<unsigned short>
35373540
STLSOFT_STATIC_CAST(void, xtests_failure_reporter<int>::xtests_report_failure_equal(file, line, function, expr, int(expected), int(actual), comp));
35383541
}
35393542
};
3540-
35413543
# ifdef STLSOFT_CF_SHORT_DISTINCT_INT_TYPE
3544+
35423545
template <>
35433546
struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_sint16_t)>
35443547
{
@@ -3564,8 +3567,8 @@ struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_uint16_t)>
35643567
}
35653568
};
35663569
# endif /* STLSOFT_CF_SHORT_DISTINCT_INT_TYPE */
3567-
35683570
# ifdef STLSOFT_CF_INT_DISTINCT_INT_TYPE
3571+
35693572
template <>
35703573
struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_sint32_t)>
35713574
{
@@ -3617,8 +3620,8 @@ struct xtests_failure_reporter<unsigned long>
36173620
STLSOFT_STATIC_CAST(void, xtests_testFailed_ulong(file, line, function, expr, expected, actual, comp));
36183621
}
36193622
};
3620-
36213623
# ifdef STLSOFT_CF_64BIT_INT_SUPPORT
3624+
36223625
template <>
36233626
struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_sint64_t)>
36243627
{
@@ -3646,20 +3649,6 @@ struct xtests_failure_reporter< STLSOFT_NS_QUAL(ss_uint64_t)>
36463649
};
36473650
# endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
36483651

3649-
template <>
3650-
struct xtests_failure_reporter<bool>
3651-
{
3652-
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)
3653-
{
3654-
# ifndef _XTESTS_NO_NAMESPACE
3655-
using namespace ::xtests::c;
3656-
# endif /* _XTESTS_NO_NAMESPACE */
3657-
3658-
STLSOFT_STATIC_CAST(void, xtests_testFailed_boolean(file, line, function, expr, expected, actual, comp));
3659-
}
3660-
};
3661-
3662-
36633652

36643653
template<
36653654
typename T1
@@ -3718,6 +3707,7 @@ xtests_reportFailedIntegerComparison(
37183707
_MSC_VER >= 1310 && \
37193708
!defined(_WIN64) && \
37203709
defined(_Wp64)
3710+
37213711
/* This special overload is to allow for cases such as:
37223712
*
37233713
* XTESTS_TEST_INTEGER_EQUAL(4u, sink.size());
@@ -3742,50 +3732,6 @@ xtests_reportFailedIntegerComparison(
37423732
}
37433733
# endif
37443734

3745-
inline
3746-
void
3747-
xtests_reportFailedIntegerComparison(
3748-
char const* file
3749-
, int line
3750-
, char const* function
3751-
, char const* expr
3752-
, bool expected
3753-
, bool actual
3754-
, xtests_comparison_t comp
3755-
)
3756-
{
3757-
# ifndef _XTESTS_NO_NAMESPACE
3758-
using namespace ::xtests::c;
3759-
# endif /* _XTESTS_NO_NAMESPACE */
3760-
3761-
# if defined(STLSOFT_COMPILER_IS_BORLAND)
3762-
3763-
xtests_integer_failure_reporter_selector<bool, bool>::type::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
3764-
# else /* ? compiler */
3765-
3766-
typedef xtests_integer_failure_reporter_selector<bool, bool>::type failure_reporter_t;
3767-
3768-
failure_reporter_t::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
3769-
# endif /* compiler */
3770-
}
3771-
3772-
#if 0
3773-
inline
3774-
void
3775-
xtests_reportFailedIntegerComparison(
3776-
char const* file
3777-
, int line
3778-
, char const* function
3779-
, char const* expr
3780-
, int expected
3781-
, bool actual
3782-
, xtests_comparison_t comp
3783-
)
3784-
{
3785-
xtests_reportFailedIntegerComparison(file, line, function, expr, 0 != expected, actual, comp);
3786-
}
3787-
#endif /* 0 */
3788-
37893735
inline
37903736
void
37913737
xtests_reportFailedFloatingPointComparison(
@@ -3923,7 +3869,7 @@ template<
39233869
>
39243870
inline
39253871
int
3926-
xtests_test_integer(
3872+
xtests_test_integer_(
39273873
char const* file
39283874
, int line
39293875
, char const* function
@@ -4006,6 +3952,34 @@ xtests_test_integer(
40063952
return comparisonSucceeded;
40073953
}
40083954

3955+
template<
3956+
typename I1
3957+
, typename I2
3958+
>
3959+
inline
3960+
int
3961+
xtests_test_integer(
3962+
char const* file
3963+
, int line
3964+
, char const* function
3965+
, char const* expr
3966+
, I1 const& expected
3967+
, I2 const& actual
3968+
, xtests_comparison_t comp
3969+
)
3970+
{
3971+
return xtests_test_integer_(
3972+
file
3973+
, line
3974+
, function
3975+
, expr
3976+
, STLSOFT_NS_QUAL(integral_traits)<I1>::get_underlying_value(expected)
3977+
, STLSOFT_NS_QUAL(integral_traits)<I2>::get_underlying_value(actual)
3978+
, comp
3979+
);
3980+
}
3981+
3982+
40093983
struct boolean_test_must_involve_boolean_parameters {};
40103984

40113985
template <typename T>
@@ -4052,9 +4026,82 @@ xtests_test_boolean_(
40524026
, STLSOFT_NS_QUAL(yes_type)
40534027
)
40544028
{
4055-
bool const actual_as_bool = actual;
4029+
# ifndef _XTESTS_NO_NAMESPACE
4030+
using namespace ::xtests::c;
4031+
# endif /* _XTESTS_NO_NAMESPACE */
4032+
4033+
bool const actual_as_bool = !!actual;
4034+
4035+
int comparisonSucceeded = false;
4036+
4037+
switch (comp)
4038+
{
4039+
case xtestsComparisonEqual:
4040+
case xtestsComparisonApproxEqual:
4041+
4042+
if (expected == actual_as_bool)
4043+
{
4044+
comparisonSucceeded = true;
4045+
}
4046+
break;
4047+
case xtestsComparisonNotEqual:
4048+
case xtestsComparisonApproxNotEqual:
4049+
4050+
if (expected != actual_as_bool)
4051+
{
4052+
comparisonSucceeded = true;
4053+
}
4054+
break;
4055+
#if 0 /* NOTE: currently don't support ordering of `bool` */
4056+
4057+
case xtestsComparisonGreaterThan:
4058+
4059+
if (actual_as_bool > expected)
4060+
{
4061+
comparisonSucceeded = true;
4062+
}
4063+
break;
4064+
case xtestsComparisonLessThan:
4065+
4066+
if (actual_as_bool < expected)
4067+
{
4068+
comparisonSucceeded = true;
4069+
}
4070+
break;
4071+
case xtestsComparisonGreaterThanOrEqual:
40564072

4057-
return xtests_test_integer<bool, bool>(file, line, function, expr, expected, actual_as_bool, comp);
4073+
if (actual_as_bool >= expected)
4074+
{
4075+
comparisonSucceeded = true;
4076+
}
4077+
break;
4078+
case xtestsComparisonLessThanOrEqual:
4079+
4080+
if (actual_as_bool <= expected)
4081+
{
4082+
comparisonSucceeded = true;
4083+
}
4084+
break;
4085+
#endif
4086+
default:
4087+
4088+
STLSOFT_MESSAGE_ASSERT("unrecognised enumerator", false);
4089+
case xtestsComparison_max_enumerator:
4090+
4091+
xtests_abend("invalid test comparison type: test framework may be out of date!");
4092+
break;
4093+
}
4094+
4095+
if (comparisonSucceeded)
4096+
{
4097+
xtests_testPassed(file, line, function, expr);
4098+
}
4099+
else
4100+
{
4101+
STLSOFT_STATIC_CAST(void, xtests_testFailed_boolean(file, line, function, expr, expected, actual_as_bool, comp));
4102+
}
4103+
4104+
return comparisonSucceeded;
40584105
}
40594106

40604107
template <typename T>
@@ -4072,7 +4119,7 @@ xtests_test_boolean(
40724119
{
40734120
typedef ss_typename_type_k boolean_argument_traits<T>::yesno_type yesno_t;
40744121

4075-
return xtests_test_boolean_(file, line, function, expr, expected, !!actual, comp, yesno_t());
4122+
return xtests_test_boolean_(file, line, function, expr, expected, actual, comp, yesno_t());
40764123
}
40774124

40784125

test/scratch/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
add_subdirectory(test.scratch.basics1)
33
add_subdirectory(test.scratch.basics2)
44
add_subdirectory(test.scratch.basics2.terse)
5+
add_subdirectory(test.scratch.custom_integral_types)
56
add_subdirectory(test.scratch.fail_all.1)
67
add_subdirectory(test.scratch.integer_comparisons.c)
78
add_subdirectory(test.scratch.setup.fail)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten
2+
define_automated_test_program(test.scratch.custom_integral_types entry.cpp)

0 commit comments

Comments
 (0)