Ports gtest to C++Builder, by Josh Kelley.

This commit is contained in:
zhanyong.wan
2009-04-28 00:28:09 +00:00
parent f2334aa195
commit c78ae6196d
13 changed files with 810 additions and 203 deletions

View File

@@ -88,10 +88,10 @@ FilePath FilePath::GetCurrentDir() {
// something reasonable.
return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS
char cwd[GTEST_PATH_MAX_ + 1] = {};
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
#else
char cwd[GTEST_PATH_MAX_ + 1] = {};
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
#endif
}
@@ -127,8 +127,13 @@ FilePath FilePath::RemoveDirectoryName() const {
// On Windows platform, '\' is the path separator, otherwise it is '/'.
FilePath FilePath::RemoveFileName() const {
const char* const last_sep = strrchr(c_str(), kPathSeparator);
return FilePath(last_sep ? String(c_str(), last_sep + 1 - c_str())
: String(kCurrentDirectoryString));
String dir;
if (last_sep) {
dir = String(c_str(), last_sep + 1 - c_str());
} else {
dir = kCurrentDirectoryString;
}
return FilePath(dir);
}
// Helper functions for naming files in a directory for xml output.
@@ -141,11 +146,13 @@ FilePath FilePath::MakeFileName(const FilePath& directory,
const FilePath& base_name,
int number,
const char* extension) {
const FilePath file_name(
(number == 0) ?
String::Format("%s.%s", base_name.c_str(), extension) :
String::Format("%s_%d.%s", base_name.c_str(), number, extension));
return ConcatPaths(directory, file_name);
String file;
if (number == 0) {
file = String::Format("%s.%s", base_name.c_str(), extension);
} else {
file = String::Format("%s_%d.%s", base_name.c_str(), number, extension);
}
return ConcatPaths(directory, FilePath(file));
}
// Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".

View File

@@ -68,8 +68,8 @@
namespace testing {
namespace internal {
#ifdef _MSC_VER
// MSVC does not provide a definition of STDERR_FILENO.
#if defined(_MSC_VER) || defined(__BORLANDC__)
// MSVC and C++Builder do not provide a definition of STDERR_FILENO.
const int kStdErrFileno = 2;
#else
const int kStdErrFileno = STDERR_FILENO;

View File

@@ -735,10 +735,11 @@ String UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
}
static TimeInMillis GetTimeInMillis() {
#ifdef _WIN32_WCE // We are on Windows CE
#if defined(_WIN32_WCE) || defined(__BORLANDC__)
// Difference between 1970-01-01 and 1601-01-01 in miliseconds.
// http://analogous.blogspot.com/2005/04/epoch.html
const TimeInMillis kJavaEpochToWinFileTimeDelta = 11644473600000UL;
const TimeInMillis kJavaEpochToWinFileTimeDelta =
static_cast<TimeInMillis>(116444736UL) * 100000UL;
const DWORD kTenthMicrosInMilliSecond = 10000;
SYSTEMTIME now_systime;
@@ -3221,13 +3222,18 @@ UnitTest * UnitTest::GetInstance() {
// different implementation in this case to bypass the compiler bug.
// This implementation makes the compiler happy, at the cost of
// leaking the UnitTest object.
#if _MSC_VER == 1310 && !defined(_DEBUG) // MSVC 7.1 and optimized build.
// CodeGear C++Builder insists on a public destructor for the
// default implementation. Use this implementation to keep good OO
// design with private destructor.
#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
static UnitTest* const instance = new UnitTest;
return instance;
#else
static UnitTest instance;
return &instance;
#endif // _MSC_VER==1310 && !defined(_DEBUG)
#endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
}
// Registers and returns a global test environment. When a test
@@ -3259,7 +3265,7 @@ Environment* UnitTest::AddEnvironment(Environment* env) {
class GoogleTestFailureException : public ::std::runtime_error {
public:
explicit GoogleTestFailureException(const TestPartResult& failure)
: runtime_error(PrintTestPartResultToString(failure).c_str()) {}
: ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
};
#endif
@@ -3350,17 +3356,20 @@ int UnitTest::Run() {
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif // _WIN32_WCE
#if defined(_MSC_VER) || defined(__MINGW32__)
// Death test children can be terminated with _abort(). On Windows,
// _abort() can show a dialog with a warning message. This forces the
// abort message to go to stderr instead.
_set_error_mode(_OUT_TO_STDERR);
#endif
#if _MSC_VER >= 1400
// In the debug version, Visual Studio pops up a separate dialog
// offering a choice to debug the aborted program. We need to suppress
// this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
// executed. Google Test will notify the user of any unexpected
// failure via stderr.
#if _MSC_VER >= 1400
//
// VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
// Users of prior VC versions shall suffer the agony and pain of
// clicking through the countless debug dialogs.