Fixes compatibility with Windows CE and Symbian (By Tim Baverstock and Mika).

This commit is contained in:
zhanyong.wan 2009-06-19 17:23:54 +00:00
parent ae3247986b
commit 4853a50337
11 changed files with 70 additions and 20 deletions

View File

@ -146,11 +146,12 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
#endif // 0 #endif // 0
#include <utility>
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
#if !GTEST_OS_SYMBIAN
#include <utility>
#endif
#if GTEST_HAS_PARAM_TEST #if GTEST_HAS_PARAM_TEST
#include <gtest/internal/gtest-internal.h> #include <gtest/internal/gtest-internal.h>

View File

@ -621,7 +621,7 @@ class TypedTestCasePState {
"REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
FormatFileLocation(file, line).c_str(), test_name, case_name); FormatFileLocation(file, line).c_str(), test_name, case_name);
fflush(stderr); fflush(stderr);
abort(); posix::Abort();
} }
defined_test_names_.insert(test_name); defined_test_names_.insert(test_name);
return true; return true;

View File

@ -154,10 +154,13 @@
// Int32FromGTestEnv() - parses an Int32 environment variable. // Int32FromGTestEnv() - parses an Int32 environment variable.
// StringFromGTestEnv() - parses a string environment variable. // StringFromGTestEnv() - parses a string environment variable.
#include <stddef.h> // For ptrdiff_t
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifndef _WIN32_WCE
#include <sys/stat.h> #include <sys/stat.h>
#endif // !_WIN32_WCE
#include <iostream> // NOLINT #include <iostream> // NOLINT
@ -191,7 +194,7 @@
#define GTEST_OS_SOLARIS 1 #define GTEST_OS_SOLARIS 1
#endif // __CYGWIN__ #endif // __CYGWIN__
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_SYMBIAN
// On some platforms, <regex.h> needs someone to define size_t, and // On some platforms, <regex.h> needs someone to define size_t, and
// won't compile otherwise. We can #include it here as we already // won't compile otherwise. We can #include it here as we already
@ -206,8 +209,10 @@
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
#ifndef _WIN32_WCE
#include <direct.h> // NOLINT #include <direct.h> // NOLINT
#include <io.h> // NOLINT #include <io.h> // NOLINT
#endif // !_WIN32_WCE
// <regex.h> is not available on Windows. Use our own simple regex // <regex.h> is not available on Windows. Use our own simple regex
// implementation instead. // implementation instead.
@ -445,7 +450,8 @@
#if GTEST_HAS_STD_STRING && (GTEST_OS_LINUX || \ #if GTEST_HAS_STD_STRING && (GTEST_OS_LINUX || \
GTEST_OS_MAC || \ GTEST_OS_MAC || \
GTEST_OS_CYGWIN || \ GTEST_OS_CYGWIN || \
(GTEST_OS_WINDOWS && _MSC_VER >= 1400)) (GTEST_OS_WINDOWS && (_MSC_VER >= 1400) && \
!defined(_WIN32_WCE)))
#define GTEST_HAS_DEATH_TEST 1 #define GTEST_HAS_DEATH_TEST 1
#include <vector> // NOLINT #include <vector> // NOLINT
#endif #endif
@ -813,20 +819,30 @@ inline int StrCaseCmp(const char* s1, const char* s2) {
return stricmp(s1, s2); return stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return strdup(src); } inline char* StrDup(const char* src) { return strdup(src); }
#else #else // !__BORLANDC__
#ifdef _WIN32_WCE
inline int IsATTY(int /* fd */) { return 0; }
#else // !_WIN32_WCE
inline int IsATTY(int fd) { return _isatty(fd); } inline int IsATTY(int fd) { return _isatty(fd); }
#endif // _WIN32_WCE
inline int StrCaseCmp(const char* s1, const char* s2) { inline int StrCaseCmp(const char* s1, const char* s2) {
return _stricmp(s1, s2); return _stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return _strdup(src); } inline char* StrDup(const char* src) { return _strdup(src); }
#endif // __BORLANDC__ #endif // __BORLANDC__
#ifdef _WIN32_WCE
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
// time and thus not defined there.
#else // !_WIN32_WCE
inline int FileNo(FILE* file) { return _fileno(file); } inline int FileNo(FILE* file) { return _fileno(file); }
inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
inline int RmDir(const char* dir) { return _rmdir(dir); } inline int RmDir(const char* dir) { return _rmdir(dir); }
inline bool IsDir(const StatStruct& st) { inline bool IsDir(const StatStruct& st) {
return (_S_IFDIR & st.st_mode) != 0; return (_S_IFDIR & st.st_mode) != 0;
} }
#endif // _WIN32_WCE
#else #else
@ -855,15 +871,25 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
inline const char* StrNCpy(char* dest, const char* src, size_t n) { inline const char* StrNCpy(char* dest, const char* src, size_t n) {
return strncpy(dest, src, n); return strncpy(dest, src, n);
} }
// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
// StrError() aren't needed on Windows CE at this time and thus not
// defined there.
#ifndef _WIN32_WCE
inline int ChDir(const char* dir) { return chdir(dir); } inline int ChDir(const char* dir) { return chdir(dir); }
#endif
inline FILE* FOpen(const char* path, const char* mode) { inline FILE* FOpen(const char* path, const char* mode) {
return fopen(path, mode); return fopen(path, mode);
} }
#ifndef _WIN32_WCE
inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
return freopen(path, mode, stream); return freopen(path, mode, stream);
} }
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
#endif
inline int FClose(FILE* fp) { return fclose(fp); } inline int FClose(FILE* fp) { return fclose(fp); }
#ifndef _WIN32_WCE
inline int Read(int fd, void* buf, unsigned int count) { inline int Read(int fd, void* buf, unsigned int count) {
return static_cast<int>(read(fd, buf, count)); return static_cast<int>(read(fd, buf, count));
} }
@ -872,6 +898,7 @@ inline int Write(int fd, const void* buf, unsigned int count) {
} }
inline int Close(int fd) { return close(fd); } inline int Close(int fd) { return close(fd); }
inline const char* StrError(int errnum) { return strerror(errnum); } inline const char* StrError(int errnum) { return strerror(errnum); }
#endif
inline const char* GetEnv(const char* name) { inline const char* GetEnv(const char* name) {
#ifdef _WIN32_WCE // We are on Windows CE, which has no environment variables. #ifdef _WIN32_WCE // We are on Windows CE, which has no environment variables.
return NULL; return NULL;
@ -992,7 +1019,7 @@ class GTestCheckProvider {
} }
~GTestCheckProvider() { ~GTestCheckProvider() {
::std::cerr << ::std::endl; ::std::cerr << ::std::endl;
abort(); posix::Abort();
} }
void FormatFileLocation(const char* file, int line) { void FormatFileLocation(const char* file, int line) {
if (file == NULL) if (file == NULL)

View File

@ -33,8 +33,8 @@
// Implements a subset of TR1 tuple needed by Google Test and Google Mock. // Implements a subset of TR1 tuple needed by Google Test and Google Mock.
#ifndef GTEST_INCLUDE_GTEST_INTERAL_GTEST_TUPLE_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#define GTEST_INCLUDE_GTEST_INTERAL_GTEST_TUPLE_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#include <utility> // For ::std::pair. #include <utility> // For ::std::pair.
@ -942,4 +942,4 @@ inline bool operator!=(const GTEST_10_TUPLE_(T)& t,
#undef GTEST_ADD_REF_ #undef GTEST_ADD_REF_
#undef GTEST_TUPLE_ELEMENT_ #undef GTEST_TUPLE_ELEMENT_
#endif // GTEST_INCLUDE_GTEST_INTERAL_GTEST_TUPLE_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_

View File

@ -34,8 +34,8 @@ $$ This meta comment fixes auto-indentation in Emacs. }}
// Implements a subset of TR1 tuple needed by Google Test and Google Mock. // Implements a subset of TR1 tuple needed by Google Test and Google Mock.
#ifndef GTEST_INCLUDE_GTEST_INTERAL_GTEST_TUPLE_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#define GTEST_INCLUDE_GTEST_INTERAL_GTEST_TUPLE_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#include <utility> // For ::std::pair. #include <utility> // For ::std::pair.
@ -317,4 +317,4 @@ $for j [[
#undef GTEST_ADD_REF_ #undef GTEST_ADD_REF_
#undef GTEST_TUPLE_ELEMENT_ #undef GTEST_TUPLE_ELEMENT_
#endif // GTEST_INCLUDE_GTEST_INTERAL_GTEST_TUPLE_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_

View File

@ -45,7 +45,9 @@
#error "It must not be included except by Google Test itself." #error "It must not be included except by Google Test itself."
#endif // GTEST_IMPLEMENTATION_ #endif // GTEST_IMPLEMENTATION_
#ifndef _WIN32_WCE
#include <errno.h> #include <errno.h>
#endif // !_WIN32_WCE
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> // For strtoll/_strtoul64. #include <stdlib.h> // For strtoll/_strtoul64.
@ -1072,7 +1074,7 @@ class UnitTestImpl {
original_working_dir_.Set(FilePath::GetCurrentDir()); original_working_dir_.Set(FilePath::GetCurrentDir());
if (original_working_dir_.IsEmpty()) { if (original_working_dir_.IsEmpty()) {
printf("%s\n", "Failed to get the current working directory."); printf("%s\n", "Failed to get the current working directory.");
abort(); posix::Abort();
} }
} }

View File

@ -36,8 +36,10 @@
#include <stdio.h> #include <stdio.h>
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
#ifndef _WIN32_WCE
#include <io.h> #include <io.h>
#include <sys/stat.h> #include <sys/stat.h>
#endif // _WIN32_WCE
#else #else
#include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
@ -425,7 +427,7 @@ void GTestLog(GTestLogSeverity severity, const char* file,
fprintf(stderr, "\n%s %s:%d: %s\n", marker, file, line, msg); fprintf(stderr, "\n%s %s:%d: %s\n", marker, file, line, msg);
if (severity == GTEST_FATAL) { if (severity == GTEST_FATAL) {
fflush(NULL); // abort() is not guaranteed to flush open file streams. fflush(NULL); // abort() is not guaranteed to flush open file streams.
abort(); posix::Abort();
} }
} }
@ -444,6 +446,10 @@ class CapturedStderr {
public: public:
// The ctor redirects stderr to a temporary file. // The ctor redirects stderr to a temporary file.
CapturedStderr() { CapturedStderr() {
#ifdef _WIN32_WCE
// Not supported on Windows CE.
posix::Abort();
#else
uncaptured_fd_ = dup(kStdErrFileno); uncaptured_fd_ = dup(kStdErrFileno);
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
@ -465,19 +471,24 @@ class CapturedStderr {
fflush(NULL); fflush(NULL);
dup2(captured_fd, kStdErrFileno); dup2(captured_fd, kStdErrFileno);
close(captured_fd); close(captured_fd);
#endif // _WIN32_WCE
} }
~CapturedStderr() { ~CapturedStderr() {
#ifndef _WIN32_WCE
remove(filename_.c_str()); remove(filename_.c_str());
#endif // _WIN32_WCE
} }
// Stops redirecting stderr. // Stops redirecting stderr.
void StopCapture() { void StopCapture() {
#ifndef _WIN32_WCE
// Restores the original stream. // Restores the original stream.
fflush(NULL); fflush(NULL);
dup2(uncaptured_fd_, kStdErrFileno); dup2(uncaptured_fd_, kStdErrFileno);
close(uncaptured_fd_); close(uncaptured_fd_);
uncaptured_fd_ = -1; uncaptured_fd_ = -1;
#endif // !_WIN32_WCE
} }
// Returns the name of the temporary file holding the stderr output. // Returns the name of the temporary file holding the stderr output.

View File

@ -86,7 +86,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
errors_str.c_str()); errors_str.c_str());
fflush(stderr); fflush(stderr);
abort(); posix::Abort();
} }
return registered_tests; return registered_tests;

View File

@ -3364,14 +3364,14 @@ int UnitTest::Run() {
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif // _WIN32_WCE #endif // _WIN32_WCE
#if defined(_MSC_VER) || defined(__MINGW32__) #if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(_WIN32_WCE)
// Death test children can be terminated with _abort(). On Windows, // Death test children can be terminated with _abort(). On Windows,
// _abort() can show a dialog with a warning message. This forces the // _abort() can show a dialog with a warning message. This forces the
// abort message to go to stderr instead. // abort message to go to stderr instead.
_set_error_mode(_OUT_TO_STDERR); _set_error_mode(_OUT_TO_STDERR);
#endif #endif
#if _MSC_VER >= 1400 #if _MSC_VER >= 1400 && !defined(_WIN32_WCE)
// In the debug version, Visual Studio pops up a separate dialog // In the debug version, Visual Studio pops up a separate dialog
// offering a choice to debug the aborted program. We need to suppress // 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 // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
@ -3387,7 +3387,7 @@ int UnitTest::Run() {
_set_abort_behavior( _set_abort_behavior(
0x0, // Clear the following flags: 0x0, // Clear the following flags:
_WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
#endif // _MSC_VER >= 1400 #endif
} }
__try { __try {

View File

@ -61,6 +61,9 @@ namespace internal {
namespace { namespace {
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
// TODO(wan@google.com): Move these to the POSIX adapter section in
// gtest-port.h.
// Windows CE doesn't have the remove C function. // Windows CE doesn't have the remove C function.
int remove(const char* path) { int remove(const char* path) {
LPCWSTR wpath = String::AnsiToUtf16(path); LPCWSTR wpath = String::AnsiToUtf16(path);

View File

@ -1446,6 +1446,8 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
// Tests that Int32FromEnvOrDie() parses the value of the var or // Tests that Int32FromEnvOrDie() parses the value of the var or
// returns the correct default. // returns the correct default.
// Environment variables are not supported on Windows CE.
#ifndef _WIN32_WCE
TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123");
@ -1453,6 +1455,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123");
EXPECT_EQ(-123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); EXPECT_EQ(-123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
} }
#endif // _WIN32_WCE
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
@ -1521,6 +1524,8 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
// Tests that sharding is enabled if total_shards > 1 and // Tests that sharding is enabled if total_shards > 1 and
// we are not in a death test subprocess. // we are not in a death test subprocess.
// Environment variables are not supported on Windows CE.
#ifndef _WIN32_WCE
TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
SetEnv(index_var_, "4"); SetEnv(index_var_, "4");
SetEnv(total_var_, "22"); SetEnv(total_var_, "22");
@ -1537,6 +1542,7 @@ TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
EXPECT_TRUE(ShouldShard(total_var_, index_var_, false)); EXPECT_TRUE(ShouldShard(total_var_, index_var_, false));
EXPECT_FALSE(ShouldShard(total_var_, index_var_, true)); EXPECT_FALSE(ShouldShard(total_var_, index_var_, true));
} }
#endif // _WIN32_WCE
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST