OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/threading/platform_thread.h" | 6 #include "base/threading/platform_thread.h" |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 11 matching lines...) Expand all Loading... |
22 bool did_run() const { return did_run_; } | 22 bool did_run() const { return did_run_; } |
23 | 23 |
24 private: | 24 private: |
25 bool did_run_; | 25 bool did_run_; |
26 | 26 |
27 DISALLOW_COPY_AND_ASSIGN(TrivialThread); | 27 DISALLOW_COPY_AND_ASSIGN(TrivialThread); |
28 }; | 28 }; |
29 | 29 |
30 TEST(PlatformThreadTest, Trivial) { | 30 TEST(PlatformThreadTest, Trivial) { |
31 TrivialThread thread; | 31 TrivialThread thread; |
32 PlatformThreadHandle handle = kNullThreadHandle; | 32 PlatformThreadHandle handle; |
33 | 33 |
34 ASSERT_FALSE(thread.did_run()); | 34 ASSERT_FALSE(thread.did_run()); |
35 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); | 35 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
36 PlatformThread::Join(handle); | 36 PlatformThread::Join(handle); |
37 ASSERT_TRUE(thread.did_run()); | 37 ASSERT_TRUE(thread.did_run()); |
38 } | 38 } |
39 | 39 |
40 TEST(PlatformThreadTest, TrivialTimesTen) { | 40 TEST(PlatformThreadTest, TrivialTimesTen) { |
41 TrivialThread thread[10]; | 41 TrivialThread thread[10]; |
42 PlatformThreadHandle handle[arraysize(thread)]; | 42 PlatformThreadHandle handle[arraysize(thread)]; |
(...skipping 30 matching lines...) Expand all Loading... |
73 private: | 73 private: |
74 PlatformThreadId thread_id_; | 74 PlatformThreadId thread_id_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(FunctionTestThread); | 76 DISALLOW_COPY_AND_ASSIGN(FunctionTestThread); |
77 }; | 77 }; |
78 | 78 |
79 TEST(PlatformThreadTest, Function) { | 79 TEST(PlatformThreadTest, Function) { |
80 PlatformThreadId main_thread_id = PlatformThread::CurrentId(); | 80 PlatformThreadId main_thread_id = PlatformThread::CurrentId(); |
81 | 81 |
82 FunctionTestThread thread; | 82 FunctionTestThread thread; |
83 PlatformThreadHandle handle = kNullThreadHandle; | 83 PlatformThreadHandle handle; |
84 | 84 |
85 ASSERT_FALSE(thread.did_run()); | 85 ASSERT_FALSE(thread.did_run()); |
86 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); | 86 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
87 PlatformThread::Join(handle); | 87 PlatformThread::Join(handle); |
88 ASSERT_TRUE(thread.did_run()); | 88 ASSERT_TRUE(thread.did_run()); |
89 EXPECT_NE(thread.thread_id(), main_thread_id); | 89 EXPECT_NE(thread.thread_id(), main_thread_id); |
90 | 90 |
91 // Make sure that the thread ID is the same across calls. | 91 // Make sure that the thread ID is the same across calls. |
92 EXPECT_EQ(main_thread_id, PlatformThread::CurrentId()); | 92 EXPECT_EQ(main_thread_id, PlatformThread::CurrentId()); |
93 } | 93 } |
(...skipping 18 matching lines...) Expand all Loading... |
112 for (size_t i = 0; i < n; ++i) { | 112 for (size_t i = 0; i < n; ++i) { |
113 EXPECT_NE(thread[i].thread_id(), thread[n].thread_id()); | 113 EXPECT_NE(thread[i].thread_id(), thread[n].thread_id()); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 // Make sure that the thread ID is the same across calls. | 117 // Make sure that the thread ID is the same across calls. |
118 EXPECT_EQ(main_thread_id, PlatformThread::CurrentId()); | 118 EXPECT_EQ(main_thread_id, PlatformThread::CurrentId()); |
119 } | 119 } |
120 | 120 |
121 } // namespace base | 121 } // namespace base |
OLD | NEW |