140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//===- llvm/unittest/ADT/TinyPtrVectorTest.cpp ----------------------------===//
240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//
340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//                     The LLVM Compiler Infrastructure
440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//
540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth// This file is distributed under the University of Illinois Open Source
640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth// License. See LICENSE.TXT for details.
740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//
840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//===----------------------------------------------------------------------===//
940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//
1040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth// TinyPtrVector unit tests.
1140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//
1240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth//===----------------------------------------------------------------------===//
1340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
1440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include "gtest/gtest.h"
1540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include "llvm/ADT/ArrayRef.h"
1640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include "llvm/ADT/SmallVector.h"
1740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include "llvm/ADT/STLExtras.h"
1840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include "llvm/ADT/TinyPtrVector.h"
1940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include "llvm/Support/type_traits.h"
2040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include <algorithm>
2140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include <list>
2240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#include <vector>
2340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
2440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthusing namespace llvm;
2540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
2640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthnamespace {
2740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
2840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth// The world's worst RNG, but it is deterministic and makes it easy to get
2940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth// *some* shuffling of elements.
3040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthstatic ptrdiff_t test_shuffle_rng(ptrdiff_t i) {
3140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  return (i + i * 33) % i;
3240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
3340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthstatic ptrdiff_t (*test_shuffle_rng_p)(ptrdiff_t) = &test_shuffle_rng;
3440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
3540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthtemplate <typename VectorT>
3640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthclass TinyPtrVectorTest : public testing::Test {
3740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthprotected:
3840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  typedef typename VectorT::value_type PtrT;
3940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  typedef typename remove_pointer<PtrT>::type ValueT;
4040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
4140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  VectorT V;
4240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  VectorT V2;
4340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
4440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  ValueT TestValues[1024];
4540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  std::vector<PtrT> TestPtrs;
4640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
4740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  TinyPtrVectorTest() {
4840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    for (size_t i = 0, e = array_lengthof(TestValues); i != e; ++i)
4940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth      TestPtrs.push_back(&TestValues[i]);
5040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
5140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    std::random_shuffle(TestPtrs.begin(), TestPtrs.end(), test_shuffle_rng_p);
5240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  }
5340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
5440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  ArrayRef<PtrT> testArray(size_t N) {
5540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    return makeArrayRef(&TestPtrs[0], N);
5640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  }
5740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
5840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  void appendValues(VectorT &V, ArrayRef<PtrT> Values) {
5940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    for (size_t i = 0, e = Values.size(); i != e; ++i)
6040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth      V.push_back(Values[i]);
6140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  }
6240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
6306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  void setVectors(ArrayRef<PtrT> Values1, ArrayRef<PtrT> Values2) {
6406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth    V.clear();
6506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth    appendValues(V, Values1);
6606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth    V2.clear();
6706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth    appendValues(V2, Values2);
6806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  }
6906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
7040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  void expectValues(const VectorT &V, ArrayRef<PtrT> Values) {
7140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    EXPECT_EQ(Values.empty(), V.empty());
7240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    EXPECT_EQ(Values.size(), V.size());
7340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    for (size_t i = 0, e = Values.size(); i != e; ++i) {
7440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth      EXPECT_EQ(Values[i], V[i]);
7540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth      EXPECT_EQ(Values[i], *llvm::next(V.begin(), i));
7640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    }
7740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    EXPECT_EQ(V.end(), llvm::next(V.begin(), Values.size()));
7840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  }
7940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth};
8040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
8140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruthtypedef ::testing::Types<TinyPtrVector<int*>,
8240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth                         TinyPtrVector<double*>
8340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth                         > TinyPtrVectorTestTypes;
8440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler CarruthTYPED_TEST_CASE(TinyPtrVectorTest, TinyPtrVectorTestTypes);
8540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
8640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler CarruthTYPED_TEST(TinyPtrVectorTest, EmptyTest) {
8740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
8840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
8940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
9040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler CarruthTYPED_TEST(TinyPtrVectorTest, PushPopBack) {
9140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[0]);
9240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(1));
9340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[1]);
9440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(2));
9540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[2]);
9640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(3));
9740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[3]);
9840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(4));
9940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[4]);
10040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(5));
10140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
10240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  // Pop and clobber a few values to keep things interesting.
10340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
10440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(4));
10540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
10640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(3));
10740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs[3] = &this->TestValues[42];
10840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs[4] = &this->TestValues[43];
10940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[3]);
11040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(4));
11140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.push_back(this->TestPtrs[4]);
11240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(5));
11340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
11440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
11540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(4));
11640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
11740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(3));
11840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
11940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(2));
12040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
12140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(1));
12240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.pop_back();
12340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
12440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
12540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(this->V, this->testArray(42));
12640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(42));
12740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
12840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
12940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler CarruthTYPED_TEST(TinyPtrVectorTest, ClearTest) {
13040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
13140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.clear();
13240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
13340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
13440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(this->V, this->testArray(1));
13540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(1));
13640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.clear();
13740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
13840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
13940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(this->V, this->testArray(42));
14040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(42));
14140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.clear();
14240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
14340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
14440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
14540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler CarruthTYPED_TEST(TinyPtrVectorTest, CopyAndMoveCtorTest) {
14640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(this->V, this->testArray(42));
14740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  TypeParam Copy(this->V);
14840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(Copy, this->testArray(42));
14940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
15040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  // This is a separate copy, and so it shouldn't destroy the original.
15140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  Copy.clear();
15240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(Copy, this->testArray(0));
15340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(42));
15440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
15540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  TypeParam Copy2(this->V2);
15640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(Copy2, this->testArray(42));
15740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(Copy2, this->testArray(42));
15840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V2, this->testArray(0));
15940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
16040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
16140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  TypeParam Move(std::move(Copy2));
16240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(Move, this->testArray(42));
16340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(Copy2, this->testArray(0));
16440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth#endif
16540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
16640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
16706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler CarruthTYPED_TEST(TinyPtrVectorTest, CopyAndMoveTest) {
16806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
16906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
17006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(0));
17106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
17206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
17306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
17406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
17506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
17606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(0));
17706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
17806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
17906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(0));
18006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
18106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(0));
18206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
18306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
18406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
18506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
18606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(0));
18706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
18806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
18906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(0));
19006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
19106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(0));
19206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
19306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
19406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
19506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
19606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(0));
19706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
19806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
19906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(0));
20006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
20106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(0));
20206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
20306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(0));
20406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
20506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
20606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(0), this->testArray(1));
20706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
20806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
20906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(1));
21006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
21106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(0), this->testArray(1));
21206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
21306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
21406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
21506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
21606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(0), this->testArray(2));
21706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
21806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
21906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(2));
22006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
22106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(0), this->testArray(2));
22206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
22306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
22406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
22506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
22606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(0), this->testArray(42));
22706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
22806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
22906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(42));
23006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
23106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(0), this->testArray(42));
23206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
23306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
23406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
23506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
23606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(1));
23706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
23806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
23906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(1));
24006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
24106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
24206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
24306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
24406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
24506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(2));
24606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
24706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
24806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(2));
24906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
25006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(2));
25106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
25206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
25306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
25406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
25506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(42));
25606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
25706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
25806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(42));
25906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
26006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(1), this->testArray(42));
26106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
26206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
26306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
26406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
26506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(1));
26606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
26706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
26806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(1));
26906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
27006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(1));
27106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
27206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
27306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
27406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
27506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(2));
27606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
27706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
27806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(2));
27906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
28006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(2));
28106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
28206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
28306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
28406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
28506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(42));
28606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
28706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
28806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(42));
28906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
29006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(2), this->testArray(42));
29106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
29206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
29306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
29406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
29506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(1));
29606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
29706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
29806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(1));
29906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
30006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(1));
30106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
30206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(1));
30306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
30406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
30506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(2));
30606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
30706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
30806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(2));
30906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
31006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(2));
31106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
31206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(2));
31306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
31406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
31506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(42));
31606bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = this->V2;
31706bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
31806bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V2, this->testArray(42));
31906bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#if LLVM_USE_RVALUE_REFERENCES
32006bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->setVectors(this->testArray(42), this->testArray(42));
32106bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->V = std::move(this->V2);
32206bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth  this->expectValues(this->V, this->testArray(42));
32306bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth#endif
32406bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth}
32506bd8ca8c276d9bc20b192188224e1e5215666a0Chandler Carruth
32640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler CarruthTYPED_TEST(TinyPtrVectorTest, EraseTest) {
32740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(this->V, this->testArray(1));
32840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(1));
32940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.erase(this->V.begin());
33040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
33140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
33240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->appendValues(this->V, this->testArray(42));
33340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(42));
33440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.erase(this->V.begin());
33540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs.erase(this->TestPtrs.begin());
33640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(41));
33740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 1));
33840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1));
33940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(40));
34040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 2));
34140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2));
34240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(39));
34340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 5));
34440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5));
34540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(38));
34640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 13));
34740dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13));
34840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(37));
34940dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
35040dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  typename TypeParam::iterator I = this->V.begin();
35140dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  do {
35240dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth    I = this->V.erase(I);
35340dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  } while (I != this->V.end());
35440dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth  this->expectValues(this->V, this->testArray(0));
35540dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
35640dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth
357147d9e05116518461653695a6022f6109f0eb936Chandler CarruthTYPED_TEST(TinyPtrVectorTest, EraseRangeTest) {
358147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->appendValues(this->V, this->testArray(1));
359147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(1));
360147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(this->V.begin(), this->V.begin());
361147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(1));
362147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(this->V.end(), this->V.end());
363147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(1));
364147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(this->V.begin(), this->V.end());
365147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(0));
366147d9e05116518461653695a6022f6109f0eb936Chandler Carruth
367147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->appendValues(this->V, this->testArray(42));
368147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(42));
369147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(this->V.begin(), llvm::next(this->V.begin(), 1));
370147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.erase(this->TestPtrs.begin(),
371147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                       llvm::next(this->TestPtrs.begin(), 1));
372147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(41));
373147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 1), llvm::next(this->V.begin(), 2));
374147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1),
375147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                       llvm::next(this->TestPtrs.begin(), 2));
376147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(40));
377147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 2), llvm::next(this->V.begin(), 4));
378147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2),
379147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                       llvm::next(this->TestPtrs.begin(), 4));
380147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(38));
381147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 5), llvm::next(this->V.begin(), 10));
382147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5),
383147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                       llvm::next(this->TestPtrs.begin(), 10));
384147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(33));
385147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 13), llvm::next(this->V.begin(), 26));
386147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13),
387147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                       llvm::next(this->TestPtrs.begin(), 26));
388147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(20));
389147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 7), this->V.end());
390147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(7));
391147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(this->V.begin(), this->V.end());
392147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(0));
393147d9e05116518461653695a6022f6109f0eb936Chandler Carruth}
394147d9e05116518461653695a6022f6109f0eb936Chandler Carruth
395147d9e05116518461653695a6022f6109f0eb936Chandler CarruthTYPED_TEST(TinyPtrVectorTest, Insert) {
396147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs[0]);
397147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(1));
398147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.clear();
399147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->appendValues(this->V, this->testArray(4));
400147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(4));
401147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs[4]);
402147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(5));
403147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.begin(), this->TestPtrs[42]);
404147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.insert(this->TestPtrs.begin(), this->TestPtrs[42]);
405147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(6));
406147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(llvm::next(this->V.begin(), 3), this->TestPtrs[43]);
407147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->TestPtrs.insert(llvm::next(this->TestPtrs.begin(), 3),
408147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                        this->TestPtrs[43]);
409147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(7));
410147d9e05116518461653695a6022f6109f0eb936Chandler Carruth}
411147d9e05116518461653695a6022f6109f0eb936Chandler Carruth
412147d9e05116518461653695a6022f6109f0eb936Chandler CarruthTYPED_TEST(TinyPtrVectorTest, InsertRange) {
413147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs.begin(), this->TestPtrs.begin());
414147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(0));
415147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.begin(), this->TestPtrs.begin(),
416147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 this->TestPtrs.begin());
417147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(0));
418147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs.end(), this->TestPtrs.end());
419147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(0));
420147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs.begin(),
421147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin()));
422147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(1));
423147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.clear();
424147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs.begin(),
425147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 2));
426147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(2));
427147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.clear();
428147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(), this->TestPtrs.begin(),
429147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 42));
430147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(42));
431147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.clear();
432147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.end(),
433147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 5),
434147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 13));
435147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(this->V.begin(),
436147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 0),
437147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 3));
438147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(llvm::next(this->V.begin(), 2),
439147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 2),
440147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 4));
441147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.erase(llvm::next(this->V.begin(), 4));
442147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->V.insert(llvm::next(this->V.begin(), 4),
443147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 4),
444147d9e05116518461653695a6022f6109f0eb936Chandler Carruth                 llvm::next(this->TestPtrs.begin(), 5));
445147d9e05116518461653695a6022f6109f0eb936Chandler Carruth  this->expectValues(this->V, this->testArray(13));
446147d9e05116518461653695a6022f6109f0eb936Chandler Carruth}
447147d9e05116518461653695a6022f6109f0eb936Chandler Carruth
44840dab1059e72d3af59f2523fa8a7d05f40dafca5Chandler Carruth}
449