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 
10 #include "llvm/ADT/ilist_node.h"
11 #include "gtest/gtest.h"
12 
13 using namespace llvm;
14 
15 namespace {
16 
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 
23 class Node : public ilist_node<Node> {};
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;
30 
31 struct LocalAccess : ilist_detail::NodeAccess {
32   using NodeAccess::getPrev;
33   using NodeAccess::getNext;
34 };
35 
TEST(IListSentinelTest,DefaultConstructor)36 TEST(IListSentinelTest, DefaultConstructor) {
37   Sentinel S;
38   EXPECT_EQ(&S, LocalAccess::getPrev(S));
39   EXPECT_EQ(&S, LocalAccess::getNext(S));
40 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
41   EXPECT_TRUE(S.isKnownSentinel());
42 #else
43   EXPECT_FALSE(S.isKnownSentinel());
44 #endif
45 
46   TrackingSentinel TS;
47   NoTrackingSentinel NTS;
48   EXPECT_TRUE(TS.isSentinel());
49   EXPECT_TRUE(TS.isKnownSentinel());
50   EXPECT_FALSE(NTS.isKnownSentinel());
51 }
52 
TEST(IListSentinelTest,NormalNodeIsNotKnownSentinel)53 TEST(IListSentinelTest, NormalNodeIsNotKnownSentinel) {
54   Node N;
55   EXPECT_EQ(nullptr, LocalAccess::getPrev(N));
56   EXPECT_EQ(nullptr, LocalAccess::getNext(N));
57   EXPECT_FALSE(N.isKnownSentinel());
58 
59   TrackingNode TN;
60   EXPECT_FALSE(TN.isSentinel());
61 }
62 
63 } // end namespace
64