summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2017-10-04 20:27:34 +0000
committerpatrick <patrick@openbsd.org>2017-10-04 20:27:34 +0000
commit31eb748944903b7f4f38afda9851951ca9dfc1ae (patch)
tree9b95b6ea45d0874d75eb05b90c0840e191416439 /gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp
parentDon't try to handle IPv4-compatible IPv6 addresses (diff)
downloadwireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.tar.xz
wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.zip
Import LLVM 5.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp')
-rw-r--r--gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp b/gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp
index d4d963fdc5b..0070d1cbae1 100644
--- a/gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp
+++ b/gnu/llvm/unittests/ADT/SmallPtrSetTest.cpp
@@ -11,8 +11,10 @@
//
//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
+#include "gtest/gtest.h"
using namespace llvm;
@@ -279,3 +281,52 @@ TEST(SmallPtrSetTest, EraseTest) {
SmallPtrSet<int *, 2> A;
checkEraseAndIterators(A);
}
+
+// Verify that dereferencing and iteration work.
+TEST(SmallPtrSetTest, dereferenceAndIterate) {
+ int Ints[] = {0, 1, 2, 3, 4, 5, 6, 7};
+ SmallPtrSet<const int *, 4> S;
+ for (int &I : Ints) {
+ EXPECT_EQ(&I, *S.insert(&I).first);
+ EXPECT_EQ(&I, *S.find(&I));
+ }
+
+ // Iterate from each and count how many times each element is found.
+ int Found[sizeof(Ints)/sizeof(int)] = {0};
+ for (int &I : Ints)
+ for (auto F = S.find(&I), E = S.end(); F != E; ++F)
+ ++Found[*F - Ints];
+
+ // Sort. We should hit the first element just once and the final element N
+ // times.
+ std::sort(std::begin(Found), std::end(Found));
+ for (auto F = std::begin(Found), E = std::end(Found); F != E; ++F)
+ EXPECT_EQ(F - Found + 1, *F);
+}
+
+// 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);
+ 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);
+ EXPECT_NE(IntSet.find(Pair), IntSet.end());
+}