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/threading/thread.h" | 5 #include "base/threading/thread.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 EXPECT_FALSE(a.message_loop()); | 187 EXPECT_FALSE(a.message_loop()); |
188 EXPECT_FALSE(a.IsRunning()); | 188 EXPECT_FALSE(a.IsRunning()); |
189 } | 189 } |
190 | 190 |
191 TEST_F(ThreadTest, ThreadName) { | 191 TEST_F(ThreadTest, ThreadName) { |
192 Thread a("ThreadName"); | 192 Thread a("ThreadName"); |
193 EXPECT_TRUE(a.Start()); | 193 EXPECT_TRUE(a.Start()); |
194 EXPECT_EQ("ThreadName", a.thread_name()); | 194 EXPECT_EQ("ThreadName", a.thread_name()); |
195 } | 195 } |
196 | 196 |
| 197 TEST_F(ThreadTest, ThreadId) { |
| 198 Thread a("ThreadId0"); |
| 199 Thread b("ThreadId1"); |
| 200 a.StartAndWaitForTesting(); |
| 201 b.StartAndWaitForTesting(); |
| 202 |
| 203 // A started thread should have a valid ID. |
| 204 EXPECT_NE(base::kInvalidThreadId, a.thread_id()); |
| 205 EXPECT_NE(base::kInvalidThreadId, b.thread_id()); |
| 206 |
| 207 // Each thread should have a different thread ID. |
| 208 EXPECT_NE(a.thread_id(), b.thread_id()); |
| 209 } |
| 210 |
197 // Make sure Init() is called after Start() and before | 211 // Make sure Init() is called after Start() and before |
198 // WaitUntilThreadInitialized() returns. | 212 // WaitUntilThreadInitialized() returns. |
199 TEST_F(ThreadTest, SleepInsideInit) { | 213 TEST_F(ThreadTest, SleepInsideInit) { |
200 SleepInsideInitThread t; | 214 SleepInsideInitThread t; |
201 EXPECT_FALSE(t.InitCalled()); | 215 EXPECT_FALSE(t.InitCalled()); |
202 t.StartAndWaitForTesting(); | 216 t.StartAndWaitForTesting(); |
203 EXPECT_TRUE(t.InitCalled()); | 217 EXPECT_TRUE(t.InitCalled()); |
204 } | 218 } |
205 | 219 |
206 // Make sure that the destruction sequence is: | 220 // Make sure that the destruction sequence is: |
(...skipping 25 matching lines...) Expand all Loading... |
232 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); | 246 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); |
233 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); | 247 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); |
234 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); | 248 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); |
235 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); | 249 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); |
236 } | 250 } |
237 | 251 |
238 TEST_F(ThreadTest, ThreadNotStarted) { | 252 TEST_F(ThreadTest, ThreadNotStarted) { |
239 Thread a("Inert"); | 253 Thread a("Inert"); |
240 EXPECT_EQ(nullptr, a.task_runner()); | 254 EXPECT_EQ(nullptr, a.task_runner()); |
241 } | 255 } |
OLD | NEW |