diff -r 72da0e4cbf4a -r 41a7cef34c19 test/array_tests.c --- a/test/array_tests.c Sun Nov 03 17:03:10 2019 +0100 +++ b/test/array_tests.c Wed Nov 06 16:27:54 2019 +0100 @@ -96,6 +96,48 @@ ucx_array_free(array); } +UCX_TEST(test_ucx_array_append_from_struct) { + struct teststruct { + unsigned long long x; + unsigned long long y; + unsigned long long z; + }; + + UcxArray *array = ucx_array_new(16, sizeof(struct teststruct)); + struct teststruct *elements; + + struct teststruct data; + data.x = 13; data.y = 37; data.z = 47; + + ucx_array_append_from(array, &data, 1); + UCX_TEST_BEGIN + + elements = array->data; + UCX_TEST_ASSERT(elements[0].x == 13, "failed"); + UCX_TEST_ASSERT(elements[0].y == 37, "failed"); + UCX_TEST_ASSERT(elements[0].z == 47, "failed"); + + data.x = 0; data.y = 8; data.z = 15; + ucx_array_append_from(array, &data, 1); + + elements = array->data; + UCX_TEST_ASSERT(array->size == 2, "incorrect size after append"); + UCX_TEST_ASSERT(elements[1].x == 0, "failed"); + UCX_TEST_ASSERT(elements[1].y == 8, "failed"); + UCX_TEST_ASSERT(elements[1].z == 15, "failed"); + + UCX_TEST_ASSERT(elements[0].x == 13, + "append corrupted previously inserted data"); + UCX_TEST_ASSERT(elements[0].y == 37, + "append corrupted previously inserted data"); + UCX_TEST_ASSERT(elements[0].z == 47, + "append corrupted previously inserted data"); + + UCX_TEST_END + + ucx_array_destroy(array); +} + UCX_TEST(test_ucx_array_prepend_from) { int *elems; UcxArray *array = ucx_array_new(16, sizeof(int)); @@ -195,6 +237,48 @@ ucx_array_destroy(array); } +UCX_TEST(test_ucx_array_append_struct) { + struct teststruct { + unsigned long long x; + unsigned long long y; + unsigned long long z; + }; + + UcxArray *array = ucx_array_new(16, sizeof(struct teststruct)); + struct teststruct *elements; + + struct teststruct data; + data.x = 13; data.y = 37; data.z = 47; + + ucx_array_append(array, data); + UCX_TEST_BEGIN + + elements = array->data; + UCX_TEST_ASSERT(elements[0].x == 13, "failed"); + UCX_TEST_ASSERT(elements[0].y == 37, "failed"); + UCX_TEST_ASSERT(elements[0].z == 47, "failed"); + + data.x = 0; data.y = 8; data.z = 15; + ucx_array_append(array, data); + + elements = array->data; + UCX_TEST_ASSERT(array->size == 2, "incorrect size after append"); + UCX_TEST_ASSERT(elements[1].x == 0, "failed"); + UCX_TEST_ASSERT(elements[1].y == 8, "failed"); + UCX_TEST_ASSERT(elements[1].z == 15, "failed"); + + UCX_TEST_ASSERT(elements[0].x == 13, + "append corrupted previously inserted data"); + UCX_TEST_ASSERT(elements[0].y == 37, + "append corrupted previously inserted data"); + UCX_TEST_ASSERT(elements[0].z == 47, + "append corrupted previously inserted data"); + + UCX_TEST_END + + ucx_array_destroy(array); +} + UCX_TEST(test_ucx_array_prepend) { int *elems; UcxArray *array = ucx_array_new(16, sizeof(int));