This topic explains how you can have tests examine data which is sent to standard output or standard error streams. This is accomplished by interacting with the C++test Stream API, which is designed for using standard input/output streams. This API allows manipulation and content verification of streams.
Using the C++test Stream API
To have tests examine data which is sent to standard output or standard error streams:
To redirect the stream before test case execution, use one of the following functions:
CppTest_StreamRedirect* CppTest_RedirectStdError()return a pointer to a special internal C++test structure or NULL (in case of error). This pointer can be used later in other stream redirection functions, as illustrated in Example.
To compare the content of streams with a null-terminated string or a data buffer, use the following functions:
Both functions return 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_StreamComparebehaves like strcmp.
To get the whole data buffer from the stream using a function, use
char* CppTest_StreamReadData(CppTest_StreamRedirect* redirect, unsigned int* len);This function returns a pointer to a buffer with data from the stream. The size of the buffer will be passed back in the
lenparameter. The buffer is allocated with the
mallocfunction. You are responsible for freeing this buffer.
To set values for the input stream, use the following initialization functions:
These functions set the input stream to the value of the supplied string (using N characters in the second case).
At the end of the test case, reset the C++test internal stream to the default state with