* tests: add unit-tests for 'mu cfind'; fix up merge

This commit is contained in:
Dirk-Jan C. Binnema
2011-05-19 22:24:12 +03:00
parent 21cbf42d27
commit 68294e4d5c
4 changed files with 441 additions and 266 deletions

View File

@ -1,3 +1,5 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
@ -34,25 +36,25 @@
static gboolean
check_contact_01 (MuMsgContact *contact, int *idx)
{
switch (*idx) {
case 0:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, "Mickey Mouse");
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "anon@example.com");
break;
case 1:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, "Donald Duck");
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "gcc-help@gcc.gnu.org");
break;
default:
g_assert_not_reached ();
}
++(*idx);
switch (*idx) {
case 0:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, "Mickey Mouse");
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "anon@example.com");
break;
case 1:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, "Donald Duck");
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "gcc-help@gcc.gnu.org");
break;
default:
g_assert_not_reached ();
}
++(*idx);
return TRUE;
return TRUE;
}
@ -61,35 +63,36 @@ check_contact_01 (MuMsgContact *contact, int *idx)
static void
test_mu_msg_01 (void)
{
MuMsg *msg;
gint i;
MuMsg *msg;
gint i;
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1220863042.12663_1.mindcrime!2,S",
NULL, NULL);
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1220863042.12663_1.mindcrime!2,S",
NULL, NULL);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "Donald Duck <gcc-help@gcc.gnu.org>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "gcc include search order");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Mickey Mouse <anon@example.com>");
g_assert_cmpstr (mu_msg_get_msgid(msg),
==, "3BE9E6535E3029448670913581E7A1A20D852173@"
"emss35m06.us.lmco.com");
/* g_assert_cmpstr (mu_msg_get_header(msg, "Mailing-List"), */
/* ==, "contact gcc-help-help@gcc.gnu.org; run by ezmlm"); */
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'klub' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 1217530645);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "Donald Duck <gcc-help@gcc.gnu.org>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "gcc include search order");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Mickey Mouse <anon@example.com>");
g_assert_cmpstr (mu_msg_get_msgid(msg),
==, "3BE9E6535E3029448670913581E7A1A20D852173@"
"emss35m06.us.lmco.com");
g_assert_cmpstr (mu_msg_get_header(msg, "Mailing-List"),
==,
"contact gcc-help-help@gcc.gnu.org; run by ezmlm");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'klub' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 1217530645);
i = 0;
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)check_contact_01,
&i);
g_assert_cmpint (i,==,2);
i = 0;
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)check_contact_01,
&i);
g_assert_cmpint (i,==,2);
mu_msg_unref (msg);
mu_msg_unref (msg);
}
@ -97,25 +100,25 @@ test_mu_msg_01 (void)
static gboolean
check_contact_02 (MuMsgContact *contact, int *idx)
{
switch (*idx) {
case 0:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "anon@example.com");
break;
case 1:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "help-gnu-emacs@gnu.org");
break;
default:
g_assert_not_reached ();
}
++(*idx);
switch (*idx) {
case 0:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "anon@example.com");
break;
case 1:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address (contact),
==, "help-gnu-emacs@gnu.org");
break;
default:
g_assert_not_reached ();
}
++(*idx);
return TRUE;
return TRUE;
}
@ -123,118 +126,118 @@ check_contact_02 (MuMsgContact *contact, int *idx)
static void
test_mu_msg_02 (void)
{
MuMsg *msg;
int i;
MuMsg *msg;
int i;
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1220863087.12663_19.mindcrime!2,S",
NULL, NULL);
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1220863087.12663_19.mindcrime!2,S",
NULL, NULL);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "help-gnu-emacs@gnu.org");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "Re: Learning LISP; Scheme vs elisp.");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "anon@example.com");
g_assert_cmpstr (mu_msg_get_msgid(msg),
==, "r6bpm5-6n6.ln1@news.ducksburg.com");
/* g_assert_cmpstr (mu_msg_get_header(msg, "Errors-To"), */
/* ==, "help-gnu-emacs-bounces+xxxx.klub=gmail.com@gnu.org"); */
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_LOW);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 1218051515);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "help-gnu-emacs@gnu.org");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "Re: Learning LISP; Scheme vs elisp.");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "anon@example.com");
g_assert_cmpstr (mu_msg_get_msgid(msg),
==, "r6bpm5-6n6.ln1@news.ducksburg.com");
g_assert_cmpstr (mu_msg_get_header(msg, "Errors-To"),
==, "help-gnu-emacs-bounces+xxxx.klub=gmail.com@gnu.org");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_LOW);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 1218051515);
i = 0;
mu_msg_contact_foreach (msg,
(MuMsgContactForeachFunc)check_contact_02,
&i);
g_assert_cmpint (i,==,2);
i = 0;
mu_msg_contact_foreach (msg,
(MuMsgContactForeachFunc)check_contact_02,
&i);
g_assert_cmpint (i,==,2);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_SEEN);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_SEEN);
mu_msg_unref (msg);
mu_msg_unref (msg);
}
static void
test_mu_msg_03 (void)
{
MuMsg *msg;
MuMsg *msg;
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1283599333.1840_11.cthulhu!2,",
NULL, NULL);
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1283599333.1840_11.cthulhu!2,",
NULL, NULL);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "Bilbo Baggins <bilbo@anotherexample.com>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "Greetings from Lothlórien");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Frodo Baggins <frodo@example.com>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
g_assert_cmpstr (mu_msg_get_body_text(msg),
==,
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
g_assert_cmpstr (mu_msg_get_to(msg),
==, "Bilbo Baggins <bilbo@anotherexample.com>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "Greetings from Lothlórien");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Frodo Baggins <frodo@example.com>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
g_assert_cmpstr (mu_msg_get_body_text(msg),
==,
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_UNREAD);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_UNREAD);
mu_msg_unref (msg);
mu_msg_unref (msg);
}
static void
test_mu_msg_04 (void)
{
MuMsg *msg;
MuMsg *msg;
msg = mu_msg_new_from_file (MU_TESTMAILDIR2
"Foo/cur/mail5", NULL, NULL);
msg = mu_msg_new_from_file (MU_TESTMAILDIR2
"Foo/cur/mail5", NULL, NULL);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "George Custer <gac@example.com>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "pics for you");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Sitting Bull <sb@example.com>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "George Custer <gac@example.com>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "pics for you");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Sitting Bull <sb@example.com>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_HAS_ATTACH);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_HAS_ATTACH);
mu_msg_unref (msg);
mu_msg_unref (msg);
}
static void
test_mu_msg_05 (void)
{
MuMsg *msg;
MuMsg *msg;
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1305664394.2171_402.cthulhu!2,",
NULL, NULL);
msg = mu_msg_new_from_file (MU_TESTMAILDIR
"cur/1305664394.2171_402.cthulhu!2,",
NULL, NULL);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "Helmut Kröger <hk@testmu.xxx>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "Motörhead");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Mü <testmu@testmu.xx>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "Helmut Kröger <hk@testmu.xxx>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "Motörhead");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Mü <testmu@testmu.xx>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
mu_msg_unref (msg);
mu_msg_unref (msg);
}
@ -255,27 +258,27 @@ test_mu_msg_05 (void)
int
main (int argc, char *argv[])
{
int rv;
g_test_init (&argc, &argv, NULL);
int rv;
g_test_init (&argc, &argv, NULL);
/* mu_msg_str_date */
g_test_add_func ("/mu-msg/mu-msg-01",
test_mu_msg_01);
g_test_add_func ("/mu-msg/mu-msg-02",
test_mu_msg_02);
g_test_add_func ("/mu-msg/mu-msg-03",
test_mu_msg_03);
g_test_add_func ("/mu-msg/mu-msg-04",
test_mu_msg_04);
g_test_add_func ("/mu-msg/mu-msg-05",
test_mu_msg_05);
/* mu_msg_str_date */
g_test_add_func ("/mu-msg/mu-msg-01",
test_mu_msg_01);
g_test_add_func ("/mu-msg/mu-msg-02",
test_mu_msg_02);
g_test_add_func ("/mu-msg/mu-msg-03",
test_mu_msg_03);
g_test_add_func ("/mu-msg/mu-msg-04",
test_mu_msg_04);
g_test_add_func ("/mu-msg/mu-msg-05",
test_mu_msg_05);
g_log_set_handler (NULL,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
(GLogFunc)black_hole, NULL);
g_log_set_handler (NULL,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
(GLogFunc)black_hole, NULL);
rv = g_test_run ();
rv = g_test_run ();
return rv;
return rv;
}