2
3
4
5
6
7
8
9
10
11
12
13#ifndef GIMBAL_TEST_MACROS_H
14#define GIMBAL_TEST_MACROS_H
16#include "../preprocessor/gimbal_macro_utils.h"
28GBL_INLINE const char* GBL_TEST_COMPARE_FMT_DFLT_ (
void) {
return "Values differed"; }
29GBL_INLINE const char* GBL_TEST_COMPARE_FMT_CHAR_ (
void) {
return "Values differed [actual: %c, expected: %c]"; }
30GBL_INLINE const char* GBL_TEST_COMPARE_FMT_INT_ (
void) {
return "Values differed [actual: %d, expected: %d]"; }
31GBL_INLINE const char* GBL_TEST_COMPARE_FMT_UINT_ (
void) {
return "Values differed [actual: %u, expected: %u]"; }
32GBL_INLINE const char* GBL_TEST_COMPARE_FMT_LINT_ (
void) {
return "Values differed [actual: %" PRId64
", expected: %" PRId64
"]"; }
33GBL_INLINE const char* GBL_TEST_COMPARE_FMT_LUINT_(
void) {
return "Values differed [actual: %" PRIu64
", expected: %" PRIu64
"]"; }
34GBL_INLINE const char* GBL_TEST_COMPARE_FMT_STR_ (
void) {
return "Values differed [actual: %s, expected: %s]"; }
35GBL_INLINE const char* GBL_TEST_COMPARE_FMT_FLT_ (
void) {
return "Values differed [actual: %f, expected: %f]"; }
36GBL_INLINE const char* GBL_TEST_COMPARE_FMT_PTR_ (
void) {
return "Values differed [actual: %p, expected: %p]"; }
39# define GBL_TEST_COMPARE_FMT_TABLE_ (
40 GBL_TEST_COMPARE_FMT_PTR_,
42 (char, GBL_TEST_COMPARE_FMT_CHAR_),
43 (int16_t, GBL_TEST_COMPARE_FMT_INT_),
44 (int32_t, GBL_TEST_COMPARE_FMT_INT_),
45 (int64_t, GBL_TEST_COMPARE_FMT_LINT_),
46 (uint8_t, GBL_TEST_COMPARE_FMT_UINT_),
47 (uint16_t, GBL_TEST_COMPARE_FMT_UINT_),
48 (uint32_t, GBL_TEST_COMPARE_FMT_UINT_),
49 (uint64_t, GBL_TEST_COMPARE_FMT_LUINT_),
50 (const char*, GBL_TEST_COMPARE_FMT_STR_),
51 (char*, GBL_TEST_COMPARE_FMT_STR_),
52 (float, GBL_TEST_COMPARE_FMT_FLT_),
53 (double, GBL_TEST_COMPARE_FMT_FLT_),
54 (const void*, GBL_TEST_COMPARE_FMT_PTR_)
58# define GBL_TEST_COMPARE_FMT_(value) GBL_META_GENERIC_MACRO_GENERATE(GBL_TEST_COMPARE_FMT_TABLE_, value)()
61inline constexpr const char* GBL_TEST_COMPARE_FMT_(
char) {
return "Values differed [actual: %c, expected: %c]"; }
62inline constexpr const char* GBL_TEST_COMPARE_FMT_(
short) {
return "Values differed [actual: %d, expected: %d]"; }
63inline constexpr const char* GBL_TEST_COMPARE_FMT_(
unsigned short) {
return "Values differed [actual: %u, expected: %u]"; }
64inline constexpr const char* GBL_TEST_COMPARE_FMT_(
int) {
return "Values differed [actual: %d, expected: %d]"; }
65inline constexpr const char* GBL_TEST_COMPARE_FMT_(
unsigned) {
return "Values differed [actual: %u, expected: %u]"; }
66inline constexpr const char* GBL_TEST_COMPARE_FMT_(
long) {
return "Values differed [actual: %ld, expected: %ld]"; }
67inline constexpr const char* GBL_TEST_COMPARE_FMT_(
unsigned long) {
return "Values differed [actual: %lu, expected: %lu]"; }
68inline constexpr const char* GBL_TEST_COMPARE_FMT_(
long long) {
return "Values differed [actual: %lld, expected: %lld]"; }
69inline constexpr const char* GBL_TEST_COMPARE_FMT_(
unsigned long long) {
return "Values differed [actual: %llu, expected: %llu]"; }
70inline constexpr const char* GBL_TEST_COMPARE_FMT_(
const char*) {
return "Values differed [actual: %s, expected: %s]"; }
71inline constexpr const char* GBL_TEST_COMPARE_FMT_(
float) {
return "Values differed [actual: %f, expected: %f]"; }
72inline constexpr const char* GBL_TEST_COMPARE_FMT_(
double) {
return "Values differed [actual: %f, expected: %f]"; }
73inline constexpr const char* GBL_TEST_COMPARE_FMT_(
auto*) {
return "Values differed [actual: %p, expected: %p]"; }
74inline constexpr const char* GBL_TEST_COMPARE_FMT_(
auto) {
return "Values differed"; }
79GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_UINTPTR_(uintptr_t actual, uintptr_t expected) {
return actual == expected; }
80GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_PTR_ (
const void* pActual,
const void* pExpected) {
return pActual == pExpected; }
81GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_UINT32_ (uint32_t actual, uint32_t expected) {
return actual == expected; }
82GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_UINT64_ (uint64_t actual, uint64_t expected) {
return actual == expected; }
83GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_INT32_ (int32_t actual, int32_t expected) {
return actual == expected; }
84GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_INT64_ (int64_t actual, int64_t expected) {
return actual == expected; }
85GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_DBL_ (
double actual,
double expected) {
return actual == expected; }
86GBL_INLINE GblBool GBL_TEST_COMPARE_CMP_STR_ (
const char* pActual,
const char* pExpected) {
return pActual == pExpected ||
87 (pActual && pExpected &&
88 strcmp(pActual, pExpected) == 0); }
91#if defined(GBL_DREAMCAST) || defined(GBL_GAMECUBE)
92# define GBL_TEST_CMP_PLATFORM_ENTRIES()
93 (size_t , GBL_TEST_COMPARE_CMP_UINT32_),
94 (int, GBL_TEST_COMPARE_CMP_INT32_),
96# define GBL_TEST_CMP_PLATFORM_ENTRIES()
97 (size_t , GBL_TEST_COMPARE_CMP_UINT32_),
98 (int, GBL_TEST_COMPARE_CMP_INT32_),
99#elif (defined(__APPLE__) && defined(GBL_64BIT))
100# define GBL_TEST_CMP_PLATFORM_ENTRIES()
101 (size_t , GBL_TEST_COMPARE_CMP_UINT64_),
102 (long, GBL_TEST_COMPARE_CMP_INT64_),
103#elif defined(__EMSCRIPTEN__)
104# define GBL_TEST_CMP_PLATFORM_ENTRIES()
105 (size_t , GBL_TEST_COMPARE_CMP_UINT64_),
106 (int8_t, GBL_TEST_COMPARE_CMP_UINT32_),
108# define GBL_TEST_CMP_PLATFORM_ENTRIES()
111# define GBL_TEST_COMPARE_CMP_TABLE_ (
112 GBL_TEST_COMPARE_CMP_PTR_,
114 (char, GBL_TEST_COMPARE_CMP_INT32_),
115 (int16_t, GBL_TEST_COMPARE_CMP_INT32_),
116 (int32_t, GBL_TEST_COMPARE_CMP_INT32_),
117 (int64_t, GBL_TEST_COMPARE_CMP_INT64_),
118 (uint8_t, GBL_TEST_COMPARE_CMP_UINT32_),
119 (uint16_t, GBL_TEST_COMPARE_CMP_UINT32_),
120 (uint32_t, GBL_TEST_COMPARE_CMP_UINT32_),
121 (uint64_t, GBL_TEST_COMPARE_CMP_UINT64_),
122 GBL_TEST_CMP_PLATFORM_ENTRIES()
123 (const char*, GBL_TEST_COMPARE_CMP_STR_),
124 (char*, GBL_TEST_COMPARE_CMP_STR_),
125 (float, GBL_TEST_COMPARE_CMP_DBL_),
126 (double, GBL_TEST_COMPARE_CMP_DBL_),
127 (const void*, GBL_TEST_COMPARE_CMP_PTR_)
131# define GBL_TEST_COMPARE_CMP_(actual, expected) GBL_META_GENERIC_MACRO_GENERATE(GBL_TEST_COMPARE_CMP_TABLE_, actual)(actual, expected)
134inline constexpr GblBool GBL_TEST_COMPARE_CMP_(
auto actual,
auto expected)
noexcept {
135 if constexpr(std::convertible_to<
decltype(actual),
decltype(expected)>)
136 return static_cast<
decltype(expected)>(actual) == expected;
137 else if constexpr(std::convertible_to<
decltype(expected),
decltype(actual)>)
138 return actual ==
static_cast<
decltype(actual)>(expected);
139 else static_assert(
"Incompatible types!");
142inline GblBool GBL_TEST_COMPARE_CMP_(
const char* pActual,
const char *pExpected)
noexcept {
143 return GBL_TEST_COMPARE_CMP_STR_(pActual, pExpected);
150 GBL_TEST_COMPARE_FMT_(actual),
154 "Values differed [expected: %d, actual: %d]",
158 "Values differed [expected: %u, actual: %u]",
162 "Values differed [expected: %s, actual: %s]",
166 "Values differed [expected: %f, actual: %f]",
170 "Values differed [exptected: %p, actual: %p]",
173typedef enum GBL_TEST_ERROR_COMPARISON {
174 GBL_TEST_ERROR_ABSOLUTE,
175 GBL_TEST_ERROR_RELATIVE,
177} GBL_TEST_ERROR_COMPARISON;
179#define GBL_TEST_ERROR(actual, precise, epsilon, cmp)
181 double relative = gblRelativeError((actual), (precise));
182 double absolute = gblAbsoluteError((actual), (precise));
183 if(((cmp) == GBL_TEST_ERROR_ABSOLUTE && absolute > (epsilon)) ||
184 ((cmp) == GBL_TEST_ERROR_RELATIVE && relative > (epsilon)) ||
185 (absolute > (epsilon) && relative > (epsilon)))
187 "\t ERROR: Rel == %.9f, Abs == %.9f, Max == %.9f",
188 (actual), (precise), relative, absolute, (epsilon));
202#define GBL_TEST_EXPECT_ERROR()
206 "Skipping test case due to GBL_CONFIG_ASSERT_ERROR_ENABLED.");
208 if(pScenario) GblTestScenario_expectError(pScenario);
212#ifndef GBL_SELF_TYPE_NAME
213# define GBL_SELF_TYPE_NAME pSelf
216#ifndef GBL_TEST_SUITE_CONTEXT_NAME
217# define GBL_TEST_SUITE_CONTEXT_NAME pCtx
220#ifndef GBL_SELF_TYPE_PRIVATE_NAME
221# define GBL_SELF_TYPE_PRIVATE_NAME pFixture
224#ifndef GBL_SELF_TYPE_PRIVATE
225# define GBL_SELF_TYPE_PRIVATE GBL_GLUE(GBL_SELF_TYPE, _)
228#define GBL_TEST_CASE(name)
235 GBL_PRIVATE
(GBL_SELF_TYPE, pSelf);
240#define GBL_TEST_CASE_END
243#define GBL_TEST_FIXTURE_TYPE
246#define GBL_TEST_FIXTURE
252# define GBL_TEST_REGISTER(...)
255# define GBL_TEST_REGISTER(...)
256 GBL_TEST_REGISTER_(__VA_ARGS__)
259#define GBL_TEST_REGISTER_(...)
262 const static GblTestCase cases[] = {
266 const static GblTestSuiteVTable vTable = {
273 type = GblTestSuite_register(GblQuark_internStatic(GBL_STRINGIFY(GBL_SELF_TYPE)),
275 sizeof(GBL_SELF_TYPE),
277 GBL_TYPE_FLAGS_NONE);
282}
284#define GBL_TEST_CASE_PAIR(suiteName, caseName)
289#define GBL_TEST_INIT_NONE
292#define GBL_TEST_FINAL_NONE
295#define GBL_TEST_FIXTURE_NONE
#define GBL_CTX_VERIFY_CALL(...)
#define GBL_CTX_END_BLOCK()
#define GBL_CTX_VERIFY_LAST_RECORD()
#define GBL_CTX_BEGIN(...)
#define GBL_CTX_VERIFY_EXPRESSION(...)
#define GBL_CTX_VERIFY(...)
#define GBL_CTX_CONTEXT()
#define GBL_DECLARE_STRUCT(S)
#define GBL_TUPLE_FOREACH(MACRO_, DATA_, TUPLE_)
#define GBL_RESULT_ERROR(value)
#define GBL_TEST_FIXTURE_TYPE
#define GBL_SELF_TYPE_PRIVATE
#define GBL_TEST_CASE(name)
#define GBL_TEST_CASE_PAIR(suiteName, caseName)
#define GBL_TEST_REGISTER_(...)
#define GBL_SELF_TYPE_PRIVATE_NAME
#define GBL_TEST_CASE_END
#define GBL_SELF_TYPE_NAME
#define GBL_TEST_FAIL(...)
#define GBL_TEST_SUITE_CONTEXT_NAME
#define GBL_TEST_SCENARIO(self)
Casts a GblInstance to a GblTestScenario.
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)