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

Unified Diff: cc/quads/list_container_unittest.cc

Issue 1163803003: cc: Implement RemoveLast for DisplayItemList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: basic unit tests Created 5 years, 7 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
« cc/base/list_container.cc ('K') | « cc/playback/display_item_list.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/quads/list_container_unittest.cc
diff --git a/cc/quads/list_container_unittest.cc b/cc/quads/list_container_unittest.cc
index 76dd966b16a39efad8fbd735f66baecd3a7f82d9..ebf16b546410527ab393023cc36cb2246c27ba39 100644
--- a/cc/quads/list_container_unittest.cc
+++ b/cc/quads/list_container_unittest.cc
@@ -650,5 +650,57 @@ TEST(ListContainerTest,
}
}
+// Increments an int when constructed (or the counter pointer is supplied) and
+// decrements when destructed.
+class InstanceCounter {
+ public:
+ InstanceCounter() : counter_(nullptr) {}
+ explicit InstanceCounter(int* counter) { SetCounter(counter); }
+ ~InstanceCounter() {
+ if (counter_)
+ --*counter_;
+ }
+ void SetCounter(int* counter) {
+ counter_ = counter;
+ ++*counter_;
+ }
+
+ private:
+ int* counter_;
+};
+
+TEST(ListContainerTest, RemoveLast) {
jbroman 2015/06/02 19:36:19 Note that this will probably collide with a Samsun
+ // We keep an explicit instance count to make sure that the destructors are
+ // indeed getting called.
+ int counter = 0;
+ ListContainer<InstanceCounter> list(sizeof(InstanceCounter), 1);
+ EXPECT_EQ(0, counter);
+ EXPECT_EQ(0u, list.size());
+
+ // We should be okay to add one and then go back to zero.
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ EXPECT_EQ(1, counter);
+ EXPECT_EQ(1u, list.size());
+ list.RemoveLast();
+ EXPECT_EQ(0, counter);
+ EXPECT_EQ(0u, list.size());
+
+ // We should also be okay to remove the last multiple times, as long as there
danakj 2015/06/02 20:04:32 Can you add a test where you append one past a new
+ // are enough elements in the first place.
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter);
+ list.RemoveLast();
+ list.RemoveLast();
+ EXPECT_EQ(4, counter); // Leaves one in the last list.
+ EXPECT_EQ(4u, list.size());
+ list.RemoveLast();
+ EXPECT_EQ(3, counter); // Removes an inner list from before.
+ EXPECT_EQ(3u, list.size());
+}
+
} // namespace
} // namespace cc
« cc/base/list_container.cc ('K') | « cc/playback/display_item_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698