From: Florian Forster Date: Sun, 28 Jun 2015 12:08:02 +0000 (+0200) Subject: src/daemon/common.c: Add unit test for escape_string(). X-Git-Tag: collectd-5.6.0~666 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=233ef890d210e7f231ebbc474894e90032ba49b1;p=collectd.git src/daemon/common.c: Add unit test for escape_string(). --- diff --git a/src/daemon/common_test.c b/src/daemon/common_test.c index ff33c9eb..f40b2b1a 100644 --- a/src/daemon/common_test.c +++ b/src/daemon/common_test.c @@ -213,6 +213,33 @@ DEF_TEST(escape_slashes) return 0; } +DEF_TEST(escape_string) +{ + struct { + char *str; + char *want; + } cases[] = { + {"foobar", "foobar"}, + {"f00bar", "f00bar"}, + {"foo bar", "\"foo bar\""}, + {"foo \"bar\"", "\"foo \\\"bar\\\"\""}, + {"012345678901234", "012345678901234"}, + {"012345 78901234", "\"012345 789012\""}, + {"012345 78901\"34", "\"012345 78901\""}, + }; + size_t i; + + for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + char buffer[16]; + + strncpy (buffer, cases[i].str, sizeof (buffer)); + OK(escape_string (buffer, sizeof (buffer)) == 0); + STREQ(cases[i].want, buffer); + } + + return 0; +} + DEF_TEST(strunescape) { char buffer[16]; @@ -319,6 +346,7 @@ int main (void) RUN_TEST(strsplit); RUN_TEST(strjoin); RUN_TEST(escape_slashes); + RUN_TEST(escape_string); RUN_TEST(strunescape); RUN_TEST(parse_values);