[llvm-readobj] - Simplify stack-sizes.test test case.
[llvm-complete.git] / unittests / ADT / IListNodeBaseTest.cpp
blob65f85fc3a237e197b26f312422efd2eef846605e
1 //===- unittests/ADT/IListNodeBaseTest.cpp - ilist_node_base 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 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/ilist_node_base.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 typedef ilist_node_base<false> RawNode;
17 typedef ilist_node_base<true> TrackingNode;
19 TEST(IListNodeBaseTest, DefaultConstructor) {
20 RawNode A;
21 EXPECT_EQ(nullptr, A.getPrev());
22 EXPECT_EQ(nullptr, A.getNext());
23 EXPECT_FALSE(A.isKnownSentinel());
25 TrackingNode TA;
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) {
33 RawNode A, B, C;
34 A.setPrev(&B);
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());
42 A.setNext(&C);
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;
51 TA.setPrev(&TB);
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());
59 TA.setNext(&TC);
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.
70 RawNode A, B;
71 EXPECT_FALSE(A.isKnownSentinel());
72 A.setPrev(&B);
73 A.setNext(&B);
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.
83 TrackingNode TA, TB;
84 EXPECT_FALSE(TA.isKnownSentinel());
85 EXPECT_FALSE(TA.isSentinel());
86 TA.setPrev(&TB);
87 TA.setNext(&TB);
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());
99 } // end namespace