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 TEST_F(ThreadIdNameManagerTest, AddThreads) { | |
17 base::Thread a("a thread"); | |
18 base::Thread b("b thread"); | |
19 | |
20 a.Start(); | |
21 b.Start(); | |
22 | |
23 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
24 std::string name; | |
25 | |
26 EXPECT_TRUE(manager->GetNameForId(a.thread_id(), &name)); | |
27 EXPECT_EQ(name, "a thread"); | |
28 | |
29 EXPECT_TRUE(manager->GetNameForId(b.thread_id(), &name)); | |
30 EXPECT_EQ(name, "b thread"); | |
31 | |
32 b.Stop(); | |
33 a.Stop(); | |
34 } | |
35 | |
36 TEST_F(ThreadIdNameManagerTest, NonExistingThread) { | |
37 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
38 std::string name; | |
39 EXPECT_FALSE(manager->GetNameForId(1234, &name)); | |
jonathan.backer
2012/12/05 20:06:12
How do you know that this isn't a valid thread id?
dsinclair
2012/12/05 20:40:09
Good point, removed the test.
| |
40 } | |
41 | |
42 TEST_F(ThreadIdNameManagerTest, RemoveThreads) { | |
43 base::Thread a("a thread"); | |
44 a.Start(); | |
45 | |
46 base::PlatformThreadId b_id; | |
47 { | |
48 base::Thread b("b thread"); | |
49 b.Start(); | |
50 b_id = b.thread_id(); | |
51 b.Stop(); | |
52 } | |
53 a.Stop(); | |
54 | |
55 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
56 std::string name; | |
57 | |
58 EXPECT_TRUE(manager->GetNameForId(a.thread_id(), &name)); | |
59 EXPECT_EQ(name, "a thread"); | |
60 | |
61 EXPECT_FALSE(manager->GetNameForId(b_id, &name)); | |
62 } | |
63 | |
64 TEST_F(ThreadIdNameManagerTest, RestartThread) { | |
65 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | |
66 std::string name; | |
67 | |
68 base::Thread a("a thread"); | |
69 | |
70 a.Start(); | |
71 base::PlatformThreadId a_id = a.thread_id(); | |
72 | |
73 a.Stop(); | |
74 EXPECT_TRUE(manager->GetNameForId(a_id, &name)); | |
75 EXPECT_EQ(name, "a thread"); | |
76 | |
77 a.Start(); | |
78 a.Stop(); | |
79 EXPECT_TRUE(manager->GetNameForId(a_id, &name)); | |
80 EXPECT_EQ(name, "a thread"); | |
81 } | |
82 | |
83 } // namespace | |
OLD | NEW |