2
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
24
#include "precompiled.hpp"
25
#include "gc/x/xList.inline.hpp"
26
#include "unittest.hpp"
31
friend class XList<XTestEntry>;
35
XListNode<XTestEntry> _node;
47
class XListTest : public ::testing::Test {
49
static void assert_sorted(XList<XTestEntry>* list) {
52
int count = list->first()->id();
53
XListIterator<XTestEntry> iter(list);
54
for (XTestEntry* entry; iter.next(&entry);) {
55
ASSERT_EQ(entry->id(), count);
62
int count = list->last()->id();
63
XListReverseIterator<XTestEntry> iter(list);
64
for (XTestEntry* entry; iter.next(&entry);) {
65
EXPECT_EQ(entry->id(), count);
72
TEST_F(XListTest, test_insert) {
73
XList<XTestEntry> list;
81
list.insert_first(&e2);
82
list.insert_before(&e2, &e1);
83
list.insert_after(&e2, &e3);
84
list.insert_last(&e4);
85
list.insert_first(&e0);
86
list.insert_last(&e5);
88
EXPECT_EQ(list.size(), 6u);
91
for (int i = 0; i < 6; i++) {
92
XTestEntry* e = list.remove_first();
93
EXPECT_EQ(e->id(), i);
96
EXPECT_EQ(list.size(), 0u);
99
TEST_F(XListTest, test_remove) {
102
XList<XTestEntry> list;
110
list.insert_last(&e0);
111
list.insert_last(&e1);
112
list.insert_last(&e2);
113
list.insert_last(&e3);
114
list.insert_last(&e4);
115
list.insert_last(&e5);
117
EXPECT_EQ(list.size(), 6u);
119
for (int i = 0; i < 6; i++) {
120
XTestEntry* e = list.remove_first();
121
EXPECT_EQ(e->id(), i);
124
EXPECT_EQ(list.size(), 0u);
129
XList<XTestEntry> list;
137
list.insert_last(&e0);
138
list.insert_last(&e1);
139
list.insert_last(&e2);
140
list.insert_last(&e3);
141
list.insert_last(&e4);
142
list.insert_last(&e5);
144
EXPECT_EQ(list.size(), 6u);
146
for (int i = 5; i >= 0; i--) {
147
XTestEntry* e = list.remove_last();
148
EXPECT_EQ(e->id(), i);
151
EXPECT_EQ(list.size(), 0u);