2011-05-20 20:32:44 +02:00
|
|
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
/*
|
2011-05-18 20:21:10 +02:00
|
|
|
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-01-31 13:14:19 +01:00
|
|
|
**
|
|
|
|
** 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-29 22:39:11 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-01-31 13:14:19 +01: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>
|
2011-07-21 07:20:10 +02:00
|
|
|
#include <locale.h>
|
2010-01-31 13:14:19 +01:00
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
#include "test-mu-common.h"
|
2012-05-20 16:41:18 +02:00
|
|
|
#include "mu-query.h"
|
|
|
|
#include "mu-str.h"
|
|
|
|
#include "mu-store.h"
|
2011-05-21 15:07:44 +02:00
|
|
|
|
2010-01-31 13:14:19 +01:00
|
|
|
static gchar*
|
2011-05-21 15:07:44 +02:00
|
|
|
fill_database (const char *testdir)
|
2010-01-31 13:14:19 +01:00
|
|
|
{
|
|
|
|
gchar *cmdline, *tmpdir, *xpath;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
2010-01-31 13:14:19 +01:00
|
|
|
" --quiet",
|
2011-05-21 15:07:44 +02:00
|
|
|
MU_PROGRAM, tmpdir, testdir);
|
2010-11-20 13:43:35 +01:00
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_printerr ("\n%s\n", cmdline);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-11-20 13:43:35 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
|
|
|
NULL, NULL));
|
2010-01-31 13:14:19 +01:00
|
|
|
g_free (cmdline);
|
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath= g_strdup_printf ("%s%c%s", tmpdir,
|
|
|
|
G_DIR_SEPARATOR, "xapian");
|
2010-01-31 13:14:19 +01:00
|
|
|
g_free (tmpdir);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-01-31 13:14:19 +01:00
|
|
|
return xpath;
|
|
|
|
}
|
|
|
|
|
2011-06-18 17:49:46 +02:00
|
|
|
static void
|
|
|
|
assert_no_dups (MuMsgIter *iter)
|
|
|
|
{
|
|
|
|
GHashTable *hash;
|
|
|
|
|
|
|
|
hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
(GDestroyNotify)g_free, NULL);
|
|
|
|
|
|
|
|
mu_msg_iter_reset (iter);
|
|
|
|
while (!mu_msg_iter_is_done(iter)) {
|
2011-08-30 20:59:05 +02:00
|
|
|
MuMsg *msg;
|
|
|
|
msg = mu_msg_iter_get_msg_floating (iter);
|
2011-06-18 17:49:46 +02:00
|
|
|
/* make sure there are no duplicates */
|
|
|
|
g_assert (!g_hash_table_lookup (hash, mu_msg_get_path (msg)));
|
|
|
|
g_hash_table_insert (hash, g_strdup (mu_msg_get_path(msg)),
|
|
|
|
GUINT_TO_POINTER(TRUE));
|
|
|
|
mu_msg_iter_next (iter);
|
|
|
|
}
|
|
|
|
mu_msg_iter_reset (iter);
|
|
|
|
g_hash_table_destroy (hash);
|
|
|
|
}
|
|
|
|
|
2010-09-05 12:01:33 +02:00
|
|
|
|
|
|
|
/* note: this also *moves the iter* */
|
2010-03-02 16:27:08 +01:00
|
|
|
static guint
|
2010-09-08 23:09:33 +02:00
|
|
|
run_and_count_matches (const char *xpath, const char *query)
|
2010-03-02 16:27:08 +01:00
|
|
|
{
|
2010-09-08 23:09:33 +02:00
|
|
|
MuQuery *mquery;
|
|
|
|
MuMsgIter *iter;
|
2011-08-30 20:59:05 +02:00
|
|
|
MuStore *store;
|
2011-06-02 17:13:17 +02:00
|
|
|
guint count1, count2;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
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);
|
2010-09-08 23:09:33 +02:00
|
|
|
g_assert (query);
|
2010-11-29 20:29:43 +01:00
|
|
|
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
if (g_test_verbose()) {
|
|
|
|
char *xs;
|
2012-01-21 10:19:15 +01:00
|
|
|
g_print ("\n==> query: %s\n", query);
|
2012-03-30 17:45:06 +02:00
|
|
|
xs = mu_query_preprocess (query, NULL);
|
2012-01-21 10:19:15 +01:00
|
|
|
g_print ("==> preproc: '%s'\n", xs);
|
|
|
|
g_free (xs);
|
2011-09-03 09:51:00 +02:00
|
|
|
xs = mu_query_as_string (mquery, query, NULL);
|
2012-01-21 10:19:15 +01:00
|
|
|
g_print ("==> xquery: '%s'\n", xs);
|
2011-09-03 09:51:00 +02:00
|
|
|
g_free (xs);
|
|
|
|
}
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2012-01-21 10:19:15 +01:00
|
|
|
|
2011-06-19 20:05:12 +02:00
|
|
|
iter = mu_query_run (mquery, query, FALSE, MU_MSG_FIELD_ID_NONE,
|
2011-12-07 07:15:48 +01:00
|
|
|
FALSE, -1, NULL);
|
2010-11-11 21:05:10 +01:00
|
|
|
mu_query_destroy (mquery);
|
2010-09-08 23:09:33 +02:00
|
|
|
g_assert (iter);
|
2010-11-20 13:43:35 +01:00
|
|
|
|
2011-06-18 17:49:46 +02:00
|
|
|
assert_no_dups (iter);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-02 17:13:17 +02:00
|
|
|
/* run query twice, to test mu_msg_iter_reset */
|
2011-08-29 22:39:11 +02:00
|
|
|
for (count1 = 0; !mu_msg_iter_is_done(iter);
|
2011-06-02 17:13:17 +02:00
|
|
|
mu_msg_iter_next(iter), ++count1);
|
|
|
|
|
2011-06-18 17:49:46 +02:00
|
|
|
mu_msg_iter_reset (iter);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-18 17:49:46 +02:00
|
|
|
assert_no_dups (iter);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-02 17:13:17 +02:00
|
|
|
for (count2 = 0; !mu_msg_iter_is_done(iter);
|
|
|
|
mu_msg_iter_next(iter), ++count2);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-09-08 23:09:33 +02:00
|
|
|
mu_msg_iter_destroy (iter);
|
2011-06-02 17:13:17 +02:00
|
|
|
|
|
|
|
g_assert_cmpuint (count1, ==, count2);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-02 17:13:17 +02:00
|
|
|
return count1;
|
2010-03-02 16:27:08 +01:00
|
|
|
}
|
|
|
|
|
2010-01-31 13:14:19 +01:00
|
|
|
typedef struct {
|
|
|
|
const char *query;
|
|
|
|
size_t count; /* expected number of matches */
|
|
|
|
} QResults;
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_query_01 (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-01-31 13:14:19 +01:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "basic", 3 },
|
|
|
|
{ "question", 5 },
|
|
|
|
{ "thanks", 2 },
|
|
|
|
{ "html", 4 },
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "subject:elisp", 1 },
|
2010-01-31 13:14:19 +01:00
|
|
|
{ "html AND contains", 1 },
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "html and contains", 1 },
|
2010-09-04 13:37:19 +02:00
|
|
|
{ "from:pepernoot", 0 },
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "foo:pepernoot", 0 },
|
2010-11-11 21:05:10 +01:00
|
|
|
{ "funky", 1 },
|
2010-09-26 14:23:17 +02:00
|
|
|
{ "fünkÿ", 1 },
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "", 17 }
|
2010-01-31 13:14:19 +01:00
|
|
|
};
|
2010-11-27 15:07:24 +01:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2010-01-31 13:14:19 +01:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2010-09-08 23:09:33 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
2010-11-27 15:07:24 +01:00
|
|
|
|
2010-01-31 13:14:19 +01:00
|
|
|
g_free (xpath);
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:48:13 +01:00
|
|
|
static void
|
|
|
|
test_mu_query_02 (void)
|
|
|
|
{
|
|
|
|
const char* q;
|
|
|
|
gchar *xpath;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2010-09-08 23:09:33 +02:00
|
|
|
g_assert (xpath);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-02-09 21:11:15 +01:00
|
|
|
q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com";
|
2010-02-04 21:48:13 +01:00
|
|
|
|
2010-09-08 23:09:33 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches(xpath, q), ==, 1);
|
2010-02-04 21:48:13 +01:00
|
|
|
g_free (xpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-02 16:27:08 +01:00
|
|
|
static void
|
|
|
|
test_mu_query_03 (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-03-02 16:27:08 +01:00
|
|
|
QResults queries[] = {
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "ploughed", 1},
|
2010-11-20 13:43:35 +01:00
|
|
|
{ "i:3BE9E6535E3029448670913581E7A1A20D852173@"
|
|
|
|
"emss35m06.us.lmco.com", 1},
|
2010-11-11 21:05:10 +01:00
|
|
|
|
|
|
|
/* subsets of the words in the subject should match */
|
|
|
|
{ "s:gcc include search order" , 1},
|
|
|
|
{ "s:gcc include search" , 1},
|
|
|
|
{ "s:search order" , 1},
|
|
|
|
{ "s:include" , 1},
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-11-11 21:05:10 +01:00
|
|
|
{ "s:lisp", 1},
|
|
|
|
{ "s:LISP", 1},
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2012-01-21 10:19:15 +01:00
|
|
|
{ "s:\"Re: Learning LISP; Scheme vs elisp.\"", 1},
|
|
|
|
{ "subject:Re: Learning LISP; Scheme vs elisp.", 0},
|
|
|
|
{ "subject:\"Re: Learning LISP; Scheme vs elisp.\"", 1},
|
2010-11-11 21:05:10 +01:00
|
|
|
{ "to:help-gnu-emacs@gnu.org", 4},
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "t:help-gnu-emacs", 0},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "flag:flagged", 1}
|
2010-03-02 16:27:08 +01:00
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2010-09-12 15:33:18 +02:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-09-08 23:09:33 +02:00
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
2010-03-02 16:27:08 +01:00
|
|
|
g_free (xpath);
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:48:13 +01:00
|
|
|
|
2010-09-05 12:01:33 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_04 (void)
|
2010-09-12 15:33:18 +02:00
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-09-12 15:33:18 +02:00
|
|
|
QResults queries[] = {
|
2012-05-04 19:58:34 +02:00
|
|
|
{ "frodo@example.com", 1},
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "f:frodo@example.com", 1},
|
|
|
|
{ "f:Frodo Baggins", 1},
|
2012-05-04 19:58:34 +02:00
|
|
|
{ "bilbo@anotherexample.com", 1},
|
2010-09-12 15:33:18 +02:00
|
|
|
{ "t:bilbo@anotherexample.com", 1},
|
|
|
|
{ "t:bilbo", 1},
|
|
|
|
{ "f:bilbo", 0},
|
2010-11-21 14:41:25 +01:00
|
|
|
{ "baggins", 1},
|
2011-05-20 20:32:44 +02:00
|
|
|
{ "prio:h", 1},
|
2010-11-21 14:41:25 +01:00
|
|
|
{ "prio:high", 1},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "prio:normal", 9},
|
2010-11-21 14:41:25 +01:00
|
|
|
{ "prio:l", 7},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "not prio:l", 10},
|
2010-09-12 15:33:18 +02:00
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2010-09-12 15:33:18 +02:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2010-09-12 15:33:18 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
g_free (xpath);
|
2012-05-04 19:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_query_logic (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
QResults queries[] = {
|
|
|
|
{ "subject:gcc" , 1},
|
|
|
|
{ "subject:lisp" , 1},
|
|
|
|
{ "subject:gcc OR subject:lisp" , 2},
|
|
|
|
{ "subject:gcc or subject:lisp" , 2},
|
|
|
|
{ "subject:gcc AND subject:lisp" , 0},
|
|
|
|
|
|
|
|
{ "subject:gcc OR (subject:scheme AND subject:elisp)" , 2},
|
|
|
|
{ "(subject:gcc OR subject:scheme) AND subject:elisp" , 1}
|
|
|
|
};
|
2010-09-12 15:33:18 +02:00
|
|
|
|
2012-05-04 19:58:34 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
|
|
|
g_assert (xpath != NULL);
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
g_free (xpath);
|
2010-09-12 15:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-04 19:58:34 +02:00
|
|
|
|
|
|
|
|
2010-09-12 15:33:18 +02:00
|
|
|
static void
|
2011-05-20 20:32:44 +02:00
|
|
|
test_mu_query_accented_chars_01 (void)
|
2010-09-05 12:01:33 +02:00
|
|
|
{
|
|
|
|
MuQuery *query;
|
|
|
|
MuMsgIter *iter;
|
|
|
|
MuMsg *msg;
|
2011-08-30 20:59:05 +02:00
|
|
|
MuStore *store;
|
2010-09-05 12:01:33 +02:00
|
|
|
gchar *xpath;
|
2011-03-21 00:56:32 +01:00
|
|
|
GError *err;
|
2011-05-15 09:40:29 +02:00
|
|
|
gchar *summ;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2010-09-05 12:01:33 +02:00
|
|
|
g_assert (xpath != NULL);
|
2010-11-21 12:43:40 +01:00
|
|
|
|
2011-08-30 20:59:05 +02:00
|
|
|
store = mu_store_new_read_only (xpath, NULL);
|
|
|
|
g_assert (store);
|
|
|
|
|
|
|
|
query = mu_query_new (store, NULL);
|
|
|
|
mu_store_unref (store);
|
|
|
|
|
2011-06-19 20:05:12 +02:00
|
|
|
iter = mu_query_run (query, "fünkÿ", FALSE, MU_MSG_FIELD_ID_NONE,
|
2011-12-07 07:15:48 +01:00
|
|
|
FALSE, -1, NULL);
|
2011-03-21 00:56:32 +01:00
|
|
|
err = NULL;
|
2011-08-30 20:59:05 +02:00
|
|
|
msg = mu_msg_iter_get_msg_floating (iter); /* don't unref */
|
2011-03-21 00:56:32 +01:00
|
|
|
if (!msg) {
|
|
|
|
g_warning ("error getting message: %s", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
g_assert_cmpstr (mu_msg_get_subject(msg),==,
|
2010-09-05 12:01:33 +02:00
|
|
|
"Greetings from Lothlórien");
|
2011-05-14 17:07:07 +02:00
|
|
|
/* TODO: fix this again */
|
2011-05-15 09:40:29 +02:00
|
|
|
|
|
|
|
summ = mu_str_summarize (mu_msg_get_body_text(msg), 5);
|
|
|
|
g_assert_cmpstr (summ,==, "Let's write some fünkÿ text using umlauts. Foo.");
|
|
|
|
g_free (summ);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-09-05 12:01:33 +02:00
|
|
|
mu_msg_iter_destroy (iter);
|
|
|
|
mu_query_destroy (query);
|
|
|
|
g_free (xpath);
|
|
|
|
}
|
|
|
|
|
2011-05-17 23:00:10 +02:00
|
|
|
static void
|
2011-05-20 20:32:44 +02:00
|
|
|
test_mu_query_accented_chars_02 (void)
|
2011-05-17 23:00:10 +02:00
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-17 23:00:10 +02:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "f:mü", 1},
|
|
|
|
{ "s:motörhead", 1},
|
2011-05-17 23:15:52 +02:00
|
|
|
{ "t:Helmut", 1},
|
2011-08-29 22:39:11 +02:00
|
|
|
{ "t:Kröger", 1},
|
2011-05-17 23:00:10 +02:00
|
|
|
{ "s:MotorHeäD", 1},
|
|
|
|
{ "queensryche", 1},
|
|
|
|
{ "Queensrÿche", 1},
|
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2011-05-17 23:00:10 +02:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-05-17 23:00:10 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
g_free (xpath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_wildcards (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "f:mü", 1},
|
|
|
|
{ "s:mo*", 1},
|
|
|
|
{ "t:Helm*", 1},
|
|
|
|
{ "queensryche", 1},
|
|
|
|
{ "Queen*", 1},
|
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2011-05-20 20:32:44 +02:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-05-20 20:32:44 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
g_free (xpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_query_dates_helsinki (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
|
|
|
const char *old_tz;
|
|
|
|
|
|
|
|
QResults queries[] = {
|
|
|
|
{ "date:20080731..20080804", 5},
|
|
|
|
/* { "date:20080804..20080731", 5}, */
|
|
|
|
{ "date:20080731..20080804", 5},
|
|
|
|
{ "date:20080731..20080804 s:gcc", 1},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "date:200808110803..now", 5},
|
|
|
|
{ "date:200808110803..today", 5},
|
2011-07-20 23:39:00 +02:00
|
|
|
/* { "date:now..2008-08-11-08-03", 1}, */
|
|
|
|
/* { "date:today..2008-08-11-08-03", 1}, */
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "date:200808110801..now", 5},
|
2011-07-20 23:39:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
old_tz = set_tz ("Europe/Helsinki");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-07-20 23:39:00 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
|
|
|
g_free (xpath);
|
|
|
|
set_tz (old_tz);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
}
|
2011-05-20 20:32:44 +02:00
|
|
|
|
|
|
|
static void
|
2011-07-20 23:39:00 +02:00
|
|
|
test_mu_query_dates_sydney (void)
|
2011-05-20 20:32:44 +02:00
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-07-20 23:39:00 +02:00
|
|
|
const char *old_tz;
|
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "date:20080731..20080804", 5},
|
2011-07-16 11:50:17 +02:00
|
|
|
/* { "date:20080804..20080731", 5}, */
|
2011-07-20 23:39:00 +02:00
|
|
|
{ "date:20080731..20080804", 5},
|
|
|
|
{ "date:20080731..20080804 s:gcc", 1},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "date:200808110803..now", 5},
|
|
|
|
{ "date:200808110803..today", 5},
|
2011-07-16 11:50:17 +02:00
|
|
|
/* { "date:now..2008-08-11-08-03", 1}, */
|
|
|
|
/* { "date:today..2008-08-11-08-03", 1}, */
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "date:200808110801..now", 5},
|
2011-05-20 20:32:44 +02:00
|
|
|
};
|
2011-07-20 23:39:00 +02:00
|
|
|
|
|
|
|
old_tz = set_tz ("Australia/Sydney");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2011-05-20 20:32:44 +02:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-05-20 20:32:44 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
|
|
|
g_free (xpath);
|
2011-07-20 23:39:00 +02:00
|
|
|
set_tz (old_tz);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
}
|
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_dates_la (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
|
|
|
const char *old_tz;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "date:20080731..20080804", 5},
|
|
|
|
/* { "date:20080804..20080731", 5}, */
|
|
|
|
{ "date:20080731..20080804", 5},
|
|
|
|
{ "date:20080731..20080804 s:gcc", 1},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "date:200808110803..now", 4},
|
|
|
|
{ "date:200808110803..today", 4},
|
2011-07-20 23:39:00 +02:00
|
|
|
/* { "date:now..2008-08-11-08-03", 1}, */
|
|
|
|
/* { "date:today..2008-08-11-08-03", 1}, */
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "date:200808110801..now", 4}, /* does not match in LA */
|
2011-07-20 23:39:00 +02:00
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
old_tz = set_tz ("America/Los_Angeles");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-20 23:39:00 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-07-20 23:39:00 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
|
|
|
g_free (xpath);
|
|
|
|
set_tz (old_tz);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_query_sizes (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
QResults queries[] = {
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "size:0b..2m", 17},
|
2012-05-11 17:39:00 +02:00
|
|
|
{ "size:2k..4k", 4},
|
2012-05-20 09:57:23 +02:00
|
|
|
{ "size:2m..0b", 17}
|
2011-05-20 20:32:44 +02:00
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
2011-05-20 20:32:44 +02:00
|
|
|
g_assert (xpath != NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-05-20 20:32:44 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
|
|
|
g_free (xpath);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_attach (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
QResults queries[] = {
|
2011-11-23 23:15:21 +01:00
|
|
|
{ "j:sittingbull.jpg", 1},
|
|
|
|
{ "file:custer", 0},
|
|
|
|
{ "file:custer.jpg", 1}
|
2011-05-21 15:07:44 +02:00
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR2);
|
|
|
|
g_assert (xpath != NULL);
|
|
|
|
|
|
|
|
/* g_print ("(%s)\n", xpath); */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-10 13:08:16 +02:00
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-05-21 15:07:44 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
g_free (xpath);
|
2011-05-21 15:07:44 +02:00
|
|
|
}
|
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
|
2011-06-16 06:59:23 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_tags (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-16 06:59:23 +02:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "x:paradise", 1},
|
|
|
|
{ "tag:lost", 1},
|
|
|
|
{ "tag:lost tag:paradise", 1},
|
|
|
|
{ "tag:lost tag:horizon", 0},
|
|
|
|
{ "tag:lost OR tag:horizon", 1},
|
|
|
|
{ "x:paradise,lost", 0},
|
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-16 06:59:23 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR2);
|
|
|
|
g_assert (xpath != NULL);
|
|
|
|
|
|
|
|
/* g_print ("(%s)\n", xpath); */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
2011-06-16 06:59:23 +02:00
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
g_free (xpath);
|
2011-06-16 06:59:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-11 17:39:00 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_signed_encrypted (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
QResults queries[] = {
|
|
|
|
{ "flag:encrypted", 2},
|
|
|
|
{ "flag:signed", 2},
|
|
|
|
};
|
|
|
|
|
|
|
|
xpath = fill_database (MU_TESTMAILDIR);
|
|
|
|
g_assert (xpath != NULL);
|
|
|
|
|
|
|
|
/* g_print ("(%s)\n", xpath); */
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
|
|
|
|
g_free (xpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-10 13:08:16 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_tags_02 (void)
|
|
|
|
{
|
|
|
|
gchar *xpath;
|
|
|
|
int i;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-10 13:08:16 +02:00
|
|
|
QResults queries[] = {
|
|
|
|
{ "x:paradise", 1},
|
|
|
|
{ "tag:@NextActions", 1},
|
|
|
|
{ "x:queensrÿche", 1},
|
2011-10-23 23:20:05 +02:00
|
|
|
{ "tag:lost OR tag:operation*", 2},
|
2011-07-10 13:08:16 +02:00
|
|
|
};
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-10 13:08:16 +02:00
|
|
|
xpath = fill_database (MU_TESTMAILDIR2);
|
|
|
|
g_assert (xpath != NULL);
|
|
|
|
|
|
|
|
/* g_print ("(%s)\n", xpath); */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-10 13:08:16 +02:00
|
|
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
|
|
|
/* g_print ("%s\n", queries[i].query); */
|
|
|
|
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
|
|
==, queries[i].count);
|
|
|
|
}
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
g_free (xpath);
|
2011-07-10 13:08:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-30 17:45:06 +02:00
|
|
|
static void
|
|
|
|
test_mu_query_preprocess (void)
|
|
|
|
{
|
|
|
|
unsigned u;
|
|
|
|
struct {
|
|
|
|
const gchar *expr, *expected;
|
|
|
|
} testcases [] = {
|
|
|
|
{ "hello", "hello" },
|
|
|
|
{ "/[Gmail].Sent Mail", "__gmail__sent mail" }
|
|
|
|
/* add more */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (u = 0; u != G_N_ELEMENTS(testcases); ++u) {
|
|
|
|
gchar *prep;
|
|
|
|
prep = mu_query_preprocess (testcases[u].expr, NULL);
|
|
|
|
g_assert_cmpstr (prep, ==, testcases[u].expected);
|
|
|
|
g_free (prep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-10 13:08:16 +02:00
|
|
|
|
2010-01-31 13:14:19 +01:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-11-27 15:07:24 +01:00
|
|
|
int rv;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
2012-03-30 17:45:06 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-preprocess",
|
|
|
|
test_mu_query_preprocess);
|
|
|
|
|
2010-03-02 16:27:08 +01:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-01", test_mu_query_01);
|
2011-08-29 22:39:11 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-02", test_mu_query_02);
|
2010-09-12 15:33:18 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03);
|
2010-09-05 12:01:33 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-04", test_mu_query_04);
|
2012-05-04 19:58:34 +02:00
|
|
|
|
2012-05-11 17:39:00 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-signed-encrypted",
|
|
|
|
test_mu_query_signed_encrypted);
|
|
|
|
|
2012-05-04 19:58:34 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-logic", test_mu_query_logic);
|
|
|
|
|
2011-05-20 20:32:44 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-accented-chars-1",
|
|
|
|
test_mu_query_accented_chars_01);
|
|
|
|
g_test_add_func ("/mu-query/test-mu-query-accented-chars-2",
|
|
|
|
test_mu_query_accented_chars_02);
|
|
|
|
g_test_add_func ("/mu-query/test-mu-query-wildcards",
|
|
|
|
test_mu_query_wildcards);
|
2011-05-21 08:14:02 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-sizes",
|
|
|
|
test_mu_query_sizes);
|
2011-07-20 23:39:00 +02:00
|
|
|
|
|
|
|
g_test_add_func ("/mu-query/test-mu-query-dates-helsinki",
|
|
|
|
test_mu_query_dates_helsinki); /* finland */
|
|
|
|
g_test_add_func ("/mu-query/test-mu-query-dates-sydney",
|
|
|
|
test_mu_query_dates_sydney);
|
|
|
|
g_test_add_func ("/mu-query/test-mu-query-dates-la",
|
|
|
|
test_mu_query_dates_la);
|
|
|
|
|
2011-05-21 15:07:44 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-attach",
|
|
|
|
test_mu_query_attach);
|
2011-06-16 06:59:23 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-tags",
|
|
|
|
test_mu_query_tags);
|
2011-07-10 13:08:16 +02:00
|
|
|
g_test_add_func ("/mu-query/test-mu-query-tags_02",
|
|
|
|
test_mu_query_tags_02);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
if (!g_test_verbose())
|
|
|
|
g_log_set_handler (NULL,
|
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
|
|
|
(GLogFunc)black_hole, NULL);
|
2010-11-27 15:07:24 +01:00
|
|
|
|
|
|
|
rv = g_test_run ();
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2010-11-27 15:07:24 +01:00
|
|
|
return rv;
|
2010-01-31 13:14:19 +01:00
|
|
|
}
|