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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 IDMap<TestObject> map; | 60 IDMap<TestObject> map; |
61 | 61 |
62 TestObject obj1; | 62 TestObject obj1; |
63 TestObject obj2; | 63 TestObject obj2; |
64 TestObject obj3; | 64 TestObject obj3; |
65 | 65 |
66 map.Add(&obj1); | 66 map.Add(&obj1); |
67 map.Add(&obj2); | 67 map.Add(&obj2); |
68 map.Add(&obj3); | 68 map.Add(&obj3); |
69 | 69 |
70 for (IDMap<TestObject>::const_iterator iter(&map); | 70 { |
71 !iter.IsAtEnd(); iter.Advance()) { | 71 IDMap<TestObject>::const_iterator iter(&map); |
72 map.Remove(iter.GetCurrentKey()); | 72 while (!iter.IsAtEnd()) { |
| 73 map.Remove(iter.GetCurrentKey()); |
| 74 iter.Advance(); |
| 75 } |
| 76 |
| 77 // Test that while an iterator is still in scope, we get the map emptiness |
| 78 // right (http://crbug.com/35571). |
| 79 EXPECT_TRUE(map.IsEmpty()); |
| 80 EXPECT_EQ(0U, map.size()); |
73 } | 81 } |
| 82 |
| 83 EXPECT_TRUE(map.IsEmpty()); |
| 84 EXPECT_EQ(0U, map.size()); |
74 } | 85 } |
75 | 86 |
76 TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { | 87 TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { |
77 IDMap<TestObject> map; | 88 IDMap<TestObject> map; |
78 | 89 |
79 const int kCount = 5; | 90 const int kCount = 5; |
80 TestObject obj[kCount]; | 91 TestObject obj[kCount]; |
81 int32 ids[kCount]; | 92 int32 ids[kCount]; |
82 | 93 |
83 for (int i = 0; i < kCount; i++) | 94 for (int i = 0; i < kCount; i++) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 188 |
178 for (int i = 0; i < kCount; ++i) { | 189 for (int i = 0; i < kCount; ++i) { |
179 delete external_obj[i]; | 190 delete external_obj[i]; |
180 } | 191 } |
181 | 192 |
182 EXPECT_EQ(external_del_count, kCount); | 193 EXPECT_EQ(external_del_count, kCount); |
183 EXPECT_EQ(owned_del_count, kCount); | 194 EXPECT_EQ(owned_del_count, kCount); |
184 } | 195 } |
185 | 196 |
186 } // namespace | 197 } // namespace |
OLD | NEW |