test-strfuncs.c revision 833fd67ffe6a1832d72b3d310e07345a42a7b6ab
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenstatic void test_p_strarray_dup(void)
7ace5117d5f2395bd66f20b09e77dac05492f7ceTimo Sirainen const char **ret;
7ace5117d5f2395bd66f20b09e77dac05492f7ceTimo Sirainen unsigned int i, j;
7ace5117d5f2395bd66f20b09e77dac05492f7ceTimo Sirainen test_assert(strcmp(input[i][j], ret[j]) == 0);
8759adc67109b5a12a7af3ed717c7040622a0a04Timo Sirainenstatic void test_t_strsplit(void)
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen const char *const *args;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen /* empty string -> empty array. was this perhaps a mistake for the
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen API to do this originally?.. can't really change now anyway. */
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen /* two empty strings */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen const char *const *args;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen /* empty strings */
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen /* multiple separators */
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen args = t_strsplit_spaces(" , , ,str1 , ,,, , str2 , ", " ,");
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainenstatic void test_t_str_replace(void)
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen test_assert(strcmp(t_str_replace("foo", 'a', 'b'), "foo") == 0);
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen test_assert(strcmp(t_str_replace("fooa", 'a', 'b'), "foob") == 0);
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen test_assert(strcmp(t_str_replace("afooa", 'a', 'b'), "bfoob") == 0);
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen test_assert(strcmp(t_str_replace("", 'a', 'b'), "") == 0);
24d7c5fc9fa1cb1f49402ec796654113199ba4e6Timo Sirainen test_assert(strcmp(t_str_replace("a", 'a', 'b'), "b") == 0);
24d7c5fc9fa1cb1f49402ec796654113199ba4e6Timo Sirainen test_assert(strcmp(t_str_replace("aaa", 'a', 'b'), "bbb") == 0);
24d7c5fc9fa1cb1f49402ec796654113199ba4e6Timo Sirainen test_assert(strcmp(t_str_replace("bbb", 'a', 'b'), "bbb") == 0);
8759adc67109b5a12a7af3ed717c7040622a0a04Timo Sirainen test_assert(strcmp(t_str_replace("aba", 'a', 'b'), "bbb") == 0);
24d7c5fc9fa1cb1f49402ec796654113199ba4e6Timo Sirainenstatic void test_t_str_trim(void)
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim("", " "), "") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim(" ", " "), "") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim(" \t ", "\t "), "") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim("f \t ", "\t "), "f") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim("foo", ""), "foo") == 0);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen test_assert(strcmp(t_str_trim("foo", " "), "foo") == 0);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen test_assert(strcmp(t_str_trim("foo ", " "), "foo") == 0);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen test_assert(strcmp(t_str_trim(" foo", " "), "foo") == 0);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen test_assert(strcmp(t_str_trim(" foo ", " "), "foo") == 0);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen test_assert(strcmp(t_str_trim("\tfoo ", "\t "), "foo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim(" \tfoo\t ", "\t "), "foo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_trim("\r \tfoo\t \r", "\t \r"), "foo") == 0);
8759adc67109b5a12a7af3ed717c7040622a0a04Timo Sirainen test_assert(strcmp(t_str_trim("\r \tfoo foo\t \r", "\t \r"), "foo foo") == 0);
145d2eef238ed8bbff635e3b06951a83f0ee5a03Timo Sirainen test_assert(strcmp(t_str_trim("\tfoo\tfoo\t", "\t \r"), "foo\tfoo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenstatic void test_t_str_ltrim(void)
00bde9ae9eab9e720462bf6ec9a4dd85e88c3bbfTimo Sirainen test_assert(strcmp(t_str_ltrim("", " "), "") == 0);
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen test_assert(strcmp(t_str_ltrim(" ", " "), "") == 0);
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen test_assert(strcmp(t_str_ltrim(" \t ", "\t "), "") == 0);
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen test_assert(strcmp(t_str_ltrim(" \t f", "\t "), "f") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_ltrim("foo", ""), "foo") == 0);
00bde9ae9eab9e720462bf6ec9a4dd85e88c3bbfTimo Sirainen test_assert(strcmp(t_str_ltrim("foo", " "), "foo") == 0);
7ace5117d5f2395bd66f20b09e77dac05492f7ceTimo Sirainen test_assert(strcmp(t_str_ltrim("foo ", " "), "foo ") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_ltrim(" foo", " "), "foo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_ltrim(" foo ", " "), "foo ") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_ltrim("\tfoo ", "\t "), "foo ") == 0);
a3dd97fb6d92a89c3de0597fed2d4b044c7aeb84Timo Sirainen test_assert(strcmp(t_str_ltrim(" \tfoo\t ", "\t "), "foo\t ") == 0);
a3dd97fb6d92a89c3de0597fed2d4b044c7aeb84Timo Sirainen test_assert(strcmp(t_str_ltrim("\r \tfoo\t \r", "\t \r"), "foo\t \r") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_ltrim("\r \tfoo foo\t \r", "\t \r"), "foo foo\t \r") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_ltrim("\tfoo\tfoo\t", "\t \r"), "foo\tfoo\t") == 0);
553308791c097219e8eb31cbd03a29e9e1333848Timo Sirainenstatic void test_t_str_rtrim(void)
7dcb5545370faa9d4ff83b3ede65a69fc3dd4b65Timo Sirainen test_assert(strcmp(t_str_rtrim("", " "), "") == 0);
a3dd97fb6d92a89c3de0597fed2d4b044c7aeb84Timo Sirainen test_assert(strcmp(t_str_rtrim(" ", " "), "") == 0);
cc0495b3bbe3c3e41c512274b302d6f0fa028187Timo Sirainen test_assert(strcmp(t_str_rtrim(" \t ", "\t "), "") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_rtrim("f \t ", "\t "), "f") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_rtrim("foo", ""), "foo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_rtrim("foo", " "), "foo") == 0);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen test_assert(strcmp(t_str_rtrim("foo ", " "), "foo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_rtrim(" foo", " "), " foo") == 0);
31a12066e4cd9310d64091c81b59fb8eb1986023Timo Sirainen test_assert(strcmp(t_str_rtrim(" foo ", " "), " foo") == 0);
31a12066e4cd9310d64091c81b59fb8eb1986023Timo Sirainen test_assert(strcmp(t_str_rtrim("\tfoo ", "\t "), "\tfoo") == 0);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen test_assert(strcmp(t_str_rtrim(" \tfoo\t ", "\t "), " \tfoo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_rtrim("\r \tfoo\t \r", "\t \r"), "\r \tfoo") == 0);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen test_assert(strcmp(t_str_rtrim("\r \tfoo foo\t \r", "\t \r"), "\r \tfoo foo") == 0);
31a12066e4cd9310d64091c81b59fb8eb1986023Timo Sirainen test_assert(strcmp(t_str_rtrim("\tfoo\tfoo\t", "\t \r"), "\tfoo\tfoo") == 0);
31a12066e4cd9310d64091c81b59fb8eb1986023Timo Sirainenstatic const char *const test_strarray_input[] = {
61618d4c58080570f689614fec204ae14e90cef2Timo Sirainenstatic const struct {
static const char *const test_strarray_input2[] = {
const char *separator;
const char *output;
} test_strarray_outputs2[] = {
static const char *const test_strarray_input3[] = {
const char *separator;
const char *output;
} test_strarray_outputs3[] = {
static void test_t_strarray_join(void)
test_end();
static void test_p_array_const_string_join(void)
char *res;
test_end();
void test_strfuncs(void)