diff --git a/src/tests/test-mu-msg-gmime.c b/src/tests/test-mu-msg-gmime.c index 56d056f8..84717c60 100644 --- a/src/tests/test-mu-msg-gmime.c +++ b/src/tests/test-mu-msg-gmime.c @@ -49,12 +49,25 @@ get_mailpath (unsigned idx) } +static gboolean +each_contact (MuMsgContact *contact, GSList **lst) +{ + char *addr; + addr = g_strdup_printf ("%s <%s>", + contact->name ? contact->name : "", + contact->address ? contact->address : ""); + + *lst = g_slist_append (*lst, addr); + return TRUE; +} + static void test_mu_msg_gmime_01 (void) { char *mfile; MuMsgGMime *msg; + GSList *lst; mu_msg_gmime_init (); mfile = get_mailpath (1); @@ -70,17 +83,85 @@ test_mu_msg_gmime_01 (void) g_assert_cmpstr (mu_msg_gmime_get_msgid(msg), ==, "3BE9E6535E3029448670913581E7A1A20D852173@" "emss35m06.us.lmco.com"); + g_assert_cmpstr (mu_msg_gmime_get_header(msg, "Mailing-List"), + ==, "contact gcc-help-help@gcc.gnu.org; run by ezmlm"); g_assert_cmpuint (mu_msg_gmime_get_priority(msg), /* 'klub' */ ==, MU_MSG_PRIORITY_NORMAL); g_assert_cmpuint (mu_msg_gmime_get_date(msg), ==, 1217530645); - + { + GSList *lst, *cur; + lst = NULL; + mu_msg_gmime_contacts_foreach (msg, + (MuMsgGMimeContactsForeachFunc)each_contact, + &lst); + g_assert_cmpuint (g_slist_length(lst),==, 1); + cur = lst; + g_assert_cmpstr ((const char*)cur->data, ==, + " "); + + g_slist_foreach (lst, (GFunc)g_free, NULL); + g_slist_free (lst); + } + mu_msg_gmime_destroy (msg); g_free (mfile); mu_msg_gmime_uninit (); } + + +static void +test_mu_msg_gmime_02 (void) +{ + char *mfile; + MuMsgGMime *msg; + GSList *lst; + + mu_msg_gmime_init (); + mfile = get_mailpath (2); + + msg = mu_msg_gmime_new (mfile, NULL); + + g_assert_cmpstr (mu_msg_gmime_get_to(msg), + ==, "help-gnu-emacs@gnu.org"); + g_assert_cmpstr (mu_msg_gmime_get_subject(msg), + ==, "Re: Learning LISP; Scheme vs elisp."); + g_assert_cmpstr (mu_msg_gmime_get_from(msg), + ==, "anon@example.com"); + g_assert_cmpstr (mu_msg_gmime_get_msgid(msg), + ==, "r6bpm5-6n6.ln1@news.ducksburg.com"); + g_assert_cmpstr (mu_msg_gmime_get_header(msg, "Errors-To"), + ==, "help-gnu-emacs-bounces+xxxx.klub=gmail.com@gnu.org"); + g_assert_cmpuint (mu_msg_gmime_get_priority(msg), /* 'low' */ + ==, MU_MSG_PRIORITY_LOW); + g_assert_cmpuint (mu_msg_gmime_get_date(msg), + ==, 1218051515); + { + GSList *lst, *cur; + lst = NULL; + mu_msg_gmime_contacts_foreach (msg, + (MuMsgGMimeContactsForeachFunc)each_contact, + &lst); + g_assert_cmpuint (g_slist_length(lst),==, 1); + cur = lst; + g_assert_cmpstr ((const char*)cur->data, ==, + " "); + + g_slist_foreach (lst, (GFunc)g_free, NULL); + g_slist_free (lst); + } + + mu_msg_gmime_destroy (msg); + + g_free (mfile); + mu_msg_gmime_uninit (); +} + + + + static gboolean ignore_error (const char* log_domain, GLogLevelFlags log_level, const gchar* msg, gpointer user_data) @@ -99,9 +180,11 @@ main (int argc, char *argv[]) g_test_init (&argc, &argv, NULL); /* mu_msg_str_date */ - g_test_add_func ("/mu-msg-gmime/mu-msg-gmime", + g_test_add_func ("/mu-msg-gmime/mu-msg-gmime-01", test_mu_msg_gmime_01); - + g_test_add_func ("/mu-msg-gmime/mu-msg-gmime-02", + test_mu_msg_gmime_02); + g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, (GLogFunc)shutup, NULL);