dovecot-2.0: Split test-mail binary to test-mail-* binaries.

dovecot at dovecot.org dovecot at dovecot.org
Tue May 26 21:55:47 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/aff3abbcb8a6
changeset: 9386:aff3abbcb8a6
user:      Timo Sirainen <tss at iki.fi>
date:      Tue May 26 14:55:40 2009 -0400
description:
Split test-mail binary to test-mail-* binaries.

diffstat:

7 files changed, 443 insertions(+), 376 deletions(-)
src/lib-mail/Makefile.am                  |   32 +-
src/lib-mail/test-istream-header-filter.c |   69 +++++
src/lib-mail/test-mail.c                  |  369 -----------------------------
src/lib-mail/test-message-address.c       |  105 ++++++++
src/lib-mail/test-message-date.c          |   66 +++++
src/lib-mail/test-message-parser.c        |  124 +++++++++
src/lib-mail/test-rfc2231-parser.c        |   54 ++++

diffs (truncated from 860 to 300 lines):

diff -r 89d2dbbfa4ca -r aff3abbcb8a6 src/lib-mail/Makefile.am
--- a/src/lib-mail/Makefile.am	Tue May 26 14:21:59 2009 -0400
+++ b/src/lib-mail/Makefile.am	Tue May 26 14:55:40 2009 -0400
@@ -49,20 +49,38 @@ else
   noinst_HEADERS = $(headers)
 endif
 
-test_programs = test-mail
+test_programs = \
+	test-istream-header-filter \
+	test-message-address \
+	test-message-date \
+	test-message-parser \
+	test-rfc2231-parser
+
 noinst_PROGRAMS = $(test_programs)
 
 test_libs = \
-	libmail.la \
-	../lib-charset/libcharset.la \
 	../lib-test/libtest.la \
 	../lib/liblib.la
 
-test_mail_SOURCES = \
-	test-mail.c
+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_mail_LDADD = $(test_libs) $(LIBICONV)
-test_mail_DEPENDENCIES = $(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_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_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_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)
 
 check: check-am check-test
 check-test: $(test_programs)
diff -r 89d2dbbfa4ca -r aff3abbcb8a6 src/lib-mail/test-istream-header-filter.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/test-istream-header-filter.c	Tue May 26 14:55:40 2009 -0400
@@ -0,0 +1,69 @@
+/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "istream.h"
+#include "message-header-parser.h"
+#include "istream-header-filter.h"
+#include "test-common.h"
+
+static void filter_callback(struct message_header_line *hdr,
+			    bool *matched, void *context ATTR_UNUSED)
+{
+	if (hdr != NULL && hdr->name_offset == 0) {
+		/* drop first header */
+		*matched = TRUE;
+	}
+}
+
+static void test_istream_filter(void)
+{
+	static const char *exclude_headers[] = { "To", NULL };
+	const char *input = "From: foo\nFrom: abc\nTo: bar\n\nhello world\n";
+	const char *output = "From: abc\n\nhello world\n";
+	struct istream *istream, *filter;
+	unsigned int i, input_len = strlen(input);
+	unsigned int output_len = strlen(output);
+	const unsigned char *data;
+	size_t size;
+	ssize_t ret;
+	bool success = TRUE;
+
+	istream = test_istream_create(input);
+	filter = i_stream_create_header_filter(istream,
+					       HEADER_FILTER_EXCLUDE |
+					       HEADER_FILTER_NO_CR,
+					       exclude_headers, 1,
+					       filter_callback, NULL);
+	for (i = 1; i <= input_len; i++) {
+		test_istream_set_size(istream, i);
+		ret = i_stream_read(filter);
+		if (ret < 0) {
+			success = FALSE;
+			break;
+		}
+	}
+	data = i_stream_get_data(filter, &size);
+	if (size != output_len || memcmp(data, output, size) != 0)
+		success = FALSE;
+
+	i_stream_skip(filter, size);
+	i_stream_seek(filter, 0);
+	while ((ret = i_stream_read(filter)) > 0) ;
+	data = i_stream_get_data(filter, &size);
+	if (size != output_len || memcmp(data, output, size) != 0)
+		success = FALSE;
+
+	i_stream_unref(&filter);
+	i_stream_unref(&istream);
+
+	test_out("i_stream_create_header_filter()", success);
+}
+
+int main(void)
+{
+	static void (*test_functions[])(void) = {
+		test_istream_filter,
+		NULL
+	};
+	return test_run(test_functions);
+}
diff -r 89d2dbbfa4ca -r aff3abbcb8a6 src/lib-mail/test-mail.c
--- a/src/lib-mail/test-mail.c	Tue May 26 14:21:59 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,369 +0,0 @@
-/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "str.h"
-#include "istream.h"
-#include "rfc822-parser.h"
-#include "rfc2231-parser.h"
-#include "message-address.h"
-#include "message-date.h"
-#include "message-parser.h"
-#include "istream-header-filter.h"
-#include "test-common.h"
-
-static const char test_msg[] =
-"Return-Path: <test at example.org>\n"
-"Subject: Hello world\n"
-"From: Test User <test at example.org>\n"
-"To: Another User <test2 at example.org>\n"
-"Message-Id: <1.2.3.4 at example>\n"
-"Mime-Version: 1.0\n"
-"Date: Sun, 23 May 2007 04:58:08 +0300\n"
-"Content-Type: multipart/signed; micalg=pgp-sha1;\n"
-"	protocol=\"application/pgp-signature\";\n"
-"	boundary=\"=-GNQXLhuj24Pl1aCkk4/d\"\n"
-"\n"
-"--=-GNQXLhuj24Pl1aCkk4/d\n"
-"Content-Type: text/plain\n"
-"Content-Transfer-Encoding: quoted-printable\n"
-"\n"
-"There was a day=20\n"
-"a happy=20day\n"
-"\n"
-"--=-GNQXLhuj24Pl1aCkk4/d\n"
-"Content-Type: application/pgp-signature; name=signature.asc\n"
-"\n"
-"-----BEGIN PGP SIGNATURE-----\n"
-"Version: GnuPG v1.2.4 (GNU/Linux)\n"
-"\n"
-"invalid\n"
-"-----END PGP SIGNATURE-----\n"
-"\n"
-"--=-GNQXLhuj24Pl1aCkk4/d--\n"
-"\n"
-"\n";
-#define TEST_MSG_LEN (sizeof(test_msg)-1)
-
-static bool cmp_addr(const struct message_address *a1,
-		     const struct message_address *a2)
-{
-	return null_strcmp(a1->name, a2->name) == 0 &&
-		null_strcmp(a1->route, a2->route) == 0 &&
-		null_strcmp(a1->mailbox, a2->mailbox) == 0 &&
-		null_strcmp(a1->domain, a2->domain) == 0 &&
-		a1->invalid_syntax == a2->invalid_syntax;
-}
-
-static void test_message_address(void)
-{
-	static const char *input[] = {
-		"user at domain",
-		"<user at domain>",
-		"foo bar <user at domain>",
-		"\"foo bar\" <user at domain>",
-		"<@route:user at domain>",
-		"<@route at route2:user at domain>",
-		"hello <@route , at route2:user at domain>",
-		"user (hello)",
-		"hello <user>",
-		"@domain"
-	};
-	static struct message_address group_prefix = {
-		NULL, NULL, NULL, "group", NULL, FALSE
-	};
-	static struct message_address group_suffix = {
-		NULL, NULL, NULL, NULL, NULL, FALSE
-	};
-	static struct message_address output[] = {
-		{ NULL, NULL, NULL, "user", "domain", FALSE },
-		{ NULL, NULL, NULL, "user", "domain", FALSE },
-		{ NULL, "foo bar", NULL, "user", "domain", FALSE },
-		{ NULL, "foo bar", NULL, "user", "domain", FALSE },
-		{ NULL, NULL, "@route", "user", "domain", FALSE },
-		{ NULL, NULL, "@route, at route2", "user", "domain", FALSE },
-		{ NULL, "hello", "@route, at route2", "user", "domain", FALSE },
-		{ NULL, "hello", NULL, "user", "", TRUE },
-		{ NULL, "hello", NULL, "user", "", TRUE },
-		{ NULL, NULL, NULL, "", "domain", TRUE }
-	};
-	struct message_address *addr;
-	string_t *group;
-	unsigned int i;
-	bool success;
-
-	group = t_str_new(256);
-	str_append(group, "group: ");
-
-	for (i = 0; i < N_ELEMENTS(input); i++) {
-		addr = message_address_parse(pool_datastack_create(),
-					     (const unsigned char *)input[i],
-					     strlen(input[i]), -1U, FALSE);
-		success = addr != NULL && addr->next == NULL &&
-			cmp_addr(addr, &output[i]);
-		test_out(t_strdup_printf("message_address_parse(%d)", i),
-			 success);
-
-		if (!output[i].invalid_syntax) {
-			if (i != 0) {
-				if ((i % 2) == 0)
-					str_append(group, ",");
-				else
-					str_append(group, " , \n ");
-			}
-			str_append(group, input[i]);
-		}
-	}
-	str_append_c(group, ';');
-
-	addr = message_address_parse(pool_datastack_create(), str_data(group),
-				     str_len(group), -1U, FALSE);
-	success = addr != NULL && cmp_addr(addr, &group_prefix);
-	addr = addr->next;
-	for (i = 0; i < N_ELEMENTS(input) && addr != NULL; i++) {
-		if (output[i].invalid_syntax)
-			continue;
-		if (!cmp_addr(addr, &output[i])) {
-			success = FALSE;
-			break;
-		}
-		addr = addr->next;
-	}
-	if (addr == NULL || addr->next != NULL ||
-	    !cmp_addr(addr, &group_suffix))
-		success = FALSE;
-	test_out("message_address_parse(group)", success);
-}
-
-struct test_message_date_output {
-	time_t time;
-	int tz_offset;
-	bool ret;
-};
-
-static void test_message_date_parse(void)
-{
-	static const char *input[] = {
-#ifdef TIME_T_SIGNED
-		"Thu, 01 Jan 1970 01:59:59 +0200",
-		"Fri, 13 Dec 1901 20:45:53 +0000",
-#endif
-#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
-		"Sun, 07 Feb 2106 06:28:15 +0000",
-#endif
-		"Wed, 07 Nov 2007 01:07:20 +0200",
-		"Wed, 07 Nov 2007 01:07:20",
-		"Thu, 01 Jan 1970 02:00:00 +0200",
-		"Tue, 19 Jan 2038 03:14:07 +0000",
-		"Tue, 19 Jan 2038"
-	};
-	static struct test_message_date_output output[] = {
-#ifdef TIME_T_SIGNED
-		{ -1, 2*60, TRUE },
-		{ -2147483647, 0, TRUE },
-#endif
-#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
-		{ 4294967295, 0, TRUE },
-#endif
-		{ 1194390440, 2*60, TRUE },
-		{ 1194397640, 0, TRUE },
-		{ 0, 2*60, TRUE },
-		{ 2147483647, 0, TRUE },
-		{ 0, 0, FALSE }
-	};
-	unsigned int i;
-	bool success;


More information about the dovecot-cvs mailing list