62 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ADT/ilist_node.h"10#include "gtest/gtest.h"11 12using namespace llvm;13 14namespace {15 16template <class T, class... Options> struct PickSentinel {17 using type = ilist_sentinel<18 typename ilist_detail::compute_node_options<T, Options...>::type>;19};20 21class Node : public ilist_node<Node> {};22class TrackingNode : public ilist_node<Node, ilist_sentinel_tracking<true>> {};23using Sentinel = PickSentinel<Node>::type;24using TrackingSentinel =25 PickSentinel<Node, ilist_sentinel_tracking<true>>::type;26using NoTrackingSentinel =27 PickSentinel<Node, ilist_sentinel_tracking<false>>::type;28 29struct LocalAccess : ilist_detail::NodeAccess {30 using NodeAccess::getPrev;31 using NodeAccess::getNext;32};33 34TEST(IListSentinelTest, DefaultConstructor) {35 Sentinel S;36 EXPECT_EQ(&S, LocalAccess::getPrev(S));37 EXPECT_EQ(&S, LocalAccess::getNext(S));38#if LLVM_ENABLE_ABI_BREAKING_CHECKS39 EXPECT_TRUE(S.isKnownSentinel());40#else41 EXPECT_FALSE(S.isKnownSentinel());42#endif43 44 TrackingSentinel TS;45 NoTrackingSentinel NTS;46 EXPECT_TRUE(TS.isSentinel());47 EXPECT_TRUE(TS.isKnownSentinel());48 EXPECT_FALSE(NTS.isKnownSentinel());49}50 51TEST(IListSentinelTest, NormalNodeIsNotKnownSentinel) {52 Node N;53 EXPECT_EQ(nullptr, LocalAccess::getPrev(N));54 EXPECT_EQ(nullptr, LocalAccess::getNext(N));55 EXPECT_FALSE(N.isKnownSentinel());56 57 TrackingNode TN;58 EXPECT_FALSE(TN.isSentinel());59}60 61} // end namespace62