dovecot-2.0: Added unit test for mbox-from.

dovecot at dovecot.org dovecot at dovecot.org
Wed May 27 04:57:07 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/82bb4c6a6d64
changeset: 9401:82bb4c6a6d64
user:      Timo Sirainen <tss at iki.fi>
date:      Tue May 26 21:57:02 2009 -0400
description:
Added unit test for mbox-from.

diffstat:

2 files changed, 111 insertions(+), 12 deletions(-)
src/lib-mail/Makefile.am      |   29 +++++++-----
src/lib-mail/test-mbox-from.c |   94 +++++++++++++++++++++++++++++++++++++++++

diffs (154 lines):

diff -r b59c6c30115e -r 82bb4c6a6d64 src/lib-mail/Makefile.am
--- a/src/lib-mail/Makefile.am	Tue May 26 21:53:54 2009 -0400
+++ b/src/lib-mail/Makefile.am	Tue May 26 21:57:02 2009 -0400
@@ -51,6 +51,7 @@ endif
 
 test_programs = \
 	test-istream-header-filter \
+	test-mbox-from \
 	test-message-address \
 	test-message-date \
 	test-message-header-parser \
@@ -64,28 +65,32 @@ test_libs = \
 	../lib/liblib.la
 
 test_istream_header_filter_SOURCES = test-istream-header-filter.c
-test_istream_header_filter_LDADD = istream-header-filter.lo message-header-parser.lo $(test_libs)
-test_istream_header_filter_DEPENDENCIES = istream-header-filter.lo message-header-parser.lo $(test_libs)
+test_istream_header_filter_LDADD = istream-header-filter.o message-header-parser.o $(test_libs)
+test_istream_header_filter_DEPENDENCIES = istream-header-filter.o message-header-parser.o $(test_libs)
+
+test_mbox_from_SOURCES = test-mbox-from.c
+test_mbox_from_LDADD = mbox-from.o $(test_libs)
+test_mbox_from_DEPENDENCIES = mbox-from.o $(test_libs)
 
 test_message_address_SOURCES = test-message-address.c
-test_message_address_LDADD = message-address.lo rfc822-parser.lo $(test_libs)
-test_message_address_DEPENDENCIES = message-address.lo rfc822-parser.lo $(test_libs)
+test_message_address_LDADD = message-address.o rfc822-parser.o $(test_libs)
+test_message_address_DEPENDENCIES = message-address.o rfc822-parser.o $(test_libs)
 
 test_message_date_SOURCES = test-message-date.c
-test_message_date_LDADD = message-date.lo rfc822-parser.lo $(test_libs)
-test_message_date_DEPENDENCIES = message-date.lo rfc822-parser.lo $(test_libs)
+test_message_date_LDADD = message-date.o rfc822-parser.o $(test_libs)
+test_message_date_DEPENDENCIES = message-date.o rfc822-parser.o $(test_libs)
 
 test_message_header_parser_SOURCES = test-message-header-parser.c
-test_message_header_parser_LDADD = message-header-parser.lo $(test_libs)
-test_message_header_parser_DEPENDENCIES = message-header-parser.lo $(test_libs)
+test_message_header_parser_LDADD = message-header-parser.o $(test_libs)
+test_message_header_parser_DEPENDENCIES = message-header-parser.o $(test_libs)
 
 test_message_parser_SOURCES = test-message-parser.c
-test_message_parser_LDADD = message-parser.lo message-header-parser.lo message-size.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs)
-test_message_parser_DEPENDENCIES = message-parser.lo message-header-parser.lo message-size.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs)
+test_message_parser_LDADD = message-parser.o message-header-parser.o message-size.o rfc822-parser.o rfc2231-parser.o $(test_libs)
+test_message_parser_DEPENDENCIES = message-parser.o message-header-parser.o message-size.o rfc822-parser.o rfc2231-parser.o $(test_libs)
 
 test_rfc2231_parser_SOURCES = test-rfc2231-parser.c
-test_rfc2231_parser_LDADD = rfc2231-parser.lo rfc822-parser.lo $(test_libs)
-test_rfc2231_parser_DEPENDENCIES = rfc2231-parser.lo rfc822-parser.lo $(test_libs)
+test_rfc2231_parser_LDADD = rfc2231-parser.o rfc822-parser.o $(test_libs)
+test_rfc2231_parser_DEPENDENCIES = rfc2231-parser.o rfc822-parser.o $(test_libs)
 
 check: check-am check-test
 check-test: $(test_programs)
diff -r b59c6c30115e -r 82bb4c6a6d64 src/lib-mail/test-mbox-from.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/test-mbox-from.c	Tue May 26 21:57:02 2009 -0400
@@ -0,0 +1,94 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "mbox-from.h"
+#include "test-common.h"
+
+struct test_mbox_from_parse_output {
+	time_t time;
+	int tz_offset;
+	const char *sender;
+	int ret;
+};
+
+static void test_mbox_from_parse(void)
+{
+	static const char *input[] = {
+		"user at domain Thu Nov 29 23:33:09 1973 +0200",
+		"user at domain Thu Nov 29 19:33:09 1973 -0200",
+		"\"user name\"@domain  Fri Jan  2 10:13:52 UTC 1970 +0000",
+		"user  Fri Jan  2 10:14 1970 +0000",
+		"user Fri, 2 Jan 1970 10:14:00 +0000",
+		"user Fri, 2 Jan 1970 10:14 +0000",
+		" Fri Jan  2 10:14 1970 +0000",
+		"user Fri, 2 Foo 1970 10:14:00",
+		"Fri Jan  2 10:14 1970 +0000",
+		"user  Fri Jan  x 10:14 1970 +0000",
+		"user  Fri Jan  2 0:14 1970 +0000",
+		"user  Fri Jan  2 xx:14 1970 +0000",
+		"user  Fri Jan  2 10: 1970 +0000",
+		"user  Fri Jan  2 10:xx 1970 +0000",
+		"user  Fri Jan  2 10:xx +0000",
+	};
+	static struct test_mbox_from_parse_output output[] = {
+		{ 123456789, 2*60, "user at domain", 0 },
+		{ 123456789, -2*60, "user at domain", 0 },
+		{ 123232, 0, "\"user name\"@domain", 0 },
+		{ 123240, 0, "user", 0 },
+		{ 123240, 0, "user", 0 },
+		{ 123240, 0, "user", 0 },
+		{ 123240, 0, "", 0 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+		{ 0, 0, NULL, -1 },
+	};
+	unsigned int i, j, len;
+	char *sender;
+	bool success;
+	time_t t;
+	int tz, ret;
+
+	for (j = 0; j < 2; j++) {
+	for (i = 0; i < N_ELEMENTS(input); i++) {
+		len = strlen(input[i]) - j*6;
+		ret = mbox_from_parse((const unsigned char *)input[i],
+				      len, &t, &tz, &sender);
+		success = (ret < 0 && output[i].ret < 0) ||
+			(ret == output[i].ret && t == output[i].time &&
+			 tz == output[i].tz_offset &&
+			 strcmp(sender, output[i].sender) == 0);
+		i_free(sender);
+		test_out(t_strdup_printf("mbox_from_parse(%d,%d)", j, i), success);
+
+		/* prepare for testing without timezone */
+		if (output[i].ret == 0) {
+			output[i].time += output[i].tz_offset*60;
+			output[i].tz_offset = -timezone/60;
+			output[i].time -= output[i].tz_offset*60;
+		}
+	}
+	}
+}
+
+static void test_mbox_from_create(void)
+{
+	test_begin("mbox_from_create()");
+	test_assert(strcmp(mbox_from_create("user", 1234567890+timezone),
+			   "From user  Fri Feb 13 23:31:30 2009\n") == 0);
+	test_end();
+}
+
+int main(void)
+{
+	static void (*test_functions[])(void) = {
+		test_mbox_from_parse,
+		test_mbox_from_create,
+		NULL
+	};
+	return test_run(test_functions);
+}


More information about the dovecot-cvs mailing list