diff options
Diffstat (limited to 'gtest/include/gtest/internal/gtest-port.h')
-rw-r--r-- | gtest/include/gtest/internal/gtest-port.h | 114 |
1 files changed, 58 insertions, 56 deletions
diff --git a/gtest/include/gtest/internal/gtest-port.h b/gtest/include/gtest/internal/gtest-port.h index a5adbc0..ee97881 100644 --- a/gtest/include/gtest/internal/gtest-port.h +++ b/gtest/include/gtest/internal/gtest-port.h @@ -77,7 +77,10 @@ // GTEST_OS_MAC - Mac OS X // GTEST_OS_SOLARIS - Sun Solaris // GTEST_OS_SYMBIAN - Symbian -// GTEST_OS_WINDOWS - Windows +// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) +// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop +// GTEST_OS_WINDOWS_MINGW - MinGW +// GTEST_OS_WINODWS_MOBILE - Windows Mobile // GTEST_OS_ZOS - z/OS // // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the @@ -184,6 +187,13 @@ #define GTEST_OS_SYMBIAN 1 #elif defined _WIN32 #define GTEST_OS_WINDOWS 1 +#ifdef _WIN32_WCE +#define GTEST_OS_WINDOWS_MOBILE 1 +#elif defined(__MINGW__) || defined(__MINGW32__) +#define GTEST_OS_WINDOWS_MINGW 1 +#else +#define GTEST_OS_WINDOWS_DESKTOP 1 +#endif // _WIN32_WCE #elif defined __APPLE__ #define GTEST_OS_MAC 1 #elif defined __linux__ @@ -210,10 +220,10 @@ #elif GTEST_OS_WINDOWS -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE #include <direct.h> // NOLINT #include <io.h> // NOLINT -#endif // !_WIN32_WCE +#endif // <regex.h> is not available on Windows. Use our own simple regex // implementation instead. @@ -449,11 +459,9 @@ // (this is covered by GTEST_HAS_STD_STRING guard). // 3. abort() in a VC 7.1 application compiled as GUI in debug config // pops up a dialog window that cannot be suppressed programmatically. -#if GTEST_HAS_STD_STRING && (GTEST_OS_LINUX || \ - GTEST_OS_MAC || \ - GTEST_OS_CYGWIN || \ - (GTEST_OS_WINDOWS && (_MSC_VER >= 1400) && \ - !defined(_WIN32_WCE))) +#if GTEST_HAS_STD_STRING && \ + (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || \ + (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || GTEST_OS_WINDOWS_MINGW) #define GTEST_HAS_DEATH_TEST 1 #include <vector> // NOLINT #endif @@ -569,6 +577,10 @@ typedef ::std::stringstream StrStream; typedef ::std::strstream StrStream; #endif // GTEST_HAS_STD_STRING +// A helper for suppressing warnings on constant condition. It just +// returns 'condition'. +bool IsTrue(bool condition); + // Defines scoped_ptr. // This implementation of scoped_ptr is PARTIAL - it only contains @@ -591,7 +603,7 @@ class scoped_ptr { void reset(T* p = NULL) { if (p != ptr_) { - if (sizeof(T) > 0) { // Makes sure T is a complete type. + if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type. delete ptr_; } ptr_ = p; @@ -672,7 +684,8 @@ class RE { }; // Defines logging utilities: -// GTEST_LOG_() - logs messages at the specified severity level. +// GTEST_LOG_(severity) - logs messages at the specified severity level. The +// message itself is streamed into the macro. // LogToStderr() - directs all log messages to stderr. // FlushInfoLog() - flushes informational log messages. @@ -683,13 +696,27 @@ enum GTestLogSeverity { GTEST_FATAL }; -void GTestLog(GTestLogSeverity severity, const char* file, - int line, const char* msg); +// Formats log entry severity, provides a stream object for streaming the +// log message, and terminates the message with a newline when going out of +// scope. +class GTestLog { + public: + GTestLog(GTestLogSeverity severity, const char* file, int line); + + // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program. + ~GTestLog(); -#define GTEST_LOG_(severity, msg)\ - ::testing::internal::GTestLog(\ - ::testing::internal::GTEST_##severity, __FILE__, __LINE__, \ - (::testing::Message() << (msg)).GetString().c_str()) + ::std::ostream& GetStream() { return ::std::cerr; } + + private: + const GTestLogSeverity severity_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog); +}; + +#define GTEST_LOG_(severity) \ + ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ + __FILE__, __LINE__).GetStream() inline void LogToStderr() {} inline void FlushInfoLog() { fflush(NULL); } @@ -820,29 +847,29 @@ inline int StrCaseCmp(const char* s1, const char* s2) { } inline char* StrDup(const char* src) { return strdup(src); } #else // !__BORLANDC__ -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE inline int IsATTY(int /* fd */) { return 0; } -#else // !_WIN32_WCE +#else inline int IsATTY(int fd) { return _isatty(fd); } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE inline int StrCaseCmp(const char* s1, const char* s2) { return _stricmp(s1, s2); } inline char* StrDup(const char* src) { return _strdup(src); } #endif // __BORLANDC__ -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE 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 +#else inline int FileNo(FILE* file) { return _fileno(file); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int RmDir(const char* dir) { return _rmdir(dir); } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE #else @@ -876,20 +903,20 @@ inline const char* StrNCpy(char* dest, const char* src, size_t n) { // StrError() aren't needed on Windows CE at this time and thus not // defined there. -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { return fopen(path, mode); } -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { return freopen(path, mode, stream); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } #endif inline int FClose(FILE* fp) { return fclose(fp); } -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE inline int Read(int fd, void* buf, unsigned int count) { return static_cast<int>(read(fd, buf, count)); } @@ -900,7 +927,8 @@ inline int Close(int fd) { return close(fd); } inline const char* StrError(int errnum) { return strerror(errnum); } #endif inline const char* GetEnv(const char* name) { -#ifdef _WIN32_WCE // We are on Windows CE, which has no environment variables. +#if GTEST_OS_WINDOWS_MOBILE + // We are on Windows CE, which has no environment variables. return NULL; #elif defined(__BORLANDC__) // Environment variables which we programmatically clear will be set to the @@ -916,14 +944,14 @@ inline const char* GetEnv(const char* name) { #pragma warning(pop) // Restores the warning state. #endif -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Windows CE has no C library. The abort() function is used in // several places in Google Test. This implementation provides a reasonable // imitation of standard behaviour. void Abort(); #else inline void Abort() { abort(); } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE } // namespace posix @@ -1011,38 +1039,12 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. // condition itself, plus additional message streamed into it, if any, // and then it aborts the program. It aborts the program irrespective of // whether it is built in the debug mode or not. -class GTestCheckProvider { - public: - GTestCheckProvider(const char* condition, const char* file, int line) { - FormatFileLocation(file, line); - ::std::cerr << " ERROR: Condition " << condition << " failed. "; - } - ~GTestCheckProvider() { - ::std::cerr << ::std::endl; - posix::Abort(); - } - void FormatFileLocation(const char* file, int line) { - if (file == NULL) - file = "unknown file"; - if (line < 0) { - ::std::cerr << file << ":"; - } else { -#if _MSC_VER - ::std::cerr << file << "(" << line << "):"; -#else - ::std::cerr << file << ":" << line << ":"; -#endif - } - } - ::std::ostream& GetStream() { return ::std::cerr; } -}; #define GTEST_CHECK_(condition) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (condition) \ + if (::testing::internal::IsTrue(condition)) \ ; \ else \ - ::testing::internal::GTestCheckProvider(\ - #condition, __FILE__, __LINE__).GetStream() + GTEST_LOG_(FATAL) << "Condition " #condition " failed. " // Macro for referencing flags. #define GTEST_FLAG(name) FLAGS_gtest_##name |