For example, assume that C++test generated the following test case:
void TestSuite_getData_0::test_getData_0()
{
/* Pre-condition initialization */
/* Initializing argument 0 (this) */
/* Initializing constructor argument 1 (fill) */
char _cpptest_TestObject_arg_fill = cpptestLimitsGetMaxChar();
::Data _cpptest_TestObject (_cpptest_TestObject_arg_fill);
/* Tested function call */
const char * _result = _cpptest_TestObject.getData();
/* Post-condition check */
CPPTEST_POST_CONDITION_CSTR("const char* _result", _result)
}
There is no need for additional precondition initialization other than creating an object to perform a function call on it. However, for the sake of this example, assume that we want to introduce the following modifications:
- Change the constructor used for creating ::Data object to: ::Data _cpptest_TestObject('g');. This will fill the internal char buffer with g.
- Replace the postcondition macro with a section with validation for controlling test results.
The modified test case would look like this:
void TestSuite_getData_0::test_getData_0()
{
/* Pre-condition initialization */
/* Initializing argument 0 (this) */
::Data _cpptest_TestObject('g') ;
/* Tested function call */
const char * _result = _cpptest_TestObject.getData();
/* Post-condition check */
bool res = true;
for (int i = 0; i < _cpptest_TestObject.getSize() - 1; i++) {
if (_result[i] != 'g') {
res = false;
}
}
// To see what is in the buffer:
CPPTEST_MESSAGE(_result);
// To control test case status:
CPPTEST_ASSERT_MESSAGE("Test failed : Buffer should be filled with 'g'",
res == true);
}
Note: The CPPTEST_MESSAGE macro will send the content of “_result” buffer as the test case output, and the CPPTEST_ASSERT_MESSAGE will assert when the test condition fails.