Code

strbuf_test: Added a couple of tests operating on a zero-size buffer.
authorSebastian Harl <sh@tokkee.org>
Fri, 13 Dec 2013 13:53:02 +0000 (14:53 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 13 Dec 2013 13:53:02 +0000 (14:53 +0100)
This is mostly about checking that this does not crash.

t/utils/strbuf_test.c

index c68a23efcf22df1157d2ac4adb02ceaf5f3b7f38..749d5821622a0189e4fa8130d38b671a6f9958b4 100644 (file)
@@ -55,7 +55,7 @@ teardown(void)
  * tests
  */
 
-START_TEST(test_empty)
+START_TEST(test_null)
 {
        sdb_strbuf_t *b = NULL;
        va_list ap;
@@ -65,6 +65,7 @@ START_TEST(test_empty)
        sdb_strbuf_skip(b, 0, 0);
        sdb_strbuf_skip(b, 0, 10);
        sdb_strbuf_skip(b, 10, 10);
+       sdb_strbuf_clear(b);
 
        /* check that methods return an error */
        fail_unless(sdb_strbuf_vappend(b, "test", ap) < 0,
@@ -86,6 +87,28 @@ START_TEST(test_empty)
 }
 END_TEST
 
+START_TEST(test_empty)
+{
+       sdb_strbuf_t *b = sdb_strbuf_create(0);
+       const char *data;
+       size_t len;
+
+       /* check that methods don't crash */
+       sdb_strbuf_skip(b, 1, 1);
+       sdb_strbuf_clear(b);
+       sdb_strbuf_chomp(b);
+
+       data = sdb_strbuf_string(b);
+       fail_unless(data && (*data == '\0'),
+                       "sdb_strbuf_string(<empty>) = '%s'; expected: ''", data);
+       len = sdb_strbuf_len(b);
+       fail_unless(len == 0,
+                       "sdb_strbuf_len(<empty>) = %zu; expected: 0", len);
+
+       sdb_strbuf_destroy(b);
+}
+END_TEST
+
 START_TEST(test_sdb_strbuf_create)
 {
        sdb_strbuf_t *s;
@@ -483,6 +506,7 @@ util_strbuf_suite(void)
        TCase *tc;
 
        tc = tcase_create("empty");
+       tcase_add_test(tc, test_null);
        tcase_add_test(tc, test_empty);
        suite_add_tcase(s, tc);