test/array_tests.c

Sun, 03 Nov 2019 16:34:29 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Nov 2019 16:34:29 +0100
changeset 364
5577d6c27a33
parent 357
0f5732f0dc00
child 366
41a7cef34c19
permissions
-rw-r--r--

adds case independent versions of sstrprefix() and sstrsuffix()

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
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
32 UCX_TEST(test_ucx_array_destroy) {
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
33 UcxArray array;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
34 ucx_array_init(&array, 16, sizeof(int));
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
35
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
36 UCX_TEST_BEGIN
353
135ce35d5108 renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
37 ucx_array_destroy(&array);
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
38 UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after destroy");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
39 UCX_TEST_ASSERT(array.size == 0, "size not zero after destroy");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
40 UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after destroy");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
41 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
42 "allocator corrupted during destroy");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
43 UCX_TEST_END
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
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
46 UCX_TEST(test_ucx_array_new) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
47 UcxArray* array = ucx_array_new(16, 47);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
48
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
49 UCX_TEST_BEGIN
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
50 UCX_TEST_ASSERT(array->data, "no memory allocated");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
51 UCX_TEST_ASSERT(array->size == 0, "size not initially zero");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
52 UCX_TEST_ASSERT(array->capacity == 16, "capacity not as requested");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
53 UCX_TEST_ASSERT(array->elemsize == 47, "element size not as requested");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
54 UCX_TEST_ASSERT(array->allocator == ucx_default_allocator(),
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
55 "array not using the default allocator");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
56 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
57 ucx_array_free(array);
334
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
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
60 UCX_TEST(test_ucx_array_append_from) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
61 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
62 int *elements;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
63
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
64 int x = 42;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
65 ucx_array_append_from(array, &x, 1);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
66 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
67
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
68 elements = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
69 UCX_TEST_ASSERT(elements[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
70
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
71 int y[2] = {13, 37};
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
72 ucx_array_append_from(array, y, 2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
73
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
74 elements = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
75 UCX_TEST_ASSERT(array->size == 3, "incorrect size after append");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
76 UCX_TEST_ASSERT(elements[1] == 13, "failed");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
77 UCX_TEST_ASSERT(elements[2] == 37, "failed");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
78 UCX_TEST_ASSERT(elements[0] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
79 "append corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
80
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
81 ucx_array_append_from(array, NULL, 2);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
82
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
83 elements = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
84 UCX_TEST_ASSERT(array->size == 5, "incorrect size after NULL append");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
85 UCX_TEST_ASSERT(elements[3] == 0, "element is not zeroed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
86 UCX_TEST_ASSERT(elements[4] == 0, "element is not zeroed");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
87 UCX_TEST_ASSERT(elements[0] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
88 "NULL append corrupted previously inserted data");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
89 UCX_TEST_ASSERT(elements[1] == 13,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
90 "NULL append corrupted previously inserted data");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
91 UCX_TEST_ASSERT(elements[2] == 37,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
92 "NULL append corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
93
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
94 UCX_TEST_END
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
95
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
96 ucx_array_free(array);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
97 }
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
98
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
99 UCX_TEST(test_ucx_array_prepend_from) {
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
100 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
101 UcxArray *array = ucx_array_new(16, sizeof(int));
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
102
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
103 int x = 42;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
104 ucx_array_prepend_from(array, &x, 1);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
105 UCX_TEST_BEGIN
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
106
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
107 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
108 UCX_TEST_ASSERT(elems[0] == 42, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
109
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
110 int y[2] = {13, 37};
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
111 ucx_array_prepend_from(array, y, 2);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
112
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
113 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
114 UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
115 UCX_TEST_ASSERT(elems[0] == 13, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
116 UCX_TEST_ASSERT(elems[1] == 37, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
117 UCX_TEST_ASSERT(elems[2] == 42,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
118 "prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
119
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
120 ucx_array_prepend_from(array, NULL, 2);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
121
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
122 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
123 UCX_TEST_ASSERT(array->size == 5, "incorrect size after NULL prepend");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
124 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
125 UCX_TEST_ASSERT(elems[1] == 0, "element is not zeroed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
126 UCX_TEST_ASSERT(elems[2] == 13,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
127 "NULL prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
128 UCX_TEST_ASSERT(elems[3] == 37,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
129 "NULL prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
130 UCX_TEST_ASSERT(elems[4] == 42,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
131 "NULL prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
132
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
133 UCX_TEST_END
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
134
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
135 ucx_array_free(array);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
136 }
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
137
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
138 UCX_TEST(test_ucx_array_set_from) {
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
139 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
140 UcxArray *array = ucx_array_new(16, sizeof(int));
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
141
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
142 int x = 42;
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
143
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
144 UCX_TEST_BEGIN
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
145
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
146 ucx_array_set_from(array, 7, &x, 1);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
147
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
148 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
149 UCX_TEST_ASSERT(elems[7] == 42, "failed");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
150 UCX_TEST_ASSERT(array->size >= 8, "array not resized on set");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
151 UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
152
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
153 int y[2] = {13, 37};
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
154 ucx_array_set_from(array, 27, y, 2);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
155
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
156 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
157 UCX_TEST_ASSERT(elems[27] == 13, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
158 UCX_TEST_ASSERT(elems[28] == 37, "failed");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
159 UCX_TEST_ASSERT(array->size == 29, "array not resized on set");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
160 UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
161
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
162 ucx_array_set_from(array, 7, NULL, 2);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
163
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
164 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
165 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
166 UCX_TEST_ASSERT(elems[8] == 0, "not zeroed on NULL set");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
167
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
168 UCX_TEST_END
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
169
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
170 ucx_array_free(array);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
171 }
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
172
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
173 UCX_TEST(test_ucx_array_append) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
174 UcxArray *array = ucx_array_new(16, sizeof(int));
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
175 int *elements;
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
176
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
177 ucx_array_append(array, 42);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
178 UCX_TEST_BEGIN
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
179
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
180 elements = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
181 UCX_TEST_ASSERT(elements[0] == 42, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
182
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
183 ucx_array_append(array, 13);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
184 ucx_array_append(array, 37);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
185
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
186 elements = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
187 UCX_TEST_ASSERT(array->size == 3, "incorrect size after append");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
188 UCX_TEST_ASSERT(elements[1] == 13, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
189 UCX_TEST_ASSERT(elements[2] == 37, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
190 UCX_TEST_ASSERT(elements[0] == 42,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
191 "append corrupted previously inserted data");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
192
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
193 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
194
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
195 ucx_array_destroy(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
196 }
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
197
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
198 UCX_TEST(test_ucx_array_prepend) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
199 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
200 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
201
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
202 ucx_array_prepend(array, 42);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
203 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
204
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
205 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
206 UCX_TEST_ASSERT(elems[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
207
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
208 ucx_array_prepend(array, 37);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
209 ucx_array_prepend(array, 13);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
210
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
211 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
212 UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
213 UCX_TEST_ASSERT(elems[0] == 13, "failed");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
214 UCX_TEST_ASSERT(elems[1] == 37, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
215 UCX_TEST_ASSERT(elems[2] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
216 "prepend corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
217
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
218 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
219
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
220 ucx_array_free(array);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
221 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
222
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
223 UCX_TEST(test_ucx_array_set) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
224 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
225 UcxArray *array = ucx_array_new(16, sizeof(int));
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
226
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
227 UCX_TEST_BEGIN
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
228
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
229 ucx_array_set(array, 7, 42);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
230
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
231 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
232 UCX_TEST_ASSERT(elems[7] == 42, "failed");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
233 UCX_TEST_ASSERT(array->size == 8, "array not resized on set");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
234 UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
235
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
236 ucx_array_set(array, 27, 13);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
237 ucx_array_set(array, 28, 37);
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
238
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
239 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
240 UCX_TEST_ASSERT(elems[27] == 13, "failed");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
241 UCX_TEST_ASSERT(elems[28] == 37, "failed");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
242 UCX_TEST_ASSERT(array->size == 29, "array not resized on set");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
243 UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown");
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
244
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
245 UCX_TEST_END
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
246
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
247 ucx_array_free(array);
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
248 }
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
249
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
250 UCX_TEST(test_ucx_array_equals) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
251 UcxArray *a1 = ucx_array_new(16, sizeof(int32_t));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
252 UcxArray *a2 = ucx_array_new(16, sizeof(int32_t));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
253 UcxArray *a3 = ucx_array_new(16, sizeof(int64_t));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
254 UcxArray *a4 = ucx_array_new(16, sizeof(int32_t));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
255
350
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
256 int32_t *intelems;
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
257 int64_t *longintelems;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
258
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
259 a1->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
260 intelems = a1->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
261 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
262 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
263 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
264 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
265 intelems[4] = 15;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
266 a2->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
267 intelems = a2->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
268 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
269 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
270 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
271 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
272 intelems[4] = 15;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
273 a3->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
274 longintelems = a3->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
275 longintelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
276 longintelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
277 longintelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
278 longintelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
279 longintelems[4] = 15;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
280 a4->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
281 intelems = a4->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
282 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
283 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
284 intelems[2] = -6;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
285 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
286 intelems[4] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
287
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
288 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
289
350
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
290 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int32, NULL), "failed");
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
291 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int32, NULL), "failed");
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
292 UCX_TEST_ASSERT(!ucx_array_equals(a4, a1, ucx_cmp_int32, NULL), "failed");
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
293 UCX_TEST_ASSERT(!ucx_array_equals(a1, a3, ucx_cmp_int64, NULL),
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
294 "comparing arrays of different element size shall fail");
350
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
295 UCX_TEST_ASSERT(!ucx_array_equals(a3, a1, ucx_cmp_int64, NULL),
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
296 "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
297
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
298 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
299 "compare using memcmp() failed");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
300 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
301 "compare using memcmp() failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
302
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
303 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
304 ucx_array_free(a1);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
305 ucx_array_free(a2);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
306 ucx_array_free(a3);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
307 ucx_array_free(a4);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
310 UCX_TEST(test_ucx_array_concat) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
311 UcxArray *a1 = ucx_array_new(16, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
312 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
313 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
314
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
315 a1->size = 2;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
316 elems = a1->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
317 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
318 elems[1] = 11;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
319 a2->size = 3;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
320 elems = a2->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
321 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
322 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
323 elems[2] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
324
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
325 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
326
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
327 UCX_TEST_ASSERT(!ucx_array_concat(a1, a2), "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
328 UCX_TEST_ASSERT(a1->size == 5, "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
329 elems = a1->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
330 UCX_TEST_ASSERT(elems[0] == 47, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
331 UCX_TEST_ASSERT(elems[1] == 11, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
332 UCX_TEST_ASSERT(elems[2] == 0, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
333 UCX_TEST_ASSERT(elems[3] == 8, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
334 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
335
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
336 a1->elemsize *= 2;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
337 UCX_TEST_ASSERT(ucx_array_concat(a1, a2),
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
338 "arrays of different element size must not be concatenated");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
339 UCX_TEST_ASSERT(a1->size == 5,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
340 "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
341
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
342 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
343 ucx_array_free(a1);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
344 ucx_array_free(a2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
345 }
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
346
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
347 UCX_TEST(test_ucx_array_at) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
348 UcxArray *array = ucx_array_new(16, sizeof(int));
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
349
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
350 int x[3] = {42, 13, 5};
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
351 ucx_array_append_from(array, x, 3);
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
352
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
353 UCX_TEST_BEGIN
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
354
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
355 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 1) == 13, "failed");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
356 *(int*)ucx_array_at(array, 1) = 80;
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
357 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 1) == 80, "assignment failed");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
358
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
359 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 0) == 42, "corrupted data");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
360 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 2) == 5, "corrupted data");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
361
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
362 UCX_TEST_END
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
363
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
364 ucx_array_free(array);
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
365 }
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
366
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
367 UCX_TEST(test_ucx_array_find) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
368 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
369 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
370
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
371 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
372 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
373 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
374 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
375 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
376 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
377 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
378
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
379 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
380 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
381
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
382 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
383
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
384 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
385 "doesn't find element");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
386 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
387 "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
388
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
389 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
390 "failed using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
391 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
392 "failed using memcmp()");
172
7084e8e8433c refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents: 162
diff changeset
393
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
394 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
395 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
396 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
397
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
398 UCX_TEST(test_ucx_array_contains) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
399 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
400 int *elems;
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
401
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
402 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
403 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
404 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
405 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
406 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
407 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
408 elems[4] = 15;
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
409
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
410 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
411 int y = 90;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
412
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
413 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
414
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
415 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
416 "false negative");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
417 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
418 "false positive");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
419
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
420 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
421 "false negative using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
422 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
423 "false positive using memcmp()");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
424
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
425 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
426 ucx_array_free(array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
427 }
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
428
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
429 UCX_TEST(test_ucx_array_remove) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
430 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
431 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
432
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
433 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
434 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
435 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
436 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
437 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
438 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
439 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
440
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
441 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
442
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
443 ucx_array_remove(array, 2);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
444 elems = array->data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
445 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
446 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
447 elems[1] == 11 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
448 elems[2] == 8 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
449 elems[3] == 15,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
450 "wrong contents after remove");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
451 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
452
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
453 ucx_array_remove_fast(array, 1);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
454 elems = array->data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
455 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
456 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
457 elems[1] == 15 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
458 elems[2] == 8,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
459 "wrong contents after fast remove");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
460 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
461
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
462 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
463 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
464 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
465
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
466 UCX_TEST(test_ucx_array_clone) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
467 UcxArray array;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
468 UcxArray copy;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
469 ucx_array_init(&array, 16, sizeof(int));
357
0f5732f0dc00 fixes two bugs: clone to uninitialized array and missing return in ucx_array_ensurecap()
Mike Becker <universe@uap-core.de>
parents: 356
diff changeset
470 ucx_array_init(&copy, 4, 2*sizeof(double));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
471 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
472
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
473 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
474 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
475 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
476 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
477 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
478 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
479 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
480
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
481 ucx_array_clone(&copy, &array);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
482 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
483
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
484 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
485 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
486 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
487 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
488 UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
489 UCX_TEST_ASSERT(ucx_array_equals(&array, &copy, ucx_cmp_int, NULL),
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
490 "contents do not match after clone");
211
07a284486fa1 added ucx_list_free_contents()
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
491
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
492 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
493
353
135ce35d5108 renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
494 ucx_array_destroy(&array);
135ce35d5108 renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
495 ucx_array_destroy(&copy);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
496 }
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
497
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
498 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
499 return -ucx_cmp_int(x,y,data);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
500 }
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
501
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
502 UCX_TEST(test_ucx_array_sort) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
503 int *elems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
504
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
505 UcxArray *array = ucx_array_new(16, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
506 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
507 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
508 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
509 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
510 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
511 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
512 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
513
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
514 UcxArray *expected = ucx_array_new(16, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
515 expected->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
516 elems = expected->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
517 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
518 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
519 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
520 elems[3] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
521 elems[4] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
522
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
523 UcxArray *expectedrev = ucx_array_new(16, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
524 expectedrev->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
525 elems = expectedrev->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
526 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
527 elems[1] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
528 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
529 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
530 elems[4] = 0;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
531
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
532
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
533 UCX_TEST_BEGIN
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
534 void* original_ptr = array->data;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
535 ucx_array_sort(array, ucx_cmp_int, NULL);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
536 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
537 UCX_TEST_ASSERT(array->size == 5, "size corrupted");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
538 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
539
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
540 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
541 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
542
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
543 ucx_array_reserve(array, 32);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
544 ucx_array_reserve(expected, 32);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
545 array->size = expected->size = 32;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
546 for (size_t i = 0 ; i < 32 ; i++) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
547 ((int*)array->data)[i]= ((i%2==0)?-1:1) * ((int) i);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
548 ((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
549 }
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
550
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
551 /* dummy third argument to trigger a possible fallback for qsort_s */
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
552 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
553 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
554 "failed for bigger arrays");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
555 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
556
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
557 ucx_array_free(expectedrev);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
558 ucx_array_free(expected);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
559 ucx_array_free(array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
560 }
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
561
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
562 UCX_TEST(test_ucx_array_autogrow) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
563 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
564 UcxArray *array = ucx_array_new(4, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
565 array->size = 3;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
566 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
567 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
568 elems[1] = 11;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
569 int x = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
570
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
571 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
572
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
573 void* oldptr = array->data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
574
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
575 ucx_array_append(array, 5);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
576 UCX_TEST_ASSERT(array->capacity == 4 && array->data == oldptr,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
577 "array should not grow too early");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
578 ucx_array_append(array, 5);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
579 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
580 UCX_TEST_ASSERT(array->capacity == 8, "array did not grow");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
581 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
582 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
583
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
584 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
585 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
586 }
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
587
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
588 UCX_TEST(test_ucx_array_shrink) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
589 UcxArray *array = ucx_array_new(16, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
590 array->size = 4;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
591
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
592 UCX_TEST_BEGIN
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
593 UCX_TEST_ASSERT(!ucx_array_shrink(array), "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
594 UCX_TEST_ASSERT(array->capacity == 4, "incorrect capacity after shrink");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
595 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
596 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
597 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
598
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
599 UCX_TEST(test_ucx_array_resize) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
600 UcxArray *array = ucx_array_new(16, sizeof(int));
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
601 array->size = 8;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
602
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
603 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
604
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
605 UCX_TEST_ASSERT(!ucx_array_resize(array, 32), "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
606 UCX_TEST_ASSERT(array->capacity == 32, "incorrect capacity after resize");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
607 UCX_TEST_ASSERT(array->size == 8, "incorrect size after resize");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
608
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
609 UCX_TEST_ASSERT(!ucx_array_resize(array, 4), "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
610 UCX_TEST_ASSERT(array->capacity == 4, "incorrect capacity after resize");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
611 UCX_TEST_ASSERT(array->size == 4, "incorrect size after resize");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
612
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
613 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
614 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
615 }
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
616
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
617 UCX_TEST(test_ucx_array_reserve) {
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
618 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
619
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
620 UCX_TEST_BEGIN
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
621
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
622 UCX_TEST_ASSERT(!ucx_array_reserve(array, 4), "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
623 UCX_TEST_ASSERT(array->capacity == 16, "reserve shall not shrink");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
624
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
625 UCX_TEST_ASSERT(!ucx_array_resize(array, 32), "failed");
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
626 UCX_TEST_ASSERT(array->capacity == 32, "incorrect capacity after reserve");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
627
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
628 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
629 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
630 }
355
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
631
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
632 UCX_TEST(test_ucx_array_util_set) {
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
633 size_t capacity = 16;
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
634 int* array = malloc(sizeof(int)*capacity);
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
635
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
636 UCX_TEST_BEGIN
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
637
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
638 UCX_ARRAY_UTIL_SET(&array, &capacity, 7, 42);
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
639
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
640 UCX_TEST_ASSERT(array[7] == 42, "failed");
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
641 UCX_TEST_ASSERT(capacity == 16, "capacity changed unnecessarily");
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
642
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
643 UCX_ARRAY_UTIL_SET(&array, &capacity, 37, 13);
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
644 UCX_ARRAY_UTIL_SET(&array, &capacity, 38, 37);
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
645
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
646 UCX_TEST_ASSERT(array[37] == 13, "failed");
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
647 UCX_TEST_ASSERT(array[38] == 37, "failed");
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
648 UCX_TEST_ASSERT(capacity == 64, "capacity not grown");
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
649
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
650 UCX_TEST_END
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
651
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
652 free(array);
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
653 }

mercurial