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..a74e683df68c268c1e6fc0e71a85f0a7c4b073f6 |
| --- /dev/null |
| +++ b/base/threading/thread_id_name_manager_unittest.cc |
| @@ -0,0 +1,71 @@ |
| +// 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 { |
| + |
| +static const char* kAThread = "a thread"; |
| +static const char* kBThread = "b thread"; |
| + |
| +TEST_F(ThreadIdNameManagerTest, AddThreads) { |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + base::Thread a(kAThread); |
|
jar (doing other things)
2012/12/06 20:54:37
nit: avoid such use of single letter names. Bette
dsinclair
2012/12/10 16:24:36
Done.
|
| + base::Thread b(kBThread); |
| + |
| + a.Start(); |
| + b.Start(); |
| + EXPECT_STREQ(kAThread, manager->GetNameForId(a.thread_id())); |
| + EXPECT_STREQ(kBThread, manager->GetNameForId(b.thread_id())); |
| + b.Stop(); |
| + a.Stop(); |
| +} |
| + |
| +TEST_F(ThreadIdNameManagerTest, RemoveThreads) { |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + base::Thread a(kAThread); |
| + |
| + a.Start(); |
| + base::PlatformThreadId b_id; |
| + { |
| + base::Thread b(kBThread); |
| + b.Start(); |
| + b_id = b.thread_id(); |
| + b.Stop(); |
| + } |
| + a.Stop(); |
| + |
| + EXPECT_STREQ(kAThread, manager->GetNameForId(a.thread_id())); |
| + EXPECT_EQ(NULL, manager->GetNameForId(b_id)); |
| +} |
| + |
| +TEST_F(ThreadIdNameManagerTest, RestartThread) { |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + base::Thread a(kAThread); |
| + |
| + a.Start(); |
| + base::PlatformThreadId a_id = a.thread_id(); |
| + a.Stop(); |
| + EXPECT_STREQ(kAThread, manager->GetNameForId(a_id)); |
| + |
| + a.Start(); |
| + a.Stop(); |
| + EXPECT_STREQ(kAThread, manager->GetNameForId(a_id)); |
| +} |
| + |
| +TEST_F(ThreadIdNameManagerTest, PointerStaysSame) { |
| + base::ThreadIdNameManager* manager = base::ThreadIdNameManager::GetInstance(); |
| + manager->SetNameForId(1, kAThread); |
| + |
| + EXPECT_EQ(kAThread, manager->GetNameForId(1)); |
| +} |
| + |
| +} // namespace |