dovecot-2.0: Tests are now run on "make check". Added initial te...

dovecot at dovecot.org dovecot at dovecot.org
Sat May 9 23:22:55 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/665ea7a8d26e
changeset: 9258:665ea7a8d26e
user:      Timo Sirainen <tss at iki.fi>
date:      Sat May 09 16:20:41 2009 -0400
description:
Tests are now run on "make check". Added initial tests for lib-index.
Moved old tests away from tests/ to libraries' individual directories.

diffstat:

31 files changed, 2068 insertions(+), 1753 deletions(-)
.hgignore                                     |    7 
configure.in                                  |    2 
src/Makefile.am                               |    7 
src/lib-imap/Makefile.am                      |   21 
src/lib-imap/test-imap.c                      |  178 ++++
src/lib-index/Makefile.am                     |   30 
src/lib-index/mail-index-transaction-export.c |    3 
src/lib-index/mail-index-transaction.c        |    3 
src/lib-index/mail-transaction-log-append.c   |   30 
src/lib-index/mail-transaction-log.h          |    4 
src/lib-index/test-index.c                    |   12 
src/lib-index/test-index.h                    |    9 
src/lib-index/test-transaction-log-view.c     |  148 +++
src/lib-mail/Makefile.am                      |   21 
src/lib-mail/test-mail.c                      |  369 +++++++++
src/lib-test/Makefile.am                      |   18 
src/lib-test/test-common.c                    |  141 +++
src/lib-test/test-common.h                    |   20 
src/lib-test/test-common.lo                   |   12 
src/lib/Makefile.am                           |   29 
src/lib/test-istream.c                        |  105 ++
src/lib/test-lib.c                            |  923 ++++++++++++++++++++++++
src/lib/test-lib.h                            |    4 
src/tests/Makefile.am                         |   40 -
src/tests/test-common.c                       |   88 --
src/tests/test-common.h                       |   14 
src/tests/test-imap.c                         |  176 ----
src/tests/test-istream.c                      |  105 --
src/tests/test-lib.c                          |  931 -------------------------
src/tests/test-lib.h                          |    4 
src/tests/test-mail.c                         |  367 ---------

diffs (truncated from 4100 to 300 lines):

diff -r 2090983d37fa -r 665ea7a8d26e .hgignore
--- a/.hgignore	Sat May 09 16:10:36 2009 -0400
+++ b/.hgignore	Sat May 09 16:20:41 2009 -0400
@@ -61,9 +61,13 @@ src/dict/dict
 src/dict/dict
 src/imap-login/imap-login
 src/imap/imap
+src/lib/test-lib
 src/lib/unicodemap.c
 src/lib/UnicodeData.txt
 src/lib-dict/dict-drivers-register.c
+src/lib-index/test-index
+src/lib-imap/test-imap
+src/lib-mail/test-mail
 src/lib-sql/sql-drivers-register.c
 src/lib-storage/register/mail-storage-register.c
 src/lib-storage/register/mailbox-list-register.c
@@ -76,9 +80,6 @@ src/plugins/fts-squat/squat-test
 src/plugins/fts-squat/squat-test
 src/pop3-login/pop3-login
 src/pop3/pop3
-src/tests/test-lib
-src/tests/test-mail
-src/tests/test-imap
 src/util/doveadm
 src/util/dovecotpw
 src/util/gdbhelper
diff -r 2090983d37fa -r 665ea7a8d26e configure.in
--- a/configure.in	Sat May 09 16:10:36 2009 -0400
+++ b/configure.in	Sat May 09 16:20:41 2009 -0400
@@ -2442,6 +2442,7 @@ src/lib-otp/Makefile
 src/lib-otp/Makefile
 src/lib-dovecot/Makefile
 src/lib-settings/Makefile
+src/lib-test/Makefile
 src/lib-storage/Makefile
 src/lib-storage/list/Makefile
 src/lib-storage/index/Makefile
@@ -2465,7 +2466,6 @@ src/master/Makefile
 src/master/Makefile
 src/pop3/Makefile
 src/pop3-login/Makefile
-src/tests/Makefile
 src/util/Makefile
 src/plugins/Makefile
 src/plugins/acl/Makefile
diff -r 2090983d37fa -r 665ea7a8d26e src/Makefile.am
--- a/src/Makefile.am	Sat May 09 16:10:36 2009 -0400
+++ b/src/Makefile.am	Sat May 09 16:20:41 2009 -0400
@@ -9,6 +9,7 @@ LIBDOVECOT_SUBDIRS = \
 	lib-settings
 
 SUBDIRS = \
+	lib-test \
 	$(LIBDOVECOT_SUBDIRS) \
 	lib-dovecot \
 	lib-index \
@@ -30,6 +31,10 @@ SUBDIRS = \
 	lmtp \
 	log \
 	config \
-	tests \
 	util \
 	plugins
+
+test:
+	for dir in $(SUBDIRS); do \
+	  cd $$dir && if ! $(MAKE) test; then exit 1; fi; cd ..; \
+	done
diff -r 2090983d37fa -r 665ea7a8d26e src/lib-imap/Makefile.am
--- a/src/lib-imap/Makefile.am	Sat May 09 16:10:36 2009 -0400
+++ b/src/lib-imap/Makefile.am	Sat May 09 16:20:41 2009 -0400
@@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libimap.la
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-test \
 	-I$(top_srcdir)/src/lib-charset \
 	-I$(top_srcdir)/src/lib-mail
 
@@ -38,3 +39,23 @@ else
 else
   noinst_HEADERS = $(headers)
 endif
+
+test_programs = test-imap
+noinst_PROGRAMS = $(test_programs)
+
+test_libs = \
+	libimap.la \
+	../lib-test/libtest.la \
+	../lib/liblib.la
+
+test_imap_SOURCES = \
+	test-imap.c
+
+test_imap_LDADD = $(test_libs)
+test_imap_DEPENDENCIES = $(test_libs)
+
+check: check-am check-test
+check-test: $(test_programs)
+	for bin in $(test_programs); do \
+	  if ! ./$$bin; then exit 1; fi \
+	done
diff -r 2090983d37fa -r 665ea7a8d26e src/lib-imap/test-imap.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap/test-imap.c	Sat May 09 16:20:41 2009 -0400
@@ -0,0 +1,178 @@
+/* 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);
+	}
+
+	/* 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);
+	}
+}
+
+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_match,
+		test_imap_utf7,
+
+		NULL
+	};
+	return test_run(test_functions);
+}
diff -r 2090983d37fa -r 665ea7a8d26e src/lib-index/Makefile.am
--- a/src/lib-index/Makefile.am	Sat May 09 16:10:36 2009 -0400
+++ b/src/lib-index/Makefile.am	Sat May 09 16:20:41 2009 -0400
@@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libindex.la
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-test \
 	-I$(top_srcdir)/src/lib-mail
 
 libindex_la_SOURCES = \
@@ -54,9 +55,34 @@ headers = \
         mailbox-list-index.h \
         mailbox-list-index-private.h


More information about the dovecot-cvs mailing list