test/test_list.cpp

Mon, 18 Apr 2022 16:29:14 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Apr 2022 16:29:14 +0200
changeset 526
b070ef465313
parent 521
e5dc54131d55
child 528
4fbfac557df8
permissions
-rw-r--r--

simplify destructor signature (but loads more responsibility onto the user)

390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
29 #include "cx/linked_list.h"
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
30 #include "cx/utils.h"
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents: 413
diff changeset
31 #include "util_allocator.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
32
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
33 #include <gtest/gtest.h>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
34 #include <array>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
35 #include <vector>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
36 #include <unordered_set>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
37 #include <algorithm>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
38
507
2e8878770de0 remove test code duplication for cxListAdd
Mike Becker <universe@uap-core.de>
parents: 506
diff changeset
39 static int cmp_int_impl(
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
40 int const *l,
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
41 int const *r
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
42 ) {
412
af766caea48d removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents: 411
diff changeset
43 int left = *l, right = *r;
af766caea48d removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents: 411
diff changeset
44 return left == right ? 0 : (left < right ? -1 : 1);
af766caea48d removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents: 411
diff changeset
45 }
af766caea48d removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents: 411
diff changeset
46
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
47 #define cmp_int ((CxListComparator) cmp_int_impl)
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
48
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
49 struct node {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
50 node *next = nullptr;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
51 node *prev = nullptr;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
52 int data = 0;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
53 };
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
54
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
55 const ptrdiff_t loc_prev = offsetof(struct node, prev);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
56 const ptrdiff_t loc_next = offsetof(struct node, next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
57 const ptrdiff_t loc_data = offsetof(struct node, data);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
58
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
59 struct node_test_data {
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
60 node *begin = nullptr;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
61
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
62 explicit node_test_data(node *begin) : begin(begin) {
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
63 auto n = begin;
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
64 while (n != nullptr) {
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
65 nodes.push_back(n);
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
66 n = n->next;
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
67 }
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
68 }
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
69
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
70 node_test_data(node_test_data &) = delete;
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
71
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
72 node_test_data(node_test_data &&) = default;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
73
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
74 ~node_test_data() {
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
75 for (auto &&n: nodes) delete n;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
76 }
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
77
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
78 private:
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
79 std::vector<node *> nodes;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
80 };
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
81
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
82 static node_test_data create_nodes_test_data(size_t len) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
83 if (len == 0) return node_test_data{nullptr};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
84 auto begin = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
85 auto prev = begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
86 for (size_t i = 1; i < len; i++) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
87 auto n = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
88 cx_linked_list_link(prev, n, loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
89 prev = n;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
90 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
91 return node_test_data{begin};
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
92 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
93
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
94 template<typename InputIter>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
95 static node_test_data create_nodes_test_data(InputIter begin, InputIter end) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
96 if (begin == end) return node_test_data{nullptr};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
97 node *first = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
98 first->data = *begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
99 node *prev = first;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
100 begin++;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
101 for (; begin != end; begin++) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
102 auto n = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
103 n->data = *begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
104 cx_linked_list_link(prev, n, loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
105 prev = n;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
106 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
107 return node_test_data{first};
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
108 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
109
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
110 static node_test_data create_nodes_test_data(std::initializer_list<int> data) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
111 return create_nodes_test_data(data.begin(), data.end());
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
112 }
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
113
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
114 template<size_t N>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
115 struct int_test_data {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
116 std::array<int, N> data;
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
117
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
118 int_test_data() {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
119 cx_for_n (i, N) data[i] = ::rand(); // NOLINT(cert-msc50-cpp)
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
120 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
121 };
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
122
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
123 TEST(LinkedList_LowLevel, link_unlink) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
124 node a, b, c;
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
125
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
126 cx_linked_list_link(&a, &b, loc_prev, loc_next);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
127 EXPECT_EQ(a.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
128 EXPECT_EQ(a.next, &b);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
129 EXPECT_EQ(b.prev, &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
130 EXPECT_EQ(b.next, nullptr);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
131
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
132 cx_linked_list_unlink(&a, &b, loc_prev, loc_next);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
133 EXPECT_EQ(a.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
134 EXPECT_EQ(a.next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
135 EXPECT_EQ(b.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
136 EXPECT_EQ(b.next, nullptr);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
137
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
138 cx_linked_list_link(&b, &c, loc_prev, loc_next);
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
139 cx_linked_list_link(&a, &b, loc_prev, loc_next);
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
140 cx_linked_list_unlink(&b, &c, loc_prev, loc_next);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
141 EXPECT_EQ(a.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
142 EXPECT_EQ(a.next, &b);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
143 EXPECT_EQ(b.prev, &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
144 EXPECT_EQ(b.next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
145 EXPECT_EQ(c.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
146 EXPECT_EQ(c.next, nullptr);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
147 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
148
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
149 TEST(LinkedList_LowLevel, cx_linked_list_at) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
150 node a, b, c, d;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
151 cx_linked_list_link(&a, &b, loc_prev, loc_next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
152 cx_linked_list_link(&b, &c, loc_prev, loc_next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
153 cx_linked_list_link(&c, &d, loc_prev, loc_next);
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
154
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
155 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 0), &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
156 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 1), &b);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
157 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 2), &c);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
158 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 3), &d);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
159 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 4), nullptr);
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
160
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
161 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_prev, 0), &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
162 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 1), &b);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
163 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 2), &c);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
164 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 3), &d);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
165 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 4), nullptr);
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
166
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
167 EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 0), &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
168 EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 1), &b);
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
169 }
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
170
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
171 TEST(LinkedList_LowLevel, cx_linked_list_find) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
172 auto testdata = create_nodes_test_data({2, 4, 6, 8});
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
173 auto list = testdata.begin;
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
174 int s;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
175
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
176 s = 2;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
177 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cmp_int, &s), 0);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
178 s = 4;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
179 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cmp_int, &s), 1);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
180 s = 6;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
181 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cmp_int, &s), 2);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
182 s = 8;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
183 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cmp_int, &s), 3);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
184 s = 10;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
185 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cmp_int, &s), 4);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
186 s = -2;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
187 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cmp_int, &s), 4);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
188 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
189
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
190 TEST(LinkedList_LowLevel, cx_linked_list_compare) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
191 auto ta = create_nodes_test_data({2, 4, 6, 8});
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
192 auto tb = create_nodes_test_data({2, 4, 6});
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
193 auto tc = create_nodes_test_data({2, 4, 6, 9});
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
194 auto la = ta.begin, lb = tb.begin, lc = tc.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
195
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
196 EXPECT_GT(cx_linked_list_compare(la, lb, loc_next, loc_data, false, cmp_int), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
197 EXPECT_LT(cx_linked_list_compare(lb, la, loc_next, loc_data, false, cmp_int), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
198 EXPECT_GT(cx_linked_list_compare(lc, la, loc_next, loc_data, false, cmp_int), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
199 EXPECT_LT(cx_linked_list_compare(la, lc, loc_next, loc_data, false, cmp_int), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
200 EXPECT_EQ(cx_linked_list_compare(la, la, loc_next, loc_data, false, cmp_int), 0);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
201 }
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
202
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
203 TEST(LinkedList_LowLevel, cx_linked_list_add) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
204 // test with begin, end / prev, next
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
205 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
206 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
207 void *begin = nullptr, *end = nullptr;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
208
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
209 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
210 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
211 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
212 EXPECT_EQ(nodes[0].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
213 EXPECT_EQ(nodes[0].next, nullptr);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
214
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
215 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
216 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
217 EXPECT_EQ(end, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
218 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
219 EXPECT_EQ(nodes[1].prev, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
220 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
221
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
222 // test with begin only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
223 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
224 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
225 void *begin = nullptr;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
226
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
227 cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
228 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
229 cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
230 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
231 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
232 EXPECT_EQ(nodes[1].prev, &nodes[0]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
233
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
234 cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
235 EXPECT_EQ(nodes[1].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
236 EXPECT_EQ(nodes[2].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
237 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
238
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
239 // test with end only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
240 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
241 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
242 void *end = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
243
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
244 cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
245 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
246 cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
247 EXPECT_EQ(end, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
248 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
249 EXPECT_EQ(nodes[1].prev, &nodes[0]);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
250
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
251 cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
252 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
253 EXPECT_EQ(nodes[1].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
254 EXPECT_EQ(nodes[2].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
255 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
256
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
257 // test with begin, end / next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
258 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
259 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
260 void *begin = nullptr, *end = nullptr;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
261
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
262 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
263 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
264 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
265 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
266 EXPECT_EQ(end, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
267 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
268 EXPECT_EQ(nodes[1].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
269 }
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
270 }
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
271
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
272 TEST(LinkedList_LowLevel, cx_linked_list_prepend) {
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
273 // test with begin, end / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
274 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
275 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
276 void *begin = nullptr, *end = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
277
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
278 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
279 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
280 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
281 EXPECT_EQ(nodes[0].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
282 EXPECT_EQ(nodes[0].next, nullptr);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
283
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
284 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
285 EXPECT_EQ(begin, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
286 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
287 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
288 EXPECT_EQ(nodes[0].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
289 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
290
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
291 // test with begin only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
292 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
293 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
294 void *begin = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
295
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
296 cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
297 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
298 cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
299 EXPECT_EQ(begin, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
300 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
301 EXPECT_EQ(nodes[0].prev, &nodes[1]);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
302
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
303 cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
304 EXPECT_EQ(begin, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
305 EXPECT_EQ(nodes[2].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
306 EXPECT_EQ(nodes[1].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
307 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
308
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
309 // test with end only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
310 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
311 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
312 void *end = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
313
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
314 cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
315 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
316 cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
317 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
318 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
319 EXPECT_EQ(nodes[0].prev, &nodes[1]);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
320
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
321 cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
322 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
323 EXPECT_EQ(nodes[2].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
324 EXPECT_EQ(nodes[1].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
325 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
326
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
327 // test with begin, end / next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
328 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
329 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
330 void *begin = nullptr, *end = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
331
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
332 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
333 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
334 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
335 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
336 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
337 EXPECT_EQ(begin, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
338 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
339 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
340 EXPECT_EQ(nodes[2].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
341 EXPECT_EQ(nodes[1].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
342 EXPECT_EQ(nodes[0].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
343 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
344 }
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
345
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
346 TEST(LinkedList_LowLevel, cx_linked_list_insert) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
347 // insert mid list
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
348 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
349 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
350 void *begin = &nodes[0], *end = &nodes[2];
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
351
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
352 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
353 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
354
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
355 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
356 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
357 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
358 EXPECT_EQ(nodes[1].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
359 EXPECT_EQ(nodes[2].prev, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
360 EXPECT_EQ(nodes[3].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
361 EXPECT_EQ(nodes[3].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
362 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
363
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
364 // insert end
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
365 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
366 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
367 void *begin = &nodes[0], *end = &nodes[2];
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
368
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
369 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
370 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
371
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
372 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
373 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
374 EXPECT_EQ(end, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
375 EXPECT_EQ(nodes[2].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
376 EXPECT_EQ(nodes[3].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
377 EXPECT_EQ(nodes[3].next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
378 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
379
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
380 // insert begin
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
381 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
382 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
383 void *begin = &nodes[0], *end = &nodes[2];
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
384
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
385 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
386 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
387
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
388 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, nullptr, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
389 EXPECT_EQ(begin, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
390 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
391 EXPECT_EQ(nodes[0].prev, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
392 EXPECT_EQ(nodes[3].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
393 EXPECT_EQ(nodes[3].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
394 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
395 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
396
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
397 TEST(LinkedList_LowLevel, cx_linked_list_insert_chain) {
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
398 // insert mid list
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
399 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
400 node nodes[5];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
401 void *begin = &nodes[0], *end = &nodes[2];
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
402
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
403 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
404 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
405 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
406
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
407 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
408 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
409 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
410 EXPECT_EQ(nodes[1].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
411 EXPECT_EQ(nodes[2].prev, &nodes[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
412 EXPECT_EQ(nodes[3].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
413 EXPECT_EQ(nodes[4].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
414 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
415
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
416 // insert end
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
417 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
418 node nodes[5];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
419 void *begin = &nodes[0], *end = &nodes[2];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
420
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
421 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
422 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
423 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
424
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
425 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
426 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
427 EXPECT_EQ(end, &nodes[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
428 EXPECT_EQ(nodes[2].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
429 EXPECT_EQ(nodes[3].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
430 EXPECT_EQ(nodes[4].next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
431 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
432
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
433 // insert begin
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
434 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
435 node nodes[5];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
436 void *begin = &nodes[0], *end = &nodes[2];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
437
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
438 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
439 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
440 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
441
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
442 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, nullptr, &nodes[3], nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
443 EXPECT_EQ(begin, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
444 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
445 EXPECT_EQ(nodes[0].prev, &nodes[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
446 EXPECT_EQ(nodes[3].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
447 EXPECT_EQ(nodes[4].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
448 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
449 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
450
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
451 TEST(LinkedList_LowLevel, cx_linked_list_first) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
452 auto testdata = create_nodes_test_data(3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
453 auto begin = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
454 EXPECT_EQ(cx_linked_list_first(begin, loc_prev), begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
455 EXPECT_EQ(cx_linked_list_first(begin->next, loc_prev), begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
456 EXPECT_EQ(cx_linked_list_first(begin->next->next, loc_prev), begin);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
457 }
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
458
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
459 TEST(LinkedList_LowLevel, cx_linked_list_last) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
460 auto testdata = create_nodes_test_data(3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
461 auto begin = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
462 auto end = begin->next->next;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
463 EXPECT_EQ(cx_linked_list_last(begin, loc_next), end);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
464 EXPECT_EQ(cx_linked_list_last(begin->next, loc_next), end);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
465 EXPECT_EQ(cx_linked_list_last(begin->next->next, loc_next), end);
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
466 }
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
467
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
468 TEST(LinkedList_LowLevel, cx_linked_list_prev) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
469 auto testdata = create_nodes_test_data(3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
470 auto begin = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
471 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin), nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
472 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next), begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
473 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next->next), begin->next);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
474 }
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
475
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
476 TEST(LinkedList_LowLevel, cx_linked_list_remove) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
477 auto testdata = create_nodes_test_data({2, 4, 6});
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
478 auto begin = reinterpret_cast<void *>(testdata.begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
479 auto first = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
480 auto second = first->next;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
481 auto third = second->next;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
482 auto end = reinterpret_cast<void *>(third);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
483
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
484 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, second);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
485 EXPECT_EQ(begin, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
486 EXPECT_EQ(end, third);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
487 EXPECT_EQ(first->prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
488 EXPECT_EQ(first->next, third);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
489 EXPECT_EQ(third->prev, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
490 EXPECT_EQ(third->next, nullptr);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
491
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
492 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, third);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
493 EXPECT_EQ(begin, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
494 EXPECT_EQ(end, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
495 EXPECT_EQ(first->prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
496 EXPECT_EQ(first->next, nullptr);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
497
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
498 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, first);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
499 EXPECT_EQ(begin, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
500 EXPECT_EQ(end, nullptr);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
501 }
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
502
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
503 TEST(LinkedList_LowLevel, cx_linked_list_size) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
504 EXPECT_EQ(cx_linked_list_size(nullptr, loc_next), 0);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
505
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
506 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
507 auto testdata = create_nodes_test_data(5);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
508 EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 5);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
509 }
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
510
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
511 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
512 auto testdata = create_nodes_test_data(13);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
513 EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 13);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
514 }
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
515 }
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
516
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
517 TEST(LinkedList_LowLevel, cx_linked_list_sort) {
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
518 int_test_data<1500> testdata;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
519 std::array<int, 1500> sorted{};
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
520 std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), sorted.begin(), sorted.end());
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
521
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
522 auto scrambled = create_nodes_test_data(testdata.data.begin(), testdata.data.end());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
523 void *begin = scrambled.begin;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
524 void *end = cx_linked_list_last(begin, loc_next);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
525
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
526 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
527 false, cmp_int);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
528
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
529 node *check = reinterpret_cast<node *>(begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
530 node *check_last = nullptr;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
531 cx_for_n (i, sorted.size()) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
532 EXPECT_EQ(check->data, sorted[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
533 EXPECT_EQ(check->prev, check_last);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
534 if (i < sorted.size() - 1) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
535 ASSERT_NE(check->next, nullptr);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
536 }
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
537 check_last = check;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
538 check = check->next;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
539 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
540 EXPECT_EQ(check, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
541 EXPECT_EQ(end, check_last);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
542 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
543
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
544 TEST(LinkedList_LowLevel, cx_linked_list_reverse) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
545 auto testdata = create_nodes_test_data({2, 4, 6, 8});
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
546 auto expected = create_nodes_test_data({8, 6, 4, 2});
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
547
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
548 auto begin = reinterpret_cast<void *>(testdata.begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
549 auto end = cx_linked_list_last(begin, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
550 auto orig_begin = begin, orig_end = end;
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
551
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
552 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
553 EXPECT_EQ(end, orig_begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
554 EXPECT_EQ(begin, orig_end);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
555 EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, 0, cmp_int), 0);
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
556 }
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
557
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
558 class HighLevelTest : public ::testing::Test {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
559 mutable std::unordered_set<CxList *> lists;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
560 protected:
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
561 CxTestingAllocator testingAllocator;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
562
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
563 void TearDown() override {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
564 for (auto &&l: lists) cxListDestroy(l);
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
565 EXPECT_TRUE(testingAllocator.verify());
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
566 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
567
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
568 static constexpr size_t testdata_len = 250;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
569 int_test_data<testdata_len> testdata;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
570
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
571 auto autofree(CxList *list) const -> CxList * {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
572 lists.insert(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
573 return list;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
574 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
575
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
576 auto linkedListFromTestData() const -> CxList * {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
577 return autofree(
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
578 cxLinkedListFromArray(
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
579 &testingAllocator,
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
580 cmp_int,
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
581 sizeof(int),
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
582 testdata_len,
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
583 testdata.data.data()
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
584 )
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
585 );
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
586 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
587
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
588 auto pointerLinkedListFromTestData() const -> CxList * {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
589 auto list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
590 cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
591 return list;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
592 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
593
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
594 void verifyCreate(CxList *list) const {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
595 EXPECT_EQ(list->size, 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
596 EXPECT_EQ(list->capacity, (size_t) -1);
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
597 EXPECT_EQ(list->allocator, &testingAllocator);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
598 EXPECT_EQ(list->cmpfunc, cmp_int);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
599 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
600
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
601 void verifyAdd(CxList *list, bool write_through) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
602 auto len = testdata_len;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
603 cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
604 EXPECT_EQ(list->size, len);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
605 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
606 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
607 cx_for_n (i, len) ++testdata.data[i];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
608 if (write_through) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
609 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
610 } else {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
611 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i] - 1);
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
612 }
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
613 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
614
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
615 static void verifyInsert(CxList *list) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
616 int a = 5, b = 47, c = 13, d = 42;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
617
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
618 EXPECT_NE(cxListInsert(list, 1, &a), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
619 EXPECT_EQ(list->size, 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
620 EXPECT_EQ(cxListInsert(list, 0, &a), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
621 EXPECT_EQ(list->size, 1);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
622 EXPECT_EQ(cxListInsert(list, 0, &b), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
623 EXPECT_EQ(list->size, 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
624 EXPECT_EQ(cxListInsert(list, 1, &c), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
625 EXPECT_EQ(list->size, 3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
626 EXPECT_EQ(cxListInsert(list, 3, &d), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
627
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
628 EXPECT_EQ(list->size, 4);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
629 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
630
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
631 EXPECT_EQ(*(int *) cxListAt(list, 0), 47);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
632 EXPECT_EQ(*(int *) cxListAt(list, 1), 13);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
633 EXPECT_EQ(*(int *) cxListAt(list, 2), 5);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
634 EXPECT_EQ(*(int *) cxListAt(list, 3), 42);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
635 }
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
636
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
637 void verifyRemove(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
638 EXPECT_EQ(cxListRemove(list, 2), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
639 EXPECT_EQ(cxListRemove(list, 4), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
640 EXPECT_EQ(list->size, testdata_len - 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
641 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
642 EXPECT_EQ(*(int *) cxListAt(list, 0), testdata.data[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
643 EXPECT_EQ(*(int *) cxListAt(list, 1), testdata.data[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
644 EXPECT_EQ(*(int *) cxListAt(list, 2), testdata.data[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
645 EXPECT_EQ(*(int *) cxListAt(list, 3), testdata.data[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
646 EXPECT_EQ(*(int *) cxListAt(list, 4), testdata.data[6]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
647
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
648 EXPECT_EQ(cxListRemove(list, 0), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
649 EXPECT_EQ(list->size, testdata_len - 3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
650 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
651 EXPECT_EQ(*(int *) cxListAt(list, 0), testdata.data[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
652 EXPECT_EQ(*(int *) cxListAt(list, 1), testdata.data[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
653
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
654 EXPECT_NE(cxListRemove(list, testdata_len), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
655 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
656
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
657 void verifyAt(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
658 auto len = testdata_len;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
659 EXPECT_EQ(list->size, len);
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
660 cx_for_n (i, len) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
661 EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
662 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
663 EXPECT_EQ(cxListAt(list, list->size), nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
664 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
665
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
666 void verifyFind(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
667 cx_for_n (attempt, 25) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
668 size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
669 int val = testdata.data[exp];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
670 // randomly picked number could occur earlier in list - find first position
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
671 cx_for_n (i, exp) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
672 if (testdata.data[i] == val) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
673 exp = i;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
674 break;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
675 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
676 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
677 EXPECT_EQ(cxListFind(list, &val), exp);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
678 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
679 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
680
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
681 void verifySort(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
682 std::array<int, testdata_len> expected{};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
683 std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), expected.begin(), expected.end());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
684 cxListSort(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
685 cx_for_n (i, testdata_len) ASSERT_EQ(*(int *) cxListAt(list, i), expected[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
686 }
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
687
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
688 void verifyIterator(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
689 int i = 0;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
690 CxIterator iter = cxListBegin(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
691 cx_foreach(int*, x, iter) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
692 ASSERT_EQ(iter.index, (size_t) (i + 1) / 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
693 ASSERT_EQ(*x, testdata.data[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
694 if (i % 2 == 1) iter.remove = true;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
695 i++;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
696 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
697 auto len = testdata_len;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
698 EXPECT_EQ(i, len);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
699 ASSERT_EQ(list->size, len / 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
700 cx_for_n(j, len / 2) ASSERT_EQ(*(int *) cxListAt(list, j), testdata.data[j * 2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
701 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
702
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
703 static void verifyInsertViaIterator(CxList *list) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
704 int newdata[] = {10, 20, 30, 40, 50};
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
705
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
706 CxIterator iter = cxListIterator(list, 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
707 EXPECT_TRUE(cxIteratorValid(&iter));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
708 EXPECT_EQ(iter.index, 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
709 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
710 cxListInsertAfter(&iter, &newdata[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
711 EXPECT_TRUE(cxIteratorValid(&iter));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
712 EXPECT_EQ(iter.index, 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
713 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
714 cxListInsertBefore(&iter, &newdata[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
715 EXPECT_TRUE(cxIteratorValid(&iter));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
716 EXPECT_EQ(iter.index, 3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
717 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
718
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
719 iter = cxListBegin(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
720 cxListInsertBefore(&iter, &newdata[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
721 EXPECT_TRUE(cxIteratorValid(&iter));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
722 EXPECT_EQ(iter.index, 1);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
723 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
724 iter = cxListIterator(list, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
725 cxListInsertBefore(&iter, &newdata[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
726 EXPECT_FALSE(cxIteratorValid(&iter));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
727 EXPECT_EQ(iter.index, 9);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
728 iter = cxListIterator(list, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
729 cxListInsertAfter(&iter, &newdata[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
730 EXPECT_FALSE(cxIteratorValid(&iter));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
731 EXPECT_EQ(iter.index, 10);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
732
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
733 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
734 cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
735 }
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
736
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
737 void verifyReverse(CxList *list) const {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
738 cxListReverse(list);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
739 cx_for_n(i, testdata_len) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
740 ASSERT_EQ(*(int *) cxListAt(list, i), testdata.data[testdata_len - 1 - i]);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
741 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
742 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
743
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
744 static void verifyCompare(CxList *left, CxList *right) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
745 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
746 int x = 42;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
747 cxListAdd(left, &x);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
748 ASSERT_GT(left->size, right->size);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
749 EXPECT_GT(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
750 EXPECT_LT(cxListCompare(right, left), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
751 cxListAdd(right, &x);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
752 ASSERT_EQ(left->size, right->size);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
753 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
754 int a = 5, b = 10;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
755 cxListInsert(left, 15, &a);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
756 cxListInsert(right, 15, &b);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
757 ASSERT_EQ(left->size, right->size);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
758 EXPECT_LT(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
759 EXPECT_GT(cxListCompare(right, left), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
760 *(int*)cxListAt(left, 15) = 10;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
761 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
762 }
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
763 };
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
764
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
765 class LinkedList : public HighLevelTest {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
766 };
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
767
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
768 class PointerLinkedList : public HighLevelTest {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
769 };
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
770
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
771 TEST_F(LinkedList, cxLinkedListCreate) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
772 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
773 EXPECT_EQ(list->itemsize, sizeof(int));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
774 verifyCreate(list);
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
775 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
776
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
777 TEST_F(PointerLinkedList, cxPointerLinkedListCreate) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
778 CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
779 EXPECT_EQ(list->itemsize, sizeof(void *));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
780 verifyCreate(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
781 }
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
782
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
783 TEST_F(LinkedList, cxLinkedListFromArray) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
784 CxList *expected = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
785 cx_for_n (i, testdata_len) cxListAdd(expected, &testdata.data[i]);
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
786 CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cmp_int, sizeof(int),
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
787 testdata_len, testdata.data.data()));
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
788 EXPECT_EQ(cxListCompare(list, expected), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
789 }
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
790
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
791 TEST_F(LinkedList, cxListAdd) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
792 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
793 verifyAdd(list, false);
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
794 }
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
795
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
796 TEST_F(PointerLinkedList, cxListAdd) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
797 CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
798 verifyAdd(list, true);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
799 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
800
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
801 TEST_F(LinkedList, cxListInsert) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
802 verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int))));
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
803 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
804
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
805 TEST_F(PointerLinkedList, cxListInsert) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
806 verifyInsert(autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int)));
506
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
807 }
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
808
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
809 TEST_F(LinkedList, cxListRemove) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
810 verifyRemove(linkedListFromTestData());
506
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
811 }
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
812
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
813 TEST_F(PointerLinkedList, cxListRemove) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
814 verifyRemove(pointerLinkedListFromTestData());
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
815 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
816
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
817 TEST_F(LinkedList, cxListAt) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
818 verifyAt(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
819 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
820
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
821 TEST_F(PointerLinkedList, cxListAt) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
822 verifyAt(pointerLinkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
823 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
824
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
825 TEST_F(LinkedList, cxListFind) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
826 verifyFind(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
827 }
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
828
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
829 TEST_F(PointerLinkedList, cxListFind) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
830 verifyFind(pointerLinkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
831 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
832
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
833 TEST_F(LinkedList, cxListSort) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
834 verifySort(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
835 }
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
836
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
837 TEST_F(PointerLinkedList, cxListSort) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
838 verifySort(pointerLinkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
839 }
413
0f4aa9fc75d9 perform array and list tests in the same test binary (use the same assertions, later)
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
840
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
841 TEST_F(LinkedList, Iterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
842 verifyIterator(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
843 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
844
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
845 TEST_F(PointerLinkedList, Iterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
846 verifyIterator(pointerLinkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
847 }
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
848
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
849 TEST_F(LinkedList, InsertViaIterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
850 int fivenums[] = {0, 1, 2, 3, 4, 5};
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
851 CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cmp_int, sizeof(int), 5, fivenums));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
852 verifyInsertViaIterator(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
853 }
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
854
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
855 TEST_F(PointerLinkedList, InsertViaIterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
856 int fivenums[] = {0, 1, 2, 3, 4, 5};
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
857 CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
858 cx_for_n (i, 5) cxListAdd(list, &fivenums[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
859 verifyInsertViaIterator(list);
390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
860 }
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
861
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
862 TEST_F(LinkedList, cxListReverse) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
863 verifyReverse(linkedListFromTestData());
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
864 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
865
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
866 TEST_F(PointerLinkedList, cxListReverse) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
867 verifyReverse(pointerLinkedListFromTestData());
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
868 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
869
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
870 TEST_F(LinkedList, cxListCompare) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
871 auto left = linkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
872 auto right = linkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
873 verifyCompare(left, right);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
874 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
875
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
876 TEST_F(PointerLinkedList, cxListCompare) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
877 auto left = pointerLinkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
878 auto right = pointerLinkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
879 verifyCompare(left, right);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
880 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
881

mercurial