1 //===- unittests/ADT/IListNodeBaseTest.cpp - ilist_node_base 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_base.h"
10 #include "gtest/gtest.h"
16 typedef ilist_node_base
<false> RawNode
;
17 typedef ilist_node_base
<true> TrackingNode
;
19 TEST(IListNodeBaseTest
, DefaultConstructor
) {
21 EXPECT_EQ(nullptr, A
.getPrev());
22 EXPECT_EQ(nullptr, A
.getNext());
23 EXPECT_FALSE(A
.isKnownSentinel());
26 EXPECT_EQ(nullptr, TA
.getPrev());
27 EXPECT_EQ(nullptr, TA
.getNext());
28 EXPECT_FALSE(TA
.isKnownSentinel());
29 EXPECT_FALSE(TA
.isSentinel());
32 TEST(IListNodeBaseTest
, setPrevAndNext
) {
35 EXPECT_EQ(&B
, A
.getPrev());
36 EXPECT_EQ(nullptr, A
.getNext());
37 EXPECT_EQ(nullptr, B
.getPrev());
38 EXPECT_EQ(nullptr, B
.getNext());
39 EXPECT_EQ(nullptr, C
.getPrev());
40 EXPECT_EQ(nullptr, C
.getNext());
43 EXPECT_EQ(&B
, A
.getPrev());
44 EXPECT_EQ(&C
, A
.getNext());
45 EXPECT_EQ(nullptr, B
.getPrev());
46 EXPECT_EQ(nullptr, B
.getNext());
47 EXPECT_EQ(nullptr, C
.getPrev());
48 EXPECT_EQ(nullptr, C
.getNext());
50 TrackingNode TA
, TB
, TC
;
52 EXPECT_EQ(&TB
, TA
.getPrev());
53 EXPECT_EQ(nullptr, TA
.getNext());
54 EXPECT_EQ(nullptr, TB
.getPrev());
55 EXPECT_EQ(nullptr, TB
.getNext());
56 EXPECT_EQ(nullptr, TC
.getPrev());
57 EXPECT_EQ(nullptr, TC
.getNext());
60 EXPECT_EQ(&TB
, TA
.getPrev());
61 EXPECT_EQ(&TC
, TA
.getNext());
62 EXPECT_EQ(nullptr, TB
.getPrev());
63 EXPECT_EQ(nullptr, TB
.getNext());
64 EXPECT_EQ(nullptr, TC
.getPrev());
65 EXPECT_EQ(nullptr, TC
.getNext());
68 TEST(IListNodeBaseTest
, isKnownSentinel
) {
69 // Without sentinel tracking.
71 EXPECT_FALSE(A
.isKnownSentinel());
74 EXPECT_EQ(&B
, A
.getPrev());
75 EXPECT_EQ(&B
, A
.getNext());
76 EXPECT_FALSE(A
.isKnownSentinel());
77 A
.initializeSentinel();
78 EXPECT_FALSE(A
.isKnownSentinel());
79 EXPECT_EQ(&B
, A
.getPrev());
80 EXPECT_EQ(&B
, A
.getNext());
82 // With sentinel tracking.
84 EXPECT_FALSE(TA
.isKnownSentinel());
85 EXPECT_FALSE(TA
.isSentinel());
88 EXPECT_EQ(&TB
, TA
.getPrev());
89 EXPECT_EQ(&TB
, TA
.getNext());
90 EXPECT_FALSE(TA
.isKnownSentinel());
91 EXPECT_FALSE(TA
.isSentinel());
92 TA
.initializeSentinel();
93 EXPECT_TRUE(TA
.isKnownSentinel());
94 EXPECT_TRUE(TA
.isSentinel());
95 EXPECT_EQ(&TB
, TA
.getPrev());
96 EXPECT_EQ(&TB
, TA
.getNext());