From: Timo Sirainen Date: Sun, 21 Feb 2016 16:31:12 +0000 (+0200) Subject: lib: Added unit test for t_strarray_join() X-Git-Tag: 2.2.22.rc1~131 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f35f54096589b0fdb04bfac4d079d06b43f2a74;p=thirdparty%2Fdovecot%2Fcore.git lib: Added unit test for t_strarray_join() --- diff --git a/src/lib/test-strfuncs.c b/src/lib/test-strfuncs.c index 2476b6c532..4c6411b68a 100644 --- a/src/lib/test-strfuncs.c +++ b/src/lib/test-strfuncs.c @@ -159,6 +159,37 @@ static void test_t_str_rtrim(void) test_end(); } +static const char *const test_strarray_input[] = { + "", "hello", "world", "", "yay", "", NULL +}; +static struct { + const char *separator; + const char *output; +} test_strarray_outputs[] = { + { "", "helloworldyay" }, + /* FIXME: v2.3 - test_output should have separator in the beginning */ + { " ", "hello world yay " }, + { "!-?", "hello!-?world!-?!-?yay!-?" } +}; + +static void test_t_strarray_join(void) +{ + const char *null = NULL; + unsigned int i; + + test_begin("t_strarray_join()"); + + /* empty array -> empty string */ + test_assert(strcmp(t_strarray_join(&null, " "), "") == 0); + + for (i = 0; i < N_ELEMENTS(test_strarray_outputs); i++) { + test_assert_idx(strcmp(t_strarray_join(test_strarray_input, + test_strarray_outputs[i].separator), + test_strarray_outputs[i].output) == 0, i); + } + test_end(); +} + void test_strfuncs(void) { test_p_strarray_dup(); @@ -168,4 +199,5 @@ void test_strfuncs(void) /*test_t_str_trim();*/ test_t_str_ltrim(); test_t_str_rtrim(); + test_t_strarray_join(); }