10#ifndef rtitest_assert_h
11#define rtitest_assert_h
16#include "rtitest/test_assert_types.h"
36#ifdef RTI_TEST_ENABLE_DEBUG_ASSERT
37 #define RTITest_debugAssert(str__) \
39 RTI_TEST_LOG_BIT_EXCEPTION, \
40 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
41 "[DEBUG %s:%d] executing command: %s", \
46 #define RTITest_debugAssert(str__)
57#define RTITest_setLastAssertErrorMessage(...) \
58 if (RTITest_g_lastAssertErrorMessage != NULL) { \
59 int unusedReturnValue__; \
60 unusedReturnValue__ = RTITestLog_snprintf( \
61 RTITest_g_lastAssertErrorMessage, \
62 RTI_TEST_MAX_ASSERT_ERROR_MESSAGE_SIZE, \
64 (void) unusedReturnValue__; \
73#define RTITest_assertLog(logMessage__, ...) \
75 RTITest_setLastAssertErrorMessage(__VA_ARGS__); \
76 RTITestLogger_log(RTI_TEST_LOG_BIT_EXCEPTION, (logMessage__), __VA_ARGS__)
85#define RTITest_assertLogWithFunctionName(functionName__, logMessage__, ...) \
86 RTITest_setLastAssertErrorMessage(__VA_ARGS__); \
87 RTITestLogger_logWithFunctionName( \
88 RTI_TEST_LOG_BIT_EXCEPTION, \
100#define RTITest_assertWithStr(statement__, str__) \
101 RTITest_debugAssert(statement__); \
102 if (!(statement__)) { \
103 const char *strConst__ = str__; \
105 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
106 "[%s:%d] assertion failed: %s reason: %s", \
122#define RTITest_assertWithAction(statement__, failAction__) \
123 RTITest_debugAssert(statement__); \
124 if (!(statement__)) { \
126 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
127 "[%s:%d] assertion failed: %s", \
140#define RTITest_assert(statement__) \
141 RTITest_assertWithAction(statement__, goto done)
149#define RTITest_assertAfterDone(statement__) \
150 RTITest_assertWithAction(statement__, result = RTI_TEST_RETCODE_FAILED)
158#define RTITest_assertWithNoAction(statement__) \
159 RTITest_assertWithAction(statement__,)
173#define RTITest_assertAlmostEqualsFloat(limit__, actual__) \
174 RTITest_assertComparisonForFloatingPointTypeWithAction( \
189#define RTITest_assertAlmostEqualsDouble(limit__, actual__) \
190 RTITest_assertComparisonForFloatingPointTypeWithAction( \
205#define RTITest_assertEqualsSN(expected__, actual__) \
207 RTITest_assertComparisonForType( \
213 RTITest_assertComparisonForType( \
229#define RTITest_assertComparisonForDDS_Duration_tWithAction(expected__, actual__, operation__, failAction__) \
231 RTITest_assertComparisonForTypeWithAction( \
238 RTITest_assertComparisonForTypeWithAction( \
239 expected__.nanosec, \
255#define RTITest_assertComparisonForDDS_Duration_t(expected__, actual__, operation__) \
256 RTITest_assertComparisonForDDS_Duration_tWithAction( \
269#define RTITest_assertEqualsDDS_Duration_t(expected__, actual__) \
270 RTITest_assertComparisonForDDS_Duration_t(expected__, actual__, ==)
280#define RTITest_assertEqualsString(expected__, actual__) \
281 RTITest_debugAssert(strcmp((expected__), (actual__)) == 0); \
282 if (strcmp((expected__), (actual__)) != 0) { \
283 const char *expectedConst__ = expected__; \
284 const char *actualConst__ = actual__; \
286 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
287 "[%s:%d] assertion failed: strcmp(%s, %s) == 0: expected: %s, " \
306#define RTITest_assertNotEqualsString(expected__, actual__) \
307 RTITest_debugAssert(strcmp((expected__), (actual__)) != 0); \
308 if (strcmp((expected__), (actual__)) == 0) { \
309 const char *expectedConst__ = expected__; \
310 const char *actualConst__ = actual__; \
312 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
313 "[%s:%d] assertion failed: strcmp(%s, %s) != 0: not expected: %s, " \
333#define RTITest_assertSubString(expectedSubStr__, actualStr__) \
334 RTITest_debugAssert(strstr((actualStr__), (expectedSubStr__)) == NULL); \
335 if (strstr((actualStr__), (expectedSubStr__)) == NULL) { \
337 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
338 "[%s:%d] assertion failed: expected to find string %s in %s", \
352#define RTITest_assertNotNull(object__) \
353 RTITest_assertNotNullWithAction(object__, goto done)
361#define RTITest_assertNotNullWithAction(object__, failAction__) \
362 RTITest_debugAssert((object__) != NULL); \
363 if ((object__) == NULL) { \
365 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
366 "[%s:%d] pointer is null: %s", \
379#define RTITest_assertNull(object__) \
380 RTITest_assertNullWithAction(object__, goto done)
388#define RTITest_assertNullWithAction(object__, failAction__) \
389 RTITest_debugAssert((object__) == NULL); \
390 if ((object__) != NULL) { \
392 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
393 "[%s:%d] pointer is not null: %s", \
408#define RTITest_assertRetcodeWithAction( \
413 DDS_ReturnCode_t retCodeTmp__ = (retcode__); \
414 RTITest_debugAssert(retCodeTmp__ == (expectedRetcode__)); \
415 if (retCodeTmp__ != (expectedRetcode__)) { \
416 if ((int) retCodeTmp__ < 0) { \
418 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
419 "[%s:%d] assertion failed: %s == %s", \
423 #expectedRetcode__); \
425 unsigned int retCodeAsUInt__ = (unsigned int) retCodeTmp__; \
426 unsigned int index__ = \
427 (retCodeAsUInt__ < RTI_TEST_NUM_RETCODES - 1 \
429 : RTI_TEST_NUM_RETCODES); \
431 (retCodeTmp__ == DDS_RETCODE_NOT_ALLOWED_BY_SECURITY \
432 ? RTI_TEST_NUM_RETCODES - 1 \
435 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
436 "[%s:%d] assertion failed: %s == %s: got %s", \
440 #expectedRetcode__, \
441 RTITest_g_returnCodeStrings[index__]); \
454#define RTITest_assertOkWithAction(retcode__, failAction__) \
455 RTITest_assertRetcodeWithAction(retcode__, failAction__, DDS_RETCODE_OK)
463#define RTITest_assertOk(retcode__) \
464 RTITest_assertOkWithAction((retcode__), goto done)
466#define RTITest_assertPassed(retcode__) \
467 RTITest_assertEqualsInt(RTI_TEST_RETCODE_PASSED, (retcode__))
476#define RTITest_assertErrorWithAction(retcode__, failAction__) \
477 RTITest_assertRetcodeWithAction(retcode__, failAction__, DDS_RETCODE_ERROR)
486#define RTITest_assertEqualsRetcode(expected__, retcode__) \
487 RTITest_assertRetcodeWithAction(retcode__, goto done, expected__)
495#define RTITest_assertError(retcode__) \
496 RTITest_assertErrorWithAction((retcode__), goto done)
509#define RTITest_assertOkAfterDone(retcode__) \
510 RTITest_assertOkWithAction((retcode__), result = RTI_TEST_RETCODE_FAILED)
517#define RTITest_assertFalseWithAction(statement__, failAction__) \
518 RTITest_debugAssert(statement__); \
519 if ((statement__)) { \
521 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
522 "[%s:%d] assertion failed: !%s", \
535#define RTITest_assertFalse(statement__) \
536 RTITest_assertFalseWithAction(statement__, goto done)
544#define RTITest_assertFalseAfterDone(statement__) \
545 RTITest_assertFalseWithAction(statement__, result = RTI_TEST_RETCODE_FAILED)
558#define RTITest_assertMarginWithAction(expected__, count__, tolerance_percentage__, failAction__) \
560 double tolerance = (double) (tolerance_percentage__) / 100; \
561 double max_count = (double) (expected__) * (1 + tolerance); \
562 double min_count = (double) (expected__) * (1 - tolerance); \
563 if (!((double) (count__) >= min_count \
564 && (double) (count__) <= max_count)) { \
566 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
567 "%s:[%s:%d]: value out of range: [%f, %f], count: %f\n", \
573 (double) (count__)); \
588#define RTITest_assertMargin(expected__, count__, tolerance_percentage__) \
589 RTITest_assertMarginWithAction( \
592 tolerance_percentage__, \
601#define RTITest_fail(msg__) \
603 &RTI_TEST_LOG_EMPTY_TEMPLATE, \
616#define RTITest_isSpdp2Enabled(participantQos__) \
617 (participantQos__.discovery_config.builtin_discovery_plugins \
618 & DDS_DISCOVERYCONFIG_BUILTIN_SPDP2)