From f2770c5957671cf4c17952e349b10c37fe45fb8a Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 26 Sep 2010 15:52:07 +0300 Subject: [PATCH] * added some more test cases --- src/tests/Makefile.am | 9 +++- src/tests/test-mu-cmd.c | 91 ++++++++++++++++++++++++++++++++ src/tests/test-mu-query.c | 2 - src/tests/testdir2/bar/cur/mail1 | 12 +++++ src/tests/testdir2/bar/cur/mail2 | 12 +++++ 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 src/tests/test-mu-cmd.c create mode 100644 src/tests/testdir2/bar/cur/mail1 create mode 100644 src/tests/testdir2/bar/cur/mail2 diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 1bd7be3f..fff8fabf 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -21,6 +21,7 @@ INCLUDES=$(XAPIAN_CXXFLAGS) \ $(GLIB_CFLAGS) \ -I ${top_srcdir} \ -DMU_TESTMAILDIR=\"${abs_srcdir}/testdir/\" \ + -DMU_TESTMAILDIR2=\"${abs_srcdir}/testdir2/\" \ -DMU_PROGRAM=\"${abs_top_builddir}/src/mu\" \ -DABS_SRCDIR=\"${abs_srcdir}\" @@ -50,6 +51,10 @@ TEST_PROGS += test-mu-query test_mu_query_SOURCES= test-mu-query.c dummy.cc test_mu_query_LDADD= libtestmucommon.la +TEST_PROGS += test-mu-cmd +test_mu_cmd_SOURCES= test-mu-cmd.c dummy.cc +test_mu_cmd_LDADD= libtestmucommon.la + TEST_PROGS += test-mu-msg test_mu_msg_SOURCES= test-mu-msg.c test_mu_msg_LDADD= libtestmucommon.la @@ -78,4 +83,6 @@ EXTRA_DIST= \ testdir/cur/1220863087.12663_19.mindcrime!2,S \ testdir/cur/1220863042.12663_1.mindcrime!2,S \ testdir/cur/1220863060.12663_3.mindcrime!2,S \ - testdir/cur/1283599333.1840_11.cthulhu!2, + testdir/cur/1283599333.1840_11.cthulhu!2, \ + testdir2/bar/cur/mail1 \ + testdir2/bar/cur/mail2 diff --git a/src/tests/test-mu-cmd.c b/src/tests/test-mu-cmd.c new file mode 100644 index 00000000..14364718 --- /dev/null +++ b/src/tests/test-mu-cmd.c @@ -0,0 +1,91 @@ +/* +** Copyright (C) 2008-2010 Dirk-Jan C. Binnema +** +** 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 +** Free Software Foundation; either version 3, or (at your option) any +** later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** 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. +** +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /*HAVE_CONFIG_H*/ + +#include +#include + +#include +#include +#include + +#include "test-mu-common.h" +#include "src/mu-store.h" + + +/* tests for the command line interface, uses testdir2 */ + +static gchar* +fill_database (void) +{ + 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, MU_TESTMAILDIR2); + + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, NULL)); + g_free (cmdline); + + xpath = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR, "xapian"); + g_free (tmpdir); + + return xpath; +} + + +static void +test_mu_index (void) +{ + MuStore *store; + gchar *xpath; + + xpath = fill_database (); + g_assert (xpath != NULL); + + store = mu_store_new (xpath); + g_assert (store); + + g_assert_cmpuint (mu_store_count (store), ==, 2); + mu_store_destroy (store); + g_free (xpath); +} + + + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index); +// g_test_add_func ("/mu-cmd/test-mu-find", test_mu_find_01); +// g_test_add_func ("/mu-cmd/test-mu-find", test_mu_find_02); + + 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 (); +} + diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index a0e11ec3..8df8e0c6 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -32,8 +32,6 @@ #include "src/mu-query.h" -static void shutup (void) {} - static gchar* fill_database (void) diff --git a/src/tests/testdir2/bar/cur/mail1 b/src/tests/testdir2/bar/cur/mail1 new file mode 100644 index 00000000..5d98edef --- /dev/null +++ b/src/tests/testdir2/bar/cur/mail1 @@ -0,0 +1,12 @@ +Date: Thu, 31 Jul 2008 14:57:25 -0400 +From: "Mickey Mouse" +Subject: a mail about avians +To: "John Smith" +Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com> +MIME-version: 1.0 +Content-type: text/plain; charset=us-ascii +Content-transfer-encoding: 7BIT +Precedence: high + +This is a mail about birds. + diff --git a/src/tests/testdir2/bar/cur/mail2 b/src/tests/testdir2/bar/cur/mail2 new file mode 100644 index 00000000..0aadc7ae --- /dev/null +++ b/src/tests/testdir2/bar/cur/mail2 @@ -0,0 +1,12 @@ +Date: Thu, 31 Jul 2008 14:57:25 -0400 +From: "Kaspar Hauser" +Subject: a mail about south-american mammals +To: "William Jones" +Message-id: <3BE9E6535E0D852173@emss35m06.us.lmco.com> +MIME-version: 1.0 +Content-type: text/plain; charset=us-ascii +Content-transfer-encoding: 7BIT +Precedence: high + +Capibaras are cute animals. +