From ad023bb09d8ea910410507e953510ee5434bd30f Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 13 Apr 2023 23:27:01 +0200 Subject: [PATCH] Improve coverage of the test suite --- tests/test-mprioqueue.c | 22 ++++++++++++++++++++++ tests/test-mstring.c | 10 ++++++++++ tests/test-mtree.c | 18 +++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/test-mprioqueue.c b/tests/test-mprioqueue.c index 0e9c797a..93805cd6 100644 --- a/tests/test-mprioqueue.c +++ b/tests/test-mprioqueue.c @@ -374,6 +374,27 @@ static void test_io(void) string_clear(str); } +// Test of internal functions, used only for reaching 100% coverage +static void test_coverage(void) +{ + int_pqueue_array_t a, b; + int_pqueue_array_init(a); + int_pqueue_array_init(b); + int_pqueue_array_push_back(a, 12); + int_pqueue_array_push_back(b, 12); + int_pqueue_array_push_back(b, 12); + int_pqueue_array_set(a,b); + int_pqueue_array_clear(a); + int_pqueue_array_clear(b); + + int_pqueue_array_init(a); + int_pqueue_array_init(b); + int_pqueue_array_push_back(a, 12); + int_pqueue_array_set(a,b); + int_pqueue_array_clear(a); + int_pqueue_array_clear(b); +} + int main(void) { test1(); @@ -382,6 +403,7 @@ int main(void) test_double(); test_it(); test_io(); + test_coverage(); testobj_final_check(); exit(0); } diff --git a/tests/test-mstring.c b/tests/test-mstring.c index 2d335d13..9ed8cfec 100644 --- a/tests/test-mstring.c +++ b/tests/test-mstring.c @@ -276,6 +276,16 @@ static void test0(void) string_replace_all(s1, s1, s2); assert( string_equal_str_p(s1, "WORLD")); + string_set_str(s1, "HE"); + string_set_str(s2, "SHE"); + string_replace_all(s1, s1, s2); + assert( string_equal_str_p(s1, "SHE")); + + string_set_str(s1, "SHE"); + string_set_str(s2, "HE"); + string_replace_all(s1, s1, s2); + assert( string_equal_str_p(s1, "HE")); + string_printf (s1, ""); assert (string_cmp_str (s1, "") == 0); assert (string_size (s1) == 0); diff --git a/tests/test-mtree.c b/tests/test-mtree.c index 4af48f3b..367b28d0 100644 --- a/tests/test-mtree.c +++ b/tests/test-mtree.c @@ -490,13 +490,29 @@ static void test_io(void) assert(b); assert(*sp == 0); assert(tree_equal_p(t1, t2)); + + string_set_str(s, "[{1,[{0,[{1,[{3},{5,[{2}]},{4,[{9},{7,[{8}]},{0},{6}]}]}]}]}]"); + for(size_t i = 0; i < string_size(s); i++) { + string_set_str(s, "[{1,[{0,[{1,[{3},{5,[{2}]},{4,[{9},{7,[{8}]},{0},{6}]}]}]}]}]"); + string_replace_at(s, i, 1, ""); + b = tree_parse_str(t2, string_get_cstr(s), &sp); + assert(!b); + f = m_core_fopen ("a-mtree.dat", "wt"); + if (!f) abort(); + fprintf(f, "%s", string_get_cstr(s)); + fclose (f); + f = m_core_fopen ("a-mtree.dat", "rt"); + if (!f) abort(); + b = tree_in_str (t2, f); + assert(!b); + fclose(f); + } } f = m_core_fopen ("a-mtree.dat", "wt"); if (!f) abort(); tree_out_str(f, t1); fclose (f); - f = m_core_fopen ("a-mtree.dat", "rt"); if (!f) abort(); b = tree_in_str (t2, f);