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