~ubuntu-branches/ubuntu/raring/protobuf/raring

« back to all changes in this revision

Viewing changes to gtest/test/gtest-port_test.cc

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2010-02-11 11:13:19 UTC
  • mfrom: (2.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100211111319-zdn8hmw0gh8s4cf8
Tags: 2.2.0a-0.1ubuntu1
* Merge from Debian testing.
* Remaining Ubuntu changes:
  - Don't use python2.4.
* Ubuntu changes dropped:
  - Disable death tests on Itanium, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
#if GTEST_OS_MAC
37
37
#include <pthread.h>
 
38
#include <time.h>
38
39
#endif  // GTEST_OS_MAC
39
40
 
40
41
#include <gtest/gtest.h>
90
91
}
91
92
 
92
93
TEST(GetThreadCountTest, ReturnsCorrectValue) {
93
 
  EXPECT_EQ(1, GetThreadCount());
 
94
  EXPECT_EQ(1U, GetThreadCount());
94
95
  pthread_mutex_t mutex;
95
96
  pthread_attr_t  attr;
96
97
  pthread_t       thread_id;
105
106
  const int status = pthread_create(&thread_id, &attr, &ThreadFunc, &mutex);
106
107
  ASSERT_EQ(0, pthread_attr_destroy(&attr));
107
108
  ASSERT_EQ(0, status);
108
 
  EXPECT_EQ(2, GetThreadCount());
 
109
  EXPECT_EQ(2U, GetThreadCount());
109
110
  pthread_mutex_unlock(&mutex);
110
111
 
111
112
  void* dummy;
112
113
  ASSERT_EQ(0, pthread_join(thread_id, &dummy));
113
 
  EXPECT_EQ(1, GetThreadCount());
 
114
 
 
115
  // MacOS X may not immediately report the updated thread count after
 
116
  // joining a thread, causing flakiness in this test. To counter that, we
 
117
  // wait for up to .5 seconds for the OS to report the correct value.
 
118
  for (int i = 0; i < 5; ++i) {
 
119
    if (GetThreadCount() == 1)
 
120
      break;
 
121
 
 
122
    timespec time;
 
123
    time.tv_sec = 0;
 
124
    time.tv_nsec = 100L * 1000 * 1000;  // .1 seconds.
 
125
    nanosleep(&time, NULL);
 
126
  }
 
127
  EXPECT_EQ(1U, GetThreadCount());
114
128
  pthread_mutex_destroy(&mutex);
115
129
}
116
130
#else
117
131
TEST(GetThreadCountTest, ReturnsZeroWhenUnableToCountThreads) {
118
 
  EXPECT_EQ(0, GetThreadCount());
 
132
  EXPECT_EQ(0U, GetThreadCount());
119
133
}
120
134
#endif  // GTEST_OS_MAC
121
135
 
674
688
 
675
689
#endif  // GTEST_USES_POSIX_RE
676
690
 
677
 
#if GTEST_HAS_STD_STRING
678
 
 
679
691
TEST(CaptureStderrTest, CapturesStdErr) {
680
692
  CaptureStderr();
681
693
  fprintf(stderr, "abc");
682
 
  ASSERT_EQ("abc", GetCapturedStderr());
 
694
  ASSERT_STREQ("abc", GetCapturedStderr().c_str());
683
695
}
684
696
 
685
 
#endif  // GTEST_HAS_STD_STRING
686
 
 
687
697
}  // namespace internal
688
698
}  // namespace testing