thread_id_name_manager_unittest.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "butil/threading/thread_id_name_manager.h"
  5. #include "butil/threading/platform_thread.h"
  6. #include <gtest/gtest.h>
  7. typedef testing::Test ThreadIdNameManagerTest;
  8. namespace {
  9. TEST_F(ThreadIdNameManagerTest, ThreadNameInterning) {
  10. butil::ThreadIdNameManager* manager = butil::ThreadIdNameManager::GetInstance();
  11. butil::PlatformThreadId a_id = butil::PlatformThread::CurrentId();
  12. butil::PlatformThread::SetName("First Name");
  13. std::string version = manager->GetName(a_id);
  14. butil::PlatformThread::SetName("New name");
  15. EXPECT_NE(version, manager->GetName(a_id));
  16. butil::PlatformThread::SetName("");
  17. }
  18. TEST_F(ThreadIdNameManagerTest, ResettingNameKeepsCorrectInternedValue) {
  19. butil::ThreadIdNameManager* manager = butil::ThreadIdNameManager::GetInstance();
  20. butil::PlatformThreadId a_id = butil::PlatformThread::CurrentId();
  21. butil::PlatformThread::SetName("Test Name");
  22. std::string version = manager->GetName(a_id);
  23. butil::PlatformThread::SetName("New name");
  24. EXPECT_NE(version, manager->GetName(a_id));
  25. butil::PlatformThread::SetName("Test Name");
  26. EXPECT_EQ(version, manager->GetName(a_id));
  27. butil::PlatformThread::SetName("");
  28. }
  29. } // namespace