summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-07-31 09:42:24 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-07-31 09:42:24 +0000
commit06bd8ca8c276d9bc20b192188224e1e5215666a0 (patch)
treece0e4cc9bad21a7beb0ecbfed45245ced370bd8f /unittests
parent3f5054f922fe0164e14750845f84d3e0e00ab7a1 (diff)
downloadllvm-06bd8ca8c276d9bc20b192188224e1e5215666a0.tar.gz
llvm-06bd8ca8c276d9bc20b192188224e1e5215666a0.tar.bz2
llvm-06bd8ca8c276d9bc20b192188224e1e5215666a0.tar.xz
Implement copy and move assignment for TinyPtrVector. These try to
re-use allocated vectors as much as possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161041 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/TinyPtrVectorTest.cpp166
1 files changed, 166 insertions, 0 deletions
diff --git a/unittests/ADT/TinyPtrVectorTest.cpp b/unittests/ADT/TinyPtrVectorTest.cpp
index 9f02b3ce0f..94939279c1 100644
--- a/unittests/ADT/TinyPtrVectorTest.cpp
+++ b/unittests/ADT/TinyPtrVectorTest.cpp
@@ -60,6 +60,13 @@ protected:
V.push_back(Values[i]);
}
+ void setVectors(ArrayRef<PtrT> Values1, ArrayRef<PtrT> Values2) {
+ V.clear();
+ appendValues(V, Values1);
+ V2.clear();
+ appendValues(V2, Values2);
+ }
+
void expectValues(const VectorT &V, ArrayRef<PtrT> Values) {
EXPECT_EQ(Values.empty(), V.empty());
EXPECT_EQ(Values.size(), V.size());
@@ -157,6 +164,165 @@ TYPED_TEST(TinyPtrVectorTest, CopyAndMoveCtorTest) {
#endif
}
+TYPED_TEST(TinyPtrVectorTest, CopyAndMoveTest) {
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(0));
+ this->expectValues(this->V2, this->testArray(0));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(0));
+#endif
+
+ this->setVectors(this->testArray(1), this->testArray(0));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(0));
+ this->expectValues(this->V2, this->testArray(0));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(1), this->testArray(0));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(0));
+#endif
+
+ this->setVectors(this->testArray(2), this->testArray(0));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(0));
+ this->expectValues(this->V2, this->testArray(0));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(2), this->testArray(0));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(0));
+#endif
+
+ this->setVectors(this->testArray(42), this->testArray(0));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(0));
+ this->expectValues(this->V2, this->testArray(0));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(42), this->testArray(0));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(0));
+#endif
+
+ this->setVectors(this->testArray(0), this->testArray(1));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(1));
+ this->expectValues(this->V2, this->testArray(1));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(0), this->testArray(1));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(1));
+#endif
+
+ this->setVectors(this->testArray(0), this->testArray(2));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(2));
+ this->expectValues(this->V2, this->testArray(2));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(0), this->testArray(2));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(2));
+#endif
+
+ this->setVectors(this->testArray(0), this->testArray(42));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(42));
+ this->expectValues(this->V2, this->testArray(42));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(0), this->testArray(42));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(42));
+#endif
+
+ this->setVectors(this->testArray(1), this->testArray(1));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(1));
+ this->expectValues(this->V2, this->testArray(1));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(1));
+#endif
+
+ this->setVectors(this->testArray(1), this->testArray(2));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(2));
+ this->expectValues(this->V2, this->testArray(2));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(1), this->testArray(2));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(2));
+#endif
+
+ this->setVectors(this->testArray(1), this->testArray(42));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(42));
+ this->expectValues(this->V2, this->testArray(42));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(1), this->testArray(42));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(42));
+#endif
+
+ this->setVectors(this->testArray(2), this->testArray(1));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(1));
+ this->expectValues(this->V2, this->testArray(1));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(2), this->testArray(1));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(1));
+#endif
+
+ this->setVectors(this->testArray(2), this->testArray(2));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(2));
+ this->expectValues(this->V2, this->testArray(2));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(2), this->testArray(2));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(2));
+#endif
+
+ this->setVectors(this->testArray(2), this->testArray(42));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(42));
+ this->expectValues(this->V2, this->testArray(42));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(2), this->testArray(42));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(42));
+#endif
+
+ this->setVectors(this->testArray(42), this->testArray(1));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(1));
+ this->expectValues(this->V2, this->testArray(1));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(42), this->testArray(1));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(1));
+#endif
+
+ this->setVectors(this->testArray(42), this->testArray(2));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(2));
+ this->expectValues(this->V2, this->testArray(2));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(42), this->testArray(2));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(2));
+#endif
+
+ this->setVectors(this->testArray(42), this->testArray(42));
+ this->V = this->V2;
+ this->expectValues(this->V, this->testArray(42));
+ this->expectValues(this->V2, this->testArray(42));
+#if LLVM_USE_RVALUE_REFERENCES
+ this->setVectors(this->testArray(42), this->testArray(42));
+ this->V = std::move(this->V2);
+ this->expectValues(this->V, this->testArray(42));
+#endif
+}
+
TYPED_TEST(TinyPtrVectorTest, EraseTest) {
this->appendValues(this->V, this->testArray(1));
this->expectValues(this->V, this->testArray(1));