Imported Upstream version 5.18.0.167

Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-20 08:25:10 +00:00
parent e19d552987
commit b084638f15
28489 changed files with 184 additions and 3866856 deletions

View File

@ -1 +0,0 @@
8b88c123b19757da6aec1d8131bb05f69208130e

File diff suppressed because it is too large Load Diff

View File

@ -1,163 +0,0 @@
//===- llvm/unittest/ADT/APSIntTest.cpp - APSInt unit 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/APSInt.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
TEST(APSIntTest, MoveTest) {
APSInt A(32, true);
EXPECT_TRUE(A.isUnsigned());
APSInt B(128, false);
A = B;
EXPECT_FALSE(A.isUnsigned());
APSInt C(B);
EXPECT_FALSE(C.isUnsigned());
APInt Wide(256, 0);
const uint64_t *Bits = Wide.getRawData();
APSInt D(std::move(Wide));
EXPECT_TRUE(D.isUnsigned());
EXPECT_EQ(Bits, D.getRawData()); // Verify that "Wide" was really moved.
A = APSInt(64, true);
EXPECT_TRUE(A.isUnsigned());
Wide = APInt(128, 1);
Bits = Wide.getRawData();
A = std::move(Wide);
EXPECT_TRUE(A.isUnsigned());
EXPECT_EQ(Bits, A.getRawData()); // Verify that "Wide" was really moved.
}
TEST(APSIntTest, get) {
EXPECT_TRUE(APSInt::get(7).isSigned());
EXPECT_EQ(64u, APSInt::get(7).getBitWidth());
EXPECT_EQ(7u, APSInt::get(7).getZExtValue());
EXPECT_EQ(7, APSInt::get(7).getSExtValue());
EXPECT_TRUE(APSInt::get(-7).isSigned());
EXPECT_EQ(64u, APSInt::get(-7).getBitWidth());
EXPECT_EQ(-7, APSInt::get(-7).getSExtValue());
EXPECT_EQ(UINT64_C(0) - 7, APSInt::get(-7).getZExtValue());
}
TEST(APSIntTest, getUnsigned) {
EXPECT_TRUE(APSInt::getUnsigned(7).isUnsigned());
EXPECT_EQ(64u, APSInt::getUnsigned(7).getBitWidth());
EXPECT_EQ(7u, APSInt::getUnsigned(7).getZExtValue());
EXPECT_EQ(7, APSInt::getUnsigned(7).getSExtValue());
EXPECT_TRUE(APSInt::getUnsigned(-7).isUnsigned());
EXPECT_EQ(64u, APSInt::getUnsigned(-7).getBitWidth());
EXPECT_EQ(-7, APSInt::getUnsigned(-7).getSExtValue());
EXPECT_EQ(UINT64_C(0) - 7, APSInt::getUnsigned(-7).getZExtValue());
}
TEST(APSIntTest, getExtValue) {
EXPECT_TRUE(APSInt(APInt(3, 7), true).isUnsigned());
EXPECT_TRUE(APSInt(APInt(3, 7), false).isSigned());
EXPECT_TRUE(APSInt(APInt(4, 7), true).isUnsigned());
EXPECT_TRUE(APSInt(APInt(4, 7), false).isSigned());
EXPECT_TRUE(APSInt(APInt(4, -7), true).isUnsigned());
EXPECT_TRUE(APSInt(APInt(4, -7), false).isSigned());
EXPECT_EQ(7, APSInt(APInt(3, 7), true).getExtValue());
EXPECT_EQ(-1, APSInt(APInt(3, 7), false).getExtValue());
EXPECT_EQ(7, APSInt(APInt(4, 7), true).getExtValue());
EXPECT_EQ(7, APSInt(APInt(4, 7), false).getExtValue());
EXPECT_EQ(9, APSInt(APInt(4, -7), true).getExtValue());
EXPECT_EQ(-7, APSInt(APInt(4, -7), false).getExtValue());
}
TEST(APSIntTest, compareValues) {
auto U = [](uint64_t V) { return APSInt::getUnsigned(V); };
auto S = [](int64_t V) { return APSInt::get(V); };
// Bit-width matches and is-signed.
EXPECT_TRUE(APSInt::compareValues(S(7), S(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(8), S(7)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(7), S(7)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(8), S(-7)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(-7)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(-8)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(-8), S(-7)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(-7)) == 0);
// Bit-width matches and not is-signed.
EXPECT_TRUE(APSInt::compareValues(U(7), U(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(U(8), U(7)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7), U(7)) == 0);
// Bit-width matches and mixed signs.
EXPECT_TRUE(APSInt::compareValues(U(7), S(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(U(8), S(7)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7), S(7)) == 0);
EXPECT_TRUE(APSInt::compareValues(U(8), S(-7)) > 0);
// Bit-width mismatch and is-signed.
EXPECT_TRUE(APSInt::compareValues(S(7).trunc(32), S(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(8).trunc(32), S(7)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(7).trunc(32), S(7)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(-7).trunc(32), S(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(8).trunc(32), S(-7)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(-7).trunc(32), S(-7)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(-7).trunc(32), S(-8)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(-8).trunc(32), S(-7)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(-7).trunc(32), S(-7)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(7), S(8).trunc(32)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(8), S(7).trunc(32)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(7), S(7).trunc(32)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(8).trunc(32)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(8), S(-7).trunc(32)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(-7).trunc(32)) == 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(-8).trunc(32)) > 0);
EXPECT_TRUE(APSInt::compareValues(S(-8), S(-7).trunc(32)) < 0);
EXPECT_TRUE(APSInt::compareValues(S(-7), S(-7).trunc(32)) == 0);
// Bit-width mismatch and not is-signed.
EXPECT_TRUE(APSInt::compareValues(U(7), U(8).trunc(32)) < 0);
EXPECT_TRUE(APSInt::compareValues(U(8), U(7).trunc(32)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7), U(7).trunc(32)) == 0);
EXPECT_TRUE(APSInt::compareValues(U(7).trunc(32), U(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(U(8).trunc(32), U(7)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7).trunc(32), U(7)) == 0);
// Bit-width mismatch and mixed signs.
EXPECT_TRUE(APSInt::compareValues(U(7).trunc(32), S(8)) < 0);
EXPECT_TRUE(APSInt::compareValues(U(8).trunc(32), S(7)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7).trunc(32), S(7)) == 0);
EXPECT_TRUE(APSInt::compareValues(U(8).trunc(32), S(-7)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7), S(8).trunc(32)) < 0);
EXPECT_TRUE(APSInt::compareValues(U(8), S(7).trunc(32)) > 0);
EXPECT_TRUE(APSInt::compareValues(U(7), S(7).trunc(32)) == 0);
EXPECT_TRUE(APSInt::compareValues(U(8), S(-7).trunc(32)) > 0);
}
TEST(APSIntTest, FromString) {
EXPECT_EQ(APSInt("1").getExtValue(), 1);
EXPECT_EQ(APSInt("-1").getExtValue(), -1);
EXPECT_EQ(APSInt("0").getExtValue(), 0);
EXPECT_EQ(APSInt("56789").getExtValue(), 56789);
EXPECT_EQ(APSInt("-1234").getExtValue(), -1234);
}
#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
TEST(APSIntTest, StringDeath) {
EXPECT_DEATH(APSInt(""), "Invalid string length");
EXPECT_DEATH(APSInt("1a"), "Invalid character in digit string");
}
#endif
} // end anonymous namespace

View File

@ -1,252 +0,0 @@
//===- llvm/unittest/ADT/ArrayRefTest.cpp - ArrayRef unit 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/ArrayRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#include <limits>
#include <vector>
using namespace llvm;
// Check that the ArrayRef-of-pointer converting constructor only allows adding
// cv qualifiers (not removing them, or otherwise changing the type)
static_assert(
std::is_convertible<ArrayRef<int *>, ArrayRef<const int *>>::value,
"Adding const");
static_assert(
std::is_convertible<ArrayRef<int *>, ArrayRef<volatile int *>>::value,
"Adding volatile");
static_assert(!std::is_convertible<ArrayRef<int *>, ArrayRef<float *>>::value,
"Changing pointer of one type to a pointer of another");
static_assert(
!std::is_convertible<ArrayRef<const int *>, ArrayRef<int *>>::value,
"Removing const");
static_assert(
!std::is_convertible<ArrayRef<volatile int *>, ArrayRef<int *>>::value,
"Removing volatile");
// Check that we can't accidentally assign a temporary location to an ArrayRef.
// (Unfortunately we can't make use of the same thing with constructors.)
//
// Disable this check under MSVC; even MSVC 2015 isn't inconsistent between
// std::is_assignable and actually writing such an assignment.
#if !defined(_MSC_VER)
static_assert(
!std::is_assignable<ArrayRef<int *>, int *>::value,
"Assigning from single prvalue element");
static_assert(
!std::is_assignable<ArrayRef<int *>, int * &&>::value,
"Assigning from single xvalue element");
static_assert(
std::is_assignable<ArrayRef<int *>, int * &>::value,
"Assigning from single lvalue element");
static_assert(
!std::is_assignable<ArrayRef<int *>, std::initializer_list<int *>>::value,
"Assigning from an initializer list");
#endif
namespace {
TEST(ArrayRefTest, AllocatorCopy) {
BumpPtrAllocator Alloc;
static const uint16_t Words1[] = { 1, 4, 200, 37 };
ArrayRef<uint16_t> Array1 = makeArrayRef(Words1, 4);
static const uint16_t Words2[] = { 11, 4003, 67, 64000, 13 };
ArrayRef<uint16_t> Array2 = makeArrayRef(Words2, 5);
ArrayRef<uint16_t> Array1c = Array1.copy(Alloc);
ArrayRef<uint16_t> Array2c = Array2.copy(Alloc);
EXPECT_TRUE(Array1.equals(Array1c));
EXPECT_NE(Array1.data(), Array1c.data());
EXPECT_TRUE(Array2.equals(Array2c));
EXPECT_NE(Array2.data(), Array2c.data());
// Check that copy can cope with uninitialized memory.
struct NonAssignable {
const char *Ptr;
NonAssignable(const char *Ptr) : Ptr(Ptr) {}
NonAssignable(const NonAssignable &RHS) = default;
void operator=(const NonAssignable &RHS) { assert(RHS.Ptr != nullptr); }
bool operator==(const NonAssignable &RHS) const { return Ptr == RHS.Ptr; }
} Array3Src[] = {"hello", "world"};
ArrayRef<NonAssignable> Array3Copy = makeArrayRef(Array3Src).copy(Alloc);
EXPECT_EQ(makeArrayRef(Array3Src), Array3Copy);
EXPECT_NE(makeArrayRef(Array3Src).data(), Array3Copy.data());
}
TEST(ArrayRefTest, SizeTSizedOperations) {
ArrayRef<char> AR(nullptr, std::numeric_limits<ptrdiff_t>::max());
// Check that drop_back accepts size_t-sized numbers.
EXPECT_EQ(1U, AR.drop_back(AR.size() - 1).size());
// Check that drop_front accepts size_t-sized numbers.
EXPECT_EQ(1U, AR.drop_front(AR.size() - 1).size());
// Check that slice accepts size_t-sized numbers.
EXPECT_EQ(1U, AR.slice(AR.size() - 1).size());
EXPECT_EQ(AR.size() - 1, AR.slice(1, AR.size() - 1).size());
}
TEST(ArrayRefTest, DropBack) {
static const int TheNumbers[] = {4, 8, 15, 16, 23, 42};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> AR2(TheNumbers, AR1.size() - 1);
EXPECT_TRUE(AR1.drop_back().equals(AR2));
}
TEST(ArrayRefTest, DropFront) {
static const int TheNumbers[] = {4, 8, 15, 16, 23, 42};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> AR2(&TheNumbers[2], AR1.size() - 2);
EXPECT_TRUE(AR1.drop_front(2).equals(AR2));
}
TEST(ArrayRefTest, DropWhile) {
static const int TheNumbers[] = {1, 3, 5, 8, 10, 11};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> Expected = AR1.drop_front(3);
EXPECT_EQ(Expected, AR1.drop_while([](const int &N) { return N % 2 == 1; }));
EXPECT_EQ(AR1, AR1.drop_while([](const int &N) { return N < 0; }));
EXPECT_EQ(ArrayRef<int>(),
AR1.drop_while([](const int &N) { return N > 0; }));
}
TEST(ArrayRefTest, DropUntil) {
static const int TheNumbers[] = {1, 3, 5, 8, 10, 11};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> Expected = AR1.drop_front(3);
EXPECT_EQ(Expected, AR1.drop_until([](const int &N) { return N % 2 == 0; }));
EXPECT_EQ(ArrayRef<int>(),
AR1.drop_until([](const int &N) { return N < 0; }));
EXPECT_EQ(AR1, AR1.drop_until([](const int &N) { return N > 0; }));
}
TEST(ArrayRefTest, TakeBack) {
static const int TheNumbers[] = {4, 8, 15, 16, 23, 42};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> AR2(AR1.end() - 1, 1);
EXPECT_TRUE(AR1.take_back().equals(AR2));
}
TEST(ArrayRefTest, TakeFront) {
static const int TheNumbers[] = {4, 8, 15, 16, 23, 42};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> AR2(AR1.data(), 2);
EXPECT_TRUE(AR1.take_front(2).equals(AR2));
}
TEST(ArrayRefTest, TakeWhile) {
static const int TheNumbers[] = {1, 3, 5, 8, 10, 11};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> Expected = AR1.take_front(3);
EXPECT_EQ(Expected, AR1.take_while([](const int &N) { return N % 2 == 1; }));
EXPECT_EQ(ArrayRef<int>(),
AR1.take_while([](const int &N) { return N < 0; }));
EXPECT_EQ(AR1, AR1.take_while([](const int &N) { return N > 0; }));
}
TEST(ArrayRefTest, TakeUntil) {
static const int TheNumbers[] = {1, 3, 5, 8, 10, 11};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> Expected = AR1.take_front(3);
EXPECT_EQ(Expected, AR1.take_until([](const int &N) { return N % 2 == 0; }));
EXPECT_EQ(AR1, AR1.take_until([](const int &N) { return N < 0; }));
EXPECT_EQ(ArrayRef<int>(),
AR1.take_until([](const int &N) { return N > 0; }));
}
TEST(ArrayRefTest, Equals) {
static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};
ArrayRef<int> AR1(A1);
EXPECT_TRUE(AR1.equals({1, 2, 3, 4, 5, 6, 7, 8}));
EXPECT_FALSE(AR1.equals({8, 1, 2, 4, 5, 6, 6, 7}));
EXPECT_FALSE(AR1.equals({2, 4, 5, 6, 6, 7, 8, 1}));
EXPECT_FALSE(AR1.equals({0, 1, 2, 4, 5, 6, 6, 7}));
EXPECT_FALSE(AR1.equals({1, 2, 42, 4, 5, 6, 7, 8}));
EXPECT_FALSE(AR1.equals({42, 2, 3, 4, 5, 6, 7, 8}));
EXPECT_FALSE(AR1.equals({1, 2, 3, 4, 5, 6, 7, 42}));
EXPECT_FALSE(AR1.equals({1, 2, 3, 4, 5, 6, 7}));
EXPECT_FALSE(AR1.equals({1, 2, 3, 4, 5, 6, 7, 8, 9}));
ArrayRef<int> AR1a = AR1.drop_back();
EXPECT_TRUE(AR1a.equals({1, 2, 3, 4, 5, 6, 7}));
EXPECT_FALSE(AR1a.equals({1, 2, 3, 4, 5, 6, 7, 8}));
ArrayRef<int> AR1b = AR1a.slice(2, 4);
EXPECT_TRUE(AR1b.equals({3, 4, 5, 6}));
EXPECT_FALSE(AR1b.equals({2, 3, 4, 5, 6}));
EXPECT_FALSE(AR1b.equals({3, 4, 5, 6, 7}));
}
TEST(ArrayRefTest, EmptyEquals) {
EXPECT_TRUE(ArrayRef<unsigned>() == ArrayRef<unsigned>());
}
TEST(ArrayRefTest, ConstConvert) {
int buf[4];
for (int i = 0; i < 4; ++i)
buf[i] = i;
static int *A[] = {&buf[0], &buf[1], &buf[2], &buf[3]};
ArrayRef<const int *> a((ArrayRef<int *>(A)));
a = ArrayRef<int *>(A);
}
static std::vector<int> ReturnTest12() { return {1, 2}; }
static void ArgTest12(ArrayRef<int> A) {
EXPECT_EQ(2U, A.size());
EXPECT_EQ(1, A[0]);
EXPECT_EQ(2, A[1]);
}
TEST(ArrayRefTest, InitializerList) {
std::initializer_list<int> init_list = { 0, 1, 2, 3, 4 };
ArrayRef<int> A = init_list;
for (int i = 0; i < 5; ++i)
EXPECT_EQ(i, A[i]);
std::vector<int> B = ReturnTest12();
A = B;
EXPECT_EQ(1, A[0]);
EXPECT_EQ(2, A[1]);
ArgTest12({1, 2});
}
TEST(ArrayRefTest, EmptyInitializerList) {
ArrayRef<int> A = {};
EXPECT_TRUE(A.empty());
A = {};
EXPECT_TRUE(A.empty());
}
// Test that makeArrayRef works on ArrayRef (no-op)
TEST(ArrayRefTest, makeArrayRef) {
static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};
// No copy expected for non-const ArrayRef (true no-op)
ArrayRef<int> AR1(A1);
ArrayRef<int> &AR1Ref = makeArrayRef(AR1);
EXPECT_EQ(&AR1, &AR1Ref);
// A copy is expected for non-const ArrayRef (thin copy)
const ArrayRef<int> AR2(A1);
const ArrayRef<int> &AR2Ref = makeArrayRef(AR2);
EXPECT_NE(&AR2Ref, &AR2);
EXPECT_TRUE(AR2.equals(AR2Ref));
}
} // end anonymous namespace

File diff suppressed because it is too large Load Diff

View File

@ -1,134 +0,0 @@
//===- llvm/unittest/ADT/BitmaskEnumTest.cpp - BitmaskEnum unit 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/BitmaskEnum.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
enum Flags {
F0 = 0,
F1 = 1,
F2 = 2,
F3 = 4,
F4 = 8,
LLVM_MARK_AS_BITMASK_ENUM(F4)
};
TEST(BitmaskEnumTest, BitwiseOr) {
Flags f = F1 | F2;
EXPECT_EQ(3, f);
f = f | F3;
EXPECT_EQ(7, f);
}
TEST(BitmaskEnumTest, BitwiseOrEquals) {
Flags f = F1;
f |= F3;
EXPECT_EQ(5, f);
// |= should return a reference to the LHS.
f = F2;
(f |= F3) = F1;
EXPECT_EQ(F1, f);
}
TEST(BitmaskEnumTest, BitwiseAnd) {
Flags f = static_cast<Flags>(3) & F2;
EXPECT_EQ(F2, f);
f = (f | F3) & (F1 | F2 | F3);
EXPECT_EQ(6, f);
}
TEST(BitmaskEnumTest, BitwiseAndEquals) {
Flags f = F1 | F2 | F3;
f &= F1 | F2;
EXPECT_EQ(3, f);
// &= should return a reference to the LHS.
(f &= F1) = F3;
EXPECT_EQ(F3, f);
}
TEST(BitmaskEnumTest, BitwiseXor) {
Flags f = (F1 | F2) ^ (F2 | F3);
EXPECT_EQ(5, f);
f = f ^ F1;
EXPECT_EQ(4, f);
}
TEST(BitmaskEnumTest, BitwiseXorEquals) {
Flags f = (F1 | F2);
f ^= (F2 | F4);
EXPECT_EQ(9, f);
// ^= should return a reference to the LHS.
(f ^= F4) = F3;
EXPECT_EQ(F3, f);
}
TEST(BitmaskEnumTest, BitwiseNot) {
Flags f = ~F1;
EXPECT_EQ(14, f); // Largest value for f is 15.
EXPECT_EQ(15, ~F0);
}
enum class FlagsClass {
F0 = 0,
F1 = 1,
F2 = 2,
F3 = 4,
LLVM_MARK_AS_BITMASK_ENUM(F3)
};
TEST(BitmaskEnumTest, ScopedEnum) {
FlagsClass f = (FlagsClass::F1 & ~FlagsClass::F0) | FlagsClass::F2;
f |= FlagsClass::F3;
EXPECT_EQ(7, static_cast<int>(f));
}
struct Container {
enum Flags { F0 = 0, F1 = 1, F2 = 2, F3 = 4, LLVM_MARK_AS_BITMASK_ENUM(F3) };
static Flags getFlags() {
Flags f = F0 | F1;
f |= F2;
return f;
}
};
TEST(BitmaskEnumTest, EnumInStruct) { EXPECT_EQ(3, Container::getFlags()); }
} // namespace
namespace foo {
namespace bar {
namespace {
enum FlagsInNamespace {
F0 = 0,
F1 = 1,
F2 = 2,
F3 = 4,
LLVM_MARK_AS_BITMASK_ENUM(F3)
};
} // namespace
} // namespace foo
} // namespace bar
namespace {
TEST(BitmaskEnumTest, EnumInNamespace) {
foo::bar::FlagsInNamespace f = ~foo::bar::F0 & (foo::bar::F1 | foo::bar::F2);
f |= foo::bar::F3;
EXPECT_EQ(7, f);
}
} // namespace

View File

@ -1,74 +0,0 @@
//=== llvm/unittest/ADT/BreadthFirstIteratorTest.cpp - BFS iterator 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/BreadthFirstIterator.h"
#include "TestGraph.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace llvm {
TEST(BreadthFristIteratorTest, Basic) {
typedef bf_iterator<Graph<4>> BFIter;
Graph<4> G;
G.AddEdge(0, 1);
G.AddEdge(0, 2);
G.AddEdge(1, 3);
auto It = BFIter::begin(G);
auto End = BFIter::end(G);
EXPECT_EQ(It.getLevel(), 0U);
EXPECT_EQ(*It, G.AccessNode(0));
++It;
EXPECT_EQ(It.getLevel(), 1U);
EXPECT_EQ(*It, G.AccessNode(1));
++It;
EXPECT_EQ(It.getLevel(), 1U);
EXPECT_EQ(*It, G.AccessNode(2));
++It;
EXPECT_EQ(It.getLevel(), 2U);
EXPECT_EQ(*It, G.AccessNode(3));
++It;
EXPECT_EQ(It, End);
}
TEST(BreadthFristIteratorTest, Cycle) {
typedef bf_iterator<Graph<4>> BFIter;
Graph<4> G;
G.AddEdge(0, 1);
G.AddEdge(1, 0);
G.AddEdge(1, 2);
G.AddEdge(2, 1);
G.AddEdge(2, 1);
G.AddEdge(2, 3);
G.AddEdge(3, 2);
G.AddEdge(3, 1);
G.AddEdge(3, 0);
auto It = BFIter::begin(G);
auto End = BFIter::end(G);
EXPECT_EQ(It.getLevel(), 0U);
EXPECT_EQ(*It, G.AccessNode(0));
++It;
EXPECT_EQ(It.getLevel(), 1U);
EXPECT_EQ(*It, G.AccessNode(1));
++It;
EXPECT_EQ(It.getLevel(), 2U);
EXPECT_EQ(*It, G.AccessNode(2));
++It;
EXPECT_EQ(It.getLevel(), 3U);
EXPECT_EQ(*It, G.AccessNode(3));
++It;
EXPECT_EQ(It, End);
}
} // end namespace llvm

View File

@ -1,243 +0,0 @@
//===- unittests/ADT/BumpPtrListTest.cpp - BumpPtrList unit 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/AllocatorList.h"
#include "llvm/ADT/STLExtras.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
struct CountsDestructors {
static unsigned NumCalls;
~CountsDestructors() { ++NumCalls; }
};
unsigned CountsDestructors::NumCalls = 0;
struct MoveOnly {
int V;
explicit MoveOnly(int V) : V(V) {}
MoveOnly() = delete;
MoveOnly(MoveOnly &&X) { V = X.V; }
MoveOnly(const MoveOnly &X) = delete;
MoveOnly &operator=(MoveOnly &&X) = delete;
MoveOnly &operator=(const MoveOnly &X) = delete;
};
struct EmplaceOnly {
int V1, V2;
explicit EmplaceOnly(int V1, int V2) : V1(V1), V2(V2) {}
EmplaceOnly() = delete;
EmplaceOnly(EmplaceOnly &&X) = delete;
EmplaceOnly(const EmplaceOnly &X) = delete;
EmplaceOnly &operator=(EmplaceOnly &&X) = delete;
EmplaceOnly &operator=(const EmplaceOnly &X) = delete;
};
TEST(BumpPtrListTest, DefaultConstructor) {
BumpPtrList<int> L;
EXPECT_TRUE(L.empty());
}
TEST(BumpPtrListTest, pushPopBack) {
// Build a list with push_back.
BumpPtrList<int> L;
int Ns[] = {1, 3, 9, 5, 7};
for (const int N : Ns)
L.push_back(N);
// Use iterators to check contents.
auto I = L.begin();
for (int N : Ns)
EXPECT_EQ(N, *I++);
EXPECT_EQ(I, L.end());
// Unbuild the list with pop_back.
for (int N : llvm::reverse(Ns)) {
EXPECT_EQ(N, L.back());
L.pop_back();
}
EXPECT_TRUE(L.empty());
}
TEST(BumpPtrListTest, pushPopFront) {
// Build a list with push_front.
BumpPtrList<int> L;
int Ns[] = {1, 3, 9, 5, 7};
for (const int N : Ns)
L.push_front(N);
// Use reverse iterators to check contents.
auto I = L.rbegin();
for (int N : Ns)
EXPECT_EQ(N, *I++);
EXPECT_EQ(I, L.rend());
// Unbuild the list with pop_front.
for (int N : llvm::reverse(Ns)) {
EXPECT_EQ(N, L.front());
L.pop_front();
}
EXPECT_TRUE(L.empty());
}
TEST(BumpPtrListTest, pushBackMoveOnly) {
BumpPtrList<MoveOnly> L;
int Ns[] = {1, 3, 9, 5, 7};
for (const int N : Ns) {
L.push_back(MoveOnly(N));
EXPECT_EQ(N, L.back().V);
}
// Instantiate with MoveOnly.
while (!L.empty())
L.pop_back();
}
TEST(BumpPtrListTest, pushFrontMoveOnly) {
BumpPtrList<MoveOnly> L;
int Ns[] = {1, 3, 9, 5, 7};
for (const int N : Ns) {
L.push_front(MoveOnly(N));
EXPECT_EQ(N, L.front().V);
}
// Instantiate with MoveOnly.
while (!L.empty())
L.pop_front();
}
TEST(BumpPtrListTest, emplaceBack) {
BumpPtrList<EmplaceOnly> L;
int N1s[] = {1, 3, 9, 5, 7};
int N2s[] = {7, 3, 1, 8, 2};
for (int I = 0; I != 5; ++I) {
L.emplace_back(N1s[I], N2s[I]);
EXPECT_EQ(N1s[I], L.back().V1);
EXPECT_EQ(N2s[I], L.back().V2);
}
// Instantiate with EmplaceOnly.
while (!L.empty())
L.pop_back();
}
TEST(BumpPtrListTest, emplaceFront) {
BumpPtrList<EmplaceOnly> L;
int N1s[] = {1, 3, 9, 5, 7};
int N2s[] = {7, 3, 1, 8, 2};
for (int I = 0; I != 5; ++I) {
L.emplace_front(N1s[I], N2s[I]);
EXPECT_EQ(N1s[I], L.front().V1);
EXPECT_EQ(N2s[I], L.front().V2);
}
// Instantiate with EmplaceOnly.
while (!L.empty())
L.pop_front();
}
TEST(BumpPtrListTest, swap) {
// Build two lists with different lifetimes and swap them.
int N1s[] = {1, 3, 5, 7, 9};
int N2s[] = {2, 4, 6, 8, 10};
BumpPtrList<int> L1;
L1.insert(L1.end(), std::begin(N1s), std::end(N1s));
{
BumpPtrList<int> L2;
L2.insert(L2.end(), std::begin(N2s), std::end(N2s));
// Swap the lists.
L1.swap(L2);
// Check L2's contents before it goes out of scope.
auto I = L2.begin();
for (int N : N1s)
EXPECT_EQ(N, *I++);
EXPECT_EQ(I, L2.end());
}
// Check L1's contents now that L2 is out of scope (with its allocation
// blocks).
auto I = L1.begin();
for (int N : N2s)
EXPECT_EQ(N, *I++);
EXPECT_EQ(I, L1.end());
}
TEST(BumpPtrListTest, clear) {
CountsDestructors::NumCalls = 0;
CountsDestructors N;
BumpPtrList<CountsDestructors> L;
L.push_back(N);
L.push_back(N);
L.push_back(N);
EXPECT_EQ(3u, L.size());
EXPECT_EQ(0u, CountsDestructors::NumCalls);
L.pop_back();
EXPECT_EQ(1u, CountsDestructors::NumCalls);
L.clear();
EXPECT_EQ(3u, CountsDestructors::NumCalls);
}
TEST(BumpPtrListTest, move) {
BumpPtrList<int> L1, L2;
L1.push_back(1);
L2.push_back(2);
L1 = std::move(L2);
EXPECT_EQ(1u, L1.size());
EXPECT_EQ(2, L1.front());
EXPECT_EQ(0u, L2.size());
}
TEST(BumpPtrListTest, moveCallsDestructors) {
CountsDestructors::NumCalls = 0;
BumpPtrList<CountsDestructors> L1, L2;
L1.emplace_back();
EXPECT_EQ(0u, CountsDestructors::NumCalls);
L1 = std::move(L2);
EXPECT_EQ(1u, CountsDestructors::NumCalls);
}
TEST(BumpPtrListTest, copy) {
BumpPtrList<int> L1, L2;
L1.push_back(1);
L2.push_back(2);
L1 = L2;
EXPECT_EQ(1u, L1.size());
EXPECT_EQ(2, L1.front());
EXPECT_EQ(1u, L2.size());
EXPECT_EQ(2, L2.front());
}
TEST(BumpPtrListTest, copyCallsDestructors) {
CountsDestructors::NumCalls = 0;
BumpPtrList<CountsDestructors> L1, L2;
L1.emplace_back();
EXPECT_EQ(0u, CountsDestructors::NumCalls);
L1 = L2;
EXPECT_EQ(1u, CountsDestructors::NumCalls);
}
TEST(BumpPtrListTest, resetAlloc) {
// Resetting an empty list should work.
BumpPtrList<int> L;
// Resetting an empty list that has allocated should also work.
L.resetAlloc();
L.push_back(5);
L.erase(L.begin());
L.resetAlloc();
// Resetting a non-empty list should crash.
L.push_back(5);
#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
EXPECT_DEATH(L.resetAlloc(), "Cannot reset allocator if not empty");
#endif
}
} // end namespace

View File

@ -1,73 +0,0 @@
set(LLVM_LINK_COMPONENTS
Support
)
set(ADTSources
APFloatTest.cpp
APIntTest.cpp
APSIntTest.cpp
ArrayRefTest.cpp
BitmaskEnumTest.cpp
BitVectorTest.cpp
BreadthFirstIteratorTest.cpp
BumpPtrListTest.cpp
DAGDeltaAlgorithmTest.cpp
DeltaAlgorithmTest.cpp
DenseMapTest.cpp
DenseSetTest.cpp
DepthFirstIteratorTest.cpp
EquivalenceClassesTest.cpp
FoldingSet.cpp
FunctionRefTest.cpp
HashingTest.cpp
IListBaseTest.cpp
IListIteratorTest.cpp
IListNodeBaseTest.cpp
IListNodeTest.cpp
IListSentinelTest.cpp
IListTest.cpp
ImmutableMapTest.cpp
ImmutableSetTest.cpp
IntEqClassesTest.cpp
IntervalMapTest.cpp
IntrusiveRefCntPtrTest.cpp
IteratorTest.cpp
MakeUniqueTest.cpp
MappedIteratorTest.cpp
MapVectorTest.cpp
OptionalTest.cpp
PackedVectorTest.cpp
PointerEmbeddedIntTest.cpp
PointerIntPairTest.cpp
PointerSumTypeTest.cpp
PointerUnionTest.cpp
PostOrderIteratorTest.cpp
PriorityWorklistTest.cpp
RangeAdapterTest.cpp
SCCIteratorTest.cpp
STLExtrasTest.cpp
ScopeExitTest.cpp
SequenceTest.cpp
SetVectorTest.cpp
SimpleIListTest.cpp
SmallPtrSetTest.cpp
SmallStringTest.cpp
SmallVectorTest.cpp
SparseBitVectorTest.cpp
SparseMultiSetTest.cpp
SparseSetTest.cpp
StringExtrasTest.cpp
StringMapTest.cpp
StringRefTest.cpp
StringSwitchTest.cpp
TinyPtrVectorTest.cpp
TripleTest.cpp
TwineTest.cpp
VariadicFunctionTest.cpp
)
add_llvm_unittest(ADTTests
${ADTSources}
)
add_dependencies(ADTTests intrinsics_gen)

View File

@ -1,105 +0,0 @@
//===- llvm/unittest/ADT/DAGDeltaAlgorithmTest.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/DAGDeltaAlgorithm.h"
#include "gtest/gtest.h"
#include <algorithm>
#include <cstdarg>
using namespace llvm;
namespace {
typedef DAGDeltaAlgorithm::edge_ty edge_ty;
class FixedDAGDeltaAlgorithm : public DAGDeltaAlgorithm {
changeset_ty FailingSet;
unsigned NumTests;
protected:
bool ExecuteOneTest(const changeset_ty &Changes) override {
++NumTests;
return std::includes(Changes.begin(), Changes.end(),
FailingSet.begin(), FailingSet.end());
}
public:
FixedDAGDeltaAlgorithm(const changeset_ty &_FailingSet)
: FailingSet(_FailingSet),
NumTests(0) {}
unsigned getNumTests() const { return NumTests; }
};
std::set<unsigned> fixed_set(unsigned N, ...) {
std::set<unsigned> S;
va_list ap;
va_start(ap, N);
for (unsigned i = 0; i != N; ++i)
S.insert(va_arg(ap, unsigned));
va_end(ap);
return S;
}
std::set<unsigned> range(unsigned Start, unsigned End) {
std::set<unsigned> S;
while (Start != End)
S.insert(Start++);
return S;
}
std::set<unsigned> range(unsigned N) {
return range(0, N);
}
TEST(DAGDeltaAlgorithmTest, Basic) {
std::vector<edge_ty> Deps;
// Dependencies:
// 1 - 3
Deps.clear();
Deps.push_back(std::make_pair(3, 1));
// P = {3,5,7} \in S,
// [0, 20),
// should minimize to {1,3,5,7} in a reasonable number of tests.
FixedDAGDeltaAlgorithm FDA(fixed_set(3, 3, 5, 7));
EXPECT_EQ(fixed_set(4, 1, 3, 5, 7), FDA.Run(range(20), Deps));
EXPECT_GE(46U, FDA.getNumTests());
// Dependencies:
// 0 - 1
// \- 2 - 3
// \- 4
Deps.clear();
Deps.push_back(std::make_pair(1, 0));
Deps.push_back(std::make_pair(2, 0));
Deps.push_back(std::make_pair(4, 0));
Deps.push_back(std::make_pair(3, 2));
// This is a case where we must hold required changes.
//
// P = {1,3} \in S,
// [0, 5),
// should minimize to {0,1,2,3} in a small number of tests.
FixedDAGDeltaAlgorithm FDA2(fixed_set(2, 1, 3));
EXPECT_EQ(fixed_set(4, 0, 1, 2, 3), FDA2.Run(range(5), Deps));
EXPECT_GE(9U, FDA2.getNumTests());
// This is a case where we should quickly prune part of the tree.
//
// P = {4} \in S,
// [0, 5),
// should minimize to {0,4} in a small number of tests.
FixedDAGDeltaAlgorithm FDA3(fixed_set(1, 4));
EXPECT_EQ(fixed_set(2, 0, 4), FDA3.Run(range(5), Deps));
EXPECT_GE(6U, FDA3.getNumTests());
}
}

View File

@ -1,100 +0,0 @@
//===- llvm/unittest/ADT/DeltaAlgorithmTest.cpp ---------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/DeltaAlgorithm.h"
#include "gtest/gtest.h"
#include <algorithm>
#include <cstdarg>
using namespace llvm;
namespace std {
std::ostream &operator<<(std::ostream &OS,
const std::set<unsigned> &S) {
OS << "{";
for (std::set<unsigned>::const_iterator it = S.begin(),
ie = S.end(); it != ie; ++it) {
if (it != S.begin())
OS << ",";
OS << *it;
}
OS << "}";
return OS;
}
}
namespace {
class FixedDeltaAlgorithm final : public DeltaAlgorithm {
changeset_ty FailingSet;
unsigned NumTests;
protected:
bool ExecuteOneTest(const changeset_ty &Changes) override {
++NumTests;
return std::includes(Changes.begin(), Changes.end(),
FailingSet.begin(), FailingSet.end());
}
public:
FixedDeltaAlgorithm(const changeset_ty &_FailingSet)
: FailingSet(_FailingSet),
NumTests(0) {}
unsigned getNumTests() const { return NumTests; }
};
std::set<unsigned> fixed_set(unsigned N, ...) {
std::set<unsigned> S;
va_list ap;
va_start(ap, N);
for (unsigned i = 0; i != N; ++i)
S.insert(va_arg(ap, unsigned));
va_end(ap);
return S;
}
std::set<unsigned> range(unsigned Start, unsigned End) {
std::set<unsigned> S;
while (Start != End)
S.insert(Start++);
return S;
}
std::set<unsigned> range(unsigned N) {
return range(0, N);
}
TEST(DeltaAlgorithmTest, Basic) {
// P = {3,5,7} \in S
// [0, 20) should minimize to {3,5,7} in a reasonable number of tests.
std::set<unsigned> Fails = fixed_set(3, 3, 5, 7);
FixedDeltaAlgorithm FDA(Fails);
EXPECT_EQ(fixed_set(3, 3, 5, 7), FDA.Run(range(20)));
EXPECT_GE(33U, FDA.getNumTests());
// P = {3,5,7} \in S
// [10, 20) should minimize to [10,20)
EXPECT_EQ(range(10,20), FDA.Run(range(10,20)));
// P = [0,4) \in S
// [0, 4) should minimize to [0,4) in 11 tests.
//
// 11 = |{ {},
// {0}, {1}, {2}, {3},
// {1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2},
// {0, 1}, {2, 3} }|
FDA = FixedDeltaAlgorithm(range(10));
EXPECT_EQ(range(4), FDA.Run(range(4)));
EXPECT_EQ(11U, FDA.getNumTests());
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,201 +0,0 @@
//===- llvm/unittest/ADT/DenseSetTest.cpp - DenseSet unit tests --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/DenseSet.h"
#include "gtest/gtest.h"
#include <type_traits>
using namespace llvm;
namespace {
// Test hashing with a set of only two entries.
TEST(DenseSetTest, DoubleEntrySetTest) {
llvm::DenseSet<unsigned> set(2);
set.insert(0);
set.insert(1);
// Original failure was an infinite loop in this call:
EXPECT_EQ(0u, set.count(2));
}
struct TestDenseSetInfo {
static inline unsigned getEmptyKey() { return ~0; }
static inline unsigned getTombstoneKey() { return ~0U - 1; }
static unsigned getHashValue(const unsigned& Val) { return Val * 37U; }
static unsigned getHashValue(const char* Val) {
return (unsigned)(Val[0] - 'a') * 37U;
}
static bool isEqual(const unsigned& LHS, const unsigned& RHS) {
return LHS == RHS;
}
static bool isEqual(const char* LHS, const unsigned& RHS) {
return (unsigned)(LHS[0] - 'a') == RHS;
}
};
// Test fixture
template <typename T> class DenseSetTest : public testing::Test {
protected:
T Set = GetTestSet();
private:
static T GetTestSet() {
typename std::remove_const<T>::type Set;
Set.insert(0);
Set.insert(1);
Set.insert(2);
return Set;
}
};
// Register these types for testing.
typedef ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>,
const DenseSet<unsigned, TestDenseSetInfo>,
SmallDenseSet<unsigned, 1, TestDenseSetInfo>,
SmallDenseSet<unsigned, 4, TestDenseSetInfo>,
const SmallDenseSet<unsigned, 4, TestDenseSetInfo>,
SmallDenseSet<unsigned, 64, TestDenseSetInfo>>
DenseSetTestTypes;
TYPED_TEST_CASE(DenseSetTest, DenseSetTestTypes);
TYPED_TEST(DenseSetTest, InitializerList) {
TypeParam set({1, 2, 1, 4});
EXPECT_EQ(3u, set.size());
EXPECT_EQ(1u, set.count(1));
EXPECT_EQ(1u, set.count(2));
EXPECT_EQ(1u, set.count(4));
EXPECT_EQ(0u, set.count(3));
}
TYPED_TEST(DenseSetTest, ConstIteratorComparison) {
TypeParam set({1});
const TypeParam &cset = set;
EXPECT_EQ(set.begin(), cset.begin());
EXPECT_EQ(set.end(), cset.end());
EXPECT_NE(set.end(), cset.begin());
EXPECT_NE(set.begin(), cset.end());
}
TYPED_TEST(DenseSetTest, DefaultConstruction) {
typename TypeParam::iterator I, J;
typename TypeParam::const_iterator CI, CJ;
EXPECT_EQ(I, J);
EXPECT_EQ(CI, CJ);
}
TYPED_TEST(DenseSetTest, EmptyInitializerList) {
TypeParam set({});
EXPECT_EQ(0u, set.size());
EXPECT_EQ(0u, set.count(0));
}
TYPED_TEST(DenseSetTest, FindAsTest) {
auto &set = this->Set;
// Size tests
EXPECT_EQ(3u, set.size());
// Normal lookup tests
EXPECT_EQ(1u, set.count(1));
EXPECT_EQ(0u, *set.find(0));
EXPECT_EQ(1u, *set.find(1));
EXPECT_EQ(2u, *set.find(2));
EXPECT_TRUE(set.find(3) == set.end());
// find_as() tests
EXPECT_EQ(0u, *set.find_as("a"));
EXPECT_EQ(1u, *set.find_as("b"));
EXPECT_EQ(2u, *set.find_as("c"));
EXPECT_TRUE(set.find_as("d") == set.end());
}
// Simple class that counts how many moves and copy happens when growing a map
struct CountCopyAndMove {
static int Move;
static int Copy;
int Value;
CountCopyAndMove(int Value) : Value(Value) {}
CountCopyAndMove(const CountCopyAndMove &RHS) {
Value = RHS.Value;
Copy++;
}
CountCopyAndMove &operator=(const CountCopyAndMove &RHS) {
Value = RHS.Value;
Copy++;
return *this;
}
CountCopyAndMove(CountCopyAndMove &&RHS) {
Value = RHS.Value;
Move++;
}
CountCopyAndMove &operator=(const CountCopyAndMove &&RHS) {
Value = RHS.Value;
Move++;
return *this;
}
};
int CountCopyAndMove::Copy = 0;
int CountCopyAndMove::Move = 0;
} // anonymous namespace
namespace llvm {
// Specialization required to insert a CountCopyAndMove into a DenseSet.
template <> struct DenseMapInfo<CountCopyAndMove> {
static inline CountCopyAndMove getEmptyKey() { return CountCopyAndMove(-1); };
static inline CountCopyAndMove getTombstoneKey() {
return CountCopyAndMove(-2);
};
static unsigned getHashValue(const CountCopyAndMove &Val) {
return Val.Value;
}
static bool isEqual(const CountCopyAndMove &LHS,
const CountCopyAndMove &RHS) {
return LHS.Value == RHS.Value;
}
};
}
namespace {
// Make sure reserve actually gives us enough buckets to insert N items
// without increasing allocation size.
TEST(DenseSetCustomTest, ReserveTest) {
// Test a few different size, 48 is *not* a random choice: we need a value
// that is 2/3 of a power of two to stress the grow() condition, and the power
// of two has to be at least 64 because of minimum size allocation in the
// DenseMa. 66 is a value just above the 64 default init.
for (auto Size : {1, 2, 48, 66}) {
DenseSet<CountCopyAndMove> Set;
Set.reserve(Size);
unsigned MemorySize = Set.getMemorySize();
CountCopyAndMove::Copy = 0;
CountCopyAndMove::Move = 0;
for (int i = 0; i < Size; ++i)
Set.insert(CountCopyAndMove(i));
// Check that we didn't grow
EXPECT_EQ(MemorySize, Set.getMemorySize());
// Check that move was called the expected number of times
EXPECT_EQ(Size, CountCopyAndMove::Move);
// Check that no copy occured
EXPECT_EQ(0, CountCopyAndMove::Copy);
}
}
TEST(DenseSetCustomTest, ConstTest) {
// Test that const pointers work okay for count and find, even when the
// underlying map is a non-const pointer.
DenseSet<int *> Map;
int A;
int *B = &A;
const int *C = &A;
Map.insert(B);
EXPECT_EQ(Map.count(B), 1u);
EXPECT_EQ(Map.count(C), 1u);
EXPECT_NE(Map.find(B), Map.end());
EXPECT_NE(Map.find(C), Map.end());
}
}

View File

@ -1,54 +0,0 @@
//=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator 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/DepthFirstIterator.h"
#include "TestGraph.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace llvm {
template <typename T> struct CountedSet {
typedef typename SmallPtrSet<T, 4>::iterator iterator;
SmallPtrSet<T, 4> S;
int InsertVisited = 0;
std::pair<iterator, bool> insert(const T &Item) {
InsertVisited++;
return S.insert(Item);
}
size_t count(const T &Item) const { return S.count(Item); }
void completed(T) { }
};
template <typename T> class df_iterator_storage<CountedSet<T>, true> {
public:
df_iterator_storage(CountedSet<T> &VSet) : Visited(VSet) {}
CountedSet<T> &Visited;
};
TEST(DepthFirstIteratorTest, ActuallyUpdateIterator) {
typedef CountedSet<Graph<3>::NodeType *> StorageT;
typedef df_iterator<Graph<3>, StorageT, true> DFIter;
Graph<3> G;
G.AddEdge(0, 1);
G.AddEdge(0, 2);
StorageT S;
for (auto N : make_range(DFIter::begin(G, S), DFIter::end(G, S)))
(void)N;
EXPECT_EQ(3, S.InsertVisited);
}
}

View File

@ -1,85 +0,0 @@
//=== llvm/unittest/ADT/EquivalenceClassesTest.cpp - the structure 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/EquivalenceClasses.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace llvm {
TEST(EquivalenceClassesTest, NoMerges) {
EquivalenceClasses<int> EqClasses;
// Until we merged any sets, check that every element is only equivalent to
// itself.
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (i == j)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
else
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, SimpleMerge1) {
EquivalenceClasses<int> EqClasses;
// Check that once we merge (A, B), (B, C), (C, D), then all elements belong
// to one set.
EqClasses.unionSets(0, 1);
EqClasses.unionSets(1, 2);
EqClasses.unionSets(2, 3);
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, SimpleMerge2) {
EquivalenceClasses<int> EqClasses;
// Check that once we merge (A, B), (C, D), (A, C), then all elements belong
// to one set.
EqClasses.unionSets(0, 1);
EqClasses.unionSets(2, 3);
EqClasses.unionSets(0, 2);
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, TwoSets) {
EquivalenceClasses<int> EqClasses;
// Form sets of odd and even numbers, check that we split them into these
// two sets correcrly.
for (int i = 0; i < 30; i += 2)
EqClasses.unionSets(0, i);
for (int i = 1; i < 30; i += 2)
EqClasses.unionSets(1, i);
for (int i = 0; i < 30; i++)
for (int j = 0; j < 30; j++)
if (i % 2 == j % 2)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
else
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, MultipleSets) {
EquivalenceClasses<int> EqClasses;
// Split numbers from [0, 100) into sets so that values in the same set have
// equal remainders (mod 17).
for (int i = 0; i < 100; i++)
EqClasses.unionSets(i % 17, i);
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
if (i % 17 == j % 17)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
else
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
} // llvm

View File

@ -1,193 +0,0 @@
//===- llvm/unittest/ADT/FoldingSetTest.cpp -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// FoldingSet unit tests.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/FoldingSet.h"
#include "gtest/gtest.h"
#include <string>
using namespace llvm;
namespace {
// Unaligned string test.
TEST(FoldingSetTest, UnalignedStringTest) {
SCOPED_TRACE("UnalignedStringTest");
FoldingSetNodeID a, b;
// An aligned string.
std::string str1= "a test string";
a.AddString(str1);
// An unaligned string.
std::string str2 = ">" + str1;
b.AddString(str2.c_str() + 1);
EXPECT_EQ(a.ComputeHash(), b.ComputeHash());
}
TEST(FoldingSetTest, LongLongComparison) {
struct LongLongContainer : FoldingSetNode {
unsigned long long A, B;
LongLongContainer(unsigned long long A, unsigned long long B)
: A(A), B(B) {}
void Profile(FoldingSetNodeID &ID) const {
ID.AddInteger(A);
ID.AddInteger(B);
}
};
LongLongContainer C1((1ULL << 32) + 1, 1ULL);
LongLongContainer C2(1ULL, (1ULL << 32) + 1);
FoldingSet<LongLongContainer> Set;
EXPECT_EQ(&C1, Set.GetOrInsertNode(&C1));
EXPECT_EQ(&C2, Set.GetOrInsertNode(&C2));
EXPECT_EQ(2U, Set.size());
}
struct TrivialPair : public FoldingSetNode {
unsigned Key = 0;
unsigned Value = 0;
TrivialPair(unsigned K, unsigned V) : FoldingSetNode(), Key(K), Value(V) {}
void Profile(FoldingSetNodeID &ID) const {
ID.AddInteger(Key);
ID.AddInteger(Value);
}
};
TEST(FoldingSetTest, IDComparison) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
Trivial.InsertNode(&T);
void *InsertPos = nullptr;
FoldingSetNodeID ID;
T.Profile(ID);
TrivialPair *N = Trivial.FindNodeOrInsertPos(ID, InsertPos);
EXPECT_EQ(&T, N);
EXPECT_EQ(nullptr, InsertPos);
}
TEST(FoldingSetTest, MissedIDComparison) {
FoldingSet<TrivialPair> Trivial;
TrivialPair S(100, 42);
TrivialPair T(99, 42);
Trivial.InsertNode(&T);
void *InsertPos = nullptr;
FoldingSetNodeID ID;
S.Profile(ID);
TrivialPair *N = Trivial.FindNodeOrInsertPos(ID, InsertPos);
EXPECT_EQ(nullptr, N);
EXPECT_NE(nullptr, InsertPos);
}
TEST(FoldingSetTest, RemoveNodeThatIsPresent) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
Trivial.InsertNode(&T);
EXPECT_EQ(Trivial.size(), 1U);
bool WasThere = Trivial.RemoveNode(&T);
EXPECT_TRUE(WasThere);
EXPECT_EQ(0U, Trivial.size());
}
TEST(FoldingSetTest, RemoveNodeThatIsAbsent) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
bool WasThere = Trivial.RemoveNode(&T);
EXPECT_FALSE(WasThere);
EXPECT_EQ(0U, Trivial.size());
}
TEST(FoldingSetTest, GetOrInsertInserting) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
TrivialPair *N = Trivial.GetOrInsertNode(&T);
EXPECT_EQ(&T, N);
}
TEST(FoldingSetTest, GetOrInsertGetting) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
TrivialPair T2(99, 42);
Trivial.InsertNode(&T);
TrivialPair *N = Trivial.GetOrInsertNode(&T2);
EXPECT_EQ(&T, N);
}
TEST(FoldingSetTest, InsertAtPos) {
FoldingSet<TrivialPair> Trivial;
void *InsertPos = nullptr;
TrivialPair Finder(99, 42);
FoldingSetNodeID ID;
Finder.Profile(ID);
Trivial.FindNodeOrInsertPos(ID, InsertPos);
TrivialPair T(99, 42);
Trivial.InsertNode(&T, InsertPos);
EXPECT_EQ(1U, Trivial.size());
}
TEST(FoldingSetTest, EmptyIsTrue) {
FoldingSet<TrivialPair> Trivial;
EXPECT_TRUE(Trivial.empty());
}
TEST(FoldingSetTest, EmptyIsFalse) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
Trivial.InsertNode(&T);
EXPECT_FALSE(Trivial.empty());
}
TEST(FoldingSetTest, ClearOnEmpty) {
FoldingSet<TrivialPair> Trivial;
Trivial.clear();
EXPECT_TRUE(Trivial.empty());
}
TEST(FoldingSetTest, ClearOnNonEmpty) {
FoldingSet<TrivialPair> Trivial;
TrivialPair T(99, 42);
Trivial.InsertNode(&T);
Trivial.clear();
EXPECT_TRUE(Trivial.empty());
}
TEST(FoldingSetTest, CapacityLargerThanReserve) {
FoldingSet<TrivialPair> Trivial;
auto OldCapacity = Trivial.capacity();
Trivial.reserve(OldCapacity + 1);
EXPECT_GE(Trivial.capacity(), OldCapacity + 1);
}
TEST(FoldingSetTest, SmallReserveChangesNothing) {
FoldingSet<TrivialPair> Trivial;
auto OldCapacity = Trivial.capacity();
Trivial.reserve(OldCapacity - 1);
EXPECT_EQ(Trivial.capacity(), OldCapacity);
}
}

View File

@ -1,42 +0,0 @@
//===- llvm/unittest/ADT/MakeUniqueTest.cpp - make_unique unit 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/STLExtras.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
// Ensure that there is a default constructor and we can test for a null
// function_ref.
TEST(FunctionRefTest, Null) {
function_ref<int()> F;
EXPECT_FALSE(F);
auto L = [] { return 1; };
F = L;
EXPECT_TRUE(F);
F = {};
EXPECT_FALSE(F);
}
// Ensure that copies of a function_ref copy the underlying state rather than
// causing one function_ref to chain to the next.
TEST(FunctionRefTest, Copy) {
auto A = [] { return 1; };
auto B = [] { return 2; };
function_ref<int()> X = A;
function_ref<int()> Y = X;
X = B;
EXPECT_EQ(1, Y());
}
}

View File

@ -1,448 +0,0 @@
//===- llvm/unittest/ADT/HashingTest.cpp ----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Hashing.h unit tests.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/Hashing.h"
#include "llvm/Support/DataTypes.h"
#include "gtest/gtest.h"
#include <deque>
#include <list>
#include <map>
#include <vector>
namespace llvm {
// Helper for test code to print hash codes.
void PrintTo(const hash_code &code, std::ostream *os) {
*os << static_cast<size_t>(code);
}
// Fake an object that is recognized as hashable data to test super large
// objects.
struct LargeTestInteger { uint64_t arr[8]; };
struct NonPOD {
uint64_t x, y;
NonPOD(uint64_t x, uint64_t y) : x(x), y(y) {}
friend hash_code hash_value(const NonPOD &obj) {
return hash_combine(obj.x, obj.y);
}
};
namespace hashing {
namespace detail {
template <> struct is_hashable_data<LargeTestInteger> : std::true_type {};
} // namespace detail
} // namespace hashing
} // namespace llvm
using namespace llvm;
namespace {
enum TestEnumeration {
TE_Foo = 42,
TE_Bar = 43
};
TEST(HashingTest, HashValueBasicTest) {
int x = 42, y = 43, c = 'x';
void *p = nullptr;
uint64_t i = 71;
const unsigned ci = 71;
volatile int vi = 71;
const volatile int cvi = 71;
uintptr_t addr = reinterpret_cast<uintptr_t>(&y);
EXPECT_EQ(hash_value(42), hash_value(x));
EXPECT_EQ(hash_value(42), hash_value(TE_Foo));
EXPECT_NE(hash_value(42), hash_value(y));
EXPECT_NE(hash_value(42), hash_value(TE_Bar));
EXPECT_NE(hash_value(42), hash_value(p));
EXPECT_EQ(hash_value(71), hash_value(i));
EXPECT_EQ(hash_value(71), hash_value(ci));
EXPECT_EQ(hash_value(71), hash_value(vi));
EXPECT_EQ(hash_value(71), hash_value(cvi));
EXPECT_EQ(hash_value(c), hash_value('x'));
EXPECT_EQ(hash_value('4'), hash_value('0' + 4));
EXPECT_EQ(hash_value(addr), hash_value(&y));
}
TEST(HashingTest, HashValueStdPair) {
EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
EXPECT_NE(hash_combine(43, 42), hash_value(std::make_pair(42, 43)));
EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43ull)));
EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42, 43ull)));
EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43)));
// Note that pairs are implicitly flattened to a direct sequence of data and
// hashed efficiently as a consequence.
EXPECT_EQ(hash_combine(42, 43, 44),
hash_value(std::make_pair(42, std::make_pair(43, 44))));
EXPECT_EQ(hash_value(std::make_pair(42, std::make_pair(43, 44))),
hash_value(std::make_pair(std::make_pair(42, 43), 44)));
// Ensure that pairs which have padding bytes *inside* them don't get treated
// this way.
EXPECT_EQ(hash_combine('0', hash_combine(1ull, '2')),
hash_value(std::make_pair('0', std::make_pair(1ull, '2'))));
// Ensure that non-POD pairs don't explode the traits used.
NonPOD obj1(1, 2), obj2(3, 4), obj3(5, 6);
EXPECT_EQ(hash_combine(obj1, hash_combine(obj2, obj3)),
hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
}
TEST(HashingTest, HashValueStdString) {
std::string s = "Hello World!";
EXPECT_EQ(hash_combine_range(s.c_str(), s.c_str() + s.size()), hash_value(s));
EXPECT_EQ(hash_combine_range(s.c_str(), s.c_str() + s.size() - 1),
hash_value(s.substr(0, s.size() - 1)));
EXPECT_EQ(hash_combine_range(s.c_str() + 1, s.c_str() + s.size() - 1),
hash_value(s.substr(1, s.size() - 2)));
std::wstring ws = L"Hello Wide World!";
EXPECT_EQ(hash_combine_range(ws.c_str(), ws.c_str() + ws.size()),
hash_value(ws));
EXPECT_EQ(hash_combine_range(ws.c_str(), ws.c_str() + ws.size() - 1),
hash_value(ws.substr(0, ws.size() - 1)));
EXPECT_EQ(hash_combine_range(ws.c_str() + 1, ws.c_str() + ws.size() - 1),
hash_value(ws.substr(1, ws.size() - 2)));
}
template <typename T, size_t N> T *begin(T (&arr)[N]) { return arr; }
template <typename T, size_t N> T *end(T (&arr)[N]) { return arr + N; }
// Provide a dummy, hashable type designed for easy verification: its hash is
// the same as its value.
struct HashableDummy { size_t value; };
hash_code hash_value(HashableDummy dummy) { return dummy.value; }
TEST(HashingTest, HashCombineRangeBasicTest) {
// Leave this uninitialized in the hope that valgrind will catch bad reads.
int dummy;
hash_code dummy_hash = hash_combine_range(&dummy, &dummy);
EXPECT_NE(hash_code(0), dummy_hash);
const int arr1[] = { 1, 2, 3 };
hash_code arr1_hash = hash_combine_range(begin(arr1), end(arr1));
EXPECT_NE(dummy_hash, arr1_hash);
EXPECT_EQ(arr1_hash, hash_combine_range(begin(arr1), end(arr1)));
const std::vector<int> vec(begin(arr1), end(arr1));
EXPECT_EQ(arr1_hash, hash_combine_range(vec.begin(), vec.end()));
const std::list<int> list(begin(arr1), end(arr1));
EXPECT_EQ(arr1_hash, hash_combine_range(list.begin(), list.end()));
const std::deque<int> deque(begin(arr1), end(arr1));
EXPECT_EQ(arr1_hash, hash_combine_range(deque.begin(), deque.end()));
const int arr2[] = { 3, 2, 1 };
hash_code arr2_hash = hash_combine_range(begin(arr2), end(arr2));
EXPECT_NE(dummy_hash, arr2_hash);
EXPECT_NE(arr1_hash, arr2_hash);
const int arr3[] = { 1, 1, 2, 3 };
hash_code arr3_hash = hash_combine_range(begin(arr3), end(arr3));
EXPECT_NE(dummy_hash, arr3_hash);
EXPECT_NE(arr1_hash, arr3_hash);
const int arr4[] = { 1, 2, 3, 3 };
hash_code arr4_hash = hash_combine_range(begin(arr4), end(arr4));
EXPECT_NE(dummy_hash, arr4_hash);
EXPECT_NE(arr1_hash, arr4_hash);
const size_t arr5[] = { 1, 2, 3 };
const HashableDummy d_arr5[] = { {1}, {2}, {3} };
hash_code arr5_hash = hash_combine_range(begin(arr5), end(arr5));
hash_code d_arr5_hash = hash_combine_range(begin(d_arr5), end(d_arr5));
EXPECT_EQ(arr5_hash, d_arr5_hash);
}
TEST(HashingTest, HashCombineRangeLengthDiff) {
// Test that as only the length varies, we compute different hash codes for
// sequences.
std::map<size_t, size_t> code_to_size;
std::vector<char> all_one_c(256, '\xff');
for (unsigned Idx = 1, Size = all_one_c.size(); Idx < Size; ++Idx) {
hash_code code = hash_combine_range(&all_one_c[0], &all_one_c[0] + Idx);
std::map<size_t, size_t>::iterator
I = code_to_size.insert(std::make_pair(code, Idx)).first;
EXPECT_EQ(Idx, I->second);
}
code_to_size.clear();
std::vector<char> all_zero_c(256, '\0');
for (unsigned Idx = 1, Size = all_zero_c.size(); Idx < Size; ++Idx) {
hash_code code = hash_combine_range(&all_zero_c[0], &all_zero_c[0] + Idx);
std::map<size_t, size_t>::iterator
I = code_to_size.insert(std::make_pair(code, Idx)).first;
EXPECT_EQ(Idx, I->second);
}
code_to_size.clear();
std::vector<unsigned> all_one_int(512, -1);
for (unsigned Idx = 1, Size = all_one_int.size(); Idx < Size; ++Idx) {
hash_code code = hash_combine_range(&all_one_int[0], &all_one_int[0] + Idx);
std::map<size_t, size_t>::iterator
I = code_to_size.insert(std::make_pair(code, Idx)).first;
EXPECT_EQ(Idx, I->second);
}
code_to_size.clear();
std::vector<unsigned> all_zero_int(512, 0);
for (unsigned Idx = 1, Size = all_zero_int.size(); Idx < Size; ++Idx) {
hash_code code = hash_combine_range(&all_zero_int[0], &all_zero_int[0] + Idx);
std::map<size_t, size_t>::iterator
I = code_to_size.insert(std::make_pair(code, Idx)).first;
EXPECT_EQ(Idx, I->second);
}
}
TEST(HashingTest, HashCombineRangeGoldenTest) {
struct { const char *s; uint64_t hash; } golden_data[] = {
#if SIZE_MAX == UINT64_MAX
{ "a", 0xaeb6f9d5517c61f8ULL },
{ "ab", 0x7ab1edb96be496b4ULL },
{ "abc", 0xe38e60bf19c71a3fULL },
{ "abcde", 0xd24461a66de97f6eULL },
{ "abcdefgh", 0x4ef872ec411dec9dULL },
{ "abcdefghijklm", 0xe8a865539f4eadfeULL },
{ "abcdefghijklmnopqrstu", 0x261cdf85faaf4e79ULL },
{ "abcdefghijklmnopqrstuvwxyzabcdef", 0x43ba70e4198e3b2aULL },
{ "abcdefghijklmnopqrstuvwxyzabcdef"
"abcdefghijklmnopqrstuvwxyzghijkl"
"abcdefghijklmnopqrstuvwxyzmnopqr"
"abcdefghijklmnopqrstuvwxyzstuvwx"
"abcdefghijklmnopqrstuvwxyzyzabcd", 0xdcd57fb2afdf72beULL },
{ "a", 0xaeb6f9d5517c61f8ULL },
{ "aa", 0xf2b3b69a9736a1ebULL },
{ "aaa", 0xf752eb6f07b1cafeULL },
{ "aaaaa", 0x812bd21e1236954cULL },
{ "aaaaaaaa", 0xff07a2cff08ac587ULL },
{ "aaaaaaaaaaaaa", 0x84ac949d54d704ecULL },
{ "aaaaaaaaaaaaaaaaaaaaa", 0xcb2c8fb6be8f5648ULL },
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0xcc40ab7f164091b6ULL },
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0xc58e174c1e78ffe9ULL },
{ "z", 0x1ba160d7e8f8785cULL },
{ "zz", 0x2c5c03172f1285d7ULL },
{ "zzz", 0x9d2c4f4b507a2ac3ULL },
{ "zzzzz", 0x0f03b9031735693aULL },
{ "zzzzzzzz", 0xe674147c8582c08eULL },
{ "zzzzzzzzzzzzz", 0x3162d9fa6938db83ULL },
{ "zzzzzzzzzzzzzzzzzzzzz", 0x37b9a549e013620cULL },
{ "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 0x8921470aff885016ULL },
{ "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 0xf60fdcd9beb08441ULL },
{ "a", 0xaeb6f9d5517c61f8ULL },
{ "ab", 0x7ab1edb96be496b4ULL },
{ "aba", 0x3edb049950884d0aULL },
{ "ababa", 0x8f2de9e73a97714bULL },
{ "abababab", 0xee14a29ddf0ce54cULL },
{ "ababababababa", 0x38b3ddaada2d52b4ULL },
{ "ababababababababababa", 0xd3665364219f2b85ULL },
{ "abababababababababababababababab", 0xa75cd6afbf1bc972ULL },
{ "abababababababababababababababab"
"abababababababababababababababab"
"abababababababababababababababab"
"abababababababababababababababab"
"abababababababababababababababab", 0x840192d129f7a22bULL }
#elif SIZE_MAX == UINT32_MAX
{ "a", 0x000000004605f745ULL },
{ "ab", 0x00000000d5f06301ULL },
{ "abc", 0x00000000559fe1eeULL },
{ "abcde", 0x00000000424028d7ULL },
{ "abcdefgh", 0x000000007bb119f8ULL },
{ "abcdefghijklm", 0x00000000edbca513ULL },
{ "abcdefghijklmnopqrstu", 0x000000007c15712eULL },
{ "abcdefghijklmnopqrstuvwxyzabcdef", 0x000000000b3aad66ULL },
{ "abcdefghijklmnopqrstuvwxyzabcdef"
"abcdefghijklmnopqrstuvwxyzghijkl"
"abcdefghijklmnopqrstuvwxyzmnopqr"
"abcdefghijklmnopqrstuvwxyzstuvwx"
"abcdefghijklmnopqrstuvwxyzyzabcd", 0x000000008c758c8bULL },
{ "a", 0x000000004605f745ULL },
{ "aa", 0x00000000dc0a52daULL },
{ "aaa", 0x00000000b309274fULL },
{ "aaaaa", 0x00000000203b5ef6ULL },
{ "aaaaaaaa", 0x00000000a429e18fULL },
{ "aaaaaaaaaaaaa", 0x000000008662070bULL },
{ "aaaaaaaaaaaaaaaaaaaaa", 0x000000003f11151cULL },
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0x000000008600fe20ULL },
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0x000000004e0e0804ULL },
{ "z", 0x00000000c5e405e9ULL },
{ "zz", 0x00000000a8d8a2c6ULL },
{ "zzz", 0x00000000fc2af672ULL },
{ "zzzzz", 0x0000000047d9efe6ULL },
{ "zzzzzzzz", 0x0000000080d77794ULL },
{ "zzzzzzzzzzzzz", 0x00000000405f93adULL },
{ "zzzzzzzzzzzzzzzzzzzzz", 0x00000000fc72838dULL },
{ "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 0x000000007ce160f1ULL },
{ "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 0x00000000aed9ed1bULL },
{ "a", 0x000000004605f745ULL },
{ "ab", 0x00000000d5f06301ULL },
{ "aba", 0x00000000a85cd91bULL },
{ "ababa", 0x000000009e3bb52eULL },
{ "abababab", 0x000000002709b3b9ULL },
{ "ababababababa", 0x000000003a234174ULL },
{ "ababababababababababa", 0x000000005c63e5ceULL },
{ "abababababababababababababababab", 0x0000000013f74334ULL },
{ "abababababababababababababababab"
"abababababababababababababababab"
"abababababababababababababababab"
"abababababababababababababababab"
"abababababababababababababababab", 0x00000000c1a6f135ULL },
#else
#error This test only supports 64-bit and 32-bit systems.
#endif
};
for (unsigned i = 0; i < sizeof(golden_data)/sizeof(*golden_data); ++i) {
StringRef str = golden_data[i].s;
hash_code hash = hash_combine_range(str.begin(), str.end());
#if 0 // Enable this to generate paste-able text for the above structure.
std::string member_str = "\"" + str.str() + "\",";
fprintf(stderr, " { %-35s 0x%016llxULL },\n",
member_str.c_str(), static_cast<uint64_t>(hash));
#endif
EXPECT_EQ(static_cast<size_t>(golden_data[i].hash),
static_cast<size_t>(hash));
}
}
TEST(HashingTest, HashCombineBasicTest) {
// Hashing a sequence of homogenous types matches range hashing.
const int i1 = 42, i2 = 43, i3 = 123, i4 = 999, i5 = 0, i6 = 79;
const int arr1[] = { i1, i2, i3, i4, i5, i6 };
EXPECT_EQ(hash_combine_range(arr1, arr1 + 1), hash_combine(i1));
EXPECT_EQ(hash_combine_range(arr1, arr1 + 2), hash_combine(i1, i2));
EXPECT_EQ(hash_combine_range(arr1, arr1 + 3), hash_combine(i1, i2, i3));
EXPECT_EQ(hash_combine_range(arr1, arr1 + 4), hash_combine(i1, i2, i3, i4));
EXPECT_EQ(hash_combine_range(arr1, arr1 + 5),
hash_combine(i1, i2, i3, i4, i5));
EXPECT_EQ(hash_combine_range(arr1, arr1 + 6),
hash_combine(i1, i2, i3, i4, i5, i6));
// 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;
const HashableDummy d1 = { 1024 }, d2 = { 8888 }, d3 = { 9000000 };
const size_t arr2[] = { s1, s2, s3 };
EXPECT_EQ(hash_combine_range(begin(arr2), end(arr2)),
hash_combine(s1, s2, s3));
EXPECT_EQ(hash_combine(s1, s2, s3), hash_combine(s1, s2, d3));
EXPECT_EQ(hash_combine(s1, s2, s3), hash_combine(s1, d2, s3));
EXPECT_EQ(hash_combine(s1, s2, s3), hash_combine(d1, s2, s3));
EXPECT_EQ(hash_combine(s1, s2, s3), hash_combine(d1, d2, s3));
EXPECT_EQ(hash_combine(s1, s2, s3), hash_combine(d1, d2, d3));
// Permuting values causes hashes to change.
EXPECT_NE(hash_combine(i1, i1, i1), hash_combine(i1, i1, i2));
EXPECT_NE(hash_combine(i1, i1, i1), hash_combine(i1, i2, i1));
EXPECT_NE(hash_combine(i1, i1, i1), hash_combine(i2, i1, i1));
EXPECT_NE(hash_combine(i1, i1, i1), hash_combine(i2, i2, i1));
EXPECT_NE(hash_combine(i1, i1, i1), hash_combine(i2, i2, i2));
EXPECT_NE(hash_combine(i2, i1, i1), hash_combine(i1, i1, i2));
EXPECT_NE(hash_combine(i1, i1, i2), hash_combine(i1, i2, i1));
EXPECT_NE(hash_combine(i1, i2, i1), hash_combine(i2, i1, i1));
// Changing type w/o changing value causes hashes to change.
EXPECT_NE(hash_combine(i1, i2, i3), hash_combine((char)i1, i2, i3));
EXPECT_NE(hash_combine(i1, i2, i3), hash_combine(i1, (char)i2, i3));
EXPECT_NE(hash_combine(i1, i2, i3), hash_combine(i1, i2, (char)i3));
// This is array of uint64, but it should have the exact same byte pattern as
// an array of LargeTestIntegers.
const uint64_t bigarr[] = {
0xaaaaaaaaababababULL, 0xacacacacbcbcbcbcULL, 0xccddeeffeeddccbbULL,
0xdeadbeafdeadbeefULL, 0xfefefefededededeULL, 0xafafafafededededULL,
0xffffeeeeddddccccULL, 0xaaaacbcbffffababULL,
0xaaaaaaaaababababULL, 0xacacacacbcbcbcbcULL, 0xccddeeffeeddccbbULL,
0xdeadbeafdeadbeefULL, 0xfefefefededededeULL, 0xafafafafededededULL,
0xffffeeeeddddccccULL, 0xaaaacbcbffffababULL,
0xaaaaaaaaababababULL, 0xacacacacbcbcbcbcULL, 0xccddeeffeeddccbbULL,
0xdeadbeafdeadbeefULL, 0xfefefefededededeULL, 0xafafafafededededULL,
0xffffeeeeddddccccULL, 0xaaaacbcbffffababULL
};
// Hash a preposterously large integer, both aligned with the buffer and
// misaligned.
const LargeTestInteger li = { {
0xaaaaaaaaababababULL, 0xacacacacbcbcbcbcULL, 0xccddeeffeeddccbbULL,
0xdeadbeafdeadbeefULL, 0xfefefefededededeULL, 0xafafafafededededULL,
0xffffeeeeddddccccULL, 0xaaaacbcbffffababULL
} };
// Rotate the storage from 'li'.
const LargeTestInteger l2 = { {
0xacacacacbcbcbcbcULL, 0xccddeeffeeddccbbULL, 0xdeadbeafdeadbeefULL,
0xfefefefededededeULL, 0xafafafafededededULL, 0xffffeeeeddddccccULL,
0xaaaacbcbffffababULL, 0xaaaaaaaaababababULL
} };
const LargeTestInteger l3 = { {
0xccddeeffeeddccbbULL, 0xdeadbeafdeadbeefULL, 0xfefefefededededeULL,
0xafafafafededededULL, 0xffffeeeeddddccccULL, 0xaaaacbcbffffababULL,
0xaaaaaaaaababababULL, 0xacacacacbcbcbcbcULL
} };
EXPECT_EQ(hash_combine_range(begin(bigarr), end(bigarr)),
hash_combine(li, li, li));
EXPECT_EQ(hash_combine_range(bigarr, bigarr + 9),
hash_combine(bigarr[0], l2));
EXPECT_EQ(hash_combine_range(bigarr, bigarr + 10),
hash_combine(bigarr[0], bigarr[1], l3));
EXPECT_EQ(hash_combine_range(bigarr, bigarr + 17),
hash_combine(li, bigarr[0], l2));
EXPECT_EQ(hash_combine_range(bigarr, bigarr + 18),
hash_combine(li, bigarr[0], bigarr[1], l3));
EXPECT_EQ(hash_combine_range(bigarr, bigarr + 18),
hash_combine(bigarr[0], l2, bigarr[9], l3));
EXPECT_EQ(hash_combine_range(bigarr, bigarr + 20),
hash_combine(bigarr[0], l2, bigarr[9], l3, bigarr[18], bigarr[19]));
}
TEST(HashingTest, HashCombineArgs18) {
// This tests that we can pass in up to 18 args.
#define CHECK_SAME(...) \
EXPECT_EQ(hash_combine(__VA_ARGS__), hash_combine(__VA_ARGS__))
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8, 9);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7, 8);
CHECK_SAME(1, 2, 3, 4, 5, 6, 7);
CHECK_SAME(1, 2, 3, 4, 5, 6);
CHECK_SAME(1, 2, 3, 4, 5);
CHECK_SAME(1, 2, 3, 4);
CHECK_SAME(1, 2, 3);
CHECK_SAME(1, 2);
CHECK_SAME(1);
#undef CHECK_SAME
}
}

View File

@ -1,166 +0,0 @@
//===- unittests/ADT/IListBaseTest.cpp - ilist_base unit 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/ilist_base.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
// Test fixture.
template <typename T> class IListBaseTest : public ::testing::Test {};
// Test variants with the same test.
typedef ::testing::Types<ilist_base<false>, ilist_base<true>>
IListBaseTestTypes;
TYPED_TEST_CASE(IListBaseTest, IListBaseTestTypes);
TYPED_TEST(IListBaseTest, insertBeforeImpl) {
typedef TypeParam list_base_type;
typedef typename list_base_type::node_base_type node_base_type;
node_base_type S, A, B;
// [S] <-> [S]
S.setPrev(&S);
S.setNext(&S);
// [S] <-> A <-> [S]
list_base_type::insertBeforeImpl(S, A);
EXPECT_EQ(&A, S.getPrev());
EXPECT_EQ(&S, A.getPrev());
EXPECT_EQ(&A, S.getNext());
EXPECT_EQ(&S, A.getNext());
// [S] <-> A <-> B <-> [S]
list_base_type::insertBeforeImpl(S, B);
EXPECT_EQ(&B, S.getPrev());
EXPECT_EQ(&A, B.getPrev());
EXPECT_EQ(&S, A.getPrev());
EXPECT_EQ(&A, S.getNext());
EXPECT_EQ(&B, A.getNext());
EXPECT_EQ(&S, B.getNext());
}
TYPED_TEST(IListBaseTest, removeImpl) {
typedef TypeParam list_base_type;
typedef typename list_base_type::node_base_type node_base_type;
node_base_type S, A, B;
// [S] <-> A <-> B <-> [S]
S.setPrev(&S);
S.setNext(&S);
list_base_type::insertBeforeImpl(S, A);
list_base_type::insertBeforeImpl(S, B);
// [S] <-> B <-> [S]
list_base_type::removeImpl(A);
EXPECT_EQ(&B, S.getPrev());
EXPECT_EQ(&S, B.getPrev());
EXPECT_EQ(&B, S.getNext());
EXPECT_EQ(&S, B.getNext());
EXPECT_EQ(nullptr, A.getPrev());
EXPECT_EQ(nullptr, A.getNext());
// [S] <-> [S]
list_base_type::removeImpl(B);
EXPECT_EQ(&S, S.getPrev());
EXPECT_EQ(&S, S.getNext());
EXPECT_EQ(nullptr, B.getPrev());
EXPECT_EQ(nullptr, B.getNext());
}
TYPED_TEST(IListBaseTest, removeRangeImpl) {
typedef TypeParam list_base_type;
typedef typename list_base_type::node_base_type node_base_type;
node_base_type S, A, B, C, D;
// [S] <-> A <-> B <-> C <-> D <-> [S]
S.setPrev(&S);
S.setNext(&S);
list_base_type::insertBeforeImpl(S, A);
list_base_type::insertBeforeImpl(S, B);
list_base_type::insertBeforeImpl(S, C);
list_base_type::insertBeforeImpl(S, D);
// [S] <-> A <-> D <-> [S]
list_base_type::removeRangeImpl(B, D);
EXPECT_EQ(&D, S.getPrev());
EXPECT_EQ(&A, D.getPrev());
EXPECT_EQ(&S, A.getPrev());
EXPECT_EQ(&A, S.getNext());
EXPECT_EQ(&D, A.getNext());
EXPECT_EQ(&S, D.getNext());
EXPECT_EQ(nullptr, B.getPrev());
EXPECT_EQ(nullptr, C.getNext());
}
TYPED_TEST(IListBaseTest, removeRangeImplAllButSentinel) {
typedef TypeParam list_base_type;
typedef typename list_base_type::node_base_type node_base_type;
node_base_type S, A, B;
// [S] <-> A <-> B <-> [S]
S.setPrev(&S);
S.setNext(&S);
list_base_type::insertBeforeImpl(S, A);
list_base_type::insertBeforeImpl(S, B);
// [S] <-> [S]
list_base_type::removeRangeImpl(A, S);
EXPECT_EQ(&S, S.getPrev());
EXPECT_EQ(&S, S.getNext());
EXPECT_EQ(nullptr, A.getPrev());
EXPECT_EQ(nullptr, B.getNext());
}
TYPED_TEST(IListBaseTest, transferBeforeImpl) {
typedef TypeParam list_base_type;
typedef typename list_base_type::node_base_type node_base_type;
node_base_type S1, S2, A, B, C, D, E;
// [S1] <-> A <-> B <-> C <-> [S1]
S1.setPrev(&S1);
S1.setNext(&S1);
list_base_type::insertBeforeImpl(S1, A);
list_base_type::insertBeforeImpl(S1, B);
list_base_type::insertBeforeImpl(S1, C);
// [S2] <-> D <-> E <-> [S2]
S2.setPrev(&S2);
S2.setNext(&S2);
list_base_type::insertBeforeImpl(S2, D);
list_base_type::insertBeforeImpl(S2, E);
// [S1] <-> C <-> [S1]
list_base_type::transferBeforeImpl(D, A, C);
EXPECT_EQ(&C, S1.getPrev());
EXPECT_EQ(&S1, C.getPrev());
EXPECT_EQ(&C, S1.getNext());
EXPECT_EQ(&S1, C.getNext());
// [S2] <-> A <-> B <-> D <-> E <-> [S2]
EXPECT_EQ(&E, S2.getPrev());
EXPECT_EQ(&D, E.getPrev());
EXPECT_EQ(&B, D.getPrev());
EXPECT_EQ(&A, B.getPrev());
EXPECT_EQ(&S2, A.getPrev());
EXPECT_EQ(&A, S2.getNext());
EXPECT_EQ(&B, A.getNext());
EXPECT_EQ(&D, B.getNext());
EXPECT_EQ(&E, D.getNext());
EXPECT_EQ(&S2, E.getNext());
}
} // end namespace

View File

@ -1,174 +0,0 @@
//===- unittests/ADT/IListIteratorTest.cpp - ilist_iterator unit 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/simple_ilist.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
struct Node : ilist_node<Node> {};
TEST(IListIteratorTest, DefaultConstructor) {
simple_ilist<Node>::iterator I;
simple_ilist<Node>::reverse_iterator RI;
simple_ilist<Node>::const_iterator CI;
simple_ilist<Node>::const_reverse_iterator CRI;
EXPECT_EQ(nullptr, I.getNodePtr());
EXPECT_EQ(nullptr, CI.getNodePtr());
EXPECT_EQ(nullptr, RI.getNodePtr());
EXPECT_EQ(nullptr, CRI.getNodePtr());
EXPECT_EQ(I, I);
EXPECT_EQ(I, CI);
EXPECT_EQ(CI, I);
EXPECT_EQ(CI, CI);
EXPECT_EQ(RI, RI);
EXPECT_EQ(RI, CRI);
EXPECT_EQ(CRI, RI);
EXPECT_EQ(CRI, CRI);
EXPECT_EQ(I, RI.getReverse());
EXPECT_EQ(RI, I.getReverse());
}
TEST(IListIteratorTest, Empty) {
simple_ilist<Node> L;
// Check iterators of L.
EXPECT_EQ(L.begin(), L.end());
EXPECT_EQ(L.rbegin(), L.rend());
// Reverse of end should be rend (since the sentinel sits on both sides).
EXPECT_EQ(L.end(), L.rend().getReverse());
EXPECT_EQ(L.rend(), L.end().getReverse());
// Iterators shouldn't match default constructors.
simple_ilist<Node>::iterator I;
simple_ilist<Node>::reverse_iterator RI;
EXPECT_NE(I, L.begin());
EXPECT_NE(I, L.end());
EXPECT_NE(RI, L.rbegin());
EXPECT_NE(RI, L.rend());
}
TEST(IListIteratorTest, OneNodeList) {
simple_ilist<Node> L;
Node A;
L.insert(L.end(), A);
// Check address of reference.
EXPECT_EQ(&A, &*L.begin());
EXPECT_EQ(&A, &*L.rbegin());
// Check that the handle matches.
EXPECT_EQ(L.rbegin().getNodePtr(), L.begin().getNodePtr());
// Check iteration.
EXPECT_EQ(L.end(), ++L.begin());
EXPECT_EQ(L.begin(), --L.end());
EXPECT_EQ(L.rend(), ++L.rbegin());
EXPECT_EQ(L.rbegin(), --L.rend());
// Check conversions.
EXPECT_EQ(L.rbegin(), L.begin().getReverse());
EXPECT_EQ(L.begin(), L.rbegin().getReverse());
}
TEST(IListIteratorTest, TwoNodeList) {
simple_ilist<Node> L;
Node A, B;
L.insert(L.end(), A);
L.insert(L.end(), B);
// Check order.
EXPECT_EQ(&A, &*L.begin());
EXPECT_EQ(&B, &*++L.begin());
EXPECT_EQ(L.end(), ++++L.begin());
EXPECT_EQ(&B, &*L.rbegin());
EXPECT_EQ(&A, &*++L.rbegin());
EXPECT_EQ(L.rend(), ++++L.rbegin());
// Check conversions.
EXPECT_EQ(++L.rbegin(), L.begin().getReverse());
EXPECT_EQ(L.rbegin(), (++L.begin()).getReverse());
EXPECT_EQ(++L.begin(), L.rbegin().getReverse());
EXPECT_EQ(L.begin(), (++L.rbegin()).getReverse());
}
TEST(IListIteratorTest, CheckEraseForward) {
simple_ilist<Node> L;
Node A, B;
L.insert(L.end(), A);
L.insert(L.end(), B);
// Erase nodes.
auto I = L.begin();
EXPECT_EQ(&A, &*I);
L.remove(*I++);
EXPECT_EQ(&B, &*I);
L.remove(*I++);
EXPECT_EQ(L.end(), I);
}
TEST(IListIteratorTest, CheckEraseReverse) {
simple_ilist<Node> L;
Node A, B;
L.insert(L.end(), A);
L.insert(L.end(), B);
// Erase nodes.
auto RI = L.rbegin();
EXPECT_EQ(&B, &*RI);
L.remove(*RI++);
EXPECT_EQ(&A, &*RI);
L.remove(*RI++);
EXPECT_EQ(L.rend(), RI);
}
TEST(IListIteratorTest, ReverseConstructor) {
simple_ilist<Node> L;
const simple_ilist<Node> &CL = L;
Node A, B;
L.insert(L.end(), A);
L.insert(L.end(), B);
// Save typing.
typedef simple_ilist<Node>::iterator iterator;
typedef simple_ilist<Node>::reverse_iterator reverse_iterator;
typedef simple_ilist<Node>::const_iterator const_iterator;
typedef simple_ilist<Node>::const_reverse_iterator const_reverse_iterator;
// Check conversion values.
EXPECT_EQ(L.begin(), iterator(L.rend()));
EXPECT_EQ(++L.begin(), iterator(++L.rbegin()));
EXPECT_EQ(L.end(), iterator(L.rbegin()));
EXPECT_EQ(L.rbegin(), reverse_iterator(L.end()));
EXPECT_EQ(++L.rbegin(), reverse_iterator(++L.begin()));
EXPECT_EQ(L.rend(), reverse_iterator(L.begin()));
// Check const iterator constructors.
EXPECT_EQ(CL.begin(), const_iterator(L.rend()));
EXPECT_EQ(CL.begin(), const_iterator(CL.rend()));
EXPECT_EQ(CL.rbegin(), const_reverse_iterator(L.end()));
EXPECT_EQ(CL.rbegin(), const_reverse_iterator(CL.end()));
// Confirm lack of implicit conversions.
static_assert(!std::is_convertible<iterator, reverse_iterator>::value,
"unexpected implicit conversion");
static_assert(!std::is_convertible<reverse_iterator, iterator>::value,
"unexpected implicit conversion");
static_assert(
!std::is_convertible<const_iterator, const_reverse_iterator>::value,
"unexpected implicit conversion");
static_assert(
!std::is_convertible<const_reverse_iterator, const_iterator>::value,
"unexpected implicit conversion");
}
} // end namespace

Some files were not shown because too many files have changed in this diff Show More