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

Provides the infrastructure to set up recursive module testing. See the user's manual for examples of how to use most of these APIs. More...

Macros

#define RTITestSetting_getTestCount(testArray)    (sizeof((testArray)) / sizeof(RTITestFunction))
 Get the number of tests in the test array. More...
 

Typedefs

typedef RTITestReturnCode(* RTITestFunction) (const struct RTITestSetting *setting)
 Function prototype for all tests. More...
 

Functions

RTIBool RTITestSetting_parseArgument (struct RTITestSetting *setting, int argCount, char **argv)
 Parses command-line arguments to initialize an RTITestSetting structure. More...
 
void RTITestSetting_getRange (const struct RTITestSetting *setting, int *begin, int *end, RTITestLevel currentLevel)
 Given the test setting and the test level, this function extracts the index of the first and last test at that level. More...
 
RTITestReturnCode RTITestSetting_runTests (const struct RTITestSetting *setting, const char *methodName, const RTITestFunction *test, int testCount, int begin, int end)
 Given a set of tests and a test setting, run a subset of these tests with that test setting. More...
 
void RTITestSetting_printComplete (const char *methodName)
 Printout to indicate completion of a Tester. More...
 
void RTITestSetting_init (struct RTITestSetting *setting)
 Fill setting with default values. More...
 
int RTITestSetting_enableHeapMonitoringSupport (void)
 Enables heap monitoring support. More...
 
void RTITestSetting_disableHeapMonitoringSupport (int *ok)
 Disables heap monitoring support and checks if there are memory leaks. More...
 
int RTITestSetting_getCurrentNumberOfRetries (void)
 Get the current number of retries. More...
 

Detailed Description

Provides the infrastructure to set up recursive module testing. See the user's manual for examples of how to use most of these APIs.

Many of the functions documented here are required to be called in the main Tester and TestSuite run methods; a deep understanding of exactly what they do is not needed. An example skeleton of a Tester run method is as follows:

RTITestReturnCode tester_run(const struct RTITestSetting *setting) {
const char *METHOD_NAME = RTI_FUNCTION_NAME;
RTIBool ok;
int begin, end;
RTITestFunction test[] = {
// an array of test suite functions
}
RTITestLog_printTestName();
// Setup
RTITestSetting_setupWithConnext();
if (setting->enableHeapMonitoring) {
// Make sure this is done before any memory allocation
}
RTITestSetting_getRange(setting, &begin,result &end,
RTI_TEST_LEVEL_SUBMODULE);
setting,
METHOD_NAME,
test,
begin,
end));
done:
if (setting->enableHeapMonitoring) {
}
return result;
}
#define RTITest_assert(statement__)
Run and assert a statement. If false, go to done tag.
Definition: test_assert.h:140
#define RTITest_assertAfterDone(statement__)
Run and assert a statement after the done tag. This sets the variable result to RTI_TEST_RETCODE_FAIL...
Definition: test_assert.h:149
#define RTITestReturnCode
Return code used for tests.
Definition: test_types.h:48
#define RTI_TEST_RETCODE_FAILED
Use RTI_TEST_RETCODE_FAILED when a test has failed.
Definition: test_types.h:54
#define RTI_TEST_RETCODE_PASSED
Use RTI_TEST_RETCODE_PASSED when a test has passed.
Definition: test_types.h:59
RTITestReturnCode(* RTITestFunction)(const struct RTITestSetting *setting)
Function prototype for all tests.
Definition: test_setting.h:642
void RTITestSetting_getRange(const struct RTITestSetting *setting, int *begin, int *end, RTITestLevel currentLevel)
Given the test setting and the test level, this function extracts the index of the first and last tes...
void RTITestSetting_printComplete(const char *methodName)
Printout to indicate completion of a Tester.
#define RTITestSetting_getTestCount(testArray)
Get the number of tests in the test array.
Definition: test_setting.h:1082
int RTITestSetting_enableHeapMonitoringSupport(void)
Enables heap monitoring support.
void RTITestSetting_disableHeapMonitoringSupport(int *ok)
Disables heap monitoring support and checks if there are memory leaks.
RTITestReturnCode RTITestSetting_runTests(const struct RTITestSetting *setting, const char *methodName, const RTITestFunction *test, int testCount, int begin, int end)
Given a set of tests and a test setting, run a subset of these tests with that test setting.

The only difference between the above method and a TestSuite run method is that a TestSuite method should not call RTITestSetting_printComplete() and the fourth argument passed to RTITestSetting_getRange() should be RTI_TEST_LEVEL_UNIT.

Macro Definition Documentation

◆ RTITestSetting_getTestCount

#define RTITestSetting_getTestCount (   testArray)     (sizeof((testArray)) / sizeof(RTITestFunction))

Get the number of tests in the test array.

Typedef Documentation

◆ RTITestFunction

typedef RTITestReturnCode(* RTITestFunction) (const struct RTITestSetting *setting)

Function prototype for all tests.

All tests (module test, submodule test or unit test) use this function prototype. This allows grouping them in arrays for recursive execution.

The RTITestSetting parameter is specified at the module test level and passed down via the submodule tests to the unit tests.

Precondition
Setting is a valid, non-NULL pointer.
Postcondition
One or more aspects of the module have been fully tested. All system resources must have been returned to their pre-condition state. For example, malloc() is allowed, but the memory must be freed finally, regardless of success or failure.
Parameters
settingIn. Pointer to the test setting information.
Returns
1 on success, 0 otherwise.
Exceptions
upto the implementer.

Function Documentation

◆ RTITestSetting_parseArgument()

RTIBool RTITestSetting_parseArgument ( struct RTITestSetting *  setting,
int  argCount,
char **  argv 
)

Parses command-line arguments to initialize an RTITestSetting structure.

This function is only useful on platforms supporting main() as the entry point.

Example usage:

int main(int argc, char **argv)
{
struct RTITestSetting setting;
//initialize setting with default values
//overwrite some of the default values with command-line arguments
RTITestSetting_parseArgument(&setting, argc, argv));
return tester_run(&setting) == RTI_TEST_RETCODE_PASSED ? 0 : -1;
}
void RTITestSetting_init(struct RTITestSetting *setting)
Fill setting with default values.
RTIBool RTITestSetting_parseArgument(struct RTITestSetting *setting, int argCount, char **argv)
Parses command-line arguments to initialize an RTITestSetting structure.

Run your program with the argument -help to check the available arguments and a brief description of the effect of each of them.

RTITestSetting_parseArgument() automatically prints a usage message if it cannot successfully parse all command-line arguments.

Precondition
setting and argv valid, non-NULL pointers.
Postcondition
setting struct updated with command-line arguments.
Parameters
settingOut. "this" pointer. The command-line arguments will be written to this RTITestSetting struct.
argCountIn. First parameter of main() entry point.
argvIn. Second parameter of main() entry point.
Returns
1 if parsing was successful, 0 otherwise.
See also
RTITestSetting_set

◆ RTITestSetting_getRange()

void RTITestSetting_getRange ( const struct RTITestSetting *  setting,
int *  begin,
int *  end,
RTITestLevel  currentLevel 
)

Given the test setting and the test level, this function extracts the index of the first and last test at that level.

The test setting contains the begin and end test numbers, both at the unit test and submodule test level. This function extracts those numbers. Use the currentLevel parameter to specify which level you need the information for.

Postcondition
begin and end contain the index of the first and last test to be run.
Parameters
settingIn. "this" pointer. The test setting that contains the info.
beginOut. Pointer to begin answer.
endOut. Pointer to end answer.
currentLevelIn. Level at which the info must be obtained.
See also
RTITestSetting_runTests

◆ RTITestSetting_runTests()

RTITestReturnCode RTITestSetting_runTests ( const struct RTITestSetting *  setting,
const char *  methodName,
const RTITestFunction *  test,
int  testCount,
int  begin,
int  end 
)

Given a set of tests and a test setting, run a subset of these tests with that test setting.

The set of tests is passed as an array of RTITestFunction function pointers. The subset of tests to run is specified as a range of array indices, from index begin to index end.

Negative indices in the range are interpreted as first and last test respectively. All other indices outside of the array bounds are ignored.

Postcondition
All tests from index begin to end in array test ran and passed.
Parameters
settingIn. "this". Run applicable tests with this setting (passed as a parameter to each test).
methodNameIn. Name of the module or submodule that is firing off the batch test. Used for generating warning or error messages.
testIn. Array of tests, as function pointers.
testCountIn. Size of the test array. This includes any NULL entries, which will be skipped.
beginIn. The array index of the first test to run. A negative number will be set to zero.
endIn. The array index of the last test to run. A negative number will be set to testCount-1.
Returns
1 if all tests in the specified range passed or if the range is empty, 0 otherwise.
See also
RTITestSetting_getRange

◆ RTITestSetting_printComplete()

void RTITestSetting_printComplete ( const char *  methodName)

Printout to indicate completion of a Tester.

◆ RTITestSetting_init()

void RTITestSetting_init ( struct RTITestSetting *  setting)

Fill setting with default values.

Override the values you are interested in after this. This function should be called in the test executable main function before RTITestSetting_parseArgument().

Precondition
valid arg
Parameters
settingOut. The setting to initialize
See also
RTITestSetting_parseArgument() for an example usage.

◆ RTITestSetting_enableHeapMonitoringSupport()

int RTITestSetting_enableHeapMonitoringSupport ( void  )

Enables heap monitoring support.

When the command-line option -enableHeapMonitoring is used, the field enableHeapMonitoring in the RTITestSetting structure will be set to RTI_TRUE. The tester_run function in a module should call this API to enable support for heap monitoring. For example:

if (setting->enableHeapMonitoring) {
// Make sure this is done before any memory allocation
}

The function must be called at the very beginning of the test before doing any DDS calls.

If the function is not called and the command-line option enableHeapMonitoring is used, the test will fail indicating that heap monitoring has not been enabled.

◆ RTITestSetting_disableHeapMonitoringSupport()

void RTITestSetting_disableHeapMonitoringSupport ( int *  ok)

Disables heap monitoring support and checks if there are memory leaks.

When the command-line option enableHeapMonitoring is used, this function must be called at the end of a tester_run function in a module to disable support for heap monitoring.

For example

if (setting->enableHeapMonitoring) {
}

If there are memory leaks, ok is set to RTI_FALSE and an exception is logged.

Parameters
okOut. It will be set to 0 if there are memory leaks.
See also
RTITestSetting_enableHeapMonitoringSupport()

◆ RTITestSetting_getCurrentNumberOfRetries()

int RTITestSetting_getCurrentNumberOfRetries ( void  )

Get the current number of retries.

The maxRetries option allows you to retry a failed test until it succeeds or until the maximum retry number specifed with this argument is reached. This function returns the current number of times a test has been retried so far. A value of zero means that the test is being run for the first time.