| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "base/id_map.h" | 5 #include "base/id_map.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 EXPECT_EQ(external_del_count, kCount); | 159 EXPECT_EQ(external_del_count, kCount); |
| 160 EXPECT_EQ(owned_del_count, kCount); | 160 EXPECT_EQ(owned_del_count, kCount); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(IDMapTest, OwningPointersDeletesThemOnDestruct) { | 163 TEST_F(IDMapTest, OwningPointersDeletesThemOnDestruct) { |
| 164 const int kCount = 3; | 164 const int kCount = 3; |
| 165 | 165 |
| 166 int external_del_count = 0; | 166 int external_del_count = 0; |
| 167 DestructorCounter* external_obj[kCount]; | 167 DestructorCounter* external_obj[kCount]; |
| 168 int map_external_ids[kCount]; | |
| 169 | 168 |
| 170 int owned_del_count = 0; | 169 int owned_del_count = 0; |
| 171 DestructorCounter* owned_obj[kCount]; | 170 DestructorCounter* owned_obj[kCount]; |
| 172 int map_owned_ids[kCount]; | |
| 173 | 171 |
| 174 { | 172 { |
| 175 IDMap<DestructorCounter> map_external; | 173 IDMap<DestructorCounter> map_external; |
| 176 IDMap<DestructorCounter, IDMapOwnPointer> map_owned; | 174 IDMap<DestructorCounter, IDMapOwnPointer> map_owned; |
| 177 | 175 |
| 178 for (int i = 0; i < kCount; ++i) { | 176 for (int i = 0; i < kCount; ++i) { |
| 179 external_obj[i] = new DestructorCounter(&external_del_count); | 177 external_obj[i] = new DestructorCounter(&external_del_count); |
| 180 map_external_ids[i] = map_external.Add(external_obj[i]); | 178 map_external.Add(external_obj[i]); |
| 181 | 179 |
| 182 owned_obj[i] = new DestructorCounter(&owned_del_count); | 180 owned_obj[i] = new DestructorCounter(&owned_del_count); |
| 183 map_owned_ids[i] = map_owned.Add(owned_obj[i]); | 181 map_owned.Add(owned_obj[i]); |
| 184 } | 182 } |
| 185 } | 183 } |
| 186 | 184 |
| 187 EXPECT_EQ(external_del_count, 0); | 185 EXPECT_EQ(external_del_count, 0); |
| 188 | 186 |
| 189 for (int i = 0; i < kCount; ++i) { | 187 for (int i = 0; i < kCount; ++i) { |
| 190 delete external_obj[i]; | 188 delete external_obj[i]; |
| 191 } | 189 } |
| 192 | 190 |
| 193 EXPECT_EQ(external_del_count, kCount); | 191 EXPECT_EQ(external_del_count, kCount); |
| 194 EXPECT_EQ(owned_del_count, kCount); | 192 EXPECT_EQ(owned_del_count, kCount); |
| 195 } | 193 } |
| 196 | 194 |
| 197 } // namespace | 195 } // namespace |
| OLD | NEW |