tests/test_list.cpp

Tue, 09 Jan 2024 00:01:03 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 09 Jan 2024 00:01:03 +0100
changeset 798
7644da6e2d35
parent 790
42877968260c
child 800
1274e46b3013
permissions
-rw-r--r--

migrate low level linked list tests - relates to #342

390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
29 #include "cx/linked_list.h"
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
30 #include "cx/array_list.h"
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
31 #include "cx/utils.h"
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
32 #include "cx/compare.h"
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents: 413
diff changeset
33 #include "util_allocator.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
34
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
35 #include <gtest/gtest.h>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
36 #include <array>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
37 #include <vector>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
38 #include <unordered_set>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
39 #include <algorithm>
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
40
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
41
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
42 class HighLevelTest : public ::testing::Test {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
43 mutable std::unordered_set<CxList *> lists;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
44 protected:
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 517
diff changeset
45 CxTestingAllocator testingAllocator;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
46
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
47 void TearDown() override {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
48 for (auto &&l: lists) cxListDestroy(l);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
49 CX_TEST_ASSERT(testingAllocator.verify());
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
50 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
51
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
52 static constexpr size_t testdata_len = 250;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
53 int_test_data<testdata_len> testdata;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
54
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
55 auto autofree(CxList *list) const -> CxList * {
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
56 if (list != NULL) lists.insert(list);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
57 return list;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
58 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
59
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
60 auto linkedListFromTestData() const -> CxList * {
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
61 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
62 cxListAddArray(list, testdata.data.data(), testdata_len);
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
63 return list;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
64 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
65
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
66 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
67 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
68 // 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
69 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
70 return list;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
71 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
72
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
73 auto arrayListFromTestData() const -> CxList * {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
74 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
75 cxListAddArray(list, testdata.data.data(), testdata_len);
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
76 return list;
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
77 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
78
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
79 auto pointerArrayListFromTestData() const -> CxList * {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
80 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
81 // 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
82 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
83 return list;
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
84 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
85
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
86 void verifyAdd(
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
87 CxList *list,
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
88 bool as_pointer
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
89 ) {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
90 auto len = testdata_len;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
91 cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
92 CX_TEST_ASSERT(cxListSize(list) == len);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
93 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
94 cx_for_n (i, len) ++testdata.data[i];
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
95 if (as_pointer) {
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
96 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
97 } else {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
98 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
99 }
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
100 }
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
101
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
102 static void verifyInsert(CxList *list) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
103 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
104
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
105 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
106 EXPECT_EQ(cxListSize(list), 0);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
107 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
108 EXPECT_EQ(cxListSize(list), 1);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
109 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
110 EXPECT_EQ(cxListSize(list), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
111 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
112 EXPECT_EQ(cxListSize(list), 3);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
113 EXPECT_EQ(cxListInsert(list, 3, &d), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
114
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
115 CX_TEST_ASSERT(cxListSize(list) == 4);
517
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 EXPECT_EQ(*(int *) cxListAt(list, 0), 47);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
118 EXPECT_EQ(*(int *) cxListAt(list, 1), 13);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
119 EXPECT_EQ(*(int *) cxListAt(list, 2), 5);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
120 EXPECT_EQ(*(int *) cxListAt(list, 3), 42);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
121 }
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
122
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
123 static void verifyInsertArray(
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
124 CxList *list,
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
125 bool pointers = false
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
126 ) {
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
127 int a[5] = {5, 47, 11, 13, 42};
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
128 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
129 int *aptr[5];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
130 int *bptr[5];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
131 cx_for_n(i, 5) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
132 aptr[i] = &a[i];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
133 bptr[i] = &b[i];
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
134 }
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
135
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
136 size_t inserted;
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
137
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
138 if (pointers) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
139 inserted = cxListInsertArray(list, 0, aptr, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
140 } else {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
141 inserted = cxListInsertArray(list, 0, a, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
142 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
143 CX_TEST_ASSERT(inserted == 5);
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
144 EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
145 EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
146 EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
147 EXPECT_EQ(*(int *) cxListAt(list, 3), 13);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
148 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
149 if (pointers) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
150 inserted = cxListInsertArray(list, 3, bptr, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
151 } else {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
152 inserted = cxListInsertArray(list, 3, b, 5);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
153 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
154 CX_TEST_ASSERT(inserted == 5);
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
155 EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
156 EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
157 EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
158 EXPECT_EQ(*(int *) cxListAt(list, 3), 9);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
159 EXPECT_EQ(*(int *) cxListAt(list, 4), 18);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
160 EXPECT_EQ(*(int *) cxListAt(list, 5), 72);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
161 EXPECT_EQ(*(int *) cxListAt(list, 6), 50);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
162 EXPECT_EQ(*(int *) cxListAt(list, 7), 7);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
163 EXPECT_EQ(*(int *) cxListAt(list, 8), 13);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
164 EXPECT_EQ(*(int *) cxListAt(list, 9), 42);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
165 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
166
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
167 void verifyRemove(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
168 EXPECT_EQ(cxListRemove(list, 2), 0);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
169 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
170 EXPECT_EQ(cxListSize(list), testdata_len - 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
171 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
172 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
173 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
174 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
175 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
176
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
177 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
178 EXPECT_EQ(cxListSize(list), testdata_len - 3);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
179 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
180 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
181
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
182 EXPECT_NE(cxListRemove(list, testdata_len), 0);
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
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
185 void verifyFindRemove(CxList *list) const {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
186 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
187 int val = testdata.data[exp];
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
188 // 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
189 cx_for_n (i, exp) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
190 if (testdata.data[i] == val) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
191 exp = i;
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
192 break;
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
193 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
194 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
195 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
196 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
197 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
198 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
199 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
200
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
201 int notinlist = -1;
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
202 EXPECT_LT(cxListFindRemove(list, &notinlist), 0);
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
203 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
204 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
205
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
206 static void verifyClear(CxList *list) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
207 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
208 EXPECT_EQ(0, cxListSize(list));
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
209 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
210
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
211 static unsigned destr_test_ctr;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
212 static int destr_last_value;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
213
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
214 static void simple_destr_test_fun(void *data) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
215 auto ptr = (int *) data;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
216 destr_last_value = *ptr;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
217 *ptr = destr_last_value + 1;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
218 destr_test_ctr++;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
219 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
220
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
221 static void advanced_destr_test_fun(
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
222 [[maybe_unused]] void *u,
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
223 void *data
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
224 ) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
225 simple_destr_test_fun(data);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
226 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
227
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
228 void verifyAnyDestructor(CxList *list) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
229 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
230
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
231 cxListRemove(list, 15);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
232 EXPECT_EQ(1, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
233 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
234 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
235 cxListRemove(list, 47);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
236 EXPECT_EQ(2, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
237 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
238 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
239
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
240 auto iter = cxListMutIteratorAt(list, 7);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
241 cxIteratorNext(iter);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
242 EXPECT_EQ(2, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
243 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
244 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
245 cxIteratorFlagRemoval(iter);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
246 cxIteratorNext(iter);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
247 EXPECT_EQ(3, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
248 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
249 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
250
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
251 iter = cxListMutBackwardsIteratorAt(list, 5);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
252 cxIteratorNext(iter);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
253 EXPECT_EQ(3, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
254 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
255 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
256 cxIteratorFlagRemoval(iter);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
257 cxIteratorNext(iter);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
258 EXPECT_EQ(4, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
259 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
260 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
261
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
262 cxListClear(list);
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
263 EXPECT_EQ(testdata_len, destr_test_ctr);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
264 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
265 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
266
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
267 void verifySimpleDestructor(CxList *list) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
268 destr_test_ctr = 0;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
269 list->simple_destructor = simple_destr_test_fun;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
270 verifyAnyDestructor(list);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
271 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
272
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
273 void verifyAdvancedDestructor(CxList *list) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
274 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
275 list->advanced_destructor = advanced_destr_test_fun;
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
276 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
277 }
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
278
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
279 static void verifySwap(CxList *list) {
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
280 CX_TEST_ASSERT(cxListSize(list) == 0);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
281
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
282 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
283 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
284
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
285 // 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
286 cx_for_n(i, 16) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
287 cxListAdd(list, &original[i]);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
288 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
289
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
290 int result;
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
291
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
292 // 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
293 result = cxListSwap(list, 1, 4);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
294 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
295 result = cxListSwap(list, 2, 14);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
296 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
297 result = cxListSwap(list, 9, 6);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
298 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
299 result = cxListSwap(list, 3, 3);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
300 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
301 result = cxListSwap(list, 10, 11);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
302 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
303 result = cxListSwap(list, 8, 0);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
304 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
305 result = cxListSwap(list, 7, 12);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
306 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
307 result = cxListSwap(list, 13, 15);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
308 EXPECT_EQ(0, result);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
309
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
310 result = cxListSwap(list, 5, 16);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
311 CX_TEST_ASSERT(0 != result);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
312 result = cxListSwap(list, 16, 6);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
313 CX_TEST_ASSERT(0 != result);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
314 result = cxListSwap(list, 16, 17);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
315 CX_TEST_ASSERT(0 != result);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
316
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
317 auto iter = cxListIterator(list);
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
318 cx_foreach(int*, e, iter) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
319 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
320 }
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
321 iter = cxListBackwardsIterator(list);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
322 cx_foreach(int*, e, iter) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
323 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
324 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
325 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
326
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
327 void verifyAt(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
328 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
329 EXPECT_EQ(cxListSize(list), len);
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
330 cx_for_n (i, len) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
331 EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
332 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
333 EXPECT_EQ(cxListAt(list, cxListSize(list)), NULL);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
334 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
335
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
336 void verifyFind(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
337 cx_for_n (attempt, 25) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
338 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
339 int val = testdata.data[exp];
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
340 // 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
341 cx_for_n (i, exp) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
342 if (testdata.data[i] == val) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
343 exp = i;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
344 break;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
345 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
346 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
347 EXPECT_EQ(cxListFind(list, &val), exp);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
348 }
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
349
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
350 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
351 EXPECT_LT(cxListFind(list, &notinlist), 0);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
352 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
353
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
354 void verifySort(CxList *list) const {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
355 std::array<int, testdata_len> expected{};
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
356 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
357 cxListSort(list);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
358 cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
359 }
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
360
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
361 void verifyIterator(CxList *list) const {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
362 auto iter = cxListIterator(list);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
363 size_t i = 0;
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
364 cx_foreach(int*, x, iter) {
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
365 CX_TEST_ASSERT(i == iter.index);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
366 EXPECT_EQ(*x, testdata.data[iter.index]);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
367 i++;
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
368 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
369 CX_TEST_ASSERT(i == cxListSize(list));
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
370 iter = cxListBackwardsIterator(list);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
371 cx_foreach(int*, x, iter) {
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
372 CX_TEST_ASSERT(i - 1 == iter.index);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
373 EXPECT_EQ(*x, testdata.data[iter.index]);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
374 i--;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
375 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
376 CX_TEST_ASSERT(i == 0);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
377 auto len = testdata_len;
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
378 i = len / 2;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
379 auto mut_iter = cxListMutIteratorAt(list, i);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
380 size_t j = 0;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
381 cx_foreach(int*, x, mut_iter) {
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
382 CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
383 CX_TEST_ASSERT(*x == testdata.data[i]);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
384 if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
385 i++;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
386 j++;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
387 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
388 CX_TEST_ASSERT(i == len);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
389 i = len / 2;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
390 j = 0;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
391 mut_iter = cxListMutBackwardsIteratorAt(list, i - 1);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
392 cx_foreach(int*, x, mut_iter) {
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
393 CX_TEST_ASSERT(mut_iter.index == len / 2 - 1 - j);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
394 CX_TEST_ASSERT(*x == testdata.data[i - 1]);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
395 if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
396 i--;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
397 j++;
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
398 }
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
399 CX_TEST_ASSERT(i == 0);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
400 CX_TEST_ASSERT(cxListSize(list) == len / 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
401 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
402 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
403
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
404 static void verifyInsertViaIterator(CxList *list) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
405 int newdata[] = {10, 20, 30, 40, 50};
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
406
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
407 auto iter = cxListMutIteratorAt(list, 2);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
408 CX_TEST_ASSERT(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
409 EXPECT_EQ(iter.index, 2);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
410 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
411 cxListInsertAfter(&iter, &newdata[0]);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
412 CX_TEST_ASSERT(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
413 EXPECT_EQ(iter.index, 2);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
414 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
415 cxListInsertBefore(&iter, &newdata[1]);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
416 CX_TEST_ASSERT(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
417 EXPECT_EQ(iter.index, 3);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
418 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
419
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
420 iter = cxListMutIterator(list);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
421 cxListInsertBefore(&iter, &newdata[2]);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
422 CX_TEST_ASSERT(cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
423 EXPECT_EQ(iter.index, 1);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
424 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
425 iter = cxListMutIteratorAt(list, cxListSize(list));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
426 cxListInsertBefore(&iter, &newdata[3]);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
427 CX_TEST_ASSERT(!cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
428 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
429 iter = cxListMutIteratorAt(list, cxListSize(list));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
430 cxListInsertAfter(&iter, &newdata[4]);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
431 CX_TEST_ASSERT(!cxIteratorValid(iter));
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
432 EXPECT_EQ(iter.index, 10);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
433
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
434 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
435 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
436 }
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
437
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
438 void verifyReverse(CxList *list) const {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
439 cxListReverse(list);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
440 cx_for_n(i, testdata_len) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
441 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
442 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
443 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
444
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
445 static void verifyCompare(
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
446 CxList *left,
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
447 CxList *right
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 521
diff changeset
448 ) {
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
449 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
450 int x = 42;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
451 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
452 ASSERT_GT(cxListSize(left), cxListSize(right));
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
453 EXPECT_GT(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
454 EXPECT_LT(cxListCompare(right, left), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
455 cxListAdd(right, &x);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
456 CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
457 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
458 int a = 5, b = 10;
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
459 cxListInsert(left, 15, &a);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
460 cxListInsert(right, 15, &b);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
461 CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
462 EXPECT_LT(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
463 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
464 *(int *) cxListAt(left, 15) = 10;
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
465 EXPECT_EQ(cxListCompare(left, right), 0);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
466 }
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
467 };
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
468
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
469 unsigned HighLevelTest::destr_test_ctr = 0;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
470 int HighLevelTest::destr_last_value = 0;
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
471
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
472 class LinkedList : public HighLevelTest {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
473 };
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
474
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
475 class PointerLinkedList : public HighLevelTest {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
476 };
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
477
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
478 class ArrayList : public HighLevelTest {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
479 };
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
480
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
481 class PointerArrayList : public HighLevelTest {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
482 };
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
483
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
484 TEST_F(PointerLinkedList, cxListStorePointers) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
485 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
486 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
487 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
488 EXPECT_EQ(list->item_size, sizeof(void *));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
489 CX_TEST_ASSERT(list->cl != NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
490 CX_TEST_ASSERT(list->climpl != NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
491 CX_TEST_ASSERT(cxListIsStoringPointers(list));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
492 cxListStoreObjects(list);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
493 CX_TEST_ASSERT(list->cl != NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
494 EXPECT_EQ(list->climpl, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
495 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
496 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
497
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
498 TEST_F(LinkedList, cxLinkedListCreate) {
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
499 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
500 ASSERT_NE(list, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
501 EXPECT_EQ(list->item_size, sizeof(int));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
502 EXPECT_EQ(list->simple_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
503 EXPECT_EQ(list->advanced_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
504 EXPECT_EQ(list->destructor_data, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
505 EXPECT_EQ(cxListSize(list), 0);
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
506 EXPECT_EQ(list->allocator, &testingAllocator);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
507 EXPECT_EQ(list->cmpfunc, cx_cmp_int);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
508 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
509 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
510
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
511 TEST_F(LinkedList, cxLinkedListCreateSimple) {
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
512 CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int)));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
513 ASSERT_NE(list, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
514 EXPECT_EQ(list->item_size, sizeof(int));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
515 EXPECT_EQ(list->cmpfunc, NULL);
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
516 EXPECT_EQ(list->allocator, cxDefaultAllocator);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
517 EXPECT_EQ(list->simple_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
518 EXPECT_EQ(list->advanced_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
519 EXPECT_EQ(list->destructor_data, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
520 EXPECT_EQ(cxListSize(list), 0);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
521 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
522 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
523
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
524 TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) {
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
525 CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
526 ASSERT_NE(list, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
527 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
528 EXPECT_EQ(list->cmpfunc, cx_cmp_ptr);
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
529 EXPECT_EQ(list->allocator, cxDefaultAllocator);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
530 EXPECT_EQ(list->simple_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
531 EXPECT_EQ(list->advanced_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
532 EXPECT_EQ(list->destructor_data, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
533 EXPECT_EQ(cxListSize(list), 0);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
534 CX_TEST_ASSERT(cxListIsStoringPointers(list));
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
535 }
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
536
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
537 TEST_F(ArrayList, cxArrayListCreate) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
538 CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
539 ASSERT_NE(list, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
540 EXPECT_EQ(list->item_size, sizeof(int));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
541 EXPECT_EQ(list->simple_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
542 EXPECT_EQ(list->advanced_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
543 EXPECT_EQ(list->destructor_data, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
544 EXPECT_EQ(cxListSize(list), 0);
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
545 EXPECT_EQ(list->allocator, &testingAllocator);
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
546 EXPECT_EQ(list->cmpfunc, cx_cmp_int);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
547 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
548 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
549
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
550 TEST_F(ArrayList, cxArrayListCreateSimple) {
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
551 CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
552 ASSERT_NE(list, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
553 EXPECT_EQ(list->cmpfunc, NULL);
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
554 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
555 EXPECT_EQ(list->item_size, sizeof(int));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
556 EXPECT_EQ(list->simple_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
557 EXPECT_EQ(list->advanced_destructor, NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
558 EXPECT_EQ(list->destructor_data, NULL);
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 672
diff changeset
559 EXPECT_EQ(cxListSize(list), 0);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
560 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
561 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
562
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
563 TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) {
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
564 CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
565 ASSERT_NE(list, NULL);
763
741a2040fa33 make cx_cmp_ptr default comparator for pointer lists - relates to #340
Mike Becker <universe@uap-core.de>
parents: 704
diff changeset
566 EXPECT_EQ(list->cmpfunc, cx_cmp_ptr);
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
567 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
568 EXPECT_EQ(list->item_size, sizeof(void *));
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
569 CX_TEST_ASSERT(cxListIsStoringPointers(list));
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
570 }
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
571
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
572 TEST_F(LinkedList, cxListAdd) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
573 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
574 verifyAdd(list, false);
509
0d3c6075f82c #129 - remove test code duplication
Mike Becker <universe@uap-core.de>
parents: 507
diff changeset
575 }
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
576
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
577 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
578 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
579 verifyAdd(list, true);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
580 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
581
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
582 TEST_F(ArrayList, cxListAdd) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
583 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
584 verifyAdd(list, false);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
585 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
586
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
587 TEST_F(PointerArrayList, cxListAdd) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
588 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
589 verifyAdd(list, true);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
590 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
591
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
592 TEST_F(LinkedList, cxListInsert) {
602
3b071ea0e9cf use ucx compare function in list tests
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
593 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
594 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
595
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
596 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
597 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
598 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
599
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
600 TEST_F(ArrayList, cxListInsert) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
601 verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2)));
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
602 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
603
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
604 TEST_F(PointerArrayList, cxListInsert) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
605 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
606 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
607
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
608 TEST_F(LinkedList, cxListInsertArray) {
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
609 verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
610 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
611
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
612 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
613 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
614 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
615
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
616 TEST_F(ArrayList, cxListInsertArray) {
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
617 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
618 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
619
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
620 TEST_F(PointerArrayList, cxListInsertArray) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
621 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
622 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
623
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
624 TEST_F(LinkedList, cxListRemove) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
625 verifyRemove(linkedListFromTestData());
506
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
626 }
18782bbe3607 add setup and teardown functions to test_list.c
Mike Becker <universe@uap-core.de>
parents: 503
diff changeset
627
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
628 TEST_F(PointerLinkedList, cxListRemove) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
629 verifyRemove(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
630 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
631
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
632 TEST_F(ArrayList, cxListRemove) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
633 verifyRemove(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
634 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
635
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
636 TEST_F(PointerArrayList, cxListRemove) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
637 verifyRemove(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
638 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
639
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
640 TEST_F(LinkedList, cxListFindRemove) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
641 verifyFindRemove(linkedListFromTestData());
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
642 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
643
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
644 TEST_F(PointerLinkedList, cxListFindRemove) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
645 verifyFindRemove(pointerLinkedListFromTestData());
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
646 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
647
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
648 TEST_F(ArrayList, cxListFindRemove) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
649 verifyFindRemove(arrayListFromTestData());
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
650 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
651
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
652 TEST_F(PointerArrayList, cxListFindRemove) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
653 verifyFindRemove(pointerArrayListFromTestData());
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
654 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
655
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
656 TEST_F(LinkedList, cxListClear) {
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
657 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
658 }
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
659
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
660 TEST_F(PointerLinkedList, cxListClear) {
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
661 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
662 }
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
663
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
664 TEST_F(ArrayList, cxListClear) {
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
665 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
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
667
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
668 TEST_F(PointerArrayList, cxListClear) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
669 verifyClear(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
670 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
671
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
672 TEST_F(LinkedList, cxListSwap) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
673 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
674 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
675
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
676 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
677 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
678 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
679
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
680 TEST_F(ArrayList, cxListSwap) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
681 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
682 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
683
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
684 TEST_F(PointerArrayList, cxListSwap) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
685 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
686 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
687
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
688 TEST_F(LinkedList, cxListSwapNoSBO) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
689 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
690 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
691 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
692 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
693
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
694 TEST_F(PointerLinkedList, cxListSwapNoSBO) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
695 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
696 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
697 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
698 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
699
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
700 TEST_F(LinkedList, cxListAt) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
701 verifyAt(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
702 }
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
703
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
704 TEST_F(PointerLinkedList, cxListAt) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
705 verifyAt(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
706 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
707
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
708 TEST_F(ArrayList, cxListAt) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
709 verifyAt(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
710 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
711
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
712 TEST_F(PointerArrayList, cxListAt) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
713 verifyAt(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
714 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
715
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
716 TEST_F(LinkedList, cxListFind) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
717 verifyFind(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
718 }
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
719
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
720 TEST_F(PointerLinkedList, cxListFind) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
721 verifyFind(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
722 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
723
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
724 TEST_F(ArrayList, cxListFind) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
725 verifyFind(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
726 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
727
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
728 TEST_F(PointerArrayList, cxListFind) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
729 verifyFind(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
730 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
731
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
732 TEST_F(LinkedList, cxListSort) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
733 verifySort(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
734 }
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
735
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
736 TEST_F(PointerLinkedList, cxListSort) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
737 verifySort(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
738 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
739
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
740 TEST_F(ArrayList, cxListSort) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
741 verifySort(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
742 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
743
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
744 TEST_F(PointerArrayList, cxListSort) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
745 verifySort(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
746 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
747
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
748 TEST_F(LinkedList, Iterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
749 verifyIterator(linkedListFromTestData());
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
750 }
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
751
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
752 TEST_F(PointerLinkedList, Iterator) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
753 verifyIterator(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
754 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
755
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
756 TEST_F(ArrayList, Iterator) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
757 verifyIterator(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
758 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
759
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
760 TEST_F(PointerArrayList, Iterator) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
761 verifyIterator(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
762 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
763
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
764 TEST_F(LinkedList, InsertViaIterator) {
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
765 int fivenums[] = {0, 1, 2, 3, 4, 5};
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
766 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
767 cxListAddArray(list, fivenums, 5);
517
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
768 verifyInsertViaIterator(list);
b3baaf9b7e3c migrate list tests to gtest
Mike Becker <universe@uap-core.de>
parents: 509
diff changeset
769 }
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
770
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
771 TEST_F(PointerLinkedList, InsertViaIterator) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
772 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
773 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
774 // 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
775 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
776 verifyInsertViaIterator(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
777 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
778
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
779 TEST_F(ArrayList, InsertViaIterator) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
780 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
781 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
782 cxListAddArray(list, fivenums, 5);
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
783 verifyInsertViaIterator(list);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
784 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
785
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
786 TEST_F(PointerArrayList, InsertViaIterator) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
787 int fivenums[] = {0, 1, 2, 3, 4, 5};
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
788 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
789 // 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
790 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
791 verifyInsertViaIterator(list);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
792 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
793
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
794 TEST_F(LinkedList, cxListReverse) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
795 verifyReverse(linkedListFromTestData());
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
796 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
797
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
798 TEST_F(PointerLinkedList, cxListReverse) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
799 verifyReverse(pointerLinkedListFromTestData());
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
800 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
801
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
802 TEST_F(ArrayList, cxListReverse) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
803 verifyReverse(arrayListFromTestData());
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
804 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
805
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
806 TEST_F(PointerArrayList, cxListReverse) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
807 verifyReverse(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
808 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
809
521
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
810 TEST_F(LinkedList, cxListCompare) {
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
811 auto left = linkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
812 auto right = linkedListFromTestData();
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
813 verifyCompare(left, right);
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
814 }
e5dc54131d55 add test for cxListCompare
Mike Becker <universe@uap-core.de>
parents: 520
diff changeset
815
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
816 TEST_F(LinkedList, cxListCompareWithPtrList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
817 auto left = linkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
818 auto right = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
819 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
820 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
821
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
822 TEST_F(LinkedList, cxListCompareWithArrayList) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
823 auto left = linkedListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
824 auto right = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
825 verifyCompare(left, right);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
826 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
827
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
828 TEST_F(LinkedList, cxListCompareWithPtrArrayList) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
829 auto left = linkedListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
830 auto right = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
831 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
832 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
833
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
834 TEST_F(PointerLinkedList, cxListCompare) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
835 auto left = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
836 auto right = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
837 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
838 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
839
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
840 TEST_F(PointerLinkedList, cxListCompareWithNormalList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
841 auto left = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
842 auto right = linkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
843 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
844 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
845
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
846 TEST_F(PointerLinkedList, cxListCompareWithArrayList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
847 auto left = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
848 auto right = arrayListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
849 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
850 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
851
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
852 TEST_F(PointerLinkedList, cxListCompareWithPtrArrayList) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
853 auto left = pointerLinkedListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
854 auto right = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
855 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
856 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
857
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
858 TEST_F(ArrayList, cxListCompare) {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
859 auto left = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
860 auto right = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
861 verifyCompare(left, right);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
862 }
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
863
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
864 TEST_F(ArrayList, cxListCompareWithPtrList) {
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
865 auto left = arrayListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
866 auto right = pointerLinkedListFromTestData();
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
867 verifyCompare(left, right);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
868 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
869
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
870 TEST_F(ArrayList, cxListCompareWithNormalList) {
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
871 auto left = arrayListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
872 auto right = linkedListFromTestData();
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
873 verifyCompare(left, right);
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents: 602
diff changeset
874 }
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
875
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
876 TEST_F(ArrayList, cxListCompareWithPtrArrayList) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
877 auto left = arrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
878 auto right = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
879 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
880 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
881
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
882 TEST_F(PointerArrayList, cxListCompare) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
883 auto left = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
884 auto right = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
885 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
886 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
887
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
888 TEST_F(PointerArrayList, cxListCompareWithPtrList) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
889 auto left = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
890 auto right = pointerLinkedListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
891 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
892 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
893
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
894 TEST_F(PointerArrayList, cxListCompareWithNormalList) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
895 auto left = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
896 auto right = linkedListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
897 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
898 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
899
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
900 TEST_F(PointerArrayList, cxListCompareWithNormalArrayList) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
901 auto left = pointerArrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
902 auto right = arrayListFromTestData();
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
903 verifyCompare(left, right);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
904 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
905
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
906 TEST_F(LinkedList, SimpleDestructor) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
907 verifySimpleDestructor(linkedListFromTestData());
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
908 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
909
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
910 TEST_F(PointerLinkedList, SimpleDestructor) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
911 verifySimpleDestructor(pointerLinkedListFromTestData());
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
912 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
913
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
914 TEST_F(ArrayList, SimpleDestructor) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
915 verifySimpleDestructor(arrayListFromTestData());
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
916 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
917
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
918 TEST_F(PointerArrayList, SimpleDestructor) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
919 verifySimpleDestructor(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
920 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
921
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
922 TEST_F(LinkedList, AdvancedDestructor) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
923 verifyAdvancedDestructor(linkedListFromTestData());
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
924 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
925
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
926 TEST_F(PointerLinkedList, AdvancedDestructor) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
927 verifyAdvancedDestructor(pointerLinkedListFromTestData());
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
928 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
929
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
930 TEST_F(ArrayList, AdvancedDestructor) {
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
931 verifyAdvancedDestructor(arrayListFromTestData());
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
932 }
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
933
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
934 TEST_F(PointerArrayList, AdvancedDestructor) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
935 verifyAdvancedDestructor(pointerArrayListFromTestData());
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
936 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
937
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
938 TEST_F(PointerLinkedList, DestroyNoDestructor) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
939 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
940 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
941 cxListAdd(list, item);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
942 CX_TEST_ASSERT(!testingAllocator.verify());
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
943 cxListDestroy(list);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
944 CX_TEST_ASSERT(!testingAllocator.verify());
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
945 cxFree(&testingAllocator, item);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
946 CX_TEST_ASSERT(testingAllocator.verify());
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
947 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
948
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
949 TEST_F(PointerLinkedList, DestroySimpleDestructor) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
950 int item = 0;
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
951 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
952 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
953 cxListAdd(list, &item);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
954 cxListDestroy(list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
955 EXPECT_EQ(item, 42);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
956 }
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
957
672
55d8fdd38ca4 increase test coverage - fixes #250
Mike Becker <universe@uap-core.de>
parents: 667
diff changeset
958 TEST_F(PointerLinkedList, DestroyAdvancedDestructor) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
959 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
960 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
961 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
962 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
963 cxListAdd(list, item);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
964 CX_TEST_ASSERT(!testingAllocator.verify());
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
965 cxListDestroy(list);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
966 CX_TEST_ASSERT(testingAllocator.verify());
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 639
diff changeset
967 }
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
968
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
969 TEST_F(PointerArrayList, DestroyNoDestructor) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
970 void *item = cxMalloc(&testingAllocator, sizeof(int));
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
971 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
972 cxListAdd(list, item);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
973 CX_TEST_ASSERT(!testingAllocator.verify());
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
974 cxListDestroy(list);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
975 CX_TEST_ASSERT(!testingAllocator.verify());
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
976 cxFree(&testingAllocator, item);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
977 CX_TEST_ASSERT(testingAllocator.verify());
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
978 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
979
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
980 TEST_F(PointerArrayList, DestroySimpleDestructor) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
981 int item = 0;
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
982 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
983 list->simple_destructor = [](void *elem) { *(int *) elem = 42; };
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
984 cxListAdd(list, &item);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
985 cxListDestroy(list);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
986 EXPECT_EQ(item, 42);
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
987 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
988
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
989 TEST_F(PointerArrayList, DestroyAdvancedDestructor) {
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
990 void *item = cxMalloc(&testingAllocator, sizeof(int));
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
991 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
992 list->destructor_data = &testingAllocator;
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
993 list->advanced_destructor = (cx_destructor_func2) cxFree;
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
994 cxListAdd(list, item);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
995 CX_TEST_ASSERT(!testingAllocator.verify());
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
996 cxListDestroy(list);
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
997 CX_TEST_ASSERT(testingAllocator.verify());
679
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
998 }
022fbd4bc057 add pointer array list tests
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
999
704
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1000 TEST(EmptyList, Size) {
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1001 auto list = cxEmptyList;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1002
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1003 EXPECT_EQ(list->size, 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1004 EXPECT_EQ(cxListSize(list), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1005 }
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1006
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1007 TEST(EmptyList, Iterator) {
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1008 auto list = cxEmptyList;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1009
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1010 auto it1 = cxListIterator(list);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1011 auto it2 = cxListBackwardsIterator(list);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1012 auto it3 = cxListMutIterator(list);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1013 auto it4 = cxListMutBackwardsIterator(list);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1014
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
1015 CX_TEST_ASSERT(!cxIteratorValid(it1));
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
1016 CX_TEST_ASSERT(!cxIteratorValid(it2));
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
1017 CX_TEST_ASSERT(!cxIteratorValid(it3));
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
1018 CX_TEST_ASSERT(!cxIteratorValid(it4));
704
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1019
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1020 int c = 0;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1021 cx_foreach(void*, data, it1) c++;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1022 cx_foreach(void*, data, it2) c++;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1023 cx_foreach(void*, data, it3) c++;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1024 cx_foreach(void*, data, it4) c++;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1025 EXPECT_EQ(c, 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1026 }
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1027
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1028 TEST(EmptyList, NoOps) {
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1029 auto list = cxEmptyList;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1030
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1031 ASSERT_NO_FATAL_FAILURE(cxListSort(list));
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1032 ASSERT_NO_FATAL_FAILURE(cxListClear(list));
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1033 ASSERT_NO_FATAL_FAILURE(cxListDestroy(list));
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1034 }
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1035
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1036 TEST(EmptyList, At) {
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1037 auto list = cxEmptyList;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1038
790
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
1039 EXPECT_EQ(cxListAt(list, 0), NULL);
42877968260c some text replacements to prepare migration of list tests
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
1040 EXPECT_EQ(cxListAt(list, 1), NULL);
704
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1041 }
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1042
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1043 TEST(EmptyList, Find) {
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1044 auto list = cxEmptyList;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1045
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1046 int x = 42, y = 1337;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1047
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1048 EXPECT_LT(cxListFind(list, &x), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1049 EXPECT_LT(cxListFind(list, &y), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1050 }
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1051
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1052 TEST(EmptyList, Compare) {
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1053 auto empty = cxEmptyList;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1054
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1055 auto ll = cxLinkedListCreateSimple(sizeof(int));
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1056 auto al = cxArrayListCreateSimple(sizeof(int), 8);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1057
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1058 int x = 5;
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1059
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1060 EXPECT_EQ(cxListCompare(empty, cxEmptyList), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1061 EXPECT_EQ(cxListCompare(ll, cxEmptyList), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1062 EXPECT_EQ(cxListCompare(al, cxEmptyList), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1063 EXPECT_EQ(cxListCompare(cxEmptyList, ll), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1064 EXPECT_EQ(cxListCompare(cxEmptyList, al), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1065
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1066 cxListAdd(ll, &x);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1067 cxListAdd(al, &x);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1068
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1069 EXPECT_GT(cxListCompare(ll, cxEmptyList), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1070 EXPECT_GT(cxListCompare(al, cxEmptyList), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1071 EXPECT_LT(cxListCompare(cxEmptyList, ll), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1072 EXPECT_LT(cxListCompare(cxEmptyList, al), 0);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1073
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1074 cxListDestroy(ll);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1075 cxListDestroy(al);
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 702
diff changeset
1076 }

mercurial