mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Add support for cmocka assert testing by overriding REQUIRE/INSIST/... macros when UNIT_TESTING is defined
This commit is contained in:
@@ -203,6 +203,19 @@
|
||||
*/
|
||||
#include <isc/likely.h>
|
||||
|
||||
#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
|
||||
*/
|
||||
@@ -217,6 +230,8 @@
|
||||
/*% Invariant Assertion */
|
||||
#define INVARIANT(e) ISC_INVARIANT(e)
|
||||
|
||||
#endif /* UNIT_TESTING */
|
||||
|
||||
/*
|
||||
* Errors
|
||||
*/
|
||||
@@ -226,9 +241,19 @@
|
||||
#define UNEXPECTED_ERROR isc_error_unexpected
|
||||
/*% Fatal Error */
|
||||
#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 */
|
||||
#define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond)
|
||||
|
||||
#endif /* UNIT_TESTING */
|
||||
|
||||
/*%
|
||||
* Time
|
||||
*/
|
||||
|
Reference in New Issue
Block a user