Code

strbuf_test: Added some NULL tests.
authorSebastian Harl <sh@tokkee.org>
Thu, 31 Oct 2013 18:09:05 +0000 (19:09 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 31 Oct 2013 18:09:05 +0000 (19:09 +0100)
These are mainly to check that the functions do no segfault but report an
error.

t/utils/strbuf_test.c

index 3b88b5844e1e8c3904afe1ef6c8f0e98a453f562..9e96b984a2a764d5d322fc60e1065e2ee9cb2b6b 100644 (file)
@@ -55,6 +55,36 @@ teardown(void)
  * tests
  */
 
+START_TEST(test_empty)
+{
+       sdb_strbuf_t *b = NULL;
+       va_list ap;
+
+       /* check that methods don't crash */
+       sdb_strbuf_destroy(b);
+       sdb_strbuf_skip(b, 0);
+       sdb_strbuf_skip(b, 10);
+
+       /* check that methods return an error */
+       fail_unless(sdb_strbuf_vappend(b, "test", ap) < 0,
+                       "sdb_strbuf_vappend(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_append(b, "test") < 0,
+                       "sdb_strbuf_append(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_vsprintf(b, "test", ap) < 0,
+                       "sdb_strbuf_vsprintf(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_sprintf(b, "test") < 0,
+                       "sdb_strbuf_sprintf(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_memcpy(b, "test", 4) < 0,
+                       "sdb_strbuf_memcpy(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_memappend(b, "test", 4) < 0,
+                       "sdb_strbuf_memappend(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_read(b, 0, 32) < 0,
+                       "sdb_strbuf_read(NULL) didn't report failure");
+       fail_unless(sdb_strbuf_chomp(b) < 0,
+                       "sdb_strbuf_chomp(NULL) didn't report failure");
+}
+END_TEST
+
 START_TEST(test_sdb_strbuf_create)
 {
        sdb_strbuf_t *s;
@@ -409,6 +439,10 @@ util_strbuf_suite(void)
        Suite *s = suite_create("utils::strbuf");
        TCase *tc;
 
+       tc = tcase_create("empty");
+       tcase_add_test(tc, test_empty);
+       suite_add_tcase(s, tc);
+
        tc = tcase_create("core");
        tcase_add_checked_fixture(tc, setup, teardown);
        tcase_add_test(tc, test_sdb_strbuf_create);