Wed, 06 Nov 2019 16:27:54 +0100
adds testcase to uncover a bug in ucx_array_append()
test/array_tests.c | file | annotate | diff | comparison | revisions | |
test/array_tests.h | file | annotate | diff | comparison | revisions | |
test/main.c | file | annotate | diff | comparison | revisions |
--- 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));
--- a/test/array_tests.h Sun Nov 03 17:03:10 2019 +0100 +++ b/test/array_tests.h Wed Nov 06 16:27:54 2019 +0100 @@ -40,9 +40,11 @@ UCX_TEST(test_ucx_array_new); UCX_TEST(test_ucx_array_at); UCX_TEST(test_ucx_array_append_from); +UCX_TEST(test_ucx_array_append_from_struct); UCX_TEST(test_ucx_array_prepend_from); UCX_TEST(test_ucx_array_set_from); UCX_TEST(test_ucx_array_append); +UCX_TEST(test_ucx_array_append_struct); UCX_TEST(test_ucx_array_prepend); UCX_TEST(test_ucx_array_set); UCX_TEST(test_ucx_array_autogrow);
--- a/test/main.c Sun Nov 03 17:03:10 2019 +0100 +++ b/test/main.c Wed Nov 06 16:27:54 2019 +0100 @@ -148,9 +148,11 @@ ucx_test_register(suite, test_ucx_array_new); ucx_test_register(suite, test_ucx_array_at); ucx_test_register(suite, test_ucx_array_append_from); + ucx_test_register(suite, test_ucx_array_append_from_struct); ucx_test_register(suite, test_ucx_array_prepend_from); ucx_test_register(suite, test_ucx_array_set_from); ucx_test_register(suite, test_ucx_array_append); + ucx_test_register(suite, test_ucx_array_append_struct); ucx_test_register(suite, test_ucx_array_prepend); ucx_test_register(suite, test_ucx_array_set); ucx_test_register(suite, test_ucx_array_autogrow);