From 22c096638758a842a084db51e35508ac323890af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 14 May 2016 09:14:08 +0200 Subject: [PATCH] tests: add tests on function string_split_command() --- tests/unit/core/test-string.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-string.cpp index 46314eb2b..0947e16b7 100644 --- a/tests/unit/core/test-string.cpp +++ b/tests/unit/core/test-string.cpp @@ -931,15 +931,33 @@ TEST(String, SplitCommand) { char **argv; + /* test with a NULL/empty string */ POINTERS_EQUAL(NULL, string_split_command (NULL, ';')); POINTERS_EQUAL(NULL, string_split_command ("", ';')); + + /* string with one command */ + argv = string_split_command ("abc", ';'); + CHECK(argv); + STRCMP_EQUAL("abc", argv[0]); + POINTERS_EQUAL(NULL, argv[1]); + string_free_split_command (argv); + + /* string with 3 commands */ argv = string_split_command ("abc;de;fghi", ';'); CHECK(argv); STRCMP_EQUAL("abc", argv[0]); STRCMP_EQUAL("de", argv[1]); STRCMP_EQUAL("fghi", argv[2]); POINTERS_EQUAL(NULL, argv[3]); + string_free_split_command (argv); + /* string with 3 commands (containing spaces) */ + argv = string_split_command (" abc ; de ; fghi ", ';'); + CHECK(argv); + STRCMP_EQUAL("abc ", argv[0]); + STRCMP_EQUAL("de ", argv[1]); + STRCMP_EQUAL("fghi ", argv[2]); + POINTERS_EQUAL(NULL, argv[3]); string_free_split_command (argv); /* separator other than ';' */ @@ -949,7 +967,6 @@ TEST(String, SplitCommand) STRCMP_EQUAL("de", argv[1]); STRCMP_EQUAL("fghi", argv[2]); POINTERS_EQUAL(NULL, argv[3]); - string_free_split_command (argv); /* free split with NULL */