Chromium Code Reviews| Index: base/memory/scoped_vector_unittest.cc |
| diff --git a/base/memory/scoped_vector_unittest.cc b/base/memory/scoped_vector_unittest.cc |
| index 7091a958c18039899bab3116715df775b026a0fd..857f93dc7aa3fcfb89b39eb2dacf9a5e52844646 100644 |
| --- a/base/memory/scoped_vector_unittest.cc |
| +++ b/base/memory/scoped_vector_unittest.cc |
| @@ -91,6 +91,11 @@ class LifeCycleWatcher : public LifeCycleObject::Observer { |
| return new LifeCycleObject(this); |
| } |
| + // Returns true iff |object| is the same object that this watcher is tracking. |
| + bool IsWatching(LifeCycleObject* object) const { |
| + return object == constructed_life_cycle_object_.get(); |
| + } |
| + |
| private: |
| LifeCycleState life_cycle_state_; |
| scoped_ptr<LifeCycleObject> constructed_life_cycle_object_; |
| @@ -113,6 +118,7 @@ TEST(ScopedVectorTest, Clear) { |
| ScopedVector<LifeCycleObject> scoped_vector; |
| scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); |
| scoped_vector.clear(); |
| EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); |
| EXPECT_EQ(implicit_cast<size_t>(0), scoped_vector.size()); |
| @@ -124,6 +130,7 @@ TEST(ScopedVectorTest, WeakClear) { |
| ScopedVector<LifeCycleObject> scoped_vector; |
| scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); |
| scoped_vector.weak_clear(); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| EXPECT_EQ(implicit_cast<size_t>(0), scoped_vector.size()); |
| @@ -139,16 +146,21 @@ TEST(ScopedVectorTest, ResizeShrink) { |
| scoped_vector.push_back(first_watcher.NewLifeCycleObject()); |
| EXPECT_EQ(LC_CONSTRUCTED, first_watcher.life_cycle_state()); |
| EXPECT_EQ(LC_INITIAL, second_watcher.life_cycle_state()); |
| + EXPECT_TRUE(first_watcher.IsWatching(scoped_vector[0])); |
| + EXPECT_FALSE(second_watcher.IsWatching(scoped_vector[0])); |
| scoped_vector.push_back(second_watcher.NewLifeCycleObject()); |
| EXPECT_EQ(LC_CONSTRUCTED, first_watcher.life_cycle_state()); |
| EXPECT_EQ(LC_CONSTRUCTED, second_watcher.life_cycle_state()); |
| + EXPECT_FALSE(first_watcher.IsWatching(scoped_vector[1])); |
| + EXPECT_TRUE(second_watcher.IsWatching(scoped_vector[1])); |
| // Test that shrinking a vector deletes elements in the dissapearing range. |
|
willchan no longer on Chromium
2012/12/04 01:41:50
disappearing
gavinp
2012/12/08 17:39:59
Done.
|
| scoped_vector.resize(1); |
| EXPECT_EQ(LC_CONSTRUCTED, first_watcher.life_cycle_state()); |
| EXPECT_EQ(LC_DESTROYED, second_watcher.life_cycle_state()); |
| EXPECT_EQ(implicit_cast<size_t>(1), scoped_vector.size()); |
| + EXPECT_TRUE(first_watcher.IsWatching(scoped_vector[0])); |
| } |
| TEST(ScopedVectorTest, ResizeGrow) { |
| @@ -157,9 +169,15 @@ TEST(ScopedVectorTest, ResizeGrow) { |
| ScopedVector<LifeCycleObject> scoped_vector; |
| scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); |
| scoped_vector.resize(5); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector[0])); |
| + EXPECT_FALSE(watcher.IsWatching(scoped_vector[1]) || |
|
willchan no longer on Chromium
2012/12/04 01:41:50
Just do multiple EXPECT_FALSEs, since if one of th
gavinp
2012/12/08 17:39:59
Done.
|
| + watcher.IsWatching(scoped_vector[2]) || |
| + watcher.IsWatching(scoped_vector[3]) || |
| + watcher.IsWatching(scoped_vector[4])); |
| EXPECT_EQ(implicit_cast<size_t>(5), scoped_vector.size()); |
|
willchan no longer on Chromium
2012/12/04 01:41:50
Move this ahead and do ASSERT_EQ, since if it's fa
gavinp
2012/12/08 17:39:59
Done. Good point, I'll remember to watch for this
|
| } |
| @@ -170,6 +188,7 @@ TEST(ScopedVectorTest, Scope) { |
| ScopedVector<LifeCycleObject> scoped_vector; |
| scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); |
| } |
| EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); |
| } |
| @@ -181,10 +200,12 @@ TEST(ScopedVectorTest, MoveConstruct) { |
| ScopedVector<LifeCycleObject> scoped_vector; |
| scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| EXPECT_FALSE(scoped_vector.empty()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); |
| ScopedVector<LifeCycleObject> scoped_vector_copy(scoped_vector.Pass()); |
| EXPECT_TRUE(scoped_vector.empty()); |
| EXPECT_FALSE(scoped_vector_copy.empty()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector_copy.back())); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| } |
| @@ -199,10 +220,12 @@ TEST(ScopedVectorTest, MoveAssign) { |
| scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| ScopedVector<LifeCycleObject> scoped_vector_assign; |
| EXPECT_FALSE(scoped_vector.empty()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); |
| scoped_vector_assign = scoped_vector.Pass(); |
| EXPECT_TRUE(scoped_vector.empty()); |
| EXPECT_FALSE(scoped_vector_assign.empty()); |
| + EXPECT_TRUE(watcher.IsWatching(scoped_vector_assign.back())); |
| EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| } |