* cleanup testcase, update for mu_msg_iter_is_done

This commit is contained in:
Dirk-Jan C. Binnema 2010-09-09 00:09:33 +03:00
parent d1f4ebde0b
commit 32a218d76e
1 changed files with 27 additions and 57 deletions

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2010 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
@ -28,7 +28,6 @@
#include <unistd.h>
#include <string.h>
#include "test-mu-common.h"
#include "src/mu-query.h"
@ -45,6 +44,7 @@ fill_database (void)
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
" --quiet",
MU_PROGRAM, tmpdir, MU_TESTMAILDIR);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, NULL));
g_free (cmdline);
@ -57,17 +57,24 @@ fill_database (void)
/* note: this also *moves the iter* */
static guint
count_matches ( MuMsgIter *iter)
run_and_count_matches (const char *xpath, const char *query)
{
MuQuery *mquery;
MuMsgIter *iter;
guint count;
mquery = mu_query_new (xpath);
g_assert (query);
if (mu_msg_iter_is_null(iter))
return 0;
count = 1;
while (mu_msg_iter_next (iter))
++count;
iter = mu_query_run (mquery, query, NULL, FALSE, 1);
g_assert (iter);
for (count = 0; !mu_msg_iter_is_done(iter);
mu_msg_iter_next(iter), ++count);
mu_msg_iter_destroy (iter);
mu_query_destroy (mquery);
return count;
}
@ -97,48 +104,24 @@ test_mu_query_01 (void)
xpath = fill_database ();
g_assert (xpath != NULL);
query = mu_query_new (xpath);
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
int count = 0;
MuMsgIter *iter =
mu_query_run (query, queries[i].query, NULL,
FALSE, 1);
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
mu_msg_iter_destroy (iter);
}
mu_query_destroy (query);
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_02 (void)
{
MuMsgIter *iter;
MuQuery *query;
const char* q;
gchar *xpath;
int i;
xpath = fill_database ();
g_assert (xpath != NULL);
g_assert (xpath);
query = mu_query_new (xpath);
g_assert (query);
q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com";
iter = mu_query_run (query, q, NULL, FALSE, 0);
g_assert (iter);
g_assert_cmpuint (count_matches(iter), ==, 1);
mu_query_destroy (query);
g_assert_cmpuint (run_and_count_matches(xpath, q), ==, 1);
g_free (xpath);
}
@ -146,29 +129,19 @@ test_mu_query_02 (void)
static void
test_mu_query_03 (void)
{
MuQuery *query;
gchar *xpath;
int i;
QResults queries[] = {
{ "t:help-gnu-emacs@gnu.org", 1},
// { "t:help-gnu-emacs@gnu.org", 1}
{ "t:help-gnu-emacs", 0}
};
xpath = fill_database ();
g_assert (xpath != NULL);
query = mu_query_new (xpath);
g_assert (xpath);
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
int count = 0;
MuMsgIter *iter =
mu_query_run (query, queries[i].query, NULL,
FALSE, 1);
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
mu_msg_iter_destroy (iter);
}
mu_query_destroy (query);
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);
}
@ -183,7 +156,6 @@ test_mu_query_04 (void)
xpath = fill_database ();
g_assert (xpath != NULL);
query = mu_query_new (xpath);
iter = mu_query_run (query, "fünkÿ", NULL, FALSE, 1);
@ -205,8 +177,6 @@ test_mu_query_04 (void)
}
int
main (int argc, char *argv[])
{