From: Niki Roo Date: Tue, 25 Jun 2024 18:09:57 +0000 (+0200) Subject: rename in tests X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=f8e193e3e18de03f07f09b723c79282dbf7781a9;p=cutils.git rename in tests --- diff --git a/src/tests/cstring-test.c b/src/tests/cstring-test.c new file mode 100644 index 0000000..e7cdc1b --- /dev/null +++ b/src/tests/cstring-test.c @@ -0,0 +1,63 @@ +#include "cutils/check/launcher.h" +#include "cutils/cstring.h" +#include "cutils/timing.h" + +cstring_t *s; + +static const char str100[101] = + "12345678901234567890123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890" +; + +void t_cstring_setup() { + s = new_cstring(); +} + +void t_cstring_teardown() { + free_cstring(s); +} + +START(add) + cstring_add(s, "Basic"); + assert_str("Add text to new cstring", "Basic", s->string); + cstring_add(s, " check for spaces "); + assert_str("Add text to already used cstring", + "Basic check for spaces ", s->string); + cstring_add(s, ""); + assert_str("Check add of ampty string", + "Basic check for spaces ", s->string); +END + +START(add_mem) + // 10M: a memory leak would hopefully be strucked if any + for (size_t i = 0 ; i < 10000000 ; i++) { + cstring_clear(s); + cstring_add(s, str100); cstring_add(s, str100); + cstring_add(s, str100); cstring_add(s, str100); + cstring_add(s, str100); cstring_add(s, str100); + cstring_add(s, str100); cstring_add(s, str100); + cstring_add(s, str100); cstring_add(s, str100); + } +END + +Suite *test_cstring(int more) { + Suite *suite = suite_create("cstring"); + + TCase *init = tcase_create("core"); + tcase_add_checked_fixture(init, t_cstring_setup, t_cstring_teardown); + tcase_add_test(init, add); + + suite_add_tcase(suite, init); + + if (more) { + TCase *extra = tcase_create("extra"); + tcase_add_checked_fixture(extra, + t_cstring_setup, t_cstring_teardown); + tcase_add_test(init, add_mem); + + suite_add_tcase(suite, extra); + } + + return suite; +} + diff --git a/src/tests/cstring.c b/src/tests/cstring.c deleted file mode 100644 index 2a8f7e0..0000000 --- a/src/tests/cstring.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "cutils/check/launcher.h" -#include "cutils/cstring.h" - -cstring_t *s; - -void t_cstring_setup() { -} - -void t_cstring_teardown() { -} - -START(add) - if (0) - FAIL("Oopsie: %s", "why?!"); -END - -START(add_mem) - if (0) - FAIL("Oopsie: %s", "why?!"); -END - -Suite *test_cstring(int more) { - Suite *suite = suite_create("cstring"); - - TCase *init = tcase_create("core"); - tcase_add_checked_fixture(init, t_cstring_setup, t_cstring_teardown); - tcase_add_test(init, add); - - suite_add_tcase(suite, init); - - if (more) { - TCase *extra = tcase_create("extra"); - tcase_add_checked_fixture(extra, - t_cstring_setup, t_cstring_teardown); - tcase_add_test(init, add_mem); - - suite_add_tcase(suite, extra); - } - - return suite; -} -