控制台程序集成gtest通用代码
#include "stdafx.h"
#include "gtest/gtest.h"
int mytest(int argc, _TCHAR* argv[])
{
int nTestReturnValue = 0;
testing::GTEST_FLAG(output) = _T("xml:gtest_result.xml");
testing::InitGoogleTest(&argc, argv);
nTestReturnValue = RUN_ALL_TESTS();
return nTestReturnValue;
}
int _tmain(int argc, _TCHAR* argv[])
{
return mytest(argc, argv);
}
MFC程序集成gtest通用代码
CConsole cc;
int argc = 0;
TCHAR* argv = _T("");
CString sOutput;
sOutput.Format("xml:%sidp_gtest_result.xml",m_sBinPath);
testing::GTEST_FLAG(output) = sOutput;
testing::InitGoogleTest(&argc, &argv);
RUN_ALL_TESTS();
HWND hwnd = GetConsoleWindow();
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
if ( __argc == 1 )
{
AfxMessageBox("click to exit!");
}
return FALSE;
其中,CConsole的实现
- Console.h
#pragma once
class CConsole
{
public:
CConsole(void);
~CConsole(void);
};
- Console.cpp
#include "StdAfx.h"
#include "Console.h"
#include <conio.h>
#include <fcntl.h>
#include <io.h>
CConsole::CConsole(void)
{
AllocConsole();
int hCrun;
hCrun = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
FILE* hFile = _fdopen(hCrun, "w");
setvbuf(hFile, NULL, _IONBF, 0);
*stdout = *hFile;
}
CConsole::~CConsole(void)
{
FreeConsole();
}