]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Added unit test for t_strarray_join()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 21 Feb 2016 16:31:12 +0000 (18:31 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 21 Feb 2016 16:31:12 +0000 (18:31 +0200)
src/lib/test-strfuncs.c

index 2476b6c532d95aed00dcacc8b3b740fc3046c736..4c6411b68a3e35d2938661680a4641b3b0904a49 100644 (file)
@@ -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();
 }