1.1 --- a/test/array_tests.c Tue Sep 24 20:16:00 2019 +0200 1.2 +++ b/test/array_tests.c Thu Oct 03 10:55:39 2019 +0200 1.3 @@ -29,58 +29,59 @@ 1.4 #include "array_tests.h" 1.5 #include <ucx/utils.h> 1.6 1.7 -UCX_TEST(test_ucx_array_free) { 1.8 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.9 +UCX_TEST(test_ucx_array_destroy) { 1.10 + UcxArray array; 1.11 + ucx_array_init(&array, 16, sizeof(int)); 1.12 1.13 UCX_TEST_BEGIN 1.14 ucx_array_destroy(&array); 1.15 - UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after free"); 1.16 - UCX_TEST_ASSERT(array.size == 0, "size not zero after free"); 1.17 - UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after free"); 1.18 + UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after destroy"); 1.19 + UCX_TEST_ASSERT(array.size == 0, "size not zero after destroy"); 1.20 + UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after destroy"); 1.21 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(), 1.22 - "allocator corrupted during free"); 1.23 + "allocator corrupted during destroy"); 1.24 UCX_TEST_END 1.25 } 1.26 1.27 UCX_TEST(test_ucx_array_new) { 1.28 - UcxArray array = ucx_array_new(16, 47); 1.29 + UcxArray* array = ucx_array_new(16, 47); 1.30 1.31 UCX_TEST_BEGIN 1.32 - UCX_TEST_ASSERT(array.data, "no memory allocated"); 1.33 - UCX_TEST_ASSERT(array.size == 0, "size not initially zero"); 1.34 - UCX_TEST_ASSERT(array.capacity == 16, "capacity not as requested"); 1.35 - UCX_TEST_ASSERT(array.elemsize == 47, "element size not as requested"); 1.36 - UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(), 1.37 + UCX_TEST_ASSERT(array->data, "no memory allocated"); 1.38 + UCX_TEST_ASSERT(array->size == 0, "size not initially zero"); 1.39 + UCX_TEST_ASSERT(array->capacity == 16, "capacity not as requested"); 1.40 + UCX_TEST_ASSERT(array->elemsize == 47, "element size not as requested"); 1.41 + UCX_TEST_ASSERT(array->allocator == ucx_default_allocator(), 1.42 "array not using the default allocator"); 1.43 UCX_TEST_END 1.44 - ucx_array_destroy(&array); 1.45 + ucx_array_free(array); 1.46 } 1.47 1.48 UCX_TEST(test_ucx_array_append_from) { 1.49 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.50 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.51 int *elements; 1.52 1.53 int x = 42; 1.54 - ucx_array_append_from(&array, &x, 1); 1.55 + ucx_array_append_from(array, &x, 1); 1.56 UCX_TEST_BEGIN 1.57 1.58 - elements = array.data; 1.59 + elements = array->data; 1.60 UCX_TEST_ASSERT(elements[0] == 42, "failed"); 1.61 1.62 int y[2] = {13, 37}; 1.63 - ucx_array_append_from(&array, y, 2); 1.64 + ucx_array_append_from(array, y, 2); 1.65 1.66 - elements = array.data; 1.67 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after append"); 1.68 + elements = array->data; 1.69 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after append"); 1.70 UCX_TEST_ASSERT(elements[1] == 13, "failed"); 1.71 UCX_TEST_ASSERT(elements[2] == 37, "failed"); 1.72 UCX_TEST_ASSERT(elements[0] == 42, 1.73 "append corrupted previously inserted data"); 1.74 1.75 - ucx_array_append_from(&array, NULL, 2); 1.76 + ucx_array_append_from(array, NULL, 2); 1.77 1.78 - elements = array.data; 1.79 - UCX_TEST_ASSERT(array.size == 5, "incorrect size after NULL append"); 1.80 + elements = array->data; 1.81 + UCX_TEST_ASSERT(array->size == 5, "incorrect size after NULL append"); 1.82 UCX_TEST_ASSERT(elements[3] == 0, "element is not zeroed"); 1.83 UCX_TEST_ASSERT(elements[4] == 0, "element is not zeroed"); 1.84 UCX_TEST_ASSERT(elements[0] == 42, 1.85 @@ -92,34 +93,34 @@ 1.86 1.87 UCX_TEST_END 1.88 1.89 - ucx_array_destroy(&array); 1.90 + ucx_array_free(array); 1.91 } 1.92 1.93 UCX_TEST(test_ucx_array_prepend_from) { 1.94 int *elems; 1.95 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.96 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.97 1.98 int x = 42; 1.99 - ucx_array_prepend_from(&array, &x, 1); 1.100 + ucx_array_prepend_from(array, &x, 1); 1.101 UCX_TEST_BEGIN 1.102 1.103 - elems = array.data; 1.104 + elems = array->data; 1.105 UCX_TEST_ASSERT(elems[0] == 42, "failed"); 1.106 1.107 int y[2] = {13, 37}; 1.108 - ucx_array_prepend_from(&array, y, 2); 1.109 + ucx_array_prepend_from(array, y, 2); 1.110 1.111 - elems = array.data; 1.112 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after prepend"); 1.113 + elems = array->data; 1.114 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend"); 1.115 UCX_TEST_ASSERT(elems[0] == 13, "failed"); 1.116 UCX_TEST_ASSERT(elems[1] == 37, "failed"); 1.117 UCX_TEST_ASSERT(elems[2] == 42, 1.118 "prepend corrupted previously inserted data"); 1.119 1.120 - ucx_array_prepend_from(&array, NULL, 2); 1.121 + ucx_array_prepend_from(array, NULL, 2); 1.122 1.123 - elems = array.data; 1.124 - UCX_TEST_ASSERT(array.size == 5, "incorrect size after NULL prepend"); 1.125 + elems = array->data; 1.126 + UCX_TEST_ASSERT(array->size == 5, "incorrect size after NULL prepend"); 1.127 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed"); 1.128 UCX_TEST_ASSERT(elems[1] == 0, "element is not zeroed"); 1.129 UCX_TEST_ASSERT(elems[2] == 13, 1.130 @@ -131,59 +132,59 @@ 1.131 1.132 UCX_TEST_END 1.133 1.134 - ucx_array_destroy(&array); 1.135 + ucx_array_free(array); 1.136 } 1.137 1.138 UCX_TEST(test_ucx_array_set_from) { 1.139 int *elems; 1.140 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.141 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.142 1.143 int x = 42; 1.144 1.145 UCX_TEST_BEGIN 1.146 1.147 - ucx_array_set_from(&array, 7, &x, 1); 1.148 + ucx_array_set_from(array, 7, &x, 1); 1.149 1.150 - elems = array.data; 1.151 + elems = array->data; 1.152 UCX_TEST_ASSERT(elems[7] == 42, "failed"); 1.153 - UCX_TEST_ASSERT(array.size >= 8, "array not resized on set"); 1.154 - UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily"); 1.155 + UCX_TEST_ASSERT(array->size >= 8, "array not resized on set"); 1.156 + UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily"); 1.157 1.158 int y[2] = {13, 37}; 1.159 - ucx_array_set_from(&array, 27, y, 2); 1.160 + ucx_array_set_from(array, 27, y, 2); 1.161 1.162 - elems = array.data; 1.163 + elems = array->data; 1.164 UCX_TEST_ASSERT(elems[27] == 13, "failed"); 1.165 UCX_TEST_ASSERT(elems[28] == 37, "failed"); 1.166 - UCX_TEST_ASSERT(array.size == 29, "array not resized on set"); 1.167 - UCX_TEST_ASSERT(array.capacity == 32, "capacity not grown"); 1.168 + UCX_TEST_ASSERT(array->size == 29, "array not resized on set"); 1.169 + UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown"); 1.170 1.171 - ucx_array_set_from(&array, 7, NULL, 2); 1.172 + ucx_array_set_from(array, 7, NULL, 2); 1.173 1.174 - elems = array.data; 1.175 + elems = array->data; 1.176 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set"); 1.177 UCX_TEST_ASSERT(elems[8] == 0, "not zeroed on NULL set"); 1.178 1.179 UCX_TEST_END 1.180 1.181 - ucx_array_destroy(&array); 1.182 + ucx_array_free(array); 1.183 } 1.184 1.185 UCX_TEST(test_ucx_array_append) { 1.186 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.187 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.188 int *elements; 1.189 1.190 - ucx_array_append(&array, 42); 1.191 + ucx_array_append(array, 42); 1.192 UCX_TEST_BEGIN 1.193 1.194 - elements = array.data; 1.195 + elements = array->data; 1.196 UCX_TEST_ASSERT(elements[0] == 42, "failed"); 1.197 1.198 - ucx_array_append(&array, 13); 1.199 - ucx_array_append(&array, 37); 1.200 + ucx_array_append(array, 13); 1.201 + ucx_array_append(array, 37); 1.202 1.203 - elements = array.data; 1.204 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after append"); 1.205 + elements = array->data; 1.206 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after append"); 1.207 UCX_TEST_ASSERT(elements[1] == 13, "failed"); 1.208 UCX_TEST_ASSERT(elements[2] == 37, "failed"); 1.209 UCX_TEST_ASSERT(elements[0] == 42, 1.210 @@ -191,24 +192,24 @@ 1.211 1.212 UCX_TEST_END 1.213 1.214 - ucx_array_destroy(&array); 1.215 + ucx_array_destroy(array); 1.216 } 1.217 1.218 UCX_TEST(test_ucx_array_prepend) { 1.219 int *elems; 1.220 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.221 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.222 1.223 - ucx_array_prepend(&array, 42); 1.224 + ucx_array_prepend(array, 42); 1.225 UCX_TEST_BEGIN 1.226 1.227 - elems = array.data; 1.228 + elems = array->data; 1.229 UCX_TEST_ASSERT(elems[0] == 42, "failed"); 1.230 1.231 - ucx_array_prepend(&array, 37); 1.232 - ucx_array_prepend(&array, 13); 1.233 + ucx_array_prepend(array, 37); 1.234 + ucx_array_prepend(array, 13); 1.235 1.236 - elems = array.data; 1.237 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after prepend"); 1.238 + elems = array->data; 1.239 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend"); 1.240 UCX_TEST_ASSERT(elems[0] == 13, "failed"); 1.241 UCX_TEST_ASSERT(elems[1] == 37, "failed"); 1.242 UCX_TEST_ASSERT(elems[2] == 42, 1.243 @@ -216,68 +217,68 @@ 1.244 1.245 UCX_TEST_END 1.246 1.247 - ucx_array_destroy(&array); 1.248 + ucx_array_free(array); 1.249 } 1.250 1.251 UCX_TEST(test_ucx_array_set) { 1.252 int *elems; 1.253 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.254 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.255 1.256 UCX_TEST_BEGIN 1.257 1.258 - ucx_array_set(&array, 7, 42); 1.259 + ucx_array_set(array, 7, 42); 1.260 1.261 - elems = array.data; 1.262 + elems = array->data; 1.263 UCX_TEST_ASSERT(elems[7] == 42, "failed"); 1.264 - UCX_TEST_ASSERT(array.size == 8, "array not resized on set"); 1.265 - UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily"); 1.266 + UCX_TEST_ASSERT(array->size == 8, "array not resized on set"); 1.267 + UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily"); 1.268 1.269 - ucx_array_set(&array, 27, 13); 1.270 - ucx_array_set(&array, 28, 37); 1.271 + ucx_array_set(array, 27, 13); 1.272 + ucx_array_set(array, 28, 37); 1.273 1.274 - elems = array.data; 1.275 + elems = array->data; 1.276 UCX_TEST_ASSERT(elems[27] == 13, "failed"); 1.277 UCX_TEST_ASSERT(elems[28] == 37, "failed"); 1.278 - UCX_TEST_ASSERT(array.size == 29, "array not resized on set"); 1.279 - UCX_TEST_ASSERT(array.capacity == 32, "capacity not grown"); 1.280 + UCX_TEST_ASSERT(array->size == 29, "array not resized on set"); 1.281 + UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown"); 1.282 1.283 UCX_TEST_END 1.284 1.285 - ucx_array_destroy(&array); 1.286 + ucx_array_free(array); 1.287 } 1.288 1.289 UCX_TEST(test_ucx_array_equals) { 1.290 - UcxArray a1 = ucx_array_new(16, sizeof(int32_t)); 1.291 - UcxArray a2 = ucx_array_new(16, sizeof(int32_t)); 1.292 - UcxArray a3 = ucx_array_new(16, sizeof(int64_t)); 1.293 - UcxArray a4 = ucx_array_new(16, sizeof(int32_t)); 1.294 + UcxArray *a1 = ucx_array_new(16, sizeof(int32_t)); 1.295 + UcxArray *a2 = ucx_array_new(16, sizeof(int32_t)); 1.296 + UcxArray *a3 = ucx_array_new(16, sizeof(int64_t)); 1.297 + UcxArray *a4 = ucx_array_new(16, sizeof(int32_t)); 1.298 1.299 int32_t *intelems; 1.300 int64_t *longintelems; 1.301 1.302 - a1.size = 5; 1.303 - intelems = a1.data; 1.304 + a1->size = 5; 1.305 + intelems = a1->data; 1.306 intelems[0] = 47; 1.307 intelems[1] = 11; 1.308 intelems[2] = 0; 1.309 intelems[3] = 8; 1.310 intelems[4] = 15; 1.311 - a2.size = 5; 1.312 - intelems = a2.data; 1.313 + a2->size = 5; 1.314 + intelems = a2->data; 1.315 intelems[0] = 47; 1.316 intelems[1] = 11; 1.317 intelems[2] = 0; 1.318 intelems[3] = 8; 1.319 intelems[4] = 15; 1.320 - a3.size = 5; 1.321 - longintelems = a3.data; 1.322 + a3->size = 5; 1.323 + longintelems = a3->data; 1.324 longintelems[0] = 47; 1.325 longintelems[1] = 11; 1.326 longintelems[2] = 0; 1.327 longintelems[3] = 8; 1.328 longintelems[4] = 15; 1.329 - a4.size = 5; 1.330 - intelems = a4.data; 1.331 + a4->size = 5; 1.332 + intelems = a4->data; 1.333 intelems[0] = 47; 1.334 intelems[1] = 11; 1.335 intelems[2] = -6; 1.336 @@ -300,54 +301,54 @@ 1.337 "compare using memcmp() failed"); 1.338 1.339 UCX_TEST_END 1.340 - ucx_array_destroy(&a1); 1.341 - ucx_array_destroy(&a2); 1.342 - ucx_array_destroy(&a3); 1.343 - ucx_array_destroy(&a4); 1.344 + ucx_array_free(a1); 1.345 + ucx_array_free(a2); 1.346 + ucx_array_free(a3); 1.347 + ucx_array_free(a4); 1.348 } 1.349 1.350 UCX_TEST(test_ucx_array_concat) { 1.351 - UcxArray a1 = ucx_array_new(16, sizeof(int)); 1.352 - UcxArray a2 = ucx_array_new(16, sizeof(int)); 1.353 + UcxArray *a1 = ucx_array_new(16, sizeof(int)); 1.354 + UcxArray *a2 = ucx_array_new(16, sizeof(int)); 1.355 int *elems; 1.356 1.357 - a1.size = 2; 1.358 - elems = a1.data; 1.359 + a1->size = 2; 1.360 + elems = a1->data; 1.361 elems[0] = 47; 1.362 elems[1] = 11; 1.363 - a2.size = 3; 1.364 - elems = a2.data; 1.365 + a2->size = 3; 1.366 + elems = a2->data; 1.367 elems[0] = 0; 1.368 elems[1] = 8; 1.369 elems[2] = 15; 1.370 1.371 UCX_TEST_BEGIN 1.372 1.373 - UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed"); 1.374 - UCX_TEST_ASSERT(a1.size == 5, "failed"); 1.375 - elems = a1.data; 1.376 + UCX_TEST_ASSERT(!ucx_array_concat(a1, a2), "failed"); 1.377 + UCX_TEST_ASSERT(a1->size == 5, "failed"); 1.378 + elems = a1->data; 1.379 UCX_TEST_ASSERT(elems[0] == 47, "failed"); 1.380 UCX_TEST_ASSERT(elems[1] == 11, "failed"); 1.381 UCX_TEST_ASSERT(elems[2] == 0, "failed"); 1.382 UCX_TEST_ASSERT(elems[3] == 8, "failed"); 1.383 UCX_TEST_ASSERT(elems[4] == 15, "failed"); 1.384 1.385 - a1.elemsize *= 2; 1.386 - UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2), 1.387 + a1->elemsize *= 2; 1.388 + UCX_TEST_ASSERT(ucx_array_concat(a1, a2), 1.389 "arrays of different element size must not be concatenated"); 1.390 - UCX_TEST_ASSERT(a1.size == 5, 1.391 + UCX_TEST_ASSERT(a1->size == 5, 1.392 "arrays of different element size must not be concatenated"); 1.393 1.394 UCX_TEST_END 1.395 - ucx_array_destroy(&a1); 1.396 - ucx_array_destroy(&a2); 1.397 + ucx_array_free(a1); 1.398 + ucx_array_free(a2); 1.399 } 1.400 1.401 UCX_TEST(test_ucx_array_at) { 1.402 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.403 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.404 1.405 int x[3] = {42, 13, 5}; 1.406 - ucx_array_append_from(&array, x, 3); 1.407 + ucx_array_append_from(array, x, 3); 1.408 1.409 UCX_TEST_BEGIN 1.410 1.411 @@ -360,15 +361,15 @@ 1.412 1.413 UCX_TEST_END 1.414 1.415 - ucx_array_destroy(&array); 1.416 + ucx_array_free(array); 1.417 } 1.418 1.419 UCX_TEST(test_ucx_array_find) { 1.420 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.421 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.422 int *elems; 1.423 1.424 - array.size = 5; 1.425 - elems = array.data; 1.426 + array->size = 5; 1.427 + elems = array->data; 1.428 elems[0] = 47; 1.429 elems[1] = 11; 1.430 elems[2] = 0; 1.431 @@ -391,15 +392,15 @@ 1.432 "failed using memcmp()"); 1.433 1.434 UCX_TEST_END 1.435 - ucx_array_destroy(&array); 1.436 + ucx_array_free(array); 1.437 } 1.438 1.439 UCX_TEST(test_ucx_array_contains) { 1.440 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.441 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.442 int *elems; 1.443 1.444 - array.size = 5; 1.445 - elems = array.data; 1.446 + array->size = 5; 1.447 + elems = array->data; 1.448 elems[0] = 47; 1.449 elems[1] = 11; 1.450 elems[2] = 0; 1.451 @@ -422,15 +423,15 @@ 1.452 "false positive using memcmp()"); 1.453 1.454 UCX_TEST_END 1.455 - ucx_array_destroy(&array); 1.456 + ucx_array_free(array); 1.457 } 1.458 1.459 UCX_TEST(test_ucx_array_remove) { 1.460 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.461 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.462 int *elems; 1.463 1.464 - array.size = 5; 1.465 - elems = array.data; 1.466 + array->size = 5; 1.467 + elems = array->data; 1.468 elems[0] = 47; 1.469 elems[1] = 11; 1.470 elems[2] = 0; 1.471 @@ -439,31 +440,33 @@ 1.472 1.473 UCX_TEST_BEGIN 1.474 1.475 - ucx_array_remove(&array, 2); 1.476 - elems = array.data; 1.477 + ucx_array_remove(array, 2); 1.478 + elems = array->data; 1.479 UCX_TEST_ASSERT( 1.480 elems[0] == 47 && 1.481 elems[1] == 11 && 1.482 elems[2] == 8 && 1.483 elems[3] == 15, 1.484 "wrong contents after remove"); 1.485 - UCX_TEST_ASSERT(array.size == 4, "wrong size after remove"); 1.486 + UCX_TEST_ASSERT(array->size == 4, "wrong size after remove"); 1.487 1.488 - ucx_array_remove_fast(&array, 1); 1.489 - elems = array.data; 1.490 + ucx_array_remove_fast(array, 1); 1.491 + elems = array->data; 1.492 UCX_TEST_ASSERT( 1.493 elems[0] == 47 && 1.494 elems[1] == 15 && 1.495 elems[2] == 8, 1.496 "wrong contents after fast remove"); 1.497 - UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove"); 1.498 + UCX_TEST_ASSERT(array->size == 3, "wrong size after fast remove"); 1.499 1.500 UCX_TEST_END 1.501 - ucx_array_destroy(&array); 1.502 + ucx_array_free(array); 1.503 } 1.504 1.505 UCX_TEST(test_ucx_array_clone) { 1.506 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.507 + UcxArray array; 1.508 + UcxArray copy; 1.509 + ucx_array_init(&array, 16, sizeof(int)); 1.510 int *elems; 1.511 1.512 array.size = 5; 1.513 @@ -474,7 +477,7 @@ 1.514 elems[3] = 8; 1.515 elems[4] = 15; 1.516 1.517 - UcxArray copy = ucx_array_clone(array); 1.518 + ucx_array_clone(©, &array); 1.519 UCX_TEST_BEGIN 1.520 1.521 UCX_TEST_ASSERT(array.data != copy.data, "no true copy"); 1.522 @@ -482,7 +485,8 @@ 1.523 UCX_TEST_ASSERT(array.capacity == copy.capacity, "capacity mismatch"); 1.524 UCX_TEST_ASSERT(array.elemsize == copy.elemsize, "element size mismatch"); 1.525 UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch"); 1.526 - UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed"); 1.527 + UCX_TEST_ASSERT(ucx_array_equals(&array, ©, ucx_cmp_int, NULL), 1.528 + "contents do not match after clone"); 1.529 1.530 UCX_TEST_END 1.531 1.532 @@ -497,27 +501,27 @@ 1.533 UCX_TEST(test_ucx_array_sort) { 1.534 int *elems; 1.535 1.536 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.537 - array.size = 5; 1.538 - elems = array.data; 1.539 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.540 + array->size = 5; 1.541 + elems = array->data; 1.542 elems[0] = 47; 1.543 elems[1] = 11; 1.544 elems[2] = 0; 1.545 elems[3] = 8; 1.546 elems[4] = 15; 1.547 1.548 - UcxArray expected = ucx_array_new(16, sizeof(int)); 1.549 - expected.size = 5; 1.550 - elems = expected.data; 1.551 + UcxArray *expected = ucx_array_new(16, sizeof(int)); 1.552 + expected->size = 5; 1.553 + elems = expected->data; 1.554 elems[0] = 0; 1.555 elems[1] = 8; 1.556 elems[2] = 11; 1.557 elems[3] = 15; 1.558 elems[4] = 47; 1.559 1.560 - UcxArray expectedrev = ucx_array_new(16, sizeof(int)); 1.561 - expectedrev.size = 5; 1.562 - elems = expectedrev.data; 1.563 + UcxArray *expectedrev = ucx_array_new(16, sizeof(int)); 1.564 + expectedrev->size = 5; 1.565 + elems = expectedrev->data; 1.566 elems[0] = 47; 1.567 elems[1] = 15; 1.568 elems[2] = 11; 1.569 @@ -526,101 +530,102 @@ 1.570 1.571 1.572 UCX_TEST_BEGIN 1.573 - void* original_ptr = array.data; 1.574 + void* original_ptr = array->data; 1.575 ucx_array_sort(array, ucx_cmp_int, NULL); 1.576 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed"); 1.577 - UCX_TEST_ASSERT(array.size == 5, "size corrupted"); 1.578 - UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate"); 1.579 + UCX_TEST_ASSERT(array->size == 5, "size corrupted"); 1.580 + UCX_TEST_ASSERT(array->data == original_ptr, "shall not reallocate"); 1.581 1.582 ucx_array_sort(array, ucx_cmp_int_reverse, NULL); 1.583 UCX_TEST_ASSERT(ucx_array_equals(array, expectedrev, NULL, NULL), "failed"); 1.584 1.585 - ucx_array_reserve(&array, 32); 1.586 - ucx_array_reserve(&expected, 32); 1.587 - array.size = expected.size = 32; 1.588 + ucx_array_reserve(array, 32); 1.589 + ucx_array_reserve(expected, 32); 1.590 + array->size = expected->size = 32; 1.591 for (size_t i = 0 ; i < 32 ; i++) { 1.592 - ((int*)array.data)[i]= ((i%2==0)?-1:1) * ((int) i); 1.593 - ((int*)expected.data)[i] = (-30+2*i) - (i > 15 ? 1 : 0); 1.594 + ((int*)array->data)[i]= ((i%2==0)?-1:1) * ((int) i); 1.595 + ((int*)expected->data)[i] = (-30+2*i) - (i > 15 ? 1 : 0); 1.596 } 1.597 1.598 /* dummy third argument to trigger a possible fallback for qsort_s */ 1.599 - ucx_array_sort(array, ucx_cmp_int, array.data); 1.600 + ucx_array_sort(array, ucx_cmp_int, array->data); 1.601 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), 1.602 "failed for bigger arrays"); 1.603 UCX_TEST_END 1.604 1.605 - ucx_array_destroy(&expected); 1.606 - ucx_array_destroy(&array); 1.607 + ucx_array_free(expectedrev); 1.608 + ucx_array_free(expected); 1.609 + ucx_array_free(array); 1.610 } 1.611 1.612 UCX_TEST(test_ucx_array_autogrow) { 1.613 int *elems; 1.614 - UcxArray array = ucx_array_new(4, sizeof(int)); 1.615 - array.size = 3; 1.616 - elems = array.data; 1.617 + UcxArray *array = ucx_array_new(4, sizeof(int)); 1.618 + array->size = 3; 1.619 + elems = array->data; 1.620 elems[0] = 47; 1.621 elems[1] = 11; 1.622 int x = 5; 1.623 1.624 UCX_TEST_BEGIN 1.625 1.626 - void* oldptr = array.data; 1.627 + void* oldptr = array->data; 1.628 1.629 - ucx_array_append(&array, 5); 1.630 - UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr, 1.631 + ucx_array_append(array, 5); 1.632 + UCX_TEST_ASSERT(array->capacity == 4 && array->data == oldptr, 1.633 "array should not grow too early"); 1.634 - ucx_array_append(&array, 5); 1.635 - elems = array.data; 1.636 - UCX_TEST_ASSERT(array.capacity == 8, "array did not grow"); 1.637 - UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow"); 1.638 + ucx_array_append(array, 5); 1.639 + elems = array->data; 1.640 + UCX_TEST_ASSERT(array->capacity == 8, "array did not grow"); 1.641 + UCX_TEST_ASSERT(array->size == 5, "incorrect size after grow"); 1.642 UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data"); 1.643 1.644 UCX_TEST_END 1.645 - ucx_array_destroy(&array); 1.646 + ucx_array_free(array); 1.647 } 1.648 1.649 UCX_TEST(test_ucx_array_shrink) { 1.650 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.651 - array.size = 4; 1.652 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.653 + array->size = 4; 1.654 1.655 UCX_TEST_BEGIN 1.656 - UCX_TEST_ASSERT(!ucx_array_shrink(&array), "failed"); 1.657 - UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after shrink"); 1.658 + UCX_TEST_ASSERT(!ucx_array_shrink(array), "failed"); 1.659 + UCX_TEST_ASSERT(array->capacity == 4, "incorrect capacity after shrink"); 1.660 UCX_TEST_END 1.661 - ucx_array_destroy(&array); 1.662 + ucx_array_free(array); 1.663 } 1.664 1.665 UCX_TEST(test_ucx_array_resize) { 1.666 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.667 - array.size = 8; 1.668 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.669 + array->size = 8; 1.670 1.671 UCX_TEST_BEGIN 1.672 1.673 - UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed"); 1.674 - UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after resize"); 1.675 - UCX_TEST_ASSERT(array.size == 8, "incorrect size after resize"); 1.676 + UCX_TEST_ASSERT(!ucx_array_resize(array, 32), "failed"); 1.677 + UCX_TEST_ASSERT(array->capacity == 32, "incorrect capacity after resize"); 1.678 + UCX_TEST_ASSERT(array->size == 8, "incorrect size after resize"); 1.679 1.680 - UCX_TEST_ASSERT(!ucx_array_resize(&array, 4), "failed"); 1.681 - UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after resize"); 1.682 - UCX_TEST_ASSERT(array.size == 4, "incorrect size after resize"); 1.683 + UCX_TEST_ASSERT(!ucx_array_resize(array, 4), "failed"); 1.684 + UCX_TEST_ASSERT(array->capacity == 4, "incorrect capacity after resize"); 1.685 + UCX_TEST_ASSERT(array->size == 4, "incorrect size after resize"); 1.686 1.687 UCX_TEST_END 1.688 - ucx_array_destroy(&array); 1.689 + ucx_array_free(array); 1.690 } 1.691 1.692 UCX_TEST(test_ucx_array_reserve) { 1.693 - UcxArray array = ucx_array_new(16, sizeof(int)); 1.694 + UcxArray *array = ucx_array_new(16, sizeof(int)); 1.695 1.696 UCX_TEST_BEGIN 1.697 1.698 - UCX_TEST_ASSERT(!ucx_array_reserve(&array, 4), "failed"); 1.699 - UCX_TEST_ASSERT(array.capacity == 16, "reserve shall not shrink"); 1.700 + UCX_TEST_ASSERT(!ucx_array_reserve(array, 4), "failed"); 1.701 + UCX_TEST_ASSERT(array->capacity == 16, "reserve shall not shrink"); 1.702 1.703 - UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed"); 1.704 - UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after reserve"); 1.705 + UCX_TEST_ASSERT(!ucx_array_resize(array, 32), "failed"); 1.706 + UCX_TEST_ASSERT(array->capacity == 32, "incorrect capacity after reserve"); 1.707 1.708 UCX_TEST_END 1.709 - ucx_array_destroy(&array); 1.710 + ucx_array_free(array); 1.711 } 1.712 1.713 UCX_TEST(test_ucx_array_util_set) {