test/array_tests.c

Tue, 06 Aug 2019 16:26:46 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 06 Aug 2019 16:26:46 +0200
branch
feature/array
changeset 342
8f0a3c00d1d2
parent 337
f695ae118460
child 344
320b962afaf9
permissions
-rw-r--r--

removes cumbersome array accessor macros

9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
3 *
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
4 * Copyright 2019 Mike Becker, Olaf Wintermann All rights reserved.
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
5 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
6 * Redistribution and use in source and binary forms, with or without
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
7 * modification, are permitted provided that the following conditions are met:
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
8 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
10 * notice, this list of conditions and the following disclaimer.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
11 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
14 * documentation and/or other materials provided with the distribution.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
15 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
29 #include "array_tests.h"
251
fae240d633fc changes source directory structure in preperation for autotools rollout
Mike Becker <universe@uap-core.de>
parents: 250
diff changeset
30 #include <ucx/utils.h>
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
32 UCX_TEST(test_ucx_array_free) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
33 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
34
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
35 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
36 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
37 UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
38 UCX_TEST_ASSERT(array.size == 0, "size not zero after free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
39 UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
40 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
41 "allocator corrupted during free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
42 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
43 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
44
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
45 UCX_TEST(test_ucx_array_new) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
46 UcxArray array = ucx_array_new(16, 47);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
47
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
48 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
49 UCX_TEST_ASSERT(array.data, "no memory allocated");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
50 UCX_TEST_ASSERT(array.size == 0, "size not initially zero");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
51 UCX_TEST_ASSERT(array.capacity == 16, "capacity not as requested");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
52 UCX_TEST_ASSERT(array.elemsize == 47, "element size not as requested");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
53 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
54 "array not using the default allocator");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
55 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
56 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
57 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
58
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
59 UCX_TEST(test_ucx_array_append) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
60 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
61 int *elements;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
62
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
63 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
64 ucx_array_append(&array, &x);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
65 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
66
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
67 elements = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
68 UCX_TEST_ASSERT(elements[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
69
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
70 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
71 ucx_array_append(&array, &x);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
72
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
73 elements = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
74 UCX_TEST_ASSERT(array.size == 2, "incorrect size after append");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
75 UCX_TEST_ASSERT(elements[1] == 13, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
76 UCX_TEST_ASSERT(elements[0] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
77 "append corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
78
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
79 ucx_array_append(&array, NULL);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
80
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
81 elements = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
82 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL append");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
83 UCX_TEST_ASSERT(elements[2] == 0, "element is not zeroed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
84 UCX_TEST_ASSERT(elements[0] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
85 "NULL append corrupted previously inserted data");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
86 UCX_TEST_ASSERT(elements[1] == 13,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
87 "NULL append corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
88
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
89 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
90
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
91 ucx_array_free(&array);
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
92 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
93
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
94 UCX_TEST(test_ucx_array_prepend) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
95 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
96 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
97
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
98 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
99 ucx_array_prepend(&array, &x);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
100 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
101
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
102 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
103 UCX_TEST_ASSERT(elems[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
104
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
105 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
106 ucx_array_prepend(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
107
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
108 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
109 UCX_TEST_ASSERT(array.size == 2, "incorrect size after prepend");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
110 UCX_TEST_ASSERT(elems[0] == 13, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
111 UCX_TEST_ASSERT(elems[1] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
112 "prepend corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
113
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
114 ucx_array_prepend(&array, NULL);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
115
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
116 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
117 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL prepend");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
118 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
119 UCX_TEST_ASSERT(elems[1] == 13,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
120 "NULL prepend corrupted previously inserted data");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
121 UCX_TEST_ASSERT(elems[2] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
122 "NULL prepend corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
123
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
124 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
125
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
126 ucx_array_free(&array);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
127 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
128
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
129 UCX_TEST(test_ucx_array_set) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
130 int *elems;
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
131 UcxArray array = ucx_array_new(16, sizeof(int));
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
132
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
133
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
134 int x = 42;
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
135
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
136 UCX_TEST_BEGIN
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
137
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
138 ucx_array_set(&array, 7, &x);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
139
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
140 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
141 UCX_TEST_ASSERT(elems[7] == 42, "failed");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
142 UCX_TEST_ASSERT(array.size >= 8, "array not resized on set");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
143 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
144
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
145 x = 13;
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
146 ucx_array_set(&array, 27, &x);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
147
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
148 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
149 UCX_TEST_ASSERT(elems[27] == 13, "failed");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
150 UCX_TEST_ASSERT(array.size == 28, "array not resized on set");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
151 UCX_TEST_ASSERT(array.capacity == 28, "capacity not grown");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
152
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
153 ucx_array_set(&array, 7, NULL);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
154
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
155 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
156 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
157
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
158 UCX_TEST_END
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
159
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
160 ucx_array_free(&array);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
161 }
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
162
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
163 UCX_TEST(test_ucx_array_equals) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
164 UcxArray a1 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
165 UcxArray a2 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
166 UcxArray a3 = ucx_array_new(16, sizeof(long int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
167 UcxArray a4 = ucx_array_new(16, sizeof(int));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
168
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
169 int *intelems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
170 long int *longintelems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
171
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
172 a1.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
173 intelems = a1.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
174 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
175 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
176 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
177 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
178 intelems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
179 a2.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
180 intelems = a2.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
181 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
182 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
183 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
184 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
185 intelems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
186 a3.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
187 longintelems = a3.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
188 longintelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
189 longintelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
190 longintelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
191 longintelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
192 longintelems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
193 a4.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
194 intelems = a4.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
195 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
196 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
197 intelems[2] = -6;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
198 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
199 intelems[4] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
200
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
201 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
202
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
203 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int, NULL), "failed");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
204 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int, NULL), "failed");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
205 UCX_TEST_ASSERT(!ucx_array_equals(a4, a1, ucx_cmp_int, NULL), "failed");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
206 UCX_TEST_ASSERT(!ucx_array_equals(a1, a3, ucx_cmp_int, NULL),
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
207 "comparing arrays of different element size shall fail");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
208 UCX_TEST_ASSERT(!ucx_array_equals(a3, a1, ucx_cmp_int, NULL),
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
209 "comparing arrays of different element size shall fail");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
210
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
211 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, NULL, NULL),
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
212 "compare using memcmp() failed");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
213 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, NULL, NULL),
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
214 "compare using memcmp() failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
215
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
216 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
217 ucx_array_free(&a1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
218 ucx_array_free(&a2);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
219 ucx_array_free(&a3);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
220 ucx_array_free(&a4);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
223 UCX_TEST(test_ucx_array_concat) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
224 UcxArray a1 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
225 UcxArray a2 = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
226 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
227
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
228 a1.size = 2;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
229 elems = a1.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
230 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
231 elems[1] = 11;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
232 a2.size = 3;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
233 elems = a2.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
234 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
235 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
236 elems[2] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
237
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
238 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
239
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
240 UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
241 UCX_TEST_ASSERT(a1.size == 5, "failed");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
242 elems = a1.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
243 UCX_TEST_ASSERT(elems[0] == 47, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
244 UCX_TEST_ASSERT(elems[1] == 11, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
245 UCX_TEST_ASSERT(elems[2] == 0, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
246 UCX_TEST_ASSERT(elems[3] == 8, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
247 UCX_TEST_ASSERT(elems[4] == 15, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
248
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
249 a1.elemsize *= 2;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
250 UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
251 "arrays of different element size must not be concatenated");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
252 UCX_TEST_ASSERT(a1.size == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
253 "arrays of different element size must not be concatenated");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
254
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
255 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
256 ucx_array_free(&a1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
257 ucx_array_free(&a2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
258 }
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
259
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
260 UCX_TEST(test_ucx_array_find) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
261 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
262 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
263
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
264 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
265 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
266 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
267 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
268 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
269 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
270 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
271
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
272 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
273 int y = 90;
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
274
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
275 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
276
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
277 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&x,ucx_cmp_int,NULL) == 3,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
278 "doesn't find element");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
279 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&y,ucx_cmp_int,NULL) == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
280 "finds non-existing element");
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
281
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
282 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&x,NULL,NULL) == 3,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
283 "failed using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
284 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&y,NULL,NULL) == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
285 "failed using memcmp()");
172
7084e8e8433c refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents: 162
diff changeset
286
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
287 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
288 ucx_array_free(&array);
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
289 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
290
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
291 UCX_TEST(test_ucx_array_contains) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
292 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
293 int *elems;
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
294
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
295 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
296 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
297 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
298 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
299 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
300 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
301 elems[4] = 15;
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
302
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
303 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
304 int y = 90;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
305
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
306 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
307
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
308 UCX_TEST_ASSERT(ucx_array_contains(array,(void*)&x,ucx_cmp_int,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
309 "false negative");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
310 UCX_TEST_ASSERT(!ucx_array_contains(array,(void*)&y,ucx_cmp_int,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
311 "false positive");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
312
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
313 UCX_TEST_ASSERT(ucx_array_contains(array,(void*)&x,NULL,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
314 "false negative using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
315 UCX_TEST_ASSERT(!ucx_array_contains(array,(void*)&y,NULL,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
316 "false positive using memcmp()");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
317
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
318 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
319 ucx_array_free(&array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
320 }
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
321
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
322 UCX_TEST(test_ucx_array_remove) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
323 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
324 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
325
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
326 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
327 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
328 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
329 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
330 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
331 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
332 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
333
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
334 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
335
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
336 ucx_array_remove(&array, 2);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
337 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
338 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
339 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
340 elems[1] == 11 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
341 elems[2] == 8 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
342 elems[3] == 15,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
343 "wrong contents after remove");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
344 UCX_TEST_ASSERT(array.size == 4, "wrong size after remove");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
345
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
346 ucx_array_remove_fast(&array, 1);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
347 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
348 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
349 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
350 elems[1] == 15 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
351 elems[2] == 8,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
352 "wrong contents after fast remove");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
353 UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
354
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
355 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
356 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
357 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
358
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
359 UCX_TEST(test_ucx_array_clone) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
360 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
361 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
362
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
363 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
364 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
365 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
366 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
367 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
368 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
369 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
370
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
371 UcxArray copy = ucx_array_clone(array);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
372 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
373
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
374 UCX_TEST_ASSERT(array.data != copy.data, "no true copy");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
375 UCX_TEST_ASSERT(array.size == copy.size, "size mismatch");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
376 UCX_TEST_ASSERT(array.capacity == copy.capacity, "capacity mismatch");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
377 UCX_TEST_ASSERT(array.elemsize == copy.elemsize, "element size mismatch");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
378 UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
379 UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed");
211
07a284486fa1 added ucx_list_free_contents()
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
380
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
381 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
382
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
383 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
384 ucx_array_free(&copy);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
385 }
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
386
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
387 static int ucx_cmp_int_reverse(const void* x, const void* y, void* data) {
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
388 return -ucx_cmp_int(x,y,data);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
389 }
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
390
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
391 UCX_TEST(test_ucx_array_sort) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
392 int *elems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
393
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
394 UcxArray array = ucx_array_new(16, sizeof(int));
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
395 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
396 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
397 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
398 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
399 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
400 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
401 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
402
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
403 UcxArray expected = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
404 expected.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
405 elems = expected.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
406 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
407 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
408 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
409 elems[3] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
410 elems[4] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
411
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
412 UcxArray expectedrev = ucx_array_new(16, sizeof(int));
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
413 expectedrev.size = 5;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
414 elems = expectedrev.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
415 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
416 elems[1] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
417 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
418 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
419 elems[4] = 0;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
420
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
421
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
422 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
423 void* original_ptr = array.data;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
424 ucx_array_sort(array, ucx_cmp_int, NULL);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
425 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
426 UCX_TEST_ASSERT(array.size == 5, "size corrupted");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
427 UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
428
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
429 ucx_array_sort(array, ucx_cmp_int_reverse, NULL);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
430 UCX_TEST_ASSERT(ucx_array_equals(array, expectedrev, NULL, NULL), "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
431
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
432 ucx_array_reserve(&array, 32);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
433 ucx_array_reserve(&expected, 32);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
434 array.size = expected.size = 32;
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
435 for (size_t i = 0 ; i < 32 ; i++) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
436 ((int*)array.data)[i]= ((i%2==0)?-1:1) * ((int) i);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
437 ((int*)expected.data)[i] = (-30+2*i) - (i > 15 ? 1 : 0);
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
438 }
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
439
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
440 /* dummy third argument to trigger a possible fallback for qsort_s */
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
441 ucx_array_sort(array, ucx_cmp_int, array.data);
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
442 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL),
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
443 "failed for bigger arrays");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
444 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
445
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
446 ucx_array_free(&expected);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
447 ucx_array_free(&array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
448 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
449
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
450 UCX_TEST(test_ucx_array_autogrow) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
451 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
452 UcxArray array = ucx_array_new(4, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
453 array.size = 3;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
454 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
455 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
456 elems[1] = 11;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
457 int x = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
458
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
459 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
460
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
461 void* oldptr = array.data;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
462
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
463 ucx_array_append(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
464 UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
465 "array should not grow too early");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
466 ucx_array_append(&array, &x);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
467 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
468 UCX_TEST_ASSERT(array.capacity == 8, "array did not grow");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
469 UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
470 UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
471
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
472 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
473 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
474 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
475
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
476 UCX_TEST(test_ucx_array_shrink) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
477 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
478 array.size = 4;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
479
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
480 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
481 UCX_TEST_ASSERT(!ucx_array_shrink(&array), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
482 UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after shrink");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
483 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
484 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
485 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
486
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
487 UCX_TEST(test_ucx_array_resize) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
488 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
489 array.size = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
490
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
491 UCX_TEST_BEGIN
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
492
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
493 UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
494 UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
495 UCX_TEST_ASSERT(array.size == 8, "incorrect size after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
496
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
497 UCX_TEST_ASSERT(!ucx_array_resize(&array, 4), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
498 UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
499 UCX_TEST_ASSERT(array.size == 4, "incorrect size after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
500
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
501 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
502 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
503 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
504
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
505 UCX_TEST(test_ucx_array_reserve) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
506 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
507
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
508 UCX_TEST_BEGIN
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
509
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
510 UCX_TEST_ASSERT(!ucx_array_reserve(&array, 4), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
511 UCX_TEST_ASSERT(array.capacity == 16, "reserve shall not shrink");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
512
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
513 UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
514 UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after reserve");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
515
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
516 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
517 ucx_array_free(&array);
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
518 }

mercurial