mirror of
https://github.com/djcb/mu.git
synced 2024-06-29 07:51:04 +02:00
* test-mu-query: speed up
This commit is contained in:
parent
57b26259f7
commit
6c3a11d1a6
|
@ -1,7 +1,7 @@
|
||||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -36,6 +36,9 @@
|
||||||
#include "mu-str.h"
|
#include "mu-str.h"
|
||||||
#include "mu-store.h"
|
#include "mu-store.h"
|
||||||
|
|
||||||
|
static char* DB_PATH1 = NULL;
|
||||||
|
static char* DB_PATH2 = NULL;
|
||||||
|
|
||||||
static gchar*
|
static gchar*
|
||||||
fill_database (const char *testdir)
|
fill_database (const char *testdir)
|
||||||
{
|
{
|
||||||
|
@ -60,6 +63,8 @@ fill_database (const char *testdir)
|
||||||
return xpath;
|
return xpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
assert_no_dups (MuMsgIter *iter)
|
assert_no_dups (MuMsgIter *iter)
|
||||||
{
|
{
|
||||||
|
@ -158,9 +163,7 @@ typedef struct {
|
||||||
static void
|
static void
|
||||||
test_mu_query_01 (void)
|
test_mu_query_01 (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "basic", 3 },
|
{ "basic", 3 },
|
||||||
{ "question", 5 },
|
{ "question", 5 },
|
||||||
|
@ -176,38 +179,24 @@ test_mu_query_01 (void)
|
||||||
{ "", 18 }
|
{ "", 18 }
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
|
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_02 (void)
|
test_mu_query_02 (void)
|
||||||
{
|
{
|
||||||
const char* q;
|
const char* q;
|
||||||
gchar *xpath;
|
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath);
|
|
||||||
|
|
||||||
q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com";
|
q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com";
|
||||||
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, q), ==, 1);
|
||||||
g_assert_cmpuint (run_and_count_matches(xpath, q), ==, 1);
|
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_03 (void)
|
test_mu_query_03 (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "ploughed", 1},
|
{ "ploughed", 1},
|
||||||
{ "i:3BE9E6535E3029448670913581E7A1A20D852173@"
|
{ "i:3BE9E6535E3029448670913581E7A1A20D852173@"
|
||||||
|
@ -230,20 +219,15 @@ test_mu_query_03 (void)
|
||||||
{ "flag:flagged", 1}
|
{ "flag:flagged", 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_04 (void)
|
test_mu_query_04 (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
|
@ -262,22 +246,16 @@ test_mu_query_04 (void)
|
||||||
{ "not prio:l", 11},
|
{ "not prio:l", 11},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_logic (void)
|
test_mu_query_logic (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "subject:gcc" , 1},
|
{ "subject:gcc" , 1},
|
||||||
{ "subject:lisp" , 1},
|
{ "subject:lisp" , 1},
|
||||||
|
@ -289,13 +267,9 @@ test_mu_query_logic (void)
|
||||||
{ "(subject:gcc OR subject:scheme) AND subject:elisp" , 1}
|
{ "(subject:gcc OR subject:scheme) AND subject:elisp" , 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,14 +282,10 @@ test_mu_query_accented_chars_01 (void)
|
||||||
MuMsgIter *iter;
|
MuMsgIter *iter;
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
MuStore *store;
|
MuStore *store;
|
||||||
gchar *xpath;
|
|
||||||
GError *err;
|
GError *err;
|
||||||
gchar *summ;
|
gchar *summ;
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
store = mu_store_new_read_only (DB_PATH1, NULL);
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
store = mu_store_new_read_only (xpath, NULL);
|
|
||||||
g_assert (store);
|
g_assert (store);
|
||||||
|
|
||||||
query = mu_query_new (store, NULL);
|
query = mu_query_new (store, NULL);
|
||||||
|
@ -341,13 +311,11 @@ test_mu_query_accented_chars_01 (void)
|
||||||
|
|
||||||
mu_msg_iter_destroy (iter);
|
mu_msg_iter_destroy (iter);
|
||||||
mu_query_destroy (query);
|
mu_query_destroy (query);
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_accented_chars_02 (void)
|
test_mu_query_accented_chars_02 (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
|
@ -360,21 +328,15 @@ test_mu_query_accented_chars_02 (void)
|
||||||
{ "Queensrÿche", 1},
|
{ "Queensrÿche", 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
g_free (xpath);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_wildcards (void)
|
test_mu_query_wildcards (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
|
@ -385,17 +347,12 @@ test_mu_query_wildcards (void)
|
||||||
{ "Queen*", 1},
|
{ "Queen*", 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_dates_helsinki (void)
|
test_mu_query_dates_helsinki (void)
|
||||||
{
|
{
|
||||||
|
@ -488,62 +445,43 @@ test_mu_query_dates_la (void)
|
||||||
static void
|
static void
|
||||||
test_mu_query_sizes (void)
|
test_mu_query_sizes (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "size:0b..2m", 18},
|
{ "size:0b..2m", 18},
|
||||||
{ "size:2k..4k", 4},
|
{ "size:2k..4k", 4},
|
||||||
{ "size:2m..0b", 18}
|
{ "size:2m..0b", 18}
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
|
|
||||||
g_free (xpath);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_attach (void)
|
test_mu_query_attach (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "j:sittingbull.jpg", 1},
|
{ "j:sittingbull.jpg", 1},
|
||||||
{ "file:custer", 0},
|
{ "file:custer", 0},
|
||||||
{ "file:custer.jpg", 1}
|
{ "file:custer.jpg", 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR2);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
if (g_test_verbose())
|
|
||||||
g_print ("(%s)\n", xpath);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
g_print ("query: %s\n", queries[i].query);
|
g_print ("query: %s\n", queries[i].query);
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH2, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_tags (void)
|
test_mu_query_tags (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "x:paradise", 1},
|
{ "x:paradise", 1},
|
||||||
{ "tag:lost", 1},
|
{ "tag:lost", 1},
|
||||||
|
@ -553,50 +491,31 @@ test_mu_query_tags (void)
|
||||||
{ "x:paradise,lost", 0},
|
{ "x:paradise,lost", 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR2);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
/* g_print ("(%s)\n", xpath); */
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH2, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
|
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_signed_encrypted (void)
|
test_mu_query_signed_encrypted (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "flag:encrypted", 2},
|
{ "flag:encrypted", 2},
|
||||||
{ "flag:signed", 2},
|
{ "flag:signed", 2},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
if (g_test_verbose ())
|
|
||||||
g_print ("%s (%s)\n", __FUNCTION__, xpath);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
g_assert_cmpuint (run_and_count_matches (DB_PATH1, queries[i].query),
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
|
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_query_tags_02 (void)
|
test_mu_query_tags_02 (void)
|
||||||
{
|
{
|
||||||
gchar *xpath;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "x:paradise", 1},
|
{ "x:paradise", 1},
|
||||||
{ "tag:@NextActions", 1},
|
{ "tag:@NextActions", 1},
|
||||||
|
@ -604,18 +523,10 @@ test_mu_query_tags_02 (void)
|
||||||
{ "tag:lost OR tag:operation*", 2},
|
{ "tag:lost OR tag:operation*", 2},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database (MU_TESTMAILDIR2);
|
|
||||||
g_assert (xpath != NULL);
|
|
||||||
|
|
||||||
/* g_print ("(%s)\n", xpath); */
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
/* g_print ("%s\n", queries[i].query); */
|
g_assert_cmpuint (run_and_count_matches (DB_PATH2, queries[i].query),
|
||||||
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
|
|
||||||
==, queries[i].count);
|
==, queries[i].count);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (xpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -631,7 +542,6 @@ test_mu_query_preprocess (void)
|
||||||
/* add more */
|
/* add more */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
for (u = 0; u != G_N_ELEMENTS(testcases); ++u) {
|
for (u = 0; u != G_N_ELEMENTS(testcases); ++u) {
|
||||||
gchar *prep;
|
gchar *prep;
|
||||||
prep = mu_query_preprocess (testcases[u].expr, NULL);
|
prep = mu_query_preprocess (testcases[u].expr, NULL);
|
||||||
|
@ -642,6 +552,8 @@ test_mu_query_preprocess (void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -649,6 +561,12 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
DB_PATH1 = fill_database (MU_TESTMAILDIR);
|
||||||
|
g_assert (DB_PATH1);
|
||||||
|
|
||||||
|
DB_PATH2 = fill_database (MU_TESTMAILDIR2);
|
||||||
|
g_assert (DB_PATH2);
|
||||||
|
|
||||||
g_test_add_func ("/mu-query/test-mu-query-preprocess",
|
g_test_add_func ("/mu-query/test-mu-query-preprocess",
|
||||||
test_mu_query_preprocess);
|
test_mu_query_preprocess);
|
||||||
|
|
||||||
|
@ -692,5 +610,8 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
rv = g_test_run ();
|
rv = g_test_run ();
|
||||||
|
|
||||||
|
g_free (DB_PATH1);
|
||||||
|
g_free (DB_PATH2);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user