Mercurial > dovecot > core-2.2
changeset 19789:39b6a7059871
lib: Added unit test for t_strarray_join()
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Sun, 21 Feb 2016 18:31:12 +0200 |
parents | 7015b5bd58bf |
children | 8d3736bf4a90 |
files | src/lib/test-strfuncs.c |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/test-strfuncs.c Sun Feb 21 17:44:38 2016 +0200 +++ b/src/lib/test-strfuncs.c Sun Feb 21 18:31:12 2016 +0200 @@ -159,6 +159,37 @@ 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 @@ /*test_t_str_trim();*/ test_t_str_ltrim(); test_t_str_rtrim(); + test_t_strarray_join(); }