[Thumb1] AND with a constant operand can be converted into BIC
[llvm-core.git] / unittests / ADT / IListIteratorTest.cpp
blobddcab781b9badffbd7451a630a9637ccdb2d9d7b
1 //===- unittests/ADT/IListIteratorTest.cpp - ilist_iterator unit tests ----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/simple_ilist.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
15 namespace {
17 struct Node : ilist_node<Node> {};
19 TEST(IListIteratorTest, DefaultConstructor) {
20 simple_ilist<Node>::iterator I;
21 simple_ilist<Node>::reverse_iterator RI;
22 simple_ilist<Node>::const_iterator CI;
23 simple_ilist<Node>::const_reverse_iterator CRI;
24 EXPECT_EQ(nullptr, I.getNodePtr());
25 EXPECT_EQ(nullptr, CI.getNodePtr());
26 EXPECT_EQ(nullptr, RI.getNodePtr());
27 EXPECT_EQ(nullptr, CRI.getNodePtr());
28 EXPECT_EQ(I, I);
29 EXPECT_EQ(I, CI);
30 EXPECT_EQ(CI, I);
31 EXPECT_EQ(CI, CI);
32 EXPECT_EQ(RI, RI);
33 EXPECT_EQ(RI, CRI);
34 EXPECT_EQ(CRI, RI);
35 EXPECT_EQ(CRI, CRI);
36 EXPECT_EQ(I, RI.getReverse());
37 EXPECT_EQ(RI, I.getReverse());
40 TEST(IListIteratorTest, Empty) {
41 simple_ilist<Node> L;
43 // Check iterators of L.
44 EXPECT_EQ(L.begin(), L.end());
45 EXPECT_EQ(L.rbegin(), L.rend());
47 // Reverse of end should be rend (since the sentinel sits on both sides).
48 EXPECT_EQ(L.end(), L.rend().getReverse());
49 EXPECT_EQ(L.rend(), L.end().getReverse());
51 // Iterators shouldn't match default constructors.
52 simple_ilist<Node>::iterator I;
53 simple_ilist<Node>::reverse_iterator RI;
54 EXPECT_NE(I, L.begin());
55 EXPECT_NE(I, L.end());
56 EXPECT_NE(RI, L.rbegin());
57 EXPECT_NE(RI, L.rend());
60 TEST(IListIteratorTest, OneNodeList) {
61 simple_ilist<Node> L;
62 Node A;
63 L.insert(L.end(), A);
65 // Check address of reference.
66 EXPECT_EQ(&A, &*L.begin());
67 EXPECT_EQ(&A, &*L.rbegin());
69 // Check that the handle matches.
70 EXPECT_EQ(L.rbegin().getNodePtr(), L.begin().getNodePtr());
72 // Check iteration.
73 EXPECT_EQ(L.end(), ++L.begin());
74 EXPECT_EQ(L.begin(), --L.end());
75 EXPECT_EQ(L.rend(), ++L.rbegin());
76 EXPECT_EQ(L.rbegin(), --L.rend());
78 // Check conversions.
79 EXPECT_EQ(L.rbegin(), L.begin().getReverse());
80 EXPECT_EQ(L.begin(), L.rbegin().getReverse());
83 TEST(IListIteratorTest, TwoNodeList) {
84 simple_ilist<Node> L;
85 Node A, B;
86 L.insert(L.end(), A);
87 L.insert(L.end(), B);
89 // Check order.
90 EXPECT_EQ(&A, &*L.begin());
91 EXPECT_EQ(&B, &*++L.begin());
92 EXPECT_EQ(L.end(), ++++L.begin());
93 EXPECT_EQ(&B, &*L.rbegin());
94 EXPECT_EQ(&A, &*++L.rbegin());
95 EXPECT_EQ(L.rend(), ++++L.rbegin());
97 // Check conversions.
98 EXPECT_EQ(++L.rbegin(), L.begin().getReverse());
99 EXPECT_EQ(L.rbegin(), (++L.begin()).getReverse());
100 EXPECT_EQ(++L.begin(), L.rbegin().getReverse());
101 EXPECT_EQ(L.begin(), (++L.rbegin()).getReverse());
104 TEST(IListIteratorTest, CheckEraseForward) {
105 simple_ilist<Node> L;
106 Node A, B;
107 L.insert(L.end(), A);
108 L.insert(L.end(), B);
110 // Erase nodes.
111 auto I = L.begin();
112 EXPECT_EQ(&A, &*I);
113 L.remove(*I++);
114 EXPECT_EQ(&B, &*I);
115 L.remove(*I++);
116 EXPECT_EQ(L.end(), I);
119 TEST(IListIteratorTest, CheckEraseReverse) {
120 simple_ilist<Node> L;
121 Node A, B;
122 L.insert(L.end(), A);
123 L.insert(L.end(), B);
125 // Erase nodes.
126 auto RI = L.rbegin();
127 EXPECT_EQ(&B, &*RI);
128 L.remove(*RI++);
129 EXPECT_EQ(&A, &*RI);
130 L.remove(*RI++);
131 EXPECT_EQ(L.rend(), RI);
134 } // end namespace