| 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_id_name_manager.h" | 5 #include "base/threading/thread_id_name_manager.h" |
| 6 | 6 |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 TEST_F(ThreadIdNameManagerTest, RemoveThreads) { | 34 TEST_F(ThreadIdNameManagerTest, RemoveThreads) { |
| 35 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | 35 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| 36 base::Thread thread_a(kAThread); | 36 base::Thread thread_a(kAThread); |
| 37 | 37 |
| 38 thread_a.Start(); | 38 thread_a.Start(); |
| 39 { | 39 { |
| 40 base::Thread thread_b(kBThread); | 40 base::Thread thread_b(kBThread); |
| 41 thread_b.Start(); | 41 thread_b.Start(); |
| 42 thread_b.Stop(); | 42 thread_b.Stop(); |
| 43 } | 43 } |
| 44 EXPECT_STREQ(kAThread, manager->GetName(thread_a.thread_id())); |
| 45 |
| 44 thread_a.Stop(); | 46 thread_a.Stop(); |
| 45 | 47 EXPECT_STREQ("", manager->GetName(thread_a.thread_id())); |
| 46 EXPECT_STREQ(kAThread, manager->GetName(thread_a.thread_id())); | |
| 47 } | 48 } |
| 48 | 49 |
| 49 TEST_F(ThreadIdNameManagerTest, RestartThread) { | 50 TEST_F(ThreadIdNameManagerTest, RestartThread) { |
| 50 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | 51 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| 51 base::Thread thread_a(kAThread); | 52 base::Thread thread_a(kAThread); |
| 52 | 53 |
| 53 thread_a.Start(); | 54 thread_a.Start(); |
| 54 base::PlatformThreadId a_id = thread_a.thread_id(); | 55 base::PlatformThreadId a_id = thread_a.thread_id(); |
| 56 EXPECT_STREQ(kAThread, manager->GetName(a_id)); |
| 55 thread_a.Stop(); | 57 thread_a.Stop(); |
| 56 EXPECT_STREQ(kAThread, manager->GetName(a_id)); | |
| 57 | 58 |
| 58 thread_a.Start(); | 59 thread_a.Start(); |
| 60 EXPECT_STREQ("", manager->GetName(a_id)); |
| 61 EXPECT_STREQ(kAThread, manager->GetName(thread_a.thread_id())); |
| 59 thread_a.Stop(); | 62 thread_a.Stop(); |
| 60 EXPECT_STREQ(kAThread, manager->GetName(a_id)); | |
| 61 } | 63 } |
| 62 | 64 |
| 63 TEST_F(ThreadIdNameManagerTest, ThreadNameInterning) { | 65 TEST_F(ThreadIdNameManagerTest, ThreadNameInterning) { |
| 64 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); | 66 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| 65 | 67 |
| 66 base::PlatformThreadId a_id = base::PlatformThread::CurrentId(); | 68 base::PlatformThreadId a_id = base::PlatformThread::CurrentId(); |
| 67 base::PlatformThread::SetName("First Name"); | 69 base::PlatformThread::SetName("First Name"); |
| 68 std::string version = manager->GetName(a_id); | 70 std::string version = manager->GetName(a_id); |
| 69 | 71 |
| 70 base::PlatformThread::SetName("New name"); | 72 base::PlatformThread::SetName("New name"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 base::PlatformThread::SetName("New name"); | 84 base::PlatformThread::SetName("New name"); |
| 83 EXPECT_NE(version, manager->GetName(a_id)); | 85 EXPECT_NE(version, manager->GetName(a_id)); |
| 84 | 86 |
| 85 base::PlatformThread::SetName("Test Name"); | 87 base::PlatformThread::SetName("Test Name"); |
| 86 EXPECT_EQ(version, manager->GetName(a_id)); | 88 EXPECT_EQ(version, manager->GetName(a_id)); |
| 87 | 89 |
| 88 base::PlatformThread::SetName(""); | 90 base::PlatformThread::SetName(""); |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace | 93 } // namespace |
| OLD | NEW |