diff options
author | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-11-24 20:13:22 (GMT) |
---|---|---|
committer | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-11-24 20:13:22 (GMT) |
commit | c440a6923aa65d5be64134a6f430a5867a63df3f (patch) | |
tree | 6d5be5dd4644d4c83cc5e434de31a8a4a59a3865 /include | |
parent | 514265c415e072caf92fb4eed57aacdfea9964f1 (diff) | |
download | googletest-c440a6923aa65d5be64134a6f430a5867a63df3f.zip googletest-c440a6923aa65d5be64134a6f430a5867a63df3f.tar.gz googletest-c440a6923aa65d5be64134a6f430a5867a63df3f.tar.bz2 |
Enables the Python tests to run with 2.3 (necessary for testing on Mac OS X Tiger); also fixes gtest_output_test when built with xcode.
Diffstat (limited to 'include')
-rw-r--r-- | include/gtest/gtest.h | 15 | ||||
-rw-r--r-- | include/gtest/internal/gtest-internal.h | 37 |
2 files changed, 41 insertions, 11 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index dae2647..38fcd7d 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -1259,8 +1259,18 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2, // EXPECT_TRUE(foo.StatusIsOK()); // } +// Note that we call GetTestTypeId() instead of GetTypeId< +// ::testing::Test>() here to get the type ID of testing::Test. This +// is to work around a suspected linker bug when using Google Test as +// a framework on Mac OS X. The bug causes GetTypeId< +// ::testing::Test>() to return different values depending on whether +// the call is from the Google Test framework itself or from user test +// code. GetTestTypeId() is guaranteed to always return the same +// value, as it always calls GetTypeId<>() from the Google Test +// framework. #define TEST(test_case_name, test_name)\ - GTEST_TEST_(test_case_name, test_name, ::testing::Test) + GTEST_TEST_(test_case_name, test_name,\ + ::testing::Test, ::testing::internal::GetTestTypeId()) // Defines a test that uses a test fixture. @@ -1290,7 +1300,8 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2, // } #define TEST_F(test_fixture, test_name)\ - GTEST_TEST_(test_fixture, test_name, test_fixture) + GTEST_TEST_(test_fixture, test_name, test_fixture,\ + ::testing::internal::GetTypeId<test_fixture>()) // Use this macro in main() to run all tests. It returns 0 if all // tests are successful, or 1 otherwise. diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index d439c00..9e353b6 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -485,20 +485,39 @@ typedef FloatingPoint<double> Double; // used to hold such IDs. The user should treat TypeId as an opaque // type: the only operation allowed on TypeId values is to compare // them for equality using the == operator. -typedef void* TypeId; +typedef const void* TypeId; + +template <typename T> +class TypeIdHelper { + public: + // dummy_ must not have a const type. Otherwise an overly eager + // compiler (e.g. MSVC 7.1 & 8.0) may try to merge + // TypeIdHelper<T>::dummy_ for different Ts as an "optimization". + static bool dummy_; +}; + +template <typename T> +bool TypeIdHelper<T>::dummy_ = false; // GetTypeId<T>() returns the ID of type T. Different values will be // returned for different types. Calling the function twice with the // same type argument is guaranteed to return the same ID. template <typename T> -inline TypeId GetTypeId() { - static bool dummy = false; - // The compiler is required to create an instance of the static - // variable dummy for each T used to instantiate the template. - // Therefore, the address of dummy is guaranteed to be unique. - return &dummy; +TypeId GetTypeId() { + // The compiler is required to allocate a different + // TypeIdHelper<T>::dummy_ variable for each T used to instantiate + // the template. Therefore, the address of dummy_ is guaranteed to + // be unique. + return &(TypeIdHelper<T>::dummy_); } +// Returns the type ID of ::testing::Test. Always call this instead +// of GetTypeId< ::testing::Test>() to get the type ID of +// ::testing::Test, as the latter may give the wrong result due to a +// suspected linker bug when compiling Google Test as a Mac OS X +// framework. +TypeId GetTestTypeId(); + // Defines the abstract factory interface that creates instances // of a Test object. class TestFactoryBase { @@ -829,7 +848,7 @@ int GetFailedPartCount(const TestResult* result); test_case_name##_##test_name##_Test // Helper macro for defining tests. -#define GTEST_TEST_(test_case_name, test_name, parent_class)\ +#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ public:\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ @@ -844,7 +863,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ ::test_info_ =\ ::testing::internal::MakeAndRegisterTestInfo(\ #test_case_name, #test_name, "", "", \ - ::testing::internal::GetTypeId< parent_class >(), \ + (parent_id), \ parent_class::SetUpTestCase, \ parent_class::TearDownTestCase, \ new ::testing::internal::TestFactoryImpl<\ |