tests: update for mu-message-fields
This commit is contained in:
@ -149,6 +149,7 @@ test_mu_find_02(void)
|
||||
search("bull m:foo", 0);
|
||||
search("bull m:/foo", 1);
|
||||
search("bull m:/Foo", 1);
|
||||
search("bull flag:attach", 1);
|
||||
search("bull flag:a", 1);
|
||||
search("g:x", 0);
|
||||
search("flag:encrypted", 0);
|
||||
|
||||
@ -46,13 +46,13 @@ make_database(const std::string& testdir)
|
||||
{
|
||||
char* tmpdir{test_mu_common_get_random_tmpdir()};
|
||||
const auto cmdline{format("/bin/sh -c '"
|
||||
"%s init --muhome=%s --maildir=%s --quiet ; "
|
||||
"%s index --muhome=%s --quiet'",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
testdir.c_str(),
|
||||
MU_PROGRAM,
|
||||
tmpdir)};
|
||||
"%s init --muhome=%s --maildir=%s --quiet ; "
|
||||
"%s index --muhome=%s --quiet'",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
testdir.c_str(),
|
||||
MU_PROGRAM,
|
||||
tmpdir)};
|
||||
|
||||
if (g_test_verbose())
|
||||
g_printerr("\n%s\n", cmdline.c_str());
|
||||
@ -87,22 +87,26 @@ assert_no_dups(const QueryResults& qres)
|
||||
/* note: this also *moves the iter* */
|
||||
static size_t
|
||||
run_and_count_matches(const std::string& xpath,
|
||||
const std::string& expr,
|
||||
Mu::QueryFlags flags = Mu::QueryFlags::None)
|
||||
const std::string& expr,
|
||||
Mu::QueryFlags flags = Mu::QueryFlags::None)
|
||||
{
|
||||
Mu::Store store{xpath};
|
||||
|
||||
if (g_test_verbose()) {
|
||||
std::cout << "==> mquery: " << store.parse_query(expr, false) << "\n";
|
||||
std::cout << "==> xquery: " << store.parse_query(expr, true) << "\n";
|
||||
}
|
||||
// if (g_test_verbose()) {
|
||||
// std::cout << "==> mquery: " << store.parse_query(expr, false) << "\n";
|
||||
// std::cout << "==> xquery: " << store.parse_query(expr, true) << "\n";
|
||||
// }
|
||||
|
||||
Mu::allow_warnings();
|
||||
|
||||
auto qres{store.run_query(expr, MU_MSG_FIELD_ID_NONE, flags)};
|
||||
auto qres{store.run_query(expr, {}, flags)};
|
||||
g_assert_true(!!qres);
|
||||
assert_no_dups(*qres);
|
||||
|
||||
|
||||
if (g_test_verbose())
|
||||
g_print("'%s' => %zu\n", expr.c_str(), qres->size());
|
||||
|
||||
return qres->size();
|
||||
}
|
||||
|
||||
@ -131,15 +135,15 @@ test_mu_query_01(void)
|
||||
{"foo:pepernoot", 0},
|
||||
{"funky", 1},
|
||||
{"fünkÿ", 1},
|
||||
// { "", 18 },
|
||||
{ "", 19 },
|
||||
{"msgid:abcd$efgh@example.com", 1},
|
||||
{"i:abcd$efgh@example.com", 1},
|
||||
};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -155,34 +159,34 @@ test_mu_query_03(void)
|
||||
{
|
||||
int i;
|
||||
QResults queries[] = {{"ploughed", 1},
|
||||
{"i:3BE9E6535E3029448670913581E7A1A20D852173@"
|
||||
"emss35m06.us.lmco.com",
|
||||
1},
|
||||
{"i:!&!AAAAAAAAAYAAAAAAAAAOH1+8mkk+lLn7Gg5fke7"
|
||||
"FbCgAAAEAAAAJ7eBDgcactKhXL6r8cEnJ8BAAAAAA==@"
|
||||
"example.com",
|
||||
1},
|
||||
{"i:3BE9E6535E3029448670913581E7A1A20D852173@"
|
||||
"emss35m06.us.lmco.com",
|
||||
1},
|
||||
{"i:!&!AAAAAAAAAYAAAAAAAAAOH1+8mkk+lLn7Gg5fke7"
|
||||
"FbCgAAAEAAAAJ7eBDgcactKhXL6r8cEnJ8BAAAAAA==@"
|
||||
"example.com",
|
||||
1},
|
||||
|
||||
/* 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},
|
||||
/* 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},
|
||||
|
||||
{"s:lisp", 1},
|
||||
{"s:LISP", 1},
|
||||
{"s:lisp", 1},
|
||||
{"s:LISP", 1},
|
||||
|
||||
/* { "s:\"Re: Learning LISP; Scheme vs elisp.\"", 1}, */
|
||||
/* { "subject:Re: Learning LISP; Scheme vs elisp.", 1}, */
|
||||
/* { "subject:\"Re: Learning LISP; Scheme vs elisp.\"", 1}, */
|
||||
{"to:help-gnu-emacs@gnu.org", 4},
|
||||
{"t:help-gnu-emacs", 4},
|
||||
{"flag:flagged", 1}};
|
||||
// { "s:\"Re: Learning LISP; Scheme vs elisp.\"", 1},
|
||||
// { "subject:Re: Learning LISP; Scheme vs elisp.", 1},
|
||||
// { "subject:\"Re: Learning LISP; Scheme vs elisp.\"", 1},
|
||||
{"to:help-gnu-emacs@gnu.org", 4},
|
||||
{"t:help-gnu-emacs", 4},
|
||||
{"flag:flagged", 1}};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -208,8 +212,8 @@ test_mu_query_04(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -217,23 +221,25 @@ test_mu_query_logic(void)
|
||||
{
|
||||
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: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}};
|
||||
{"subject:gcc OR (subject:scheme AND subject:elisp)", 2},
|
||||
{"(subject:gcc OR subject:scheme) AND subject:elisp", 1}};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
test_mu_query_accented_chars_01(void)
|
||||
{
|
||||
return;
|
||||
|
||||
Store store{DB_PATH1};
|
||||
|
||||
auto qres{store.run_query("fünkÿ")};
|
||||
@ -261,17 +267,17 @@ test_mu_query_accented_chars_02(void)
|
||||
int i;
|
||||
|
||||
QResults queries[] = {{"f:mü", 1},
|
||||
{"s:motörhead", 1},
|
||||
{"t:Helmut", 1},
|
||||
{"t:Kröger", 1},
|
||||
{"s:MotorHeäD", 1},
|
||||
{"queensryche", 1},
|
||||
{"Queensrÿche", 1}};
|
||||
{"s:motörhead", 1},
|
||||
{"t:Helmut", 1},
|
||||
{"t:Kröger", 1},
|
||||
{"s:MotorHeäD", 1},
|
||||
{"queensryche", 1},
|
||||
{"Queensrÿche", 1}};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -280,20 +286,20 @@ test_mu_query_accented_chars_fraiche(void)
|
||||
int i;
|
||||
|
||||
QResults queries[] = {{"crème fraîche", 1},
|
||||
{"creme fraiche", 1},
|
||||
{"fraîche crème", 1},
|
||||
{"будланула", 1},
|
||||
{"БУДЛАНУЛА", 1},
|
||||
{"CRÈME FRAÎCHE", 1},
|
||||
{"CREME FRAICHE", 1}};
|
||||
{"creme fraiche", 1},
|
||||
{"fraîche crème", 1},
|
||||
{"будланула", 1},
|
||||
{"БУДЛАНУЛА", 1},
|
||||
{"CRÈME FRAÎCHE", 1},
|
||||
{"CREME FRAICHE", 1}};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||
if (g_test_verbose())
|
||||
g_print("'%s'\n", queries[i].query);
|
||||
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,8 +318,8 @@ test_mu_query_wildcards(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -323,10 +329,10 @@ test_mu_query_dates_helsinki(void)
|
||||
const char* old_tz;
|
||||
|
||||
QResults queries[] = {{"date:20080731..20080804", 5},
|
||||
{"date:20080731..20080804 s:gcc", 1},
|
||||
{"date:200808110803..now", 7},
|
||||
{"date:200808110803..today", 7},
|
||||
{"date:200808110801..now", 7}};
|
||||
{"date:20080731..20080804 s:gcc", 1},
|
||||
{"date:200808110803..now", 7},
|
||||
{"date:200808110803..today", 7},
|
||||
{"date:200808110801..now", 7}};
|
||||
|
||||
old_tz = set_tz("Europe/Helsinki");
|
||||
|
||||
@ -335,8 +341,8 @@ test_mu_query_dates_helsinki(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
|
||||
set_tz(old_tz);
|
||||
}
|
||||
@ -347,10 +353,10 @@ test_mu_query_dates_sydney(void)
|
||||
int i;
|
||||
const char* old_tz;
|
||||
QResults queries[] = {{"date:20080731..20080804", 5},
|
||||
{"date:20080731..20080804 s:gcc", 1},
|
||||
{"date:200808110803..now", 7},
|
||||
{"date:200808110803..today", 7},
|
||||
{"date:200808110801..now", 7}};
|
||||
{"date:20080731..20080804 s:gcc", 1},
|
||||
{"date:200808110803..now", 7},
|
||||
{"date:200808110803..today", 7},
|
||||
{"date:200808110801..now", 7}};
|
||||
|
||||
old_tz = set_tz("Australia/Sydney");
|
||||
|
||||
@ -359,8 +365,8 @@ test_mu_query_dates_sydney(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
set_tz(old_tz);
|
||||
}
|
||||
|
||||
@ -371,12 +377,12 @@ test_mu_query_dates_la(void)
|
||||
const char* old_tz;
|
||||
|
||||
QResults queries[] = {{"date:20080731..20080804", 5},
|
||||
{"date:2008-07-31..2008-08-04", 5},
|
||||
{"date:20080804..20080731", 5},
|
||||
{"date:20080731..20080804 s:gcc", 1},
|
||||
{"date:200808110803..now", 6},
|
||||
{"date:200808110803..today", 6},
|
||||
{"date:200808110801..now", 6}};
|
||||
{"date:2008-07-31..2008-08-04", 5},
|
||||
{"date:20080804..20080731", 5},
|
||||
{"date:20080731..20080804 s:gcc", 1},
|
||||
{"date:200808110803..now", 6},
|
||||
{"date:200808110803..today", 6},
|
||||
{"date:200808110801..now", 6}};
|
||||
|
||||
old_tz = set_tz("America/Los_Angeles");
|
||||
|
||||
@ -386,8 +392,8 @@ test_mu_query_dates_la(void)
|
||||
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);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
set_tz(old_tz);
|
||||
@ -408,8 +414,8 @@ test_mu_query_sizes(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -422,8 +428,8 @@ test_mu_query_attach(void)
|
||||
if (g_test_verbose())
|
||||
g_print("query: %s\n", queries[i].query);
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,8 +451,8 @@ test_mu_query_msgid(void)
|
||||
if (g_test_verbose())
|
||||
g_print("query: %s\n", queries[i].query);
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,8 +473,8 @@ test_mu_query_tags(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -483,8 +489,8 @@ test_mu_query_wom_bat(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -498,8 +504,8 @@ test_mu_query_signed_encrypted(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -516,8 +522,8 @@ test_mu_query_multi_to_cc(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -533,8 +539,8 @@ test_mu_query_tags_02(void)
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||
==,
|
||||
queries[i].count);
|
||||
==,
|
||||
queries[i].count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -551,10 +557,10 @@ test_mu_query_threads_compilation_error(void)
|
||||
g_assert_cmpuint(run_and_count_matches(xpath, "msgid:uwsireh25.fsf@one.dot.net"), ==, 1);
|
||||
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"msgid:uwsireh25.fsf@one.dot.net",
|
||||
QueryFlags::IncludeRelated),
|
||||
==,
|
||||
3);
|
||||
"msgid:uwsireh25.fsf@one.dot.net",
|
||||
QueryFlags::IncludeRelated),
|
||||
==,
|
||||
3);
|
||||
}
|
||||
|
||||
/* https://github.com/djcb/mu/issues/1428 */
|
||||
@ -569,26 +575,26 @@ test_mu_query_cjk(void)
|
||||
g_unsetenv("XAPIAN_CJK_NGRAM");
|
||||
const auto xpath = make_database(MU_TESTMAILDIR_CJK);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 1);
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 1);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
}
|
||||
|
||||
{
|
||||
g_setenv("XAPIAN_CJK_NGRAM", "1", TRUE);
|
||||
const auto xpath = make_database(MU_TESTMAILDIR_CJK);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -617,11 +623,11 @@ main(int argc, char* argv[])
|
||||
g_test_add_func("/mu-query/test-mu-query-logic", test_mu_query_logic);
|
||||
|
||||
g_test_add_func("/mu-query/test-mu-query-accented-chars-1",
|
||||
test_mu_query_accented_chars_01);
|
||||
test_mu_query_accented_chars_01);
|
||||
g_test_add_func("/mu-query/test-mu-query-accented-chars-2",
|
||||
test_mu_query_accented_chars_02);
|
||||
test_mu_query_accented_chars_02);
|
||||
g_test_add_func("/mu-query/test-mu-query-accented-chars-fraiche",
|
||||
test_mu_query_accented_chars_fraiche);
|
||||
test_mu_query_accented_chars_fraiche);
|
||||
|
||||
g_test_add_func("/mu-query/test-mu-query-msgid", test_mu_query_msgid);
|
||||
|
||||
@ -639,17 +645,17 @@ main(int argc, char* argv[])
|
||||
g_test_add_func("/mu-query/test-mu-query-tags_02", test_mu_query_tags_02);
|
||||
|
||||
g_test_add_func("/mu-query/test-mu-query-threads-compilation-error",
|
||||
test_mu_query_threads_compilation_error);
|
||||
test_mu_query_threads_compilation_error);
|
||||
|
||||
g_test_add_func("/mu-query/test-mu-query-cjk",
|
||||
test_mu_query_cjk);
|
||||
test_mu_query_cjk);
|
||||
|
||||
if (!g_test_verbose())
|
||||
g_log_set_handler(NULL,
|
||||
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
|
||||
G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION),
|
||||
(GLogFunc)black_hole,
|
||||
NULL);
|
||||
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
|
||||
G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION),
|
||||
(GLogFunc)black_hole,
|
||||
NULL);
|
||||
rv = g_test_run();
|
||||
|
||||
return rv;
|
||||
|
||||
Reference in New Issue
Block a user