#pragma once
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include "gtest/gtest.h"
class CConsole
{
public:
CConsole(void)
{
AllocConsole();
int hCrun;
hCrun = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
FILE* hFile = _fdopen(hCrun, "w");
// use default stream buffer
setvbuf(hFile, NULL, _IONBF, 0);
*stdout = *hFile;
}
public:
~CConsole(void)
{
FreeConsole();
}
};
#define RUN_TEST() \
CConsole cc; \
int argc = 1; \
TCHAR* argv = _T("E:\xxxx\trunk\Bin\xxxx.exe"); \
testing::InitGoogleTest(&argc, &argv); \
RUN_ALL_TESTS(); \
HWND hwnd = GetConsoleWindow(); \
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); \
AfxMessageBox(_T("about to exit!")); \
exit(0);
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include "gtest/gtest.h"
class CConsole
{
public:
CConsole(void)
{
AllocConsole();
int hCrun;
hCrun = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
FILE* hFile = _fdopen(hCrun, "w");
// use default stream buffer
setvbuf(hFile, NULL, _IONBF, 0);
*stdout = *hFile;
}
public:
~CConsole(void)
{
FreeConsole();
}
};
#define RUN_TEST() \
CConsole cc; \
int argc = 1; \
TCHAR* argv = _T("E:\xxxx\trunk\Bin\xxxx.exe"); \
testing::InitGoogleTest(&argc, &argv); \
RUN_ALL_TESTS(); \
HWND hwnd = GetConsoleWindow(); \
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); \
AfxMessageBox(_T("about to exit!")); \
exit(0);
本文介绍了一个名为CConsole的类的实现,该类用于创建控制台并重定向标准输出。此外,还提供了一个宏定义RUN_TEST(),用于初始化并运行谷歌测试框架中的所有测试用例。
7334

被折叠的 条评论
为什么被折叠?



