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

Side by Side Diff: base/id_map_unittest.cc

Issue 2830093003: Replace uses of hash_map in //base (Closed)
Patch Set: WebKit callers Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 TEST(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { 100 TEST(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) {
101 IDMap<TestObject*> map; 101 IDMap<TestObject*> map;
102 102
103 const int kCount = 5; 103 const int kCount = 5;
104 TestObject obj[kCount]; 104 TestObject obj[kCount];
105 105
106 for (int i = 0; i < kCount; i++) 106 for (int i = 0; i < kCount; i++)
107 map.Add(&obj[i]); 107 map.Add(&obj[i]);
108 108
109 // IDMap uses a hash_map, which has no predictable iteration order. 109 // IDMap has no predictable iteration order.
Łukasz Anforowicz 2017/04/24 18:46:10 Thanks for making the comment more generic - this
110 int32_t ids_in_iteration_order[kCount]; 110 int32_t ids_in_iteration_order[kCount];
111 const TestObject* objs_in_iteration_order[kCount]; 111 const TestObject* objs_in_iteration_order[kCount];
112 int counter = 0; 112 int counter = 0;
113 for (IDMap<TestObject*>::const_iterator iter(&map); !iter.IsAtEnd(); 113 for (IDMap<TestObject*>::const_iterator iter(&map); !iter.IsAtEnd();
114 iter.Advance()) { 114 iter.Advance()) {
115 ids_in_iteration_order[counter] = iter.GetCurrentKey(); 115 ids_in_iteration_order[counter] = iter.GetCurrentKey();
116 objs_in_iteration_order[counter] = iter.GetCurrentValue(); 116 objs_in_iteration_order[counter] = iter.GetCurrentValue();
117 counter++; 117 counter++;
118 } 118 }
119 119
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 TEST(IDMapTest, IteratorRemainsValidWhenClearing) { 210 TEST(IDMapTest, IteratorRemainsValidWhenClearing) {
211 IDMap<TestObject*> map; 211 IDMap<TestObject*> map;
212 212
213 const int kCount = 5; 213 const int kCount = 5;
214 TestObject obj[kCount]; 214 TestObject obj[kCount];
215 215
216 for (int i = 0; i < kCount; i++) 216 for (int i = 0; i < kCount; i++)
217 map.Add(&obj[i]); 217 map.Add(&obj[i]);
218 218
219 // IDMap uses a hash_map, which has no predictable iteration order. 219 // IDMap has no predictable iteration order.
220 int32_t ids_in_iteration_order[kCount]; 220 int32_t ids_in_iteration_order[kCount];
221 const TestObject* objs_in_iteration_order[kCount]; 221 const TestObject* objs_in_iteration_order[kCount];
222 int counter = 0; 222 int counter = 0;
223 for (IDMap<TestObject*>::const_iterator iter(&map); !iter.IsAtEnd(); 223 for (IDMap<TestObject*>::const_iterator iter(&map); !iter.IsAtEnd();
224 iter.Advance()) { 224 iter.Advance()) {
225 ids_in_iteration_order[counter] = iter.GetCurrentKey(); 225 ids_in_iteration_order[counter] = iter.GetCurrentKey();
226 objs_in_iteration_order[counter] = iter.GetCurrentValue(); 226 objs_in_iteration_order[counter] = iter.GetCurrentValue();
227 counter++; 227 counter++;
228 } 228 }
229 229
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 EXPECT_EQ(kId1, iter.GetCurrentKey()); 368 EXPECT_EQ(kId1, iter.GetCurrentKey());
369 EXPECT_EQ(&obj1, iter.GetCurrentValue()); 369 EXPECT_EQ(&obj1, iter.GetCurrentValue());
370 iter.Advance(); 370 iter.Advance();
371 ASSERT_TRUE(iter.IsAtEnd()); 371 ASSERT_TRUE(iter.IsAtEnd());
372 372
373 map.Remove(kId1); 373 map.Remove(kId1);
374 EXPECT_TRUE(map.IsEmpty()); 374 EXPECT_TRUE(map.IsEmpty());
375 } 375 }
376 376
377 } // namespace 377 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698