From: Sebastian Harl Date: Thu, 31 Oct 2013 18:00:50 +0000 (+0100) Subject: strbuf_test: Added tests for len / nil-termination after skip(). X-Git-Tag: sysdb-0.1.0~336^2~21 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5e52344352367b90dbb3fb52684e7ecc0f9f7e10;p=sysdb.git strbuf_test: Added tests for len / nil-termination after skip(). --- diff --git a/t/utils/strbuf_test.c b/t/utils/strbuf_test.c index db392fa..3b88b58 100644 --- a/t/utils/strbuf_test.c +++ b/t/utils/strbuf_test.c @@ -308,14 +308,15 @@ END_TEST static struct { size_t n; const char *expected; + size_t expected_len; } skip_golden_data[] = { - { 0, "1234567890" }, - { 1, "234567890" }, - { 2, "34567890" }, - { 9, "0" }, - { 10, "" }, - { 11, "" }, - { 100, "" }, + { 0, "1234567890", 10 }, + { 1, "234567890", 9 }, + { 2, "34567890", 8 }, + { 9, "0", 1 }, + { 10, "", 0 }, + { 11, "", 0 }, + { 100, "", 0 }, }; START_TEST(test_sdb_strbuf_skip) @@ -325,14 +326,23 @@ START_TEST(test_sdb_strbuf_skip) for (i = 0; i < SDB_STATIC_ARRAY_LEN(skip_golden_data); ++i) { const char *check; + size_t n; sdb_strbuf_sprintf(buf, input); sdb_strbuf_skip(buf, skip_golden_data[i].n); + n = sdb_strbuf_len(buf); + fail_unless(n == skip_golden_data[i].expected_len, + "sdb_strbuf_len() = %zu (after skip); expected: %zu", + n, skip_golden_data[i].expected_len); + check = sdb_strbuf_string(buf); fail_unless(!!check, "sdb_strbuf_string() = NULL (after skip); expected: string"); + fail_unless(check[n] == '\0', + "sdb_strbuf_skip() did not nil-terminate the string"); + fail_unless(! strcmp(skip_golden_data[i].expected, check), "sdb_strbuf_skip('%s', %zu) did not skip correctly; " "got string '%s'; expected: '%s'", input,