From 95bb29b6539cad7a9b384a5dd24bdc7ec2873ca1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 24 Jun 2011 00:24:04 +0300 Subject: [PATCH] * update / add test cases for threading --- src/tests/Makefile.am | 6 + src/tests/test-mu-msg.c | 30 +++- src/tests/test-mu-threads.c | 160 ++++++++++++++++++ .../cur/1305664394.2171_402.cthulhu!2, | 2 + src/tests/testdir3/cur/child0.0 | 9 + src/tests/testdir3/cur/child0.1 | 9 + src/tests/testdir3/cur/child0.1.0 | 9 + src/tests/testdir3/cur/child2.0.0 | 12 ++ src/tests/testdir3/cur/child3.0.0.0.0 | 9 + src/tests/testdir3/cur/child4.0 | 9 + src/tests/testdir3/cur/child4.1 | 9 + src/tests/testdir3/cur/root0 | 7 + src/tests/testdir3/cur/root1 | 7 + src/tests/testdir3/cur/root2 | 7 + 14 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 src/tests/test-mu-threads.c create mode 100644 src/tests/testdir3/cur/child0.0 create mode 100644 src/tests/testdir3/cur/child0.1 create mode 100644 src/tests/testdir3/cur/child0.1.0 create mode 100644 src/tests/testdir3/cur/child2.0.0 create mode 100644 src/tests/testdir3/cur/child3.0.0.0.0 create mode 100644 src/tests/testdir3/cur/child4.0 create mode 100644 src/tests/testdir3/cur/child4.1 create mode 100644 src/tests/testdir3/cur/root0 create mode 100644 src/tests/testdir3/cur/root1 create mode 100644 src/tests/testdir3/cur/root2 diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index c9cf0786..20a69171 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -22,6 +22,7 @@ INCLUDES=$(XAPIAN_CXXFLAGS) \ -I ${top_srcdir} -I ${top_srcdir}/src \ -DMU_TESTMAILDIR=\"${abs_srcdir}/testdir/\" \ -DMU_TESTMAILDIR2=\"${abs_srcdir}/testdir2/\" \ + -DMU_TESTMAILDIR3=\"${abs_srcdir}/testdir3/\" \ -DMU_PROGRAM=\"${abs_top_builddir}/src/mu\" \ -DABS_CURDIR=\"${abs_builddir}\" \ -DABS_SRCDIR=\"${abs_srcdir}\" @@ -81,6 +82,11 @@ TEST_PROGS += test-mu-store test_mu_store_SOURCES= test-mu-store.c dummy.cc test_mu_store_LDADD= libtestmucommon.la +TEST_PROGS += test-mu-threads +test_mu_threads_SOURCES= test-mu-threads.c dummy.cc +test_mu_threads_LDADD= libtestmucommon.la + + # TEST_PROGS += test-mu-msg-file # test_mu_msg_file_SOURCES= test-mu-msg-file.c dummy.cc # test_mu_msg_file_LDADD= libtestmucommon.la diff --git a/src/tests/test-mu-msg.c b/src/tests/test-mu-msg.c index 11ce1331..33eeeea0 100644 --- a/src/tests/test-mu-msg.c +++ b/src/tests/test-mu-msg.c @@ -241,6 +241,33 @@ test_mu_msg_umlaut (void) } +static void +test_mu_msg_references (void) +{ + MuMsg *msg; + const GSList *refs; + + msg = mu_msg_new_from_file (MU_TESTMAILDIR + "cur/1305664394.2171_402.cthulhu!2,", + NULL, NULL); + refs = mu_msg_get_references(msg); + + g_assert_cmpuint (g_slist_length ((GSList*)refs), ==, 4); + + g_assert_cmpstr ((char*)refs->data,==, "non-exist-01@msg.id"); + refs = g_slist_next (refs); + g_assert_cmpstr ((char*)refs->data,==, "non-exist-02@msg.id"); + refs = g_slist_next (refs); + g_assert_cmpstr ((char*)refs->data,==, "non-exist-03@msg.id"); + refs = g_slist_next (refs); + g_assert_cmpstr ((char*)refs->data,==, "non-exist-04@msg.id"); + refs = g_slist_next (refs); + + mu_msg_unref (msg); +} + + + static void test_mu_msg_tags (void) { @@ -280,7 +307,6 @@ test_mu_msg_comp_unix_programmer (void) msg = mu_msg_new_from_file (MU_TESTMAILDIR2 "bar/cur/181736.eml", NULL, NULL); - g_assert_cmpstr (mu_msg_get_to(msg), ==, NULL); g_assert_cmpstr (mu_msg_get_subject(msg), @@ -339,6 +365,8 @@ main (int argc, char *argv[]) test_mu_msg_04); g_test_add_func ("/mu-msg/mu-msg-tags", test_mu_msg_tags); + g_test_add_func ("/mu-msg/mu-msg-references", + test_mu_msg_references); g_test_add_func ("/mu-msg/mu-msg-umlaut", test_mu_msg_umlaut); g_test_add_func ("/mu-msg/mu-msg-comp-unix-programmer", diff --git a/src/tests/test-mu-threads.c b/src/tests/test-mu-threads.c new file mode 100644 index 00000000..b8f45259 --- /dev/null +++ b/src/tests/test-mu-threads.c @@ -0,0 +1,160 @@ +/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ + +/* +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 3, or (at your option) any +** later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /*HAVE_CONFIG_H*/ + +#include +#include + +#include +#include +#include + +#include "test-mu-common.h" +#include "src/mu-query.h" +#include "src/mu-str.h" + +static gchar* +fill_database (const char *testdir) +{ + gchar *cmdline, *tmpdir, *xpath; + + tmpdir = test_mu_common_get_random_tmpdir(); + cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" + " --quiet", + MU_PROGRAM, tmpdir, testdir); + g_print ("%s\n", cmdline); + + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, + NULL, NULL)); + g_free (cmdline); + xpath= g_strdup_printf ("%s%c%s", tmpdir, + G_DIR_SEPARATOR, "xapian"); + g_free (tmpdir); + + return xpath; +} + +/* note: this also *moves the iter* */ +static MuMsgIter* +run_and_get_iter (const char *xpath, const char *query) +{ + MuQuery *mquery; + MuMsgIter *iter; + + mquery = mu_query_new (xpath, NULL); + g_assert (query); + + iter = mu_query_run (mquery, query, TRUE, MU_MSG_FIELD_ID_NONE, + FALSE, NULL); + mu_query_destroy (mquery); + g_assert (iter); + + return iter; +} + + + + +static void +test_mu_threads_01 (void) +{ + gchar *xpath; + MuMsgIter *iter; + unsigned u; + + struct { + const char* threadpath; + const char *msgid; + const char* subject; + } items [] = { + {"0", "root0@msg.id", "root0"}, + {"0:0", "child0.0@msg.id", "Re: child 0.0"}, + {"0:1", "child0.1@msg.id", "Re: child 0.1"}, + {"0:1:0", "child0.1.0@msg.id", "Re: child 0.1.0"}, + {"1", "root1@msg.id", "root1"}, + {"2", "root2@msg.id", "root2"}, + /* next one's been promoted 2.0.0 => 2.0 */ + {"2:0", "child2.0.0@msg.id", "Re: child 2.0.0"}, + /* next one's been promoted 3.0.0.0.0 => 3 */ + {"3", "child3.0.0.0.0@msg.id", "Re: child 3.0.0.0"}, + + /* two children of absent root 4.0 */ + {"4:0", "child4.0@msg.id", "Re: child 4.0"}, + {"4:1", "child4.1@msg.id", "Re: child 4.1"} + }; + + xpath = fill_database (MU_TESTMAILDIR3); + g_assert (xpath != NULL); + + iter = run_and_get_iter (xpath, "abc"); + g_assert (iter); + g_assert (!mu_msg_iter_is_done(iter)); + + u = 0; + while (!mu_msg_iter_is_done (iter) && u < G_N_ELEMENTS(items)) { + MuMsg *msg; + const MuMsgIterThreadInfo *ti; + + ti = mu_msg_iter_get_thread_info (iter); + if (!ti) + g_print ("%s: thread info not found\n", + mu_msg_get_msgid(mu_msg_iter_get_msg (iter, NULL))); + + g_assert(ti); + + msg = mu_msg_iter_get_msg (iter, NULL); + + g_assert (u < G_N_ELEMENTS(items)); + + g_assert_cmpstr (ti->threadpath,==,items[u].threadpath); + g_assert_cmpstr (mu_msg_get_msgid(msg),==,items[u].msgid); + g_assert_cmpstr (mu_msg_get_subject(msg),==,items[u++].subject); + + mu_msg_iter_next (iter); + } + g_assert (u == G_N_ELEMENTS(items)); + + g_free (xpath); + mu_msg_iter_destroy (iter); +} + + +int +main (int argc, char *argv[]) +{ + int rv; + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/mu-query/test-mu-threads-01", test_mu_threads_01); + + /* 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 (); + + return rv; +} + diff --git a/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, b/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, index cea827fb..863f7144 100644 --- a/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, +++ b/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, @@ -2,6 +2,8 @@ From: =?UTF-8?B?TcO8?= To: Helmut =?UTF-8?B?S3LDtmdlcg==?= Subject: =?UTF-8?B?TW90w7ZyaGVhZA==?= User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/24.0 Mule/6.0 (HANACHIRUSATO) +References: +1n-Reply-To: MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/src/tests/testdir3/cur/child0.0 b/src/tests/testdir3/cur/child0.0 new file mode 100644 index 00000000..58da7d68 --- /dev/null +++ b/src/tests/testdir3/cur/child0.0 @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 0.0 +Message-Id: +References: +In-reply-to: +Date: Tue, 21 Jun 2011 11:10 +0000 + +abc diff --git a/src/tests/testdir3/cur/child0.1 b/src/tests/testdir3/cur/child0.1 new file mode 100644 index 00000000..163fadbd --- /dev/null +++ b/src/tests/testdir3/cur/child0.1 @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 0.1 +Message-Id: +References: +In-reply-to: +Date: Tue, 21 Jun 2011 11:20 +0000 + +abc diff --git a/src/tests/testdir3/cur/child0.1.0 b/src/tests/testdir3/cur/child0.1.0 new file mode 100644 index 00000000..40a9eb25 --- /dev/null +++ b/src/tests/testdir3/cur/child0.1.0 @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 0.1.0 +Message-Id: +References: +In-Reply-To: +Date: Tue, 21 Jun 2011 11:22 +0000 + +abc diff --git a/src/tests/testdir3/cur/child2.0.0 b/src/tests/testdir3/cur/child2.0.0 new file mode 100644 index 00000000..4e4446e9 --- /dev/null +++ b/src/tests/testdir3/cur/child2.0.0 @@ -0,0 +1,12 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 2.0.0 +Message-Id: +References: +In-Reply-To: +Date: Tue, 21 Jun 2011 15:02 +0000 + +abc + +note, there's no message for 'nonexistant@msg.id', so this msg should +be promoted to level 2.0 diff --git a/src/tests/testdir3/cur/child3.0.0.0.0 b/src/tests/testdir3/cur/child3.0.0.0.0 new file mode 100644 index 00000000..1e2f4abc --- /dev/null +++ b/src/tests/testdir3/cur/child3.0.0.0.0 @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 3.0.0.0 +Message-Id: +References: +1n-Reply-To: +Date: Wed, 22 Jun 2011 16:33 +0000 + +abc diff --git a/src/tests/testdir3/cur/child4.0 b/src/tests/testdir3/cur/child4.0 new file mode 100644 index 00000000..4e5256c1 --- /dev/null +++ b/src/tests/testdir3/cur/child4.0 @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 4.0 +Message-Id: +References: +In-reply-to: +Date: Tue, 24 Jun 2011 11:10 +0000 + +abc diff --git a/src/tests/testdir3/cur/child4.1 b/src/tests/testdir3/cur/child4.1 new file mode 100644 index 00000000..976fd00b --- /dev/null +++ b/src/tests/testdir3/cur/child4.1 @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: Re: child 4.1 +Message-Id: +References: +In-reply-to: +Date: Tue, 24 Jun 2011 11:20 +0000 + +abc diff --git a/src/tests/testdir3/cur/root0 b/src/tests/testdir3/cur/root0 new file mode 100644 index 00000000..deb64bb1 --- /dev/null +++ b/src/tests/testdir3/cur/root0 @@ -0,0 +1,7 @@ +From: testfrom@example.com +To: testto@example.com +Subject: root0 +Message-Id: +Date: Tue, 21 Jun 2011 11:00 +0000 + +abc diff --git a/src/tests/testdir3/cur/root1 b/src/tests/testdir3/cur/root1 new file mode 100644 index 00000000..fc3efd8e --- /dev/null +++ b/src/tests/testdir3/cur/root1 @@ -0,0 +1,7 @@ +From: testfrom@example.com +To: testto@example.com +Subject: root1 +Message-Id: +Date: Tue, 21 Jun 2011 12:00 +0000 + +abc diff --git a/src/tests/testdir3/cur/root2 b/src/tests/testdir3/cur/root2 new file mode 100644 index 00000000..6ba24516 --- /dev/null +++ b/src/tests/testdir3/cur/root2 @@ -0,0 +1,7 @@ +From: testfrom@example.com +To: testto@example.com +Subject: root2 +Message-Id: +Date: Tue, 21 Jun 2011 13:00 +0000 + +abc