From ff7a40b3d9d6f782cd82ee06f14d8db047c9b52f Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 29 Aug 2011 23:39:11 +0300 Subject: [PATCH] * update test cases for other changes --- src/tests/test-mu-cmd.c | 144 ++++++++++++++++---------------- src/tests/test-mu-query.c | 168 +++++++++++++++++++------------------- src/tests/test-mu-store.c | 52 ++++++------ 3 files changed, 184 insertions(+), 180 deletions(-) diff --git a/src/tests/test-mu-cmd.c b/src/tests/test-mu-cmd.c index c7cba8ae..dbd310a0 100644 --- a/src/tests/test-mu-cmd.c +++ b/src/tests/test-mu-cmd.c @@ -1,5 +1,5 @@ /* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- -** +** ** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it @@ -14,8 +14,8 @@ ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** */ #if HAVE_CONFIG_H @@ -41,13 +41,13 @@ static gchar* fill_database (void) { gchar *cmdline, *tmpdir; - + tmpdir = test_mu_common_get_random_tmpdir(); cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" " --quiet", MU_PROGRAM, tmpdir, MU_TESTMAILDIR2); - + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, NULL)); g_free (cmdline); @@ -67,7 +67,7 @@ newlines_in_output (const char* str) ++count; ++str; } - + return count; } @@ -78,12 +78,12 @@ search (const char* query, unsigned expected) muhome = fill_database (); g_assert (muhome); - + cmdline = g_strdup_printf ("%s find --muhome=%s %s", MU_PROGRAM, muhome, query); /* g_printerr ("%s\n", cmdline); */ - + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL)); @@ -93,7 +93,7 @@ search (const char* query, unsigned expected) * otherwise there should be one line 'No matches found' */ /* g_assert_cmpuint (newlines_in_output(erroutput),==, */ /* expected == 0 ? 1 : 0); */ - + g_free (output); g_free (erroutput); g_free (cmdline); @@ -111,11 +111,11 @@ test_mu_index (void) g_assert (muhome != NULL); xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR, "xapian"); - - store = mu_store_new (xpath, NULL, NULL); + + store = mu_store_new_read_only (xpath, NULL); g_assert (store); - g_assert_cmpuint (mu_store_count (store), ==, 9); + g_assert_cmpuint (mu_store_count (store), ==, 9); mu_store_destroy (store); g_free (muhome); @@ -128,14 +128,14 @@ static void test_mu_find_01 (void) { search ("f:john fruit", 1); - search ("f:soc@example.com", 1); + search ("f:soc@example.com", 1); search ("t:alki@example.com", 1); search ("t:alcibiades", 1); - search ("f:soc@example.com OR f:john", 2); + search ("f:soc@example.com OR f:john", 2); search ("f:soc@example.com OR f:john OR t:edmond", 3); - search ("t:julius", 1); + search ("t:julius", 1); search ("s:dude", 1); - search ("t:dantès", 1); + search ("t:dantès", 1); } @@ -144,7 +144,7 @@ static void test_mu_find_02 (void) { search ("bull", 1); - search ("bull m:foo", 0); + search ("bull m:foo", 0); search ("bull m:/foo", 1); search ("bull m:/Foo", 1); search ("bull flag:a", 1); @@ -159,7 +159,7 @@ static void test_mu_find_03 (void) { search ("bull", 1); - search ("bull m:foo", 0); + search ("bull m:foo", 0); search ("bull m:/foo", 1); search ("i:3BE9E6535E0D852173@emss35m06.us.lmco.com", 1); } @@ -179,10 +179,10 @@ test_mu_find_04 (void) G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR); - + g_assert (g_spawn_command_line_sync (cmdline, NULL, &erroutput, NULL, NULL)); - + /* we expect multiple lines of error output */ g_assert_cmpuint (newlines_in_output(erroutput),>=,1); @@ -199,7 +199,7 @@ test_mu_extract_01 (void) tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s extract --muhome=%s %s%cFoo%ccur%cmail5", MU_PROGRAM, tmpdir, @@ -209,7 +209,7 @@ test_mu_extract_01 (void) G_DIR_SEPARATOR); /* g_print ("[%s]", cmdline); */ - + output = erroutput = NULL; g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL)); @@ -220,7 +220,7 @@ test_mu_extract_01 (void) " 1 text/plain []\n" " 2 sittingbull.jpg image/jpeg [inline]\n" " 3 custer.jpg image/jpeg [inline]\n"); - + /* we expect zero lines of error output */ g_assert_cmpuint (newlines_in_output(erroutput),==,0); @@ -244,16 +244,16 @@ get_file_size (const char* path) } -static void +static void test_mu_extract_02 (void) { gchar *cmdline, *output, *tmpdir; gchar *att1, *att2; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s extract --muhome=%s -a " "--target-dir=%s %s%cFoo%ccur%cmail5", MU_PROGRAM, @@ -267,13 +267,13 @@ test_mu_extract_02 (void) output = NULL; g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); g_assert_cmpstr (output, ==, ""); - + att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR); att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR); - + g_assert_cmpint (get_file_size(att1),==,15960); g_assert_cmpint (get_file_size(att2),==,17674); - + g_free (output); g_free (tmpdir); g_free (cmdline); @@ -282,16 +282,16 @@ test_mu_extract_02 (void) } -static void +static void test_mu_extract_03 (void) { gchar *cmdline, *output, *tmpdir; gchar *att1, *att2; - + tmpdir = test_mu_common_get_random_tmpdir(); - + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s extract --muhome=%s --parts 3 " "--target-dir=%s %s%cFoo%ccur%cmail5", MU_PROGRAM, @@ -307,10 +307,10 @@ test_mu_extract_03 (void) att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR); att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR); - + g_assert_cmpint (get_file_size(att1),==,15960); /* should not exist */ g_assert_cmpint (get_file_size(att2),==,-1); - + g_free (output); g_free (tmpdir); g_free (cmdline); @@ -319,15 +319,15 @@ test_mu_extract_03 (void) } -static void +static void test_mu_extract_overwrite (void) { gchar *cmdline, *output, *erroutput, *tmpdir; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s extract --muhome=%s -a " "--target-dir=%s %s%cFoo%ccur%cmail5", MU_PROGRAM, tmpdir, tmpdir, @@ -340,7 +340,7 @@ test_mu_extract_overwrite (void) g_assert_cmpstr (erroutput, ==, ""); g_free (erroutput); g_free (output); - + /* now, it should fail, because we don't allow overwrites * without --overwrite */ g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, @@ -349,7 +349,7 @@ test_mu_extract_overwrite (void) g_assert_cmpstr (erroutput, !=, ""); g_free (erroutput); g_free (output); - + g_free (cmdline); /* this should work now, because we have specified --overwrite */ cmdline = g_strdup_printf ("%s extract --muhome=%s -a --overwrite " @@ -369,15 +369,15 @@ test_mu_extract_overwrite (void) } -static void +static void test_mu_extract_by_name (void) { gchar *cmdline, *output, *erroutput, *tmpdir, *path; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s extract --muhome=%s " "--target-dir=%s %s%cFoo%ccur%cmail5 " "sittingbull.jpg", @@ -403,15 +403,15 @@ test_mu_extract_by_name (void) -static void +static void test_mu_view_01 (void) { gchar *cmdline, *output, *tmpdir; int len; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s view --muhome=%s %s%cbar%ccur%cmail4", MU_PROGRAM, tmpdir, @@ -422,21 +422,21 @@ test_mu_view_01 (void) output = NULL; g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); g_assert_cmpstr (output, !=, NULL); - + /* * note: there are two possibilities here; older versions of * GMime will produce: * * From: "=?iso-8859-1?Q? =F6tzi ?=" - * + * * while newer ones return something like: * * From: ?tzi * - * or even + * or even * * From: \xc3\xb6tzi - * + * * both are 'okay' from mu's perspective; it'd be even better * to have some #ifdefs for the GMime versions, but this * should work for now @@ -446,22 +446,22 @@ test_mu_view_01 (void) len = strlen(output); /* g_print ("\n[%s] (%d)\n", output, len); */ g_assert (len > 349); - + g_free (output); g_free (cmdline); g_free (tmpdir); } -static void +static void test_mu_view_multi (void) { gchar *cmdline, *output, *tmpdir; int len; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s view --muhome=%s " "%s%cbar%ccur%cmail5 " "%s%cbar%ccur%cmail5", @@ -482,22 +482,22 @@ test_mu_view_multi (void) len = strlen(output); /* g_print ("\n[%s](%u)\n", output, len); */ g_assert_cmpuint (len,>,150); - + g_free (output); g_free (cmdline); g_free (tmpdir); } -static void +static void test_mu_view_multi_separate (void) { gchar *cmdline, *output, *tmpdir; int len; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s view --terminate --muhome=%s " "%s%cbar%ccur%cmail5 " "%s%cbar%ccur%cmail5", @@ -518,7 +518,7 @@ test_mu_view_multi_separate (void) len = strlen(output); /* g_print ("\n[%s](%u)\n", output, len); */ g_assert_cmpuint (len,>,150); - + g_free (output); g_free (cmdline); g_free (tmpdir); @@ -527,12 +527,12 @@ test_mu_view_multi_separate (void) -static void +static void test_mu_view_attach (void) { gchar *cmdline, *output, *tmpdir; int len; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); @@ -546,11 +546,11 @@ test_mu_view_attach (void) output = NULL; g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); g_assert_cmpstr (output, !=, NULL); - + len = strlen(output); /* g_print ("\n[%s] (%d)\n", output, len);*/ g_assert (len == 170 || len == 168); - + g_free (output); g_free (cmdline); g_free (tmpdir); @@ -559,15 +559,15 @@ test_mu_view_attach (void) -static void +static void test_mu_mkdir_01 (void) { gchar *cmdline, *output, *tmpdir; gchar *dir; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - + cmdline = g_strdup_printf ("%s mkdir --muhome=%s %s%ctest1 %s%ctest2", MU_PROGRAM,tmpdir, tmpdir, G_DIR_SEPARATOR, @@ -581,7 +581,7 @@ test_mu_mkdir_01 (void) G_DIR_SEPARATOR); g_assert (access (dir, F_OK) == 0); g_free (dir); - + dir = g_strdup_printf ("%s%ctest2%ctmp", tmpdir, G_DIR_SEPARATOR, G_DIR_SEPARATOR); g_assert (access (dir, F_OK) == 0); @@ -591,7 +591,7 @@ test_mu_mkdir_01 (void) G_DIR_SEPARATOR); g_assert (access (dir, F_OK) == 0); g_free (dir); - + g_free (output); g_free (tmpdir); g_free (cmdline); @@ -606,13 +606,13 @@ main (int argc, char *argv[]) g_test_init (&argc, &argv, NULL); setenv ("LC_ALL", "en_US.utf8", 1); - + g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index); - g_test_add_func ("/mu-cmd/test-mu-find-01", test_mu_find_01); + g_test_add_func ("/mu-cmd/test-mu-find-01", test_mu_find_01); g_test_add_func ("/mu-cmd/test-mu-find-02", test_mu_find_02); g_test_add_func ("/mu-cmd/test-mu-find-03", test_mu_find_03); g_test_add_func ("/mu-cmd/test-mu-find-04", test_mu_find_04); - + g_test_add_func ("/mu-cmd/test-mu-extract-01", test_mu_extract_01); g_test_add_func ("/mu-cmd/test-mu-extract-02", test_mu_extract_02); g_test_add_func ("/mu-cmd/test-mu-extract-03", test_mu_extract_03); @@ -628,7 +628,7 @@ main (int argc, char *argv[]) test_mu_view_multi_separate); g_test_add_func ("/mu-cmd/test-mu-view-attach", test_mu_view_attach); g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01); - + g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING| G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 669920ab..f1323e07 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -1,6 +1,6 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ -/* +/* ** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it @@ -15,8 +15,8 @@ ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** */ #ifdef HAVE_CONFIG_H @@ -40,14 +40,14 @@ static gchar* fill_database (const char *testdir) { gchar *cmdline, *tmpdir, *xpath; - + tmpdir = test_mu_common_get_random_tmpdir(); cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" " --quiet", MU_PROGRAM, tmpdir, testdir); /* g_printerr ("\n%s\n", cmdline); */ - + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, NULL)); g_free (cmdline); @@ -55,7 +55,7 @@ fill_database (const char *testdir) xpath= g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR, "xapian"); g_free (tmpdir); - + return xpath; } @@ -88,7 +88,7 @@ run_and_count_matches (const char *xpath, const char *query) MuQuery *mquery; MuMsgIter *iter; guint count1, count2; - + mquery = mu_query_new (xpath, NULL); g_assert (query); @@ -101,29 +101,29 @@ run_and_count_matches (const char *xpath, const char *query) /* g_print ("xquery: '%s'\n", xs); */ /* g_free (xs); */ /* } */ - + iter = mu_query_run (mquery, query, FALSE, MU_MSG_FIELD_ID_NONE, FALSE, NULL); mu_query_destroy (mquery); g_assert (iter); assert_no_dups (iter); - + /* run query twice, to test mu_msg_iter_reset */ - for (count1 = 0; !mu_msg_iter_is_done(iter); + for (count1 = 0; !mu_msg_iter_is_done(iter); mu_msg_iter_next(iter), ++count1); mu_msg_iter_reset (iter); - + assert_no_dups (iter); - + for (count2 = 0; !mu_msg_iter_is_done(iter); mu_msg_iter_next(iter), ++count2); - + mu_msg_iter_destroy (iter); g_assert_cmpuint (count1, ==, count2); - + return count1; } @@ -138,7 +138,7 @@ test_mu_query_01 (void) { gchar *xpath; int i; - + QResults queries[] = { { "basic", 3 }, { "question", 5 }, @@ -154,11 +154,11 @@ test_mu_query_01 (void) { "", 13 } }; - + 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), ==, queries[i].count); @@ -170,10 +170,10 @@ test_mu_query_02 (void) { const char* q; gchar *xpath; - + xpath = fill_database (MU_TESTMAILDIR); g_assert (xpath); - + q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com"; g_assert_cmpuint (run_and_count_matches(xpath, q), ==, 1); @@ -186,7 +186,7 @@ test_mu_query_03 (void) { gchar *xpath; int i; - + QResults queries[] = { { "ploughed", 1}, { "i:3BE9E6535E3029448670913581E7A1A20D852173@" @@ -197,19 +197,19 @@ test_mu_query_03 (void) { "s:gcc include search" , 1}, { "s:search order" , 1}, { "s:include" , 1}, - + { "s:lisp", 1}, { "s:LISP", 1}, - + { "s: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", 0}, }; - + xpath = fill_database (MU_TESTMAILDIR); 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); @@ -223,7 +223,7 @@ test_mu_query_04 (void) { gchar *xpath; int i; - + QResults queries[] = { { "frodo@example.com", 1}, /* does not match: see mu-find (1) */ { "f:frodo@example.com", 1}, @@ -239,11 +239,11 @@ test_mu_query_04 (void) { "prio:l", 7}, { "not prio:l", 6}, }; - + 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), ==, queries[i].count); g_free (xpath); @@ -260,7 +260,7 @@ test_mu_query_accented_chars_01 (void) gchar *xpath; GError *err; gchar *summ; - + xpath = fill_database (MU_TESTMAILDIR); g_assert (xpath != NULL); @@ -274,15 +274,15 @@ test_mu_query_accented_chars_01 (void) g_error_free (err); g_assert_not_reached (); } - - g_assert_cmpstr (mu_msg_get_subject(msg),==, + + g_assert_cmpstr (mu_msg_get_subject(msg),==, "Greetings from Lothlórien"); /* TODO: fix this again */ summ = mu_str_summarize (mu_msg_get_body_text(msg), 5); g_assert_cmpstr (summ,==, "Let's write some fünkÿ text using umlauts. Foo."); g_free (summ); - + mu_msg_iter_destroy (iter); mu_query_destroy (query); g_free (xpath); @@ -293,21 +293,21 @@ test_mu_query_accented_chars_02 (void) { gchar *xpath; int i; - + QResults queries[] = { { "f:mü", 1}, { "s:motörhead", 1}, { "t:Helmut", 1}, - { "t:Kröger", 1}, + { "t:Kröger", 1}, { "s:MotorHeäD", 1}, { "queensryche", 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), ==, queries[i].count); g_free (xpath); @@ -320,7 +320,7 @@ test_mu_query_wildcards (void) { gchar *xpath; int i; - + QResults queries[] = { { "f:mü", 1}, { "s:mo*", 1}, @@ -328,11 +328,11 @@ test_mu_query_wildcards (void) { "queensryche", 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), ==, queries[i].count); g_free (xpath); @@ -347,7 +347,7 @@ test_mu_query_dates_helsinki (void) int i; const char *old_tz; - + QResults queries[] = { { "date:20080731..20080804", 5}, /* { "date:20080804..20080731", 5}, */ @@ -361,17 +361,17 @@ test_mu_query_dates_helsinki (void) }; old_tz = set_tz ("Europe/Helsinki"); - + 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), ==, queries[i].count); g_free (xpath); set_tz (old_tz); - + } static void @@ -381,7 +381,7 @@ test_mu_query_dates_sydney (void) int i; const char *old_tz; - + QResults queries[] = { { "date:20080731..20080804", 5}, /* { "date:20080804..20080731", 5}, */ @@ -395,17 +395,17 @@ test_mu_query_dates_sydney (void) }; old_tz = set_tz ("Australia/Sydney"); - + 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), ==, queries[i].count); g_free (xpath); set_tz (old_tz); - + } static void @@ -414,7 +414,7 @@ test_mu_query_dates_la (void) gchar *xpath; int i; const char *old_tz; - + QResults queries[] = { { "date:20080731..20080804", 5}, /* { "date:20080804..20080731", 5}, */ @@ -426,13 +426,13 @@ test_mu_query_dates_la (void) /* { "date:today..2008-08-11-08-03", 1}, */ { "date:200808110801..now", 0}, /* does not match in LA */ }; - + old_tz = set_tz ("America/Los_Angeles"); - + 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), ==, queries[i].count); @@ -448,22 +448,22 @@ test_mu_query_sizes (void) { gchar *xpath; int i; - + QResults queries[] = { { "size:0b..2m", 13}, { "size:2k..4k", 2}, { "size:2m..0b", 13} }; - + 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), ==, queries[i].count); g_free (xpath); - + } @@ -472,24 +472,24 @@ test_mu_query_attach (void) { gchar *xpath; int i; - + QResults queries[] = { { "a:sittingbull.jpg", 1}, { "'attach:sitting*'", 1}, { "attach:custer", 0}, { "attach:custer.jpg", 1} }; - + xpath = fill_database (MU_TESTMAILDIR2); g_assert (xpath != NULL); /* g_print ("(%s)\n", xpath); */ - + 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); + g_free (xpath); } @@ -498,7 +498,7 @@ test_mu_query_tags (void) { gchar *xpath; int i; - + QResults queries[] = { { "x:paradise", 1}, { "tag:lost", 1}, @@ -507,17 +507,17 @@ test_mu_query_tags (void) { "tag:lost OR tag:horizon", 1}, { "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), ==, queries[i].count); - g_free (xpath); + g_free (xpath); } @@ -526,26 +526,26 @@ test_mu_query_tags_02 (void) { gchar *xpath; int i; - + QResults queries[] = { { "x:paradise", 1}, { "tag:@NextActions", 1}, { "x:queensrÿche", 1}, { "tag:lost OR tag:operation:mindcrime", 2}, }; - + xpath = fill_database (MU_TESTMAILDIR2); g_assert (xpath != NULL); /* g_print ("(%s)\n", xpath); */ - + 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); } - g_free (xpath); + g_free (xpath); } @@ -555,11 +555,11 @@ int main (int argc, char *argv[]) { int rv; - - g_test_init (&argc, &argv, NULL); - + + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/mu-query/test-mu-query-01", test_mu_query_01); - g_test_add_func ("/mu-query/test-mu-query-02", test_mu_query_02); + 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-accented-chars-1", @@ -584,13 +584,13 @@ main (int argc, char *argv[]) test_mu_query_tags); g_test_add_func ("/mu-query/test-mu-query-tags_02", test_mu_query_tags_02); - - 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 (); - + return rv; } diff --git a/src/tests/test-mu-store.c b/src/tests/test-mu-store.c index 7927b56c..6a52ef3a 100644 --- a/src/tests/test-mu-store.c +++ b/src/tests/test-mu-store.c @@ -1,6 +1,6 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ -/* +/* ** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it @@ -15,8 +15,8 @@ ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** */ #if HAVE_CONFIG_H @@ -44,7 +44,7 @@ test_mu_store_new_destroy (void) g_assert (tmpdir); err = NULL; - store = mu_store_new (tmpdir, NULL, &err); + store = mu_store_new_writable (tmpdir, NULL, &err); g_assert (store); g_assert (err == NULL); @@ -53,7 +53,7 @@ test_mu_store_new_destroy (void) mu_store_flush (store); mu_store_destroy (store); - g_free (tmpdir); + g_free (tmpdir); } @@ -63,27 +63,31 @@ test_mu_store_version (void) MuStore *store; gchar* tmpdir; GError *err; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (tmpdir); err = NULL; - store = mu_store_new (tmpdir, NULL, &err); + store = mu_store_new_writable (tmpdir, NULL, &err); g_assert (store); + mu_store_destroy (store); + store = mu_store_new_read_only (tmpdir, &err); + g_assert (store); + g_assert (err == NULL); g_assert_cmpuint (0,==,mu_store_count (store)); g_assert_cmpstr (MU_XAPIAN_DB_VERSION,==, mu_store_version(store)); - + mu_store_destroy (store); - g_free (tmpdir); + g_free (tmpdir); } static void test_mu_store_store_msg_and_count (void) -{ +{ MuMsg *msg; MuStore *store; gchar* tmpdir; @@ -91,15 +95,15 @@ test_mu_store_store_msg_and_count (void) tmpdir = test_mu_common_get_random_tmpdir(); g_assert (tmpdir); - store = mu_store_new (tmpdir, NULL, NULL); + store = mu_store_new_writable (tmpdir, NULL, NULL); g_assert (store); - + g_assert_cmpuint (0,==,mu_store_count (store)); - + /* add one */ msg = mu_msg_new_from_file ( MU_TESTMAILDIR "cur/1283599333.1840_11.cthulhu!2,", - NULL, NULL); + NULL, NULL); g_assert (msg); g_assert_cmpuint (mu_store_store_msg (store, msg, TRUE), ==, TRUE); g_assert_cmpuint (1,==,mu_store_count (store)); @@ -116,7 +120,7 @@ test_mu_store_store_msg_and_count (void) g_assert_cmpuint (2,==,mu_store_count (store)); g_assert_cmpuint (TRUE,==, mu_store_contains_message (store, MU_TESTMAILDIR2 - "bar/cur/mail3")); + "bar/cur/mail3")); mu_msg_unref (msg); /* try to add the first one again. count should be 2 still */ @@ -126,7 +130,7 @@ test_mu_store_store_msg_and_count (void) g_assert (msg); g_assert_cmpuint (mu_store_store_msg (store, msg, TRUE), ==, TRUE); g_assert_cmpuint (2,==,mu_store_count (store)); - + mu_msg_unref (msg); mu_store_destroy (store); @@ -135,20 +139,20 @@ test_mu_store_store_msg_and_count (void) static void test_mu_store_store_msg_remove_and_count (void) -{ +{ MuMsg *msg; MuStore *store; gchar* tmpdir; GError *err; - + tmpdir = test_mu_common_get_random_tmpdir(); g_assert (tmpdir); - store = mu_store_new (tmpdir, NULL, NULL); + store = mu_store_new_writable (tmpdir, NULL, NULL); g_assert (store); - + g_assert_cmpuint (0,==,mu_store_count (store)); - + /* add one */ err = NULL; msg = mu_msg_new_from_file ( @@ -175,7 +179,7 @@ int main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); - + /* mu_runtime_init/uninit */ g_test_add_func ("/mu-store/mu-store-new-destroy", test_mu_store_new_destroy); @@ -184,10 +188,10 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-store/mu-store-store-and-count", test_mu_store_store_msg_and_count); g_test_add_func ("/mu-store/mu-store-store-remove-and-count", - test_mu_store_store_msg_remove_and_count); + test_mu_store_store_msg_remove_and_count); g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, (GLogFunc)black_hole, NULL); - + return g_test_run (); }