tests/test_list.cpp

Tue, 21 Mar 2023 17:18:29 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 21 Mar 2023 17:18:29 +0100
changeset 667
2f88a7c13a28
parent 666
b5dd654deb3b
child 672
55d8fdd38ca4
permissions
-rw-r--r--

add CX_STORE_POINTERS special "item size" for lists

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"
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
30 #include "cx/array_list.h"
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
31 #include "cx/utils.h"
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
32 #include "cx/compare.h"
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents: 413
diff changeset
33 #include "util_allocator.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
34
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
35 #include <gtest/gtest.h>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
36 #include <array>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
37 #include <vector>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
38 #include <unordered_set>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
39 #include <algorithm>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
40
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
41 struct testdatastruct {
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
42 int x;
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
43 void *ptr;
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
44 };
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
45
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
46 static void free_testdatastruct(
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
47 void *a,
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
48 void *s
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
49 ) {
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
50 auto al = reinterpret_cast<CxTestingAllocator *>(a);
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
51 cxFree(al, reinterpret_cast<testdatastruct *>(s)->ptr);
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
52 }
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
53
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
54 struct node {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
55 node *next = nullptr;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
56 node *prev = nullptr;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
57 int data = 0;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
58 };
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
59
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
60 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
61 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
62 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
63
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
64 struct node_test_data {
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
65 node *begin = nullptr;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
66
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
67 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
68 auto n = begin;
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
69 while (n != nullptr) {
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
70 nodes.push_back(n);
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
71 n = n->next;
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
72 }
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
73 }
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
74
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
75 node_test_data(node_test_data &) = delete;
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
76
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
77 node_test_data(node_test_data &&) = default;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
78
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
79 ~node_test_data() {
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
80 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
81 }
520
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
82
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
83 private:
f937c6d11d1f fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents: 518
diff changeset
84 std::vector<node *> nodes;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
85 };
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
86
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
87 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
88 if (len == 0) return node_test_data{nullptr};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
89 auto begin = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
90 auto prev = begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
91 for (size_t i = 1; i < len; i++) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
92 auto n = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
93 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
94 prev = n;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
95 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
96 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
97 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
98
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
99 template<typename InputIter>
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
100 static node_test_data create_nodes_test_data(
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
101 InputIter begin,
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
102 InputIter end
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
103 ) {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
104 if (begin == end) return node_test_data{nullptr};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
105 node *first = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
106 first->data = *begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
107 node *prev = first;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
108 begin++;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
109 for (; begin != end; begin++) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
110 auto n = new node;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
111 n->data = *begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
112 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
113 prev = n;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
114 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
115 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
116 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
117
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
118 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
119 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
120 }
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
121
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
122 template<size_t N>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
123 struct int_test_data {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
124 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
125
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
126 int_test_data() {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
127 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
128 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
129 };
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
130
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
131 TEST(LinkedList_LowLevel, link_unlink) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
132 node a, b, c;
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
133
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
134 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
135 EXPECT_EQ(a.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
136 EXPECT_EQ(a.next, &b);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
137 EXPECT_EQ(b.prev, &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
138 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
139
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
140 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
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, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
143 EXPECT_EQ(b.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
144 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
145
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
146 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
147 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
148 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
149 EXPECT_EQ(a.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
150 EXPECT_EQ(a.next, &b);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
151 EXPECT_EQ(b.prev, &a);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
152 EXPECT_EQ(b.next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
153 EXPECT_EQ(c.prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
154 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
155 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
156
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
157 TEST(LinkedList_LowLevel, cx_linked_list_at) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
158 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
159 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
160 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
161 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
162
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
163 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
164 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
165 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
166 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
167 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
168
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
169 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
170 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
171 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
172 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
173 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
174
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
175 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
176 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
177 }
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
178
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
179 TEST(LinkedList_LowLevel, cx_linked_list_find) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
180 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
181 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
182 int s;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
183
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
184 s = 2;
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
185 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_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
186 s = 4;
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
187 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_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
188 s = 6;
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
189 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_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
190 s = 8;
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
191 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_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
192 s = 10;
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
193 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_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
194 s = -2;
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
195 EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 4);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
196 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
197
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
198 TEST(LinkedList_LowLevel, cx_linked_list_compare) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
199 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
200 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
201 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
202 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
203
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
204 EXPECT_GT(cx_linked_list_compare(la, lb, loc_next, loc_data, cx_cmp_int), 0);
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
205 EXPECT_LT(cx_linked_list_compare(lb, la, loc_next, loc_data, cx_cmp_int), 0);
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
206 EXPECT_GT(cx_linked_list_compare(lc, la, loc_next, loc_data, cx_cmp_int), 0);
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
207 EXPECT_LT(cx_linked_list_compare(la, lc, loc_next, loc_data, cx_cmp_int), 0);
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
208 EXPECT_EQ(cx_linked_list_compare(la, la, loc_next, loc_data, cx_cmp_int), 0);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
209 }
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
210
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
211 TEST(LinkedList_LowLevel, cx_linked_list_add) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
212 // test with begin, end / prev, next
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
213 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
214 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
215 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
216
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
217 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
218 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
219 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
220 EXPECT_EQ(nodes[0].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
221 EXPECT_EQ(nodes[0].next, nullptr);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
222
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
223 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
224 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
225 EXPECT_EQ(end, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
226 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
227 EXPECT_EQ(nodes[1].prev, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
228 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
229
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
230 // test with begin only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
231 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
232 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
233 void *begin = nullptr;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
234
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
235 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
236 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
237 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
238 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
239 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
240 EXPECT_EQ(nodes[1].prev, &nodes[0]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
241
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
242 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
243 EXPECT_EQ(nodes[1].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
244 EXPECT_EQ(nodes[2].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
245 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
246
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
247 // test with end only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
248 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
249 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
250 void *end = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
251
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
252 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
253 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
254 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
255 EXPECT_EQ(end, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
256 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
257 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
258
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
259 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
260 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
261 EXPECT_EQ(nodes[1].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
262 EXPECT_EQ(nodes[2].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
263 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
264
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
265 // test with begin, end / next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
266 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
267 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
268 void *begin = nullptr, *end = nullptr;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
269
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
270 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
271 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
272 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
273 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
274 EXPECT_EQ(end, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
275 EXPECT_EQ(nodes[0].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
276 EXPECT_EQ(nodes[1].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
277 }
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
278 }
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
279
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
280 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
281 // test with begin, end / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
282 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
283 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
284 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
285
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
286 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
287 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
288 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
289 EXPECT_EQ(nodes[0].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
290 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
291
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
292 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
293 EXPECT_EQ(begin, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
294 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
295 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
296 EXPECT_EQ(nodes[0].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
297 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
298
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
299 // test with begin only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
300 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
301 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
302 void *begin = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
303
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
304 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
305 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
306 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
307 EXPECT_EQ(begin, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
308 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
309 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
310
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
311 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
312 EXPECT_EQ(begin, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
313 EXPECT_EQ(nodes[2].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
314 EXPECT_EQ(nodes[1].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
315 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
316
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
317 // test with end only / prev, next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
318 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
319 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
320 void *end = nullptr;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
321
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
322 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
323 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
324 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
325 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
326 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
327 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
328
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
329 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
330 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
331 EXPECT_EQ(nodes[2].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
332 EXPECT_EQ(nodes[1].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
333 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
334
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
335 // test with begin, end / next
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
336 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
337 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
338 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
339
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
340 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
341 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
342 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
343 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
344 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
345 EXPECT_EQ(begin, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
346 EXPECT_EQ(end, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
347 EXPECT_EQ(nodes[1].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
348 EXPECT_EQ(nodes[2].next, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
349 EXPECT_EQ(nodes[1].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
350 EXPECT_EQ(nodes[0].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
351 }
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
352 }
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
353
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
354 TEST(LinkedList_LowLevel, cx_linked_list_insert) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
355 // insert mid list
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
356 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
357 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
358 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
359
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
360 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
361 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
362
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
363 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
364 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
365 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
366 EXPECT_EQ(nodes[1].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
367 EXPECT_EQ(nodes[2].prev, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
368 EXPECT_EQ(nodes[3].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
369 EXPECT_EQ(nodes[3].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
370 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
371
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
372 // insert end
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
373 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
374 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
375 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
376
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
377 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
378 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
379
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
380 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
381 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
382 EXPECT_EQ(end, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
383 EXPECT_EQ(nodes[2].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
384 EXPECT_EQ(nodes[3].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
385 EXPECT_EQ(nodes[3].next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
386 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
387
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
388 // insert begin
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
389 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
390 node nodes[4];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
391 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
392
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
393 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
394 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
395
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
396 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
397 EXPECT_EQ(begin, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
398 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
399 EXPECT_EQ(nodes[0].prev, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
400 EXPECT_EQ(nodes[3].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
401 EXPECT_EQ(nodes[3].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
402 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
403 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
404
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
405 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
406 // insert mid list
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
407 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
408 node nodes[5];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
409 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
410
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
411 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
412 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
413 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
414
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
415 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
416 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
417 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
418 EXPECT_EQ(nodes[1].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
419 EXPECT_EQ(nodes[2].prev, &nodes[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
420 EXPECT_EQ(nodes[3].prev, &nodes[1]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
421 EXPECT_EQ(nodes[4].next, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
422 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
423
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
424 // insert end
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
425 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
426 node nodes[5];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
427 void *begin = &nodes[0], *end = &nodes[2];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
428
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
429 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
430 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
431 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
432
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
433 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
434 EXPECT_EQ(begin, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
435 EXPECT_EQ(end, &nodes[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
436 EXPECT_EQ(nodes[2].next, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
437 EXPECT_EQ(nodes[3].prev, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
438 EXPECT_EQ(nodes[4].next, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
439 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
440
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
441 // insert begin
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
442 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
443 node nodes[5];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
444 void *begin = &nodes[0], *end = &nodes[2];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
445
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
446 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
447 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
448 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
449
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
450 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
451 EXPECT_EQ(begin, &nodes[3]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
452 EXPECT_EQ(end, &nodes[2]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
453 EXPECT_EQ(nodes[0].prev, &nodes[4]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
454 EXPECT_EQ(nodes[3].prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
455 EXPECT_EQ(nodes[4].next, &nodes[0]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
456 }
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
457 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
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_first) {
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 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
463 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
464 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
465 }
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
466
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
467 TEST(LinkedList_LowLevel, cx_linked_list_last) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
468 auto testdata = create_nodes_test_data(3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
469 auto begin = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
470 auto end = begin->next->next;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
471 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
472 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
473 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
474 }
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
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_prev) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
477 auto testdata = create_nodes_test_data(3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
478 auto begin = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
479 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
480 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
481 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
482 }
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
483
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
484 TEST(LinkedList_LowLevel, cx_linked_list_remove) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
485 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
486 auto begin = reinterpret_cast<void *>(testdata.begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
487 auto first = testdata.begin;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
488 auto second = first->next;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
489 auto third = second->next;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
490 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
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, second);
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, third);
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, third);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
497 EXPECT_EQ(third->prev, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
498 EXPECT_EQ(third->next, nullptr);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
499
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
500 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
501 EXPECT_EQ(begin, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
502 EXPECT_EQ(end, first);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
503 EXPECT_EQ(first->prev, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
504 EXPECT_EQ(first->next, nullptr);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
505
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
506 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
507 EXPECT_EQ(begin, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
508 EXPECT_EQ(end, nullptr);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
509 }
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
510
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
511 TEST(LinkedList_LowLevel, cx_linked_list_size) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
512 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
513
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
514 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
515 auto testdata = create_nodes_test_data(5);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
516 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
517 }
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
518
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
519 {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
520 auto testdata = create_nodes_test_data(13);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
521 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
522 }
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
523 }
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
524
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
525 TEST(LinkedList_LowLevel, cx_linked_list_sort) {
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
526 int_test_data<1500> testdata;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
527 std::array<int, 1500> sorted{};
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
528 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
529
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
530 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
531 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
532 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
533
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
534 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, cx_cmp_int);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
535
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
536 node *check = reinterpret_cast<node *>(begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
537 node *check_last = nullptr;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
538 cx_for_n (i, sorted.size()) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
539 EXPECT_EQ(check->data, sorted[i]);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
540 EXPECT_EQ(check->prev, check_last);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
541 if (i < sorted.size() - 1) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
542 ASSERT_NE(check->next, nullptr);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
543 }
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
544 check_last = check;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
545 check = check->next;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
546 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
547 EXPECT_EQ(check, nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
548 EXPECT_EQ(end, check_last);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
549 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
550
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
551 TEST(LinkedList_LowLevel, cx_linked_list_reverse) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
552 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
553 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
554
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
555 auto begin = reinterpret_cast<void *>(testdata.begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
556 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
557 auto orig_begin = begin, orig_end = end;
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
558
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
559 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
560 EXPECT_EQ(end, orig_begin);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
561 EXPECT_EQ(begin, orig_end);
639
309e8b08c60e temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
562 EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, cx_cmp_int), 0);
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
563 }
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
564
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
565 class HighLevelTest : public ::testing::Test {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
566 mutable std::unordered_set<CxList *> lists;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
567 protected:
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
568 CxTestingAllocator testingAllocator;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
569
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
570 void TearDown() override {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
571 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
572 EXPECT_TRUE(testingAllocator.verify());
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
573 }
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 static constexpr size_t testdata_len = 250;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
576 int_test_data<testdata_len> testdata;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
577
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
578 auto autofree(CxList *list) const -> CxList * {
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
579 if (list != nullptr) lists.insert(list);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
580 return list;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
581 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
582
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
583 auto linkedListFromTestData() const -> CxList * {
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
584 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
585 cxListAddArray(list, testdata.data.data(), testdata_len);
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
586 return list;
517
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
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
589 auto pointerLinkedListFromTestData() const -> CxList * {
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
590 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
591 // note: cannot use cxListAddArray() because we don't have a list of pointers
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
592 cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
593 return list;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
594 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
595
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
596 auto arrayListFromTestData() const -> CxList * {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
597 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), testdata_len));
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
598 cxListAddArray(list, testdata.data.data(), testdata_len);
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
599 return list;
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
600 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
601
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
602 void verifyCreate(CxList *list) const {
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
603 EXPECT_EQ(list->content_destructor_type, CX_DESTRUCTOR_NONE);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
604 EXPECT_EQ(list->size, 0);
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
605 EXPECT_EQ(list->allocator, &testingAllocator);
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
606 EXPECT_EQ(list->cmpfunc, cx_cmp_int);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
607 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
608
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
609 void verifyAdd(
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
610 CxList *list,
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
611 bool as_pointer
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
612 ) {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
613 auto len = testdata_len;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
614 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
615 EXPECT_EQ(list->size, len);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
616 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
617 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
618 cx_for_n (i, len) ++testdata.data[i];
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
619 if (as_pointer) {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
620 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
621 } else {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
622 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
623 }
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
624 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
625
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
626 static void verifyInsert(CxList *list) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
627 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
628
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
629 EXPECT_NE(cxListInsert(list, 1, &a), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
630 EXPECT_EQ(list->size, 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
631 EXPECT_EQ(cxListInsert(list, 0, &a), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
632 EXPECT_EQ(list->size, 1);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
633 EXPECT_EQ(cxListInsert(list, 0, &b), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
634 EXPECT_EQ(list->size, 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
635 EXPECT_EQ(cxListInsert(list, 1, &c), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
636 EXPECT_EQ(list->size, 3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
637 EXPECT_EQ(cxListInsert(list, 3, &d), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
638
611
77efa5163ae5 #219 array list: implement insert
Mike Becker <universe@uap-core.de>
parents: 610
diff changeset
639 ASSERT_EQ(list->size, 4);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
640 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
641
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
642 EXPECT_EQ(*(int *) cxListAt(list, 0), 47);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
643 EXPECT_EQ(*(int *) cxListAt(list, 1), 13);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
644 EXPECT_EQ(*(int *) cxListAt(list, 2), 5);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
645 EXPECT_EQ(*(int *) cxListAt(list, 3), 42);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
646 }
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
647
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
648 static void verifyInsertArray(
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
649 CxList *list,
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
650 bool pointers = false
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
651 ) {
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
652 int a[5] = {5, 47, 11, 13, 42};
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
653 int b[5] = {9, 18, 72, 50, 7};
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
654 int *aptr[5];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
655 int *bptr[5];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
656 cx_for_n(i, 5) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
657 aptr[i] = &a[i];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
658 bptr[i] = &b[i];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
659 }
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
660
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
661 size_t inserted;
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
662
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
663 if (pointers) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
664 inserted = cxListInsertArray(list, 0, aptr, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
665 } else {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
666 inserted = cxListInsertArray(list, 0, a, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
667 }
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
668 EXPECT_EQ(inserted, 5);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
669 EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
670 EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
671 EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
672 EXPECT_EQ(*(int *) cxListAt(list, 3), 13);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
673 EXPECT_EQ(*(int *) cxListAt(list, 4), 42);
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
674 if (pointers) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
675 inserted = cxListInsertArray(list, 3, bptr, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
676 } else {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
677 inserted = cxListInsertArray(list, 3, b, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
678 }
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
679 EXPECT_EQ(inserted, 5);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
680 EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
681 EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
682 EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
683 EXPECT_EQ(*(int *) cxListAt(list, 3), 9);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
684 EXPECT_EQ(*(int *) cxListAt(list, 4), 18);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
685 EXPECT_EQ(*(int *) cxListAt(list, 5), 72);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
686 EXPECT_EQ(*(int *) cxListAt(list, 6), 50);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
687 EXPECT_EQ(*(int *) cxListAt(list, 7), 7);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
688 EXPECT_EQ(*(int *) cxListAt(list, 8), 13);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
689 EXPECT_EQ(*(int *) cxListAt(list, 9), 42);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
690 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
691
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
692 void verifyRemove(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
693 EXPECT_EQ(cxListRemove(list, 2), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
694 EXPECT_EQ(cxListRemove(list, 4), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
695 EXPECT_EQ(list->size, testdata_len - 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
696 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
697 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
698 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
699 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
700 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
701 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
702
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
703 EXPECT_EQ(cxListRemove(list, 0), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
704 EXPECT_EQ(list->size, testdata_len - 3);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
705 EXPECT_GE(list->capacity, list->size);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
706 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
707 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
708
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
709 EXPECT_NE(cxListRemove(list, testdata_len), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
710 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
711
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
712 void verifyClear(CxList *list) {
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
713 // use the testing allocator for testing the destructor function
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
714 list->content_destructor_type = CX_DESTRUCTOR_ADVANCED;
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
715 list->advanced_destructor.func = free_testdatastruct;
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
716 list->advanced_destructor.data = &testingAllocator;
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
717
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
718 testdatastruct s[10];
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
719 for (auto &t: s) {
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
720 t.ptr = cxMalloc(&testingAllocator, 16);
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
721 cxListAdd(list, &t);
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
722 }
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
723
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
724 cxListClear(list);
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
725 }
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
726
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
727 static void verifySwap(CxList *list) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
728 ASSERT_EQ(list->size, 0);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
729
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
730 int original[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
731 int swapped[16] = {8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13};
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
732
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
733 // we have to add the items one by one, because it could be a pointer list
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
734 cx_for_n(i, 16) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
735 cxListAdd(list, &original[i]);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
736 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
737
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
738 int result;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
739
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
740 // execute the test two times with different item sizes
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
741 result = cxListSwap(list, 1, 4);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
742 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
743 result = cxListSwap(list, 2, 14);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
744 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
745 result = cxListSwap(list, 9, 6);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
746 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
747 result = cxListSwap(list, 3, 3);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
748 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
749 result = cxListSwap(list, 10, 11);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
750 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
751 result = cxListSwap(list, 8, 0);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
752 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
753 result = cxListSwap(list, 7, 12);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
754 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
755 result = cxListSwap(list, 13, 15);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
756 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
757
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
758 result = cxListSwap(list, 5, 16);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
759 EXPECT_NE(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
760 result = cxListSwap(list, 16, 6);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
761 EXPECT_NE(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
762 result = cxListSwap(list, 16, 17);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
763 EXPECT_NE(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
764
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
765 auto iter = cxListIterator(list);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
766 cx_foreach(int*, e, iter) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
767 EXPECT_EQ(*e, swapped[iter.index]);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
768 }
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
769 iter = cxListBackwardsIterator(list);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
770 cx_foreach(int*, e, iter) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
771 EXPECT_EQ(*e, swapped[iter.index]);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
772 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
773 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
774
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
775 void verifyAt(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
776 auto len = testdata_len;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
777 EXPECT_EQ(list->size, len);
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
778 cx_for_n (i, len) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
779 EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
780 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
781 EXPECT_EQ(cxListAt(list, list->size), nullptr);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
782 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
783
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
784 void verifyFind(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
785 cx_for_n (attempt, 25) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
786 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
787 int val = testdata.data[exp];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
788 // 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
789 cx_for_n (i, exp) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
790 if (testdata.data[i] == val) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
791 exp = i;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
792 break;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
793 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
794 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
795 EXPECT_EQ(cxListFind(list, &val), exp);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
796 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
797 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
798
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
799 void verifySort(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
800 std::array<int, testdata_len> expected{};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
801 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
802 cxListSort(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
803 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
804 }
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
805
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
806 void verifyIterator(CxList *list) const {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
807 auto iter = cxListIterator(list);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
808 size_t i = 0;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
809 cx_foreach(int*, x, iter) {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
810 ASSERT_EQ(i, iter.index);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
811 EXPECT_EQ(*x, testdata.data[iter.index]);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
812 i++;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
813 }
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
814 ASSERT_EQ(i, list->size);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
815 iter = cxListBackwardsIterator(list);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
816 cx_foreach(int*, x, iter) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
817 ASSERT_EQ(i - 1, iter.index);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
818 EXPECT_EQ(*x, testdata.data[iter.index]);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
819 i--;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
820 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
821 ASSERT_EQ(i, 0);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
822 auto len = testdata_len;
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
823 i = len / 2;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
824 auto mut_iter = cxListMutIteratorAt(list, i);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
825 size_t j = 0;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
826 cx_foreach(int*, x, mut_iter) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
827 ASSERT_EQ(mut_iter.index, len / 2 + j / 2);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
828 ASSERT_EQ(*x, testdata.data[i]);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
829 if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
830 i++;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
831 j++;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
832 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
833 ASSERT_EQ(i, len);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
834 i = len / 2;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
835 j = 0;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
836 mut_iter = cxListMutBackwardsIteratorAt(list, i - 1);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
837 cx_foreach(int*, x, mut_iter) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
838 ASSERT_EQ(mut_iter.index, len / 2 - 1 - j);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
839 ASSERT_EQ(*x, testdata.data[i - 1]);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
840 if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
841 i--;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
842 j++;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
843 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
844 ASSERT_EQ(i, 0);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
845 ASSERT_EQ(list->size, len / 2);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
846 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
847 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
848
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
849 static void verifyInsertViaIterator(CxList *list) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
850 int newdata[] = {10, 20, 30, 40, 50};
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
851
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
852 auto iter = cxListMutIteratorAt(list, 2);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
853 EXPECT_TRUE(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
854 EXPECT_EQ(iter.index, 2);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
855 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
856 cxListInsertAfter(&iter, &newdata[0]);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
857 EXPECT_TRUE(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
858 EXPECT_EQ(iter.index, 2);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
859 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
860 cxListInsertBefore(&iter, &newdata[1]);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
861 EXPECT_TRUE(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
862 EXPECT_EQ(iter.index, 3);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
863 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
864
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
865 iter = cxListMutIterator(list);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
866 cxListInsertBefore(&iter, &newdata[2]);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
867 EXPECT_TRUE(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
868 EXPECT_EQ(iter.index, 1);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
869 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
870 iter = cxListMutIteratorAt(list, list->size);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
871 cxListInsertBefore(&iter, &newdata[3]);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
872 EXPECT_FALSE(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
873 EXPECT_EQ(iter.index, 9);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
874 iter = cxListMutIteratorAt(list, list->size);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
875 cxListInsertAfter(&iter, &newdata[4]);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
876 EXPECT_FALSE(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
877 EXPECT_EQ(iter.index, 10);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
878
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
879 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
880 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
881 }
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
882
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
883 void verifyReverse(CxList *list) const {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
884 cxListReverse(list);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
885 cx_for_n(i, testdata_len) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
886 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
887 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
888 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
889
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
890 static void verifyCompare(
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
891 CxList *left,
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
892 CxList *right
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
893 ) {
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
894 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
895 int x = 42;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
896 cxListAdd(left, &x);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
897 ASSERT_GT(left->size, right->size);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
898 EXPECT_GT(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
899 EXPECT_LT(cxListCompare(right, left), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
900 cxListAdd(right, &x);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
901 ASSERT_EQ(left->size, right->size);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
902 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
903 int a = 5, b = 10;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
904 cxListInsert(left, 15, &a);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
905 cxListInsert(right, 15, &b);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
906 ASSERT_EQ(left->size, right->size);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
907 EXPECT_LT(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
908 EXPECT_GT(cxListCompare(right, left), 0);
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
909 *(int *) cxListAt(left, 15) = 10;
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
910 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
911 }
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
912 };
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
913
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
914 class LinkedList : public HighLevelTest {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
915 };
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
916
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
917 class PointerLinkedList : public HighLevelTest {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
918 };
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
919
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
920 class ArrayList : public HighLevelTest {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
921 };
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
922
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
923 TEST_F(PointerLinkedList, cxListStorePointers) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
924 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47));
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
925 EXPECT_FALSE(cxListIsStoringPointers(list));
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
926 cxListStorePointers(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
927 EXPECT_EQ(list->itemsize, sizeof(void *));
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
928 EXPECT_NE(list->cl, nullptr);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
929 EXPECT_NE(list->climpl, nullptr);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
930 EXPECT_TRUE(cxListIsStoringPointers(list));
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
931 cxListStoreObjects(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
932 EXPECT_NE(list->cl, nullptr);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
933 EXPECT_EQ(list->climpl, nullptr);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
934 EXPECT_FALSE(cxListIsStoringPointers(list));
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
935
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
936 list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
937 EXPECT_EQ(list->itemsize, sizeof(void *));
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
938 EXPECT_NE(list->cl, nullptr);
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
939 EXPECT_NE(list->climpl, nullptr);
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
940 EXPECT_TRUE(cxListIsStoringPointers(list));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
941 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
942
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
943 TEST_F(LinkedList, cxLinkedListCreate) {
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
944 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
945 ASSERT_NE(list, nullptr);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
946 EXPECT_EQ(list->itemsize, sizeof(int));
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
947 EXPECT_EQ(list->capacity, (size_t) -1);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
948 verifyCreate(list);
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
949 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
950
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
951 TEST_F(LinkedList, cxLinkedListCreateSimple) {
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
952 CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int)));
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
953 ASSERT_NE(list, nullptr);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
954 EXPECT_EQ(list->itemsize, sizeof(int));
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
955 EXPECT_EQ(list->capacity, (size_t) -1);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
956 EXPECT_EQ(list->cmpfunc, nullptr);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
957 EXPECT_EQ(list->allocator, cxDefaultAllocator);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
958 }
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
959
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
960 TEST_F(ArrayList, cxArrayListCreate) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
961 CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
962 ASSERT_NE(list, nullptr);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
963 EXPECT_EQ(list->itemsize, sizeof(int));
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
964 EXPECT_EQ(list->capacity, 8);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
965 verifyCreate(list);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
966 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
967
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
968 TEST_F(ArrayList, cxArrayListCreateSimple) {
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
969 CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8));
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
970 ASSERT_NE(list, nullptr);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
971 EXPECT_EQ(list->cmpfunc, nullptr);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
972 EXPECT_EQ(list->allocator, cxDefaultAllocator);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
973 EXPECT_EQ(list->itemsize, sizeof(int));
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
974 EXPECT_EQ(list->capacity, 8);
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
975 }
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
976
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
977 TEST_F(LinkedList, cxListAdd) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
978 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
979 verifyAdd(list, false);
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
980 }
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
981
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
982 TEST_F(PointerLinkedList, cxListAdd) {
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
983 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
984 verifyAdd(list, true);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
985 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
986
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
987 TEST_F(ArrayList, cxListAdd) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
988 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
989 verifyAdd(list, false);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
990 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
991
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
992 TEST_F(LinkedList, cxListInsert) {
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
993 verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
994 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
995
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
996 TEST_F(PointerLinkedList, cxListInsert) {
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
997 verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
998 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
999
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1000 TEST_F(ArrayList, cxListInsert) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1001 verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2)));
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1002 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1003
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1004 TEST_F(LinkedList, cxListInsertArray) {
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1005 verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1006 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1007
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1008 TEST_F(PointerLinkedList, cxListInsertArray) {
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1009 verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)), true);
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1010 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1011
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1012 TEST_F(ArrayList, cxListInsertArray) {
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1013 verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)));
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1014 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
1015
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1016 TEST_F(LinkedList, cxListRemove) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1017 verifyRemove(linkedListFromTestData());
506
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
1018 }
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
1019
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1020 TEST_F(PointerLinkedList, cxListRemove) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1021 verifyRemove(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1022 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1023
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1024 TEST_F(ArrayList, cxListRemove) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1025 verifyRemove(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1026 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1027
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1028 TEST_F(LinkedList, cxListClear) {
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1029 verifyClear(autofree(cxLinkedListCreateSimple(sizeof(testdatastruct))));
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1030 }
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1031
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1032 TEST_F(PointerLinkedList, cxListClear) {
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1033 verifyClear(cxLinkedListCreateSimple(CX_STORE_POINTERS));
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1034 }
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1035
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1036 TEST_F(ArrayList, cxListClear) {
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1037 verifyClear(autofree(cxArrayListCreateSimple(sizeof(testdatastruct), 8)));
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1038 }
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1039
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1040 TEST_F(LinkedList, cxListSwap) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1041 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1042 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1043
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1044 TEST_F(PointerLinkedList, cxListSwap) {
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1045 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)));
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1046 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1047
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1048 TEST_F(ArrayList, cxListSwap) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1049 verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 16)));
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1050 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1051
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1052 TEST_F(LinkedList, cxListSwapNoSBO) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1053 CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1054 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1055 CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1056 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1057
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1058 TEST_F(PointerLinkedList, cxListSwapNoSBO) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1059 CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1060 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)));
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1061 CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1062 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1063
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1064 TEST_F(ArrayList, cxListSwapNoSBO) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1065 CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1066 verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 16)));
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1067 CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1068 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
1069
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1070 TEST_F(LinkedList, cxListAt) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1071 verifyAt(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1072 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
1073
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1074 TEST_F(PointerLinkedList, cxListAt) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1075 verifyAt(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1076 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1077
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1078 TEST_F(ArrayList, cxListAt) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1079 verifyAt(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1080 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1081
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1082 TEST_F(LinkedList, cxListFind) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1083 verifyFind(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1084 }
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
1085
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1086 TEST_F(PointerLinkedList, cxListFind) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1087 verifyFind(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1088 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1089
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1090 TEST_F(ArrayList, cxListFind) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1091 verifyFind(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1092 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1093
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1094 TEST_F(LinkedList, cxListSort) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1095 verifySort(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1096 }
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
1097
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1098 TEST_F(PointerLinkedList, cxListSort) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1099 verifySort(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1100 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1101
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1102 TEST_F(ArrayList, cxListSort) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1103 verifySort(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1104 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1105
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1106 TEST_F(LinkedList, Iterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1107 verifyIterator(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1108 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1109
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1110 TEST_F(PointerLinkedList, Iterator) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1111 verifyIterator(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1112 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1113
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1114 TEST_F(ArrayList, Iterator) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1115 verifyIterator(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1116 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1117
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1118 TEST_F(LinkedList, InsertViaIterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1119 int fivenums[] = {0, 1, 2, 3, 4, 5};
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
1120 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
1121 cxListAddArray(list, fivenums, 5);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1122 verifyInsertViaIterator(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
1123 }
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
1124
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1125 TEST_F(PointerLinkedList, InsertViaIterator) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1126 int fivenums[] = {0, 1, 2, 3, 4, 5};
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1127 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1128 // note: cannot use cxListAddArray() because we don't have a list of pointers
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1129 cx_for_n(i, 5) cxListAdd(list, &fivenums[i]);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1130 verifyInsertViaIterator(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1131 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1132
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1133 TEST_F(ArrayList, InsertViaIterator) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1134 int fivenums[] = {0, 1, 2, 3, 4, 5};
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1135 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4));
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
1136 cxListAddArray(list, fivenums, 5);
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1137 verifyInsertViaIterator(list);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1138 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1139
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1140 TEST_F(LinkedList, cxListReverse) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1141 verifyReverse(linkedListFromTestData());
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1142 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1143
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1144 TEST_F(PointerLinkedList, cxListReverse) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1145 verifyReverse(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1146 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1147
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1148 TEST_F(ArrayList, cxListReverse) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1149 verifyReverse(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1150 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1151
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1152 TEST_F(LinkedList, cxListCompare) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1153 auto left = linkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1154 auto right = linkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1155 verifyCompare(left, right);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1156 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
1157
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1158 TEST_F(LinkedList, cxListCompareWithPtrList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1159 auto left = linkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1160 auto right = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1161 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1162 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1163
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1164 TEST_F(LinkedList, cxListCompareWithArrayList) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1165 auto left = linkedListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1166 auto right = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1167 verifyCompare(left, right);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1168 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1169
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1170 TEST_F(PointerLinkedList, cxListCompare) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1171 auto left = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1172 auto right = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1173 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1174 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1175
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1176 TEST_F(PointerLinkedList, cxListCompareWithNormalList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1177 auto left = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1178 auto right = linkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1179 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1180 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1181
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1182 TEST_F(PointerLinkedList, cxListCompareWithArrayList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1183 auto left = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1184 auto right = arrayListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1185 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1186 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1187
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1188 TEST_F(ArrayList, cxListCompare) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1189 auto left = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1190 auto right = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1191 verifyCompare(left, right);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1192 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1193
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1194 TEST_F(ArrayList, cxListCompareWithPtrList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1195 auto left = arrayListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1196 auto right = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1197 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1198 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1199
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1200 TEST_F(ArrayList, cxListCompareWithNormalList) {
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1201 auto left = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1202 auto right = linkedListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1203 verifyCompare(left, right);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
1204 }
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1205
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1206 TEST_F(PointerLinkedList, NoDestructor) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1207 void *item = cxMalloc(&testingAllocator, sizeof(int));
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1208 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1209 cxListAdd(list, item);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1210 ASSERT_FALSE(testingAllocator.verify());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1211 cxListDestroy(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1212 EXPECT_FALSE(testingAllocator.verify());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1213 cxFree(&testingAllocator, item);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1214 EXPECT_TRUE(testingAllocator.verify());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1215 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1216
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1217 TEST_F(PointerLinkedList, SimpleDestructor) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1218 int item = 0;
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1219 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1220 list->content_destructor_type = CX_DESTRUCTOR_SIMPLE;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1221 list->simple_destructor = [](void *elem) { *(int *) elem = 42; };
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1222 cxListAdd(list, &item);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1223 cxListDestroy(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1224 EXPECT_EQ(item, 42);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1225 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1226
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1227 TEST_F(PointerLinkedList, AdvancedDestructor) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1228 void *item = cxMalloc(&testingAllocator, sizeof(int));
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
1229 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1230 list->content_destructor_type = CX_DESTRUCTOR_ADVANCED;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1231 list->advanced_destructor.data = &testingAllocator;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1232 list->advanced_destructor.func = (cx_destructor_func2) cxFree;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1233 cxListAdd(list, item);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1234 ASSERT_FALSE(testingAllocator.verify());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1235 cxListDestroy(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1236 EXPECT_TRUE(testingAllocator.verify());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
1237 }

mercurial