dovecot-1.1: Added unit tests for imap_match()

dovecot at dovecot.org dovecot at dovecot.org
Sun Mar 2 06:08:28 EET 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/ff7b11c64321
changeset: 7313:ff7b11c64321
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Mar 02 06:08:18 2008 +0200
description:
Added unit tests for imap_match()

diffstat:

3 files changed, 94 insertions(+), 1 deletion(-)
.hgignore             |    1 
src/tests/Makefile.am |   13 +++++++
src/tests/test-imap.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++++

diffs (133 lines):

diff -r 6f59434cf229 -r ff7b11c64321 .hgignore
--- a/.hgignore	Sun Mar 02 02:50:00 2008 +0200
+++ b/.hgignore	Sun Mar 02 06:08:18 2008 +0200
@@ -69,6 +69,7 @@ src/pop3/pop3
 src/pop3/pop3
 src/tests/test-lib
 src/tests/test-mail
+src/tests/test-imap
 src/util/dovecotpw
 src/util/gdbhelper
 src/util/idxview
diff -r 6f59434cf229 -r ff7b11c64321 src/tests/Makefile.am
--- a/src/tests/Makefile.am	Sun Mar 02 02:50:00 2008 +0200
+++ b/src/tests/Makefile.am	Sun Mar 02 06:08:18 2008 +0200
@@ -1,10 +1,11 @@ noinst_PROGRAMS = test-lib test-mail
-noinst_PROGRAMS = test-lib test-mail
+noinst_PROGRAMS = test-lib test-mail test-imap
 
 noinst_LIBRARIES = libtest.a
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
 	-I$(top_srcdir)/src/lib-mail \
+	-I$(top_srcdir)/src/lib-imap \
 	-I$(top_srcdir)/src/lib-index \
 	-I$(top_srcdir)/src/lib-storage
 
@@ -23,6 +24,9 @@ test_mail_SOURCES = \
 test_mail_SOURCES = \
 	test-mail.c
 
+test_imap_SOURCES = \
+	test-imap.c
+
 noinst_HEADERS = \
 	test-common.h \
 	test-lib.h
@@ -34,3 +38,10 @@ test_mail_LDADD = \
 	../lib-mail/libmail.a \
 	../lib-charset/libcharset.a \
 	../lib/liblib.a
+
+test_imap_LDADD = \
+	$(LIBICONV) \
+	$(RAND_LIBS) \
+	libtest.a \
+	../lib-imap/libimap.a \
+	../lib/liblib.a
diff -r 6f59434cf229 -r ff7b11c64321 src/tests/test-imap.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tests/test-imap.c	Sun Mar 02 06:08:18 2008 +0200
@@ -0,0 +1,81 @@
+/* Copyright (c) 2008 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 },
+		{ "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)
+{
+	test_init();
+
+	test_imap_match();
+	return test_deinit();
+}


More information about the dovecot-cvs mailing list