rename in tests
authorNiki Roo <niki@nikiroo.be>
Tue, 25 Jun 2024 18:09:57 +0000 (20:09 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 25 Jun 2024 18:09:57 +0000 (20:09 +0200)
src/tests/cstring-test.c [new file with mode: 0644]
src/tests/cstring.c [deleted file]

diff --git a/src/tests/cstring-test.c b/src/tests/cstring-test.c
new file mode 100644 (file)
index 0000000..e7cdc1b
--- /dev/null
@@ -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 (file)
index 2a8f7e0..0000000
+++ /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;
-}
-