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

Unified 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: Move the set to PlatformThread::SetName so we catch any name changes. Created 8 years 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 side-by-side diff with in-line comments
Download patch
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
« base/threading/thread_id_name_manager.h ('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