summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul J Stevens <paul@nfg.nl>2009-02-07 16:07:31 +0100
committerPaul J Stevens <paul@nfg.nl>2009-02-07 16:07:31 +0100
commitf928d2f5050366799564aa4024bd9ee0f1cc2eee (patch)
tree10936f2b4454096fcc7a42227e3c7679b73ac0a7 /test
parent3707c31f0afcf59500106cb34719f0a46569ee9f (diff)
cleanup unittests for message reconstruction
also adds a test to exersize bug #681
Diffstat (limited to 'test')
-rw-r--r--test/check_dbmail.h34
-rw-r--r--test/check_dbmail_message.c245
2 files changed, 158 insertions, 121 deletions
diff --git a/test/check_dbmail.h b/test/check_dbmail.h
index 14cb0fe0..30a57caa 100644
--- a/test/check_dbmail.h
+++ b/test/check_dbmail.h
@@ -289,6 +289,39 @@ char *multipart_alternative = "From paul@nfg.nl Tue Oct 11 13:06:24 2005\n"
"7LF3kd0klwPUfuX7HS032seT7fokkkufZpP/2Q==\n"
"--------------050000030206040804030909--\n";
+const char *multipart_alternative2 = "Message-ID: <000e01c86e33$aaea2c00$0301a8c0@hercules.decimalint.pt>\n"
+ "From: trash <trash@decimal.pt>\n"
+ "To: trash@decimal.pt\n"
+ "Subject: =?iso-8859-1?B?5+fn?=\n"
+ "Date: Wed, 13 Feb 2008 11:29:16 -0000\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: multipart/alternative;\n"
+ " boundary=\"----=_NextPart_000_000B_01C86E33.AAE54A00\"\n"
+ "\n"
+ "This is a multi-part message in MIME format.\n"
+ "\n"
+ "------=_NextPart_000_000B_01C86E33.AAE54A00\n"
+ "Content-Type: text/plain;\n"
+ " charset=\"iso-8859-1\"\n"
+ "Content-Transfer-Encoding: quoted-printable\n"
+ "\n"
+ "------=_NextPart_000_000B_01C86E33.AAE54A00\n"
+ "Content-Type: text/html;\n"
+ " charset=\"iso-8859-1\"\n"
+ "Content-Transfer-Encoding: quoted-printable\n"
+ "\n"
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"
+ "<HTML><HEAD>\n"
+ "<META http-equiv=3DContent-Type content=3D\"text/html; =\n"
+ "charset=3Diso-8859-1\">\n"
+ "<META content=3D\"MSHTML 6.00.2900.3243\" name=3DGENERATOR>\n"
+ "<STYLE></STYLE>\n"
+ "</HEAD>\n"
+ "<BODY bgColor=3D#ffffff>\n"
+ "<DIV> </DIV></BODY></HTML>\n"
+ "\n"
+ "------=_NextPart_000_000B_01C86E33.AAE54A00--\n";
+
//
char *outlook_multipart = "From aprilbabies-bounces@lists.nfg.nl Fri Nov 25 22: 34:35 2005\n"
"From: \"Foo Bar\" <foobar@foo.bar>\n"
@@ -300,6 +333,7 @@ char *outlook_multipart = "From aprilbabies-bounces@lists.nfg.nl Fri Nov 25 22:
"Content-Type: multipart/mixed;\n"
" boundary=\"===============0825346837==\"\n"
"\n"
+ "\n"
"--===============0825346837==\n"
"Content-Type: text/plain;\n"
" charset=\"Windows-1252\"\n"
diff --git a/test/check_dbmail_message.c b/test/check_dbmail_message.c
index fba3ef65..743b60c8 100644
--- a/test/check_dbmail_message.c
+++ b/test/check_dbmail_message.c
@@ -108,33 +108,46 @@ START_TEST(test_dbmail_message_get_class)
dbmail_message_free(m);
}
END_TEST
+static char * showdiff(const char *a, const char *b)
+{
+ assert(a && b);
+ while (*a++ == *b++)
+ ;
+ if (--a && --b)
+ return g_strdup_printf("[%s]\n[%s]\n", a, b);
+ return NULL;
+}
FILE *i;
#define COMPARE(a,b) \
- unlink("/tmp/test1.txt"); unlink("/tmp/test2.txt"); \
- i = fopen("/tmp/test1.txt","w"); \
- fputs((char *)(a), i); \
- fclose(i);\
- i = fopen("/tmp/test2.txt","w"); \
- fputs((char *)(b), i); \
- fclose(i); \
- fail_unless(strcmp((a),(b)) == 0, "store store/retrieve failed. run: \n diff -y /tmp/test1.txt /tmp/test2.txt");
-
+ { \
+ int d; size_t l;\
+ l = strlen(a); \
+ d = memcmp((a),(b),l); \
+ fail_unless(d == 0, "store store/retrieve failed\n%s\n\n", showdiff(a,b)); \
+ }
-START_TEST(test_dbmail_message_store)
+static DbmailMessage * message_init(const char *message)
{
- DbmailMessage *m, *n;
- u64_t physid;
GString *s;
- char *t;
- char *expect;
+ DbmailMessage *m;
- s = g_string_new(multipart_message);
+ s = g_string_new(message);
m = dbmail_message_new();
m = dbmail_message_init_with_string(m, s);
- expect = dbmail_message_to_string(m);
+ g_string_free(s,TRUE);
+
fail_unless(m != NULL, "dbmail_message_init_with_string failed");
+ return m;
+
+}
+static char *store_and_retrieve(DbmailMessage *m)
+{
+ u64_t physid;
+ DbmailMessage *n;
+ char *t;
+
dbmail_message_store(m);
physid = dbmail_message_get_physid(m);
fail_unless(physid != 0,"dbmail_message_store failed. physid [%llu]", physid);
@@ -146,122 +159,113 @@ START_TEST(test_dbmail_message_store)
fail_unless(n != NULL, "_mime_retrieve failed");
t = dbmail_message_to_string(n);
+ dbmail_message_free(n);
+ return t;
+}
- COMPARE(expect,t);
+START_TEST(test_dbmail_message_store)
+{
+ DbmailMessage *m;
+ char *t, *e;
- dbmail_message_free(n);
- g_string_free(s,TRUE);
+ //-----------------------------------------
+ m = message_init(simple);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
g_free(t);
-
- return;
- //
//-----------------------------------------
- //
- s = g_string_new(simple);
- m = dbmail_message_new();
- m = dbmail_message_init_with_string(m, s);
- expect = dbmail_message_to_string(m);
- fail_unless(m != NULL, "dbmail_message_init_with_string failed");
-
- dbmail_message_store(m);
- physid = dbmail_message_get_physid(m);
- dbmail_message_free(m);
-
- n = dbmail_message_new();
- dbmail_message_set_physid(n, physid);
- n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_FULL);
- fail_unless(n != NULL, "_mime_retrieve failed");
-
- t = dbmail_message_to_string(n);
- COMPARE(expect,t);
-
- dbmail_message_free(n);
- g_string_free(s,TRUE);
- g_free(expect);
+ m = message_init(rfc822);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
g_free(t);
-
-
- //
//-----------------------------------------
- //
- s = g_string_new(rfc822);
- m = dbmail_message_new();
- m = dbmail_message_init_with_string(m, s);
- expect = dbmail_message_to_string(m);
- fail_unless(m != NULL, "dbmail_message_init_with_string failed");
-
- dbmail_message_store(m);
- physid = dbmail_message_get_physid(m);
- dbmail_message_free(m);
-
- n = dbmail_message_new();
- dbmail_message_set_physid(n, physid);
- n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_FULL);
- fail_unless(n != NULL, "_mime_retrieve failed");
-
- t = dbmail_message_to_string(n);
- COMPARE(expect,t);
-
- dbmail_message_free(n);
- g_string_free(s,TRUE);
- g_free(expect);
+ m = message_init(multipart_message);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
g_free(t);
-
- //
//-----------------------------------------
- //
- s = g_string_new(multipart_mixed);
- m = dbmail_message_new();
- m = dbmail_message_init_with_string(m, s);
- expect = dbmail_message_to_string(m);
- fail_unless(m != NULL, "dbmail_message_init_with_string failed");
-
- dbmail_message_store(m);
- physid = dbmail_message_get_physid(m);
- dbmail_message_free(m);
-
- n = dbmail_message_new();
- dbmail_message_set_physid(n, physid);
- n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_FULL);
- fail_unless(n != NULL, "_mime_retrieve failed");
-
- t = dbmail_message_to_string(n);
-
- COMPARE(expect,t);
-
- dbmail_message_free(n);
- g_string_free(s,TRUE);
- g_free(expect);
+ m = message_init(multipart_message2);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
g_free(t);
- //
//-----------------------------------------
- //
- //
- s = g_string_new(broken_message);
- m = dbmail_message_new();
- m = dbmail_message_init_with_string(m, s);
- fail_unless(m != NULL, "dbmail_message_init_with_string failed");
-
- expect = dbmail_message_to_string(m);
-
- dbmail_message_store(m);
- physid = dbmail_message_get_physid(m);
- dbmail_message_free(m);
-
- n = dbmail_message_new();
- dbmail_message_set_physid(n, physid);
- n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_FULL);
- fail_unless(n != NULL, "_mime_retrieve failed");
-
- t = dbmail_message_to_string(n);
-
+ m = message_init(multipart_mixed);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(broken_message);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
//COMPARE(expect,t);
-
- dbmail_message_free(n);
- g_string_free(s,TRUE);
- g_free(expect);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(encoded_message_latin_1);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(encoded_message_latin_2);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(encoded_message_utf8);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(encoded_message_koi);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(raw_message_koi);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(multipart_alternative);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(outlook_multipart);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
+ g_free(t);
+ //-----------------------------------------
+ m = message_init(multipart_alternative2);
+ e = dbmail_message_to_string(m);
+ t = store_and_retrieve(m);
+ COMPARE(e,t);
+ g_free(e);
g_free(t);
-
}
END_TEST
@@ -866,7 +870,6 @@ Suite *dbmail_message_suite(void)
suite_add_tcase(s, tc_message);
tcase_add_checked_fixture(tc_message, setup, teardown);
-
tcase_add_test(tc_message, test_dbmail_message_new);
tcase_add_test(tc_message, test_dbmail_message_new_from_stream);
tcase_add_test(tc_message, test_dbmail_message_set_class);