* 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

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