Chromium Code Reviews| Index: base/threading/thread_id_name_manager_unittest.cc |
| diff --git a/base/threading/thread_id_name_manager_unittest.cc b/base/threading/thread_id_name_manager_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3bfdf03c3756e3a9175f75fa9145d5e34500a40a |
| --- /dev/null |
| +++ b/base/threading/thread_id_name_manager_unittest.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/threading/thread_id_name_manager.h" |
| + |
| +#include "base/threading/platform_thread.h" |
| +#include "base/threading/thread.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "testing/platform_test.h" |
| + |
| +typedef PlatformTest ThreadIdNameManagerTest; |
| + |
| +namespace { |
| + |
| +TEST_F(ThreadIdNameManagerTest, AddThreads) { |
| + base::Thread a("a thread"); |
| + base::Thread b("b thread"); |
| + |
| + a.Start(); |
| + b.Start(); |
| + |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + std::string name; |
| + |
| + EXPECT_TRUE(manager->GetNameForId(a.thread_id(), &name)); |
| + EXPECT_EQ(name, "a thread"); |
| + |
| + EXPECT_TRUE(manager->GetNameForId(b.thread_id(), &name)); |
| + EXPECT_EQ(name, "b thread"); |
| + |
| + b.Stop(); |
| + a.Stop(); |
| +} |
| + |
| +TEST_F(ThreadIdNameManagerTest, NonExistingThread) { |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + std::string name; |
| + 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.
|
| +} |
| + |
| +TEST_F(ThreadIdNameManagerTest, RemoveThreads) { |
| + base::Thread a("a thread"); |
| + a.Start(); |
| + |
| + base::PlatformThreadId b_id; |
| + { |
| + base::Thread b("b thread"); |
| + b.Start(); |
| + b_id = b.thread_id(); |
| + b.Stop(); |
| + } |
| + a.Stop(); |
| + |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + std::string name; |
| + |
| + EXPECT_TRUE(manager->GetNameForId(a.thread_id(), &name)); |
| + EXPECT_EQ(name, "a thread"); |
| + |
| + EXPECT_FALSE(manager->GetNameForId(b_id, &name)); |
| +} |
| + |
| +TEST_F(ThreadIdNameManagerTest, RestartThread) { |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + std::string name; |
| + |
| + base::Thread a("a thread"); |
| + |
| + a.Start(); |
| + base::PlatformThreadId a_id = a.thread_id(); |
| + |
| + a.Stop(); |
| + EXPECT_TRUE(manager->GetNameForId(a_id, &name)); |
| + EXPECT_EQ(name, "a thread"); |
| + |
| + a.Start(); |
| + a.Stop(); |
| + EXPECT_TRUE(manager->GetNameForId(a_id, &name)); |
| + EXPECT_EQ(name, "a thread"); |
| +} |
| + |
| +} // namespace |