test/array_tests.c

changeset 366
41a7cef34c19
parent 357
0f5732f0dc00
child 369
28a8ccc442b0
equal deleted inserted replaced
365:72da0e4cbf4a 366:41a7cef34c19
94 UCX_TEST_END 94 UCX_TEST_END
95 95
96 ucx_array_free(array); 96 ucx_array_free(array);
97 } 97 }
98 98
99 UCX_TEST(test_ucx_array_append_from_struct) {
100 struct teststruct {
101 unsigned long long x;
102 unsigned long long y;
103 unsigned long long z;
104 };
105
106 UcxArray *array = ucx_array_new(16, sizeof(struct teststruct));
107 struct teststruct *elements;
108
109 struct teststruct data;
110 data.x = 13; data.y = 37; data.z = 47;
111
112 ucx_array_append_from(array, &data, 1);
113 UCX_TEST_BEGIN
114
115 elements = array->data;
116 UCX_TEST_ASSERT(elements[0].x == 13, "failed");
117 UCX_TEST_ASSERT(elements[0].y == 37, "failed");
118 UCX_TEST_ASSERT(elements[0].z == 47, "failed");
119
120 data.x = 0; data.y = 8; data.z = 15;
121 ucx_array_append_from(array, &data, 1);
122
123 elements = array->data;
124 UCX_TEST_ASSERT(array->size == 2, "incorrect size after append");
125 UCX_TEST_ASSERT(elements[1].x == 0, "failed");
126 UCX_TEST_ASSERT(elements[1].y == 8, "failed");
127 UCX_TEST_ASSERT(elements[1].z == 15, "failed");
128
129 UCX_TEST_ASSERT(elements[0].x == 13,
130 "append corrupted previously inserted data");
131 UCX_TEST_ASSERT(elements[0].y == 37,
132 "append corrupted previously inserted data");
133 UCX_TEST_ASSERT(elements[0].z == 47,
134 "append corrupted previously inserted data");
135
136 UCX_TEST_END
137
138 ucx_array_destroy(array);
139 }
140
99 UCX_TEST(test_ucx_array_prepend_from) { 141 UCX_TEST(test_ucx_array_prepend_from) {
100 int *elems; 142 int *elems;
101 UcxArray *array = ucx_array_new(16, sizeof(int)); 143 UcxArray *array = ucx_array_new(16, sizeof(int));
102 144
103 int x = 42; 145 int x = 42;
186 elements = array->data; 228 elements = array->data;
187 UCX_TEST_ASSERT(array->size == 3, "incorrect size after append"); 229 UCX_TEST_ASSERT(array->size == 3, "incorrect size after append");
188 UCX_TEST_ASSERT(elements[1] == 13, "failed"); 230 UCX_TEST_ASSERT(elements[1] == 13, "failed");
189 UCX_TEST_ASSERT(elements[2] == 37, "failed"); 231 UCX_TEST_ASSERT(elements[2] == 37, "failed");
190 UCX_TEST_ASSERT(elements[0] == 42, 232 UCX_TEST_ASSERT(elements[0] == 42,
233 "append corrupted previously inserted data");
234
235 UCX_TEST_END
236
237 ucx_array_destroy(array);
238 }
239
240 UCX_TEST(test_ucx_array_append_struct) {
241 struct teststruct {
242 unsigned long long x;
243 unsigned long long y;
244 unsigned long long z;
245 };
246
247 UcxArray *array = ucx_array_new(16, sizeof(struct teststruct));
248 struct teststruct *elements;
249
250 struct teststruct data;
251 data.x = 13; data.y = 37; data.z = 47;
252
253 ucx_array_append(array, data);
254 UCX_TEST_BEGIN
255
256 elements = array->data;
257 UCX_TEST_ASSERT(elements[0].x == 13, "failed");
258 UCX_TEST_ASSERT(elements[0].y == 37, "failed");
259 UCX_TEST_ASSERT(elements[0].z == 47, "failed");
260
261 data.x = 0; data.y = 8; data.z = 15;
262 ucx_array_append(array, data);
263
264 elements = array->data;
265 UCX_TEST_ASSERT(array->size == 2, "incorrect size after append");
266 UCX_TEST_ASSERT(elements[1].x == 0, "failed");
267 UCX_TEST_ASSERT(elements[1].y == 8, "failed");
268 UCX_TEST_ASSERT(elements[1].z == 15, "failed");
269
270 UCX_TEST_ASSERT(elements[0].x == 13,
271 "append corrupted previously inserted data");
272 UCX_TEST_ASSERT(elements[0].y == 37,
273 "append corrupted previously inserted data");
274 UCX_TEST_ASSERT(elements[0].z == 47,
191 "append corrupted previously inserted data"); 275 "append corrupted previously inserted data");
192 276
193 UCX_TEST_END 277 UCX_TEST_END
194 278
195 ucx_array_destroy(array); 279 ucx_array_destroy(array);

mercurial