Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: base/threading/thread_unittest.cc

Issue 1239623003: (not for review): PlatformThreadHandle: remove public id() interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: allow to wait inside thread_id() Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/threading/thread.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.Start();
201 b.Start();
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
211 TEST_F(ThreadTest, ThreadIdWithRestart) {
212 Thread a("ThreadIdWithRestart");
213 base::PlatformThreadId previous_id = base::kInvalidThreadId;
214
215 for (size_t i = 0; i < 16; ++i) {
216 EXPECT_TRUE(a.Start());
217 base::PlatformThreadId current_id = a.thread_id();
218 EXPECT_NE(previous_id, current_id);
219 previous_id = current_id;
220 a.Stop();
221 }
222 }
223
197 // Make sure Init() is called after Start() and before 224 // Make sure Init() is called after Start() and before
198 // WaitUntilThreadInitialized() returns. 225 // WaitUntilThreadInitialized() returns.
199 TEST_F(ThreadTest, SleepInsideInit) { 226 TEST_F(ThreadTest, SleepInsideInit) {
200 SleepInsideInitThread t; 227 SleepInsideInitThread t;
201 EXPECT_FALSE(t.InitCalled()); 228 EXPECT_FALSE(t.InitCalled());
202 t.StartAndWaitForTesting(); 229 t.StartAndWaitForTesting();
203 EXPECT_TRUE(t.InitCalled()); 230 EXPECT_TRUE(t.InitCalled());
204 } 231 }
205 232
206 // Make sure that the destruction sequence is: 233 // Make sure that the destruction sequence is:
(...skipping 25 matching lines...) Expand all
232 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); 259 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size());
233 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); 260 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]);
234 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); 261 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]);
235 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); 262 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]);
236 } 263 }
237 264
238 TEST_F(ThreadTest, ThreadNotStarted) { 265 TEST_F(ThreadTest, ThreadNotStarted) {
239 Thread a("Inert"); 266 Thread a("Inert");
240 EXPECT_EQ(nullptr, a.task_runner()); 267 EXPECT_EQ(nullptr, a.task_runner());
241 } 268 }
OLDNEW
« no previous file with comments | « base/threading/thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698