OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/threading/thread_id_name_manager.h" | |
6 | |
7 #include "base/threading/platform_thread.h" | |
8 #include "base/threading/thread.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "testing/platform_test.h" | |
11 | |
12 typedef PlatformTest ThreadIdNameManagerTest; | |
13 | |
14 namespace { | |
15 | |
16 static const char* kAThread = "a thread"; | |
17 static const char* kBThread = "b thread"; | |
18 | |
19 TEST_F(ThreadIdNameManagerTest, AddThreads) { | |
20 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
21 base::Thread a(kAThread); | |
jar (doing other things)
2012/12/06 20:54:37
nit: avoid such use of single letter names. Bette
dsinclair
2012/12/10 16:24:36
Done.
| |
22 base::Thread b(kBThread); | |
23 | |
24 a.Start(); | |
25 b.Start(); | |
26 EXPECT_STREQ(kAThread, manager->GetNameForId(a.thread_id())); | |
27 EXPECT_STREQ(kBThread, manager->GetNameForId(b.thread_id())); | |
28 b.Stop(); | |
29 a.Stop(); | |
30 } | |
31 | |
32 TEST_F(ThreadIdNameManagerTest, RemoveThreads) { | |
33 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
34 base::Thread a(kAThread); | |
35 | |
36 a.Start(); | |
37 base::PlatformThreadId b_id; | |
38 { | |
39 base::Thread b(kBThread); | |
40 b.Start(); | |
41 b_id = b.thread_id(); | |
42 b.Stop(); | |
43 } | |
44 a.Stop(); | |
45 | |
46 EXPECT_STREQ(kAThread, manager->GetNameForId(a.thread_id())); | |
47 EXPECT_EQ(NULL, manager->GetNameForId(b_id)); | |
48 } | |
49 | |
50 TEST_F(ThreadIdNameManagerTest, RestartThread) { | |
51 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
52 base::Thread a(kAThread); | |
53 | |
54 a.Start(); | |
55 base::PlatformThreadId a_id = a.thread_id(); | |
56 a.Stop(); | |
57 EXPECT_STREQ(kAThread, manager->GetNameForId(a_id)); | |
58 | |
59 a.Start(); | |
60 a.Stop(); | |
61 EXPECT_STREQ(kAThread, manager->GetNameForId(a_id)); | |
62 } | |
63 | |
64 TEST_F(ThreadIdNameManagerTest, PointerStaysSame) { | |
65 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
66 manager->SetNameForId(1, kAThread); | |
67 | |
68 EXPECT_EQ(kAThread, manager->GetNameForId(1)); | |
69 } | |
70 | |
71 } // namespace | |
OLD | NEW |