mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +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>
|
#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
|
* Assertions
|
||||||
*/
|
*/
|
||||||
@@ -217,6 +230,8 @@
|
|||||||
/*% Invariant Assertion */
|
/*% Invariant Assertion */
|
||||||
#define INVARIANT(e) ISC_INVARIANT(e)
|
#define INVARIANT(e) ISC_INVARIANT(e)
|
||||||
|
|
||||||
|
#endif /* UNIT_TESTING */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Errors
|
* Errors
|
||||||
*/
|
*/
|
||||||
@@ -226,9 +241,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
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user