1 //===- unittests/ADT/IListSentinelTest.cpp - ilist_sentinel unit tests ----===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/ilist_node.h"
10 #include "gtest/gtest.h"
16 template <class T
, class... Options
> struct PickSentinel
{
17 typedef ilist_sentinel
<
18 typename
ilist_detail::compute_node_options
<T
, Options
...>::type
>
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
27 typedef PickSentinel
<Node
, ilist_sentinel_tracking
<false>>::type
30 struct LocalAccess
: ilist_detail::NodeAccess
{
31 using NodeAccess::getPrev
;
32 using NodeAccess::getNext
;
35 TEST(IListSentinelTest
, DefaultConstructor
) {
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());
42 EXPECT_FALSE(S
.isKnownSentinel());
46 NoTrackingSentinel NTS
;
47 EXPECT_TRUE(TS
.isSentinel());
48 EXPECT_TRUE(TS
.isKnownSentinel());
49 EXPECT_FALSE(NTS
.isKnownSentinel());
52 TEST(IListSentinelTest
, NormalNodeIsNotKnownSentinel
) {
54 EXPECT_EQ(nullptr, LocalAccess::getPrev(N
));
55 EXPECT_EQ(nullptr, LocalAccess::getNext(N
));
56 EXPECT_FALSE(N
.isKnownSentinel());
59 EXPECT_FALSE(TN
.isSentinel());