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

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

Issue 11438022: Add ability to retrieve a thread_name given a thread_id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixup to leaky properly. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(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 thread_a(kAThread);
22 base::Thread thread_b(kBThread);
23
24 thread_a.Start();
25 thread_b.Start();
26
27 EXPECT_STREQ(kAThread, manager->GetName(thread_a.thread_id()));
28 EXPECT_STREQ(kBThread, manager->GetName(thread_b.thread_id()));
29
30 thread_b.Stop();
31 thread_a.Stop();
32 }
33
34 TEST_F(ThreadIdNameManagerTest, RemoveThreads) {
35 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance();
36 base::Thread thread_a(kAThread);
37
38 thread_a.Start();
39 base::PlatformThreadId b_id;
40 {
41 base::Thread thread_b(kBThread);
42 thread_b.Start();
43 b_id = thread_b.thread_id();
44 thread_b.Stop();
45 }
46 thread_a.Stop();
47
48 EXPECT_STREQ(kAThread, manager->GetName(thread_a.thread_id()));
49 }
50
51 TEST_F(ThreadIdNameManagerTest, RestartThread) {
52 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance();
53 base::Thread thread_a(kAThread);
54
55 thread_a.Start();
56 base::PlatformThreadId a_id = thread_a.thread_id();
57 thread_a.Stop();
58 EXPECT_STREQ(kAThread, manager->GetName(a_id));
59
60 thread_a.Start();
61 thread_a.Stop();
62 EXPECT_STREQ(kAThread, manager->GetName(a_id));
63 }
64
65 TEST_F(ThreadIdNameManagerTest, ThreadNameInterning) {
66 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance();
67
68 base::PlatformThreadId a_id = base::PlatformThread::CurrentId();
69 base::PlatformThread::SetName("First Name");
70 std::string version = manager->GetName(a_id);
71
72 base::PlatformThread::SetName("New name");
73 EXPECT_NE(version, manager->GetName(a_id));
74 base::PlatformThread::SetName("");
75 }
76
77 TEST_F(ThreadIdNameManagerTest, ResettingNameKeepsCorrectInternedValue) {
78 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance();
79
80 base::PlatformThreadId a_id = base::PlatformThread::CurrentId();
81 base::PlatformThread::SetName("Test Name");
82 std::string version = manager->GetName(a_id);
83
84 base::PlatformThread::SetName("New name");
85 EXPECT_NE(version, manager->GetName(a_id));
86
87 base::PlatformThread::SetName("Test Name");
88 EXPECT_EQ(version, manager->GetName(a_id));
89
90 base::PlatformThread::SetName("");
91 }
92
93 } // namespace
OLDNEW
« base/threading/thread_id_name_manager.cc ('K') | « base/threading/thread_id_name_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698