* update / add test cases for threading

This commit is contained in:
Dirk-Jan C. Binnema 2011-06-24 00:24:04 +03:00
parent eb9b0c6de8
commit 95bb29b653
14 changed files with 284 additions and 1 deletions

View File

@ -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

View File

@ -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",

160
src/tests/test-mu-threads.c Normal file
View File

@ -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 <djcb@djcbsoftware.nl>
**
** 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 <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#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;
}

View File

@ -2,6 +2,8 @@ From: =?UTF-8?B?TcO8?= <testmu@testmu.xx>
To: Helmut =?UTF-8?B?S3LDtmdlcg==?= <hk@testmu.xxx>
Subject: =?UTF-8?B?TW90w7ZyaGVhZA==?=
User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/24.0 Mule/6.0 (HANACHIRUSATO)
References: <non-exist-01@msg.id> <non-exist-02@msg.id> <non-exist-03@msg.id> <non-exist-04@msg.id>
1n-Reply-To: <non-exist-04@msg.id>
MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

View File

@ -0,0 +1,9 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 0.0
Message-Id: <child0.0@msg.id>
References: <root0@msg.id>
In-reply-to: <root0@msg.id>
Date: Tue, 21 Jun 2011 11:10 +0000
abc

View File

@ -0,0 +1,9 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 0.1
Message-Id: <child0.1@msg.id>
References: <root0@msg.id>
In-reply-to: <root0@msg.id>
Date: Tue, 21 Jun 2011 11:20 +0000
abc

View File

@ -0,0 +1,9 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 0.1.0
Message-Id: <child0.1.0@msg.id>
References: <root0@msg.id> <child0.1@msg.id>
In-Reply-To: <child0.1@msg.id>
Date: Tue, 21 Jun 2011 11:22 +0000
abc

View File

@ -0,0 +1,12 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 2.0.0
Message-Id: <child2.0.0@msg.id>
References: <root2@msg.id> <nonexistant@msg.id>
In-Reply-To: <nonexistant@msg.id>
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

View File

@ -0,0 +1,9 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 3.0.0.0
Message-Id: <child3.0.0.0.0@msg.id>
References: <non-exist-01@msg.id> <non-exist-02@msg.id> <non-exist-03@msg.id> <non-exist-04@msg.id>
1n-Reply-To: <non-exist-04@msg.id>
Date: Wed, 22 Jun 2011 16:33 +0000
abc

View File

@ -0,0 +1,9 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 4.0
Message-Id: <child4.0@msg.id>
References: <root4@msg.id>
In-reply-to: <root4@msg.id>
Date: Tue, 24 Jun 2011 11:10 +0000
abc

View File

@ -0,0 +1,9 @@
From: testfrom@example.com
To: testto@example.com
Subject: Re: child 4.1
Message-Id: <child4.1@msg.id>
References: <root4@msg.id>
In-reply-to: <root4@msg.id>
Date: Tue, 24 Jun 2011 11:20 +0000
abc

View File

@ -0,0 +1,7 @@
From: testfrom@example.com
To: testto@example.com
Subject: root0
Message-Id: <root0@msg.id>
Date: Tue, 21 Jun 2011 11:00 +0000
abc

View File

@ -0,0 +1,7 @@
From: testfrom@example.com
To: testto@example.com
Subject: root1
Message-Id: <root1@msg.id>
Date: Tue, 21 Jun 2011 12:00 +0000
abc

View File

@ -0,0 +1,7 @@
From: testfrom@example.com
To: testto@example.com
Subject: root2
Message-Id: <root2@msg.id>
Date: Tue, 21 Jun 2011 13:00 +0000
abc