From: Sebastian Harl Date: Fri, 13 Dec 2013 13:53:02 +0000 (+0100) Subject: strbuf_test: Added a couple of tests operating on a zero-size buffer. X-Git-Tag: sysdb-0.1.0~300^2~8 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ead57d6d05d4b9fbfe3b47089b65fb889354d870;p=sysdb.git strbuf_test: Added a couple of tests operating on a zero-size buffer. This is mostly about checking that this does not crash. --- diff --git a/t/utils/strbuf_test.c b/t/utils/strbuf_test.c index c68a23e..749d582 100644 --- a/t/utils/strbuf_test.c +++ b/t/utils/strbuf_test.c @@ -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() = '%s'; expected: ''", data); + len = sdb_strbuf_len(b); + fail_unless(len == 0, + "sdb_strbuf_len() = %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);