Page tree

Skip to end of metadata
Go to start of metadata

These macros / functions can be used to redirect stdin / stdout / stderr for test case execution.

MacroDefinition
CppTest_StreamRedirect*
CppTest_RedirectStdInput(const char* value);
Sets values of the stdin stream for the current test case to the value of the supplied string.
CppTest_StreamRedirect*
CppTest_RedirectNStdInput(const char* value, unsigned int size)
Sets values of the stdin stream for the current test case to the value of the first 'size' characters of the supplied string.
CppTest_StreamRedirect* CppTest_RedirectStdOutput()Redirects stdout stream for the currently executed test case. The returned CppTest_StreamRedirect object can be used to validate stream contents in the test case post-condition section. The previous value of the stdout stream is restored automatically at the end of the current test case execution.
CppTest_StreamRedirect* CppTest_RedirectStdError()Redirects stderr stream for the currently executed test case. The returned CppTest_StreamRedirect object can be used to validate stream contents in the test case post-condition section. The previous value of the stderr stream is restored automatically at the end of the current test case execution.
CppTest_StreamCompare(CppTest_StreamRedirect* redirect, const char* value)Used to validate contents of the redirected stdout / stderr stream. Returns 0 if the 'value' matches the  stream value, an integer less than zero if the 'value' is less than the stream value, or an integer greater than zero if the 'value' is greater than the stream value.
CppTest_StreamNCompare(CppTest_StreamRedirect* redirect, const char* value, unsigned int size)Used to validate contents of the redirected stdout / stderr stream. Returns 0 if the 'value' matches the stream value, an integer less than zero if the 'value' is less than the stream value, or an integer greater than zero if the 'value' is greater than the stream value. Only the first 'size' characters of the stream are compared.

int
CppTest_StreamSearch(CppTest_StreamRedirect, redirect, const char* pattern)

Used to validate contents of the redirected stdout / stderr stream. Searches for the given pattern in the redirected stream. Returns the  index of the pattern found in the stream or -1 if pattern wasn't found.
int
CppTest_StreamNSearch(CppTest_StreamRedirect* redirect, const char* pattern, unsigned int size)
Used to validate contents of the redirected stdout / stderr stream. Searches for the first 'size' characters of the given pattern in the redirected stream. Returns the index of the pattern found in the stream or -1 if pattern wasn't found.
char*
CppTest_StreamReadData(CppTest_StreamRedirect* redirect, unsigned int* len)
Returns a pointer to a buffer with data read from the redirected stream. The size of the buffer will be  passed back in the 'len' parameter (if non-null is passed to the function). The buffer is allocated with the cpptestMalloc() function. The returned buffer should be freed using the cpptestFree() function.
void
CppTest_StreamReset(CppTest_StreamRedirect* redirect)
Resets the C++test internal stream to the default state. It is done automatically for each redirected stream at the end of the test case execution.
  • No labels