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

Unified Diff: Source/platform/graphics/ListContainerTest.cpp

Issue 1207773003: Add ListContainer::swap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refactor for clairty Created 5 years, 6 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
« no previous file with comments | « Source/platform/graphics/ListContainer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/ListContainerTest.cpp
diff --git a/Source/platform/graphics/ListContainerTest.cpp b/Source/platform/graphics/ListContainerTest.cpp
index 95d644edd07d509aa62ab2c37a2fec5e24e8889b..b92b588bcb977fdb77a9bd1e13ba78e1e440cbbd 100644
--- a/Source/platform/graphics/ListContainerTest.cpp
+++ b/Source/platform/graphics/ListContainerTest.cpp
@@ -113,6 +113,14 @@ public:
}
};
+class SimpleDerivedElementConstructMagicNumberThree : public SimpleDerivedElement {
+public:
+ SimpleDerivedElementConstructMagicNumberThree()
+ {
+ setValue(kMagicNumberToUseForSimpleDerivedElementThree);
+ }
+};
+
class MockDerivedElement : public SimpleDerivedElementConstructMagicNumberOne {
public:
~MockDerivedElement() override { Destruct(); }
@@ -939,5 +947,33 @@ TEST(ListContainerTest, AppendByMovingLongAndSimpleDerivedElements)
EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne, list.back()->getValue());
}
+TEST(ListContainerTest, Swap)
+{
+ ListContainer<SimpleDerivedElement> list1(kCurrentLargestDerivedElementSize);
+ list1.allocateAndConstruct<SimpleDerivedElementConstructMagicNumberOne>();
+ ListContainer<SimpleDerivedElement> list2(kCurrentLargestDerivedElementSize);
+ list2.allocateAndConstruct<SimpleDerivedElementConstructMagicNumberTwo>();
+ list2.allocateAndConstruct<SimpleDerivedElementConstructMagicNumberThree>();
+
+ SimpleDerivedElement* preSwapList1Front = list1.front();
+
+ EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne, list1.front()->getValue());
+ EXPECT_EQ(1u, list1.size());
+ EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo, list2.front()->getValue());
+ EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementThree, list2.back()->getValue());
+ EXPECT_EQ(2u, list2.size());
+
+ list2.swap(list1);
+
+ EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo, list1.front()->getValue());
+ EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementThree, list1.back()->getValue());
+ EXPECT_EQ(2u, list1.size());
+ EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne, list2.front()->getValue());
+ EXPECT_EQ(1u, list2.size());
+
+ // Ensure pointers are still valid after swapping.
+ EXPECT_EQ(preSwapList1Front, list2.front());
+}
+
} // namespace
} // namespace blink
« no previous file with comments | « Source/platform/graphics/ListContainer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698