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 |