Index: base/id_map_unittest.cc |
diff --git a/base/id_map_unittest.cc b/base/id_map_unittest.cc |
index 76d7c3ed4e99eae72655c07c52fc72b6ea034c82..c005a69057869b107e5dcde6b8467c9509a0caf6 100644 |
--- a/base/id_map_unittest.cc |
+++ b/base/id_map_unittest.cc |
@@ -94,31 +94,41 @@ TEST(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { |
const int kCount = 5; |
TestObject obj[kCount]; |
- int32 ids[kCount]; |
for (int i = 0; i < kCount; i++) |
- ids[i] = map.Add(&obj[i]); |
+ map.Add(&obj[i]); |
+ // IDMap uses a hash_map, which has no predictable iteration order. |
+ int32 ids_in_iteration_order[kCount]; |
+ const TestObject* objs_in_iteration_order[kCount]; |
int counter = 0; |
for (IDMap<TestObject>::const_iterator iter(&map); |
!iter.IsAtEnd(); iter.Advance()) { |
+ ids_in_iteration_order[counter] = iter.GetCurrentKey(); |
+ objs_in_iteration_order[counter] = iter.GetCurrentValue(); |
+ counter++; |
+ } |
+ |
+ counter = 0; |
+ for (IDMap<TestObject>::const_iterator iter(&map); |
+ !iter.IsAtEnd(); iter.Advance()) { |
EXPECT_EQ(1, map.iteration_depth()); |
switch (counter) { |
case 0: |
- EXPECT_EQ(ids[0], iter.GetCurrentKey()); |
- EXPECT_EQ(&obj[0], iter.GetCurrentValue()); |
- map.Remove(ids[1]); |
+ EXPECT_EQ(ids_in_iteration_order[0], iter.GetCurrentKey()); |
+ EXPECT_EQ(objs_in_iteration_order[0], iter.GetCurrentValue()); |
+ map.Remove(ids_in_iteration_order[1]); |
break; |
case 1: |
- EXPECT_EQ(ids[2], iter.GetCurrentKey()); |
- EXPECT_EQ(&obj[2], iter.GetCurrentValue()); |
- map.Remove(ids[3]); |
+ EXPECT_EQ(ids_in_iteration_order[2], iter.GetCurrentKey()); |
+ EXPECT_EQ(objs_in_iteration_order[2], iter.GetCurrentValue()); |
+ map.Remove(ids_in_iteration_order[3]); |
break; |
case 2: |
- EXPECT_EQ(ids[4], iter.GetCurrentKey()); |
- EXPECT_EQ(&obj[4], iter.GetCurrentValue()); |
- map.Remove(ids[0]); |
+ EXPECT_EQ(ids_in_iteration_order[4], iter.GetCurrentKey()); |
+ EXPECT_EQ(objs_in_iteration_order[4], iter.GetCurrentValue()); |
+ map.Remove(ids_in_iteration_order[0]); |
break; |
default: |
FAIL() << "should not have that many elements"; |
@@ -194,22 +204,32 @@ TEST(IDMapTest, IteratorRemainsValidWhenClearing) { |
const int kCount = 5; |
TestObject obj[kCount]; |
- int32 ids[kCount]; |
for (int i = 0; i < kCount; i++) |
- ids[i] = map.Add(&obj[i]); |
+ map.Add(&obj[i]); |
+ // IDMap uses a hash_map, which has no predictable iteration order. |
+ int32 ids_in_iteration_order[kCount]; |
+ const TestObject* objs_in_iteration_order[kCount]; |
int counter = 0; |
for (IDMap<TestObject>::const_iterator iter(&map); |
!iter.IsAtEnd(); iter.Advance()) { |
+ ids_in_iteration_order[counter] = iter.GetCurrentKey(); |
+ objs_in_iteration_order[counter] = iter.GetCurrentValue(); |
+ counter++; |
+ } |
+ |
+ counter = 0; |
+ for (IDMap<TestObject>::const_iterator iter(&map); |
+ !iter.IsAtEnd(); iter.Advance()) { |
switch (counter) { |
case 0: |
- EXPECT_EQ(ids[0], iter.GetCurrentKey()); |
- EXPECT_EQ(&obj[0], iter.GetCurrentValue()); |
+ EXPECT_EQ(ids_in_iteration_order[0], iter.GetCurrentKey()); |
+ EXPECT_EQ(objs_in_iteration_order[0], iter.GetCurrentValue()); |
break; |
case 1: |
- EXPECT_EQ(ids[1], iter.GetCurrentKey()); |
- EXPECT_EQ(&obj[1], iter.GetCurrentValue()); |
+ EXPECT_EQ(ids_in_iteration_order[1], iter.GetCurrentKey()); |
+ EXPECT_EQ(objs_in_iteration_order[1], iter.GetCurrentValue()); |
map.Clear(); |
EXPECT_TRUE(map.IsEmpty()); |
EXPECT_EQ(0U, map.size()); |