summaryrefslogtreecommitdiffstats
path: root/unittests/ADT
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ADT')
-rw-r--r--unittests/ADT/APIntTest.cpp28
-rw-r--r--unittests/ADT/BitVectorTest.cpp68
-rw-r--r--unittests/ADT/CMakeLists.txt33
-rw-r--r--unittests/ADT/DenseMapTest.cpp295
-rw-r--r--unittests/ADT/HashingTest.cpp2
-rw-r--r--unittests/ADT/SmallBitVectorTest.cpp196
-rw-r--r--unittests/ADT/SmallVectorTest.cpp329
-rw-r--r--unittests/ADT/SparseSetTest.cpp2
-rw-r--r--unittests/ADT/StringMapTest.cpp28
-rw-r--r--unittests/ADT/StringRefTest.cpp28
-rw-r--r--unittests/ADT/TinyPtrVectorTest.cpp448
-rw-r--r--unittests/ADT/TripleTest.cpp77
12 files changed, 1090 insertions, 444 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 89b8aa9..49d7e70 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -171,6 +171,34 @@ TEST(APIntTest, i1) {
EXPECT_EQ(zero, neg_one.srem(one));
EXPECT_EQ(zero, neg_one.urem(one));
EXPECT_EQ(zero, one.srem(neg_one));
+
+ // sdivrem
+ {
+ APInt q(8, 0);
+ APInt r(8, 0);
+ APInt one(8, 1);
+ APInt two(8, 2);
+ APInt nine(8, 9);
+ APInt four(8, 4);
+
+ EXPECT_EQ(nine.srem(two), one);
+ EXPECT_EQ(nine.srem(-two), one);
+ EXPECT_EQ((-nine).srem(two), -one);
+ EXPECT_EQ((-nine).srem(-two), -one);
+
+ APInt::sdivrem(nine, two, q, r);
+ EXPECT_EQ(four, q);
+ EXPECT_EQ(one, r);
+ APInt::sdivrem(-nine, two, q, r);
+ EXPECT_EQ(-four, q);
+ EXPECT_EQ(-one, r);
+ APInt::sdivrem(nine, -two, q, r);
+ EXPECT_EQ(-four, q);
+ EXPECT_EQ(one, r);
+ APInt::sdivrem(-nine, -two, q, r);
+ EXPECT_EQ(four, q);
+ EXPECT_EQ(-one, r);
+ }
}
TEST(APIntTest, fromString) {
diff --git a/unittests/ADT/BitVectorTest.cpp b/unittests/ADT/BitVectorTest.cpp
index f733e13..d836036 100644
--- a/unittests/ADT/BitVectorTest.cpp
+++ b/unittests/ADT/BitVectorTest.cpp
@@ -11,14 +11,23 @@
#ifndef __ppc__
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/SmallBitVector.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
-TEST(BitVectorTest, TrivialOperation) {
- BitVector Vec;
+// Test fixture
+template <typename T>
+class BitVectorTest : public ::testing::Test { };
+
+// Test both BitVector and SmallBitVector with the same suite of tests.
+typedef ::testing::Types<BitVector, SmallBitVector> BitVectorTestTypes;
+TYPED_TEST_CASE(BitVectorTest, BitVectorTestTypes);
+
+TYPED_TEST(BitVectorTest, TrivialOperation) {
+ TypeParam Vec;
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(0U, Vec.size());
EXPECT_FALSE(Vec.any());
@@ -42,7 +51,8 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_FALSE(Vec.none());
EXPECT_FALSE(Vec.empty());
- BitVector Inv = ~Vec;
+ TypeParam Inv = Vec;
+ Inv.flip();
EXPECT_EQ(6U, Inv.count());
EXPECT_EQ(11U, Inv.size());
EXPECT_TRUE(Inv.any());
@@ -52,7 +62,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_FALSE(Inv == Vec);
EXPECT_TRUE(Inv != Vec);
- Vec = ~Vec;
+ Vec.flip();
EXPECT_TRUE(Inv == Vec);
EXPECT_FALSE(Inv != Vec);
@@ -76,8 +86,8 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_FALSE(Vec[56]);
Vec.resize(61, false);
- BitVector Copy = Vec;
- BitVector Alt(3, false);
+ TypeParam Copy = Vec;
+ TypeParam Alt(3, false);
Alt.resize(6, true);
std::swap(Alt, Vec);
EXPECT_TRUE(Copy == Alt);
@@ -131,7 +141,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_TRUE(Vec.none());
EXPECT_FALSE(Vec.empty());
- Inv = ~BitVector();
+ Inv = TypeParam().flip();
EXPECT_EQ(0U, Inv.count());
EXPECT_EQ(0U, Inv.size());
EXPECT_FALSE(Inv.any());
@@ -148,13 +158,13 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_TRUE(Vec.empty());
}
-TEST(BitVectorTest, CompoundAssignment) {
- BitVector A;
+TYPED_TEST(BitVectorTest, CompoundAssignment) {
+ TypeParam A;
A.resize(10);
A.set(4);
A.set(7);
- BitVector B;
+ TypeParam B;
B.resize(50);
B.set(5);
B.set(18);
@@ -187,8 +197,8 @@ TEST(BitVectorTest, CompoundAssignment) {
EXPECT_EQ(100U, A.size());
}
-TEST(BitVectorTest, ProxyIndex) {
- BitVector Vec(3);
+TYPED_TEST(BitVectorTest, ProxyIndex) {
+ TypeParam Vec(3);
EXPECT_TRUE(Vec.none());
Vec[0] = Vec[1] = Vec[2] = true;
EXPECT_EQ(Vec.size(), Vec.count());
@@ -196,8 +206,8 @@ TEST(BitVectorTest, ProxyIndex) {
EXPECT_TRUE(Vec.none());
}
-TEST(BitVectorTest, PortableBitMask) {
- BitVector A;
+TYPED_TEST(BitVectorTest, PortableBitMask) {
+ TypeParam A;
const uint32_t Mask1[] = { 0x80000000, 6, 5 };
A.resize(10);
@@ -242,6 +252,34 @@ TEST(BitVectorTest, PortableBitMask) {
A.clearBitsNotInMask(Mask1, 1);
EXPECT_EQ(64-4u, A.count());
}
-}
+TYPED_TEST(BitVectorTest, BinOps) {
+ TypeParam A;
+ TypeParam B;
+
+ A.resize(65);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(B));
+
+ B.resize(64);
+ A.set(64);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(A));
+
+ B.set(63);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(A));
+
+ A.set(63);
+ EXPECT_TRUE(A.anyCommon(B));
+ EXPECT_TRUE(B.anyCommon(A));
+
+ B.resize(70);
+ B.set(64);
+ B.reset(63);
+ A.resize(64);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(A));
+}
+}
#endif
diff --git a/unittests/ADT/CMakeLists.txt b/unittests/ADT/CMakeLists.txt
new file mode 100644
index 0000000..d272b09
--- /dev/null
+++ b/unittests/ADT/CMakeLists.txt
@@ -0,0 +1,33 @@
+set(LLVM_LINK_COMPONENTS
+ Support
+ )
+
+add_llvm_unittest(ADTTests
+ APFloatTest.cpp
+ APIntTest.cpp
+ BitVectorTest.cpp
+ DAGDeltaAlgorithmTest.cpp
+ DeltaAlgorithmTest.cpp
+ DenseMapTest.cpp
+ DenseSetTest.cpp
+ FoldingSet.cpp
+ HashingTest.cpp
+ ilistTest.cpp
+ ImmutableSetTest.cpp
+ IntEqClassesTest.cpp
+ IntervalMapTest.cpp
+ IntrusiveRefCntPtrTest.cpp
+ PackedVectorTest.cpp
+ SCCIteratorTest.cpp
+ SmallPtrSetTest.cpp
+ SmallStringTest.cpp
+ SmallVectorTest.cpp
+ SparseBitVectorTest.cpp
+ SparseSetTest.cpp
+ StringMapTest.cpp
+ StringRefTest.cpp
+ TinyPtrVectorTest.cpp
+ TripleTest.cpp
+ TwineTest.cpp
+ VariadicFunctionTest.cpp
+ )
diff --git a/unittests/ADT/DenseMapTest.cpp b/unittests/ADT/DenseMapTest.cpp
index e0ee778..75e7006 100644
--- a/unittests/ADT/DenseMapTest.cpp
+++ b/unittests/ADT/DenseMapTest.cpp
@@ -9,170 +9,283 @@
#include "gtest/gtest.h"
#include "llvm/ADT/DenseMap.h"
+#include <map>
+#include <set>
using namespace llvm;
namespace {
-// Test fixture
-class DenseMapTest : public testing::Test {
-protected:
- DenseMap<uint32_t, uint32_t> uintMap;
- DenseMap<uint32_t *, uint32_t *> uintPtrMap;
- uint32_t dummyInt;
+uint32_t getTestKey(int i, uint32_t *) { return i; }
+uint32_t getTestValue(int i, uint32_t *) { return 42 + i; }
+
+uint32_t *getTestKey(int i, uint32_t **) {
+ static uint32_t dummy_arr1[8192];
+ assert(i < 8192 && "Only support 8192 dummy keys.");
+ return &dummy_arr1[i];
+}
+uint32_t *getTestValue(int i, uint32_t **) {
+ static uint32_t dummy_arr1[8192];
+ assert(i < 8192 && "Only support 8192 dummy keys.");
+ return &dummy_arr1[i];
+}
+
+/// \brief A test class that tries to check that construction and destruction
+/// occur correctly.
+class CtorTester {
+ static std::set<CtorTester *> Constructed;
+ int Value;
+
+public:
+ explicit CtorTester(int Value = 0) : Value(Value) {
+ EXPECT_TRUE(Constructed.insert(this).second);
+ }
+ CtorTester(uint32_t Value) : Value(Value) {
+ EXPECT_TRUE(Constructed.insert(this).second);
+ }
+ CtorTester(const CtorTester &Arg) : Value(Arg.Value) {
+ EXPECT_TRUE(Constructed.insert(this).second);
+ }
+ ~CtorTester() {
+ EXPECT_EQ(1u, Constructed.erase(this));
+ }
+ operator uint32_t() const { return Value; }
+
+ int getValue() const { return Value; }
+ bool operator==(const CtorTester &RHS) const { return Value == RHS.Value; }
};
-// Empty map tests
-TEST_F(DenseMapTest, EmptyIntMapTest) {
- // Size tests
- EXPECT_EQ(0u, uintMap.size());
- EXPECT_TRUE(uintMap.empty());
+std::set<CtorTester *> CtorTester::Constructed;
- // Iterator tests
- EXPECT_TRUE(uintMap.begin() == uintMap.end());
+struct CtorTesterMapInfo {
+ static inline CtorTester getEmptyKey() { return CtorTester(-1); }
+ static inline CtorTester getTombstoneKey() { return CtorTester(-2); }
+ static unsigned getHashValue(const CtorTester &Val) {
+ return Val.getValue() * 37u;
+ }
+ static bool isEqual(const CtorTester &LHS, const CtorTester &RHS) {
+ return LHS == RHS;
+ }
+};
- // Lookup tests
- EXPECT_FALSE(uintMap.count(0u));
- EXPECT_TRUE(uintMap.find(0u) == uintMap.end());
- EXPECT_EQ(0u, uintMap.lookup(0u));
-}
+CtorTester getTestKey(int i, CtorTester *) { return CtorTester(i); }
+CtorTester getTestValue(int i, CtorTester *) { return CtorTester(42 + i); }
+
+// Test fixture, with helper functions implemented by forwarding to global
+// function overloads selected by component types of the type parameter. This
+// allows all of the map implementations to be tested with shared
+// implementations of helper routines.
+template <typename T>
+class DenseMapTest : public ::testing::Test {
+protected:
+ T Map;
+
+ static typename T::key_type *const dummy_key_ptr;
+ static typename T::mapped_type *const dummy_value_ptr;
+
+ typename T::key_type getKey(int i = 0) {
+ return getTestKey(i, dummy_key_ptr);
+ }
+ typename T::mapped_type getValue(int i = 0) {
+ return getTestValue(i, dummy_value_ptr);
+ }
+};
-// Empty map tests for pointer map
-TEST_F(DenseMapTest, EmptyPtrMapTest) {
+template <typename T>
+typename T::key_type *const DenseMapTest<T>::dummy_key_ptr = 0;
+template <typename T>
+typename T::mapped_type *const DenseMapTest<T>::dummy_value_ptr = 0;
+
+// Register these types for testing.
+typedef ::testing::Types<DenseMap<uint32_t, uint32_t>,
+ DenseMap<uint32_t *, uint32_t *>,
+ DenseMap<CtorTester, CtorTester, CtorTesterMapInfo>,
+ SmallDenseMap<uint32_t, uint32_t>,
+ SmallDenseMap<uint32_t *, uint32_t *>,
+ SmallDenseMap<CtorTester, CtorTester, 4,
+ CtorTesterMapInfo>
+ > DenseMapTestTypes;
+TYPED_TEST_CASE(DenseMapTest, DenseMapTestTypes);
+
+// Empty map tests
+TYPED_TEST(DenseMapTest, EmptyIntMapTest) {
// Size tests
- EXPECT_EQ(0u, uintPtrMap.size());
- EXPECT_TRUE(uintPtrMap.empty());
+ EXPECT_EQ(0u, this->Map.size());
+ EXPECT_TRUE(this->Map.empty());
// Iterator tests
- EXPECT_TRUE(uintPtrMap.begin() == uintPtrMap.end());
+ EXPECT_TRUE(this->Map.begin() == this->Map.end());
// Lookup tests
- EXPECT_FALSE(uintPtrMap.count(&dummyInt));
- EXPECT_TRUE(uintPtrMap.find(&dummyInt) == uintPtrMap.begin());
- EXPECT_EQ(0, uintPtrMap.lookup(&dummyInt));
+ EXPECT_FALSE(this->Map.count(this->getKey()));
+ EXPECT_TRUE(this->Map.find(this->getKey()) == this->Map.end());
+#ifndef _MSC_VER
+ EXPECT_EQ(typename TypeParam::mapped_type(),
+ this->Map.lookup(this->getKey()));
+#else
+ // MSVC, at least old versions, cannot parse the typename to disambiguate
+ // TypeParam::mapped_type as a type. However, because MSVC doesn't implement
+ // two-phase name lookup, it also doesn't require the typename. Deal with
+ // this mutual incompatibility through specialized code.
+ EXPECT_EQ(TypeParam::mapped_type(),
+ this->Map.lookup(this->getKey()));
+#endif
}
// Constant map tests
-TEST_F(DenseMapTest, ConstEmptyMapTest) {
- const DenseMap<uint32_t, uint32_t> & constUintMap = uintMap;
- const DenseMap<uint32_t *, uint32_t *> & constUintPtrMap = uintPtrMap;
- EXPECT_EQ(0u, constUintMap.size());
- EXPECT_EQ(0u, constUintPtrMap.size());
- EXPECT_TRUE(constUintMap.empty());
- EXPECT_TRUE(constUintPtrMap.empty());
- EXPECT_TRUE(constUintMap.begin() == constUintMap.end());
- EXPECT_TRUE(constUintPtrMap.begin() == constUintPtrMap.end());
+TYPED_TEST(DenseMapTest, ConstEmptyMapTest) {
+ const TypeParam &ConstMap = this->Map;
+ EXPECT_EQ(0u, ConstMap.size());
+ EXPECT_TRUE(ConstMap.empty());
+ EXPECT_TRUE(ConstMap.begin() == ConstMap.end());
}
// A map with a single entry
-TEST_F(DenseMapTest, SingleEntryMapTest) {
- uintMap[0] = 1;
+TYPED_TEST(DenseMapTest, SingleEntryMapTest) {
+ this->Map[this->getKey()] = this->getValue();
// Size tests
- EXPECT_EQ(1u, uintMap.size());
- EXPECT_FALSE(uintMap.begin() == uintMap.end());
- EXPECT_FALSE(uintMap.empty());
+ EXPECT_EQ(1u, this->Map.size());
+ EXPECT_FALSE(this->Map.begin() == this->Map.end());
+ EXPECT_FALSE(this->Map.empty());
// Iterator tests
- DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin();
- EXPECT_EQ(0u, it->first);
- EXPECT_EQ(1u, it->second);
+ typename TypeParam::iterator it = this->Map.begin();
+ EXPECT_EQ(this->getKey(), it->first);
+ EXPECT_EQ(this->getValue(), it->second);
++it;
- EXPECT_TRUE(it == uintMap.end());
+ EXPECT_TRUE(it == this->Map.end());
// Lookup tests
- EXPECT_TRUE(uintMap.count(0u));
- EXPECT_TRUE(uintMap.find(0u) == uintMap.begin());
- EXPECT_EQ(1u, uintMap.lookup(0u));
- EXPECT_EQ(1u, uintMap[0]);
+ EXPECT_TRUE(this->Map.count(this->getKey()));
+ EXPECT_TRUE(this->Map.find(this->getKey()) == this->Map.begin());
+ EXPECT_EQ(this->getValue(), this->Map.lookup(this->getKey()));
+ EXPECT_EQ(this->getValue(), this->Map[this->getKey()]);
}
// Test clear() method
-TEST_F(DenseMapTest, ClearTest) {
- uintMap[0] = 1;
- uintMap.clear();
+TYPED_TEST(DenseMapTest, ClearTest) {
+ this->Map[this->getKey()] = this->getValue();
+ this->Map.clear();
- EXPECT_EQ(0u, uintMap.size());
- EXPECT_TRUE(uintMap.empty());
- EXPECT_TRUE(uintMap.begin() == uintMap.end());
+ EXPECT_EQ(0u, this->Map.size());
+ EXPECT_TRUE(this->Map.empty());
+ EXPECT_TRUE(this->Map.begin() == this->Map.end());
}
// Test erase(iterator) method
-TEST_F(DenseMapTest, EraseTest) {
- uintMap[0] = 1;
- uintMap.erase(uintMap.begin());
+TYPED_TEST(DenseMapTest, EraseTest) {
+ this->Map[this->getKey()] = this->getValue();
+ this->Map.erase(this->Map.begin());
- EXPECT_EQ(0u, uintMap.size());
- EXPECT_TRUE(uintMap.empty());
- EXPECT_TRUE(uintMap.begin() == uintMap.end());
+ EXPECT_EQ(0u, this->Map.size());
+ EXPECT_TRUE(this->Map.empty());
+ EXPECT_TRUE(this->Map.begin() == this->Map.end());
}
// Test erase(value) method
-TEST_F(DenseMapTest, EraseTest2) {
- uintMap[0] = 1;
- uintMap.erase(0);
+TYPED_TEST(DenseMapTest, EraseTest2) {
+ this->Map[this->getKey()] = this->getValue();
+ this->Map.erase(this->getKey());
- EXPECT_EQ(0u, uintMap.size());
- EXPECT_TRUE(uintMap.empty());
- EXPECT_TRUE(uintMap.begin() == uintMap.end());
+ EXPECT_EQ(0u, this->Map.size());
+ EXPECT_TRUE(this->Map.empty());
+ EXPECT_TRUE(this->Map.begin() == this->Map.end());
}
// Test insert() method
-TEST_F(DenseMapTest, InsertTest) {
- uintMap.insert(std::make_pair(0u, 1u));
- EXPECT_EQ(1u, uintMap.size());
- EXPECT_EQ(1u, uintMap[0]);
+TYPED_TEST(DenseMapTest, InsertTest) {
+ this->Map.insert(std::make_pair(this->getKey(), this->getValue()));
+ EXPECT_EQ(1u, this->Map.size());
+ EXPECT_EQ(this->getValue(), this->Map[this->getKey()]);
}
// Test copy constructor method
-TEST_F(DenseMapTest, CopyConstructorTest) {
- uintMap[0] = 1;
- DenseMap<uint32_t, uint32_t> copyMap(uintMap);
+TYPED_TEST(DenseMapTest, CopyConstructorTest) {
+ this->Map[this->getKey()] = this->getValue();
+ TypeParam copyMap(this->Map);
EXPECT_EQ(1u, copyMap.size());
- EXPECT_EQ(1u, copyMap[0]);
+ EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
}
// Test assignment operator method
-TEST_F(DenseMapTest, AssignmentTest) {
- uintMap[0] = 1;
- DenseMap<uint32_t, uint32_t> copyMap = uintMap;
+TYPED_TEST(DenseMapTest, AssignmentTest) {
+ this->Map[this->getKey()] = this->getValue();
+ TypeParam copyMap = this->Map;
EXPECT_EQ(1u, copyMap.size());
- EXPECT_EQ(1u, copyMap[0]);
+ EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
+}
+
+// Test swap method
+TYPED_TEST(DenseMapTest, SwapTest) {
+ this->Map[this->getKey()] = this->getValue();
+ TypeParam otherMap;
+
+ this->Map.swap(otherMap);
+ EXPECT_EQ(0u, this->Map.size());
+ EXPECT_TRUE(this->Map.empty());
+ EXPECT_EQ(1u, otherMap.size());
+ EXPECT_EQ(this->getValue(), otherMap[this->getKey()]);
+
+ this->Map.swap(otherMap);
+ EXPECT_EQ(0u, otherMap.size());
+ EXPECT_TRUE(otherMap.empty());
+ EXPECT_EQ(1u, this->Map.size());
+ EXPECT_EQ(this->getValue(), this->Map[this->getKey()]);
+
+ // Make this more interesting by inserting 100 numbers into the map.
+ for (int i = 0; i < 100; ++i)
+ this->Map[this->getKey(i)] = this->getValue(i);
+
+ this->Map.swap(otherMap);
+ EXPECT_EQ(0u, this->Map.size());
+ EXPECT_TRUE(this->Map.empty());
+ EXPECT_EQ(100u, otherMap.size());
+ for (int i = 0; i < 100; ++i)
+ EXPECT_EQ(this->getValue(i), otherMap[this->getKey(i)]);
+
+ this->Map.swap(otherMap);
+ EXPECT_EQ(0u, otherMap.size());
+ EXPECT_TRUE(otherMap.empty());
+ EXPECT_EQ(100u, this->Map.size());
+ for (int i = 0; i < 100; ++i)
+ EXPECT_EQ(this->getValue(i), this->Map[this->getKey(i)]);
}
// A more complex iteration test
-TEST_F(DenseMapTest, IterationTest) {
+TYPED_TEST(DenseMapTest, IterationTest) {
bool visited[100];
+ std::map<typename TypeParam::key_type, unsigned> visitedIndex;
// Insert 100 numbers into the map
for (int i = 0; i < 100; ++i) {
visited[i] = false;
- uintMap[i] = 3;
+ visitedIndex[this->getKey(i)] = i;
+
+ this->Map[this->getKey(i)] = this->getValue(i);
}
// Iterate over all numbers and mark each one found.
- for (DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin();
- it != uintMap.end(); ++it) {
- visited[it->first] = true;
- }
+ for (typename TypeParam::iterator it = this->Map.begin();
+ it != this->Map.end(); ++it)
+ visited[visitedIndex[it->first]] = true;
// Ensure every number was visited.
- for (int i = 0; i < 100; ++i) {
+ for (int i = 0; i < 100; ++i)
ASSERT_TRUE(visited[i]) << "Entry #" << i << " was never visited";
- }
}
// const_iterator test
-TEST_F(DenseMapTest, ConstIteratorTest) {
+TYPED_TEST(DenseMapTest, ConstIteratorTest) {
// Check conversion from iterator to const_iterator.
- DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin();
- DenseMap<uint32_t, uint32_t>::const_iterator cit(it);
+ typename TypeParam::iterator it = this->Map.begin();
+ typename TypeParam::const_iterator cit(it);
EXPECT_TRUE(it == cit);
// Check copying of const_iterators.
- DenseMap<uint32_t, uint32_t>::const_iterator cit2(cit);
+ typename TypeParam::const_iterator cit2(cit);
EXPECT_TRUE(cit == cit2);
}
@@ -194,7 +307,7 @@ struct TestDenseMapInfo {
};
// find_as() tests
-TEST_F(DenseMapTest, FindAsTest) {
+TEST(DenseMapCustomTest, FindAsTest) {
DenseMap<unsigned, unsigned, TestDenseMapInfo> map;
map[0] = 1;
map[1] = 2;
diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp
index b148f14..1b3d061 100644
--- a/unittests/ADT/HashingTest.cpp
+++ b/unittests/ADT/HashingTest.cpp
@@ -345,7 +345,7 @@ TEST(HashingTest, HashCombineBasicTest) {
EXPECT_EQ(hash_combine_range(arr1, arr1 + 6),
hash_combine(i1, i2, i3, i4, i5, i6));
- // Hashing a sequence of heterogenous types which *happen* to all produce the
+ // Hashing a sequence of heterogeneous types which *happen* to all produce the
// same data for hashing produces the same as a range-based hash of the
// fundamental values.
const size_t s1 = 1024, s2 = 8888, s3 = 9000000;
diff --git a/unittests/ADT/SmallBitVectorTest.cpp b/unittests/ADT/SmallBitVectorTest.cpp
deleted file mode 100644
index c4dda9e..0000000
--- a/unittests/ADT/SmallBitVectorTest.cpp
+++ /dev/null
@@ -1,196 +0,0 @@
-//===- llvm/unittest/ADT/SmallBitVectorTest.cpp - SmallBitVector tests ----===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/SmallBitVector.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-namespace {
-
-TEST(SmallBitVectorTest, TrivialOperation) {
- SmallBitVector Vec;
- EXPECT_EQ(0U, Vec.count());
- EXPECT_EQ(0U, Vec.size());
- EXPECT_FALSE(Vec.any());
- EXPECT_TRUE(Vec.all());
- EXPECT_TRUE(Vec.none());
- EXPECT_TRUE(Vec.empty());
-
- Vec.resize(5, true);
- EXPECT_EQ(5U, Vec.count());
- EXPECT_EQ(5U, Vec.size());
- EXPECT_TRUE(Vec.any());
- EXPECT_TRUE(Vec.all());
- EXPECT_FALSE(Vec.none());
- EXPECT_FALSE(Vec.empty());
-
- Vec.resize(11);
- EXPECT_EQ(5U, Vec.count());
- EXPECT_EQ(11U, Vec.size());
- EXPECT_TRUE(Vec.any());
- EXPECT_FALSE(Vec.all());
- EXPECT_FALSE(Vec.none());
- EXPECT_FALSE(Vec.empty());
-
- SmallBitVector Inv = ~Vec;
- EXPECT_EQ(6U, Inv.count());
- EXPECT_EQ(11U, Inv.size());
- EXPECT_TRUE(Inv.any());
- EXPECT_FALSE(Inv.all());
- EXPECT_FALSE(Inv.none());
- EXPECT_FALSE(Inv.empty());
-
- EXPECT_FALSE(Inv == Vec);
- EXPECT_TRUE(Inv != Vec);
- Vec = ~Vec;
- EXPECT_TRUE(Inv == Vec);
- EXPECT_FALSE(Inv != Vec);
-
- // Add some "interesting" data to Vec.
- Vec.resize(23, true);
- Vec.resize(25, false);
- Vec.resize(26, true);
- Vec.resize(29, false);
- Vec.resize(33, true);
- Vec.resize(57, false);
- unsigned Count = 0;
- for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
- ++Count;
- EXPECT_TRUE(Vec[i]);
- EXPECT_TRUE(Vec.test(i));
- }
- EXPECT_EQ(Count, Vec.count());
- EXPECT_EQ(Count, 23u);
- EXPECT_FALSE(Vec[0]);
- EXPECT_TRUE(Vec[32]);
- EXPECT_FALSE(Vec[56]);
- Vec.resize(61, false);
-
- SmallBitVector Copy = Vec;
- SmallBitVector Alt(3, false);
- Alt.resize(6, true);
- std::swap(Alt, Vec);
- EXPECT_TRUE(Copy == Alt);
- EXPECT_TRUE(Vec.size() == 6);
- EXPECT_TRUE(Vec.count() == 3);
- EXPECT_TRUE(Vec.find_first() == 3);
- std::swap(Copy, Vec);
-
- // Add some more "interesting" data.
- Vec.resize(68, true);
- Vec.resize(78, false);
- Vec.resize(89, true);
- Vec.resize(90, false);
- Vec.resize(91, true);
- Vec.resize(130, false);
- Count = 0;
- for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
- ++Count;
- EXPECT_TRUE(Vec[i]);
- EXPECT_TRUE(Vec.test(i));
- }
- EXPECT_EQ(Count, Vec.count());
- EXPECT_EQ(Count, 42u);
- EXPECT_FALSE(Vec[0]);
- EXPECT_TRUE(Vec[32]);
- EXPECT_FALSE(Vec[60]);
- EXPECT_FALSE(Vec[129]);
-
- Vec.flip(60);
- EXPECT_TRUE(Vec[60]);
- EXPECT_EQ(Count + 1, Vec.count());
- Vec.flip(60);
- EXPECT_FALSE(Vec[60]);
- EXPECT_EQ(Count, Vec.count());
-
- Vec.reset(32);
- EXPECT_FALSE(Vec[32]);
- EXPECT_EQ(Count - 1, Vec.count());
- Vec.set(32);
- EXPECT_TRUE(Vec[32]);
- EXPECT_EQ(Count, Vec.count());
-
- Vec.flip();
- EXPECT_EQ(Vec.size() - Count, Vec.count());
-
- Vec.reset();
- EXPECT_EQ(0U, Vec.count());
- EXPECT_EQ(130U, Vec.size());
- EXPECT_FALSE(Vec.any());
- EXPECT_FALSE(Vec.all());
- EXPECT_TRUE(Vec.none());
- EXPECT_FALSE(Vec.empty());
-
- Inv = ~SmallBitVector();
- EXPECT_EQ(0U, Inv.count());
- EXPECT_EQ(0U, Inv.size());
- EXPECT_FALSE(Inv.any());
- EXPECT_TRUE(Inv.all());
- EXPECT_TRUE(Inv.none());
- EXPECT_TRUE(Inv.empty());
-
- Vec.clear();
- EXPECT_EQ(0U, Vec.count());
- EXPECT_EQ(0U, Vec.size());
- EXPECT_FALSE(Vec.any());
- EXPECT_TRUE(Vec.all());
- EXPECT_TRUE(Vec.none());
- EXPECT_TRUE(Vec.empty());
-}
-
-TEST(SmallBitVectorTest, CompoundAssignment) {
- SmallBitVector A;
- A.resize(10);
- A.set(4);
- A.set(7);
-
- SmallBitVector B;
- B.resize(50);
- B.set(5);
- B.set(18);
-
- A |= B;
- EXPECT_TRUE(A.test(4));
- EXPECT_TRUE(A.test(5));
- EXPECT_TRUE(A.test(7));
- EXPECT_TRUE(A.test(18));
- EXPECT_EQ(4U, A.count());
- EXPECT_EQ(50U, A.size());
-
- B.resize(10);
- B.set();
- B.reset(2);
- B.reset(7);
- A &= B;
- EXPECT_FALSE(A.test(2));
- EXPECT_FALSE(A.test(7));
- EXPECT_EQ(2U, A.count());
- EXPECT_EQ(50U, A.size());
-
- B.resize(100);
- B.set();
-
- A ^= B;
- EXPECT_TRUE(A.test(2));
- EXPECT_TRUE(A.test(7));
- EXPECT_EQ(98U, A.count());
- EXPECT_EQ(100U, A.size());
-}
-
-TEST(SmallBitVectorTest, ProxyIndex) {
- SmallBitVector Vec(3);
- EXPECT_TRUE(Vec.none());
- Vec[0] = Vec[1] = Vec[2] = true;
- EXPECT_EQ(Vec.size(), Vec.count());
- Vec[2] = Vec[1] = Vec[0] = false;
- EXPECT_TRUE(Vec.none());
-}
-
-}
diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp
index d5bfe76..7fd71f5 100644
--- a/unittests/ADT/SmallVectorTest.cpp
+++ b/unittests/ADT/SmallVectorTest.cpp
@@ -88,18 +88,17 @@ int Constructable::numDestructorCalls;
int Constructable::numAssignmentCalls;
// Test fixture class
+template <typename VectorT>
class SmallVectorTest : public testing::Test {
protected:
- typedef SmallVector<Constructable, 4> VectorType;
-
- VectorType theVector;
- VectorType otherVector;
+ VectorT theVector;
+ VectorT otherVector;
void SetUp() {
Constructable::reset();
}
- void assertEmpty(VectorType & v) {
+ void assertEmpty(VectorT & v) {
// Size tests
EXPECT_EQ(0u, v.size());
EXPECT_TRUE(v.empty());
@@ -109,7 +108,7 @@ protected:
}
// Assert that theVector contains the specified values, in order.
- void assertValuesInOrder(VectorType & v, size_t size, ...) {
+ void assertValuesInOrder(VectorT & v, size_t size, ...) {
EXPECT_EQ(size, v.size());
va_list ap;
@@ -123,267 +122,327 @@ protected:
}
// Generate a sequence of values to initialize the vector.
- void makeSequence(VectorType & v, int start, int end) {
+ void makeSequence(VectorT & v, int start, int end) {
for (int i = start; i <= end; ++i) {
v.push_back(Constructable(i));
}
}
};
+typedef ::testing::Types<SmallVector<Constructable, 0>,
+ SmallVector<Constructable, 1>,
+ SmallVector<Constructable, 2>,
+ SmallVector<Constructable, 4>
+ > SmallVectorTestTypes;
+TYPED_TEST_CASE(SmallVectorTest, SmallVectorTestTypes);
+
// New vector test.
-TEST_F(SmallVectorTest, EmptyVectorTest) {
+TYPED_TEST(SmallVectorTest, EmptyVectorTest) {
SCOPED_TRACE("EmptyVectorTest");
- assertEmpty(theVector);
- EXPECT_TRUE(theVector.rbegin() == theVector.rend());
+ this->assertEmpty(this->theVector);
+ EXPECT_TRUE(this->theVector.rbegin() == this->theVector.rend());
EXPECT_EQ(0, Constructable::getNumConstructorCalls());
EXPECT_EQ(0, Constructable::getNumDestructorCalls());
}
// Simple insertions and deletions.
-TEST_F(SmallVectorTest, PushPopTest) {
+TYPED_TEST(SmallVectorTest, PushPopTest) {
SCOPED_TRACE("PushPopTest");
+ // Track whether the vector will potentially have to grow.
+ bool RequiresGrowth = this->theVector.capacity() < 3;
+
// Push an element
- theVector.push_back(Constructable(1));
+ this->theVector.push_back(Constructable(1));
// Size tests
- assertValuesInOrder(theVector, 1u, 1);
- EXPECT_FALSE(theVector.begin() == theVector.end());
- EXPECT_FALSE(theVector.empty());
+ this->assertValuesInOrder(this->theVector, 1u, 1);
+ EXPECT_FALSE(this->theVector.begin() == this->theVector.end());
+ EXPECT_FALSE(this->theVector.empty());
// Push another element
- theVector.push_back(Constructable(2));
- assertValuesInOrder(theVector, 2u, 1, 2);
+ this->theVector.push_back(Constructable(2));
+ this->assertValuesInOrder(this->theVector, 2u, 1, 2);
// Insert at beginning
- theVector.insert(theVector.begin(), theVector[1]);
- assertValuesInOrder(theVector, 3u, 2, 1, 2);
+ this->theVector.insert(this->theVector.begin(), this->theVector[1]);
+ this->assertValuesInOrder(this->theVector, 3u, 2, 1, 2);
// Pop one element
- theVector.pop_back();
- assertValuesInOrder(theVector, 2u, 2, 1);
+ this->theVector.pop_back();
+ this->assertValuesInOrder(this->theVector, 2u, 2, 1);
// Pop remaining elements
- theVector.pop_back();
- theVector.pop_back();
- assertEmpty(theVector);
+ this->theVector.pop_back();
+ this->theVector.pop_back();
+ this->assertEmpty(this->theVector);
// Check number of constructor calls. Should be 2 for each list element,
// one for the argument to push_back, one for the argument to insert,
// and one for the list element itself.
- EXPECT_EQ(5, Constructable::getNumConstructorCalls());
- EXPECT_EQ(5, Constructable::getNumDestructorCalls());
+ if (!RequiresGrowth) {
+ EXPECT_EQ(5, Constructable::getNumConstructorCalls());
+ EXPECT_EQ(5, Constructable::getNumDestructorCalls());
+ } else {
+ // If we had to grow the vector, these only have a lower bound, but should
+ // always be equal.
+ EXPECT_LE(5, Constructable::getNumConstructorCalls());
+ EXPECT_EQ(Constructable::getNumConstructorCalls(),
+ Constructable::getNumDestructorCalls());
+ }
}
// Clear test.
-TEST_F(SmallVectorTest, ClearTest) {
+TYPED_TEST(SmallVectorTest, ClearTest) {
SCOPED_TRACE("ClearTest");
- makeSequence(theVector, 1, 2);
- theVector.clear();
+ this->theVector.reserve(2);
+ this->makeSequence(this->theVector, 1, 2);
+ this->theVector.clear();
- assertEmpty(theVector);
+ this->assertEmpty(this->theVector);
EXPECT_EQ(4, Constructable::getNumConstructorCalls());
EXPECT_EQ(4, Constructable::getNumDestructorCalls());
}
// Resize smaller test.
-TEST_F(SmallVectorTest, ResizeShrinkTest) {
+TYPED_TEST(SmallVectorTest, ResizeShrinkTest) {
SCOPED_TRACE("ResizeShrinkTest");
- makeSequence(theVector, 1, 3);
- theVector.resize(1);
+ this->theVector.reserve(3);
+ this->makeSequence(this->theVector, 1, 3);
+ this->theVector.resize(1);
- assertValuesInOrder(theVector, 1u, 1);
+ this->assertValuesInOrder(this->theVector, 1u, 1);
EXPECT_EQ(6, Constructable::getNumConstructorCalls());
EXPECT_EQ(5, Constructable::getNumDestructorCalls());
}
// Resize bigger test.
-TEST_F(SmallVectorTest, ResizeGrowTest) {
+TYPED_TEST(SmallVectorTest, ResizeGrowTest) {
SCOPED_TRACE("ResizeGrowTest");
- theVector.resize(2);
+ this->theVector.resize(2);
// The extra constructor/destructor calls come from the temporary object used
// to initialize the contents of the resized array (via copy construction).
EXPECT_EQ(3, Constructable::getNumConstructorCalls());
EXPECT_EQ(1, Constructable::getNumDestructorCalls());
- EXPECT_EQ(2u, theVector.size());
+ EXPECT_EQ(2u, this->theVector.size());
}
// Resize with fill value.
-TEST_F(SmallVectorTest, ResizeFillTest) {
+TYPED_TEST(SmallVectorTest, ResizeFillTest) {
SCOPED_TRACE("ResizeFillTest");
- theVector.resize(3, Constructable(77));
- assertValuesInOrder(theVector, 3u, 77, 77, 77);
+ this->theVector.resize(3, Constructable(77));
+ this->assertValuesInOrder(this->theVector, 3u, 77, 77, 77);
}
// Overflow past fixed size.
-TEST_F(SmallVectorTest, OverflowTest) {
+TYPED_TEST(SmallVectorTest, OverflowTest) {
SCOPED_TRACE("OverflowTest");
// Push more elements than the fixed size.
- makeSequence(theVector, 1, 10);
+ this->makeSequence(this->theVector, 1, 10);
// Test size and values.
- EXPECT_EQ(10u, theVector.size());
+ EXPECT_EQ(10u, this->theVector.size());
for (int i = 0; i < 10; ++i) {
- EXPECT_EQ(i+1, theVector[i].getValue());
+ EXPECT_EQ(i+1, this->theVector[i].getValue());
}
// Now resize back to fixed size.
- theVector.resize(1);
+ this->theVector.resize(1);
- assertValuesInOrder(theVector, 1u, 1);
+ this->assertValuesInOrder(this->theVector, 1u, 1);
}
// Iteration tests.
-TEST_F(SmallVectorTest, IterationTest) {
- makeSequence(theVector, 1, 2);
+TYPED_TEST(SmallVectorTest, IterationTest) {
+ this->makeSequence(this->theVector, 1, 2);
// Forward Iteration
- VectorType::iterator it = theVector.begin();
- EXPECT_TRUE(*it == theVector.front());
- EXPECT_TRUE(*it == theVector[0]);
+ typename TypeParam::iterator it = this->theVector.begin();
+ EXPECT_TRUE(*it == this->theVector.front());
+ EXPECT_TRUE(*it == this->theVector[0]);
EXPECT_EQ(1, it->getValue());
++it;
- EXPECT_TRUE(*it == theVector[1]);
- EXPECT_TRUE(*it == theVector.back());
+ EXPECT_TRUE(*it == this->theVector[1]);
+ EXPECT_TRUE(*it == this->theVector.back());
EXPECT_EQ(2, it->getValue());
++it;
- EXPECT_TRUE(it == theVector.end());
+ EXPECT_TRUE(it == this->theVector.end());
--it;
- EXPECT_TRUE(*it == theVector[1]);
+ EXPECT_TRUE(*it == this->theVector[1]);
EXPECT_EQ(2, it->getValue());
--it;
- EXPECT_TRUE(*it == theVector[0]);
+ EXPECT_TRUE(*it == this->theVector[0]);
EXPECT_EQ(1, it->getValue());
// Reverse Iteration
- VectorType::reverse_iterator rit = theVector.rbegin();
- EXPECT_TRUE(*rit == theVector[1]);
+ typename TypeParam::reverse_iterator rit = this->theVector.rbegin();
+ EXPECT_TRUE(*rit == this->theVector[1]);
EXPECT_EQ(2, rit->getValue());
++rit;
- EXPECT_TRUE(*rit == theVector[0]);
+ EXPECT_TRUE(*rit == this->theVector[0]);
EXPECT_EQ(1, rit->getValue());
++rit;
- EXPECT_TRUE(rit == theVector.rend());
+ EXPECT_TRUE(rit == this->theVector.rend());
--rit;
- EXPECT_TRUE(*rit == theVector[0]);
+ EXPECT_TRUE(*rit == this->theVector[0]);
EXPECT_EQ(1, rit->getValue());
--rit;
- EXPECT_TRUE(*rit == theVector[1]);
+ EXPECT_TRUE(*rit == this->theVector[1]);
EXPECT_EQ(2, rit->getValue());
}
// Swap test.
-TEST_F(SmallVectorTest, SwapTest) {
+TYPED_TEST(SmallVectorTest, SwapTest) {
SCOPED_TRACE("SwapTest");
- makeSequence(theVector, 1, 2);
- std::swap(theVector, otherVector);
+ this->makeSequence(this->theVector, 1, 2);
+ std::swap(this->theVector, this->otherVector);
- assertEmpty(theVector);
- assertValuesInOrder(otherVector, 2u, 1, 2);
+ this->assertEmpty(this->theVector);
+ this->assertValuesInOrder(this->otherVector, 2u, 1, 2);
}
// Append test
-TEST_F(SmallVectorTest, AppendTest) {
+TYPED_TEST(SmallVectorTest, AppendTest) {
SCOPED_TRACE("AppendTest");
- makeSequence(otherVector, 2, 3);
+ this->makeSequence(this->otherVector, 2, 3);
- theVector.push_back(Constructable(1));
- theVector.append(otherVector.begin(), otherVector.end());
+ this->theVector.push_back(Constructable(1));
+ this->theVector.append(this->otherVector.begin(), this->otherVector.end());
- assertValuesInOrder(theVector, 3u, 1, 2, 3);
+ this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
}
// Append repeated test
-TEST_F(SmallVectorTest, AppendRepeatedTest) {
+TYPED_TEST(SmallVectorTest, AppendRepeatedTest) {
SCOPED_TRACE("AppendRepeatedTest");
- theVector.push_back(Constructable(1));
- theVector.append(2, Constructable(77));
- assertValuesInOrder(theVector, 3u, 1, 77, 77);
+ this->theVector.push_back(Constructable(1));
+ this->theVector.append(2, Constructable(77));
+ this->assertValuesInOrder(this->theVector, 3u, 1, 77, 77);
}
// Assign test
-TEST_F(SmallVectorTest, AssignTest) {
+TYPED_TEST(SmallVectorTest, AssignTest) {
SCOPED_TRACE("AssignTest");
- theVector.push_back(Constructable(1));
- theVector.assign(2, Constructable(77));
- assertValuesInOrder(theVector, 2u, 77, 77);
+ this->theVector.push_back(Constructable(1));
+ this->theVector.assign(2, Constructable(77));
+ this->assertValuesInOrder(this->theVector, 2u, 77, 77);
}
// Erase a single element
-TEST_F(SmallVectorTest, EraseTest) {
+TYPED_TEST(SmallVectorTest, EraseTest) {
SCOPED_TRACE("EraseTest");
- makeSequence(theVector, 1, 3);
- theVector.erase(theVector.begin());
- assertValuesInOrder(theVector, 2u, 2, 3);
+ this->makeSequence(this->theVector, 1, 3);
+ this->theVector.erase(this->theVector.begin());
+ this->assertValuesInOrder(this->theVector, 2u, 2, 3);
}
// Erase a range of elements
-TEST_F(SmallVectorTest, EraseRangeTest) {
+TYPED_TEST(SmallVectorTest, EraseRangeTest) {
SCOPED_TRACE("EraseRangeTest");
- makeSequence(theVector, 1, 3);
- theVector.erase(theVector.begin(), theVector.begin() + 2);
- assertValuesInOrder(theVector, 1u, 3);
+ this->makeSequence(this->theVector, 1, 3);
+ this->theVector.erase(this->theVector.begin(), this->theVector.begin() + 2);
+ this->assertValuesInOrder(this->theVector, 1u, 3);
}
// Insert a single element.
-TEST_F(SmallVectorTest, InsertTest) {
+TYPED_TEST(SmallVectorTest, InsertTest) {
SCOPED_TRACE("InsertTest");
- makeSequence(theVector, 1, 3);
- theVector.insert(theVector.begin() + 1, Constructable(77));
- assertValuesInOrder(theVector, 4u, 1, 77, 2, 3);
+ this->makeSequence(this->theVector, 1, 3);
+ typename TypeParam::iterator I =
+ this->theVector.insert(this->theVector.begin() + 1, Constructable(77));
+ EXPECT_EQ(this->theVector.begin() + 1, I);
+ this->assertValuesInOrder(this->theVector, 4u, 1, 77, 2, 3);
}
// Insert repeated elements.
-TEST_F(SmallVectorTest, InsertRepeatedTest) {
+TYPED_TEST(SmallVectorTest, InsertRepeatedTest) {
SCOPED_TRACE("InsertRepeatedTest");
- makeSequence(theVector, 10, 15);
- theVector.insert(theVector.begin() + 1, 2, Constructable(16));
- assertValuesInOrder(theVector, 8u, 10, 16, 16, 11, 12, 13, 14, 15);
+ this->makeSequence(this->theVector, 10, 15);
+ typename TypeParam::iterator I =
+ this->theVector.insert(this->theVector.begin() + 1, 2, Constructable(16));
+ EXPECT_EQ(this->theVector.begin() + 1, I);
+ this->assertValuesInOrder(this->theVector, 8u,
+ 10, 16, 16, 11, 12, 13, 14, 15);
+
+ // Insert at end.
+ I = this->theVector.insert(this->theVector.end(), 2, Constructable(16));
+ EXPECT_EQ(this->theVector.begin() + 8, I);
+ this->assertValuesInOrder(this->theVector, 10u,
+ 10, 16, 16, 11, 12, 13, 14, 15, 16, 16);
+
+ // Empty insert.
+ EXPECT_EQ(this->theVector.end(),
+ this->theVector.insert(this->theVector.end(),
+ 0, Constructable(42)));
+ EXPECT_EQ(this->theVector.begin() + 1,
+ this->theVector.insert(this->theVector.begin() + 1,
+ 0, Constructable(42)));
}
// Insert range.
-TEST_F(SmallVectorTest, InsertRangeTest) {
- SCOPED_TRACE("InsertRepeatedTest");
-
- makeSequence(theVector, 1, 3);
- theVector.insert(theVector.begin() + 1, 3, Constructable(77));
- assertValuesInOrder(theVector, 6u, 1, 77, 77, 77, 2, 3);
+TYPED_TEST(SmallVectorTest, InsertRangeTest) {
+ SCOPED_TRACE("InsertRangeTest");
+
+ Constructable Arr[3] =
+ { Constructable(77), Constructable(77), Constructable(77) };
+
+ this->makeSequence(this->theVector, 1, 3);
+ typename TypeParam::iterator I =
+ this->theVector.insert(this->theVector.begin() + 1, Arr, Arr+3);
+ EXPECT_EQ(this->theVector.begin() + 1, I);
+ this->assertValuesInOrder(this->theVector, 6u, 1, 77, 77, 77, 2, 3);
+
+ // Insert at end.
+ I = this->theVector.insert(this->theVector.end(), Arr, Arr+3);
+ EXPECT_EQ(this->theVector.begin() + 6, I);
+ this->assertValuesInOrder(this->theVector, 9u,
+ 1, 77, 77, 77, 2, 3, 77, 77, 77);
+
+ // Empty insert.
+ EXPECT_EQ(this->theVector.end(),
+ this->theVector.insert(this->theVector.end(),
+ this->theVector.begin(),
+ this->theVector.begin()));
+ EXPECT_EQ(this->theVector.begin() + 1,
+ this->theVector.insert(this->theVector.begin() + 1,
+ this->theVector.begin(),
+ this->theVector.begin()));
}
// Comparison tests.
-TEST_F(SmallVectorTest, ComparisonTest) {
+TYPED_TEST(SmallVectorTest, ComparisonTest) {
SCOPED_TRACE("ComparisonTest");
- makeSequence(theVector, 1, 3);
- makeSequence(otherVector, 1, 3);
+ this->makeSequence(this->theVector, 1, 3);
+ this->makeSequence(this->otherVector, 1, 3);
- EXPECT_TRUE(theVector == otherVector);
- EXPECT_FALSE(theVector != otherVector);
+ EXPECT_TRUE(this->theVector == this->otherVector);
+ EXPECT_FALSE(this->theVector != this->otherVector);
- otherVector.clear();
- makeSequence(otherVector, 2, 4);
+ this->otherVector.clear();
+ this->makeSequence(this->otherVector, 2, 4);
- EXPECT_FALSE(theVector == otherVector);
- EXPECT_TRUE(theVector != otherVector);
+ EXPECT_FALSE(this->theVector == this->otherVector);
+ EXPECT_TRUE(this->theVector != this->otherVector);
}
// Constant vector tests.
-TEST_F(SmallVectorTest, ConstVectorTest) {
- VectorType constVector;
+TYPED_TEST(SmallVectorTest, ConstVectorTest) {
+ const TypeParam constVector;
EXPECT_EQ(0u, constVector.size());
EXPECT_TRUE(constVector.empty());
@@ -391,26 +450,40 @@ TEST_F(SmallVectorTest, ConstVectorTest) {
}
// Direct array access.
-TEST_F(SmallVectorTest, DirectVectorTest) {
- EXPECT_EQ(0u, theVector.size());
- EXPECT_LE(4u, theVector.capacity());
+TYPED_TEST(SmallVectorTest, DirectVectorTest) {
+ EXPECT_EQ(0u, this->theVector.size());
+ this->theVector.reserve(4);
+ EXPECT_LE(4u, this->theVector.capacity());
EXPECT_EQ(0, Constructable::getNumConstructorCalls());
- theVector.end()[0] = 1;
- theVector.end()[1] = 2;
- theVector.end()[2] = 3;
- theVector.end()[3] = 4;
- theVector.set_size(4);
- EXPECT_EQ(4u, theVector.size());
+ this->theVector.end()[0] = 1;
+ this->theVector.end()[1] = 2;
+ this->theVector.end()[2] = 3;
+ this->theVector.end()[3] = 4;
+ this->theVector.set_size(4);
+ EXPECT_EQ(4u, this->theVector.size());
EXPECT_EQ(4, Constructable::getNumConstructorCalls());
- EXPECT_EQ(1, theVector[0].getValue());
- EXPECT_EQ(2, theVector[1].getValue());
- EXPECT_EQ(3, theVector[2].getValue());
- EXPECT_EQ(4, theVector[3].getValue());
+ EXPECT_EQ(1, this->theVector[0].getValue());
+ EXPECT_EQ(2, this->theVector[1].getValue());
+ EXPECT_EQ(3, this->theVector[2].getValue());
+ EXPECT_EQ(4, this->theVector[3].getValue());
}
-TEST_F(SmallVectorTest, IteratorTest) {
+TYPED_TEST(SmallVectorTest, IteratorTest) {
std::list<int> L;
- theVector.insert(theVector.end(), L.begin(), L.end());
+ this->theVector.insert(this->theVector.end(), L.begin(), L.end());
+}
+
+struct notassignable {
+ int &x;
+ notassignable(int &x) : x(x) {}
+};
+
+TEST(SmallVectorCustomTest, NoAssignTest) {
+ int x = 0;
+ SmallVector<notassignable, 2> vec;
+ vec.push_back(notassignable(x));
+ x = 42;
+ EXPECT_EQ(42, vec.pop_back_val().x);
}
}
diff --git a/unittests/ADT/SparseSetTest.cpp b/unittests/ADT/SparseSetTest.cpp
index a6ea757..eb0e0db 100644
--- a/unittests/ADT/SparseSetTest.cpp
+++ b/unittests/ADT/SparseSetTest.cpp
@@ -161,7 +161,7 @@ TEST(SparseSetTest, MultipleEntrySet) {
struct Alt {
unsigned Value;
explicit Alt(unsigned x) : Value(x) {}
- unsigned getSparseSetKey() const { return Value - 1000; }
+ unsigned getSparseSetIndex() const { return Value - 1000; }
};
TEST(SparseSetTest, AltStructSet) {
diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp
index 2ae5820..5bb65cb 100644
--- a/unittests/ADT/StringMapTest.cpp
+++ b/unittests/ADT/StringMapTest.cpp
@@ -75,7 +75,6 @@ const std::string StringMapTest::testKeyStr(testKey);
// Empty map tests.
TEST_F(StringMapTest, EmptyMapTest) {
- SCOPED_TRACE("EmptyMapTest");
assertEmptyMap();
}
@@ -102,14 +101,12 @@ TEST_F(StringMapTest, ConstEmptyMapTest) {
// A map with a single entry.
TEST_F(StringMapTest, SingleEntryMapTest) {
- SCOPED_TRACE("SingleEntryMapTest");
testMap[testKey] = testValue;
assertSingleItemMap();
}
// Test clear() method.
TEST_F(StringMapTest, ClearTest) {
- SCOPED_TRACE("ClearTest");
testMap[testKey] = testValue;
testMap.clear();
assertEmptyMap();
@@ -117,7 +114,6 @@ TEST_F(StringMapTest, ClearTest) {
// Test erase(iterator) method.
TEST_F(StringMapTest, EraseIteratorTest) {
- SCOPED_TRACE("EraseIteratorTest");
testMap[testKey] = testValue;
testMap.erase(testMap.begin());
assertEmptyMap();
@@ -125,7 +121,6 @@ TEST_F(StringMapTest, EraseIteratorTest) {
// Test erase(value) method.
TEST_F(StringMapTest, EraseValueTest) {
- SCOPED_TRACE("EraseValueTest");
testMap[testKey] = testValue;
testMap.erase(testKey);
assertEmptyMap();
@@ -133,13 +128,34 @@ TEST_F(StringMapTest, EraseValueTest) {
// Test inserting two values and erasing one.
TEST_F(StringMapTest, InsertAndEraseTest) {
- SCOPED_TRACE("InsertAndEraseTest");
testMap[testKey] = testValue;
testMap["otherKey"] = 2;
testMap.erase("otherKey");
assertSingleItemMap();
}
+TEST_F(StringMapTest, SmallFullMapTest) {
+ // StringMap has a tricky corner case when the map is small (<8 buckets) and
+ // it fills up through a balanced pattern of inserts and erases. This can
+ // lead to inf-loops in some cases (PR13148) so we test it explicitly here.
+ llvm::StringMap<int> Map(2);
+
+ Map["eins"] = 1;
+ Map["zwei"] = 2;
+ Map["drei"] = 3;
+ Map.erase("drei");
+ Map.erase("eins");
+ Map["veir"] = 4;
+ Map["funf"] = 5;
+
+ EXPECT_EQ(3u, Map.size());
+ EXPECT_EQ(0, Map.lookup("eins"));
+ EXPECT_EQ(2, Map.lookup("zwei"));
+ EXPECT_EQ(0, Map.lookup("drei"));
+ EXPECT_EQ(4, Map.lookup("veir"));
+ EXPECT_EQ(5, Map.lookup("funf"));
+}
+
// A more complex iteration test.
TEST_F(StringMapTest, IterationTest) {
bool visited[100];
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp
index cc7a7fb..315eacb 100644
--- a/unittests/ADT/StringRefTest.cpp
+++ b/unittests/ADT/StringRefTest.cpp
@@ -221,6 +221,30 @@ TEST(StringRefTest, Split2) {
EXPECT_TRUE(parts == expected);
}
+TEST(StringRefTest, Trim) {
+ StringRef Str0("hello");
+ StringRef Str1(" hello ");
+ StringRef Str2(" hello ");
+
+ EXPECT_EQ(StringRef("hello"), Str0.rtrim());
+ EXPECT_EQ(StringRef(" hello"), Str1.rtrim());
+ EXPECT_EQ(StringRef(" hello"), Str2.rtrim());
+ EXPECT_EQ(StringRef("hello"), Str0.ltrim());
+ EXPECT_EQ(StringRef("hello "), Str1.ltrim());
+ EXPECT_EQ(StringRef("hello "), Str2.ltrim());
+ EXPECT_EQ(StringRef("hello"), Str0.trim());
+ EXPECT_EQ(StringRef("hello"), Str1.trim());
+ EXPECT_EQ(StringRef("hello"), Str2.trim());
+
+ EXPECT_EQ(StringRef("ello"), Str0.trim("hhhhhhhhhhh"));
+
+ EXPECT_EQ(StringRef(""), StringRef("").trim());
+ EXPECT_EQ(StringRef(""), StringRef(" ").trim());
+ EXPECT_EQ(StringRef("\0", 1), StringRef(" \0 ", 3).trim());
+ EXPECT_EQ(StringRef("\0\0", 2), StringRef("\0\0", 2).trim());
+ EXPECT_EQ(StringRef("x"), StringRef("\0\0x\0\0", 5).trim(StringRef("\0", 1)));
+}
+
TEST(StringRefTest, StartsWith) {
StringRef Str("hello");
EXPECT_TRUE(Str.startswith("he"));
@@ -267,6 +291,10 @@ TEST(StringRefTest, Find) {
EXPECT_EQ(1U, Str.find_first_not_of('h'));
EXPECT_EQ(4U, Str.find_first_not_of("hel"));
EXPECT_EQ(StringRef::npos, Str.find_first_not_of("hello"));
+
+ EXPECT_EQ(3U, Str.find_last_not_of('o'));
+ EXPECT_EQ(1U, Str.find_last_not_of("lo"));
+ EXPECT_EQ(StringRef::npos, Str.find_last_not_of("helo"));
}
TEST(StringRefTest, Count) {
diff --git a/unittests/ADT/TinyPtrVectorTest.cpp b/unittests/ADT/TinyPtrVectorTest.cpp
new file mode 100644
index 0000000..05dd797
--- /dev/null
+++ b/unittests/ADT/TinyPtrVectorTest.cpp
@@ -0,0 +1,448 @@
+//===- llvm/unittest/ADT/TinyPtrVectorTest.cpp ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// TinyPtrVector unit tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/TinyPtrVector.h"
+#include "llvm/Support/type_traits.h"
+#include <algorithm>
+#include <list>
+#include <vector>
+
+using namespace llvm;
+
+namespace {
+
+// The world's worst RNG, but it is deterministic and makes it easy to get
+// *some* shuffling of elements.
+static ptrdiff_t test_shuffle_rng(ptrdiff_t i) {
+ return (i + i * 33) % i;
+}
+static ptrdiff_t (*test_shuffle_rng_p)(ptrdiff_t) = &test_shuffle_rng;
+
+template <typename VectorT>
+class TinyPtrVectorTest : public testing::Test {
+protected:
+ typedef typename VectorT::value_type PtrT;
+ typedef typename remove_pointer<PtrT>::type ValueT;
+
+ VectorT V;
+ VectorT V2;
+
+ ValueT TestValues[1024];
+ std::vector<PtrT> TestPtrs;
+
+ TinyPtrVectorTest() {
+ for (size_t i = 0, e = array_lengthof(TestValues); i != e; ++i)
+ TestPtrs.push_back(&TestValues[i]);
+
+ std::random_shuffle(TestPtrs.begin(), TestPtrs.end(), test_shuffle_rng_p);
+ }
+
+ ArrayRef<PtrT> testArray(size_t N) {
+ return makeArrayRef(&TestPtrs[0], N);
+ }
+
+ void appendValues(VectorT &V, ArrayRef<PtrT> Values) {
+ for (size_t i = 0, e = Values.size(); i != e; ++i)
+ 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());
+ for (size_t i = 0, e = Values.size(); i != e; ++i) {
+ EXPECT_EQ(Values[i], V[i]);
+ EXPECT_EQ(Values[i], *llvm::next(V.begin(), i));
+ }
+ EXPECT_EQ(V.end(), llvm::next(V.begin(), Values.size()));
+ }
+};
+
+typedef ::testing::Types<TinyPtrVector<int*>,
+ TinyPtrVector<double*>
+ > TinyPtrVectorTestTypes;
+TYPED_TEST_CASE(TinyPtrVectorTest, TinyPtrVectorTestTypes);
+
+TYPED_TEST(TinyPtrVectorTest, EmptyTest) {
+ this->expectValues(this->V, this->testArray(0));
+}
+
+TYPED_TEST(TinyPtrVectorTest, PushPopBack) {
+ this->V.push_back(this->TestPtrs[0]);
+ this->expectValues(this->V, this->testArray(1));
+ this->V.push_back(this->TestPtrs[1]);
+ this->expectValues(this->V, this->testArray(2));
+ this->V.push_back(this->TestPtrs[2]);
+ this->expectValues(this->V, this->testArray(3));
+ this->V.push_back(this->TestPtrs[3]);
+ this->expectValues(this->V, this->testArray(4));
+ this->V.push_back(this->TestPtrs[4]);
+ this->expectValues(this->V, this->testArray(5));
+
+ // Pop and clobber a few values to keep things interesting.
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(4));
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(3));
+ this->TestPtrs[3] = &this->TestValues[42];
+ this->TestPtrs[4] = &this->TestValues[43];
+ this->V.push_back(this->TestPtrs[3]);
+ this->expectValues(this->V, this->testArray(4));
+ this->V.push_back(this->TestPtrs[4]);
+ this->expectValues(this->V, this->testArray(5));
+
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(4));
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(3));
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(2));
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(1));
+ this->V.pop_back();
+ this->expectValues(this->V, this->testArray(0));
+
+ this->appendValues(this->V, this->testArray(42));
+ this->expectValues(this->V, this->testArray(42));
+}
+
+TYPED_TEST(TinyPtrVectorTest, ClearTest) {
+ this->expectValues(this->V, this->testArray(0));
+ this->V.clear();
+ this->expectValues(this->V, this->testArray(0));
+
+ this->appendValues(this->V, this->testArray(1));
+ this->expectValues(this->V, this->testArray(1));
+ this->V.clear();
+ this->expectValues(this->V, this->testArray(0));
+
+ this->appendValues(this->V, this->testArray(42));
+ this->expectValues(this->V, this->testArray(42));
+ this->V.clear();
+ this->expectValues(this->V, this->testArray(0));
+}
+
+TYPED_TEST(TinyPtrVectorTest, CopyAndMoveCtorTest) {
+ this->appendValues(this->V, this->testArray(42));
+ TypeParam Copy(this->V);
+ this->expectValues(Copy, this->testArray(42));
+
+ // This is a separate copy, and so it shouldn't destroy the original.
+ Copy.clear();
+ this->expectValues(Copy, this->testArray(0));
+ this->expectValues(this->V, this->testArray(42));
+
+ TypeParam Copy2(this->V2);
+ this->appendValues(Copy2, this->testArray(42));
+ this->expectValues(Copy2, this->testArray(42));
+ this->expectValues(this->V2, this->testArray(0));
+
+#if LLVM_USE_RVALUE_REFERENCES
+ TypeParam Move(std::move(Copy2));
+ this->expectValues(Move, this->testArray(42));
+ this->expectValues(Copy2, this->testArray(0));
+#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));
+ this->V.erase(this->V.begin());
+ this->expectValues(this->V, this->testArray(0));
+
+ this->appendValues(this->V, this->testArray(42));
+ this->expectValues(this->V, this->testArray(42));
+ this->V.erase(this->V.begin());
+ this->TestPtrs.erase(this->TestPtrs.begin());
+ this->expectValues(this->V, this->testArray(41));
+ this->V.erase(llvm::next(this->V.begin(), 1));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1));
+ this->expectValues(this->V, this->testArray(40));
+ this->V.erase(llvm::next(this->V.begin(), 2));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2));
+ this->expectValues(this->V, this->testArray(39));
+ this->V.erase(llvm::next(this->V.begin(), 5));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5));
+ this->expectValues(this->V, this->testArray(38));
+ this->V.erase(llvm::next(this->V.begin(), 13));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13));
+ this->expectValues(this->V, this->testArray(37));
+
+ typename TypeParam::iterator I = this->V.begin();
+ do {
+ I = this->V.erase(I);
+ } while (I != this->V.end());
+ this->expectValues(this->V, this->testArray(0));
+}
+
+TYPED_TEST(TinyPtrVectorTest, EraseRangeTest) {
+ this->appendValues(this->V, this->testArray(1));
+ this->expectValues(this->V, this->testArray(1));
+ this->V.erase(this->V.begin(), this->V.begin());
+ this->expectValues(this->V, this->testArray(1));
+ this->V.erase(this->V.end(), this->V.end());
+ this->expectValues(this->V, this->testArray(1));
+ this->V.erase(this->V.begin(), this->V.end());
+ this->expectValues(this->V, this->testArray(0));
+
+ this->appendValues(this->V, this->testArray(42));
+ this->expectValues(this->V, this->testArray(42));
+ this->V.erase(this->V.begin(), llvm::next(this->V.begin(), 1));
+ this->TestPtrs.erase(this->TestPtrs.begin(),
+ llvm::next(this->TestPtrs.begin(), 1));
+ this->expectValues(this->V, this->testArray(41));
+ this->V.erase(llvm::next(this->V.begin(), 1), llvm::next(this->V.begin(), 2));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1),
+ llvm::next(this->TestPtrs.begin(), 2));
+ this->expectValues(this->V, this->testArray(40));
+ this->V.erase(llvm::next(this->V.begin(), 2), llvm::next(this->V.begin(), 4));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2),
+ llvm::next(this->TestPtrs.begin(), 4));
+ this->expectValues(this->V, this->testArray(38));
+ this->V.erase(llvm::next(this->V.begin(), 5), llvm::next(this->V.begin(), 10));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5),
+ llvm::next(this->TestPtrs.begin(), 10));
+ this->expectValues(this->V, this->testArray(33));
+ this->V.erase(llvm::next(this->V.begin(), 13), llvm::next(this->V.begin(), 26));
+ this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13),
+ llvm::next(this->TestPtrs.begin(), 26));
+ this->expectValues(this->V, this->testArray(20));
+ this->V.erase(llvm::next(this->V.begin(), 7), this->V.end());
+ this->expectValues(this->V, this->testArray(7));
+ this->V.erase(this->V.begin(), this->V.end());
+ this->expectValues(this->V, this->testArray(0));
+}
+
+TYPED_TEST(TinyPtrVectorTest, Insert) {
+ this->V.insert(this->V.end(), this->TestPtrs[0]);
+ this->expectValues(this->V, this->testArray(1));
+ this->V.clear();
+ this->appendValues(this->V, this->testArray(4));
+ this->expectValues(this->V, this->testArray(4));
+ this->V.insert(this->V.end(), this->TestPtrs[4]);
+ this->expectValues(this->V, this->testArray(5));
+ this->V.insert(this->V.begin(), this->TestPtrs[42]);
+ this->TestPtrs.insert(this->TestPtrs.begin(), this->TestPtrs[42]);
+ this->expectValues(this->V, this->testArray(6));
+ this->V.insert(llvm::next(this->V.begin(), 3), this->TestPtrs[43]);
+ this->TestPtrs.insert(llvm::next(this->TestPtrs.begin(), 3),
+ this->TestPtrs[43]);
+ this->expectValues(this->V, this->testArray(7));
+}
+
+TYPED_TEST(TinyPtrVectorTest, InsertRange) {
+ this->V.insert(this->V.end(), this->TestPtrs.begin(), this->TestPtrs.begin());
+ this->expectValues(this->V, this->testArray(0));
+ this->V.insert(this->V.begin(), this->TestPtrs.begin(),
+ this->TestPtrs.begin());
+ this->expectValues(this->V, this->testArray(0));
+ this->V.insert(this->V.end(), this->TestPtrs.end(), this->TestPtrs.end());
+ this->expectValues(this->V, this->testArray(0));
+ this->V.insert(this->V.end(), this->TestPtrs.begin(),
+ llvm::next(this->TestPtrs.begin()));
+ this->expectValues(this->V, this->testArray(1));
+ this->V.clear();
+ this->V.insert(this->V.end(), this->TestPtrs.begin(),
+ llvm::next(this->TestPtrs.begin(), 2));
+ this->expectValues(this->V, this->testArray(2));
+ this->V.clear();
+ this->V.insert(this->V.end(), this->TestPtrs.begin(),
+ llvm::next(this->TestPtrs.begin(), 42));
+ this->expectValues(this->V, this->testArray(42));
+ this->V.clear();
+ this->V.insert(this->V.end(),
+ llvm::next(this->TestPtrs.begin(), 5),
+ llvm::next(this->TestPtrs.begin(), 13));
+ this->V.insert(this->V.begin(),
+ llvm::next(this->TestPtrs.begin(), 0),
+ llvm::next(this->TestPtrs.begin(), 3));
+ this->V.insert(llvm::next(this->V.begin(), 2),
+ llvm::next(this->TestPtrs.begin(), 2),
+ llvm::next(this->TestPtrs.begin(), 4));
+ this->V.erase(llvm::next(this->V.begin(), 4));
+ this->V.insert(llvm::next(this->V.begin(), 4),
+ llvm::next(this->TestPtrs.begin(), 4),
+ llvm::next(this->TestPtrs.begin(), 5));
+ this->expectValues(this->V, this->testArray(13));
+}
+
+}
diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp
index 479046e..967437c 100644
--- a/unittests/ADT/TripleTest.cpp
+++ b/unittests/ADT/TripleTest.cpp
@@ -353,9 +353,9 @@ TEST(TripleTest, BitWidthArchVariants) {
EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
- T.setArch(Triple::ptx32);
- EXPECT_EQ(Triple::ptx32, T.get32BitArchVariant().getArch());
- EXPECT_EQ(Triple::ptx64, T.get64BitArchVariant().getArch());
+ T.setArch(Triple::nvptx);
+ EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
T.setArch(Triple::sparc);
EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
@@ -377,9 +377,9 @@ TEST(TripleTest, BitWidthArchVariants) {
EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
- T.setArch(Triple::ptx64);
- EXPECT_EQ(Triple::ptx32, T.get32BitArchVariant().getArch());
- EXPECT_EQ(Triple::ptx64, T.get64BitArchVariant().getArch());
+ T.setArch(Triple::nvptx64);
+ EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
T.setArch(Triple::sparcv9);
EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
@@ -390,4 +390,69 @@ TEST(TripleTest, BitWidthArchVariants) {
EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
}
+TEST(TripleTest, getOSVersion) {
+ Triple T;
+ unsigned Major, Minor, Micro;
+
+ T = Triple("i386-apple-darwin9");
+ T.getMacOSXVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)10, Major);
+ EXPECT_EQ((unsigned)5, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+ T.getiOSVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)0, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+
+ T = Triple("x86_64-apple-darwin9");
+ T.getMacOSXVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)10, Major);
+ EXPECT_EQ((unsigned)5, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+ T.getiOSVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)0, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+
+ T = Triple("x86_64-apple-macosx");
+ T.getMacOSXVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)10, Major);
+ EXPECT_EQ((unsigned)4, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+ T.getiOSVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)0, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+
+ T = Triple("x86_64-apple-macosx10.7");
+ T.getMacOSXVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)10, Major);
+ EXPECT_EQ((unsigned)7, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+ T.getiOSVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)0, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+
+ T = Triple("armv7-apple-ios");
+ T.getMacOSXVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)10, Major);
+ EXPECT_EQ((unsigned)4, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+ T.getiOSVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)0, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+
+ T = Triple("armv7-apple-ios5.0");
+ T.getMacOSXVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)10, Major);
+ EXPECT_EQ((unsigned)4, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+ T.getiOSVersion(Major, Minor, Micro);
+ EXPECT_EQ((unsigned)5, Major);
+ EXPECT_EQ((unsigned)0, Minor);
+ EXPECT_EQ((unsigned)0, Micro);
+}
+
}
OpenPOWER on IntegriCloud