From 12a92c26fc0e0de81f687dbe739a6aa24f37f9dd Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 4 Mar 2010 22:15:53 +0000 Subject: Renames ThreadStartSempahore to Notificaton (by Vlad Losev); adds threading tests for SCOPED_TRACE() (by Vlad Losev); replaces native pthread calls with gtest's threading constructs (by Vlad Losev); fixes flakiness in CountedDestructor (by Vlad Losev); minor MSVC 7.1 clean-up (by Zhanyong Wan). --- test/gtest_unittest.cc | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'test/gtest_unittest.cc') diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index bc190e1e..d5a6f302 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -71,10 +71,6 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include #include -#if GTEST_HAS_PTHREAD -#include -#endif // GTEST_HAS_PTHREAD - #include namespace testing { @@ -191,6 +187,10 @@ using testing::internal::CaptureStdout; using testing::internal::GetCapturedStdout; #endif // GTEST_HAS_STREAM_REDIRECTION_ +#if GTEST_IS_THREADSAFE +using testing::internal::ThreadWithParam; +#endif + class TestingVector : public std::vector { }; @@ -1283,25 +1283,14 @@ TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) { EXPECT_EQ(1, results.size()); } -#if GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD +#if GTEST_IS_THREADSAFE class ScopedFakeTestPartResultReporterWithThreadsTest : public ScopedFakeTestPartResultReporterTest { protected: static void AddFailureInOtherThread(FailureMode failure) { - pthread_t tid; - pthread_create(&tid, - NULL, - ScopedFakeTestPartResultReporterWithThreadsTest:: - FailureThread, - &failure); - pthread_join(tid, NULL); - } - private: - static void* FailureThread(void* attr) { - FailureMode* failure = static_cast(attr); - AddFailure(*failure); - return NULL; + ThreadWithParam thread(&AddFailure, failure, NULL); + thread.Join(); } }; @@ -1324,7 +1313,7 @@ TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest, EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed()); } -#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD +#endif // GTEST_IS_THREADSAFE // Tests EXPECT_FATAL_FAILURE{,ON_ALL_THREADS}. Makes sure that they // work even if the failure is generated in a called function rather than @@ -1435,7 +1424,7 @@ TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { }, ""); } -#if GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD +#if GTEST_IS_THREADSAFE typedef ScopedFakeTestPartResultReporterWithThreadsTest ExpectFailureWithThreadsTest; @@ -1450,7 +1439,7 @@ TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) { AddFailureInOtherThread(NONFATAL_FAILURE), "Expected non-fatal failure."); } -#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD +#endif // GTEST_IS_THREADSAFE // Tests the TestProperty class. -- cgit v1.2.3