2016-12-14 08:15:57 +08:00
|
|
|
//===- llvm/unittest/ADT/ReverseIterationTest.cpp ------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// ReverseIteration unit tests.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2017-06-06 19:06:56 +08:00
|
|
|
#include "gtest/gtest.h"
|
2016-12-14 08:15:57 +08:00
|
|
|
|
|
|
|
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
TEST(ReverseIterationTest, SmallPtrSetTest) {
|
|
|
|
|
|
|
|
SmallPtrSet<void*, 4> Set;
|
|
|
|
void *Ptrs[] = { (void*)0x1, (void*)0x2, (void*)0x3, (void*)0x4 };
|
|
|
|
void *ReversePtrs[] = { (void*)0x4, (void*)0x3, (void*)0x2, (void*)0x1 };
|
|
|
|
|
|
|
|
for (auto *Ptr: Ptrs)
|
|
|
|
Set.insert(Ptr);
|
|
|
|
|
|
|
|
// Check forward iteration.
|
|
|
|
ReverseIterate<bool>::value = false;
|
|
|
|
for (const auto &Tuple : zip(Set, Ptrs))
|
|
|
|
ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));
|
|
|
|
|
2016-12-30 20:34:36 +08:00
|
|
|
// Check operator++ (post-increment) in forward iteration.
|
|
|
|
int i = 0;
|
|
|
|
for (auto begin = Set.begin(), end = Set.end();
|
|
|
|
begin != end; i++)
|
|
|
|
ASSERT_EQ(*begin++, Ptrs[i]);
|
|
|
|
|
2016-12-14 08:15:57 +08:00
|
|
|
// Check reverse iteration.
|
|
|
|
ReverseIterate<bool>::value = true;
|
|
|
|
for (const auto &Tuple : zip(Set, ReversePtrs))
|
|
|
|
ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));
|
2016-12-30 20:34:36 +08:00
|
|
|
|
|
|
|
// Check operator++ (post-increment) in reverse iteration.
|
|
|
|
i = 0;
|
|
|
|
for (auto begin = Set.begin(), end = Set.end();
|
|
|
|
begin != end; i++)
|
|
|
|
ASSERT_EQ(*begin++, ReversePtrs[i]);
|
|
|
|
|
2016-12-14 08:15:57 +08:00
|
|
|
}
|
|
|
|
#endif
|