dovecot-2.0: Split test-imap binary to test-imap-match and test-...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 26 04:03:49 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/07b601734cc8
changeset: 9365:07b601734cc8
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 25 21:03:42 2009 -0400
description:
Split test-imap binary to test-imap-match and test-imap-utf7.

diffstat:

4 files changed, 196 insertions(+), 186 deletions(-)
src/lib-imap/Makefile.am       |   15 +--
src/lib-imap/test-imap-match.c |   85 +++++++++++++++++++
src/lib-imap/test-imap-utf7.c  |  104 +++++++++++++++++++++++
src/lib-imap/test-imap.c       |  178 ----------------------------------------

diffs (truncated from 411 to 300 lines):

diff -r 26cb0925f2c4 -r 07b601734cc8 src/lib-imap/Makefile.am
--- a/src/lib-imap/Makefile.am	Mon May 25 21:02:18 2009 -0400
+++ b/src/lib-imap/Makefile.am	Mon May 25 21:03:42 2009 -0400
@@ -40,21 +40,20 @@ else
   noinst_HEADERS = $(headers)
 endif
 
-test_programs = test-imap
+test_programs = test-imap-utf7 test-imap-match
 noinst_PROGRAMS = $(test_programs)
 
 test_libs = \
-	libimap.la \
-	../lib-mail/libmail.la \
-	../lib-charset/libcharset.la \
 	../lib-test/libtest.la \
 	../lib/liblib.la
 
-test_imap_SOURCES = \
-	test-imap.c
+test_imap_utf7_SOURCES = test-imap-utf7.c
+test_imap_utf7_LDADD = imap-utf7.o $(test_libs)
+test_imap_utf7_DEPENDENCIES = imap-utf7.o $(test_libs)
 
-test_imap_LDADD = $(test_libs) $(LIBICONV)
-test_imap_DEPENDENCIES = $(test_libs)
+test_imap_match_SOURCES = test-imap-match.c
+test_imap_match_LDADD = imap-match.o $(test_libs)
+test_imap_match_DEPENDENCIES = imap-match.o $(test_libs)
 
 check: check-am check-test
 check-test: $(test_programs)
diff -r 26cb0925f2c4 -r 07b601734cc8 src/lib-imap/test-imap-match.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap/test-imap-match.c	Mon May 25 21:03:42 2009 -0400
@@ -0,0 +1,85 @@
+/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "imap-match.h"
+#include "test-common.h"
+
+struct test_imap_match {
+	const char *pattern;
+	const char *input;
+	enum imap_match_result result;
+};
+
+static void test_imap_match(void)
+{
+	struct test_imap_match test[] = {
+		{ "", "", IMAP_MATCH_YES },
+		{ "a", "b", IMAP_MATCH_NO },
+		{ "foo", "foo", IMAP_MATCH_YES },
+		{ "foo", "foo/", IMAP_MATCH_PARENT },
+		{ "%", "", IMAP_MATCH_YES },
+		{ "%", "foo", IMAP_MATCH_YES },
+		{ "%", "foo/", IMAP_MATCH_PARENT },
+		{ "%/", "foo/", IMAP_MATCH_YES },
+		{ "%", "foo/bar", IMAP_MATCH_PARENT },
+		{ "%/%", "foo", IMAP_MATCH_CHILDREN },
+		{ "%/%", "foo/", IMAP_MATCH_YES },
+		{ "foo/bar/%", "foo", IMAP_MATCH_CHILDREN },
+		{ "foo/bar/%", "foo/", IMAP_MATCH_CHILDREN },
+		{ "foo*", "foo", IMAP_MATCH_YES },
+		{ "foo*", "foo/", IMAP_MATCH_YES },
+		{ "foo*", "fobo", IMAP_MATCH_NO },
+		{ "*foo*", "bar/foo/", IMAP_MATCH_YES },
+		{ "*foo*", "fobo", IMAP_MATCH_CHILDREN },
+		{ "foo*bar", "foobar/baz", IMAP_MATCH_CHILDREN | IMAP_MATCH_PARENT },
+		{ "*foo*", "fobo", IMAP_MATCH_CHILDREN },
+		{ "%/%/%", "foo/", IMAP_MATCH_CHILDREN },
+		{ "%/%o/%", "foo/", IMAP_MATCH_CHILDREN },
+		{ "%/%o/%", "foo", IMAP_MATCH_CHILDREN },
+		{ "inbox", "inbox", IMAP_MATCH_YES },
+		{ "inbox", "INBOX", IMAP_MATCH_NO }
+	};
+	struct test_imap_match inbox_test[] = {
+		{ "inbox", "inbox", IMAP_MATCH_YES },
+		{ "inbox", "iNbOx", IMAP_MATCH_YES },
+		{ "i%X", "iNbOx", IMAP_MATCH_YES },
+		{ "%I%N%B%O%X%", "inbox", IMAP_MATCH_YES },
+		{ "i%X/foo", "iNbOx/foo", IMAP_MATCH_YES },
+		{ "%I%N%B%O%X%/foo", "inbox/foo", IMAP_MATCH_YES },
+		{ "i%X/foo", "inbx/foo", IMAP_MATCH_NO }
+	};
+	struct imap_match_glob *glob;
+	unsigned int i;
+	enum imap_match_result result;
+
+	/* first try tests without inboxcasing */
+	for (i = 0; i < N_ELEMENTS(test); i++) {
+		glob = imap_match_init(default_pool, test[i].pattern,
+				       FALSE, '/');
+		result = imap_match(glob, test[i].input);
+		imap_match_deinit(&glob);
+
+		test_out(t_strdup_printf("imap_match(%d)", i), 
+			 result == test[i].result);
+	}
+
+	/* inboxcasing tests */
+	for (i = 0; i < N_ELEMENTS(inbox_test); i++) {
+		glob = imap_match_init(default_pool, inbox_test[i].pattern,
+				       TRUE, '/');
+		result = imap_match(glob, inbox_test[i].input);
+		imap_match_deinit(&glob);
+
+		test_out(t_strdup_printf("imap_match(inboxcase, %d)", i),
+			 result == inbox_test[i].result);
+	}
+}
+
+int main(void)
+{
+	static void (*test_functions[])(void) = {
+		test_imap_match,
+		NULL
+	};
+	return test_run(test_functions);
+}
diff -r 26cb0925f2c4 -r 07b601734cc8 src/lib-imap/test-imap-utf7.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap/test-imap-utf7.c	Mon May 25 21:03:42 2009 -0400
@@ -0,0 +1,104 @@
+/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "str.h"
+#include "unichar.h"
+#include "imap-utf7.h"
+#include "test-common.h"
+
+static void test_imap_utf7(void)
+{
+	static const char *to_utf7[] = {
+		"&&x&&", "&-&-x&-&-",
+		"~peter/mail/台北/日本語", "~peter/mail/&U,BTFw-/&ZeVnLIqe-",
+		"tietäjä", "tiet&AOQ-j&AOQ-",
+		"pää", NULL,
+		NULL
+	};
+	static const char *invalid_utf7[] = {
+		"&Jjo!",
+		"&U,BTFw-&ZeVnLIqe-",
+		NULL
+	};
+	string_t *src, *dest;
+	const char *orig_src;
+	unsigned int i, j;
+	unichar_t chr;
+	bool success, all_success = TRUE;
+
+	src = t_str_new(256);
+	dest = t_str_new(256);
+
+	for (i = 0; to_utf7[i] != NULL; i += 2) {
+		str_truncate(dest, 0);
+		if (imap_utf8_to_utf7(to_utf7[i], dest) < 0)
+			success = to_utf7[i+1] == NULL;
+		else {
+			success = to_utf7[i+1] != NULL &&
+				strcmp(to_utf7[i+1], str_c(dest)) == 0;
+		}
+		if (!success) {
+			test_out(t_strdup_printf("imap_utf8_to_utf7(%d)", i/2),
+				 FALSE);
+			all_success = FALSE;
+		} else if (to_utf7[i+1] != NULL) {
+			str_truncate(dest, 0);
+			if (imap_utf7_to_utf8(to_utf7[i+1], dest) < 0 ||
+			    strcmp(to_utf7[i], str_c(dest)) != 0) {
+				test_out(t_strdup_printf("imap_utf7_to_utf8(%d)", i/2),
+					 FALSE);
+				all_success = FALSE;
+			}
+		}
+	}
+	if (all_success)
+		test_out("imap_utf8_to_utf7()", TRUE);
+
+	success = TRUE;
+	for (chr = 0xffff; chr <= 0x10010; chr++) {
+		for (i = 1; i <= 10; i++) {
+			str_truncate(src, 0);
+			str_truncate(dest, 0);
+			for (j = 0; j < i; j++) {
+				if (j % 3 == 0)
+					str_append_c(src, 'x');
+				if (j % 5 == 0)
+					str_append_c(src, '&');
+				uni_ucs4_to_utf8_c(chr, src);
+			}
+
+			orig_src = t_strdup(str_c(src));
+			str_truncate(src, 0);
+
+			if (imap_utf8_to_utf7(orig_src, dest) < 0)
+				success = FALSE;
+			else if (imap_utf7_to_utf8(str_c(dest), src) < 0)
+				success = FALSE;
+			else
+				success = strcmp(str_c(src), orig_src) == 0;
+			if (!success)
+				goto end;
+		}
+	}
+end:
+	test_out("imap_utf7_to_utf8(reverse)", success);
+	for (i = 0; invalid_utf7[i] != NULL; i++) {
+		str_truncate(dest, 0);
+		if (imap_utf7_to_utf8(invalid_utf7[i], dest) == 0) {
+			test_out(t_strdup_printf("imap_utf7_to_utf8(invalid.%d)", i),
+				 FALSE);
+			all_success = FALSE;
+		}
+	}
+	if (all_success)
+		test_out("imap_utf7_to_utf8(invalid)", TRUE);
+}
+
+int main(void)
+{
+	static void (*test_functions[])(void) = {
+		test_imap_utf7,
+		NULL
+	};
+	return test_run(test_functions);
+}
diff -r 26cb0925f2c4 -r 07b601734cc8 src/lib-imap/test-imap.c
--- a/src/lib-imap/test-imap.c	Mon May 25 21:02:18 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "str.h"
-#include "unichar.h"
-#include "imap-match.h"
-#include "imap-utf7.h"
-#include "test-common.h"
-
-struct test_imap_match {
-	const char *pattern;
-	const char *input;
-	enum imap_match_result result;
-};
-
-static void test_imap_match(void)
-{
-	struct test_imap_match test[] = {
-		{ "", "", IMAP_MATCH_YES },
-		{ "a", "b", IMAP_MATCH_NO },
-		{ "foo", "foo", IMAP_MATCH_YES },
-		{ "foo", "foo/", IMAP_MATCH_PARENT },
-		{ "%", "", IMAP_MATCH_YES },
-		{ "%", "foo", IMAP_MATCH_YES },
-		{ "%", "foo/", IMAP_MATCH_PARENT },
-		{ "%/", "foo/", IMAP_MATCH_YES },
-		{ "%", "foo/bar", IMAP_MATCH_PARENT },
-		{ "%/%", "foo", IMAP_MATCH_CHILDREN },
-		{ "%/%", "foo/", IMAP_MATCH_YES },
-		{ "foo/bar/%", "foo", IMAP_MATCH_CHILDREN },
-		{ "foo/bar/%", "foo/", IMAP_MATCH_CHILDREN },
-		{ "foo*", "foo", IMAP_MATCH_YES },
-		{ "foo*", "foo/", IMAP_MATCH_YES },
-		{ "foo*", "fobo", IMAP_MATCH_NO },
-		{ "*foo*", "bar/foo/", IMAP_MATCH_YES },
-		{ "*foo*", "fobo", IMAP_MATCH_CHILDREN },
-		{ "foo*bar", "foobar/baz", IMAP_MATCH_CHILDREN | IMAP_MATCH_PARENT },
-		{ "*foo*", "fobo", IMAP_MATCH_CHILDREN },
-		{ "%/%/%", "foo/", IMAP_MATCH_CHILDREN },
-		{ "%/%o/%", "foo/", IMAP_MATCH_CHILDREN },
-		{ "%/%o/%", "foo", IMAP_MATCH_CHILDREN },
-		{ "inbox", "inbox", IMAP_MATCH_YES },
-		{ "inbox", "INBOX", IMAP_MATCH_NO }
-	};
-	struct test_imap_match inbox_test[] = {
-		{ "inbox", "inbox", IMAP_MATCH_YES },
-		{ "inbox", "iNbOx", IMAP_MATCH_YES },
-		{ "i%X", "iNbOx", IMAP_MATCH_YES },
-		{ "%I%N%B%O%X%", "inbox", IMAP_MATCH_YES },
-		{ "i%X/foo", "iNbOx/foo", IMAP_MATCH_YES },
-		{ "%I%N%B%O%X%/foo", "inbox/foo", IMAP_MATCH_YES },
-		{ "i%X/foo", "inbx/foo", IMAP_MATCH_NO }
-	};
-	struct imap_match_glob *glob;
-	unsigned int i;
-	enum imap_match_result result;
-
-	/* first try tests without inboxcasing */
-	for (i = 0; i < N_ELEMENTS(test); i++) {
-		glob = imap_match_init(default_pool, test[i].pattern,
-				       FALSE, '/');
-		result = imap_match(glob, test[i].input);
-		imap_match_deinit(&glob);
-
-		test_out(t_strdup_printf("imap_match(%d)", i), 
-			 result == test[i].result);
-	}


More information about the dovecot-cvs mailing list