Fri, 29 Dec 2023 17:17:43 +0100
revert the insanely stupid idea to automatically run the test program on default build
390 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
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 | 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 | |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
41 | struct node { |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
42 | node *next = nullptr; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
43 | node *prev = nullptr; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
44 | int data = 0; |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
45 | }; |
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
46 | |
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
47 | 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
|
48 | 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
|
49 | 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
|
50 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
51 | struct node_test_data { |
520
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
52 | node *begin = nullptr; |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
53 | |
520
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
54 | 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
|
55 | auto n = begin; |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
56 | while (n != nullptr) { |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
57 | nodes.push_back(n); |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
58 | n = n->next; |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
59 | } |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
60 | } |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
61 | |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
62 | node_test_data(node_test_data &) = delete; |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
63 | |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
64 | node_test_data(node_test_data &&) = default; |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
65 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
66 | ~node_test_data() { |
520
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
67 | 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
|
68 | } |
520
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
69 | |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
70 | private: |
f937c6d11d1f
fix memory leak in test data
Mike Becker <universe@uap-core.de>
parents:
518
diff
changeset
|
71 | std::vector<node *> nodes; |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
72 | }; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
73 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
74 | 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
|
75 | if (len == 0) return node_test_data{nullptr}; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
76 | auto begin = new node; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
77 | auto prev = begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
78 | for (size_t i = 1; i < len; i++) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
79 | auto n = new node; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
80 | 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
|
81 | prev = n; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
82 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
83 | 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
|
84 | } |
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
85 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
86 | template<typename InputIter> |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
87 | 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
|
88 | InputIter begin, |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
89 | InputIter end |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
90 | ) { |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
91 | if (begin == end) return node_test_data{nullptr}; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
92 | node *first = new node; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
93 | first->data = *begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
94 | node *prev = first; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
95 | begin++; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
96 | for (; begin != end; begin++) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
97 | auto n = new node; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
98 | n->data = *begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
99 | 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
|
100 | prev = n; |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
101 | } |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
102 | 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
|
103 | } |
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
104 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
105 | 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
|
106 | 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
|
107 | } |
0d3c6075f82c
#129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents:
507
diff
changeset
|
108 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
109 | template<size_t N> |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
110 | struct int_test_data { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
111 | 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
|
112 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
113 | int_test_data() { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
114 | 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
|
115 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
116 | }; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
117 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
118 | TEST(LinkedList_LowLevel, link_unlink) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
119 | node a, b, c; |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
120 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
121 | 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
|
122 | EXPECT_EQ(a.prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
123 | EXPECT_EQ(a.next, &b); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
124 | EXPECT_EQ(b.prev, &a); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
125 | 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
|
126 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
127 | 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
|
128 | EXPECT_EQ(a.prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
129 | EXPECT_EQ(a.next, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
130 | EXPECT_EQ(b.prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
131 | 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
|
132 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
133 | 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
|
134 | 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
|
135 | 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
|
136 | EXPECT_EQ(a.prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
137 | EXPECT_EQ(a.next, &b); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
138 | EXPECT_EQ(b.prev, &a); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
139 | EXPECT_EQ(b.next, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
140 | EXPECT_EQ(c.prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
141 | 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
|
142 | } |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
143 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
144 | TEST(LinkedList_LowLevel, cx_linked_list_at) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
150 | 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
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | 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
|
155 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
156 | 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
|
157 | 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
|
158 | 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
|
159 | 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
|
160 | 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
|
161 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
162 | 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
|
163 | 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
|
164 | } |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
165 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
166 | TEST(LinkedList_LowLevel, cx_linked_list_find) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
167 | 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
|
168 | 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
|
169 | int s; |
4bd19279778c
use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents:
486
diff
changeset
|
170 | |
4bd19279778c
use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents:
486
diff
changeset
|
171 | s = 2; |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
172 | 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
|
173 | s = 4; |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
174 | 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
|
175 | s = 6; |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
176 | 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
|
177 | s = 8; |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
178 | 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
|
179 | s = 10; |
699
35b2b99ee523
make list find return a negative value when elem not found
Mike Becker <universe@uap-core.de>
parents:
680
diff
changeset
|
180 | EXPECT_LT(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
|
181 | s = -2; |
699
35b2b99ee523
make list find return a negative value when elem not found
Mike Becker <universe@uap-core.de>
parents:
680
diff
changeset
|
182 | EXPECT_LT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 0); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
183 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
184 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
185 | TEST(LinkedList_LowLevel, cx_linked_list_compare) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
186 | 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
|
187 | 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
|
188 | 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
|
189 | 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
|
190 | |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
191 | 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
|
192 | 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
|
193 | 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
|
194 | 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
|
195 | 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
|
196 | } |
4bd19279778c
use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents:
486
diff
changeset
|
197 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
198 | TEST(LinkedList_LowLevel, cx_linked_list_add) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
199 | // test with begin, end / prev, next |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
200 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
201 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
202 | 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
|
203 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
204 | 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
|
205 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
206 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
207 | EXPECT_EQ(nodes[0].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
208 | EXPECT_EQ(nodes[0].next, nullptr); |
449 | 209 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
210 | 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
|
211 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
212 | EXPECT_EQ(end, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
213 | EXPECT_EQ(nodes[0].next, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
214 | EXPECT_EQ(nodes[1].prev, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
215 | } |
449 | 216 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
217 | // test with begin only / prev, next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
218 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
219 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
220 | void *begin = nullptr; |
449 | 221 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
222 | 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
|
223 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
224 | 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
|
225 | EXPECT_EQ(begin, &nodes[0]); |
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]); |
449 | 228 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
229 | cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
230 | EXPECT_EQ(nodes[1].next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
231 | EXPECT_EQ(nodes[2].prev, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
232 | } |
449 | 233 | |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
234 | // test with end only / prev, next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
235 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
236 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
237 | void *end = nullptr; |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
238 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
239 | 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
|
240 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
241 | 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
|
242 | EXPECT_EQ(end, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
243 | EXPECT_EQ(nodes[0].next, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
244 | 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
|
245 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
246 | cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
247 | EXPECT_EQ(end, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
248 | EXPECT_EQ(nodes[1].next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
249 | EXPECT_EQ(nodes[2].prev, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
250 | } |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
251 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
252 | // test with begin, end / next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
253 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
254 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
255 | void *begin = nullptr, *end = nullptr; |
449 | 256 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
257 | 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
|
258 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
259 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
260 | 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
|
261 | EXPECT_EQ(end, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
262 | EXPECT_EQ(nodes[0].next, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
263 | EXPECT_EQ(nodes[1].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
264 | } |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
265 | } |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
266 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
267 | 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
|
268 | // test with begin, end / prev, next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
269 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
270 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
271 | 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
|
272 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
273 | 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
|
274 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
275 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
276 | EXPECT_EQ(nodes[0].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
277 | 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
|
278 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
279 | 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
|
280 | EXPECT_EQ(begin, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
281 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
282 | EXPECT_EQ(nodes[1].next, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
283 | EXPECT_EQ(nodes[0].prev, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
284 | } |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
285 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
286 | // test with begin only / prev, next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
287 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
288 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
289 | void *begin = nullptr; |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
290 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
291 | 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
|
292 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
293 | 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
|
294 | EXPECT_EQ(begin, &nodes[1]); |
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]); |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
297 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
298 | cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
299 | EXPECT_EQ(begin, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
300 | EXPECT_EQ(nodes[2].next, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
301 | EXPECT_EQ(nodes[1].prev, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
302 | } |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
303 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
304 | // test with end only / prev, next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
305 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
306 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
307 | void *end = nullptr; |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
308 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
309 | 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
|
310 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
311 | 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
|
312 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
313 | EXPECT_EQ(nodes[1].next, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
314 | 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
|
315 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
316 | cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
317 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
318 | EXPECT_EQ(nodes[2].next, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
319 | EXPECT_EQ(nodes[1].prev, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
320 | } |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
321 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
322 | // test with begin, end / next |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
323 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
324 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
325 | 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
|
326 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
327 | 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
|
328 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
329 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
330 | 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
|
331 | 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
|
332 | EXPECT_EQ(begin, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
333 | EXPECT_EQ(end, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
334 | EXPECT_EQ(nodes[1].next, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
335 | EXPECT_EQ(nodes[2].next, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
336 | EXPECT_EQ(nodes[1].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
337 | EXPECT_EQ(nodes[0].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
338 | } |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
339 | } |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
340 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
341 | TEST(LinkedList_LowLevel, cx_linked_list_insert) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
342 | // insert mid list |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
343 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
344 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
345 | 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
|
346 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
347 | 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
|
348 | 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
|
349 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
350 | 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
|
351 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
352 | EXPECT_EQ(end, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
353 | EXPECT_EQ(nodes[1].next, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
354 | EXPECT_EQ(nodes[2].prev, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
355 | EXPECT_EQ(nodes[3].prev, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
356 | EXPECT_EQ(nodes[3].next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
357 | } |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
358 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
359 | // insert end |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
360 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
361 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
362 | 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
|
363 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
364 | 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
|
365 | 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
|
366 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
367 | 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
|
368 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
369 | EXPECT_EQ(end, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
370 | EXPECT_EQ(nodes[2].next, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
371 | EXPECT_EQ(nodes[3].prev, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
372 | EXPECT_EQ(nodes[3].next, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
373 | } |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
374 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
375 | // insert begin |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
376 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
377 | node nodes[4]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
378 | 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
|
379 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
380 | 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
|
381 | 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
|
382 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
383 | 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
|
384 | EXPECT_EQ(begin, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
385 | EXPECT_EQ(end, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
386 | EXPECT_EQ(nodes[0].prev, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
387 | EXPECT_EQ(nodes[3].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
388 | EXPECT_EQ(nodes[3].next, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
389 | } |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
390 | } |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
391 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
392 | 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
|
393 | // insert mid list |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
394 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
395 | node nodes[5]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
396 | 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
|
397 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
398 | 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
|
399 | 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
|
400 | 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
|
401 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
402 | 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
|
403 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
404 | EXPECT_EQ(end, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
405 | EXPECT_EQ(nodes[1].next, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
406 | EXPECT_EQ(nodes[2].prev, &nodes[4]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
407 | EXPECT_EQ(nodes[3].prev, &nodes[1]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
408 | EXPECT_EQ(nodes[4].next, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
409 | } |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
410 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
411 | // insert end |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
412 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
413 | node nodes[5]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
414 | void *begin = &nodes[0], *end = &nodes[2]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
415 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
416 | 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
|
417 | 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
|
418 | 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
|
419 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
420 | 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
|
421 | EXPECT_EQ(begin, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
422 | EXPECT_EQ(end, &nodes[4]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
423 | EXPECT_EQ(nodes[2].next, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
424 | EXPECT_EQ(nodes[3].prev, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
425 | EXPECT_EQ(nodes[4].next, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
426 | } |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
427 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
428 | // insert begin |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
429 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
430 | node nodes[5]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
431 | void *begin = &nodes[0], *end = &nodes[2]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
432 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
433 | 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
|
434 | 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
|
435 | 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
|
436 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
437 | 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
|
438 | EXPECT_EQ(begin, &nodes[3]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
439 | EXPECT_EQ(end, &nodes[2]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
440 | EXPECT_EQ(nodes[0].prev, &nodes[4]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
441 | EXPECT_EQ(nodes[3].prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
442 | EXPECT_EQ(nodes[4].next, &nodes[0]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
443 | } |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
444 | } |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
445 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
446 | TEST(LinkedList_LowLevel, cx_linked_list_first) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
447 | auto testdata = create_nodes_test_data(3); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
448 | auto begin = testdata.begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
449 | 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
|
450 | 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
|
451 | 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
|
452 | } |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
453 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
454 | TEST(LinkedList_LowLevel, cx_linked_list_last) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
455 | auto testdata = create_nodes_test_data(3); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
456 | auto begin = testdata.begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
457 | auto end = begin->next->next; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
458 | 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
|
459 | 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
|
460 | 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
|
461 | } |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
462 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
463 | TEST(LinkedList_LowLevel, cx_linked_list_prev) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
464 | auto testdata = create_nodes_test_data(3); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
465 | auto begin = testdata.begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
466 | 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
|
467 | 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
|
468 | 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
|
469 | } |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
470 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
471 | TEST(LinkedList_LowLevel, cx_linked_list_remove) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
472 | 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
|
473 | auto begin = reinterpret_cast<void *>(testdata.begin); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
474 | auto first = testdata.begin; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
475 | auto second = first->next; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
476 | auto third = second->next; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
477 | 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
|
478 | |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
479 | 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
|
480 | EXPECT_EQ(begin, first); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
481 | EXPECT_EQ(end, third); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
482 | EXPECT_EQ(first->prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
483 | EXPECT_EQ(first->next, third); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
484 | EXPECT_EQ(third->prev, first); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
485 | EXPECT_EQ(third->next, nullptr); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
486 | |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
487 | 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
|
488 | EXPECT_EQ(begin, first); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
489 | EXPECT_EQ(end, first); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
490 | EXPECT_EQ(first->prev, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
491 | EXPECT_EQ(first->next, nullptr); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
492 | |
486
d7ca126eab7f
add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents:
482
diff
changeset
|
493 | 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
|
494 | EXPECT_EQ(begin, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
495 | EXPECT_EQ(end, nullptr); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
496 | } |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
497 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
498 | TEST(LinkedList_LowLevel, cx_linked_list_size) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
499 | 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
|
500 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
501 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
502 | auto testdata = create_nodes_test_data(5); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
503 | 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
|
504 | } |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
505 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
506 | { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
507 | auto testdata = create_nodes_test_data(13); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
508 | EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 13); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
509 | } |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
510 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
511 | |
702
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
512 | TEST(LinkedList_LowLevel, cx_linked_list_sort_empty) { |
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
513 | void *begin = nullptr; |
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
514 | EXPECT_NO_FATAL_FAILURE( |
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
515 | cx_linked_list_sort(&begin, nullptr, loc_prev, loc_next, loc_data, cx_cmp_int); |
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
516 | ); |
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
517 | } |
3390b58ad15a
fix cx_linked_list_sort() not working for empty lists
Mike Becker <universe@uap-core.de>
parents:
699
diff
changeset
|
518 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
519 | TEST(LinkedList_LowLevel, cx_linked_list_sort) { |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
520 | int_test_data<1500> testdata; |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
521 | std::array<int, 1500> sorted{}; |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
522 | 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
|
523 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
524 | 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
|
525 | 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
|
526 | 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
|
527 | |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
528 | 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
|
529 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
530 | node *check = reinterpret_cast<node *>(begin); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
531 | node *check_last = nullptr; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
532 | cx_for_n (i, sorted.size()) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
533 | EXPECT_EQ(check->data, sorted[i]); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
534 | EXPECT_EQ(check->prev, check_last); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
535 | if (i < sorted.size() - 1) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
536 | ASSERT_NE(check->next, nullptr); |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
537 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
538 | check_last = check; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
539 | check = check->next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
540 | } |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
541 | EXPECT_EQ(check, nullptr); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
542 | EXPECT_EQ(end, check_last); |
498
435c9965b2dd
reorder the list test functions
Mike Becker <universe@uap-core.de>
parents:
497
diff
changeset
|
543 | } |
435c9965b2dd
reorder the list test functions
Mike Becker <universe@uap-core.de>
parents:
497
diff
changeset
|
544 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
545 | TEST(LinkedList_LowLevel, cx_linked_list_reverse) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
546 | 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
|
547 | 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
|
548 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
549 | auto begin = reinterpret_cast<void *>(testdata.begin); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
550 | 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
|
551 | auto orig_begin = begin, orig_end = end; |
509
0d3c6075f82c
#129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents:
507
diff
changeset
|
552 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
553 | 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
|
554 | EXPECT_EQ(end, orig_begin); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
555 | EXPECT_EQ(begin, orig_end); |
639
309e8b08c60e
temporarily remove pointer lists - see #234
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
556 | 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
|
557 | } |
498
435c9965b2dd
reorder the list test functions
Mike Becker <universe@uap-core.de>
parents:
497
diff
changeset
|
558 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
559 | class HighLevelTest : public ::testing::Test { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
560 | mutable std::unordered_set<CxList *> lists; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
561 | protected: |
518
74d0372f5c6f
improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents:
517
diff
changeset
|
562 | CxTestingAllocator testingAllocator; |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
563 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
564 | void TearDown() override { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
565 | 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
|
566 | EXPECT_TRUE(testingAllocator.verify()); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
567 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
568 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
569 | static constexpr size_t testdata_len = 250; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
570 | int_test_data<testdata_len> testdata; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
571 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
572 | auto autofree(CxList *list) const -> CxList * { |
606 | 573 | if (list != nullptr) lists.insert(list); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
574 | return list; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
575 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
576 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
577 | auto linkedListFromTestData() const -> CxList * { |
629
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
623
diff
changeset
|
578 | auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
623
diff
changeset
|
579 | cxListAddArray(list, testdata.data.data(), testdata_len); |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
623
diff
changeset
|
580 | return list; |
517
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 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
583 | 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
|
584 | 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
|
585 | // 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
|
586 | 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
|
587 | return list; |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
588 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
589 | |
606 | 590 | auto arrayListFromTestData() const -> CxList * { |
591 | 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
|
592 | cxListAddArray(list, testdata.data.data(), testdata_len); |
606 | 593 | return list; |
594 | } | |
595 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
596 | auto pointerArrayListFromTestData() const -> CxList * { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
597 | auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 256)); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
598 | // note: cannot use cxListAddArray() because we don't have a list of pointers |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
599 | cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
600 | return list; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
601 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
602 | |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
603 | void verifyAdd( |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
604 | CxList *list, |
606 | 605 | bool as_pointer |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
606 | ) { |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
607 | auto len = testdata_len; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
608 | cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
609 | EXPECT_EQ(cxListSize(list), len); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
610 | 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
|
611 | cx_for_n (i, len) ++testdata.data[i]; |
606 | 612 | if (as_pointer) { |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
613 | 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
|
614 | } else { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
615 | 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
|
616 | } |
0d3c6075f82c
#129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents:
507
diff
changeset
|
617 | } |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
618 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
619 | static void verifyInsert(CxList *list) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
620 | 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
|
621 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
622 | EXPECT_NE(cxListInsert(list, 1, &a), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
623 | EXPECT_EQ(cxListSize(list), 0); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
624 | EXPECT_EQ(cxListInsert(list, 0, &a), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
625 | EXPECT_EQ(cxListSize(list), 1); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
626 | EXPECT_EQ(cxListInsert(list, 0, &b), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
627 | EXPECT_EQ(cxListSize(list), 2); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
628 | EXPECT_EQ(cxListInsert(list, 1, &c), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
629 | EXPECT_EQ(cxListSize(list), 3); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
630 | EXPECT_EQ(cxListInsert(list, 3, &d), 0); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
631 | |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
632 | ASSERT_EQ(cxListSize(list), 4); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
633 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
634 | EXPECT_EQ(*(int *) cxListAt(list, 0), 47); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
635 | EXPECT_EQ(*(int *) cxListAt(list, 1), 13); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
636 | EXPECT_EQ(*(int *) cxListAt(list, 2), 5); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
637 | EXPECT_EQ(*(int *) cxListAt(list, 3), 42); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
638 | } |
498
435c9965b2dd
reorder the list test functions
Mike Becker <universe@uap-core.de>
parents:
497
diff
changeset
|
639 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
640 | static void verifyInsertArray( |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
641 | CxList *list, |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
642 | bool pointers = false |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
643 | ) { |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
644 | int a[5] = {5, 47, 11, 13, 42}; |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
645 | 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
|
646 | int *aptr[5]; |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
647 | int *bptr[5]; |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
648 | cx_for_n(i, 5) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
649 | aptr[i] = &a[i]; |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
650 | bptr[i] = &b[i]; |
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 | |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
653 | size_t inserted; |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
654 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
655 | if (pointers) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
656 | inserted = cxListInsertArray(list, 0, aptr, 5); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
657 | } else { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
658 | inserted = cxListInsertArray(list, 0, a, 5); |
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 | EXPECT_EQ(inserted, 5); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
661 | EXPECT_EQ(*(int *) cxListAt(list, 0), 5); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
662 | EXPECT_EQ(*(int *) cxListAt(list, 1), 47); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
663 | EXPECT_EQ(*(int *) cxListAt(list, 2), 11); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
664 | EXPECT_EQ(*(int *) cxListAt(list, 3), 13); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
665 | 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
|
666 | if (pointers) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
667 | inserted = cxListInsertArray(list, 3, bptr, 5); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
668 | } else { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
669 | inserted = cxListInsertArray(list, 3, b, 5); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
670 | } |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
671 | EXPECT_EQ(inserted, 5); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
672 | EXPECT_EQ(*(int *) cxListAt(list, 0), 5); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
673 | EXPECT_EQ(*(int *) cxListAt(list, 1), 47); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
674 | EXPECT_EQ(*(int *) cxListAt(list, 2), 11); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
675 | EXPECT_EQ(*(int *) cxListAt(list, 3), 9); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
676 | EXPECT_EQ(*(int *) cxListAt(list, 4), 18); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
677 | EXPECT_EQ(*(int *) cxListAt(list, 5), 72); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
678 | EXPECT_EQ(*(int *) cxListAt(list, 6), 50); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
679 | EXPECT_EQ(*(int *) cxListAt(list, 7), 7); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
680 | EXPECT_EQ(*(int *) cxListAt(list, 8), 13); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
681 | EXPECT_EQ(*(int *) cxListAt(list, 9), 42); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
682 | } |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
683 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
684 | void verifyRemove(CxList *list) const { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
685 | EXPECT_EQ(cxListRemove(list, 2), 0); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
686 | EXPECT_EQ(cxListRemove(list, 4), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
687 | EXPECT_EQ(cxListSize(list), testdata_len - 2); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
688 | 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
|
689 | 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
|
690 | 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
|
691 | 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
|
692 | 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
|
693 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
694 | EXPECT_EQ(cxListRemove(list, 0), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
695 | EXPECT_EQ(cxListSize(list), testdata_len - 3); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
696 | 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
|
697 | 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
|
698 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
699 | EXPECT_NE(cxListRemove(list, testdata_len), 0); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
700 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
701 | |
764
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
702 | void verifyFindRemove(CxList *list) const { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
703 | size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp) |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
704 | int val = testdata.data[exp]; |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
705 | // randomly picked number could occur earlier in list - find first position |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
706 | cx_for_n (i, exp) { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
707 | if (testdata.data[i] == val) { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
708 | exp = i; |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
709 | break; |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
710 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
711 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
712 | EXPECT_EQ(cxListSize(list), testdata_len); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
713 | EXPECT_EQ(cxListFind(list, &val), exp); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
714 | EXPECT_EQ(cxListFindRemove(list, &val), exp); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
715 | EXPECT_EQ(cxListSize(list), testdata_len - 1); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
716 | EXPECT_NE(cxListFind(list, &val), exp); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
717 | |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
718 | int notinlist = -1; |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
719 | EXPECT_LT(cxListFindRemove(list, ¬inlist), 0); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
720 | EXPECT_EQ(cxListSize(list), testdata_len - 1); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
721 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
722 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
723 | static void verifyClear(CxList *list) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
724 | cxListClear(list); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
725 | EXPECT_EQ(0, cxListSize(list)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
726 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
727 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
728 | static unsigned destr_test_ctr; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
729 | static int destr_last_value; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
730 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
731 | static void simple_destr_test_fun(void *data) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
732 | auto ptr = (int *) data; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
733 | destr_last_value = *ptr; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
734 | *ptr = destr_last_value + 1; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
735 | destr_test_ctr++; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
736 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
737 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
738 | static void advanced_destr_test_fun( |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
739 | [[maybe_unused]] void *u, |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
740 | void *data |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
741 | ) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
742 | simple_destr_test_fun(data); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
743 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
744 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
745 | void verifyAnyDestructor(CxList *list) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
746 | int off = cxListIsStoringPointers(list) ? 1 : 0; |
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
|
747 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
748 | cxListRemove(list, 15); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
749 | EXPECT_EQ(1, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
750 | EXPECT_EQ(testdata.data[15], destr_last_value + off); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
751 | EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
752 | cxListRemove(list, 47); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
753 | EXPECT_EQ(2, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
754 | EXPECT_EQ(testdata.data[48], destr_last_value + off); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
755 | EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
756 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
757 | auto iter = cxListMutIteratorAt(list, 7); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
758 | cxIteratorNext(iter); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
759 | EXPECT_EQ(2, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
760 | EXPECT_EQ(testdata.data[48], destr_last_value + off); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
761 | EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
762 | cxIteratorFlagRemoval(iter); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
763 | cxIteratorNext(iter); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
764 | EXPECT_EQ(3, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
765 | EXPECT_EQ(testdata.data[8], destr_last_value + off); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
766 | EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
767 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
768 | iter = cxListMutBackwardsIteratorAt(list, 5); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
769 | cxIteratorNext(iter); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
770 | EXPECT_EQ(3, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
771 | EXPECT_EQ(testdata.data[8], destr_last_value + off); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
772 | EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
773 | cxIteratorFlagRemoval(iter); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
774 | cxIteratorNext(iter); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
775 | EXPECT_EQ(4, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
776 | EXPECT_EQ(testdata.data[4], destr_last_value + off); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
777 | EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list)); |
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
|
778 | |
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
|
779 | cxListClear(list); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
780 | EXPECT_EQ(testdata_len, destr_test_ctr); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
781 | EXPECT_EQ(testdata.data[testdata_len - 1], destr_last_value + off); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
782 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
783 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
784 | void verifySimpleDestructor(CxList *list) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
785 | destr_test_ctr = 0; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
786 | list->simple_destructor = simple_destr_test_fun; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
787 | verifyAnyDestructor(list); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
788 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
789 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
790 | void verifyAdvancedDestructor(CxList *list) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
791 | destr_test_ctr = 0; |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
792 | list->advanced_destructor = advanced_destr_test_fun; |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
793 | verifyAnyDestructor(list); |
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
|
794 | } |
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
|
795 | |
647
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
796 | static void verifySwap(CxList *list) { |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
797 | ASSERT_EQ(cxListSize(list), 0); |
647
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
798 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
799 | 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
|
800 | 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
|
801 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
802 | // 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
|
803 | cx_for_n(i, 16) { |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
804 | cxListAdd(list, &original[i]); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
805 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
806 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
807 | int result; |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
808 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
809 | // 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
|
810 | result = cxListSwap(list, 1, 4); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
811 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
812 | result = cxListSwap(list, 2, 14); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
813 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
814 | result = cxListSwap(list, 9, 6); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
815 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
816 | result = cxListSwap(list, 3, 3); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
817 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
818 | result = cxListSwap(list, 10, 11); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
819 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
820 | result = cxListSwap(list, 8, 0); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
821 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
822 | result = cxListSwap(list, 7, 12); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
823 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
824 | result = cxListSwap(list, 13, 15); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
825 | EXPECT_EQ(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
826 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
827 | result = cxListSwap(list, 5, 16); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
828 | EXPECT_NE(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
829 | result = cxListSwap(list, 16, 6); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
830 | EXPECT_NE(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
831 | result = cxListSwap(list, 16, 17); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
832 | EXPECT_NE(0, result); |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
833 | |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
834 | auto iter = cxListIterator(list); |
647
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
835 | cx_foreach(int*, e, iter) { |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
836 | 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
|
837 | } |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
838 | iter = cxListBackwardsIterator(list); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
839 | cx_foreach(int*, e, iter) { |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
840 | 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
|
841 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
842 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
843 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
844 | void verifyAt(CxList *list) const { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
845 | auto len = testdata_len; |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
846 | EXPECT_EQ(cxListSize(list), len); |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
847 | cx_for_n (i, len) { |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
848 | EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
849 | } |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
850 | EXPECT_EQ(cxListAt(list, cxListSize(list)), nullptr); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
851 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
852 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
853 | void verifyFind(CxList *list) const { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
854 | cx_for_n (attempt, 25) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
855 | 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
|
856 | int val = testdata.data[exp]; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
857 | // 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
|
858 | cx_for_n (i, exp) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
859 | if (testdata.data[i] == val) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
860 | exp = i; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
861 | break; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
862 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
863 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
864 | EXPECT_EQ(cxListFind(list, &val), exp); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
865 | } |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
866 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
867 | int notinlist = -1; |
699
35b2b99ee523
make list find return a negative value when elem not found
Mike Becker <universe@uap-core.de>
parents:
680
diff
changeset
|
868 | EXPECT_LT(cxListFind(list, ¬inlist), 0); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
869 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
870 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
871 | void verifySort(CxList *list) const { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
872 | std::array<int, testdata_len> expected{}; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
873 | 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
|
874 | cxListSort(list); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
875 | 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
|
876 | } |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
877 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
878 | void verifyIterator(CxList *list) const { |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
879 | auto iter = cxListIterator(list); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
880 | size_t i = 0; |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
881 | cx_foreach(int*, x, iter) { |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
882 | ASSERT_EQ(i, iter.index); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
883 | EXPECT_EQ(*x, testdata.data[iter.index]); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
884 | i++; |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
885 | } |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
886 | ASSERT_EQ(i, cxListSize(list)); |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
887 | iter = cxListBackwardsIterator(list); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
888 | cx_foreach(int*, x, iter) { |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
889 | ASSERT_EQ(i - 1, iter.index); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
890 | EXPECT_EQ(*x, testdata.data[iter.index]); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
891 | i--; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
892 | } |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
893 | ASSERT_EQ(i, 0); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
894 | auto len = testdata_len; |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
895 | i = len / 2; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
896 | auto mut_iter = cxListMutIteratorAt(list, i); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
897 | size_t j = 0; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
898 | cx_foreach(int*, x, mut_iter) { |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
899 | 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
|
900 | ASSERT_EQ(*x, testdata.data[i]); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
901 | if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
902 | i++; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
903 | j++; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
904 | } |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
905 | ASSERT_EQ(i, len); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
906 | i = len / 2; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
907 | j = 0; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
908 | mut_iter = cxListMutBackwardsIteratorAt(list, i - 1); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
909 | cx_foreach(int*, x, mut_iter) { |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
910 | 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
|
911 | ASSERT_EQ(*x, testdata.data[i - 1]); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
912 | if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter); |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
913 | i--; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
914 | j++; |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
915 | } |
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
916 | ASSERT_EQ(i, 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
917 | ASSERT_EQ(cxListSize(list), len / 2); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
918 | 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
|
919 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
920 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
921 | static void verifyInsertViaIterator(CxList *list) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
922 | int newdata[] = {10, 20, 30, 40, 50}; |
498
435c9965b2dd
reorder the list test functions
Mike Becker <universe@uap-core.de>
parents:
497
diff
changeset
|
923 | |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
924 | auto iter = cxListMutIteratorAt(list, 2); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
925 | EXPECT_TRUE(cxIteratorValid(iter)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
926 | EXPECT_EQ(iter.index, 2); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
927 | EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
928 | cxListInsertAfter(&iter, &newdata[0]); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
929 | EXPECT_TRUE(cxIteratorValid(iter)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
930 | EXPECT_EQ(iter.index, 2); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
931 | EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
932 | cxListInsertBefore(&iter, &newdata[1]); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
933 | EXPECT_TRUE(cxIteratorValid(iter)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
934 | EXPECT_EQ(iter.index, 3); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
935 | EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
936 | |
655
7340c4255f1f
implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents:
654
diff
changeset
|
937 | iter = cxListMutIterator(list); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
938 | cxListInsertBefore(&iter, &newdata[2]); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
939 | EXPECT_TRUE(cxIteratorValid(iter)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
940 | EXPECT_EQ(iter.index, 1); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
941 | EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
942 | iter = cxListMutIteratorAt(list, cxListSize(list)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
943 | cxListInsertBefore(&iter, &newdata[3]); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
944 | EXPECT_FALSE(cxIteratorValid(iter)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
945 | EXPECT_EQ(iter.index, 9); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
946 | iter = cxListMutIteratorAt(list, cxListSize(list)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
947 | cxListInsertAfter(&iter, &newdata[4]); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
948 | EXPECT_FALSE(cxIteratorValid(iter)); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
949 | EXPECT_EQ(iter.index, 10); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
950 | |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
951 | 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
|
952 | 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
|
953 | } |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
954 | |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
955 | void verifyReverse(CxList *list) const { |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
956 | cxListReverse(list); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
957 | cx_for_n(i, testdata_len) { |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
958 | 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
|
959 | } |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
960 | } |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
961 | |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
962 | static void verifyCompare( |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
963 | CxList *left, |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
964 | CxList *right |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
521
diff
changeset
|
965 | ) { |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
966 | EXPECT_EQ(cxListCompare(left, right), 0); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
967 | int x = 42; |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
968 | cxListAdd(left, &x); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
969 | ASSERT_GT(cxListSize(left), cxListSize(right)); |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
970 | EXPECT_GT(cxListCompare(left, right), 0); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
971 | EXPECT_LT(cxListCompare(right, left), 0); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
972 | cxListAdd(right, &x); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
973 | ASSERT_EQ(cxListSize(left), cxListSize(right)); |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
974 | EXPECT_EQ(cxListCompare(left, right), 0); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
975 | int a = 5, b = 10; |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
976 | cxListInsert(left, 15, &a); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
977 | cxListInsert(right, 15, &b); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
978 | ASSERT_EQ(cxListSize(left), cxListSize(right)); |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
979 | EXPECT_LT(cxListCompare(left, right), 0); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
980 | 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
|
981 | *(int *) cxListAt(left, 15) = 10; |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
982 | EXPECT_EQ(cxListCompare(left, right), 0); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
983 | } |
509
0d3c6075f82c
#129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents:
507
diff
changeset
|
984 | }; |
498
435c9965b2dd
reorder the list test functions
Mike Becker <universe@uap-core.de>
parents:
497
diff
changeset
|
985 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
986 | unsigned HighLevelTest::destr_test_ctr = 0; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
987 | int HighLevelTest::destr_last_value = 0; |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
988 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
989 | class LinkedList : public HighLevelTest { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
990 | }; |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
991 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
992 | class PointerLinkedList : public HighLevelTest { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
993 | }; |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
994 | |
606 | 995 | class ArrayList : public HighLevelTest { |
996 | }; | |
997 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
998 | class PointerArrayList : public HighLevelTest { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
999 | }; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1000 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1001 | TEST_F(PointerLinkedList, cxListStorePointers) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1002 | 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
|
1003 | EXPECT_FALSE(cxListIsStoringPointers(list)); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1004 | cxListStorePointers(list); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1005 | EXPECT_EQ(list->item_size, sizeof(void *)); |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1006 | EXPECT_NE(list->cl, nullptr); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1007 | EXPECT_NE(list->climpl, nullptr); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1008 | EXPECT_TRUE(cxListIsStoringPointers(list)); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1009 | cxListStoreObjects(list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1010 | EXPECT_NE(list->cl, nullptr); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1011 | EXPECT_EQ(list->climpl, nullptr); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1012 | EXPECT_FALSE(cxListIsStoringPointers(list)); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1013 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1014 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1015 | TEST_F(LinkedList, cxLinkedListCreate) { |
602
3b071ea0e9cf
use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents:
552
diff
changeset
|
1016 | CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); |
606 | 1017 | ASSERT_NE(list, nullptr); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1018 | EXPECT_EQ(list->item_size, sizeof(int)); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1019 | EXPECT_EQ(list->simple_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1020 | EXPECT_EQ(list->advanced_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1021 | EXPECT_EQ(list->destructor_data, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1022 | EXPECT_EQ(cxListSize(list), 0); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1023 | EXPECT_EQ(list->allocator, &testingAllocator); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1024 | EXPECT_EQ(list->cmpfunc, cx_cmp_int); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1025 | EXPECT_FALSE(cxListIsStoringPointers(list)); |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
492
diff
changeset
|
1026 | } |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
492
diff
changeset
|
1027 | |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1028 | TEST_F(LinkedList, cxLinkedListCreateSimple) { |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1029 | CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int))); |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1030 | ASSERT_NE(list, nullptr); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1031 | EXPECT_EQ(list->item_size, sizeof(int)); |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1032 | EXPECT_EQ(list->cmpfunc, nullptr); |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1033 | EXPECT_EQ(list->allocator, cxDefaultAllocator); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1034 | EXPECT_EQ(list->simple_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1035 | EXPECT_EQ(list->advanced_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1036 | EXPECT_EQ(list->destructor_data, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1037 | EXPECT_EQ(cxListSize(list), 0); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1038 | EXPECT_FALSE(cxListIsStoringPointers(list)); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1039 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1040 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1041 | TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) { |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1042 | CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS)); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1043 | ASSERT_NE(list, nullptr); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1044 | EXPECT_EQ(list->item_size, sizeof(void *)); |
763
741a2040fa33
make cx_cmp_ptr default comparator for pointer lists - relates to #340
Mike Becker <universe@uap-core.de>
parents:
704
diff
changeset
|
1045 | EXPECT_EQ(list->cmpfunc, cx_cmp_ptr); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1046 | EXPECT_EQ(list->allocator, cxDefaultAllocator); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1047 | EXPECT_EQ(list->simple_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1048 | EXPECT_EQ(list->advanced_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1049 | EXPECT_EQ(list->destructor_data, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1050 | EXPECT_EQ(cxListSize(list), 0); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1051 | EXPECT_TRUE(cxListIsStoringPointers(list)); |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1052 | } |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1053 | |
606 | 1054 | TEST_F(ArrayList, cxArrayListCreate) { |
1055 | CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); | |
1056 | ASSERT_NE(list, nullptr); | |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1057 | EXPECT_EQ(list->item_size, sizeof(int)); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1058 | EXPECT_EQ(list->simple_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1059 | EXPECT_EQ(list->advanced_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1060 | EXPECT_EQ(list->destructor_data, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1061 | EXPECT_EQ(cxListSize(list), 0); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1062 | EXPECT_EQ(list->allocator, &testingAllocator); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1063 | EXPECT_EQ(list->cmpfunc, cx_cmp_int); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1064 | EXPECT_FALSE(cxListIsStoringPointers(list)); |
606 | 1065 | } |
1066 | ||
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1067 | TEST_F(ArrayList, cxArrayListCreateSimple) { |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1068 | CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8)); |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1069 | ASSERT_NE(list, nullptr); |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1070 | EXPECT_EQ(list->cmpfunc, nullptr); |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1071 | EXPECT_EQ(list->allocator, cxDefaultAllocator); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1072 | EXPECT_EQ(list->item_size, sizeof(int)); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1073 | EXPECT_EQ(list->simple_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1074 | EXPECT_EQ(list->advanced_destructor, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1075 | EXPECT_EQ(list->destructor_data, nullptr); |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1076 | EXPECT_EQ(cxListSize(list), 0); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1077 | EXPECT_FALSE(cxListIsStoringPointers(list)); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1078 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1079 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1080 | TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) { |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1081 | CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8)); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1082 | ASSERT_NE(list, nullptr); |
763
741a2040fa33
make cx_cmp_ptr default comparator for pointer lists - relates to #340
Mike Becker <universe@uap-core.de>
parents:
704
diff
changeset
|
1083 | EXPECT_EQ(list->cmpfunc, cx_cmp_ptr); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1084 | EXPECT_EQ(list->allocator, cxDefaultAllocator); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1085 | EXPECT_EQ(list->item_size, sizeof(void *)); |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1086 | EXPECT_TRUE(cxListIsStoringPointers(list)); |
662
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1087 | } |
d0d95740071b
add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
1088 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1089 | TEST_F(LinkedList, cxListAdd) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1090 | 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
|
1091 | verifyAdd(list, false); |
509
0d3c6075f82c
#129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents:
507
diff
changeset
|
1092 | } |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
498
diff
changeset
|
1093 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1094 | 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
|
1095 | 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
|
1096 | verifyAdd(list, true); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1097 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1098 | |
606 | 1099 | TEST_F(ArrayList, cxListAdd) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1100 | auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); |
606 | 1101 | verifyAdd(list, false); |
1102 | } | |
1103 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1104 | TEST_F(PointerArrayList, cxListAdd) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1105 | auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 8)); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1106 | verifyAdd(list, true); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1107 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1108 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1109 | TEST_F(LinkedList, cxListInsert) { |
602
3b071ea0e9cf
use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents:
552
diff
changeset
|
1110 | 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
|
1111 | } |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
498
diff
changeset
|
1112 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1113 | 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
|
1114 | 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
|
1115 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1116 | |
606 | 1117 | TEST_F(ArrayList, cxListInsert) { |
1118 | verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2))); | |
1119 | } | |
1120 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1121 | TEST_F(PointerArrayList, cxListInsert) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1122 | verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 2))); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1123 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1124 | |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1125 | TEST_F(LinkedList, cxListInsertArray) { |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1126 | verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1127 | } |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1128 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1129 | 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
|
1130 | 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
|
1131 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1132 | |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1133 | TEST_F(ArrayList, cxListInsertArray) { |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1134 | 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
|
1135 | } |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
1136 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1137 | TEST_F(PointerArrayList, cxListInsertArray) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1138 | verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 4)), true); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1139 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1140 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1141 | TEST_F(LinkedList, cxListRemove) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1142 | verifyRemove(linkedListFromTestData()); |
506
18782bbe3607
add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
1143 | } |
18782bbe3607
add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
1144 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1145 | TEST_F(PointerLinkedList, cxListRemove) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1146 | verifyRemove(pointerLinkedListFromTestData()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1147 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1148 | |
606 | 1149 | TEST_F(ArrayList, cxListRemove) { |
1150 | verifyRemove(arrayListFromTestData()); | |
1151 | } | |
1152 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1153 | TEST_F(PointerArrayList, cxListRemove) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1154 | verifyRemove(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1155 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1156 | |
764
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1157 | TEST_F(LinkedList, cxListFindRemove) { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1158 | verifyFindRemove(linkedListFromTestData()); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1159 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1160 | |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1161 | TEST_F(PointerLinkedList, cxListFindRemove) { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1162 | verifyFindRemove(pointerLinkedListFromTestData()); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1163 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1164 | |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1165 | TEST_F(ArrayList, cxListFindRemove) { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1166 | verifyFindRemove(arrayListFromTestData()); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1167 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1168 | |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1169 | TEST_F(PointerArrayList, cxListFindRemove) { |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1170 | verifyFindRemove(pointerArrayListFromTestData()); |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1171 | } |
ccbdbd088455
add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents:
763
diff
changeset
|
1172 | |
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
|
1173 | TEST_F(LinkedList, cxListClear) { |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1174 | verifyClear(linkedListFromTestData()); |
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
|
1175 | } |
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
|
1176 | |
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
|
1177 | TEST_F(PointerLinkedList, cxListClear) { |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1178 | verifyClear(pointerLinkedListFromTestData()); |
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
|
1179 | } |
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
|
1180 | |
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
|
1181 | TEST_F(ArrayList, cxListClear) { |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1182 | verifyClear(arrayListFromTestData()); |
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
|
1183 | } |
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
|
1184 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1185 | TEST_F(PointerArrayList, cxListClear) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1186 | verifyClear(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1187 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1188 | |
647
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1189 | TEST_F(LinkedList, cxListSwap) { |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1190 | 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
|
1191 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1192 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1193 | 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
|
1194 | 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
|
1195 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1196 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1197 | TEST_F(ArrayList, cxListSwap) { |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1198 | 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
|
1199 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1200 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1201 | TEST_F(PointerArrayList, cxListSwap) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1202 | verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 16))); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1203 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1204 | |
647
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1205 | TEST_F(LinkedList, cxListSwapNoSBO) { |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1206 | 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
|
1207 | 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
|
1208 | 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
|
1209 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1210 | |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1211 | TEST_F(PointerLinkedList, cxListSwapNoSBO) { |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1212 | 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
|
1213 | 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
|
1214 | 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
|
1215 | } |
2e6e9d9f2159
implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents:
641
diff
changeset
|
1216 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1217 | TEST_F(LinkedList, cxListAt) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1218 | verifyAt(linkedListFromTestData()); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1219 | } |
449 | 1220 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1221 | TEST_F(PointerLinkedList, cxListAt) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1222 | verifyAt(pointerLinkedListFromTestData()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1223 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1224 | |
606 | 1225 | TEST_F(ArrayList, cxListAt) { |
1226 | verifyAt(arrayListFromTestData()); | |
1227 | } | |
1228 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1229 | TEST_F(PointerArrayList, cxListAt) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1230 | verifyAt(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1231 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1232 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1233 | TEST_F(LinkedList, cxListFind) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1234 | verifyFind(linkedListFromTestData()); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1235 | } |
455 | 1236 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1237 | TEST_F(PointerLinkedList, cxListFind) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1238 | verifyFind(pointerLinkedListFromTestData()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1239 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1240 | |
606 | 1241 | TEST_F(ArrayList, cxListFind) { |
1242 | verifyFind(arrayListFromTestData()); | |
1243 | } | |
1244 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1245 | TEST_F(PointerArrayList, cxListFind) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1246 | verifyFind(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1247 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1248 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1249 | TEST_F(LinkedList, cxListSort) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1250 | verifySort(linkedListFromTestData()); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1251 | } |
455 | 1252 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1253 | TEST_F(PointerLinkedList, cxListSort) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1254 | verifySort(pointerLinkedListFromTestData()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1255 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1256 | |
606 | 1257 | TEST_F(ArrayList, cxListSort) { |
1258 | verifySort(arrayListFromTestData()); | |
1259 | } | |
1260 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1261 | TEST_F(PointerArrayList, cxListSort) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1262 | verifySort(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1263 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1264 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1265 | TEST_F(LinkedList, Iterator) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1266 | verifyIterator(linkedListFromTestData()); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1267 | } |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1268 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1269 | TEST_F(PointerLinkedList, Iterator) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1270 | verifyIterator(pointerLinkedListFromTestData()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1271 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1272 | |
606 | 1273 | TEST_F(ArrayList, Iterator) { |
1274 | verifyIterator(arrayListFromTestData()); | |
1275 | } | |
1276 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1277 | TEST_F(PointerArrayList, Iterator) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1278 | verifyIterator(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1279 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1280 | |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1281 | TEST_F(LinkedList, InsertViaIterator) { |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1282 | int fivenums[] = {0, 1, 2, 3, 4, 5}; |
629
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
623
diff
changeset
|
1283 | CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
623
diff
changeset
|
1284 | cxListAddArray(list, fivenums, 5); |
517
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1285 | verifyInsertViaIterator(list); |
b3baaf9b7e3c
migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents:
509
diff
changeset
|
1286 | } |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1287 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1288 | TEST_F(PointerLinkedList, InsertViaIterator) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1289 | 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
|
1290 | 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
|
1291 | // 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
|
1292 | 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
|
1293 | verifyInsertViaIterator(list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1294 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1295 | |
606 | 1296 | TEST_F(ArrayList, InsertViaIterator) { |
1297 | 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
|
1298 | 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
|
1299 | cxListAddArray(list, fivenums, 5); |
606 | 1300 | verifyInsertViaIterator(list); |
1301 | } | |
1302 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1303 | TEST_F(PointerArrayList, InsertViaIterator) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1304 | int fivenums[] = {0, 1, 2, 3, 4, 5}; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1305 | auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 4)); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1306 | // note: cannot use cxListAddArray() because we don't have a list of pointers |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1307 | cx_for_n(i, 5) cxListAdd(list, &fivenums[i]); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1308 | verifyInsertViaIterator(list); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1309 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1310 | |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1311 | TEST_F(LinkedList, cxListReverse) { |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1312 | verifyReverse(linkedListFromTestData()); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1313 | } |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1314 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1315 | TEST_F(PointerLinkedList, cxListReverse) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1316 | verifyReverse(pointerLinkedListFromTestData()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1317 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1318 | |
606 | 1319 | TEST_F(ArrayList, cxListReverse) { |
1320 | verifyReverse(arrayListFromTestData()); | |
1321 | } | |
1322 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1323 | TEST_F(PointerArrayList, cxListReverse) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1324 | verifyReverse(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1325 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1326 | |
521
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1327 | TEST_F(LinkedList, cxListCompare) { |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1328 | auto left = linkedListFromTestData(); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1329 | auto right = linkedListFromTestData(); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1330 | verifyCompare(left, right); |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1331 | } |
e5dc54131d55
add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents:
520
diff
changeset
|
1332 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1333 | TEST_F(LinkedList, cxListCompareWithPtrList) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1334 | auto left = linkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1335 | auto right = pointerLinkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1336 | verifyCompare(left, right); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1337 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1338 | |
606 | 1339 | TEST_F(LinkedList, cxListCompareWithArrayList) { |
1340 | auto left = linkedListFromTestData(); | |
1341 | auto right = arrayListFromTestData(); | |
1342 | verifyCompare(left, right); | |
1343 | } | |
1344 | ||
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1345 | TEST_F(LinkedList, cxListCompareWithPtrArrayList) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1346 | auto left = linkedListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1347 | auto right = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1348 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1349 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1350 | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1351 | TEST_F(PointerLinkedList, cxListCompare) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1352 | auto left = pointerLinkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1353 | auto right = pointerLinkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1354 | verifyCompare(left, right); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1355 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1356 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1357 | TEST_F(PointerLinkedList, cxListCompareWithNormalList) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1358 | auto left = pointerLinkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1359 | auto right = linkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1360 | verifyCompare(left, right); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1361 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1362 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1363 | TEST_F(PointerLinkedList, cxListCompareWithArrayList) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1364 | auto left = pointerLinkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1365 | auto right = arrayListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1366 | verifyCompare(left, right); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1367 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1368 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1369 | TEST_F(PointerLinkedList, cxListCompareWithPtrArrayList) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1370 | auto left = pointerLinkedListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1371 | auto right = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1372 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1373 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1374 | |
606 | 1375 | TEST_F(ArrayList, cxListCompare) { |
1376 | auto left = arrayListFromTestData(); | |
1377 | auto right = arrayListFromTestData(); | |
1378 | verifyCompare(left, right); | |
1379 | } | |
1380 | ||
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1381 | TEST_F(ArrayList, cxListCompareWithPtrList) { |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1382 | auto left = arrayListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1383 | auto right = pointerLinkedListFromTestData(); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1384 | verifyCompare(left, right); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1385 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1386 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1387 | TEST_F(ArrayList, cxListCompareWithNormalList) { |
606 | 1388 | auto left = arrayListFromTestData(); |
1389 | auto right = linkedListFromTestData(); | |
1390 | verifyCompare(left, right); | |
1391 | } | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1392 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1393 | TEST_F(ArrayList, cxListCompareWithPtrArrayList) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1394 | auto left = arrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1395 | auto right = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1396 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1397 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1398 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1399 | TEST_F(PointerArrayList, cxListCompare) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1400 | auto left = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1401 | auto right = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1402 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1403 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1404 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1405 | TEST_F(PointerArrayList, cxListCompareWithPtrList) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1406 | auto left = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1407 | auto right = pointerLinkedListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1408 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1409 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1410 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1411 | TEST_F(PointerArrayList, cxListCompareWithNormalList) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1412 | auto left = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1413 | auto right = linkedListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1414 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1415 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1416 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1417 | TEST_F(PointerArrayList, cxListCompareWithNormalArrayList) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1418 | auto left = pointerArrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1419 | auto right = arrayListFromTestData(); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1420 | verifyCompare(left, right); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1421 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1422 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1423 | TEST_F(LinkedList, SimpleDestructor) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1424 | verifySimpleDestructor(linkedListFromTestData()); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1425 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1426 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1427 | TEST_F(PointerLinkedList, SimpleDestructor) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1428 | verifySimpleDestructor(pointerLinkedListFromTestData()); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1429 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1430 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1431 | TEST_F(ArrayList, SimpleDestructor) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1432 | verifySimpleDestructor(arrayListFromTestData()); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1433 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1434 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1435 | TEST_F(PointerArrayList, SimpleDestructor) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1436 | verifySimpleDestructor(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1437 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1438 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1439 | TEST_F(LinkedList, AdvancedDestructor) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1440 | verifyAdvancedDestructor(linkedListFromTestData()); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1441 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1442 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1443 | TEST_F(PointerLinkedList, AdvancedDestructor) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1444 | verifyAdvancedDestructor(pointerLinkedListFromTestData()); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1445 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1446 | |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1447 | TEST_F(ArrayList, AdvancedDestructor) { |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1448 | verifyAdvancedDestructor(arrayListFromTestData()); |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1449 | } |
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1450 | |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1451 | TEST_F(PointerArrayList, AdvancedDestructor) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1452 | verifyAdvancedDestructor(pointerArrayListFromTestData()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1453 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1454 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1455 | TEST_F(PointerLinkedList, DestroyNoDestructor) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1456 | 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
|
1457 | 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
|
1458 | cxListAdd(list, item); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1459 | ASSERT_FALSE(testingAllocator.verify()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1460 | cxListDestroy(list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1461 | EXPECT_FALSE(testingAllocator.verify()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1462 | cxFree(&testingAllocator, item); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1463 | EXPECT_TRUE(testingAllocator.verify()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1464 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1465 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1466 | TEST_F(PointerLinkedList, DestroySimpleDestructor) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1467 | int item = 0; |
667
2f88a7c13a28
add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents:
666
diff
changeset
|
1468 | 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
|
1469 | 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
|
1470 | cxListAdd(list, &item); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1471 | cxListDestroy(list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1472 | EXPECT_EQ(item, 42); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1473 | } |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1474 | |
672
55d8fdd38ca4
increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents:
667
diff
changeset
|
1475 | TEST_F(PointerLinkedList, DestroyAdvancedDestructor) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1476 | 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
|
1477 | auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1478 | list->destructor_data = &testingAllocator; |
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
672
diff
changeset
|
1479 | list->advanced_destructor = (cx_destructor_func2) cxFree; |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1480 | cxListAdd(list, item); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1481 | ASSERT_FALSE(testingAllocator.verify()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1482 | cxListDestroy(list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1483 | EXPECT_TRUE(testingAllocator.verify()); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
639
diff
changeset
|
1484 | } |
679
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1485 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1486 | TEST_F(PointerArrayList, DestroyNoDestructor) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1487 | void *item = cxMalloc(&testingAllocator, sizeof(int)); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1488 | auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1489 | cxListAdd(list, item); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1490 | ASSERT_FALSE(testingAllocator.verify()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1491 | cxListDestroy(list); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1492 | EXPECT_FALSE(testingAllocator.verify()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1493 | cxFree(&testingAllocator, item); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1494 | EXPECT_TRUE(testingAllocator.verify()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1495 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1496 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1497 | TEST_F(PointerArrayList, DestroySimpleDestructor) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1498 | int item = 0; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1499 | auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1500 | list->simple_destructor = [](void *elem) { *(int *) elem = 42; }; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1501 | cxListAdd(list, &item); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1502 | cxListDestroy(list); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1503 | EXPECT_EQ(item, 42); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1504 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1505 | |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1506 | TEST_F(PointerArrayList, DestroyAdvancedDestructor) { |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1507 | void *item = cxMalloc(&testingAllocator, sizeof(int)); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1508 | auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1509 | list->destructor_data = &testingAllocator; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1510 | list->advanced_destructor = (cx_destructor_func2) cxFree; |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1511 | cxListAdd(list, item); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1512 | ASSERT_FALSE(testingAllocator.verify()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1513 | cxListDestroy(list); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1514 | EXPECT_TRUE(testingAllocator.verify()); |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1515 | } |
022fbd4bc057
add pointer array list tests
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
1516 | |
704
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1517 | TEST(EmptyList, Size) { |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1518 | auto list = cxEmptyList; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1519 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1520 | EXPECT_EQ(list->size, 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1521 | EXPECT_EQ(cxListSize(list), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1522 | } |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1523 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1524 | TEST(EmptyList, Iterator) { |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1525 | auto list = cxEmptyList; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1526 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1527 | auto it1 = cxListIterator(list); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1528 | auto it2 = cxListBackwardsIterator(list); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1529 | auto it3 = cxListMutIterator(list); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1530 | auto it4 = cxListMutBackwardsIterator(list); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1531 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1532 | EXPECT_FALSE(cxIteratorValid(it1)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1533 | EXPECT_FALSE(cxIteratorValid(it2)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1534 | EXPECT_FALSE(cxIteratorValid(it3)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1535 | EXPECT_FALSE(cxIteratorValid(it4)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1536 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1537 | int c = 0; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1538 | cx_foreach(void*, data, it1) c++; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1539 | cx_foreach(void*, data, it2) c++; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1540 | cx_foreach(void*, data, it3) c++; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1541 | cx_foreach(void*, data, it4) c++; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1542 | EXPECT_EQ(c, 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1543 | } |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1544 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1545 | TEST(EmptyList, NoOps) { |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1546 | auto list = cxEmptyList; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1547 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1548 | ASSERT_NO_FATAL_FAILURE(cxListSort(list)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1549 | ASSERT_NO_FATAL_FAILURE(cxListClear(list)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1550 | ASSERT_NO_FATAL_FAILURE(cxListDestroy(list)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1551 | } |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1552 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1553 | TEST(EmptyList, At) { |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1554 | auto list = cxEmptyList; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1555 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1556 | EXPECT_EQ(cxListAt(list, 0), nullptr); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1557 | EXPECT_EQ(cxListAt(list, 1), nullptr); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1558 | } |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1559 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1560 | TEST(EmptyList, Find) { |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1561 | auto list = cxEmptyList; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1562 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1563 | int x = 42, y = 1337; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1564 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1565 | EXPECT_LT(cxListFind(list, &x), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1566 | EXPECT_LT(cxListFind(list, &y), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1567 | } |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1568 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1569 | TEST(EmptyList, Compare) { |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1570 | auto empty = cxEmptyList; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1571 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1572 | auto ll = cxLinkedListCreateSimple(sizeof(int)); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1573 | auto al = cxArrayListCreateSimple(sizeof(int), 8); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1574 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1575 | int x = 5; |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1576 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1577 | EXPECT_EQ(cxListCompare(empty, cxEmptyList), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1578 | EXPECT_EQ(cxListCompare(ll, cxEmptyList), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1579 | EXPECT_EQ(cxListCompare(al, cxEmptyList), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1580 | EXPECT_EQ(cxListCompare(cxEmptyList, ll), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1581 | EXPECT_EQ(cxListCompare(cxEmptyList, al), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1582 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1583 | cxListAdd(ll, &x); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1584 | cxListAdd(al, &x); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1585 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1586 | EXPECT_GT(cxListCompare(ll, cxEmptyList), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1587 | EXPECT_GT(cxListCompare(al, cxEmptyList), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1588 | EXPECT_LT(cxListCompare(cxEmptyList, ll), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1589 | EXPECT_LT(cxListCompare(cxEmptyList, al), 0); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1590 | |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1591 | cxListDestroy(ll); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1592 | cxListDestroy(al); |
35f06c5eeb0e
add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents:
702
diff
changeset
|
1593 | } |