summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/IListSentinelTest.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-22 22:21:07 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-22 22:21:07 +0000
commit9f5c83b914ff8d7094fef580cf86ecee784ad008 (patch)
treea5c1602d914d37877e2aa697ba5f50eb30bf425e /llvm/unittests/ADT/IListSentinelTest.cpp
parent49a8ebd7c1f73b9da4e2d85795e97f7928aff26b (diff)
downloadbcm5719-llvm-9f5c83b914ff8d7094fef580cf86ecee784ad008.tar.gz
bcm5719-llvm-9f5c83b914ff8d7094fef580cf86ecee784ad008.zip
ADT: Separate some list manipulation API into ilist_base, NFC
Separate algorithms in iplist<T> that don't depend on T into ilist_base, and unit test them. While I was adding unit tests for these algorithms anyway, I also added unit tests for ilist_node_base and ilist_sentinel<T>. To make the algorithms and unit tests easier to write, I also did the following minor changes as a drive-by: - encapsulate Prev/Next in ilist_node_base to so that algorithms are easier to read, and - update ilist_node_access API to take nodes by reference. There should be no real functionality change here. llvm-svn: 279484
Diffstat (limited to 'llvm/unittests/ADT/IListSentinelTest.cpp')
-rw-r--r--llvm/unittests/ADT/IListSentinelTest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/IListSentinelTest.cpp b/llvm/unittests/ADT/IListSentinelTest.cpp
new file mode 100644
index 00000000000..533421e8504
--- /dev/null
+++ b/llvm/unittests/ADT/IListSentinelTest.cpp
@@ -0,0 +1,37 @@
+//===- unittests/ADT/IListSentinelTest.cpp - ilist_sentinel 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.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+class Node : public ilist_node<Node> {};
+
+TEST(IListSentinelTest, DefaultConstructor) {
+ ilist_sentinel<Node> S;
+ EXPECT_EQ(&S, ilist_node_access::getPrev(S));
+ EXPECT_EQ(&S, ilist_node_access::getNext(S));
+#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
+ EXPECT_TRUE(S.isKnownSentinel());
+#else
+ EXPECT_FALSE(S.isKnownSentinel());
+#endif
+}
+
+TEST(IListSentinelTest, NormalNodeIsNotKnownSentinel) {
+ Node N;
+ EXPECT_EQ(nullptr, ilist_node_access::getPrev(N));
+ EXPECT_EQ(nullptr, ilist_node_access::getNext(N));
+ EXPECT_FALSE(N.isKnownSentinel());
+}
+
+} // end namespace
OpenPOWER on IntegriCloud