这些宏/函数可用于重定向 stdin/stdout/stderr 以执行测试用例。

定义
CppTest_StreamRedirect*
CppTest_RedirectStdInput(const char* value);
将当前测试用例的 stdin 流的值设置为提供的字符串的值。
CppTest_StreamRedirect*
CppTest_RedirectNStdInput(const char* value, unsigned int size)
将当前测试用例的 stdin 流的值设置为所提供字符串的第一个 'size' 字符的值。
CppTest_StreamRedirect* CppTest_RedirectStdOutput()重定向当前执行的测试用例的 stdout 流。返回的 CppTest_StreamRedirect 对象可用于验证测试用例后置条件部分中的流内容。在当前测试用例执行结束时自动恢复标准输出流的先前值。
CppTest_StreamRedirect* CppTest_RedirectStdError()为当前执行的测试用例重定向 stderr 流。返回的 CppTest_StreamRedirect 对象可用于验证测试用例后置条件部分中的流内容。在当前测试用例执行结束时自动恢复 stderr 流的先前值。
CppTest_StreamCompare(CppTest_StreamRedirect* redirect, const char* value)用于验证重定向的 stdout/stderr 流的内容。如果“值”与流值匹配,则返回 0;如果“值”小于流值,则返回小于零的整数;如果“值”大于流值,则返回大于零的整数。
CppTest_StreamNCompare(CppTest_StreamRedirect* redirect, const char* value, unsigned int size)用于验证重定向的 stdout/stderr 流的内容。如果“值”与流值匹配,则返回 0;如果“值”小于流值,则返回小于零的整数;如果“值”大于流值,则返回大于零的整数。仅比较流的第一个 'size’字符。

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

用于验证重定向的 stdout/stderr 流的内容。在重定向流中搜索给定模式。返回在流中找到的模式的索引,如果未找到模式,则返回 -1。
int
CppTest_StreamNSearch(CppTest_StreamRedirect* redirect, const char* pattern, unsigned int size)
用于验证重定向的 stdout/stderr 流的内容。在重定向流中搜索给定模式的第一个 'size’字符。返回在流中找到的模式的索引,如果未找到模式,则返回 -1。
char*
CppTest_StreamReadData(CppTest_StreamRedirect* redirect, unsigned int* len)
返回一个指向缓冲区的指针,其中包含从重定向流中读取的数据。缓冲区的大小将在 'len' 参数中传回(如果将非空值传递给函数)。缓冲区由 cpptestMalloc()函数分配。应该使用 cpptestFree() 函数释放返回的缓冲区。
void
CppTest_StreamReset(CppTest_StreamRedirect* redirect)
将 C++test 内部流重置为默认状态。它在测试用例执行结束时为每个重定向流自动完成。
  • No labels