Code

strbuf_test: Added tests for sdb_strbuf_clear().
authorSebastian Harl <sh@tokkee.org>
Fri, 13 Dec 2013 13:57:40 +0000 (14:57 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 13 Dec 2013 13:57:40 +0000 (14:57 +0100)
t/utils/strbuf_test.c

index 749d5821622a0189e4fa8130d38b671a6f9958b4..0acb1de0521849d6533a347fd8a8858a106ce72b 100644 (file)
@@ -447,6 +447,27 @@ START_TEST(test_sdb_strbuf_skip)
 }
 END_TEST
 
+START_TEST(test_sdb_strbuf_clear)
+{
+       const char *data;
+       size_t len;
+
+       sdb_strbuf_append(buf, "abc");
+       len = sdb_strbuf_len(buf);
+       fail_unless(len != 0,
+                       "sdb_strbuf_len() = %zu; expected: != 0", len);
+
+       sdb_strbuf_clear(buf);
+       len = sdb_strbuf_len(buf);
+       fail_unless(len == 0,
+                       "sdb_strbuf_len() = %zu (after clear); expected: 0", len);
+
+       data = sdb_strbuf_string(buf);
+       fail_unless(*data == '\0',
+                       "sdb_strbuf_string() = '%s' (after clear); expected: ''", data);
+}
+END_TEST
+
 static struct {
        const char *input;
        const char *expected;
@@ -520,6 +541,7 @@ util_strbuf_suite(void)
        tcase_add_test(tc, test_sdb_strbuf_memappend);
        tcase_add_test(tc, test_sdb_strbuf_chomp);
        tcase_add_test(tc, test_sdb_strbuf_skip);
+       tcase_add_test(tc, test_sdb_strbuf_clear);
        tcase_add_test(tc, test_sdb_strbuf_string);
        tcase_add_test(tc, test_sdb_strbuf_len);
        suite_add_tcase(s, tc);