diff options
author | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 22:39:42 +0000 |
---|---|---|
committer | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 22:39:42 +0000 |
commit | e31354232246bf18820115ea1d4cc4d341a09ce6 (patch) | |
tree | 44541ec42bd45a79c3c7d49e7223d52c10cea5f4 | |
parent | ac4f468b91aaa11d6a52f7fc2075760ac6331eb7 (diff) | |
download | chromium_src-e31354232246bf18820115ea1d4cc4d341a09ce6.zip chromium_src-e31354232246bf18820115ea1d4cc4d341a09ce6.tar.gz chromium_src-e31354232246bf18820115ea1d4cc4d341a09ce6.tar.bz2 |
Assert on actual contents of ScopedVector in scoped_vector_unittest.
It's great if objects have the expected life cycles, and it's great if the vectors have the right sizes and clear at the right times.
But isn't it also nice if the expected object is being stored in the expected place?
R=willchan@chromium.org
BUG=None
Review URL: https://chromiumcodereview.appspot.com/11316156
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171996 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/memory/scoped_vector_unittest.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/base/memory/scoped_vector_unittest.cc b/base/memory/scoped_vector_unittest.cc index 6eefbff..a91776a 100644 --- a/base/memory/scoped_vector_unittest.cc +++ b/base/memory/scoped_vector_unittest.cc @@ -93,6 +93,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_; @@ -115,6 +120,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_TRUE(scoped_vector.empty()); @@ -126,6 +132,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_TRUE(scoped_vector.empty()); @@ -141,16 +148,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. + // Test that shrinking a vector deletes elements in the disappearing range. scoped_vector.resize(1); EXPECT_EQ(LC_CONSTRUCTED, first_watcher.life_cycle_state()); EXPECT_EQ(LC_DESTROYED, second_watcher.life_cycle_state()); EXPECT_EQ(1u, scoped_vector.size()); + EXPECT_TRUE(first_watcher.IsWatching(scoped_vector[0])); } TEST(ScopedVectorTest, ResizeGrow) { @@ -159,10 +171,16 @@ 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_EQ(5u, scoped_vector.size()); + ASSERT_EQ(5u, scoped_vector.size()); + EXPECT_TRUE(watcher.IsWatching(scoped_vector[0])); + EXPECT_FALSE(watcher.IsWatching(scoped_vector[1])); + EXPECT_FALSE(watcher.IsWatching(scoped_vector[2])); + EXPECT_FALSE(watcher.IsWatching(scoped_vector[3])); + EXPECT_FALSE(watcher.IsWatching(scoped_vector[4])); } TEST(ScopedVectorTest, Scope) { @@ -172,6 +190,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()); } @@ -183,10 +202,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()); } @@ -201,10 +222,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()); } |