libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_test_macros.h File Reference

Go to the source code of this file.

Macros

#define GBL_TEST_VERIFY(expr)
 
#define GBL_TEST_COMPARE_FMT_(value)
 
#define GBL_TEST_COMPARE_CMP_(actual, expected)
 
#define GBL_TEST_COMPARE(actual, expected)
 
#define GBL_TEST_COMPARE_INT(actual, expected)
 
#define GBL_TEST_COMPARE_UINT(actual, expected)
 
#define GBL_TEST_COMPARE_STRING(actual, expected)
 
#define GBL_TEST_COMPARE_FLOAT(actual, expected)
 
#define GBL_TEST_COMPARE_POINTER(actual, expected)
 
#define GBL_TEST_CALL
 
#define GBL_TEST_SKIP(reason)
 
#define GBL_TEST_FAIL(reason)
 
#define GBL_TEST_EXPECT_ERROR()
 
#define GBL_SELF_TYPE_NAME
 
#define GBL_TEST_SUITE_CONTEXT_NAME
 
#define GBL_SELF_TYPE_PRIVATE_NAME
 
#define GBL_SELF_TYPE_PRIVATE
 
#define GBL_TEST_CASE(name)
 
#define GBL_TEST_CASE_END
 
#define GBL_TEST_FIXTURE_TYPE
 
#define GBL_TEST_FIXTURE
 
#define GBL_TEST_REGISTER(...)
 
#define GBL_TEST_REGISTER_(...)
 
#define GBL_TEST_CASE_PAIR(suiteName, caseName)
 
#define GBL_TEST_INIT()
 
#define GBL_TEST_FINAL()
 
#define GBL_TEST_NO_INIT
 
#define GBL_TEST_NO_FINAL
 
#define GBL_TEST_INIT_END
 
#define GBL_TEST_FINAL_END
 

Detailed Description

Unit testing macro utilities.

Todo:
  • need to make an actual exported set of C functions as the top-level entry-point into GBL_TEST_COMPARE(), so that language bindings without macros can use the test framework.
Author
Falco Girgis

Definition in file gimbal_test_macros.h.

Macro Definition Documentation

◆ GBL_TEST_VERIFY

#define GBL_TEST_VERIFY (   expr)

Definition at line 21 of file gimbal_test_macros.h.

◆ GBL_TEST_COMPARE_FMT_

#define GBL_TEST_COMPARE_FMT_ (   value)

Definition at line 22 of file gimbal_test_macros.h.

◆ GBL_TEST_COMPARE_CMP_

#define GBL_TEST_COMPARE_CMP_ (   actual,
  expected 
)

Definition at line 23 of file gimbal_test_macros.h.

◆ GBL_TEST_COMPARE

#define GBL_TEST_COMPARE (   actual,
  expected 
)

Definition at line 111 of file gimbal_test_macros.h.

115 : %d, actual: %d]", \
116 actual, expected)
117
118#define GBL_TEST_COMPARE_UINT(actual, expected) GBL_CTX_VERIFY_EXPRESSION(actual == expected, \
119 "Values differed [expected: %u, actual: %u]", \
120 actual, expected)
121
122#define GBL_TEST_COMPARE_STRING(actual, expected) GBL_CTX_VERIFY_EXPRESSION(strcmp(actual, expected) == 0, \
123 "Values differed [expected: %s, actual: %s]", \
124 actual, expected)
125
126#define GBL_TEST_COMPARE_FLOAT(actual, expected) GBL_CTX_VERIFY_EXPRESSION(actual == expected, \
127 "Values differed [expected: %f, actual: %f]", \
128 actual, expected)
129
130#define GBL_TEST_COMPARE_POINTER(actual, expected) GBL_CTX_VERIFY_EXPRESSION(actual == expected, \
131 "Values differed [exptected: %p, actual: %p]", \
132 actual, expected)
133
134#define GBL_TEST_CALL GBL_CTX_VERIFY_CALL
135
136#define GBL_TEST_SKIP(reason) GBL_CTX_VERIFY(GBL_FALSE, \
137 GBL_RESULT_SKIPPED, \
138 reason)
139
140#define GBL_TEST_FAIL(reason) GBL_CTX_VERIFY(GBL_FALSE, \
141 GBL_RESULT_ERROR, \
142 reason)
143
144#define GBL_TEST_EXPECT_ERROR() \
145 GBL_STMT_START { \
146 GBL_CTX_VERIFY(!GBL_CONFIG_ASSERT_ERROR_ENABLED, \
147 GBL_RESULT_SKIPPED, \
148 "Skipping test case due to GBL_CONFIG_ASSERT_ERROR_ENABLED."); \
149 GblTestScenario* pScenario = GBL_TEST_SCENARIO(GBL_CTX_CONTEXT()); \
150 if(pScenario) GblTestScenario_expectError(pScenario); \
151 } GBL_STMT_END
152
153
154#ifndef GBL_SELF_TYPE_NAME
155# define GBL_SELF_TYPE_NAME pSelf
156#endif
157
158#ifndef GBL_TEST_SUITE_CONTEXT_NAME
159# define GBL_TEST_SUITE_CONTEXT_NAME pCtx
160#endif
161
162#ifndef GBL_SELF_TYPE_PRIVATE_NAME
163# define GBL_SELF_TYPE_PRIVATE_NAME pFixture
164#endif
165
166#ifndef GBL_SELF_TYPE_PRIVATE
167# define GBL_SELF_TYPE_PRIVATE GBL_GLUE(GBL_SELF_TYPE, _)
168#endif
169
170#define GBL_TEST_CASE(name) \
171 static GBL_RESULT GBL_GLUE(GBL_GLUE(GBL_GLUE(GBL_SELF_TYPE, _), name), _) \
172 (GblTestSuite* GBL_SELF_TYPE_NAME, \
173 GblContext* GBL_TEST_SUITE_CONTEXT_NAME) { \
174 GBL_CTX_BEGIN(GBL_TEST_SUITE_CONTEXT_NAME); \
175 GBL_SELF_TYPE_PRIVATE* GBL_SELF_TYPE_PRIVATE_NAME = \
176 (GBL_SELF_TYPE_PRIVATE*) \
177 GBL_PRIVATE(GBL_SELF_TYPE, pSelf); \
178 GBL_UNUSED(GBL_SELF_TYPE_NAME, \
179 GBL_TEST_SUITE_CONTEXT_NAME, \
180 GBL_SELF_TYPE_PRIVATE_NAME);
181
182#define GBL_TEST_CASE_END \
183 GBL_CTX_END(); }
184
185#define GBL_TEST_FIXTURE_TYPE \
186 GBL_SELF_TYPE_PRIVATE
187
188#define GBL_TEST_FIXTURE \
189 struct GBL_TEST_FIXTURE_TYPE; \
190 typedef struct GBL_TEST_FIXTURE_TYPE GblTestFixture; \
191 GBL_DECLARE_STRUCT(GBL_TEST_FIXTURE_TYPE)
192
193#ifdef __cplusplus
194# define GBL_TEST_REGISTER(...) \
195 extern "C" GBL_TEST_REGISTER_(__VA_ARGS__)
196#else
197# define GBL_TEST_REGISTER(...) \
198 GBL_TEST_REGISTER_(__VA_ARGS__)
199#endif
200
201#define GBL_TEST_REGISTER_(...) \
202 GBL_EXPORT GblType GBL_GLUE(GBL_GLUE(GBL_SELF_TYPE, _), type)(void) GBL_NOEXCEPT { \
203 static GblType type = GBL_INVALID_TYPE; \
204 const static GblTestCase cases[] = { \
205 GBL_TUPLE_FOREACH(GBL_TEST_CASE_PAIR, GBL_GLUE(GBL_SELF_TYPE,_), (__VA_ARGS__)) \
206 { NULL, NULL } \
207 }; \
208 const static GblTestSuiteVTable vTable = { \
209 .pFnSuiteInit = GBL_GLUE(GBL_GLUE(GBL_GLUE(GBL_SELF_TYPE, _), init), _), \
210 .pFnSuiteFinal = GBL_GLUE(GBL_GLUE(GBL_GLUE(GBL_SELF_TYPE, _), final), _), \
211 .pCases = cases \
212 }; \
213 if(type == GBL_INVALID_TYPE) { \
214 GBL_CTX_BEGIN(NULL); \
215 type = GblTestSuite_register(GblQuark_internStatic(GBL_STRINGIFY(GBL_SELF_TYPE)), \
216 &vTable, \
217 sizeof(GBL_SELF_TYPE), \
218 sizeof(GBL_SELF_TYPE_PRIVATE), \
219 GBL_TYPE_FLAGS_NONE); \
220 GBL_CTX_VERIFY_LAST_RECORD(); \
221 GBL_CTX_END_BLOCK();\
222 } \
223 return type; \
224}
225
226#define GBL_TEST_CASE_PAIR(suiteName, caseName) \
227 { GBL_STRINGIFY(caseName), GBL_GLUE(GBL_GLUE(suiteName, caseName), _) },
228
229#define GBL_TEST_INIT() GBL_TEST_CASE(init)
230#define GBL_TEST_FINAL() GBL_TEST_CASE(final)
231#define GBL_TEST_NO_INIT \
232 GBL_TEST_INIT() \
233 GBL_TEST_CASE_END
234#define GBL_TEST_NO_FINAL \
235 GBL_TEST_FINAL() \
236 GBL_TEST_CASE_END
237#define GBL_TEST_INIT_END GBL_TEST_CASE_END
238#define GBL_TEST_FINAL_END GBL_TEST_CASE_END
239
240#endif // GIMBAL_TEST_MACROS_H

◆ GBL_TEST_COMPARE_INT

#define GBL_TEST_COMPARE_INT (   actual,
  expected 
)

Definition at line 115 of file gimbal_test_macros.h.

116 : %d, actual: %d]", \
117 actual, expected)

◆ GBL_TEST_COMPARE_UINT

#define GBL_TEST_COMPARE_UINT (   actual,
  expected 
)

Definition at line 119 of file gimbal_test_macros.h.

120 : %u, actual: %u]", \
121 actual, expected)

◆ GBL_TEST_COMPARE_STRING

#define GBL_TEST_COMPARE_STRING (   actual,
  expected 
)

Definition at line 123 of file gimbal_test_macros.h.

124 : %s, actual: %s]", \
125 actual, expected)

◆ GBL_TEST_COMPARE_FLOAT

#define GBL_TEST_COMPARE_FLOAT (   actual,
  expected 
)

Definition at line 127 of file gimbal_test_macros.h.

128 : %f, actual: %f]", \
129 actual, expected)

◆ GBL_TEST_COMPARE_POINTER

#define GBL_TEST_COMPARE_POINTER (   actual,
  expected 
)

Definition at line 131 of file gimbal_test_macros.h.

132 : %p, actual: %p]", \
133 actual, expected)

◆ GBL_TEST_CALL

#define GBL_TEST_CALL

Definition at line 135 of file gimbal_test_macros.h.

◆ GBL_TEST_SKIP

#define GBL_TEST_SKIP (   reason)

Definition at line 137 of file gimbal_test_macros.h.

◆ GBL_TEST_FAIL

#define GBL_TEST_FAIL (   reason)

Definition at line 141 of file gimbal_test_macros.h.

◆ GBL_TEST_EXPECT_ERROR

#define GBL_TEST_EXPECT_ERROR ( )

Definition at line 145 of file gimbal_test_macros.h.

146 { \
147 GBL_CTX_VERIFY(!GBL_CONFIG_ASSERT_ERROR_ENABLED, \
148 GBL_RESULT_SKIPPED, \
149 "Skipping test case due to GBL_CONFIG_ASSERT_ERROR_ENABLED."); \
150 GblTestScenario* pScenario = GBL_TEST_SCENARIO(GBL_CTX_CONTEXT()); \
151 if(pScenario) GblTestScenario_expectError(pScenario); \
152 } GBL_STMT_END
Represents a single top-level test object.

◆ GBL_SELF_TYPE_NAME

#define GBL_SELF_TYPE_NAME

Definition at line 156 of file gimbal_test_macros.h.

◆ GBL_TEST_SUITE_CONTEXT_NAME

#define GBL_TEST_SUITE_CONTEXT_NAME

Definition at line 160 of file gimbal_test_macros.h.

◆ GBL_SELF_TYPE_PRIVATE_NAME

#define GBL_SELF_TYPE_PRIVATE_NAME

Definition at line 164 of file gimbal_test_macros.h.

◆ GBL_SELF_TYPE_PRIVATE

#define GBL_SELF_TYPE_PRIVATE

Definition at line 168 of file gimbal_test_macros.h.

◆ GBL_TEST_CASE

#define GBL_TEST_CASE (   name)

Definition at line 171 of file gimbal_test_macros.h.

174 { \
175 GBL_CTX_BEGIN(GBL_TEST_SUITE_CONTEXT_NAME); \
176 GBL_SELF_TYPE_PRIVATE* GBL_SELF_TYPE_PRIVATE_NAME = \
177 (GBL_SELF_TYPE_PRIVATE*) \
178 GBL_PRIVATE(GBL_SELF_TYPE, pSelf); \
179 GBL_UNUSED(GBL_SELF_TYPE_NAME, \
180 GBL_TEST_SUITE_CONTEXT_NAME, \
181 GBL_SELF_TYPE_PRIVATE_NAME);

◆ GBL_TEST_CASE_END

#define GBL_TEST_CASE_END

Definition at line 183 of file gimbal_test_macros.h.

◆ GBL_TEST_FIXTURE_TYPE

#define GBL_TEST_FIXTURE_TYPE

Definition at line 186 of file gimbal_test_macros.h.

◆ GBL_TEST_FIXTURE

#define GBL_TEST_FIXTURE

Definition at line 189 of file gimbal_test_macros.h.

◆ GBL_TEST_REGISTER

#define GBL_TEST_REGISTER (   ...)

Definition at line 198 of file gimbal_test_macros.h.

◆ GBL_TEST_REGISTER_

#define GBL_TEST_REGISTER_ (   ...)

Definition at line 202 of file gimbal_test_macros.h.

203 { \
204 static GblType type = GBL_INVALID_TYPE; \
205 const static GblTestCase cases[] = { \
206 GBL_TUPLE_FOREACH(GBL_TEST_CASE_PAIR, GBL_GLUE(GBL_SELF_TYPE,_), (__VA_ARGS__)) \
207 { NULL, NULL } \
208 }; \
209 const static GblTestSuiteVTable vTable = { \
210 .pFnSuiteInit = GBL_GLUE(GBL_GLUE(GBL_GLUE(GBL_SELF_TYPE, _), init), _), \
211 .pFnSuiteFinal = GBL_GLUE(GBL_GLUE(GBL_GLUE(GBL_SELF_TYPE, _), final), _), \
212 .pCases = cases \
213 }; \
214 if(type == GBL_INVALID_TYPE) { \
215 GBL_CTX_BEGIN(NULL); \
216 type = GblTestSuite_register(GblQuark_internStatic(GBL_STRINGIFY(GBL_SELF_TYPE)), \
217 &vTable, \
218 sizeof(GBL_SELF_TYPE), \
219 sizeof(GBL_SELF_TYPE_PRIVATE), \
221 GBL_CTX_VERIFY_LAST_RECORD(); \
222 GBL_CTX_END_BLOCK();\
223 } \
224 return type; \
225}
const char * GblQuark_internStatic(const char *pString)
Creates a GblQuark from the given STATIC string (if necessary, saving on allocating),...
GblType GblTestSuite_register(const char *pName, const GblTestSuiteVTable *pVTable, size_t instanceSize, size_t instancePrivateSize, GblFlags typeFlags)
Registers a new GblType deriving from GBL_TEST_SUITE_TYPE.
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
Definition gimbal_type.h:31
@ GBL_TYPE_FLAGS_NONE
Type which adds no additional flags beyond what's inherited.
Definition gimbal_type.h:59
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
Represenst a single test case within a GblTestSuite.
Virtual table structure for a GblTestSuiteClass.
GBL_RESULT(* pFnSuiteInit)(GblTestSuite *pSelf, GblContext *pCtx)
Called to set up the test suite before any test cases are run.

◆ GBL_TEST_CASE_PAIR

#define GBL_TEST_CASE_PAIR (   suiteName,
  caseName 
)

Definition at line 227 of file gimbal_test_macros.h.

228 { GBL_STRINGIFY(caseName), GBL_GLUE(GBL_GLUE(suiteName, caseName), _) },

◆ GBL_TEST_INIT

#define GBL_TEST_INIT ( )

Definition at line 230 of file gimbal_test_macros.h.

◆ GBL_TEST_FINAL

#define GBL_TEST_FINAL ( )

Definition at line 231 of file gimbal_test_macros.h.

◆ GBL_TEST_NO_INIT

#define GBL_TEST_NO_INIT

Definition at line 232 of file gimbal_test_macros.h.

◆ GBL_TEST_NO_FINAL

#define GBL_TEST_NO_FINAL

Definition at line 235 of file gimbal_test_macros.h.

◆ GBL_TEST_INIT_END

#define GBL_TEST_INIT_END

Definition at line 238 of file gimbal_test_macros.h.

◆ GBL_TEST_FINAL_END

#define GBL_TEST_FINAL_END

Definition at line 239 of file gimbal_test_macros.h.