Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: base/id_map_unittest.cc

Issue 604048: Correctly recognize emptiness of IDMap. (Closed)
Patch Set: Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/id_map.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/id_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698