* tests: add unit-tests for 'mu cfind'; fix up merge
This commit is contained in:
@ -64,6 +64,11 @@ TEST_PROGS += test-mu-cmd
|
|||||||
test_mu_cmd_SOURCES= test-mu-cmd.c dummy.cc
|
test_mu_cmd_SOURCES= test-mu-cmd.c dummy.cc
|
||||||
test_mu_cmd_LDADD= libtestmucommon.la
|
test_mu_cmd_LDADD= libtestmucommon.la
|
||||||
|
|
||||||
|
TEST_PROGS += test-mu-cmd-cfind
|
||||||
|
test_mu_cmd_cfind_SOURCES= test-mu-cmd-cfind.c dummy.cc
|
||||||
|
test_mu_cmd_cfind_LDADD= libtestmucommon.la
|
||||||
|
|
||||||
|
|
||||||
TEST_PROGS += test-mu-msg
|
TEST_PROGS += test-mu-msg
|
||||||
test_mu_msg_SOURCES= test-mu-msg.c dummy.cc
|
test_mu_msg_SOURCES= test-mu-msg.c dummy.cc
|
||||||
test_mu_msg_LDADD= libtestmucommon.la
|
test_mu_msg_LDADD= libtestmucommon.la
|
||||||
|
|||||||
281
src/tests/test-mu-cmd-cfind.c
Normal file
281
src/tests/test-mu-cmd-cfind.c
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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 "src/mu-store.h"
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
fill_contacts_cache (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_TESTMAILDIR);
|
||||||
|
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
||||||
|
NULL, NULL));
|
||||||
|
g_free (cmdline);
|
||||||
|
|
||||||
|
return tmpdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_plain (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=plain "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
"Helmut Kröger hk@testmu.xxx\n"
|
||||||
|
"Mü testmu@testmu.xx\n");
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_bbdb (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=bbdb "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
";; -*-coding: utf-8-emacs;-*-\n"
|
||||||
|
";;; file-version: 6\n"
|
||||||
|
|
||||||
|
"[\"Helmut\" \"Kröger\" nil nil nil nil (\"hk@testmu.xxx\") "
|
||||||
|
"((creation-date . \"2011-05-19\") "
|
||||||
|
"(time-stamp . \"1970-01-01\")) nil]\n"
|
||||||
|
|
||||||
|
"[\"Mü\" \"\" nil nil nil nil (\"testmu@testmu.xx\") "
|
||||||
|
"((creation-date . \"2011-05-19\") "
|
||||||
|
"(time-stamp . \"1970-01-01\")) nil]\n");
|
||||||
|
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_wl (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=wl "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
"hk@testmu.xxx \"HelmutK\" \"Helmut Kröger\"\n"
|
||||||
|
"testmu@testmu.xx \"Mü\" \"Mü\"\n");
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_mutt_alias (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-alias "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
"alias HelmutK Helmut Kröger <hk@testmu.xxx>\n"
|
||||||
|
"alias Mü Mü <testmu@testmu.xx>\n");
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_mutt_ab (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-ab "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
"hk@testmu.xxx\tHelmut Kröger\t\n"
|
||||||
|
"testmu@testmu.xx\tMü\t\n");
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_org_contact (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=org-contact "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
"* Helmut Kröger\n"
|
||||||
|
":PROPERTIES:\n"
|
||||||
|
":EMAIL: hk@testmu.xxx\n"
|
||||||
|
":END:\n\n"
|
||||||
|
|
||||||
|
"* Mü\n"
|
||||||
|
":PROPERTIES:\n"
|
||||||
|
":EMAIL: testmu@testmu.xx\n"
|
||||||
|
":END:\n\n");
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_cfind_csv (void)
|
||||||
|
{
|
||||||
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
|
muhome = fill_contacts_cache ();
|
||||||
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=csv "
|
||||||
|
"'testmu\\.xxx?'",
|
||||||
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
|
output = erroutput = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
|
g_assert_cmpstr (output,
|
||||||
|
==,
|
||||||
|
"Helmut Kröger,hk@testmu.xxx\n"
|
||||||
|
"Mü,testmu@testmu.xx\n");
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (muhome);
|
||||||
|
g_free (output);
|
||||||
|
g_free (erroutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-plain", test_mu_cfind_plain);
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-bbdb", test_mu_cfind_bbdb);
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-wl", test_mu_cfind_wl);
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-mutt-alias",
|
||||||
|
test_mu_cfind_mutt_alias);
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-mutt-ab",
|
||||||
|
test_mu_cfind_mutt_ab);
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-org-contact",
|
||||||
|
test_mu_cfind_org_contact);
|
||||||
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-csv",
|
||||||
|
test_mu_cfind_csv);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
/*
|
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||||
|
**
|
||||||
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2011 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
|
||||||
@ -44,7 +45,8 @@ fill_database (void)
|
|||||||
tmpdir = test_mu_common_get_random_tmpdir();
|
tmpdir = test_mu_common_get_random_tmpdir();
|
||||||
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_TESTMAILDIR2);
|
MU_PROGRAM,
|
||||||
|
tmpdir, MU_TESTMAILDIR2);
|
||||||
|
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
@ -171,7 +173,8 @@ test_mu_find_04 (void)
|
|||||||
muhome = fill_database ();
|
muhome = fill_database ();
|
||||||
g_assert (muhome);
|
g_assert (muhome);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s --muhome=%cfoo%cbar%cnonexistent find f:socrates",
|
cmdline = g_strdup_printf ("%s --muhome=%cfoo%cbar%cnonexistent "
|
||||||
|
"find f:socrates",
|
||||||
MU_PROGRAM,
|
MU_PROGRAM,
|
||||||
G_DIR_SEPARATOR,
|
G_DIR_SEPARATOR,
|
||||||
G_DIR_SEPARATOR,
|
G_DIR_SEPARATOR,
|
||||||
@ -208,7 +211,8 @@ test_mu_extract_01 (void)
|
|||||||
/* g_print ("[%s]", cmdline); */
|
/* g_print ("[%s]", cmdline); */
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
g_assert_cmpstr (output,
|
g_assert_cmpstr (output,
|
||||||
==,
|
==,
|
||||||
"MIME-parts in this message:\n"
|
"MIME-parts in this message:\n"
|
||||||
@ -250,7 +254,8 @@ test_mu_extract_02 (void)
|
|||||||
|
|
||||||
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
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",
|
cmdline = g_strdup_printf ("%s extract --muhome=%s -a "
|
||||||
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
||||||
MU_PROGRAM,
|
MU_PROGRAM,
|
||||||
tmpdir,
|
tmpdir,
|
||||||
tmpdir,
|
tmpdir,
|
||||||
@ -323,19 +328,23 @@ test_mu_extract_04 (void)
|
|||||||
|
|
||||||
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
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",
|
cmdline = g_strdup_printf ("%s extract --muhome=%s -a "
|
||||||
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
||||||
MU_PROGRAM, tmpdir, tmpdir,
|
MU_PROGRAM, tmpdir, tmpdir,
|
||||||
MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
||||||
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
||||||
|
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
g_assert_cmpstr (output, ==, "");
|
g_assert_cmpstr (output, ==, "");
|
||||||
g_assert_cmpstr (erroutput, ==, "");
|
g_assert_cmpstr (erroutput, ==, "");
|
||||||
g_free (erroutput);
|
g_free (erroutput);
|
||||||
g_free (output);
|
g_free (output);
|
||||||
|
|
||||||
/* now, it should fail, because we don't allow overwrites without --overwrite */
|
/* now, it should fail, because we don't allow overwrites
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
|
* without --overwrite */
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
g_assert_cmpstr (output, ==, "");
|
g_assert_cmpstr (output, ==, "");
|
||||||
g_assert_cmpstr (erroutput, !=, "");
|
g_assert_cmpstr (erroutput, !=, "");
|
||||||
g_free (erroutput);
|
g_free (erroutput);
|
||||||
@ -345,9 +354,11 @@ test_mu_extract_04 (void)
|
|||||||
/* this should work now, because we have specified --overwrite */
|
/* this should work now, because we have specified --overwrite */
|
||||||
cmdline = g_strdup_printf ("%s extract --muhome=%s -a --overwrite "
|
cmdline = g_strdup_printf ("%s extract --muhome=%s -a --overwrite "
|
||||||
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
||||||
MU_PROGRAM, tmpdir, tmpdir, MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
MU_PROGRAM, tmpdir, tmpdir,
|
||||||
|
MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
||||||
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
|
NULL, NULL));
|
||||||
g_assert_cmpstr (output, ==, "");
|
g_assert_cmpstr (output, ==, "");
|
||||||
g_assert_cmpstr (erroutput, ==, "");
|
g_assert_cmpstr (erroutput, ==, "");
|
||||||
g_free (erroutput);
|
g_free (erroutput);
|
||||||
@ -474,9 +485,8 @@ main (int argc, char *argv[])
|
|||||||
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||||
(GLogFunc)black_hole, NULL);
|
(GLogFunc)black_hole, NULL);
|
||||||
|
|
||||||
mu_msg_gmime_init ();
|
|
||||||
rv = g_test_run ();
|
rv = g_test_run ();
|
||||||
mu_msg_gmime_uninit();
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -171,7 +171,7 @@ main (int argc, char *argv[])
|
|||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
g_test_add_func ("/mu-contact/test-mu-contacts-01", test_mu_contacts_01);
|
g_test_add_func ("/mu-contacts/test-mu-contacts-01", test_mu_contacts_01);
|
||||||
|
|
||||||
g_log_set_handler (NULL,
|
g_log_set_handler (NULL,
|
||||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||||
|
|||||||
Reference in New Issue
Block a user