dovecot-2.2: liblib: Added unit test for t_strsplit(data="")
dovecot at dovecot.org
dovecot at dovecot.org
Mon Apr 7 21:09:33 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/3bff23b6c187
changeset: 17201:3bff23b6c187
user: Timo Sirainen <tss at iki.fi>
date: Tue Apr 08 00:09:03 2014 +0300
description:
liblib: Added unit test for t_strsplit(data="")
diffstat:
src/lib/strfuncs.h | 3 ++-
src/lib/test-strfuncs.c | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletions(-)
diffs (47 lines):
diff -r 3e1a69e0cda9 -r 3bff23b6c187 src/lib/strfuncs.h
--- a/src/lib/strfuncs.h Tue Apr 08 00:08:21 2014 +0300
+++ b/src/lib/strfuncs.h Tue Apr 08 00:09:03 2014 +0300
@@ -56,7 +56,8 @@
int i_strcmp_p(const char *const *p1, const char *const *p2) ATTR_PURE;
int i_strcasecmp_p(const char *const *p1, const char *const *p2) ATTR_PURE;
-/* separators is an array of separator characters, not a separator string. */
+/* separators is an array of separator characters, not a separator string.
+ an empty data string results in an array containing only NULL. */
char **p_strsplit(pool_t pool, const char *data, const char *separators)
ATTR_MALLOC;
const char **t_strsplit(const char *data, const char *separators)
diff -r 3e1a69e0cda9 -r 3bff23b6c187 src/lib/test-strfuncs.c
--- a/src/lib/test-strfuncs.c Tue Apr 08 00:08:21 2014 +0300
+++ b/src/lib/test-strfuncs.c Tue Apr 08 00:09:03 2014 +0300
@@ -29,6 +29,23 @@
test_end();
}
+static void test_t_strsplit(void)
+{
+ const char *const *args;
+
+ test_begin("t_strsplit");
+ /* empty string -> empty array. was this perhaps a mistake for the
+ API to do this originally?.. can't really change now anyway. */
+ args = t_strsplit("", "\n");
+ test_assert(args[0] == NULL);
+ /* two empty strings */
+ args = t_strsplit("\n", "\n");
+ test_assert(args[0][0] == '\0');
+ test_assert(args[1][0] == '\0');
+ test_assert(args[2] == NULL);
+ test_end();
+}
+
static void strsplit_verify(const char *str)
{
T_BEGIN {
@@ -82,5 +99,6 @@
void test_strfuncs(void)
{
test_p_strarray_dup();
+ test_t_strsplit();
test_t_strsplit_tab();
}
More information about the dovecot-cvs
mailing list