X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftest%2Ftest-strv.c;h=068e4210979d50e828b34bdeb25908f619e528c8;hp=e46885902bad6519f112d6173700b122b27c8fa0;hb=e3dd987cfc395848256fc6eae637ed0eaf5f1635;hpb=aed2ebfed00acdc5db1542be499f6a0d71a76f08 diff --git a/src/test/test-strv.c b/src/test/test-strv.c index e46885902..068e42109 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -143,6 +143,7 @@ static void test_strv_quote_unquote(const char* const *split, const char *quoted char **t; p = strv_join_quoted((char **)split); + assert_se(p); printf("-%s- --- -%s-\n", p, quoted); /* fprintf deals with NULL, puts does not */ assert_se(p); assert_se(streq(p, quoted)); @@ -156,6 +157,20 @@ static void test_strv_quote_unquote(const char* const *split, const char *quoted } } +static void test_strv_quote_unquote2(const char *quoted, const char ** list) { + _cleanup_strv_free_ char **s; + unsigned i = 0; + char **t; + + s = strv_split_quoted(quoted); + assert_se(s); + + STRV_FOREACH(t, s) + assert_se(streq(list[i++], *t)); + + assert_se(list[i] == NULL); +} + static void test_strv_split(void) { char **s; unsigned i = 0; @@ -405,6 +420,18 @@ int main(int argc, char *argv[]) { test_strv_quote_unquote(input_table_quotes, QUOTES_STRING); test_strv_quote_unquote(input_table_spaces, SPACES_STRING); + test_strv_quote_unquote2(" foo=bar \"waldo\" zzz ", (const char*[]) { "foo=bar", "waldo", "zzz", NULL }); + test_strv_quote_unquote2("", (const char*[]) { NULL }); + test_strv_quote_unquote2(" ", (const char*[]) { NULL }); + test_strv_quote_unquote2(" ", (const char*[]) { NULL }); + test_strv_quote_unquote2(" x", (const char*[]) { "x", NULL }); + test_strv_quote_unquote2("x ", (const char*[]) { "x", NULL }); + test_strv_quote_unquote2(" x ", (const char*[]) { "x", NULL }); + test_strv_quote_unquote2(" \"x\" ", (const char*[]) { "x", NULL }); + test_strv_quote_unquote2(" \'x\' ", (const char*[]) { "x", NULL }); + test_strv_quote_unquote2(" \'x\"\' ", (const char*[]) { "x\"", NULL }); + test_strv_quote_unquote2(" \"x\'\" ", (const char*[]) { "x\'", NULL }); + test_strv_split(); test_strv_split_newlines(); test_strv_split_nulstr();