diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/CMakeLists.txt | 3 | ||||
-rw-r--r-- | unittests/Support/IteratorTest.cpp | 59 |
2 files changed, 61 insertions, 1 deletions
diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index 4afa4fd701..44f80ac222 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -15,12 +15,13 @@ add_llvm_unittest(SupportTests EndianTest.cpp ErrorOrTest.cpp FileOutputBufferTest.cpp + IteratorTest.cpp LEB128Test.cpp LineIteratorTest.cpp LockFileManagerTest.cpp + MD5Test.cpp ManagedStatic.cpp MathExtrasTest.cpp - MD5Test.cpp MemoryBufferTest.cpp MemoryTest.cpp Path.cpp diff --git a/unittests/Support/IteratorTest.cpp b/unittests/Support/IteratorTest.cpp new file mode 100644 index 0000000000..3a16406d6f --- /dev/null +++ b/unittests/Support/IteratorTest.cpp @@ -0,0 +1,59 @@ +//===- IteratorTest.cpp - Unit tests for iterator utilities ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/SmallVector.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(PointeeIteratorTest, Basic) { + int arr[4] = { 1, 2, 3, 4 }; + SmallVector<int *, 4> V; + V.push_back(&arr[0]); + V.push_back(&arr[1]); + V.push_back(&arr[2]); + V.push_back(&arr[3]); + + typedef pointee_iterator<SmallVectorImpl<int *>::const_iterator> test_iterator; + + test_iterator Begin, End; + Begin = V.begin(); + End = test_iterator(V.end()); + + test_iterator I = Begin; + for (int i = 0; i < 4; ++i) { + EXPECT_EQ(*V[i], *I); + + EXPECT_EQ(I, Begin + i); + EXPECT_EQ(I, std::next(Begin, i)); + test_iterator J = Begin; + J += i; + EXPECT_EQ(I, J); + EXPECT_EQ(*V[i], Begin[i]); + + EXPECT_NE(I, End); + EXPECT_GT(End, I); + EXPECT_LT(I, End); + EXPECT_GE(I, Begin); + EXPECT_LE(Begin, I); + + EXPECT_EQ(i, I - Begin); + EXPECT_EQ(i, std::distance(Begin, I)); + EXPECT_EQ(Begin, I - i); + + test_iterator K = I++; + EXPECT_EQ(K, std::prev(I)); + } + EXPECT_EQ(End, I); +} + +} // anonymous namespace |