From 64cdcb69b28fc26e78d95c574187f7dd9830c84c Mon Sep 17 00:00:00 2001 From: shiqian Date: Fri, 26 Sep 2008 16:08:30 +0000 Subject: Lots of changes: * changes the XML report format to match JUnit/Ant's. * improves file path handling. * allows the user to disable RTTI using the GTEST_HAS_RTTI macro. * makes the code compile with -Wswitch-enum. --- include/gtest/internal/gtest-filepath.h | 40 ++++++++++++++++++--- include/gtest/internal/gtest-port.h | 52 ++++++++++++++++++++++++--- include/gtest/internal/gtest-type-util.h | 6 ++++ include/gtest/internal/gtest-type-util.h.pump | 6 ++++ 4 files changed, 95 insertions(+), 9 deletions(-) (limited to 'include/gtest/internal') diff --git a/include/gtest/internal/gtest-filepath.h b/include/gtest/internal/gtest-filepath.h index fecdddcc..9a0682af 100644 --- a/include/gtest/internal/gtest-filepath.h +++ b/include/gtest/internal/gtest-filepath.h @@ -60,8 +60,19 @@ class FilePath { public: FilePath() : pathname_("") { } FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } - explicit FilePath(const char* pathname) : pathname_(pathname) { } - explicit FilePath(const String& pathname) : pathname_(pathname) { } + + explicit FilePath(const char* pathname) : pathname_(pathname) { + Normalize(); + } + + explicit FilePath(const String& pathname) : pathname_(pathname) { + Normalize(); + } + + FilePath& operator=(const FilePath& rhs) { + Set(rhs); + return *this; + } void Set(const FilePath& rhs) { pathname_ = rhs.pathname_; @@ -149,11 +160,30 @@ class FilePath { // This does NOT check that a directory (or file) actually exists. bool IsDirectory() const; + // Returns true if pathname describes a root directory. (Windows has one + // root directory per disk drive.) + bool IsRootDirectory() const; + private: - String pathname_; + // Replaces multiple consecutive separators with a single separator. + // For example, "bar///foo" becomes "bar/foo". Does not eliminate other + // redundancies that might be in a pathname involving "." or "..". + // + // A pathname with multiple consecutive separators may occur either through + // user error or as a result of some scripts or APIs that generate a pathname + // with a trailing separator. On other platforms the same API or script + // may NOT generate a pathname with a trailing "/". Then elsewhere that + // pathname may have another "/" and pathname components added to it, + // without checking for the separator already being there. + // The script language and operating system may allow paths like "foo//bar" + // but some of the functions in FilePath will not handle that correctly. In + // particular, RemoveTrailingPathSeparator() only removes one separator, and + // it is called in CreateDirectoriesRecursively() assuming that it will change + // a pathname from directory syntax (trailing separator) to filename syntax. + + void Normalize(); - // Don't implement operator= because it is banned by the style guide. - FilePath& operator=(const FilePath& rhs); + String pathname_; }; // class FilePath } // namespace internal diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 75429b2b..022e6706 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -55,6 +55,9 @@ // is/isn't available (some systems define // ::wstring, which is different to std::wstring). // Leave it undefined to let Google Test define it. +// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't +// enabled. Leave it undefined to let Google +// Test define it. // This header defines the following utilities: // @@ -135,6 +138,13 @@ #define GTEST_FLAG_PREFIX "gtest_" #define GTEST_FLAG_PREFIX_UPPER "GTEST_" +// Determines the version of gcc that is used to compile this. +#ifdef __GNUC__ +// 40302 means version 4.3.2. +#define GTEST_GCC_VER_ \ + (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) +#endif // __GNUC__ + // Determines the platform on which Google Test is compiled. #ifdef __CYGWIN__ #define GTEST_OS_CYGWIN @@ -215,6 +225,42 @@ #include // NOLINT #endif // GTEST_HAS_STD_STRING +// Determines whether RTTI is available. +#ifndef GTEST_HAS_RTTI +// The user didn't tell us whether RTTI is enabled, so we need to +// figure it out. + +#ifdef _MSC_VER + +#ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. +#define GTEST_HAS_RTTI 1 +#else +#define GTEST_HAS_RTTI 0 +#endif // _CPPRTTI + +#elif defined(__GNUC__) + +// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled. +#if GTEST_GCC_VER_ >= 40302 +#ifdef __GXX_RTTI +#define GTEST_HAS_RTTI 1 +#else +#define GTEST_HAS_RTTI 0 +#endif // __GXX_RTTI +#else +// For gcc versions smaller than 4.3.2, we assume RTTI is enabled. +#define GTEST_HAS_RTTI 1 +#endif // GTEST_GCC_VER >= 40302 + +#else + +// Unknown compiler - assume RTTI is enabled. +#define GTEST_HAS_RTTI 1 + +#endif // _MSC_VER + +#endif // GTEST_HAS_RTTI + // Determines whether to support death tests. #if GTEST_HAS_STD_STRING && defined(GTEST_OS_LINUX) #define GTEST_HAS_DEATH_TEST @@ -284,13 +330,11 @@ // following the argument list: // // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT; -#if defined(__GNUC__) \ - && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \ - && !defined(COMPILER_ICC) +#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC) #define GTEST_MUST_USE_RESULT __attribute__ ((warn_unused_result)) #else #define GTEST_MUST_USE_RESULT -#endif // (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC namespace testing { diff --git a/include/gtest/internal/gtest-type-util.h b/include/gtest/internal/gtest-type-util.h index 8b56082b..815da4ba 100644 --- a/include/gtest/internal/gtest-type-util.h +++ b/include/gtest/internal/gtest-type-util.h @@ -71,6 +71,8 @@ struct AssertTypeEq { // GetTypeName() returns a human-readable name of type T. template String GetTypeName() { +#if GTEST_HAS_RTTI + const char* const name = typeid(T).name(); #ifdef __GNUC__ int status = 0; @@ -83,6 +85,10 @@ String GetTypeName() { #else return name; #endif // __GNUC__ + +#else + return ""; +#endif // GTEST_HAS_RTTI } // A unique type used as the default value for the arguments of class diff --git a/include/gtest/internal/gtest-type-util.h.pump b/include/gtest/internal/gtest-type-util.h.pump index f43be5ea..4858c7d8 100644 --- a/include/gtest/internal/gtest-type-util.h.pump +++ b/include/gtest/internal/gtest-type-util.h.pump @@ -71,6 +71,8 @@ struct AssertTypeEq { // GetTypeName() returns a human-readable name of type T. template String GetTypeName() { +#if GTEST_HAS_RTTI + const char* const name = typeid(T).name(); #ifdef __GNUC__ int status = 0; @@ -83,6 +85,10 @@ String GetTypeName() { #else return name; #endif // __GNUC__ + +#else + return ""; +#endif // GTEST_HAS_RTTI } // A unique type used as the default value for the arguments of class -- cgit v1.2.3