09a699a9624640983b36e6fe82c632eccc2cec6f
[oota-llvm.git] / unittests / ADT / ilistTest.cpp
1 //===- llvm/unittest/ADT/APInt.cpp - APInt 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 //===----------------------------------------------------------------------===//
9
10 #include <ostream>
11 #include "gtest/gtest.h"
12 #include "llvm/ADT/ilist.h"
13 #include "llvm/ADT/ilist_node.h"
14
15 using namespace llvm;
16
17 namespace {
18
19 struct Node : ilist_node<Node> {
20   int Value;
21
22   Node() {}
23   Node(int _Value) : Value(_Value) {}
24 };
25
26 TEST(ilistTest, Basic) {
27   ilist<Node> List;
28   List.push_back(Node(1));
29   EXPECT_EQ(1, List.back().Value);
30   EXPECT_EQ(0, List.back().getPrevNode());
31   EXPECT_EQ(0, List.back().getNextNode());
32
33   List.push_back(Node(2));
34   EXPECT_EQ(2, List.back().Value);
35   EXPECT_EQ(2, List.front().getNextNode()->Value);
36   EXPECT_EQ(1, List.back().getPrevNode()->Value);
37
38   const ilist<Node> &ConstList = List;
39   EXPECT_EQ(2, ConstList.back().Value);
40   EXPECT_EQ(2, ConstList.front().getNextNode()->Value);
41   EXPECT_EQ(1, ConstList.back().getPrevNode()->Value);
42 }
43
44 }