Unit Test Framework C and Traditional C++ API Reference
Utilities

Macros to help writing unit tests. More...

Macros

#define RTITest_fail(msg__)
 Make a test fail with a given message. More...
 
#define RTITest_waitForConditionNoFailure(cond__, maxSeconds__)
 Wait for a condition to be true. More...
 
#define RTITest_waitForConditionWithAction(cond__, maxSeconds__, action__)
 Wait for a condition to be true. Otherwise, run the given action. More...
 
#define RTITest_waitForCondition(cond__, maxSeconds__)    RTITest_waitForConditionEx(cond__, maxSeconds__, 0)
 Wait for a condition to be true. More...
 
#define RTITest_waitForOk(retcode__, maxSeconds__)    RTITest_waitForConditionEx((retcode__) == DDS_RETCODE_OK, (maxSeconds__), 0)
 Wait for a DDS_ReturnCode_t return code to be DDS_RETCODE_OK. More...
 
#define RTITest_waitWhileConditionMatchWithAction(cond__, maxSeconds__, action__)
 Wait while a condition is true for a given number of seconds. If the condition becomes false, run the given action. More...
 
#define RTITest_waitWhileConditionMatch(cond__, maxSeconds__)    RTITest_waitWhileConditionMatchWithAction(cond__, maxSeconds__, goto done)
 Wait while a condition is true for a given number of seconds. More...
 
#define RTITest_waitForGreaterThanInt(expected__, actual__, maxSeconds__)
 Wait for a given integer to become greater than another one. More...
 
#define RTITest_waitForGreaterOrEqualsInt(expected__, actual__, maxSeconds__)
 Wait for an integer to become equal to or greater than another one. More...
 
#define RTITest_waitForLessThanOrEqualsInt(expected__, actual__, maxSeconds__)
 Wait for a given integer to become less than or equal to another one. More...
 
#define RTITest_waitForEqualsInt(expected__, actual__, maxSeconds__)
 Wait for two given integers to become equal. More...
 
#define RTITest_waitForEqualsLong(expected__, actual__, maxSeconds__)
 Wait for two given long integers to become equal. More...
 
#define RTITest_waitForEqualsLongLong(expected__, actual__, maxSeconds__)
 Wait for two given long long integers to become equal. More...
 
#define RTITest_waitForGreaterThanLongLong(expected__, actual__, maxSeconds__)
 Wait for a long long integer to become greater than another one. More...
 
#define RTITest_waitForEqualsUnsignedInt(expected__, actual__, maxSeconds__)
 Wait for two given unsigned integers to become equal. More...
 
#define RTITest_waitForEqualsUnsignedLongLong(expected__, actual__, maxSeconds__)
 Wait for two given unsigned long long integers to become equal. More...
 
#define RTITestTime_toMilliseconds(s__, msec__, time__)
 Convert RTITestTime into seconds and milliseconds. More...
 
#define RTITestTime_toMicroseconds(s__, usec__, time__)
 Convert RTITestTime into seconds and microseconds. More...
 
#define RTITestTime_toNanoseconds(s__, nsec__, time__)
 Convert RTITestTime into seconds and nanoseconds. More...
 
#define RTITestTime_fromMilliseconds(time__, s__, msec__)
 Convert seconds and milliseconds into RTITestTime. More...
 
#define RTITestTime_fromMicroseconds(time__, s__, usec__)
 Convert seconds and microseconds into RTITestTime. More...
 
#define RTITestTime_fromNanoseconds(time__, s__, nsec__)
 Convert seconds and nanoseconds into RTITestTime. More...
 

Detailed Description

Macros to help writing unit tests.

Macro Definition Documentation

◆ RTITest_fail

#define RTITest_fail (   msg__)
Value:
RTITest_assertLog( \
&RTI_TEST_LOG_EMPTY_TEMPLATE, \
"%s[%s:%d] %s\n", \
RTI_FUNCTION_NAME, \
__FILE__, \
__LINE__, \
msg__); \
goto done;

Make a test fail with a given message.

Parameters
msg__In. The message to be printed.

Calls goto done if the assertion fails. Therefore, this macro requires a done label to be defined in the method that this assertion is called in.

◆ RTITest_waitForConditionNoFailure

#define RTITest_waitForConditionNoFailure (   cond__,
  maxSeconds__ 
)
Value:
RTITest_waitForConditionNoFailureEx( \
cond__, \
maxSeconds__, \
0 /* additionalSleepTimeSec__ */)

Wait for a condition to be true.

Parameters
cond__The condition to wait for.
maxSeconds__The maximum number of seconds to wait.

◆ RTITest_waitForConditionWithAction

#define RTITest_waitForConditionWithAction (   cond__,
  maxSeconds__,
  action__ 
)
Value:
RTITest_waitForConditionWithActionEx( \
cond__, \
maxSeconds__, \
0, /* additionalSleepTimeSec__ */ \
action__)

Wait for a condition to be true. Otherwise, run the given action.

Parameters
cond__The condition to wait for.
maxSeconds__The maximum number of seconds to wait.
action__The action to run if the condition is not true.

◆ RTITest_waitForCondition

#define RTITest_waitForCondition (   cond__,
  maxSeconds__ 
)     RTITest_waitForConditionEx(cond__, maxSeconds__, 0)

Wait for a condition to be true.

Parameters
cond__The condition to wait for.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForOk

#define RTITest_waitForOk (   retcode__,
  maxSeconds__ 
)     RTITest_waitForConditionEx((retcode__) == DDS_RETCODE_OK, (maxSeconds__), 0)

Wait for a DDS_ReturnCode_t return code to be DDS_RETCODE_OK.

Parameters
retcode__The DDS_ReturnCode_t code to wait for.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitWhileConditionMatchWithAction

#define RTITest_waitWhileConditionMatchWithAction (   cond__,
  maxSeconds__,
  action__ 
)
Value:
{ \
const struct RTITestTime sleepTime__ = { 0, 429496730 }; \
int sleeps__ = 0; \
int condEv__; \
while ((condEv__ = (cond__)) && sleeps__ < ((maxSeconds__) * 10)) { \
RTITest_sleep(&sleepTime__); \
++sleeps__; \
} \
if (!condEv__) { \
RTITest_assertLog( \
&RTI_TEST_LOG_EMPTY_TEMPLATE, \
"[%s:%d] wait while condition match failed: %s", \
__FILE__, \
__LINE__, \
#cond__); \
action__; \
} \
}

Wait while a condition is true for a given number of seconds. If the condition becomes false, run the given action.

Parameters
cond__Wait while this condition is true.
maxSeconds__The maximum number of seconds to wait.
action__The action to run if the condition becomes false.

◆ RTITest_waitWhileConditionMatch

#define RTITest_waitWhileConditionMatch (   cond__,
  maxSeconds__ 
)     RTITest_waitWhileConditionMatchWithAction(cond__, maxSeconds__, goto done)

Wait while a condition is true for a given number of seconds.

Parameters
cond__Wait while this condition is true.
maxSeconds__The maximum number of seconds to wait.

◆ RTITest_waitForGreaterThanInt

#define RTITest_waitForGreaterThanInt (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForGreaterThanIntExt( \
((void) 0), \
expected__, \
actual__, \
maxSeconds__)

Wait for a given integer to become greater than another one.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForGreaterOrEqualsInt

#define RTITest_waitForGreaterOrEqualsInt (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForGreaterOrEqualsIntExt( \
((void) 0), \
expected__, \
actual__, \
maxSeconds__)

Wait for an integer to become equal to or greater than another one.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForLessThanOrEqualsInt

#define RTITest_waitForLessThanOrEqualsInt (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForLessThanOrEqualsIntExt( \
((void) 0), \
expected__, \
actual__, \
maxSeconds__)

Wait for a given integer to become less than or equal to another one.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForEqualsInt

#define RTITest_waitForEqualsInt (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForEquals( \
expected__, \
actual__, \
((expected__) == (actual__)), \
"%d", \
maxSeconds__)

Wait for two given integers to become equal.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForEqualsLong

#define RTITest_waitForEqualsLong (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForEquals( \
expected__, \
actual__, \
((expected__) == (actual__)), \
"%ld", \
maxSeconds__)

Wait for two given long integers to become equal.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForEqualsLongLong

#define RTITest_waitForEqualsLongLong (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForEquals( \
expected__, \
actual__, \
((expected__) == (actual__)), \
"%lld", \
maxSeconds__)

Wait for two given long long integers to become equal.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForGreaterThanLongLong

#define RTITest_waitForGreaterThanLongLong (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForGreaterThanLongLongExt( \
((void) 0), \
expected__, \
actual__, \
maxSeconds__)

Wait for a long long integer to become greater than another one.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForEqualsUnsignedInt

#define RTITest_waitForEqualsUnsignedInt (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForEquals( \
expected__, \
actual__, \
((expected__) == (actual__)), \
"%u", \
maxSeconds__)

Wait for two given unsigned integers to become equal.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITest_waitForEqualsUnsignedLongLong

#define RTITest_waitForEqualsUnsignedLongLong (   expected__,
  actual__,
  maxSeconds__ 
)
Value:
RTITest_waitForEquals( \
expected__, \
actual__, \
((expected__) == (actual__)), \
"%llu", \
maxSeconds__)

Wait for two given unsigned long long integers to become equal.

Parameters
expected__The expected value.
actual__The actual value.
maxSeconds__The maximum number of seconds to wait.

Calls goto done if the condition is never met. Therefore, this macro requires a done label to be defined in the method that this macro is called in.

◆ RTITestTime_toMilliseconds

#define RTITestTime_toMilliseconds (   s__,
  msec__,
  time__ 
)
Value:
RTITestTime_toPrecision( \
s__, \
msec__, \
time__, \
RTI_TEST_TIME_SEC_TO_MILLISECONDS);

Convert RTITestTime into seconds and milliseconds.

Parameters
s__Out. The seconds field of the RTITestTime.
msec__Out. The fraction of the RTITestTime expressed in milliseconds.
time__In. The input RTITestTime.

◆ RTITestTime_toMicroseconds

#define RTITestTime_toMicroseconds (   s__,
  usec__,
  time__ 
)
Value:
RTITestTime_toPrecision( \
s__, \
usec__, \
time__, \
RTI_TEST_TIME_SEC_TO_MICROSECONDS);

Convert RTITestTime into seconds and microseconds.

Parameters
s__Out. The seconds field of the RTITestTime.
usec__Out. The fraction of the RTITestTime expressed in microseconds.
time__In. The input RTITestTime.

◆ RTITestTime_toNanoseconds

#define RTITestTime_toNanoseconds (   s__,
  nsec__,
  time__ 
)
Value:
RTITestTime_toPrecision( \
s__, \
nsec__, \
time__, \
RTI_TEST_TIME_SEC_TO_NANOSECONDS);

Convert RTITestTime into seconds and nanoseconds.

Parameters
s__Out. The seconds field of the RTITestTime.
nsec__Out. The fraction of the RTITestTime expressed in nanoseconds.
time__In. The input RTITestTime.

◆ RTITestTime_fromMilliseconds

#define RTITestTime_fromMilliseconds (   time__,
  s__,
  msec__ 
)
Value:
RTITestTime_fromPrecision( \
time__, \
s__, \
msec__, \
RTI_TEST_TIME_SEC_TO_MILLISECONDS)

Convert seconds and milliseconds into RTITestTime.

Parameters
time__Out. The output RTITestTime.
s__In. The amount of seconds.
msec__In. The amount of milliseconds.

◆ RTITestTime_fromMicroseconds

#define RTITestTime_fromMicroseconds (   time__,
  s__,
  usec__ 
)
Value:
RTITestTime_fromPrecision( \
time__, \
s__, \
usec__, \
RTI_TEST_TIME_SEC_TO_MICROSECONDS)

Convert seconds and microseconds into RTITestTime.

Parameters
time__Out. The output RTITestTime.
s__In. The amount of seconds.
usec__In. The amount of microseconds.

◆ RTITestTime_fromNanoseconds

#define RTITestTime_fromNanoseconds (   time__,
  s__,
  nsec__ 
)
Value:
RTITestTime_fromPrecision( \
time__, \
s__, \
nsec__, \
RTI_TEST_TIME_SEC_TO_NANOSECONDS)

Convert seconds and nanoseconds into RTITestTime.

Parameters
time__Out. The output RTITestTime.
s__In. The amount of seconds.
nsec__In. The amount of nanoseconds.