Code

t/unit/: Create one test binary for each *_test.c file.
[sysdb.git] / t / unit / utils / strbuf_test.c
index e7cb9f5a6438cfb9ba1cc30ed90835ab5dbcaeb1..c15c1e9cb21a9b6821d8bfe8b57ed490ea320483 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
 #include "utils/strbuf.h"
-#include "libsysdb_test.h"
+#include "testutils.h"
 
 #include <check.h>
 
@@ -233,6 +237,9 @@ START_TEST(test_sprintf)
 
        size_t i;
 
+       sdb_strbuf_destroy(buf);
+       buf = sdb_strbuf_create(1); /* -> min_size = 1 */
+
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                n = sdb_strbuf_sprintf(buf, "%s", golden_data[i]);
                fail_unless((size_t)n == strlen(golden_data[i]),
@@ -251,7 +258,9 @@ START_TEST(test_sprintf)
                                "got: %s; expected: %s", test, golden_data[i]);
 
                check = sdb_strbuf_cap(buf);
-               if (n) /* 3 times the current len is the threshold for shrinking */
+               /* 3 times the current len is the threshold for shrinking,
+                * but it's capped to the initial size (or 64) */
+               if (n)
                        fail_unless(((size_t)n < check) && (check < (size_t)n * 3),
                                        "sdb_strbuf_sprintf() did not resize the buffer "
                                        "correctly (got size %zu; expected %zi < <size> < %d)",
@@ -608,16 +617,12 @@ START_TEST(test_len)
 }
 END_TEST
 
-Suite *
-util_strbuf_suite(void)
+TEST_MAIN("utils::strbuf")
 {
-       Suite *s = suite_create("utils::strbuf");
-       TCase *tc;
-
-       tc = tcase_create("empty");
+       TCase *tc = tcase_create("empty");
        tcase_add_test(tc, test_null);
        tcase_add_test(tc, test_empty);
-       suite_add_tcase(s, tc);
+       ADD_TCASE(tc);
 
        tc = tcase_create("core");
        tcase_add_checked_fixture(tc, setup, teardown);
@@ -632,10 +637,9 @@ util_strbuf_suite(void)
        tcase_add_test(tc, test_clear);
        tcase_add_test(tc, test_string);
        tcase_add_test(tc, test_len);
-       suite_add_tcase(s, tc);
-
-       return s;
-} /* util_strbuf_suite */
+       ADD_TCASE(tc);
+}
+TEST_MAIN_END
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */