From: Sebastian Harl Date: Thu, 31 Oct 2013 18:09:05 +0000 (+0100) Subject: strbuf_test: Added some NULL tests. X-Git-Tag: sysdb-0.1.0~336^2~20 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=17e0c267962be6f91ca0847e9f5feefc8b2d4907;p=sysdb.git strbuf_test: Added some NULL tests. These are mainly to check that the functions do no segfault but report an error. --- diff --git a/t/utils/strbuf_test.c b/t/utils/strbuf_test.c index 3b88b58..9e96b98 100644 --- a/t/utils/strbuf_test.c +++ b/t/utils/strbuf_test.c @@ -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);