Commit 3223b1b5 authored by Ondřej Surý's avatar Ondřej Surý Committed by Mark Andrews
Browse files

Add support for cmocka assert testing by overriding REQUIRE/INSIST/... macros...

Add support for cmocka assert testing by overriding REQUIRE/INSIST/... macros when UNIT_TESTING is defined

(cherry picked from commit 52731c00)
parent f2243e5f
Pipeline #6424 passed with stages
in 8 minutes and 13 seconds
...@@ -208,6 +208,19 @@ ...@@ -208,6 +208,19 @@
#define ISC_UNREACHABLE() #define ISC_UNREACHABLE()
#endif #endif
#ifdef UNIT_TESTING
extern void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
#define REQUIRE(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
#define ENSURE(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
#define INSIST(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
#define INVARIANT(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
#else /* UNIT_TESTING */
/* /*
* Assertions * Assertions
*/ */
...@@ -222,6 +235,8 @@ ...@@ -222,6 +235,8 @@
/*% Invariant Assertion */ /*% Invariant Assertion */
#define INVARIANT(e) ISC_INVARIANT(e) #define INVARIANT(e) ISC_INVARIANT(e)
#endif /* UNIT_TESTING */
/* /*
* Errors * Errors
*/ */
...@@ -231,9 +246,19 @@ ...@@ -231,9 +246,19 @@
#define UNEXPECTED_ERROR isc_error_unexpected #define UNEXPECTED_ERROR isc_error_unexpected
/*% Fatal Error */ /*% Fatal Error */
#define FATAL_ERROR isc_error_fatal #define FATAL_ERROR isc_error_fatal
#ifdef UNIT_TESTING
#define RUNTIME_CHECK(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
#else /* UNIT_TESTING */
/*% Runtime Check */ /*% Runtime Check */
#define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond) #define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond)
#endif /* UNIT_TESTING */
/*% /*%
* Time * Time
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment