| 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 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
|  | 4 | // See https://llvm.org/LICENSE.txt for license information. | 
|  | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 |  | 
| Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 9 | #include "llvm/ADT/ilist_node.h" | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 10 | #include "gtest/gtest.h" | 
|  | 11 |  | 
|  | 12 | using namespace llvm; | 
|  | 13 |  | 
|  | 14 | namespace { | 
|  | 15 |  | 
| Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 16 | template <class T, class... Options> struct PickSentinel { | 
|  | 17 | typedef ilist_sentinel< | 
|  | 18 | typename ilist_detail::compute_node_options<T, Options...>::type> | 
|  | 19 | type; | 
|  | 20 | }; | 
|  | 21 |  | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 22 | class Node : public ilist_node<Node> {}; | 
| Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 23 | class TrackingNode : public ilist_node<Node, ilist_sentinel_tracking<true>> {}; | 
|  | 24 | typedef PickSentinel<Node>::type Sentinel; | 
|  | 25 | typedef PickSentinel<Node, ilist_sentinel_tracking<true>>::type | 
|  | 26 | TrackingSentinel; | 
|  | 27 | typedef PickSentinel<Node, ilist_sentinel_tracking<false>>::type | 
|  | 28 | NoTrackingSentinel; | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 29 |  | 
| Duncan P. N. Exon Smith | 34c4d2a | 2016-09-10 16:55:06 +0000 | [diff] [blame] | 30 | struct LocalAccess : ilist_detail::NodeAccess { | 
|  | 31 | using NodeAccess::getPrev; | 
|  | 32 | using NodeAccess::getNext; | 
|  | 33 | }; | 
|  | 34 |  | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 35 | TEST(IListSentinelTest, DefaultConstructor) { | 
| Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 36 | Sentinel S; | 
| Duncan P. N. Exon Smith | 34c4d2a | 2016-09-10 16:55:06 +0000 | [diff] [blame] | 37 | EXPECT_EQ(&S, LocalAccess::getPrev(S)); | 
|  | 38 | EXPECT_EQ(&S, LocalAccess::getNext(S)); | 
| Joerg Sonnenberger | ece29ea | 2016-09-30 19:52:27 +0000 | [diff] [blame] | 39 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 40 | EXPECT_TRUE(S.isKnownSentinel()); | 
|  | 41 | #else | 
|  | 42 | EXPECT_FALSE(S.isKnownSentinel()); | 
|  | 43 | #endif | 
| Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 44 |  | 
|  | 45 | TrackingSentinel TS; | 
|  | 46 | NoTrackingSentinel NTS; | 
|  | 47 | EXPECT_TRUE(TS.isSentinel()); | 
|  | 48 | EXPECT_TRUE(TS.isKnownSentinel()); | 
|  | 49 | EXPECT_FALSE(NTS.isKnownSentinel()); | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 50 | } | 
|  | 51 |  | 
|  | 52 | TEST(IListSentinelTest, NormalNodeIsNotKnownSentinel) { | 
|  | 53 | Node N; | 
| Duncan P. N. Exon Smith | 34c4d2a | 2016-09-10 16:55:06 +0000 | [diff] [blame] | 54 | EXPECT_EQ(nullptr, LocalAccess::getPrev(N)); | 
|  | 55 | EXPECT_EQ(nullptr, LocalAccess::getNext(N)); | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 56 | EXPECT_FALSE(N.isKnownSentinel()); | 
| Duncan P. N. Exon Smith | 085bbf1 | 2016-09-11 16:20:53 +0000 | [diff] [blame] | 57 |  | 
|  | 58 | TrackingNode TN; | 
|  | 59 | EXPECT_FALSE(TN.isSentinel()); | 
| Duncan P. N. Exon Smith | 9f5c83b | 2016-08-22 22:21:07 +0000 | [diff] [blame] | 60 | } | 
|  | 61 |  | 
|  | 62 | } // end namespace |