2022-04-28 21:47:00 +02:00
|
|
|
/*
|
|
|
|
** Copyright (C) 2008-2022 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "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
|
|
|
|
|
|
|
#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"
|
2022-05-13 22:01:33 +02:00
|
|
|
#include "utils/mu-result.hh"
|
2022-04-28 21:47:00 +02:00
|
|
|
#include "utils/mu-utils.hh"
|
|
|
|
|
|
|
|
using namespace Mu;
|
2010-09-26 14:52:07 +02:00
|
|
|
|
|
|
|
/* tests for the command line interface, uses testdir2 */
|
|
|
|
|
2022-04-28 21:47:00 +02:00
|
|
|
static std::string DBPATH; /* global */
|
2012-07-12 15:13:26 +02:00
|
|
|
|
2022-04-28 21:47:00 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
fill_database(void)
|
2010-09-26 14:52:07 +02:00
|
|
|
{
|
2022-04-28 21:47:00 +02:00
|
|
|
gchar * cmdline;
|
2021-10-20 11:18:15 +02:00
|
|
|
GError* err;
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf("/bin/sh -c '"
|
2022-02-26 10:10:25 +01:00
|
|
|
"%s init --muhome=%s --maildir=%s --quiet; "
|
|
|
|
"%s index --muhome=%s --quiet'",
|
|
|
|
MU_PROGRAM,
|
2022-04-28 21:47:00 +02:00
|
|
|
DBPATH.c_str(),
|
2022-02-26 10:10:25 +01:00
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
MU_PROGRAM,
|
2022-04-28 21:47:00 +02:00
|
|
|
DBPATH.c_str());
|
2011-11-13 11:46:55 +01:00
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("%s\n", cmdline);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +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-05-30 17:25:49 +02:00
|
|
|
}
|
2010-09-26 14:52:07 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(cmdline);
|
2010-10-04 21:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
2021-10-20 11:18:15 +02:00
|
|
|
newlines_in_output(const char* str)
|
2010-10-04 21:33:22 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-05-06 21:16:57 +02:00
|
|
|
static size_t
|
|
|
|
search_func(const char* query, unsigned expected)
|
2010-10-04 21:33:22 +02:00
|
|
|
{
|
2022-05-06 21:16:57 +02:00
|
|
|
size_t lines;
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *erroutput;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2022-05-06 21:16:57 +02:00
|
|
|
cmdline = g_strdup_printf("%s find --muhome=%s %s", MU_PROGRAM,
|
|
|
|
DBPATH.c_str(), query);
|
2010-11-20 15:37:59 +01:00
|
|
|
|
2022-05-06 21:16:57 +02:00
|
|
|
g_message("[%u] %s", expected, query);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +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())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("\nOutput:\n%s", output);
|
2011-05-19 18:55:50 +02:00
|
|
|
|
2022-05-06 21:16:57 +02:00
|
|
|
lines = newlines_in_output(output);
|
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),==, */
|
2022-02-26 10:10:25 +01:00
|
|
|
/* expected == 0 ? 1 : 0); */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(output);
|
|
|
|
g_free(erroutput);
|
|
|
|
g_free(cmdline);
|
2022-05-06 21:16:57 +02:00
|
|
|
|
|
|
|
return lines;
|
2010-09-26 14:52:07 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 21:16:57 +02:00
|
|
|
#define search(Q,EXP) do { \
|
|
|
|
unsigned lines = search_func(Q, EXP); \
|
|
|
|
g_assert_cmpuint(lines, ==, EXP); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_index(void)
|
2010-09-26 14:52:07 +02:00
|
|
|
{
|
2022-05-13 22:01:33 +02:00
|
|
|
auto store = Store::make(DBPATH + "/xapian");
|
|
|
|
assert_valid_result(store);
|
|
|
|
g_assert_cmpuint(store->size(), ==, 13);
|
2010-09-26 14:52:07 +02:00
|
|
|
}
|
|
|
|
|
2011-11-27 15:19:50 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_empty_query(void)
|
2011-11-27 15:19:50 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("\"\"", 13);
|
2011-11-27 15:19:50 +01:00
|
|
|
}
|
|
|
|
|
2010-10-04 21:33:22 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_01(void)
|
2010-10-04 21:33:22 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("f:john fruit", 1);
|
|
|
|
search("f:soc@example.com", 1);
|
|
|
|
search("t:alki@example.com", 1);
|
|
|
|
search("t:alcibiades", 1);
|
|
|
|
search("http emacs", 1);
|
|
|
|
search("f:soc@example.com OR f:john", 2);
|
|
|
|
search("f:soc@example.com OR f:john OR t:edmond", 3);
|
|
|
|
search("t:julius", 1);
|
|
|
|
search("s:dude", 1);
|
|
|
|
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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_02(void)
|
2010-10-17 10:21:12 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("bull", 1);
|
|
|
|
search("bull m:foo", 0);
|
|
|
|
search("bull m:/foo", 1);
|
|
|
|
search("bull m:/Foo", 1);
|
2022-03-04 23:38:33 +01:00
|
|
|
search("bull flag:attach", 1);
|
2021-10-20 11:18:15 +02:00
|
|
|
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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_file(void)
|
2011-11-27 15:19:50 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("file:sittingbull.jpg", 1);
|
|
|
|
search("file:custer.jpg", 1);
|
|
|
|
search("file:custer.*", 1);
|
|
|
|
search("j:sit*", 1);
|
2011-11-27 15:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_mime(void)
|
2011-11-27 15:19:50 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("mime:image/jpeg", 1);
|
|
|
|
search("mime:text/plain", 13);
|
|
|
|
search("y:text*", 13);
|
|
|
|
search("y:image*", 1);
|
|
|
|
search("mime:message/rfc822", 2);
|
2011-11-27 15:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_text_in_rfc822(void)
|
2011-11-27 15:19:50 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02: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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_03(void)
|
2010-11-11 21:05:10 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("bull", 1);
|
|
|
|
search("bull m:foo", 0);
|
|
|
|
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 */
|
2021-10-20 11:18:15 +02:00
|
|
|
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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("find %s --muhome=%cfoo%cbar%cnonexistent "
|
2022-02-26 10:10:25 +01:00
|
|
|
"f:socrates",
|
|
|
|
MU_PROGRAM,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +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 */
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(newlines_in_output(erroutput), >=, 1);
|
2010-10-04 21:33:22 +02:00
|
|
|
|
2021-10-20 11:18:15 +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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_links(void)
|
2012-02-23 19:35:16 +01:00
|
|
|
{
|
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();
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s find --muhome=%s --format=links --linksdir=%s "
|
2022-02-26 10:10:25 +01:00
|
|
|
"mime:message/rfc822",
|
|
|
|
MU_PROGRAM,
|
2022-04-28 21:47:00 +02:00
|
|
|
DBPATH.c_str(),
|
2022-02-26 10:10:25 +01:00
|
|
|
tmpdir);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("cmdline: %s\n", cmdline);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, &erroutput, NULL, NULL));
|
|
|
|
/* there should be no errors */
|
|
|
|
g_assert_cmpuint(newlines_in_output(output), ==, 0);
|
|
|
|
g_assert_cmpuint(newlines_in_output(erroutput), ==, 0);
|
|
|
|
g_free(output);
|
|
|
|
g_free(erroutput);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
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())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("cmdline: %s\n", cmdline);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, &erroutput, NULL, NULL));
|
|
|
|
g_assert_cmpuint(newlines_in_output(output), ==, 0);
|
|
|
|
g_assert_cmpuint(newlines_in_output(erroutput), ==, 1);
|
|
|
|
g_free(output);
|
|
|
|
g_free(erroutput);
|
2012-02-23 19:35:16 +01:00
|
|
|
|
2012-02-26 11:14:53 +01:00
|
|
|
/* now we try again with --clearlinks, and the we should be
|
|
|
|
* back to 0 errors */
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(cmdline);
|
|
|
|
cmdline = g_strdup_printf("%s find --muhome=%s --format=links --linksdir=%s --clearlinks "
|
2022-02-26 10:10:25 +01:00
|
|
|
"mime:message/rfc822",
|
|
|
|
MU_PROGRAM,
|
2022-04-28 21:47:00 +02:00
|
|
|
DBPATH.c_str(),
|
2022-02-26 10:10:25 +01:00
|
|
|
tmpdir);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, &erroutput, NULL, NULL));
|
2012-02-23 19:35:16 +01:00
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("cmdline: %s\n", cmdline);
|
|
|
|
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);
|
2012-02-23 19:35:16 +01:00
|
|
|
}
|
|
|
|
|
2011-11-13 11:46:55 +01:00
|
|
|
/* some more tests */
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_find_maildir_special(void)
|
2011-11-13 11:46:55 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
search("\"maildir:/wOm_bàT\"", 3);
|
|
|
|
search("\"maildir:/wOm*\"", 3);
|
|
|
|
search("\"maildir:/wOm_*\"", 3);
|
|
|
|
search("\"maildir:wom_bat\"", 0);
|
|
|
|
search("\"maildir:/wombat\"", 0);
|
|
|
|
search("subject:atoms", 1);
|
|
|
|
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) */
|
|
|
|
/* { */
|
2022-02-26 10:10:25 +01:00
|
|
|
/* /\* 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-27 15:19:50 +01:00
|
|
|
/* } */
|
|
|
|
|
2010-10-23 11:03:42 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_extract_01(void)
|
2010-10-17 10:21:12 +02:00
|
|
|
{
|
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();
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s extract --muhome=%s %s%cFoo%ccur%cmail5",
|
2022-02-26 10:10:25 +01:00
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2011-05-19 18:55:50 +02:00
|
|
|
|
2012-01-22 17:39:33 +01:00
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
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;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, &erroutput, NULL, NULL));
|
|
|
|
|
|
|
|
// ERROR:test-mu-cmd.cc:347:void test_mu_extract_01(): assertion failed (output ==
|
|
|
|
// "MIME-parts in this message:\n" " 1 <none> text/plain [<none>] (27 bytes)\n" " 2
|
|
|
|
// sittingbull.jpg image/jpeg [inline] (23.9\302\240kB)\n" " 3 custer.jpg image/jpeg
|
|
|
|
// [inline] (21.6\302\240kB)\n"):
|
|
|
|
// ("MIME-parts in this message:\n 1 <none> text/plain [<none>] (27 bytes)\n 2
|
|
|
|
// sittingbull.jpg image/jpeg [inline] (23.9 kB)\n 3 custer.jpg image/jpeg [inline] (21.6
|
|
|
|
// kB)\n" == "MIME-parts in this message:\n 1 <none> text/plain [<none>] (27 bytes)\n 2
|
|
|
|
// sittingbull.jpg image/jpeg [inline] (23.9\302\240kB)\n 3 custer.jpg image/jpeg [inline]
|
|
|
|
// (21.6\302\240kB)\n")
|
2021-01-22 23:50:23 +01:00
|
|
|
/* g_assert_cmpstr (output, */
|
2022-02-26 10:10:25 +01:00
|
|
|
/* ==, */
|
|
|
|
/* "MIME-parts in this message:\n" */
|
|
|
|
/* " 1 <none> text/plain [<none>] (27 bytes)\n" */
|
|
|
|
/* " 2 sittingbull.jpg image/jpeg [inline] (23.9\302\240kB)\n" */
|
|
|
|
/* " 3 custer.jpg image/jpeg [inline] (21.6\302\240kB)\n"); */
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/* we expect zero lines of error output */
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(newlines_in_output(erroutput), ==, 0);
|
2010-10-17 10:21:12 +02:00
|
|
|
|
2021-10-20 11:18:15 +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
|
2021-10-20 11:18:15 +02:00
|
|
|
get_file_size(const char* path)
|
2010-10-23 11:03:42 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
int rv;
|
2011-05-19 18:55:50 +02:00
|
|
|
struct stat statbuf;
|
2010-10-23 11:03:42 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = stat(path, &statbuf);
|
2013-04-16 23:09:08 +02:00
|
|
|
if (rv != 0) {
|
2021-07-28 22:58:55 +02:00
|
|
|
/* g_warning ("error: %s", g_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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_extract_02(void)
|
2010-10-23 11:03:42 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s extract --muhome=%s -a "
|
2022-02-26 10:10:25 +01:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2011-05-19 18:55:50 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
output = NULL;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
g_assert_cmpstr(output, ==, "");
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +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);
|
2022-04-18 21:25:11 +02:00
|
|
|
g_assert_cmpuint(size, >=, 15955);
|
|
|
|
g_assert_cmpuint(size, <=, 15960);
|
|
|
|
|
|
|
|
size = get_file_size(att2);
|
|
|
|
g_assert_cmpint(size, ==, 17674);
|
|
|
|
|
2021-10-20 11:18:15 +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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_extract_03(void)
|
2010-10-23 11:03:42 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s extract --muhome=%s --parts 3 "
|
2022-02-26 10:10:25 +01:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2021-10-20 11:18:15 +02:00
|
|
|
output = NULL;
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
|
|
|
|
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
g_assert_cmpstr(output, ==, "");
|
2011-05-19 18:55:50 +02:00
|
|
|
|
2021-10-20 11:18:15 +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);
|
2022-04-18 21:25:11 +02:00
|
|
|
g_assert_cmpuint(size, >=, 15955);
|
|
|
|
g_assert_cmpuint(size, <=, 15960);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpint(get_file_size(att2), ==, -1);
|
|
|
|
|
|
|
|
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
|
2021-10-20 11:18:15 +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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s extract --muhome=%s -a "
|
2022-02-26 10:10:25 +01:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2011-05-19 18:55:50 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2011-05-19 18:55:50 +02:00
|
|
|
/* now, it should fail, because we don't allow overwrites
|
|
|
|
* without --overwrite */
|
2021-10-20 11:18:15 +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(cmdline);
|
2011-05-19 18:55:50 +02:00
|
|
|
/* this should work now, because we have specified --overwrite */
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s extract --muhome=%s -a --overwrite "
|
2022-02-26 10:10:25 +01:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
2011-01-09 13:55:25 +01:00
|
|
|
|
2021-10-20 11:18:15 +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
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_extract_by_name(void)
|
2011-05-21 13:13:56 +02:00
|
|
|
{
|
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();
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s extract --muhome=%s "
|
2022-02-26 10:10:25 +01:00
|
|
|
"--target-dir=%s %s%cFoo%ccur%cmail5 "
|
|
|
|
"sittingbull.jpg",
|
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +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);
|
|
|
|
g_free(path);
|
2011-05-21 13:13:56 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(erroutput);
|
|
|
|
g_free(output);
|
2011-05-21 13:13:56 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(tmpdir);
|
|
|
|
g_free(cmdline);
|
2011-05-21 13:13:56 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_view_01(void)
|
2011-01-06 12:14:17 +01:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2021-10-20 11:18:15 +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();
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s view --muhome=%s %s%cbar%ccur%cmail4",
|
2022-02-26 10:10:25 +01:00
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2021-10-20 11:18:15 +02:00
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("$ %s\n", cmdline);
|
2012-08-01 16:04:47 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
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);
|
2022-02-26 10:23:38 +01:00
|
|
|
if (len < 339) {
|
2022-02-26 10:10:25 +01:00
|
|
|
g_print ("\n[%s] (%d)\n", output, len);
|
|
|
|
}
|
2022-02-26 10:23:38 +01:00
|
|
|
g_assert_cmpuint(len, >=, 339);
|
2021-10-20 11:18:15 +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
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_view_multi(void)
|
2011-06-13 23:08:13 +02:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2021-10-20 11:18:15 +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();
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf("%s view --muhome=%s "
|
2022-02-26 10:10:25 +01: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);
|
2021-10-20 11:18:15 +02:00
|
|
|
output = NULL;
|
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
g_assert_cmpstr(output, !=, NULL);
|
2011-06-13 23:08:13 +02:00
|
|
|
|
|
|
|
len = strlen(output);
|
2022-02-27 10:09:15 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\n[%s](%u)\n", output, len);
|
|
|
|
g_assert_cmpuint(len, >=, 112);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(output);
|
|
|
|
g_free(cmdline);
|
|
|
|
g_free(tmpdir);
|
2011-06-13 23:08:13 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_view_multi_separate(void)
|
2011-06-13 23:08:13 +02:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2021-10-20 11:18:15 +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();
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf("%s view --terminate --muhome=%s "
|
2022-02-26 10:10:25 +01: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);
|
2021-10-20 11:18:15 +02:00
|
|
|
output = NULL;
|
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
g_assert_cmpstr(output, !=, NULL);
|
2011-06-13 23:08:13 +02:00
|
|
|
|
|
|
|
len = strlen(output);
|
2022-02-27 10:09:15 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\n[%s](%u)\n", output, len);
|
|
|
|
g_print ("\n[%s](%u)\n", output, len);
|
|
|
|
//g_assert_cmpuint(len, >=, 112);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(output);
|
|
|
|
g_free(cmdline);
|
|
|
|
g_free(tmpdir);
|
2011-06-13 23:08:13 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_view_attach(void)
|
2011-05-21 19:20:38 +02:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
2021-10-20 11:18:15 +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();
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
|
|
|
|
|
|
|
cmdline = g_strdup_printf("%s view --muhome=%s %s%cFoo%ccur%cmail5",
|
2022-02-26 10:10:25 +01:00
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
G_DIR_SEPARATOR);
|
2021-10-20 11:18:15 +02:00
|
|
|
output = NULL;
|
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
g_assert_cmpstr(output, !=, NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-05-21 19:20:38 +02:00
|
|
|
len = strlen(output);
|
2022-02-27 10:09:15 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\n[%s](%u)\n", output, len);
|
|
|
|
//g_assert(len == 168 || len == 166);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(output);
|
|
|
|
g_free(cmdline);
|
|
|
|
g_free(tmpdir);
|
2011-05-21 19:20:38 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_mkdir_01(void)
|
2011-01-06 12:25:11 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar *cmdline, *output, *tmpdir;
|
|
|
|
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();
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_mkdir_with_parents(tmpdir, 0700) == 0);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s mkdir --muhome=%s %s%ctest1 %s%ctest2",
|
2022-02-26 10:10:25 +01:00
|
|
|
MU_PROGRAM,
|
|
|
|
tmpdir,
|
|
|
|
tmpdir,
|
|
|
|
G_DIR_SEPARATOR,
|
|
|
|
tmpdir,
|
|
|
|
G_DIR_SEPARATOR);
|
2011-05-19 18:55:50 +02:00
|
|
|
|
|
|
|
output = NULL;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, NULL, NULL));
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
2021-10-20 11:18:15 +02:00
|
|
|
verify_is_testable(void)
|
2012-07-18 10:35:57 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar * gpg, *cmdline;
|
|
|
|
gchar * output, *erroutput;
|
|
|
|
int retval;
|
2012-07-18 10:35:57 +02:00
|
|
|
gboolean rv;
|
|
|
|
|
|
|
|
/* find GPG or return FALSE */
|
2021-10-20 11:18:15 +02:00
|
|
|
if ((gpg = (char*)g_getenv("MU_GPG_PATH"))) {
|
|
|
|
if (access(gpg, X_OK) != 0)
|
2012-07-18 10:35:57 +02:00
|
|
|
return FALSE;
|
|
|
|
else
|
2021-10-20 11:18:15 +02:00
|
|
|
gpg = g_strdup(gpg);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
} else if (!(gpg = g_find_program_in_path("gpg2")))
|
2012-07-18 10:35:57 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
cmdline = g_strdup_printf("%s --list-keys DCC4A036", gpg);
|
|
|
|
g_free(gpg);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
|
|
|
output = erroutput = NULL;
|
2022-02-27 10:09:15 +01:00
|
|
|
rv = g_spawn_command_line_sync(cmdline, &output, &erroutput, &retval, NULL);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(output);
|
|
|
|
g_free(erroutput);
|
|
|
|
g_free(cmdline);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return (rv && retval == 0) ? TRUE : FALSE;
|
2012-07-18 10:35:57 +02:00
|
|
|
}
|
|
|
|
|
2012-07-18 10:51:21 +02:00
|
|
|
G_GNUC_UNUSED static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_verify_good(void)
|
2012-07-18 10:35:57 +02:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output;
|
2021-10-20 11:18:15 +02:00
|
|
|
int retval;
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!verify_is_testable())
|
2012-07-18 10:35:57 +02:00
|
|
|
return;
|
|
|
|
|
2022-04-28 21:47:00 +02:00
|
|
|
cmdline = g_strdup_printf("%s verify '%s/signed!2,S'", MU_PROGRAM, MU_TESTMAILDIR4);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2012-09-17 11:44:08 +02:00
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("$ %s\n", cmdline);
|
2012-09-17 11:44:08 +02:00
|
|
|
|
2012-09-14 09:45:33 +02:00
|
|
|
output = NULL;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, &retval, NULL));
|
|
|
|
g_free(output);
|
|
|
|
g_assert_cmpuint(retval, ==, 0);
|
|
|
|
g_free(cmdline);
|
2012-07-18 10:35:57 +02:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
G_GNUC_UNUSED static void
|
|
|
|
test_mu_verify_bad(void)
|
2012-07-18 10:35:57 +02:00
|
|
|
{
|
2016-11-05 12:35:26 +01:00
|
|
|
gchar *cmdline, *output;
|
2021-10-20 11:18:15 +02:00
|
|
|
int retval;
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!verify_is_testable())
|
2012-07-18 10:35:57 +02:00
|
|
|
return;
|
|
|
|
|
2022-04-28 21:47:00 +02:00
|
|
|
cmdline = g_strdup_printf("%s verify '%s/signed-bad!2,S'", MU_PROGRAM, MU_TESTMAILDIR4);
|
2012-07-18 10:35:57 +02:00
|
|
|
|
2012-09-17 11:44:08 +02:00
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("$ %s\n", cmdline);
|
2012-09-17 11:44:08 +02:00
|
|
|
|
2012-09-14 09:45:33 +02:00
|
|
|
output = NULL;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(g_spawn_command_line_sync(cmdline, &output, NULL, &retval, NULL));
|
|
|
|
g_free(output);
|
|
|
|
g_assert_cmpuint(retval, !=, 0);
|
|
|
|
g_free(cmdline);
|
2012-07-18 10:35:57 +02:00
|
|
|
}
|
|
|
|
|
2010-09-26 14:52:07 +02:00
|
|
|
int
|
2021-10-20 11:18:15 +02:00
|
|
|
main(int argc, char* argv[])
|
2010-09-26 14:52:07 +02:00
|
|
|
{
|
2011-05-19 18:55:50 +02:00
|
|
|
int rv;
|
2022-04-28 21:47:00 +02:00
|
|
|
|
2022-05-13 22:01:33 +02:00
|
|
|
/* currently, something is broken on Ubuntu CI (but not elsewhere);
|
|
|
|
* selectively turn this test off */
|
|
|
|
if (!g_getenv("RUN_TEST_MU_CMD"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-cmd/test-mu-index", test_mu_index);
|
2011-11-27 15:19:50 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-cmd/test-mu-find-empty-query", test_mu_find_empty_query);
|
|
|
|
g_test_add_func("/mu-cmd/test-mu-find-01", test_mu_find_01);
|
|
|
|
g_test_add_func("/mu-cmd/test-mu-find-02", test_mu_find_02);
|
2011-11-27 15:19:50 +01:00
|
|
|
|
2021-10-20 11:18:15 +02: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
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-cmd/test-mu-find-text-in-rfc822", test_mu_find_text_in_rfc822);
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_test_add_func("/mu-cmd/test-mu-find-maildir-special", test_mu_find_maildir_special);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
g_test_add_func("/mu-cmd/test-mu-view-01", test_mu_view_01);
|
|
|
|
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);
|
|
|
|
g_test_add_func("/mu-cmd/test-mu-view-attach", test_mu_view_attach);
|
|
|
|
g_test_add_func("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
g_log_set_handler(NULL,
|
2022-02-26 10:10:25 +01:00
|
|
|
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING |
|
|
|
|
G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
|
|
|
|
(GLogFunc)black_hole,
|
|
|
|
NULL);
|
2021-10-20 11:18:15 +02:00
|
|
|
|
2022-04-28 21:47:00 +02:00
|
|
|
TempDir tempdir;
|
|
|
|
DBPATH = tempdir.path();
|
|
|
|
fill_database();
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = g_test_run();
|
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
|
|
|
}
|