2020-11-03 09:01:18 +01:00
|
|
|
/*
|
2012-03-07 23:11:31 +01:00
|
|
|
**
|
2020-01-01 14:41:49 +01:00
|
|
|
** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2011-05-19 21:24:12 +02:00
|
|
|
**
|
|
|
|
** 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,
|
2012-03-07 23:11:31 +01:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2011-05-19 21:24:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-11-03 09:01:18 +01:00
|
|
|
#include "test-mu-common.hh"
|
2019-07-28 13:28:25 +02:00
|
|
|
#include "mu-store.hh"
|
2020-11-03 09:01:18 +01:00
|
|
|
#include "mu-query.hh"
|
2011-05-19 21:24:12 +02:00
|
|
|
|
2012-09-15 17:03:58 +02:00
|
|
|
static gchar *CONTACTS_CACHE = NULL;
|
2012-05-30 17:25:49 +02:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
static gchar*
|
|
|
|
fill_contacts_cache (void)
|
|
|
|
{
|
|
|
|
gchar *cmdline, *tmpdir;
|
2012-05-30 17:25:49 +02:00
|
|
|
GError *err;
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
2020-02-09 17:01:06 +01:00
|
|
|
cmdline = g_strdup_printf (
|
|
|
|
"/bin/sh -c '"
|
|
|
|
"%s init --muhome=%s --maildir=%s --quiet; "
|
|
|
|
"%s index --muhome=%s --quiet'",
|
|
|
|
MU_PROGRAM, tmpdir, MU_TESTMAILDIR,
|
|
|
|
MU_PROGRAM, tmpdir);
|
|
|
|
|
2012-03-18 23:14:48 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("%s\n", cmdline);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2012-05-30 17:25:49 +02:00
|
|
|
err = NULL;
|
|
|
|
if (!g_spawn_command_line_sync (cmdline, NULL, NULL,
|
|
|
|
NULL, &err)) {
|
|
|
|
g_printerr ("Error: %s\n", err ? err->message : "?");
|
|
|
|
g_assert (0);
|
|
|
|
}
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2012-05-30 17:25:49 +02:00
|
|
|
g_free (cmdline);
|
2011-05-19 21:24:12 +02:00
|
|
|
return tmpdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_plain (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=plain "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-18 23:14:48 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("%s\n", cmdline);
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-18 23:14:48 +01:00
|
|
|
|
|
|
|
/* note, output order is unspecified */
|
|
|
|
g_assert (output);
|
|
|
|
if (output[0] == 'H')
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"Helmut Kröger hk@testmu.xxx\n"
|
|
|
|
"Mü testmu@testmu.xx\n");
|
|
|
|
else
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"Mü testmu@testmu.xx\n"
|
|
|
|
"Helmut Kröger hk@testmu.xxx\n");
|
2011-05-19 21:24:12 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_bbdb (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar *cmdline, *output, *erroutput, *expected;
|
2011-05-20 07:20:11 +02:00
|
|
|
gchar today[12];
|
|
|
|
struct tm *tmtoday;
|
|
|
|
time_t now;
|
2011-07-20 23:58:40 +02:00
|
|
|
const char *old_tz;
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-07-20 23:58:40 +02:00
|
|
|
old_tz = set_tz ("Europe/Helsinki");
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=bbdb "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2018-06-11 09:49:07 +02:00
|
|
|
#define frm1 ";; -*-coding: utf-8-emacs;-*-\n" \
|
|
|
|
";;; file-version: 6\n" \
|
|
|
|
"[\"Helmut\" \"Kröger\" nil nil nil nil (\"hk@testmu.xxx\") " \
|
|
|
|
"((creation-date . \"%s\") " \
|
|
|
|
"(time-stamp . \"1970-01-01\")) nil]\n" \
|
|
|
|
"[\"Mü\" \"\" nil nil nil nil (\"testmu@testmu.xx\") " \
|
|
|
|
"((creation-date . \"%s\") " \
|
2011-05-20 07:20:11 +02:00
|
|
|
"(time-stamp . \"1970-01-01\")) nil]\n"
|
|
|
|
|
2012-03-18 23:14:48 +01:00
|
|
|
|
2018-06-11 09:49:07 +02:00
|
|
|
#define frm2 ";; -*-coding: utf-8-emacs;-*-\n" \
|
|
|
|
";;; file-version: 6\n" \
|
|
|
|
"[\"Mü\" \"\" nil nil nil nil (\"testmu@testmu.xx\") " \
|
|
|
|
"((creation-date . \"%s\") " \
|
|
|
|
"(time-stamp . \"1970-01-01\")) nil]\n" \
|
|
|
|
"[\"Helmut\" \"Kröger\" nil nil nil nil (\"hk@testmu.xxx\") " \
|
|
|
|
"((creation-date . \"%s\") " \
|
2012-03-18 23:14:48 +01:00
|
|
|
"(time-stamp . \"1970-01-01\")) nil]\n"
|
|
|
|
|
|
|
|
g_assert (output);
|
|
|
|
|
2011-05-20 07:20:11 +02:00
|
|
|
now = time(NULL);
|
|
|
|
tmtoday = localtime(&now);
|
|
|
|
strftime(today,sizeof(today),"%Y-%m-%d", tmtoday);
|
2012-03-18 23:14:48 +01:00
|
|
|
|
|
|
|
expected = g_strdup_printf (output[52] == 'H' ? frm1 : frm2,
|
|
|
|
today, today);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-20 07:20:11 +02:00
|
|
|
/* g_print ("\n%s\n", output); */
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-20 07:20:11 +02:00
|
|
|
g_assert_cmpstr (output, ==, expected);
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
2011-05-20 07:20:11 +02:00
|
|
|
g_free (expected);
|
2011-07-20 23:58:40 +02:00
|
|
|
|
|
|
|
set_tz (old_tz);
|
2011-05-19 21:24:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_wl (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=wl "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-18 23:14:48 +01:00
|
|
|
|
|
|
|
g_assert (output);
|
|
|
|
if (output[0] == 'h')
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"hk@testmu.xxx \"HelmutK\" \"Helmut Kröger\"\n"
|
|
|
|
"testmu@testmu.xx \"Mü\" \"Mü\"\n");
|
|
|
|
else
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"testmu@testmu.xx \"Mü\" \"Mü\"\n"
|
|
|
|
"hk@testmu.xxx \"HelmutK\" \"Helmut Kröger\"\n");
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_mutt_alias (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-alias "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-18 23:14:48 +01:00
|
|
|
|
|
|
|
/* both orders are possible... */
|
|
|
|
g_assert (output);
|
|
|
|
|
|
|
|
if (output[6] == 'H')
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"alias HelmutK Helmut Kröger <hk@testmu.xxx>\n"
|
|
|
|
"alias Mü Mü <testmu@testmu.xx>\n");
|
|
|
|
else
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"alias Mü Mü <testmu@testmu.xx>\n"
|
|
|
|
"alias HelmutK Helmut Kröger <hk@testmu.xxx>\n");
|
|
|
|
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_mutt_ab (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-ab "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("%s\n", cmdline);
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-18 23:14:48 +01:00
|
|
|
g_assert (output);
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2012-03-18 23:14:48 +01:00
|
|
|
if (output[39] == 'h')
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"Matching addresses in the mu database:\n"
|
|
|
|
"hk@testmu.xxx\tHelmut Kröger\t\n"
|
|
|
|
"testmu@testmu.xx\tMü\t\n");
|
|
|
|
else
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"Matching addresses in the mu database:\n"
|
|
|
|
"testmu@testmu.xx\tMü\t\n"
|
|
|
|
"hk@testmu.xxx\tHelmut Kröger\t\n");
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_org_contact (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar*cmdline, *output, *erroutput;
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=org-contact "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-18 23:14:48 +01:00
|
|
|
|
|
|
|
g_assert (output);
|
|
|
|
|
|
|
|
if (output[2] == 'H')
|
|
|
|
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");
|
|
|
|
else
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"* Mü\n"
|
|
|
|
":PROPERTIES:\n"
|
|
|
|
":EMAIL: testmu@testmu.xx\n"
|
|
|
|
":END:\n\n"
|
|
|
|
"* Helmut Kröger\n"
|
|
|
|
":PROPERTIES:\n"
|
|
|
|
":EMAIL: hk@testmu.xxx\n"
|
|
|
|
":END:\n\n");
|
|
|
|
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_cfind_csv (void)
|
|
|
|
{
|
2012-09-15 17:03:58 +02:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=csv "
|
|
|
|
"'testmu\\.xxx?'",
|
2012-09-15 17:03:58 +02:00
|
|
|
MU_PROGRAM, CONTACTS_CACHE);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("%s\n", cmdline);
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-03-18 23:14:48 +01:00
|
|
|
g_assert (output);
|
2020-06-08 22:04:05 +02:00
|
|
|
if (output[1] == 'H')
|
2012-03-18 23:14:48 +01:00
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
2020-06-08 22:04:05 +02:00
|
|
|
"\"Helmut Kröger\",\"hk@testmu.xxx\"\n"
|
|
|
|
"\"Mü\",\"testmu@testmu.xx\"\n");
|
2012-03-18 23:14:48 +01:00
|
|
|
else
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
2020-06-08 22:04:05 +02:00
|
|
|
"\"Mü\",\"testmu@testmu.xx\"\n"
|
|
|
|
"\"Helmut Kröger\",\"hk@testmu.xxx\"\n");
|
2011-05-19 21:24:12 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
2012-03-07 23:11:31 +01:00
|
|
|
if (!set_en_us_utf8_locale())
|
|
|
|
return 0; /* don't error out... */
|
|
|
|
|
2012-09-15 17:03:58 +02:00
|
|
|
CONTACTS_CACHE = fill_contacts_cache ();
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
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);
|
2012-03-07 23:11:31 +01:00
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
g_log_set_handler (NULL,
|
2020-06-08 22:04:05 +02:00
|
|
|
(GLogLevelFlags)(
|
2011-05-19 21:24:12 +02:00
|
|
|
G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING|
|
2020-06-08 22:04:05 +02:00
|
|
|
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION),
|
2011-05-19 21:24:12 +02:00
|
|
|
(GLogFunc)black_hole, NULL);
|
|
|
|
|
|
|
|
rv = g_test_run ();
|
|
|
|
|
2012-09-15 17:03:58 +02:00
|
|
|
g_free (CONTACTS_CACHE);
|
|
|
|
CONTACTS_CACHE = NULL;
|
|
|
|
|
2011-05-19 21:24:12 +02:00
|
|
|
return rv;
|
|
|
|
}
|