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

Unified Diff: base/memory/scoped_vector_unittest.cc

Issue 11316156: Assert on actual contents of ScopedVector in scoped_vector_unittest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediate to review Created 8 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/scoped_vector_unittest.cc
diff --git a/base/memory/scoped_vector_unittest.cc b/base/memory/scoped_vector_unittest.cc
index 6eefbffba6f1fa85cb016643f202b4ad6db5aeee..a91776afe92a97a66b02b300dca9112966232af1 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());
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698