diff options
| author | Daniel Berlin <dberlin@dberlin.org> | 2017-03-07 18:47:52 +0000 |
|---|---|---|
| committer | Daniel Berlin <dberlin@dberlin.org> | 2017-03-07 18:47:52 +0000 |
| commit | 44296ea4db3e5055bd4c7ae5da31be285dc7ac34 (patch) | |
| tree | 8770e4a40a6296e9c1d3a7749868e0799ba60216 | |
| parent | 44b876e2591bd9bb6a989049d6b3524063cbfb9f (diff) | |
| download | bcm5719-llvm-44296ea4db3e5055bd4c7ae5da31be285dc7ac34.tar.gz bcm5719-llvm-44296ea4db3e5055bd4c7ae5da31be285dc7ac34.zip | |
Add unit tests for changes to SmallPtrSet and PointerLikeTypeTraits
llvm-svn: 297182
| -rw-r--r-- | llvm/unittests/ADT/SmallPtrSetTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp index d4d963fdc5b..bb9ee67b7eb 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -12,7 +12,9 @@ //===----------------------------------------------------------------------===// #include "gtest/gtest.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/PointerLikeTypeTraits.h" using namespace llvm; @@ -279,3 +281,34 @@ TEST(SmallPtrSetTest, EraseTest) { SmallPtrSet<int *, 2> A; checkEraseAndIterators(A); } + +// Verify that const pointers work for count and find even when the underlying +// SmallPtrSet is not for a const pointer type. +TEST(SmallPtrSetTest, ConstTest) { + SmallPtrSet<int *, 8> IntSet; + int A; + int *B = &A; + const int *C = &A; + IntSet.insert(B); + EXPECT_EQ(IntSet.count(B), 1u); + EXPECT_EQ(IntSet.count(C), 1u); + // FIXME: We can't unit test find right now because ABI_BREAKING_CHECKS breaks + // find(). + // EXPECT_NE(IntSet.find(B), IntSet.end()); + // EXPECT_NE(IntSet.find(C), IntSet.end()); +} + +// Verify that we automatically get the const version of PointerLikeTypeTraits +// filled in for us, even for a non-pointer type +using TestPair = PointerIntPair<int *, 1>; + +TEST(SmallPtrSetTest, ConstNonPtrTest) { + SmallPtrSet<TestPair, 8> IntSet; + int A[1]; + TestPair Pair(&A[0], 1); + IntSet.insert(Pair); + EXPECT_EQ(IntSet.count(Pair), 1u); + // FIXME: We can't unit test find right now because ABI_BREAKING_CHECKS breaks + // find(). + // EXPECT_NE(IntSet.find(Pair), IntSet.end()); +} |

