llvm/unittests/ADT/IListNodeBaseTest.cpp
Duncan P. N. Exon Smith fd2abc5908 ADT: Separate some list manipulation API into ilist_base, NFC
Separate algorithms in iplist<T> that don't depend on T into ilist_base,
and unit test them.

While I was adding unit tests for these algorithms anyway, I also added
unit tests for ilist_node_base and ilist_sentinel<T>.

To make the algorithms and unit tests easier to write, I also did the
following minor changes as a drive-by:
- encapsulate Prev/Next in ilist_node_base to so that algorithms are
  easier to read, and
- update ilist_node_access API to take nodes by reference.

There should be no real functionality change here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279484 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 22:21:07 +00:00

61 lines
1.5 KiB
C++

//===- unittests/ADT/IListNodeBaseTest.cpp - ilist_node_base unit tests ---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ilist_node.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
TEST(IListNodeBaseTest, DefaultConstructor) {
ilist_node_base A;
EXPECT_EQ(nullptr, A.getPrev());
EXPECT_EQ(nullptr, A.getNext());
EXPECT_FALSE(A.isKnownSentinel());
}
TEST(IListNodeBaseTest, setPrevAndNext) {
ilist_node_base A, B, C;
A.setPrev(&B);
EXPECT_EQ(&B, A.getPrev());
EXPECT_EQ(nullptr, A.getNext());
EXPECT_EQ(nullptr, B.getPrev());
EXPECT_EQ(nullptr, B.getNext());
EXPECT_EQ(nullptr, C.getPrev());
EXPECT_EQ(nullptr, C.getNext());
A.setNext(&C);
EXPECT_EQ(&B, A.getPrev());
EXPECT_EQ(&C, A.getNext());
EXPECT_EQ(nullptr, B.getPrev());
EXPECT_EQ(nullptr, B.getNext());
EXPECT_EQ(nullptr, C.getPrev());
EXPECT_EQ(nullptr, C.getNext());
}
TEST(IListNodeBaseTest, isKnownSentinel) {
ilist_node_base A, B;
EXPECT_FALSE(A.isKnownSentinel());
A.setPrev(&B);
A.setNext(&B);
EXPECT_EQ(&B, A.getPrev());
EXPECT_EQ(&B, A.getNext());
A.initializeSentinel();
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
EXPECT_TRUE(A.isKnownSentinel());
#else
EXPECT_FALSE(A.isKnownSentinel());
#endif
EXPECT_EQ(&B, A.getPrev());
EXPECT_EQ(&B, A.getNext());
}
} // end namespace