| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
| 6 | 6 |
| 7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 class NoopTracked : public tracked_objects::Tracked { | 55 class NoopTracked : public tracked_objects::Tracked { |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 58 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
| 59 if (!ThreadData::StartTracking(true)) | 59 if (!ThreadData::StartTracking(true)) |
| 60 return; | 60 return; |
| 61 | 61 |
| 62 // Instigate tracking on a single tracked object, or our thread. | 62 // Instigate tracking on a single tracked object, or our thread. |
| 63 const Location& location = FROM_HERE; |
| 63 NoopTracked tracked; | 64 NoopTracked tracked; |
| 65 tracked.SetBirthPlace(location); |
| 64 | 66 |
| 65 const ThreadData* data = ThreadData::first(); | 67 const ThreadData* data = ThreadData::first(); |
| 66 EXPECT_TRUE(data); | 68 ASSERT_TRUE(data); |
| 67 EXPECT_TRUE(!data->next()); | 69 EXPECT_TRUE(!data->next()); |
| 68 EXPECT_EQ(data, ThreadData::current()); | 70 EXPECT_EQ(data, ThreadData::current()); |
| 69 ThreadData::BirthMap birth_map; | 71 ThreadData::BirthMap birth_map; |
| 70 data->SnapshotBirthMap(&birth_map); | 72 data->SnapshotBirthMap(&birth_map); |
| 71 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 73 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 72 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 74 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 73 ThreadData::DeathMap death_map; | 75 ThreadData::DeathMap death_map; |
| 74 data->SnapshotDeathMap(&death_map); | 76 data->SnapshotDeathMap(&death_map); |
| 75 EXPECT_EQ(0u, death_map.size()); // No deaths. | 77 EXPECT_EQ(0u, death_map.size()); // No deaths. |
| 76 | 78 |
| 77 | 79 |
| 78 // Now instigate a birth, and a death. | 80 // Now instigate a birth, and a death. |
| 79 delete new NoopTracked; | 81 NoopTracked* new_tracked = new NoopTracked; |
| 82 new_tracked->SetBirthPlace(location); |
| 83 delete new_tracked; |
| 80 | 84 |
| 81 birth_map.clear(); | 85 birth_map.clear(); |
| 82 data->SnapshotBirthMap(&birth_map); | 86 data->SnapshotBirthMap(&birth_map); |
| 83 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 87 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 84 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 88 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 85 death_map.clear(); | 89 death_map.clear(); |
| 86 data->SnapshotDeathMap(&death_map); | 90 data->SnapshotDeathMap(&death_map); |
| 87 EXPECT_EQ(1u, death_map.size()); // 1 location. | 91 EXPECT_EQ(1u, death_map.size()); // 1 location. |
| 88 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 92 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
| 89 | 93 |
| 90 // The births were at the same location as the one known death. | 94 // The births were at the same location as the one known death. |
| 91 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 95 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
| 92 | 96 |
| 93 ThreadData::ShutdownSingleThreadedCleanup(); | 97 ThreadData::ShutdownSingleThreadedCleanup(); |
| 94 } | 98 } |
| 95 | 99 |
| 96 } // namespace tracked_objects | 100 } // namespace tracked_objects |
| OLD | NEW |