Skip to content

Commit

Permalink
lib: Added unit test for t_strarray_join()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Feb 21, 2016
1 parent 11c685e commit 1f35f54
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lib/test-strfuncs.c
Expand Up @@ -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();
Expand All @@ -168,4 +199,5 @@ void test_strfuncs(void)
/*test_t_str_trim();*/
test_t_str_ltrim();
test_t_str_rtrim();
test_t_strarray_join();
}

0 comments on commit 1f35f54

Please sign in to comment.