mirror of https://github.com/djcb/mu.git
* add unit tests for wildcards, size: and date:
This commit is contained in:
parent
620b7e2cae
commit
e607aed8de
|
@ -1,3 +1,5 @@
|
|||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
|
||||
/*
|
||||
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
|
@ -67,6 +69,14 @@ run_and_count_matches (const char *xpath, const char *query)
|
|||
g_assert (query);
|
||||
|
||||
/* g_printerr ("\n=>'%s'\n", query); */
|
||||
|
||||
/* { /\* debug *\/ */
|
||||
/* char *xs; */
|
||||
/* g_print ("query : '%s'\n", query); */
|
||||
/* xs = mu_query_as_string (mquery, query, NULL); */
|
||||
/* g_print ("xquery: '%s'\n", xs); */
|
||||
/* g_free (xs); */
|
||||
/* } */
|
||||
|
||||
iter = mu_query_run (mquery, query, MU_MSG_FIELD_ID_NONE,
|
||||
FALSE, 1, NULL);
|
||||
|
@ -186,9 +196,9 @@ test_mu_query_04 (void)
|
|||
{ "t:bilbo", 1},
|
||||
{ "f:bilbo", 0},
|
||||
{ "baggins", 1},
|
||||
{ "prio:h", 1},
|
||||
{ "prio:high", 1},
|
||||
{ "prio:normal", 4},
|
||||
{ "prio:h", 1},
|
||||
{ "prio:l", 7},
|
||||
{ "not prio:l", 5},
|
||||
};
|
||||
|
@ -205,7 +215,7 @@ test_mu_query_04 (void)
|
|||
|
||||
|
||||
static void
|
||||
test_mu_query_05 (void)
|
||||
test_mu_query_accented_chars_01 (void)
|
||||
{
|
||||
MuQuery *query;
|
||||
MuMsgIter *iter;
|
||||
|
@ -242,7 +252,7 @@ test_mu_query_05 (void)
|
|||
}
|
||||
|
||||
static void
|
||||
test_mu_query_06 (void)
|
||||
test_mu_query_accented_chars_02 (void)
|
||||
{
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
@ -268,6 +278,85 @@ test_mu_query_06 (void)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mu_query_wildcards (void)
|
||||
{
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
||||
QResults queries[] = {
|
||||
{ "f:mü", 1},
|
||||
{ "s:mo*", 1},
|
||||
{ "t:Helm*", 1},
|
||||
{ "queensryche", 1},
|
||||
{ "Queen*", 1},
|
||||
};
|
||||
|
||||
xpath = fill_database ();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
test_mu_query_dates (void)
|
||||
{
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
||||
QResults queries[] = {
|
||||
{ "date:20080731..20080804", 5},
|
||||
/* { "date:20080804..20080731", 5}, */
|
||||
{ "date:2008-07/31..2008@08:04", 5},
|
||||
{ "date:2008-0731..20080804 s:gcc", 1},
|
||||
{ "date:2008-08-11-08-03..now", 1},
|
||||
{ "date:2008-08-11-08-05..now", 0}
|
||||
};
|
||||
|
||||
xpath = fill_database ();
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mu_query_sizes (void)
|
||||
{
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
||||
QResults queries[] = {
|
||||
{ "size:0b..2m", 12},
|
||||
{ "size:2k..4k", 2},
|
||||
/* { "size:2m..0b", 12}, */
|
||||
};
|
||||
|
||||
xpath = fill_database ();
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
|
@ -278,12 +367,20 @@ main (int argc, char *argv[])
|
|||
g_test_add_func ("/mu-query/test-mu-query-02", test_mu_query_02);
|
||||
g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03);
|
||||
g_test_add_func ("/mu-query/test-mu-query-04", test_mu_query_04);
|
||||
g_test_add_func ("/mu-query/test-mu-query-05", test_mu_query_05);
|
||||
g_test_add_func ("/mu-query/test-mu-query-06", test_mu_query_06);
|
||||
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);
|
||||
g_test_add_func ("/mu-query/test-mu-query-dates",
|
||||
test_mu_query_dates);
|
||||
g_test_add_func ("/mu-query/test-mu-query-sizes",
|
||||
test_mu_query_sizes);
|
||||
|
||||
/* g_log_set_handler (NULL, */
|
||||
/* G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, */
|
||||
/* (GLogFunc)black_hole, NULL); */
|
||||
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 ();
|
||||
|
||||
|
|
Loading…
Reference in New Issue