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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 IDMap<TestObject> map; | 52 IDMap<TestObject> map; |
53 | 53 |
54 TestObject obj1; | 54 TestObject obj1; |
55 TestObject obj2; | 55 TestObject obj2; |
56 TestObject obj3; | 56 TestObject obj3; |
57 | 57 |
58 map.Add(&obj1); | 58 map.Add(&obj1); |
59 map.Add(&obj2); | 59 map.Add(&obj2); |
60 map.Add(&obj3); | 60 map.Add(&obj3); |
61 | 61 |
62 for (IDMap<TestObject>::const_iterator iter(&map); | 62 { |
63 !iter.IsAtEnd(); iter.Advance()) { | 63 IDMap<TestObject>::const_iterator iter(&map); |
64 map.Remove(iter.GetCurrentKey()); | 64 while (!iter.IsAtEnd()) { |
| 65 map.Remove(iter.GetCurrentKey()); |
| 66 iter.Advance(); |
| 67 } |
| 68 |
| 69 // Test that while an iterator is still in scope, we get the map emptiness |
| 70 // right (http://crbug.com/35571). |
| 71 EXPECT_TRUE(map.IsEmpty()); |
| 72 EXPECT_EQ(0U, map.size()); |
65 } | 73 } |
| 74 |
| 75 EXPECT_TRUE(map.IsEmpty()); |
| 76 EXPECT_EQ(0U, map.size()); |
66 } | 77 } |
67 | 78 |
68 TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { | 79 TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { |
69 IDMap<TestObject> map; | 80 IDMap<TestObject> map; |
70 | 81 |
71 const int kCount = 5; | 82 const int kCount = 5; |
72 TestObject obj[kCount]; | 83 TestObject obj[kCount]; |
73 int32 ids[kCount]; | 84 int32 ids[kCount]; |
74 | 85 |
75 for (int i = 0; i < kCount; i++) | 86 for (int i = 0; i < kCount; i++) |
(...skipping 21 matching lines...) Expand all Loading... |
97 default: | 108 default: |
98 FAIL() << "should not have that many elements"; | 109 FAIL() << "should not have that many elements"; |
99 break; | 110 break; |
100 } | 111 } |
101 | 112 |
102 counter++; | 113 counter++; |
103 } | 114 } |
104 } | 115 } |
105 | 116 |
106 } // namespace | 117 } // namespace |
OLD | NEW |