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

Unified Diff: Source/wtf/VectorTest.cpp

Issue 390983010: Fix Deque.swap for deques with inline capacity Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use more fullnesses in test to improve coverage Created 6 years, 5 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
« Source/wtf/Vector.h ('K') | « Source/wtf/Vector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/VectorTest.cpp
diff --git a/Source/wtf/VectorTest.cpp b/Source/wtf/VectorTest.cpp
index 3c1e4783e83e071bf2d14d519c87c356422abfab..3cd32449fe050de2151552ae4b0a22a6025ffe0c 100644
--- a/Source/wtf/VectorTest.cpp
+++ b/Source/wtf/VectorTest.cpp
@@ -302,4 +302,106 @@ TEST(VectorTest, Compare)
compare<Comparable>();
compare<WTF::String>();
}
+
+class LivenessCounter {
+public:
+ void ref() { s_live++; }
+ void deref() { s_live--; }
+
+ static unsigned s_live;
+};
+
+unsigned LivenessCounter::s_live = 0;
+
+template<size_t inlineCapacity>
+void theBigSwapTest()
+{
+ LivenessCounter::s_live = 0;
+ LivenessCounter counter;
+ EXPECT_EQ(0u, LivenessCounter::s_live);
+
+ Vector<RefPtr<LivenessCounter>, inlineCapacity> vector;
+ Vector<RefPtr<LivenessCounter>, inlineCapacity> vector2;
+ vector.append(&counter);
+ vector2.append(&counter);
+ EXPECT_EQ(2u, LivenessCounter::s_live);
+
+ for (unsigned i = 0; i < 13; i++) {
+ for (unsigned j = 0; j < 13; j++) {
+ vector.clear();
+ vector2.clear();
+ EXPECT_EQ(0u, LivenessCounter::s_live);
+
+ for (unsigned k = 0; k < j; k++)
+ vector.append(&counter);
+ EXPECT_EQ(j, LivenessCounter::s_live);
+ EXPECT_EQ(j, vector.size());
+
+ for (unsigned k = 0; k < i; k++)
+ vector2.append(&counter);
+ EXPECT_EQ(i + j, LivenessCounter::s_live);
+ EXPECT_EQ(i, vector2.size());
+
+ vector.swap(vector2);
+ EXPECT_EQ(i + j, LivenessCounter::s_live);
+ EXPECT_EQ(i, vector.size());
+ EXPECT_EQ(j, vector2.size());
+
+ unsigned size = vector.size();
+ unsigned size2 = vector2.size();
+
+ for (unsigned k = 0; k < 5; k++) {
+ vector.swap(vector2);
+ std::swap(size, size2);
+ EXPECT_EQ(i + j, LivenessCounter::s_live);
+ EXPECT_EQ(size, vector.size());
+ EXPECT_EQ(size2, vector2.size());
+
+ vector2.append(&counter);
+ vector2.remove(0);
+ }
+ }
+ }
+
+}
+
+TEST(VectorTest, BigSwapTest)
+{
+ theBigSwapTest<0>();
+ theBigSwapTest<2>();
+ theBigSwapTest<10>();
+}
+
+template<size_t inlineCapacity>
+void swapValuesTest()
+{
+ Vector<unsigned, inlineCapacity> vector;
+ Vector<unsigned, inlineCapacity> vector2;
+
+ for (unsigned size = 0; size < 13; size++) {
+ for (unsigned size2 = 0; size2 < 13; size2++) {
+ vector.clear();
+ vector2.clear();
+ for (unsigned i = 0; i < size; i++)
+ vector.append(i);
+ for (unsigned i = 0; i < size2; i++)
+ vector2.append(i + 42);
+ EXPECT_EQ(size, vector.size());
+ EXPECT_EQ(size2, vector2.size());
+ vector.swap(vector2);
+ for (unsigned i = 0; i < size; i++)
+ EXPECT_EQ(i, vector2[i]);
+ for (unsigned i = 0; i < size2; i++)
+ EXPECT_EQ(i + 42, vector[i]);
+ }
+ }
+}
+
+TEST(VectorTest, SwapValuesTest)
+{
+ swapValuesTest<0>();
+ swapValuesTest<2>();
+ swapValuesTest<10>();
+}
+
} // namespace
« Source/wtf/Vector.h ('K') | « Source/wtf/Vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698