diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index d03066a5..9989d6f0 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -20,29 +20,39 @@ INCLUDES=$(XAPIAN_CXXFLAGS) \ $(GMIME_CFLAGS) \ $(GLIB_CFLAGS) \ -I ${top_srcdir} \ - -DMU_PROGRAM=\"${top_srcdir}/src/mu\" \ + -DMU_TESTMAILDIR=\"${top_srcdir}/src/tests/testdir\" \ + -DMU_PROGRAM=\"${top_builddir}/src//mu\" \ -DABS_SRCDIR=\"${abs_srcdir}\" noinst_PROGRAMS= $(TEST_PROGS) +noinst_LTLIBRARIES=libtestmucommon.la + TEST_PROGS += test-mu-util test_mu_util_SOURCES= test-mu-util.c -test_mu_util_LDADD= ${top_srcdir}/src/libmu.la +test_mu_util_LDADD= libtestmucommon.la TEST_PROGS += test-mu-msg-str test_mu_msg_str_SOURCES= test-mu-msg-str.c -test_mu_msg_str_LDADD= ${top_srcdir}/src/libmu.la +test_mu_msg_str_LDADD= libtestmucommon.la TEST_PROGS += test-mu-maildir test_mu_maildir_SOURCES= test-mu-maildir.c -test_mu_maildir_LDADD= ${top_srcdir}/src/libmu.la +test_mu_maildir_LDADD= libtestmucommon.la TEST_PROGS += test-mu-query test_mu_query_SOURCES= test-mu-query.c dummy.cc -test_mu_query_LDADD= ${top_srcdir}/src/libmu.la +test_mu_query_LDADD= libtestmucommon.la +libtestmucommon_la_SOURCES= \ + test-mu-common.c \ + test-mu-common.h +libtestmucommon_la_LIBADD= ../libmu.la + +# note the question marks; make does not like files with ':', so we +# use the (also supported) version with '!' instead. We could escape +# the : with \: but automake does not recognize that.... -# note the question marks; make does not like files with ':' # 11 messages, the '.ignore' message should be ignored # when indexing EXTRA_DIST= \ @@ -51,9 +61,9 @@ EXTRA_DIST= \ testdir/new/1220863087.12663_25.mindcrime \ testdir/new/1220863087.12663_21.mindcrime \ testdir/new/1220863087.12663_23.mindcrime \ - testdir/cur/1220863087.12663_5.mindcrime?2,S \ - testdir/cur/1220863087.12663_7.mindcrime?2,RS \ - testdir/cur/1220863087.12663_15.mindcrime?2,PS \ - 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/1220863087.12663_5.mindcrime!2,S \ + testdir/cur/1220863087.12663_7.mindcrime!2,RS \ + testdir/cur/1220863087.12663_15.mindcrime!2,PS \ + testdir/cur/1220863087.12663_19.mindcrime!2,S \ + testdir/cur/1220863042.12663_1.mindcrime!2,S \ + testdir/cur/1220863060.12663_3.mindcrime!2,S diff --git a/src/tests/test-mu-maildir.c b/src/tests/test-mu-maildir.c index 21335058..b6f8c004 100644 --- a/src/tests/test-mu-maildir.c +++ b/src/tests/test-mu-maildir.c @@ -28,18 +28,9 @@ #include #include - +#include "test-mu-common.h" #include "src/mu-maildir.h" -static char* -random_tmpdir (void) -{ - return g_strdup_printf ("%s%cmu-test-%x", g_get_tmp_dir(), - G_DIR_SEPARATOR, - (int)random()*getpid()*(int)time(NULL)); -} - - static void test_mu_maildir_mkmdir_01 (void) { @@ -47,7 +38,7 @@ test_mu_maildir_mkmdir_01 (void) gchar *tmpdir, *mdir, *tmp; const gchar *subs[] = {"tmp", "cur", "new"}; - tmpdir = random_tmpdir (); + tmpdir = test_mu_common_get_random_tmpdir (); mdir = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux"); @@ -81,7 +72,7 @@ test_mu_maildir_mkmdir_02 (void) gchar *tmpdir, *mdir, *tmp; const gchar *subs[] = {"tmp", "cur", "new"}; - tmpdir = random_tmpdir (); + tmpdir = test_mu_common_get_random_tmpdir (); mdir = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux"); @@ -136,11 +127,17 @@ copy_test_data (void) { gchar *dir, *cmd; - dir = random_tmpdir(); + dir = test_mu_common_get_random_tmpdir(); cmd = g_strdup_printf ("mkdir %s", dir); g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL)); g_free (cmd); - cmd = g_strdup_printf ("cp -R testdir %s", dir); + + cmd = g_strdup_printf ("cp -R %s %s", MU_TESTMAILDIR, dir); + g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL)); + g_free (cmd); + + /* unbreak make distcheck */ + cmd = g_strdup_printf ("chmod -R 700 %s", dir); g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL)); g_free (cmd); @@ -174,7 +171,6 @@ msg_cb (const char *fullpath, gboolean enter, WalkData *data) } - static void test_mu_maildir_walk_01 (void) { @@ -208,7 +204,7 @@ test_mu_maildir_walk_02 (void) tmpdir = copy_test_data (); memset (&data, 0, sizeof(WalkData)); - + /* mark the 'new' dir with '.noindex', to ignore it */ cmd = g_strdup_printf ("touch %s%ctestdir%cnew%c.noindex", tmpdir, G_DIR_SEPARATOR, G_DIR_SEPARATOR, diff --git a/src/tests/test-mu-msg-str.c b/src/tests/test-mu-msg-str.c index 6a5cff06..39ea2746 100644 --- a/src/tests/test-mu-msg-str.c +++ b/src/tests/test-mu-msg-str.c @@ -27,6 +27,8 @@ #include #include + +#include "test-mu-common.h" #include "src/mu-msg-str.h" static void diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 00702681..d1f8ba7b 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -29,24 +29,9 @@ #include +#include "test-mu-common.h" #include "src/mu-query-xapian.h" -static char* -random_tmpdir (void) -{ - return g_strdup_printf ("%s%cmu-test-%x", g_get_tmp_dir(), - G_DIR_SEPARATOR, - (int)random()*getpid()*(int)time(NULL)); -} - - - -/* static gboolean */ -/* ignore_error (const char* log_domain, GLogLevelFlags log_level, const gchar* msg, */ -/* gpointer user_data) */ -/* { */ -/* return FALSE; /\* don't abort *\/ */ -/* } */ static void shutup (void) {} @@ -56,10 +41,12 @@ fill_database (void) { gchar *cmdline, *tmpdir, *xpath; - tmpdir = random_tmpdir(); - cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s%ctestdir" + tmpdir = test_mu_common_get_random_tmpdir(); + cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" " --quiet", - MU_PROGRAM, tmpdir, ABS_SRCDIR, G_DIR_SEPARATOR); + MU_PROGRAM, tmpdir, MU_TESTMAILDIR); + + g_print ("[%s]\n", cmdline); g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, NULL)); g_free (cmdline); @@ -106,7 +93,8 @@ test_mu_query_01 (void) if (!mu_msg_iter_xapian_is_null (iter)) do { ++count; } while (mu_msg_iter_xapian_next (iter)); - + + g_print ("[%s][%d,%d]\n", queries[i].query,queries[i].count,count); g_assert_cmpuint (queries[i].count, ==, count); mu_msg_iter_xapian_destroy (iter); }