2011-06-23 23:24:04 +02:00
|
|
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
|
|
|
2011-08-30 20:59:05 +02:00
|
|
|
/*
|
2011-06-23 23:24:04 +02:00
|
|
|
** 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,
|
2011-08-30 20:59:05 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2011-06-23 23:24:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
2012-05-20 16:41:18 +02:00
|
|
|
#include "mu-query.h"
|
|
|
|
#include "mu-str.h"
|
2011-06-23 23:24:04 +02:00
|
|
|
|
|
|
|
static gchar*
|
|
|
|
fill_database (const char *testdir)
|
|
|
|
{
|
|
|
|
gchar *cmdline, *tmpdir, *xpath;
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
|
|
|
" --quiet",
|
|
|
|
MU_PROGRAM, tmpdir, testdir);
|
2012-12-27 14:59:38 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("%s\n", cmdline);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
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);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
return xpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: this also *moves the iter* */
|
|
|
|
static MuMsgIter*
|
|
|
|
run_and_get_iter (const char *xpath, const char *query)
|
|
|
|
{
|
|
|
|
MuQuery *mquery;
|
2011-08-30 20:59:05 +02:00
|
|
|
MuStore *store;
|
2011-06-23 23:24:04 +02:00
|
|
|
MuMsgIter *iter;
|
2011-08-30 20:59:05 +02:00
|
|
|
|
|
|
|
store = mu_store_new_read_only (xpath, NULL);
|
|
|
|
g_assert (store);
|
|
|
|
|
|
|
|
mquery = mu_query_new (store, NULL);
|
|
|
|
mu_store_unref (store);
|
2011-06-23 23:24:04 +02:00
|
|
|
g_assert (query);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2012-12-16 14:08:34 +01:00
|
|
|
iter = mu_query_run (mquery, query, MU_MSG_FIELD_ID_DATE,
|
2012-12-27 14:59:38 +01:00
|
|
|
-1, MU_QUERY_FLAG_THREADS, NULL);
|
2011-06-23 23:24:04 +02:00
|
|
|
mu_query_destroy (mquery);
|
|
|
|
g_assert (iter);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_threads_01 (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
2011-08-30 20:59:05 +02:00
|
|
|
MuMsgIter *iter;
|
2011-06-23 23:24:04 +02:00
|
|
|
unsigned u;
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
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"},
|
2011-08-30 20:59:05 +02:00
|
|
|
{"4:1", "child4.1@msg.id", "Re: child 4.1"}
|
2011-06-23 23:24:04 +02:00
|
|
|
};
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR3);
|
|
|
|
g_assert (xpath != NULL);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
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;
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
ti = mu_msg_iter_get_thread_info (iter);
|
|
|
|
if (!ti)
|
2011-08-30 20:59:05 +02:00
|
|
|
g_print ("%s: thread info not found for %u\n",
|
|
|
|
__FUNCTION__, (unsigned)mu_msg_iter_get_docid(iter));
|
2011-06-23 23:24:04 +02:00
|
|
|
g_assert(ti);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
|
|
|
msg = mu_msg_iter_get_msg_floating (iter);
|
|
|
|
g_assert (msg);
|
2012-12-27 14:59:38 +01:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("%s %s %s\n", ti->threadpath,
|
|
|
|
mu_msg_get_msgid(msg),
|
|
|
|
mu_msg_get_path (msg));
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
g_assert (u < G_N_ELEMENTS(items));
|
2011-06-30 22:43:08 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
g_assert_cmpstr (ti->threadpath,==,items[u].threadpath);
|
2011-06-30 22:43:08 +02:00
|
|
|
g_assert_cmpstr (mu_msg_get_subject(msg),==,items[u].subject);
|
2011-06-23 23:24:04 +02:00
|
|
|
g_assert_cmpstr (mu_msg_get_msgid(msg),==,items[u].msgid);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
++u;
|
|
|
|
mu_msg_iter_next (iter);
|
|
|
|
}
|
|
|
|
g_assert (u == G_N_ELEMENTS(items));
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
g_free (xpath);
|
|
|
|
mu_msg_iter_destroy (iter);
|
|
|
|
}
|
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
|
2011-08-15 23:02:32 +02:00
|
|
|
struct _tinfo {
|
|
|
|
const char* threadpath;
|
|
|
|
const char *msgid;
|
|
|
|
const char* subject;
|
|
|
|
};
|
|
|
|
typedef struct _tinfo tinfo;
|
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
static void
|
|
|
|
test_mu_threads_rogue (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
2011-08-30 20:59:05 +02:00
|
|
|
MuMsgIter *iter;
|
2011-06-30 22:43:08 +02:00
|
|
|
unsigned u;
|
2011-08-15 23:02:32 +02:00
|
|
|
tinfo *items;
|
|
|
|
|
|
|
|
tinfo items1 [] = {
|
2011-06-30 22:43:08 +02:00
|
|
|
{"0", "cycle0@msg.id", "cycle0"},
|
|
|
|
{"0:0", "cycle0.0@msg.id", "cycle0.0"},
|
2011-08-15 23:02:32 +02:00
|
|
|
{"0:0:0", "cycle0.0.0@msg.id", "cycle0.0.0"},
|
|
|
|
{"0:1", "rogue0@msg.id", "rogue0"},
|
2011-06-30 22:43:08 +02:00
|
|
|
};
|
2011-08-15 23:02:32 +02:00
|
|
|
|
|
|
|
tinfo items2 [] = {
|
|
|
|
{"0", "cycle0.0@msg.id", "cycle0.0"},
|
|
|
|
{"0:0", "cycle0@msg.id", "cycle0"},
|
|
|
|
{"0:0:0", "rogue0@msg.id", "rogue0" },
|
|
|
|
{"0:1", "cycle0.0.0@msg.id", "cycle0.0.0"}
|
|
|
|
};
|
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR3);
|
|
|
|
g_assert (xpath != NULL);
|
2011-08-15 23:02:32 +02:00
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
iter = run_and_get_iter (xpath, "def");
|
|
|
|
g_assert (iter);
|
|
|
|
g_assert (!mu_msg_iter_is_done(iter));
|
2011-08-30 20:59:05 +02:00
|
|
|
|
|
|
|
/* due to the random order in files can be indexed, there are two possible ways
|
2011-08-15 23:02:32 +02:00
|
|
|
* for the threads to be built-up; both are okay */
|
2011-08-30 20:59:05 +02:00
|
|
|
if (g_strcmp0 (mu_msg_get_msgid(mu_msg_iter_get_msg_floating (iter)),
|
2011-08-15 23:02:32 +02:00
|
|
|
"cycle0@msg.id") == 0)
|
|
|
|
items = items1;
|
|
|
|
else
|
|
|
|
items = items2;
|
2011-06-30 22:43:08 +02:00
|
|
|
|
|
|
|
u = 0;
|
2011-08-15 23:02:32 +02:00
|
|
|
while (!mu_msg_iter_is_done (iter) && u < G_N_ELEMENTS(items1)) {
|
2011-06-30 22:43:08 +02:00
|
|
|
MuMsg *msg;
|
|
|
|
const MuMsgIterThreadInfo *ti;
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
ti = mu_msg_iter_get_thread_info (iter);
|
|
|
|
if (!ti)
|
|
|
|
g_print ("%s: thread info not found\n",
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_msg_get_msgid(mu_msg_iter_get_msg_floating (iter)));
|
2011-06-30 22:43:08 +02:00
|
|
|
g_assert(ti);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
|
|
|
msg = mu_msg_iter_get_msg_floating (iter); /* don't unref */
|
2011-06-30 22:43:08 +02:00
|
|
|
/* g_print ("%s %s %s\n", ti->threadpath, */
|
|
|
|
/* mu_msg_get_msgid(msg), */
|
|
|
|
/* mu_msg_get_path (msg) */
|
|
|
|
/* ); */
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-08-15 23:02:32 +02:00
|
|
|
g_assert (u < G_N_ELEMENTS(items1));
|
2011-06-30 22:43:08 +02:00
|
|
|
|
2011-08-15 23:02:32 +02:00
|
|
|
g_assert_cmpstr (ti->threadpath,==,(items)[u].threadpath);
|
|
|
|
g_assert_cmpstr (mu_msg_get_subject(msg),==,(items)[u].subject);
|
|
|
|
g_assert_cmpstr (mu_msg_get_msgid(msg),==,(items)[u].msgid);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
++u;
|
2011-06-23 23:24:04 +02:00
|
|
|
mu_msg_iter_next (iter);
|
|
|
|
}
|
2011-08-15 23:02:32 +02:00
|
|
|
g_assert (u == G_N_ELEMENTS(items1));
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
g_free (xpath);
|
|
|
|
mu_msg_iter_destroy (iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int rv;
|
2011-08-30 20:59:05 +02:00
|
|
|
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
2011-06-23 23:24:04 +02:00
|
|
|
|
|
|
|
g_test_add_func ("/mu-query/test-mu-threads-01", test_mu_threads_01);
|
2011-06-30 22:43:08 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-threads-rogue", test_mu_threads_rogue);
|
2011-08-30 20:59:05 +02:00
|
|
|
|
|
|
|
g_log_set_handler (NULL,
|
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
|
|
|
(GLogFunc)black_hole, NULL);
|
2011-06-23 23:24:04 +02:00
|
|
|
|
|
|
|
rv = g_test_run ();
|
2011-08-30 20:59:05 +02:00
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
return rv;
|
|
|
|
}
|