Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 1 | //===- unittests/ADT/IListSentinelTest.cpp - ilist_sentinel unit tests ----===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/ilist_node.h" |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | |
| 15 | namespace { |
| 16 | |
Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 17 | template <class T, class... Options> struct PickSentinel { |
| 18 | typedef ilist_sentinel< |
| 19 | typename ilist_detail::compute_node_options<T, Options...>::type> |
| 20 | type; |
| 21 | }; |
| 22 | |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 23 | class Node : public ilist_node<Node> {}; |
Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 24 | class TrackingNode : public ilist_node<Node, ilist_sentinel_tracking<true>> {}; |
| 25 | typedef PickSentinel<Node>::type Sentinel; |
| 26 | typedef PickSentinel<Node, ilist_sentinel_tracking<true>>::type |
| 27 | TrackingSentinel; |
| 28 | typedef PickSentinel<Node, ilist_sentinel_tracking<false>>::type |
| 29 | NoTrackingSentinel; |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 30 | |
Duncan P. N. Exon Smith | 34c4d2a | 2016-09-10 16:55:06 +0000 | [diff] [blame] | 31 | struct LocalAccess : ilist_detail::NodeAccess { |
| 32 | using NodeAccess::getPrev; |
| 33 | using NodeAccess::getNext; |
| 34 | }; |
| 35 | |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 36 | TEST(IListSentinelTest, DefaultConstructor) { |
Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 37 | Sentinel S; |
Duncan P. N. Exon Smith | 34c4d2a | 2016-09-10 16:55:06 +0000 | [diff] [blame] | 38 | EXPECT_EQ(&S, LocalAccess::getPrev(S)); |
| 39 | EXPECT_EQ(&S, LocalAccess::getNext(S)); |
Joerg Sonnenberger | ece29ea | 2016-09-30 19:52:27 +0000 | [diff] [blame] | 40 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 41 | EXPECT_TRUE(S.isKnownSentinel()); |
| 42 | #else |
| 43 | EXPECT_FALSE(S.isKnownSentinel()); |
| 44 | #endif |
Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 45 | |
| 46 | TrackingSentinel TS; |
| 47 | NoTrackingSentinel NTS; |
| 48 | EXPECT_TRUE(TS.isSentinel()); |
| 49 | EXPECT_TRUE(TS.isKnownSentinel()); |
| 50 | EXPECT_FALSE(NTS.isKnownSentinel()); |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | TEST(IListSentinelTest, NormalNodeIsNotKnownSentinel) { |
| 54 | Node N; |
Duncan P. N. Exon Smith | 34c4d2a | 2016-09-10 16:55:06 +0000 | [diff] [blame] | 55 | EXPECT_EQ(nullptr, LocalAccess::getPrev(N)); |
| 56 | EXPECT_EQ(nullptr, LocalAccess::getNext(N)); |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 57 | EXPECT_FALSE(N.isKnownSentinel()); |
Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 58 | |
| 59 | TrackingNode TN; |
| 60 | EXPECT_FALSE(TN.isSentinel()); |
Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | } // end namespace |