Sun, 29 Dec 2019 11:29:17 +0100
adds string replace functions
9 | 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 | 27 | */ |
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 | 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 | |
337 | 215 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
216 | 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
|
217 | 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
|
218 | 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
|
219 | 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
|
220 | 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
|
221 | |
350
82a88d938108
fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents:
344
diff
changeset
|
222 | int32_t *intelems; |
82a88d938108
fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents:
344
diff
changeset
|
223 | int64_t *longintelems; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
224 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
225 | a1->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
226 | intelems = a1->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
227 | intelems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
228 | intelems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
229 | intelems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
230 | intelems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
231 | intelems[4] = 15; |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
232 | a2->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
233 | intelems = a2->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
234 | intelems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
235 | intelems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
236 | intelems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
237 | intelems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
238 | intelems[4] = 15; |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
239 | a3->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
240 | longintelems = a3->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
241 | longintelems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
242 | longintelems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
243 | longintelems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
244 | longintelems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
245 | longintelems[4] = 15; |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
246 | a4->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
247 | intelems = a4->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
248 | intelems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
249 | intelems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
250 | intelems[2] = -6; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
251 | intelems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
252 | intelems[4] = 15; |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
253 | |
123
7fb0f74517c5
changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
254 | 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
|
255 | |
350
82a88d938108
fixes array_equals test (broken on 32 bit platforms)
Mike Becker <universe@uap-core.de>
parents:
344
diff
changeset
|
256 | 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
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | "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
|
261 | 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
|
262 | "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
|
263 | |
336
6d7aa8a1a3b3
implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents:
334
diff
changeset
|
264 | 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
|
265 | "compare using memcmp() failed"); |
336
6d7aa8a1a3b3
implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents:
334
diff
changeset
|
266 | 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
|
267 | "compare using memcmp() failed"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
268 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
269 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
270 | ucx_array_free(a1); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
271 | ucx_array_free(a2); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
272 | ucx_array_free(a3); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
273 | ucx_array_free(a4); |
9 | 274 | } |
275 | ||
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
276 | 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
|
277 | 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
|
278 | 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
|
279 | int *elems; |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
280 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
281 | a1->size = 2; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
282 | elems = a1->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
283 | elems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
284 | elems[1] = 11; |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
285 | a2->size = 3; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
286 | elems = a2->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
287 | elems[0] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
288 | elems[1] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
289 | elems[2] = 15; |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
290 | |
123
7fb0f74517c5
changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
291 | 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
|
292 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
293 | 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
|
294 | 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
|
295 | elems = a1->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
296 | UCX_TEST_ASSERT(elems[0] == 47, "failed"); |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
297 | UCX_TEST_ASSERT(elems[1] == 11, "failed"); |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
298 | UCX_TEST_ASSERT(elems[2] == 0, "failed"); |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
299 | UCX_TEST_ASSERT(elems[3] == 8, "failed"); |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
300 | 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
|
301 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
302 | a1->elemsize *= 2; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
303 | 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
|
304 | "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
|
305 | UCX_TEST_ASSERT(a1->size == 5, |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
306 | "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
|
307 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
308 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
309 | ucx_array_free(a1); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
310 | ucx_array_free(a2); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
311 | } |
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
|
312 | |
344
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
313 | 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
|
314 | 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
|
315 | |
354
7fd13b9f8f60
improves array append/prepend/set interface
Mike Becker <universe@uap-core.de>
parents:
353
diff
changeset
|
316 | 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
|
317 | 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
|
318 | |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
319 | UCX_TEST_BEGIN |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
320 | |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
321 | 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
|
322 | *(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
|
323 | 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
|
324 | |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
325 | 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
|
326 | 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
|
327 | |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
328 | UCX_TEST_END |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
329 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
330 | ucx_array_free(array); |
344
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
331 | } |
320b962afaf9
reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents:
342
diff
changeset
|
332 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
333 | 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
|
334 | 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
|
335 | int *elems; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
336 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
337 | array->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
338 | elems = array->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
339 | elems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
340 | elems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
341 | elems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
342 | elems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
343 | elems[4] = 15; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
344 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
345 | int x = 8; |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
346 | 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
|
347 | |
7fb0f74517c5
changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
348 | 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
|
349 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
350 | 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
|
351 | "doesn't find element"); |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
352 | 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
|
353 | "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
|
354 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
355 | 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
|
356 | "failed using memcmp()"); |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
357 | 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
|
358 | "failed using memcmp()"); |
172
7084e8e8433c
refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
359 | |
123
7fb0f74517c5
changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
360 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
361 | 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
|
362 | } |
7fb0f74517c5
changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
363 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
364 | 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
|
365 | 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
|
366 | int *elems; |
90
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
367 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
368 | array->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
369 | elems = array->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
370 | elems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
371 | elems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
372 | elems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
373 | elems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
374 | elems[4] = 15; |
162
52dfe5f4ecd7
added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
134
diff
changeset
|
375 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
376 | int x = 8; |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
377 | int y = 90; |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
378 | |
123
7fb0f74517c5
changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
379 | 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
|
380 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
381 | 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
|
382 | "false negative"); |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
383 | 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
|
384 | "false positive"); |
162
52dfe5f4ecd7
added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
134
diff
changeset
|
385 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
386 | 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
|
387 | "false negative using memcmp()"); |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
388 | 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
|
389 | "false positive using memcmp()"); |
162
52dfe5f4ecd7
added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
134
diff
changeset
|
390 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
391 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
392 | ucx_array_free(array); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
393 | } |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
394 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
395 | 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
|
396 | 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
|
397 | int *elems; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
398 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
399 | array->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
400 | elems = array->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; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
403 | elems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
404 | elems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
405 | elems[4] = 15; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
406 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
407 | UCX_TEST_BEGIN |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
408 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
409 | ucx_array_remove(array, 2); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
410 | elems = array->data; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
411 | UCX_TEST_ASSERT( |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
412 | elems[0] == 47 && |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
413 | elems[1] == 11 && |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
414 | elems[2] == 8 && |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
415 | elems[3] == 15, |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
416 | "wrong contents after remove"); |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
417 | 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
|
418 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
419 | ucx_array_remove_fast(array, 1); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
420 | elems = array->data; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
421 | UCX_TEST_ASSERT( |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
422 | elems[0] == 47 && |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
423 | elems[1] == 15 && |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
424 | elems[2] == 8, |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
425 | "wrong contents after fast remove"); |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
426 | 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
|
427 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
428 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
429 | ucx_array_free(array); |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
430 | } |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
431 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
432 | 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
|
433 | UcxArray array; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
434 | UcxArray copy; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
435 | 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
|
436 | ucx_array_init(©, 4, 2*sizeof(double)); |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
437 | int *elems; |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
438 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
439 | array.size = 5; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
440 | elems = array.data; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
441 | elems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
442 | elems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
443 | elems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
444 | elems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
445 | elems[4] = 15; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
446 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
447 | ucx_array_clone(©, &array); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
448 | UCX_TEST_BEGIN |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
449 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
450 | 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
|
451 | 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
|
452 | 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
|
453 | 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
|
454 | 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
|
455 | UCX_TEST_ASSERT(ucx_array_equals(&array, ©, ucx_cmp_int, NULL), |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
456 | "contents do not match after clone"); |
211
07a284486fa1
added ucx_list_free_contents()
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
457 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
458 | UCX_TEST_END |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
459 | |
353
135ce35d5108
renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents:
350
diff
changeset
|
460 | ucx_array_destroy(&array); |
135ce35d5108
renames ucx_array_free() to ucx_array_destroy()
Mike Becker <universe@uap-core.de>
parents:
350
diff
changeset
|
461 | ucx_array_destroy(©); |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
462 | } |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
463 | |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
464 | 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
|
465 | return -ucx_cmp_int(x,y,data); |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
466 | } |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
467 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
468 | UCX_TEST(test_ucx_array_sort) { |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
469 | int *elems; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
470 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
471 | 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
|
472 | array->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
473 | elems = array->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
474 | elems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
475 | elems[1] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
476 | elems[2] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
477 | elems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
478 | elems[4] = 15; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
479 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
480 | 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
|
481 | expected->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
482 | elems = expected->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
483 | elems[0] = 0; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
484 | elems[1] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
485 | elems[2] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
486 | elems[3] = 15; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
487 | elems[4] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
488 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
489 | 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
|
490 | expectedrev->size = 5; |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
491 | elems = expectedrev->data; |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
492 | elems[0] = 47; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
493 | elems[1] = 15; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
494 | elems[2] = 11; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
495 | elems[3] = 8; |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
496 | elems[4] = 0; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
497 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
498 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
499 | UCX_TEST_BEGIN |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
500 | void* original_ptr = array->data; |
336
6d7aa8a1a3b3
implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents:
334
diff
changeset
|
501 | ucx_array_sort(array, ucx_cmp_int, NULL); |
6d7aa8a1a3b3
implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents:
334
diff
changeset
|
502 | 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
|
503 | 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
|
504 | 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
|
505 | |
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
506 | 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
|
507 | 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
|
508 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
509 | ucx_array_reserve(array, 32); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
510 | ucx_array_reserve(expected, 32); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
511 | array->size = expected->size = 32; |
336
6d7aa8a1a3b3
implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents:
334
diff
changeset
|
512 | 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
|
513 | ((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
|
514 | ((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
|
515 | } |
6d7aa8a1a3b3
implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents:
334
diff
changeset
|
516 | |
342
8f0a3c00d1d2
removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents:
337
diff
changeset
|
517 | /* 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
|
518 | 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
|
519 | 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
|
520 | "failed for bigger arrays"); |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
521 | UCX_TEST_END |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
522 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
523 | ucx_array_free(expectedrev); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
524 | ucx_array_free(expected); |
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
525 | ucx_array_free(array); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
526 | } |
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
|
527 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
528 | 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
|
529 | 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
|
530 | array->size = 4; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
531 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
532 | UCX_TEST_BEGIN |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
533 | 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
|
534 | 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
|
535 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
536 | ucx_array_free(array); |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
537 | } |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
538 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
539 | 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
|
540 | 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
|
541 | array->size = 8; |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
542 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
543 | 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
|
544 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
545 | 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
|
546 | 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
|
547 | 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
|
548 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
549 | 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
|
550 | 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
|
551 | 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
|
552 | |
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
553 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
554 | ucx_array_free(array); |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
555 | } |
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
|
556 | |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
557 | 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
|
558 | 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
|
559 | |
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
|
560 | UCX_TEST_BEGIN |
334
bc81faa9afda
adds array interface and tests
Mike Becker <universe@uap-core.de>
parents:
323
diff
changeset
|
561 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
562 | 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
|
563 | 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
|
564 | |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
565 | 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
|
566 | 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
|
567 | |
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
|
568 | UCX_TEST_END |
356
77efe51c6c9a
changes UcxArray from value to pointer semantics
Mike Becker <universe@uap-core.de>
parents:
355
diff
changeset
|
569 | 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
|
570 | } |
355
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
571 | |
369
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
572 | UCX_TEST(test_ucx_array_grow) { |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
573 | UcxArray *array = ucx_array_new(16, sizeof(int)); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
574 | array->size = 12; |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
575 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
576 | UCX_TEST_BEGIN |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
577 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
578 | UCX_TEST_ASSERT(!ucx_array_grow(array, 4), "failed"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
579 | UCX_TEST_ASSERT(array->capacity == 16, "shall be noop if contents fit"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
580 | /* subsequent calls shall also be noops */ |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
581 | UCX_TEST_ASSERT(!ucx_array_grow(array, 4), "failed"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
582 | UCX_TEST_ASSERT(array->capacity == 16, "shall be noop if contents fit"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
583 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
584 | UCX_TEST_ASSERT(!ucx_array_grow(array, 6), "failed"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
585 | UCX_TEST_ASSERT(array->capacity == 18, "incorrect capacity after grow"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
586 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
587 | UCX_TEST_END |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
588 | ucx_array_free(array); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
589 | } |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
590 | |
355
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
591 | 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
|
592 | size_t capacity = 16; |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
593 | int* array = malloc(sizeof(int)*capacity); |
369
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
594 | int x; |
355
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
595 | |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
596 | UCX_TEST_BEGIN |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
597 | |
369
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
598 | x = 42; |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
599 | ucx_array_util_set(&array, &capacity, sizeof(int), 7, &x); |
355
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
600 | |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
601 | 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
|
602 | 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
|
603 | |
369
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
604 | x = 13; |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
605 | ucx_array_util_set(&array, &capacity, sizeof(int), 37, &x); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
606 | x = 37; |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
607 | ucx_array_util_set(&array, &capacity, sizeof(int), 38, &x); |
355
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
608 | |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
609 | 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
|
610 | 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
|
611 | 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
|
612 | |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
613 | UCX_TEST_END |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
614 | |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
615 | free(array); |
d315a068235a
adds array utility functions for user defined arrays
Mike Becker <universe@uap-core.de>
parents:
354
diff
changeset
|
616 | } |
369
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
617 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
618 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
619 | UCX_TEST(test_ucx_array_util_setptr) { |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
620 | size_t capacity = 16; |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
621 | double** array = malloc(sizeof(double*)*capacity); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
622 | double x, y, z; |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
623 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
624 | UCX_TEST_BEGIN |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
625 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
626 | ucx_array_util_setptr(&array, &capacity, 7, &x); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
627 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
628 | UCX_TEST_ASSERT(array[7] == &x, "failed"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
629 | UCX_TEST_ASSERT(capacity == 16, "capacity changed unnecessarily"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
630 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
631 | ucx_array_util_setptr(&array, &capacity, 37, &y); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
632 | ucx_array_util_setptr(&array, &capacity, 38, &z); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
633 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
634 | UCX_TEST_ASSERT(array[37] == &y, "failed"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
635 | UCX_TEST_ASSERT(array[38] == &z, "failed"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
636 | UCX_TEST_ASSERT(capacity == 64, "capacity not grown"); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
637 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
638 | UCX_TEST_END |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
639 | |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
640 | free(array); |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
641 | } |
28a8ccc442b0
removes some bugs by redesigning the array API
Mike Becker <universe@uap-core.de>
parents:
366
diff
changeset
|
642 |