diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-04-07 21:03:22 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-04-07 21:03:22 +0000 |
commit | c12f63214e9b7761d27e68353e4aaf1761c9cf88 (patch) | |
tree | 78dba5344afb37f56eb716fbe75786aab1eb52d9 /test/gtest-port_test.cc | |
parent | 0da92aaf7f696ebfa2374247ae9010dacbc057fc (diff) | |
download | googletest-c12f63214e9b7761d27e68353e4aaf1761c9cf88.tar.gz googletest-c12f63214e9b7761d27e68353e4aaf1761c9cf88.tar.bz2 googletest-c12f63214e9b7761d27e68353e4aaf1761c9cf88.zip |
Adds sample4_unittest to scons (by Vlad Losev); adds logic for getting the thread count on Mac (by Vlad Losev); adds HasFailure() and HasNonfatalFailure() (by Zhanyong Wan).
Diffstat (limited to 'test/gtest-port_test.cc')
-rw-r--r-- | test/gtest-port_test.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc index 0bda6f5e..f4560f19 100644 --- a/test/gtest-port_test.cc +++ b/test/gtest-port_test.cc @@ -32,6 +32,11 @@ // This file tests the internal cross-platform support utilities. #include <gtest/internal/gtest-port.h> + +#if GTEST_OS_MAC +#include <pthread.h> +#endif // GTEST_OS_MAC + #include <gtest/gtest.h> #include <gtest/gtest-spi.h> @@ -76,6 +81,44 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) { GTEST_CHECK_(true) << "Check failed in switch case"; } +#if GTEST_OS_MAC +void* ThreadFunc(void* data) { + pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(data); + pthread_mutex_lock(mutex); + pthread_mutex_unlock(mutex); + return NULL; +} + +TEST(GetThreadCountTest, ReturnsCorrectValue) { + EXPECT_EQ(1, GetThreadCount()); + pthread_mutex_t mutex; + pthread_attr_t attr; + pthread_t thread_id; + + // TODO(vladl@google.com): turn mutex into internal::Mutex for automatic + // destruction. + pthread_mutex_init(&mutex, NULL); + pthread_mutex_lock(&mutex); + ASSERT_EQ(0, pthread_attr_init(&attr)); + ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE)); + + const int status = pthread_create(&thread_id, &attr, &ThreadFunc, &mutex); + ASSERT_EQ(0, pthread_attr_destroy(&attr)); + ASSERT_EQ(0, status); + EXPECT_EQ(2, GetThreadCount()); + pthread_mutex_unlock(&mutex); + + void* dummy; + ASSERT_EQ(0, pthread_join(thread_id, &dummy)); + EXPECT_EQ(1, GetThreadCount()); + pthread_mutex_destroy(&mutex); +} +#else +TEST(GetThreadCountTest, ReturnsZeroWhenUnableToCountThreads) { + EXPECT_EQ(0, GetThreadCount()); +} +#endif // GTEST_OS_MAC + #if GTEST_HAS_DEATH_TEST TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) { |