Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* guile: beginnings of some unit tests
- Loading branch information
Showing
4 changed files
with
304 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (C) 2008-2011 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 | ||
## 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. | ||
|
||
include $(top_srcdir)/gtest.mk | ||
|
||
INCLUDES=$(XAPIAN_CXXFLAGS) \ | ||
$(GMIME_CFLAGS) \ | ||
$(GLIB_CFLAGS) \ | ||
-I ${top_srcdir} \ | ||
-I ${top_srcdir}/lib \ | ||
-I ${top_srcdir}/lib/tests \ | ||
-DMU_TESTMAILDIR=\"${top_srcdir}/lib/tests/testdir\" \ | ||
-DMU_TESTMAILDIR2=\"${top_srcdir}/lib/tests/testdir2\" \ | ||
-DMU_TESTMAILDIR3=\"${top_srcdir}/lib/tests/testdir3\" \ | ||
-DMU_PROGRAM=\"${abs_top_builddir}/mu/mu\" \ | ||
-DMU_GUILE_MODULE_PATH=\"${top_srcdir}/guile/mu\" \ | ||
-DABS_CURDIR=\"${abs_builddir}\" \ | ||
-DABS_SRCDIR=\"${abs_srcdir}\" | ||
|
||
# don't use -Werror, as it might break on other compilers | ||
# use -Wno-unused-parameters, because some callbacks may not | ||
# really need all the params they get | ||
AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement | ||
AM_CXXFLAGS=-Wall -Wextra -Wno-unused-parameter | ||
|
||
noinst_PROGRAMS= $(TEST_PROGS) | ||
|
||
TEST_PROGS += test-mu-guile | ||
test_mu_guile_SOURCES= test-mu-guile.c dummy.cc | ||
test_mu_guile_LDADD=${top_builddir}/lib/tests/libtestmucommon.la | ||
|
||
# we need to use dummy.cc to enforce c++ linking... | ||
BUILT_SOURCES= \ | ||
dummy.cc | ||
dummy.cc: | ||
touch dummy.cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | ||
** | ||
** Copyright (C) 2012 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 | ||
** 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. | ||
** | ||
*/ | ||
|
||
#if HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif /*HAVE_CONFIG_H*/ | ||
|
||
#include <glib.h> | ||
#include <glib/gstdio.h> | ||
|
||
#include "../mu-query.h" | ||
|
||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
|
||
#include "test-mu-common.h" | ||
#include "mu-store.h" | ||
|
||
|
||
/* tests for the command line interface, uses testdir2 */ | ||
|
||
static gchar* | ||
fill_database (void) | ||
{ | ||
gchar *cmdline, *tmpdir; | ||
GError *err; | ||
|
||
tmpdir = test_mu_common_get_random_tmpdir(); | ||
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" | ||
" --quiet", | ||
MU_PROGRAM, | ||
tmpdir, MU_TESTMAILDIR2); | ||
if (g_test_verbose()) | ||
g_print ("%s\n", cmdline); | ||
|
||
err = NULL; | ||
if (!g_spawn_command_line_sync (cmdline, NULL, NULL, | ||
NULL, &err)) { | ||
g_printerr ("Error: %s\n", err ? err->message : "?"); | ||
g_assert (0); | ||
} | ||
|
||
g_free (cmdline); | ||
return tmpdir; | ||
} | ||
|
||
|
||
static void | ||
test_something (const char *what) | ||
{ | ||
char *dir, *cmdline, *output, *erroutput; | ||
gint result; | ||
|
||
dir = fill_database (); | ||
cmdline = g_strdup_printf ( | ||
"%s -q -L %s -e main %s/test-mu-guile.scm --muhome=%s --test=%s", | ||
GUILE_BINARY, | ||
MU_GUILE_MODULE_PATH, | ||
ABS_SRCDIR, | ||
dir, | ||
what); | ||
|
||
if (g_test_verbose ()) | ||
g_print ("cmdline: %s\n", cmdline); | ||
|
||
output = erroutput = NULL; | ||
g_assert (g_spawn_command_line_sync (cmdline, | ||
&output, &erroutput, | ||
&result, NULL)); | ||
g_assert (result == 0); | ||
|
||
if (g_test_verbose ()) { | ||
if (output) | ||
g_print ("stdout: %s\n", output); | ||
if (erroutput) | ||
g_print ("stderr: %s\n", erroutput); | ||
} | ||
|
||
g_free (output); | ||
g_free (erroutput); | ||
g_free (dir); | ||
g_free (cmdline); | ||
} | ||
|
||
static void | ||
test_mu_guile_queries (void) | ||
{ | ||
test_something ("queries"); | ||
} | ||
|
||
static void | ||
test_mu_guile_messages (void) | ||
{ | ||
test_something ("message"); | ||
} | ||
|
||
static void | ||
test_mu_guile_stats (void) | ||
{ | ||
test_something ("stats"); | ||
} | ||
|
||
|
||
int | ||
main (int argc, char *argv[]) | ||
{ | ||
int rv; | ||
g_test_init (&argc, &argv, NULL); | ||
|
||
if (!set_en_us_utf8_locale()) | ||
return 0; /* don't error out... */ | ||
|
||
g_test_add_func ("/guile/queries", test_mu_guile_queries); | ||
g_test_add_func ("/guile/message", test_mu_guile_messages); | ||
g_test_add_func ("/guile/stats", test_mu_guile_stats); | ||
|
||
|
||
g_log_set_handler (NULL, | ||
G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING| | ||
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, | ||
(GLogFunc)black_hole, NULL); | ||
|
||
rv = g_test_run (); | ||
|
||
return rv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/bin/sh | ||
exec guile -e main -s $0 $@ | ||
!# | ||
|
||
;; Copyright (C) 2012 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 | ||
;; 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. | ||
(setlocale LC_ALL "") | ||
|
||
(use-modules (ice-9 getopt-long) (ice-9 optargs) (ice-9 popen) (ice-9 format)) | ||
(use-modules (mu) (mu message) (mu stats) (mu plot)) | ||
|
||
(define (n-results-or-exit query n) | ||
"Run QUERY, and exit 1 if the number of results != N." | ||
(let ((lst (mu:message-list query))) | ||
(if (not (= (length lst) n)) | ||
(begin | ||
(simple-format (current-error-port) "Query: \"~A\"; expected ~A, got ~A\n" | ||
query n (length lst)) | ||
(exit 1))))) | ||
|
||
(define (test-queries) | ||
"Test a bunch of queries (or die trying)." | ||
|
||
(n-results-or-exit "hello" 1) | ||
(n-results-or-exit "f:john fruit" 1) | ||
(n-results-or-exit "f:soc@example.com" 1) | ||
(n-results-or-exit "t:alki@example.com" 1) | ||
(n-results-or-exit "t:alcibiades" 1) | ||
(n-results-or-exit "f:soc@example.com OR f:john" 2) | ||
(n-results-or-exit "f:soc@example.com OR f:john OR t:edmond" 3) | ||
(n-results-or-exit "t:julius" 1) | ||
(n-results-or-exit "s:dude" 1) | ||
(n-results-or-exit "t:dantès" 1) | ||
(n-results-or-exit "file:sittingbull.jpg" 1) | ||
(n-results-or-exit "file:custer.jpg" 1) | ||
(n-results-or-exit "file:custer.*" 1) | ||
(n-results-or-exit "j:sit*" 1) | ||
(n-results-or-exit "mime:image/jpeg" 1) | ||
(n-results-or-exit "mime:text/plain" 12) | ||
(n-results-or-exit "y:text*" 12) | ||
(n-results-or-exit "y:image*" 1) | ||
(n-results-or-exit "mime:message/rfc822" 2)) | ||
|
||
|
||
(define (str-equal-or-exit s1 s2) | ||
"S1 == S2 or exit 1." | ||
;; (format #t "'~A' <=> '~A'\n" s1 s2) | ||
(if (not (string= s1 s2)) | ||
(begin | ||
(simple-format (current-error-port) "Message: expected \"~A\", got \"~A\"\n" | ||
s1 s2) | ||
(exit 1)))) | ||
|
||
(define (test-message) | ||
"Test functions for a particular message." | ||
(let ((msg (car (mu:message-list "hello")))) | ||
(str-equal-or-exit (mu:subject msg) "Fwd: rfc822") | ||
(str-equal-or-exit (mu:to msg) "martin") | ||
(str-equal-or-exit (mu:from msg) "foobar <foo@example.com>"))) | ||
|
||
|
||
(define (test-stats) | ||
"Test statistical functions." | ||
) | ||
|
||
|
||
(define (main args) | ||
|
||
(let* ((optionspec '((muhome (value #t)) | ||
(test (value #t)))) | ||
(options (getopt-long args optionspec)) | ||
(muhome (option-ref options 'muhome #f)) | ||
(test (option-ref options 'test #f))) | ||
|
||
(mu:initialize muhome) | ||
|
||
(if test | ||
(cond | ||
((string= test "queries") (test-queries)) | ||
((string= test "message") (test-message)) | ||
((string= test "stats") (test-stats)) | ||
(#t (exit 1)))))) | ||
|
||
|
||
;; Local Variables: | ||
;; mode: scheme | ||
;; End: |