OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 EXPECT_EQ(data, ThreadData::current()); | 44 EXPECT_EQ(data, ThreadData::current()); |
45 birth_map.clear(); | 45 birth_map.clear(); |
46 data->SnapshotBirthMap(&birth_map); | 46 data->SnapshotBirthMap(&birth_map); |
47 EXPECT_EQ(0u, birth_map.size()); | 47 EXPECT_EQ(0u, birth_map.size()); |
48 death_map.clear(); | 48 death_map.clear(); |
49 data->SnapshotDeathMap(&death_map); | 49 data->SnapshotDeathMap(&death_map); |
50 EXPECT_EQ(0u, death_map.size()); | 50 EXPECT_EQ(0u, death_map.size()); |
51 ThreadData::ShutdownSingleThreadedCleanup(); | 51 ThreadData::ShutdownSingleThreadedCleanup(); |
52 } | 52 } |
53 | 53 |
54 class NoopTask : public Task { | 54 class NoopTracked : public tracked_objects::Tracked { |
55 public: | |
56 void Run() {} | |
57 }; | 55 }; |
58 | 56 |
59 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 57 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
60 if (!ThreadData::StartTracking(true)) | 58 if (!ThreadData::StartTracking(true)) |
61 return; | 59 return; |
62 | 60 |
63 // Instigate tracking on a single task, or our thread. | 61 // Instigate tracking on a single tracked object, or our thread. |
64 NoopTask task; | 62 NoopTracked tracked; |
65 | 63 |
66 const ThreadData* data = ThreadData::first(); | 64 const ThreadData* data = ThreadData::first(); |
67 EXPECT_TRUE(data); | 65 EXPECT_TRUE(data); |
68 EXPECT_TRUE(!data->next()); | 66 EXPECT_TRUE(!data->next()); |
69 EXPECT_EQ(data, ThreadData::current()); | 67 EXPECT_EQ(data, ThreadData::current()); |
70 ThreadData::BirthMap birth_map; | 68 ThreadData::BirthMap birth_map; |
71 data->SnapshotBirthMap(&birth_map); | 69 data->SnapshotBirthMap(&birth_map); |
72 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 70 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
73 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 71 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
74 ThreadData::DeathMap death_map; | 72 ThreadData::DeathMap death_map; |
75 data->SnapshotDeathMap(&death_map); | 73 data->SnapshotDeathMap(&death_map); |
76 EXPECT_EQ(0u, death_map.size()); // No deaths. | 74 EXPECT_EQ(0u, death_map.size()); // No deaths. |
77 | 75 |
78 | 76 |
79 // Now instigate a birth, and a death. | 77 // Now instigate a birth, and a death. |
80 delete new NoopTask; | 78 delete new NoopTracked; |
81 | 79 |
82 birth_map.clear(); | 80 birth_map.clear(); |
83 data->SnapshotBirthMap(&birth_map); | 81 data->SnapshotBirthMap(&birth_map); |
84 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 82 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
85 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 83 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
86 death_map.clear(); | 84 death_map.clear(); |
87 data->SnapshotDeathMap(&death_map); | 85 data->SnapshotDeathMap(&death_map); |
88 EXPECT_EQ(1u, death_map.size()); // 1 location. | 86 EXPECT_EQ(1u, death_map.size()); // 1 location. |
89 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 87 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
90 | 88 |
91 // The births were at the same location as the one known death. | 89 // The births were at the same location as the one known death. |
92 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 90 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
93 | 91 |
94 ThreadData::ShutdownSingleThreadedCleanup(); | 92 ThreadData::ShutdownSingleThreadedCleanup(); |
95 } | 93 } |
96 | 94 |
97 } // namespace tracked_objects | 95 } // namespace tracked_objects |
OLD | NEW |