2011-05-19 18:55:50 +02:00
|
|
|
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
2011-08-29 22:39:11 +02:00
|
|
|
**
|
2016-11-05 12:35:26 +01:00
|
|
|
** Copyright (C) 2008-2016 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-09-26 14:52:07 +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,
|
2011-08-29 22:39:11 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-09-26 14:52:07 +02:00
|
|
|
*/
|
|
|
|
|
2010-11-20 13:43:35 +01:00
|
|
|
#if HAVE_CONFIG_H
|
2010-09-26 14:52:07 +02:00
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
2013-04-16 23:09:08 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2010-09-26 14:52:07 +02:00
|
|
|
|
2010-11-11 21:05:10 +01:00
|
|
|
#include "../mu-query.h"
|
|
|
|
|
2010-09-26 14:52:07 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "test-mu-common.h"
|
2019-07-28 13:28:25 +02:00
|
|
|
#include "mu-store.hh"
|
2010-09-26 14:52:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* tests for the command line interface, uses testdir2 */
|
|
|
|
|
2012-07-12 15:13:26 +02:00
|
|
|
static gchar *DBPATH; /* global */
|
|
|
|
|
2010-09-26 14:52:07 +02:00
|
|
|
static gchar*
|
|
|
|
fill_database (void)
|
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
gchar *cmdline, *tmpdir;
|
2012-05-30 17:25:49 +02:00
|
|
|
GError *err;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
|
|
|
" --quiet",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir, MU_TESTMAILDIR2);
|
2011-11-13 11:46:55 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("%s\n", cmdline);
|
2011-08-29 22:39:11 +02: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);
|
|
|
|
}
|
2010-09-26 14:52:07 +02:00
|
|
|
|
2012-05-30 17:25:49 +02:00
|
|
|
g_free (cmdline);
|
2011-05-19 18:55:50 +02:00
|
|
|
return tmpdir;
|
2010-10-04 21:33:22 +02:00
|
|
|
}
|
|
|
|
|
2012-05-30 17:25:49 +02:00
|
|
|
|
2010-10-04 21:33:22 +02:00
|
|
|
static unsigned
|
|
|
|
newlines_in_output (const char* str)
|
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
int count;
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
count = 0;
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
while (str && *str) {
|
|
|
|
if (*str == '\n')
|
|
|
|
++count;
|
|
|
|
++str;
|
|
|
|
}
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
return count;
|
2010-10-04 21:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
search (const char* query, unsigned expected)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2019-12-01 15:09:28 +01:00
|
|
|
cmdline = g_strdup_printf ("%s find --muhome=%s %s --skip-related --include-dups",
|
2012-07-12 15:13:26 +02:00
|
|
|
MU_PROGRAM, DBPATH, query);
|
2010-11-20 15:37:59 +01:00
|
|
|
|
2011-11-13 11:46:55 +01:00
|
|
|
if (g_test_verbose())
|
2012-07-24 21:12:49 +02:00
|
|
|
g_printerr ("\n$ %s\n", cmdline);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline,
|
|
|
|
&output, &erroutput,
|
|
|
|
NULL, NULL));
|
2011-11-27 15:19:50 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\nOutput:\n%s", output);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpuint (newlines_in_output(output),==,expected);
|
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/* we expect zero lines of error output if there is a match;
|
|
|
|
* otherwise there should be one line 'No matches found' */
|
|
|
|
/* g_assert_cmpuint (newlines_in_output(erroutput),==, */
|
|
|
|
/* expected == 0 ? 1 : 0); */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (cmdline);
|
2010-09-26 14:52:07 +02:00
|
|
|
}
|
|
|
|
|
2010-10-04 21:33:22 +02:00
|
|
|
/* index testdir2, and make sure it adds two documents */
|
2010-09-26 14:52:07 +02:00
|
|
|
static void
|
|
|
|
test_mu_index (void)
|
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
MuStore *store;
|
2012-07-12 15:13:26 +02:00
|
|
|
gchar *xpath;
|
2010-09-26 14:52:07 +02:00
|
|
|
|
2012-07-12 15:13:26 +02:00
|
|
|
xpath = g_strdup_printf ("%s%c%s", DBPATH, G_DIR_SEPARATOR, "xapian");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2019-07-28 13:28:25 +02:00
|
|
|
store = mu_store_new_readable (xpath, NULL);
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (store);
|
2010-09-26 14:52:07 +02:00
|
|
|
|
2012-12-09 12:34:16 +01:00
|
|
|
g_assert_cmpuint (mu_store_count (store, NULL), ==, 13);
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (xpath);
|
2010-09-26 14:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
static void
|
|
|
|
test_mu_find_empty_query (void)
|
|
|
|
{
|
2012-12-09 12:34:16 +01:00
|
|
|
search ("\"\"", 13);
|
2011-11-27 15:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 21:33:22 +02:00
|
|
|
static void
|
|
|
|
test_mu_find_01 (void)
|
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("f:john fruit", 1);
|
2011-08-29 22:39:11 +02:00
|
|
|
search ("f:soc@example.com", 1);
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("t:alki@example.com", 1);
|
|
|
|
search ("t:alcibiades", 1);
|
2013-05-12 23:04:07 +02:00
|
|
|
search ("http emacs", 1);
|
2011-08-29 22:39:11 +02:00
|
|
|
search ("f:soc@example.com OR f:john", 2);
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("f:soc@example.com OR f:john OR t:edmond", 3);
|
2011-08-29 22:39:11 +02:00
|
|
|
search ("t:julius", 1);
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("s:dude", 1);
|
2011-08-29 22:39:11 +02:00
|
|
|
search ("t:dantès", 1);
|
2010-10-04 21:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-17 10:21:12 +02:00
|
|
|
/* index testdir2, and make sure it adds two documents */
|
|
|
|
static void
|
2010-10-04 21:33:22 +02:00
|
|
|
test_mu_find_02 (void)
|
2010-10-17 10:21:12 +02:00
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("bull", 1);
|
2011-08-29 22:39:11 +02:00
|
|
|
search ("bull m:foo", 0);
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("bull m:/foo", 1);
|
|
|
|
search ("bull m:/Foo", 1);
|
|
|
|
search ("bull flag:a", 1);
|
|
|
|
search ("g:x", 0);
|
|
|
|
search ("flag:encrypted", 0);
|
|
|
|
search ("flag:attach", 1);
|
2010-10-17 10:21:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_find_file (void)
|
|
|
|
{
|
|
|
|
search ("file:sittingbull.jpg", 1);
|
|
|
|
search ("file:custer.jpg", 1);
|
|
|
|
search ("file:custer.*", 1);
|
|
|
|
search ("j:sit*", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_find_mime (void)
|
|
|
|
{
|
|
|
|
search ("mime:image/jpeg", 1);
|
2012-12-09 12:34:16 +01:00
|
|
|
search ("mime:text/plain", 13);
|
|
|
|
search ("y:text*", 13);
|
2011-11-27 15:19:50 +01:00
|
|
|
search ("y:image*", 1);
|
|
|
|
search ("mime:message/rfc822", 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_find_text_in_rfc822 (void)
|
|
|
|
{
|
2011-12-01 20:18:56 +01:00
|
|
|
search ("embed:dancing", 1);
|
|
|
|
search ("e:curious", 1);
|
|
|
|
search ("embed:with", 2);
|
|
|
|
search ("e:karjala", 0);
|
|
|
|
search ("embed:navigation", 1);
|
2011-11-27 15:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-11 21:05:10 +01:00
|
|
|
/* some more tests */
|
|
|
|
static void
|
2010-10-17 10:21:12 +02:00
|
|
|
test_mu_find_03 (void)
|
2010-11-11 21:05:10 +01:00
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("bull", 1);
|
2011-08-29 22:39:11 +02:00
|
|
|
search ("bull m:foo", 0);
|
2011-05-19 18:55:50 +02:00
|
|
|
search ("bull m:/foo", 1);
|
|
|
|
search ("i:3BE9E6535E0D852173@emss35m06.us.lmco.com", 1);
|
2010-11-11 21:05:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void /* error cases */
|
|
|
|
test_mu_find_04 (void)
|
2010-10-04 21:33:22 +02:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *erroutput;
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2019-11-17 04:40:48 +01:00
|
|
|
cmdline = g_strdup_printf ("find %s --muhome=%cfoo%cbar%cnonexistent "
|
|
|
|
"f:socrates",
|
2011-05-19 18:55:50 +02:00
|
|
|
MU_PROGRAM,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, NULL, &erroutput,
|
|
|
|
NULL, NULL));
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/* we expect multiple lines of error output */
|
|
|
|
g_assert_cmpuint (newlines_in_output(erroutput),>=,1);
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (erroutput);
|
|
|
|
g_free (cmdline);
|
2010-10-04 21:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-05 12:35:26 +01:00
|
|
|
G_GNUC_UNUSED static void
|
2012-02-23 19:35:16 +01:00
|
|
|
test_mu_find_links (void)
|
|
|
|
{
|
2012-07-12 15:13:26 +02:00
|
|
|
gchar *cmdline, *output, *erroutput, *tmpdir;
|
2012-02-23 19:35:16 +01:00
|
|
|
|
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
|
2012-02-26 11:14:53 +01:00
|
|
|
cmdline = g_strdup_printf (
|
|
|
|
"%s find --muhome=%s --format=links --linksdir=%s "
|
2012-07-12 15:13:26 +02:00
|
|
|
"mime:message/rfc822", MU_PROGRAM, DBPATH, tmpdir);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
2012-07-12 17:09:42 +02:00
|
|
|
g_print ("cmdline: %s\n", cmdline);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline,
|
|
|
|
&output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-07-12 17:09:42 +02:00
|
|
|
/* there should be no errors */
|
2012-02-23 19:35:16 +01:00
|
|
|
g_assert_cmpuint (newlines_in_output(output),==,0);
|
|
|
|
g_assert_cmpuint (newlines_in_output(erroutput),==,0);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
|
2012-07-12 17:09:42 +02:00
|
|
|
/* now we try again, we should get a line of error output,
|
|
|
|
* when we find the first target file already exists */
|
2012-02-23 19:35:16 +01:00
|
|
|
|
2012-07-12 17:09:42 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("cmdline: %s\n", cmdline);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline,
|
|
|
|
&output, &erroutput,
|
|
|
|
NULL, NULL));
|
2012-07-12 17:09:42 +02:00
|
|
|
g_assert_cmpuint (newlines_in_output(output),==,0);
|
|
|
|
g_assert_cmpuint (newlines_in_output(erroutput),==,1);
|
2012-02-23 19:35:16 +01:00
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
|
2012-02-26 11:14:53 +01:00
|
|
|
/* now we try again with --clearlinks, and the we should be
|
|
|
|
* back to 0 errors */
|
2012-02-23 19:35:16 +01:00
|
|
|
g_free (cmdline);
|
2012-02-26 11:14:53 +01:00
|
|
|
cmdline = g_strdup_printf (
|
|
|
|
"%s find --muhome=%s --format=links --linksdir=%s --clearlinks "
|
2012-07-12 15:13:26 +02:00
|
|
|
"mime:message/rfc822", MU_PROGRAM, DBPATH, tmpdir);
|
2012-02-23 19:35:16 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline,
|
|
|
|
&output, &erroutput,
|
|
|
|
NULL, NULL));
|
|
|
|
if (g_test_verbose())
|
2012-07-12 17:09:42 +02:00
|
|
|
g_print ("cmdline: %s\n", cmdline);
|
2012-02-23 19:35:16 +01:00
|
|
|
g_assert_cmpuint (newlines_in_output(output),==,0);
|
|
|
|
g_assert_cmpuint (newlines_in_output(erroutput),==,0);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 11:46:55 +01:00
|
|
|
/* some more tests */
|
|
|
|
static void
|
2011-11-27 15:19:50 +01:00
|
|
|
test_mu_find_maildir_special (void)
|
2011-11-13 11:46:55 +01:00
|
|
|
{
|
2017-10-24 21:58:52 +02:00
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
search ("\"maildir:/wOm_bàT\"", 3);
|
|
|
|
search ("\"maildir:/wOm*\"", 3);
|
2013-04-16 23:09:08 +02:00
|
|
|
search ("\"maildir:/wOm_*\"", 3);
|
|
|
|
search ("\"maildir:wom_bat\"", 0);
|
2011-11-27 15:19:50 +01:00
|
|
|
search ("\"maildir:/wombat\"", 0);
|
|
|
|
search ("subject:atoms", 1);
|
2017-10-24 21:58:52 +02:00
|
|
|
search ("\"maildir:/wom_bat\" subject:atoms", 1);
|
2011-11-13 11:46:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
/* static void */
|
|
|
|
/* test_mu_find_mime_types (void) */
|
|
|
|
/* { */
|
|
|
|
/* /\* ensure that maldirs with spaces in their names work... *\/ */
|
|
|
|
/* search ("\"maildir:/wom bat\" subject:atoms", 1); */
|
|
|
|
/* search ("\"maildir:/wOm_bàT\"", 3); */
|
|
|
|
/* search ("subject:atoms", 1); */
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 11:46:55 +01:00
|
|
|
|
2010-10-23 11:03:42 +02:00
|
|
|
static void
|
2010-10-17 10:21:12 +02:00
|
|
|
test_mu_extract_01 (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *erroutput, *tmpdir;
|
2010-10-17 10:21:12 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
cmdline = g_strdup_printf ("%s extract --muhome=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
|
2012-01-22 17:39:33 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("cmd: %s\n", cmdline);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
output = erroutput = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
|
|
|
g_assert_cmpstr (output,
|
|
|
|
==,
|
|
|
|
"MIME-parts in this message:\n"
|
2019-12-16 20:44:03 +01:00
|
|
|
" 1 <none> text/plain [<none>] (27 bytes)\n"
|
|
|
|
" 2 sittingbull.jpg image/jpeg [inline] (23.3 KB)\n"
|
|
|
|
" 3 custer.jpg image/jpeg [inline] (21.1 KB)\n");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/* we expect zero lines of error output */
|
|
|
|
g_assert_cmpuint (newlines_in_output(erroutput),==,0);
|
2010-10-17 10:21:12 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (tmpdir);
|
2010-10-17 10:21:12 +02:00
|
|
|
}
|
|
|
|
|
2010-10-23 11:03:42 +02:00
|
|
|
static gint64
|
|
|
|
get_file_size (const char* path)
|
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
int rv;
|
|
|
|
struct stat statbuf;
|
2010-10-23 11:03:42 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
rv = stat (path, &statbuf);
|
2013-04-16 23:09:08 +02:00
|
|
|
if (rv != 0) {
|
|
|
|
/* g_warning ("error: %s", strerror (errno)); */
|
2011-05-19 18:55:50 +02:00
|
|
|
return -1;
|
2013-04-16 23:09:08 +02:00
|
|
|
}
|
2010-10-23 11:03:42 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
return (gint64)statbuf.st_size;
|
2010-10-23 11:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2010-10-23 11:03:42 +02:00
|
|
|
test_mu_extract_02 (void)
|
|
|
|
{
|
2018-08-18 09:05:31 +02:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
|
|
|
gchar *att1, *att2;
|
|
|
|
size_t size;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
2010-10-23 11:03:42 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
cmdline = g_strdup_printf ("%s extract --muhome=%s -a "
|
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
|
2012-08-01 16:04:47 +02:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
output = NULL;
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpstr (output, ==, "");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR);
|
|
|
|
att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2018-08-18 09:05:31 +02:00
|
|
|
size = get_file_size(att1);
|
|
|
|
g_assert_true (size >= 15958 && size <= 15960);
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpint (get_file_size(att2),==,17674);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (att1);
|
|
|
|
g_free (att2);
|
2010-10-23 11:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2010-10-23 11:03:42 +02:00
|
|
|
test_mu_extract_03 (void)
|
|
|
|
{
|
2018-08-18 09:05:31 +02:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
|
|
|
gchar *att1, *att2;
|
|
|
|
size_t size;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2012-08-01 16:04:47 +02:00
|
|
|
cmdline = g_strdup_printf ("%s extract --muhome=%s --parts 3 "
|
2011-05-19 18:55:50 +02:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
output = NULL;
|
2012-08-01 16:04:47 +02:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpstr (output, ==, "");
|
|
|
|
|
|
|
|
att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR);
|
|
|
|
att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2018-08-18 09:05:31 +02:00
|
|
|
size = get_file_size(att1);
|
|
|
|
g_assert_true (size >= 15958 && size <= 15960);
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpint (get_file_size(att2),==,-1);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (att1);
|
|
|
|
g_free (att2);
|
2010-10-23 11:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-05-21 13:13:56 +02:00
|
|
|
test_mu_extract_overwrite (void)
|
2011-01-09 13:55:25 +01:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *erroutput, *tmpdir;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
2011-01-09 13:55:25 +01:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
cmdline = g_strdup_printf ("%s extract --muhome=%s -a "
|
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM, tmpdir, tmpdir,
|
|
|
|
MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
|
|
|
|
2012-08-01 16:04:47 +02:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
|
|
|
g_assert_cmpstr (output, ==, "");
|
|
|
|
g_assert_cmpstr (erroutput, ==, "");
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (output);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2012-08-01 16:04:47 +02:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/* now, it should fail, because we don't allow overwrites
|
|
|
|
* without --overwrite */
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
|
|
|
g_assert_cmpstr (output, ==, "");
|
|
|
|
g_assert_cmpstr (erroutput, !=, "");
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (output);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (cmdline);
|
|
|
|
/* this should work now, because we have specified --overwrite */
|
|
|
|
cmdline = g_strdup_printf ("%s extract --muhome=%s -a --overwrite "
|
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM, tmpdir, tmpdir,
|
|
|
|
MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
2012-08-01 16:04:47 +02:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
|
|
|
g_assert_cmpstr (output, ==, "");
|
|
|
|
g_assert_cmpstr (erroutput, ==, "");
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (output);
|
|
|
|
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (cmdline);
|
2011-01-09 13:55:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-05-21 13:13:56 +02:00
|
|
|
test_mu_extract_by_name (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *erroutput, *tmpdir, *path;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 13:13:56 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 13:13:56 +02:00
|
|
|
cmdline = g_strdup_printf ("%s extract --muhome=%s "
|
2011-05-25 07:12:27 +02:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5 "
|
|
|
|
"sittingbull.jpg",
|
2011-05-21 13:13:56 +02:00
|
|
|
MU_PROGRAM, tmpdir, tmpdir,
|
|
|
|
MU_TESTMAILDIR2, G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2011-05-21 13:13:56 +02:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
NULL, NULL));
|
|
|
|
g_assert_cmpstr (output, ==, "");
|
|
|
|
g_assert_cmpstr (erroutput, ==, "");
|
|
|
|
path = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
"sittingbull.jpg");
|
|
|
|
g_assert (access (path, F_OK) == 0);
|
2011-05-25 07:12:27 +02:00
|
|
|
g_free (path);
|
2011-05-21 13:13:56 +02:00
|
|
|
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (output);
|
|
|
|
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (cmdline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-09 13:55:25 +01:00
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-01-06 12:14:17 +01:00
|
|
|
test_mu_view_01 (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2011-05-19 18:55:50 +02:00
|
|
|
int len;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
cmdline = g_strdup_printf ("%s view --muhome=%s %s%cbar%ccur%cmail4",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
output = NULL;
|
2012-08-01 16:04:47 +02:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpstr (output, !=, NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/*
|
|
|
|
* note: there are two possibilities here; older versions of
|
|
|
|
* GMime will produce:
|
|
|
|
*
|
|
|
|
* From: "=?iso-8859-1?Q? =F6tzi ?=" <oetzi@web.de>
|
2011-08-29 22:39:11 +02:00
|
|
|
*
|
2011-05-19 18:55:50 +02:00
|
|
|
* while newer ones return something like:
|
|
|
|
*
|
|
|
|
* From: ?tzi <oetzi@web.de>
|
|
|
|
*
|
2011-08-29 22:39:11 +02:00
|
|
|
* or even
|
2011-05-19 18:55:50 +02:00
|
|
|
*
|
|
|
|
* From: \xc3\xb6tzi <oetzi@web.de>
|
2011-08-29 22:39:11 +02:00
|
|
|
*
|
2011-05-19 18:55:50 +02:00
|
|
|
* both are 'okay' from mu's perspective; it'd be even better
|
|
|
|
* to have some #ifdefs for the GMime versions, but this
|
|
|
|
* should work for now
|
|
|
|
*
|
|
|
|
* Added 350 as 'okay', which comes with gmime 2.4.24 (ubuntu 10.04)
|
|
|
|
*/
|
|
|
|
len = strlen(output);
|
|
|
|
/* g_print ("\n[%s] (%d)\n", output, len); */
|
2011-07-21 07:20:10 +02:00
|
|
|
g_assert (len > 349);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (tmpdir);
|
2011-01-06 12:14:17 +01:00
|
|
|
}
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2010-09-26 14:52:07 +02:00
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-06-13 23:08:13 +02:00
|
|
|
test_mu_view_multi (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2011-06-13 23:08:13 +02:00
|
|
|
int len;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
cmdline = g_strdup_printf ("%s view --muhome=%s "
|
|
|
|
"%s%cbar%ccur%cmail5 "
|
|
|
|
"%s%cbar%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
output = NULL;
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-06-13 23:08:13 +02:00
|
|
|
g_assert_cmpstr (output, !=, NULL);
|
|
|
|
|
|
|
|
len = strlen(output);
|
|
|
|
/* g_print ("\n[%s](%u)\n", output, len); */
|
2011-07-21 07:20:10 +02:00
|
|
|
g_assert_cmpuint (len,>,150);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-06-13 23:08:13 +02:00
|
|
|
test_mu_view_multi_separate (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2011-06-13 23:08:13 +02:00
|
|
|
int len;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-07-10 13:07:35 +02:00
|
|
|
cmdline = g_strdup_printf ("%s view --terminate --muhome=%s "
|
2011-06-13 23:08:13 +02:00
|
|
|
"%s%cbar%ccur%cmail5 "
|
|
|
|
"%s%cbar%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
output = NULL;
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-06-13 23:08:13 +02:00
|
|
|
g_assert_cmpstr (output, !=, NULL);
|
|
|
|
|
|
|
|
len = strlen(output);
|
|
|
|
/* g_print ("\n[%s](%u)\n", output, len); */
|
2011-07-21 07:20:10 +02:00
|
|
|
g_assert_cmpuint (len,>,150);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-05-21 19:20:38 +02:00
|
|
|
test_mu_view_attach (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2011-05-21 19:20:38 +02:00
|
|
|
int len;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 19:20:38 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s view --muhome=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
output = NULL;
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-05-21 19:20:38 +02:00
|
|
|
g_assert_cmpstr (output, !=, NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 19:20:38 +02:00
|
|
|
len = strlen(output);
|
2012-09-14 09:06:33 +02:00
|
|
|
g_assert (len == 168 || len == 166);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 19:20:38 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-18 20:21:10 +02:00
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2011-01-06 12:25:11 +01:00
|
|
|
test_mu_mkdir_01 (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2011-05-19 18:55:50 +02:00
|
|
|
gchar *dir;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
cmdline = g_strdup_printf ("%s mkdir --muhome=%s %s%ctest1 %s%ctest2",
|
|
|
|
MU_PROGRAM,tmpdir,
|
|
|
|
tmpdir, G_DIR_SEPARATOR,
|
|
|
|
tmpdir, G_DIR_SEPARATOR);
|
|
|
|
|
|
|
|
output = NULL;
|
2012-02-26 11:14:53 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
|
|
|
NULL, NULL));
|
2011-05-19 18:55:50 +02:00
|
|
|
g_assert_cmpstr (output, ==, "");
|
|
|
|
|
|
|
|
dir = g_strdup_printf ("%s%ctest1%ccur", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
g_assert (access (dir, F_OK) == 0);
|
|
|
|
g_free (dir);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
dir = g_strdup_printf ("%s%ctest2%ctmp", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
g_assert (access (dir, F_OK) == 0);
|
|
|
|
g_free (dir);
|
|
|
|
|
|
|
|
dir = g_strdup_printf ("%s%ctest1%cnew", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
g_assert (access (dir, F_OK) == 0);
|
|
|
|
g_free (dir);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_free (output);
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (cmdline);
|
2011-01-06 12:25:11 +01:00
|
|
|
}
|
|
|
|
|
2012-07-18 10:35:57 +02:00
|
|
|
/* we can only test 'verify' if gpg is installed, and has
|
|
|
|
* djcb@djcbsoftware's key in the keyring */
|
2012-09-14 09:45:33 +02:00
|
|
|
G_GNUC_UNUSED static gboolean
|
2012-07-18 10:35:57 +02:00
|
|
|
verify_is_testable (void)
|
|
|
|
{
|
|
|
|
gchar *gpg, *cmdline;
|
|
|
|
gchar *output, *erroutput;
|
|
|
|
int retval;
|
|
|
|
gboolean rv;
|
|
|
|
|
|
|
|
/* find GPG or return FALSE */
|
|
|
|
if ((gpg = (char*)g_getenv ("MU_GPG_PATH"))) {
|
|
|
|
if (access (gpg, X_OK) != 0)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
gpg = g_strdup (gpg);
|
|
|
|
|
2019-03-24 10:54:12 +01:00
|
|
|
} else if (!(gpg = g_find_program_in_path ("gpg2")))
|
2012-07-18 10:35:57 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2019-03-24 10:54:12 +01:00
|
|
|
cmdline = g_strdup_printf ("%s --list-keys DCC4A036", gpg);
|
2012-07-18 10:35:57 +02:00
|
|
|
g_free (gpg);
|
|
|
|
|
|
|
|
output = erroutput = NULL;
|
|
|
|
rv = g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
|
|
|
&retval, NULL);
|
|
|
|
g_free (output);
|
|
|
|
g_free (erroutput);
|
|
|
|
g_free (cmdline);
|
|
|
|
|
|
|
|
return (rv && retval == 0) ? TRUE:FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-18 10:51:21 +02:00
|
|
|
G_GNUC_UNUSED static void
|
2012-07-18 10:35:57 +02:00
|
|
|
test_mu_verify_good (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output;
|
2012-07-18 10:35:57 +02:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!verify_is_testable ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s verify %s/signed!2,S",
|
2019-03-24 10:54:12 +01:00
|
|
|
MU_PROGRAM, MU_TESTMAILDIR4);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2012-09-17 11:44:08 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2012-09-14 09:45:33 +02:00
|
|
|
output = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
2012-07-18 10:35:57 +02:00
|
|
|
&retval, NULL));
|
2012-09-14 09:45:33 +02:00
|
|
|
g_free (output);
|
2012-07-18 10:35:57 +02:00
|
|
|
g_assert_cmpuint (retval, ==, 0);
|
|
|
|
g_free (cmdline);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-18 10:51:21 +02:00
|
|
|
G_GNUC_UNUSED static void
|
2012-07-18 10:35:57 +02:00
|
|
|
test_mu_verify_bad (void)
|
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output;
|
2012-07-18 10:35:57 +02:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!verify_is_testable ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf ("%s verify %s/signed-bad!2,S",
|
|
|
|
MU_PROGRAM,
|
|
|
|
MU_TESTMAILDIR4);
|
|
|
|
|
2012-09-17 11:44:08 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("$ %s\n", cmdline);
|
|
|
|
|
2012-09-14 09:45:33 +02:00
|
|
|
output = NULL;
|
|
|
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL,
|
2012-07-18 10:35:57 +02:00
|
|
|
&retval, NULL));
|
2012-09-14 09:45:33 +02:00
|
|
|
g_free (output);
|
2012-07-18 10:35:57 +02:00
|
|
|
g_assert_cmpuint (retval, !=, 0);
|
|
|
|
g_free (cmdline);
|
|
|
|
}
|
|
|
|
|
2011-01-06 12:25:11 +01:00
|
|
|
|
|
|
|
|
2010-09-26 14:52:07 +02:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
int rv;
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
2011-07-21 07:20:10 +02:00
|
|
|
|
2012-03-07 23:11:31 +01:00
|
|
|
if (!set_en_us_utf8_locale())
|
|
|
|
return 0; /* don't error out... */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index);
|
2011-11-27 15:19:50 +01:00
|
|
|
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-empty-query",
|
|
|
|
test_mu_find_empty_query);
|
2011-08-29 22:39:11 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-01", test_mu_find_01);
|
2011-05-19 18:55:50 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-02", test_mu_find_02);
|
2011-11-27 15:19:50 +01:00
|
|
|
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-file", test_mu_find_file);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-mime", test_mu_find_mime);
|
2011-12-01 20:18:56 +01:00
|
|
|
|
2016-11-05 12:35:26 +01:00
|
|
|
/* recently, this test breaks _sometimes_ when run on Travis; but it
|
|
|
|
* seems related to the setup there, as nothing has changed in the code.
|
|
|
|
* turn off for now. */
|
|
|
|
/* g_test_add_func ("/mu-cmd/test-mu-find-links",
|
|
|
|
* test_mu_find_links); */
|
2012-02-23 19:35:16 +01:00
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-text-in-rfc822",
|
|
|
|
test_mu_find_text_in_rfc822);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-03", test_mu_find_03);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-04", test_mu_find_04);
|
2011-11-27 15:19:50 +01:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-find-maildir-special",
|
|
|
|
test_mu_find_maildir_special);
|
2011-05-19 18:55:50 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-extract-01", test_mu_extract_01);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-extract-02", test_mu_extract_02);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-extract-03", test_mu_extract_03);
|
2011-05-21 13:13:56 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-extract-overwrite",
|
|
|
|
test_mu_extract_overwrite);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-extract-by-name",
|
|
|
|
test_mu_extract_by_name);
|
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-view-01", test_mu_view_01);
|
2011-06-13 23:08:13 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-view-multi",
|
|
|
|
test_mu_view_multi);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-view-multi-separate",
|
|
|
|
test_mu_view_multi_separate);
|
2011-05-21 19:20:38 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-view-attach", test_mu_view_attach);
|
2011-05-19 18:55:50 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2012-09-14 09:45:33 +02:00
|
|
|
g_test_add_func ("/mu-cmd/test-mu-verify-good", test_mu_verify_good);
|
|
|
|
g_test_add_func ("/mu-cmd/test-mu-verify-bad", test_mu_verify_bad);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
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);
|
2012-07-12 15:13:26 +02:00
|
|
|
|
|
|
|
DBPATH = fill_database ();
|
2011-05-19 18:55:50 +02:00
|
|
|
rv = g_test_run ();
|
2012-07-12 15:13:26 +02:00
|
|
|
g_free (DBPATH);
|
2010-11-27 15:07:24 +01:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
return rv;
|
2010-09-26 14:52:07 +02:00
|
|
|
}
|