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 |
1.1 --- a/test/array_tests.c Sun Nov 03 17:03:10 2019 +0100 1.2 +++ b/test/array_tests.c Wed Nov 06 16:27:54 2019 +0100 1.3 @@ -96,6 +96,48 @@ 1.4 ucx_array_free(array); 1.5 } 1.6 1.7 +UCX_TEST(test_ucx_array_append_from_struct) { 1.8 + struct teststruct { 1.9 + unsigned long long x; 1.10 + unsigned long long y; 1.11 + unsigned long long z; 1.12 + }; 1.13 + 1.14 + UcxArray *array = ucx_array_new(16, sizeof(struct teststruct)); 1.15 + struct teststruct *elements; 1.16 + 1.17 + struct teststruct data; 1.18 + data.x = 13; data.y = 37; data.z = 47; 1.19 + 1.20 + ucx_array_append_from(array, &data, 1); 1.21 + UCX_TEST_BEGIN 1.22 + 1.23 + elements = array->data; 1.24 + UCX_TEST_ASSERT(elements[0].x == 13, "failed"); 1.25 + UCX_TEST_ASSERT(elements[0].y == 37, "failed"); 1.26 + UCX_TEST_ASSERT(elements[0].z == 47, "failed"); 1.27 + 1.28 + data.x = 0; data.y = 8; data.z = 15; 1.29 + ucx_array_append_from(array, &data, 1); 1.30 + 1.31 + elements = array->data; 1.32 + UCX_TEST_ASSERT(array->size == 2, "incorrect size after append"); 1.33 + UCX_TEST_ASSERT(elements[1].x == 0, "failed"); 1.34 + UCX_TEST_ASSERT(elements[1].y == 8, "failed"); 1.35 + UCX_TEST_ASSERT(elements[1].z == 15, "failed"); 1.36 + 1.37 + UCX_TEST_ASSERT(elements[0].x == 13, 1.38 + "append corrupted previously inserted data"); 1.39 + UCX_TEST_ASSERT(elements[0].y == 37, 1.40 + "append corrupted previously inserted data"); 1.41 + UCX_TEST_ASSERT(elements[0].z == 47, 1.42 + "append corrupted previously inserted data"); 1.43 + 1.44 + UCX_TEST_END 1.45 + 1.46 + ucx_array_destroy(array); 1.47 +} 1.48 + 1.49 UCX_TEST(test_ucx_array_prepend_from) { 1.50 int *elems; 1.51 UcxArray *array = ucx_array_new(16, sizeof(int)); 1.52 @@ -195,6 +237,48 @@ 1.53 ucx_array_destroy(array); 1.54 } 1.55 1.56 +UCX_TEST(test_ucx_array_append_struct) { 1.57 + struct teststruct { 1.58 + unsigned long long x; 1.59 + unsigned long long y; 1.60 + unsigned long long z; 1.61 + }; 1.62 + 1.63 + UcxArray *array = ucx_array_new(16, sizeof(struct teststruct)); 1.64 + struct teststruct *elements; 1.65 + 1.66 + struct teststruct data; 1.67 + data.x = 13; data.y = 37; data.z = 47; 1.68 + 1.69 + ucx_array_append(array, data); 1.70 + UCX_TEST_BEGIN 1.71 + 1.72 + elements = array->data; 1.73 + UCX_TEST_ASSERT(elements[0].x == 13, "failed"); 1.74 + UCX_TEST_ASSERT(elements[0].y == 37, "failed"); 1.75 + UCX_TEST_ASSERT(elements[0].z == 47, "failed"); 1.76 + 1.77 + data.x = 0; data.y = 8; data.z = 15; 1.78 + ucx_array_append(array, data); 1.79 + 1.80 + elements = array->data; 1.81 + UCX_TEST_ASSERT(array->size == 2, "incorrect size after append"); 1.82 + UCX_TEST_ASSERT(elements[1].x == 0, "failed"); 1.83 + UCX_TEST_ASSERT(elements[1].y == 8, "failed"); 1.84 + UCX_TEST_ASSERT(elements[1].z == 15, "failed"); 1.85 + 1.86 + UCX_TEST_ASSERT(elements[0].x == 13, 1.87 + "append corrupted previously inserted data"); 1.88 + UCX_TEST_ASSERT(elements[0].y == 37, 1.89 + "append corrupted previously inserted data"); 1.90 + UCX_TEST_ASSERT(elements[0].z == 47, 1.91 + "append corrupted previously inserted data"); 1.92 + 1.93 + UCX_TEST_END 1.94 + 1.95 + ucx_array_destroy(array); 1.96 +} 1.97 + 1.98 UCX_TEST(test_ucx_array_prepend) { 1.99 int *elems; 1.100 UcxArray *array = ucx_array_new(16, sizeof(int));
2.1 --- a/test/array_tests.h Sun Nov 03 17:03:10 2019 +0100 2.2 +++ b/test/array_tests.h Wed Nov 06 16:27:54 2019 +0100 2.3 @@ -40,9 +40,11 @@ 2.4 UCX_TEST(test_ucx_array_new); 2.5 UCX_TEST(test_ucx_array_at); 2.6 UCX_TEST(test_ucx_array_append_from); 2.7 +UCX_TEST(test_ucx_array_append_from_struct); 2.8 UCX_TEST(test_ucx_array_prepend_from); 2.9 UCX_TEST(test_ucx_array_set_from); 2.10 UCX_TEST(test_ucx_array_append); 2.11 +UCX_TEST(test_ucx_array_append_struct); 2.12 UCX_TEST(test_ucx_array_prepend); 2.13 UCX_TEST(test_ucx_array_set); 2.14 UCX_TEST(test_ucx_array_autogrow);
3.1 --- a/test/main.c Sun Nov 03 17:03:10 2019 +0100 3.2 +++ b/test/main.c Wed Nov 06 16:27:54 2019 +0100 3.3 @@ -148,9 +148,11 @@ 3.4 ucx_test_register(suite, test_ucx_array_new); 3.5 ucx_test_register(suite, test_ucx_array_at); 3.6 ucx_test_register(suite, test_ucx_array_append_from); 3.7 + ucx_test_register(suite, test_ucx_array_append_from_struct); 3.8 ucx_test_register(suite, test_ucx_array_prepend_from); 3.9 ucx_test_register(suite, test_ucx_array_set_from); 3.10 ucx_test_register(suite, test_ucx_array_append); 3.11 + ucx_test_register(suite, test_ucx_array_append_struct); 3.12 ucx_test_register(suite, test_ucx_array_prepend); 3.13 ucx_test_register(suite, test_ucx_array_set); 3.14 ucx_test_register(suite, test_ucx_array_autogrow);