test/array_tests.c

Wed, 06 Nov 2019 20:34:54 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 06 Nov 2019 20:34:54 +0100
changeset 367
e54e0b24e98e
parent 366
41a7cef34c19
child 369
28a8ccc442b0
permissions
-rw-r--r--

fix: configure.ac

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
366
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
99 UCX_TEST(test_ucx_array_append_from_struct) {
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
100 struct teststruct {
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
101 unsigned long long x;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
102 unsigned long long y;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
103 unsigned long long z;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
104 };
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
105
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
106 UcxArray *array = ucx_array_new(16, sizeof(struct teststruct));
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
107 struct teststruct *elements;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
108
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
109 struct teststruct data;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
110 data.x = 13; data.y = 37; data.z = 47;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
111
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
112 ucx_array_append_from(array, &data, 1);
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
113 UCX_TEST_BEGIN
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
114
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
115 elements = array->data;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
116 UCX_TEST_ASSERT(elements[0].x == 13, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
117 UCX_TEST_ASSERT(elements[0].y == 37, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
118 UCX_TEST_ASSERT(elements[0].z == 47, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
119
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
120 data.x = 0; data.y = 8; data.z = 15;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
121 ucx_array_append_from(array, &data, 1);
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
122
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
123 elements = array->data;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
124 UCX_TEST_ASSERT(array->size == 2, "incorrect size after append");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
125 UCX_TEST_ASSERT(elements[1].x == 0, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
126 UCX_TEST_ASSERT(elements[1].y == 8, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
127 UCX_TEST_ASSERT(elements[1].z == 15, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
128
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
129 UCX_TEST_ASSERT(elements[0].x == 13,
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
130 "append corrupted previously inserted data");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
131 UCX_TEST_ASSERT(elements[0].y == 37,
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
132 "append corrupted previously inserted data");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
133 UCX_TEST_ASSERT(elements[0].z == 47,
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
134 "append corrupted previously inserted data");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
135
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
136 UCX_TEST_END
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
137
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
138 ucx_array_destroy(array);
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
139 }
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
140
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
141 UCX_TEST(test_ucx_array_prepend_from) {
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
142 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
143 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
144
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
145 int x = 42;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
146 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
147 UCX_TEST_BEGIN
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
148
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
149 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
150 UCX_TEST_ASSERT(elems[0] == 42, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
151
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
152 int y[2] = {13, 37};
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
153 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
154
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
155 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
156 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
157 UCX_TEST_ASSERT(elems[0] == 13, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
158 UCX_TEST_ASSERT(elems[1] == 37, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
159 UCX_TEST_ASSERT(elems[2] == 42,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
160 "prepend corrupted previously inserted data");
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_prepend_from(array, 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;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
165 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
166 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
167 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
168 UCX_TEST_ASSERT(elems[2] == 13,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
169 "NULL prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
170 UCX_TEST_ASSERT(elems[3] == 37,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
171 "NULL prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
172 UCX_TEST_ASSERT(elems[4] == 42,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
173 "NULL prepend corrupted previously inserted data");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
174
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
175 UCX_TEST_END
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_free(array);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
178 }
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
179
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
180 UCX_TEST(test_ucx_array_set_from) {
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
181 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
182 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
183
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
184 int x = 42;
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
185
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
186 UCX_TEST_BEGIN
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
187
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
188 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
189
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
190 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
191 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
192 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
193 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
194
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
195 int y[2] = {13, 37};
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
196 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
197
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
198 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
199 UCX_TEST_ASSERT(elems[27] == 13, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
200 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
201 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
202 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
203
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
204 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
205
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
206 elems = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
207 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
208 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
209
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
210 UCX_TEST_END
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
211
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
212 ucx_array_free(array);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
213 }
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
214
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
215 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
216 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
217 int *elements;
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
218
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
219 ucx_array_append(array, 42);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
220 UCX_TEST_BEGIN
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
221
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
222 elements = array->data;
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
223 UCX_TEST_ASSERT(elements[0] == 42, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
224
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
225 ucx_array_append(array, 13);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
226 ucx_array_append(array, 37);
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
227
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
228 elements = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
229 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
230 UCX_TEST_ASSERT(elements[1] == 13, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
231 UCX_TEST_ASSERT(elements[2] == 37, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
232 UCX_TEST_ASSERT(elements[0] == 42,
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
233 "append corrupted previously inserted data");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
234
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
235 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
236
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
237 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
238 }
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
239
366
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
240 UCX_TEST(test_ucx_array_append_struct) {
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
241 struct teststruct {
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
242 unsigned long long x;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
243 unsigned long long y;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
244 unsigned long long z;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
245 };
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
246
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
247 UcxArray *array = ucx_array_new(16, sizeof(struct teststruct));
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
248 struct teststruct *elements;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
249
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
250 struct teststruct data;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
251 data.x = 13; data.y = 37; data.z = 47;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
252
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
253 ucx_array_append(array, data);
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
254 UCX_TEST_BEGIN
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
255
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
256 elements = array->data;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
257 UCX_TEST_ASSERT(elements[0].x == 13, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
258 UCX_TEST_ASSERT(elements[0].y == 37, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
259 UCX_TEST_ASSERT(elements[0].z == 47, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
260
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
261 data.x = 0; data.y = 8; data.z = 15;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
262 ucx_array_append(array, data);
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
263
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
264 elements = array->data;
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
265 UCX_TEST_ASSERT(array->size == 2, "incorrect size after append");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
266 UCX_TEST_ASSERT(elements[1].x == 0, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
267 UCX_TEST_ASSERT(elements[1].y == 8, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
268 UCX_TEST_ASSERT(elements[1].z == 15, "failed");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
269
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
270 UCX_TEST_ASSERT(elements[0].x == 13,
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
271 "append corrupted previously inserted data");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
272 UCX_TEST_ASSERT(elements[0].y == 37,
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
273 "append corrupted previously inserted data");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
274 UCX_TEST_ASSERT(elements[0].z == 47,
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
275 "append corrupted previously inserted data");
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
276
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
277 UCX_TEST_END
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
278
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
279 ucx_array_destroy(array);
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
280 }
41a7cef34c19 adds testcase to uncover a bug in ucx_array_append()
Mike Becker <universe@uap-core.de>
parents: 357
diff changeset
281
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
282 UCX_TEST(test_ucx_array_prepend) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
283 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
284 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
285
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
286 ucx_array_prepend(array, 42);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
287 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
288
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
289 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
290 UCX_TEST_ASSERT(elems[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
291
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
292 ucx_array_prepend(array, 37);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
293 ucx_array_prepend(array, 13);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
294
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
295 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
296 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
297 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
298 UCX_TEST_ASSERT(elems[1] == 37, "failed");
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
299 UCX_TEST_ASSERT(elems[2] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
300 "prepend corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
301
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
302 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
303
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
304 ucx_array_free(array);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
305 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
306
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
307 UCX_TEST(test_ucx_array_set) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
308 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
309 UcxArray *array = ucx_array_new(16, sizeof(int));
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
310
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
311 UCX_TEST_BEGIN
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
312
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
313 ucx_array_set(array, 7, 42);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
314
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
315 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
316 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
317 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
318 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
319
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
320 ucx_array_set(array, 27, 13);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
321 ucx_array_set(array, 28, 37);
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
322
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
323 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
324 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
325 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
326 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
327 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
328
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
329 UCX_TEST_END
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
330
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
331 ucx_array_free(array);
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
332 }
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
333
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
334 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
335 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
336 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
337 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
338 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
339
350
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
340 int32_t *intelems;
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
341 int64_t *longintelems;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
342
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
343 a1->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
344 intelems = a1->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
345 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
346 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
347 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
348 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
349 intelems[4] = 15;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
350 a2->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
351 intelems = a2->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
352 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
353 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
354 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
355 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
356 intelems[4] = 15;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
357 a3->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
358 longintelems = a3->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
359 longintelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
360 longintelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
361 longintelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
362 longintelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
363 longintelems[4] = 15;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
364 a4->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
365 intelems = a4->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
366 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
367 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
368 intelems[2] = -6;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
369 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
370 intelems[4] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
371
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
372 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
373
350
82a88d938108 fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents: 344
diff changeset
374 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
375 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
376 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
377 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
378 "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
379 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
380 "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
381
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
382 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
383 "compare using memcmp() failed");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
384 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
385 "compare using memcmp() failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
386
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
387 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
388 ucx_array_free(a1);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
389 ucx_array_free(a2);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
390 ucx_array_free(a3);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
391 ucx_array_free(a4);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
394 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
395 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
396 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
397 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
398
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
399 a1->size = 2;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
400 elems = a1->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
401 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
402 elems[1] = 11;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
403 a2->size = 3;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
404 elems = a2->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
405 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
406 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
407 elems[2] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
408
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
409 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
410
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
411 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
412 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
413 elems = a1->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
414 UCX_TEST_ASSERT(elems[0] == 47, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
415 UCX_TEST_ASSERT(elems[1] == 11, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
416 UCX_TEST_ASSERT(elems[2] == 0, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
417 UCX_TEST_ASSERT(elems[3] == 8, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
418 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
419
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
420 a1->elemsize *= 2;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
421 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
422 "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
423 UCX_TEST_ASSERT(a1->size == 5,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
424 "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
425
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
426 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
427 ucx_array_free(a1);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
428 ucx_array_free(a2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
429 }
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
430
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
431 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
432 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
433
354
7fd13b9f8f60 improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents: 353
diff changeset
434 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
435 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
436
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
437 UCX_TEST_BEGIN
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
438
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
439 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
440 *(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
441 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
442
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
443 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
444 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
445
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
446 UCX_TEST_END
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
447
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
448 ucx_array_free(array);
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
449 }
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
450
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
451 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
452 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
453 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
454
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
455 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
456 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
457 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
458 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
459 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
460 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
461 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
462
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
463 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
464 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
465
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
466 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
467
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
468 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
469 "doesn't find element");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
470 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
471 "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
472
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
473 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
474 "failed using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
475 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
476 "failed using memcmp()");
172
7084e8e8433c refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents: 162
diff changeset
477
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
478 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
479 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
480 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
481
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
482 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
483 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
484 int *elems;
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
485
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
486 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
487 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
488 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
489 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
490 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
491 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
492 elems[4] = 15;
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
493
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
494 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
495 int y = 90;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
496
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
497 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
498
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
499 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
500 "false negative");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
501 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
502 "false positive");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
503
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
504 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
505 "false negative using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
506 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
507 "false positive using memcmp()");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
508
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
509 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
510 ucx_array_free(array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
511 }
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
512
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
513 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
514 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
515 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
516
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
517 array->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
518 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
519 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
520 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
521 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
522 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
523 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
524
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
525 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
526
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
527 ucx_array_remove(array, 2);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
528 elems = array->data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
529 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
530 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
531 elems[1] == 11 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
532 elems[2] == 8 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
533 elems[3] == 15,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
534 "wrong contents after remove");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
535 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
536
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
537 ucx_array_remove_fast(array, 1);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
538 elems = array->data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
539 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
540 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
541 elems[1] == 15 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
542 elems[2] == 8,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
543 "wrong contents after fast remove");
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
544 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
545
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
546 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
547 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
548 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
549
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
550 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
551 UcxArray array;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
552 UcxArray copy;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
553 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
554 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
555 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
556
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
557 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
558 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
559 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
560 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
561 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
562 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
563 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
564
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
565 ucx_array_clone(&copy, &array);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
566 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
567
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
568 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
569 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
570 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
571 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
572 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
573 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
574 "contents do not match after clone");
211
07a284486fa1 added ucx_list_free_contents()
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
575
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
576 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
577
353
135ce35d5108 renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
578 ucx_array_destroy(&array);
135ce35d5108 renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
579 ucx_array_destroy(&copy);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
580 }
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
581
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
582 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
583 return -ucx_cmp_int(x,y,data);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
584 }
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
585
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
586 UCX_TEST(test_ucx_array_sort) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
587 int *elems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
588
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 = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
591 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
592 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
593 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
594 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
595 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
596 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
597
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
598 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
599 expected->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
600 elems = expected->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
601 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
602 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
603 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
604 elems[3] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
605 elems[4] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
606
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
607 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
608 expectedrev->size = 5;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
609 elems = expectedrev->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
610 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
611 elems[1] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
612 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
613 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
614 elems[4] = 0;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
615
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
616
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
617 UCX_TEST_BEGIN
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
618 void* original_ptr = array->data;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
619 ucx_array_sort(array, ucx_cmp_int, NULL);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
620 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
621 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
622 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
623
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
624 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
625 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
626
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
627 ucx_array_reserve(array, 32);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
628 ucx_array_reserve(expected, 32);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
629 array->size = expected->size = 32;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
630 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
631 ((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
632 ((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
633 }
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
634
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
635 /* 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
636 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
637 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
638 "failed for bigger arrays");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
639 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
640
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
641 ucx_array_free(expectedrev);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
642 ucx_array_free(expected);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
643 ucx_array_free(array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
644 }
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
645
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
646 UCX_TEST(test_ucx_array_autogrow) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
647 int *elems;
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
648 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
649 array->size = 3;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
650 elems = array->data;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
651 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
652 elems[1] = 11;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
653 int x = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
654
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
655 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
656
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
657 void* oldptr = array->data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
658
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
659 ucx_array_append(array, 5);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
660 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
661 "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
662 ucx_array_append(array, 5);
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
663 elems = array->data;
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
664 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
665 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
666 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
667
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
668 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
669 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
670 }
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
671
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
672 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
673 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
674 array->size = 4;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
675
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
676 UCX_TEST_BEGIN
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
677 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
678 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
679 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
680 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
681 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
682
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
683 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
684 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
685 array->size = 8;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
686
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
687 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
688
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
689 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
690 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
691 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
692
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
693 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
694 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
695 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
696
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
697 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
698 ucx_array_free(array);
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
699 }
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
700
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
701 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
702 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
703
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
704 UCX_TEST_BEGIN
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
705
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
706 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
707 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
708
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
709 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
710 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
711
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
712 UCX_TEST_END
356
77efe51c6c9a changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents: 355
diff changeset
713 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
714 }
355
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
715
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
716 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
717 size_t capacity = 16;
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
718 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
719
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
720 UCX_TEST_BEGIN
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
721
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
722 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
723
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
724 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
725 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
726
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
727 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
728 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
729
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
730 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
731 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
732 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
733
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
734 UCX_TEST_END
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
735
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
736 free(array);
d315a068235a adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents: 354
diff changeset
737 }

mercurial