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 thread_a(kAThread); |
| 22 base::Thread thread_b(kBThread); |
| 23 |
| 24 thread_a.Start(); |
| 25 thread_b.Start(); |
| 26 EXPECT_STREQ(kAThread, manager->GetNameForId(thread_a.thread_id())); |
| 27 EXPECT_STREQ(kBThread, manager->GetNameForId(thread_b.thread_id())); |
| 28 thread_b.Stop(); |
| 29 thread_a.Stop(); |
| 30 } |
| 31 |
| 32 TEST_F(ThreadIdNameManagerTest, RemoveThreads) { |
| 33 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| 34 base::Thread thread_a(kAThread); |
| 35 |
| 36 thread_a.Start(); |
| 37 base::PlatformThreadId b_id; |
| 38 { |
| 39 base::Thread thread_b(kBThread); |
| 40 thread_b.Start(); |
| 41 b_id = thread_b.thread_id(); |
| 42 thread_b.Stop(); |
| 43 } |
| 44 thread_a.Stop(); |
| 45 |
| 46 EXPECT_STREQ(kAThread, manager->GetNameForId(thread_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 thread_a(kAThread); |
| 53 |
| 54 thread_a.Start(); |
| 55 base::PlatformThreadId a_id = thread_a.thread_id(); |
| 56 thread_a.Stop(); |
| 57 EXPECT_STREQ(kAThread, manager->GetNameForId(a_id)); |
| 58 |
| 59 thread_a.Start(); |
| 60 thread_a.Stop(); |
| 61 EXPECT_STREQ(kAThread, manager->GetNameForId(a_id)); |
| 62 } |
| 63 |
| 64 TEST_F(ThreadIdNameManagerTest, ThreadNameVersion) { |
| 65 base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| 66 |
| 67 base::PlatformThreadId a_id = base::PlatformThread::CurrentId(); |
| 68 uint version = manager->GetVersionForId(a_id); |
| 69 |
| 70 base::PlatformThread::SetName("New name"); |
| 71 EXPECT_NE(version, manager->GetVersionForId(a_id)); |
| 72 base::PlatformThread::SetName(""); |
| 73 } |
| 74 |
| 75 } // namespace |
OLD | NEW |