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

Unified Diff: base/id_map_unittest.cc

Issue 130783003: Fix incorrect assumption in IDMap and SmallMap tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: do not use == (causes compile errors) Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/containers/small_map_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « base/containers/small_map_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698