2020-11-11 20:42:31 +01:00
|
|
|
/*
|
2022-03-13 11:36:53 +01:00
|
|
|
** Copyright (C) 2012-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2020-11-11 20:42:31 +01: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,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include <lib/mu-query.hh>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-08-10 07:20:58 +02:00
|
|
|
#include "utils/mu-test-utils.hh"
|
2020-11-11 20:42:31 +01:00
|
|
|
#include <lib/mu-store.hh>
|
2022-05-21 16:44:09 +02:00
|
|
|
#include <utils/mu-utils.hh>
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2022-05-21 16:44:09 +02:00
|
|
|
using namespace Mu;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2022-05-21 16:44:09 +02:00
|
|
|
static std::string test_dir;
|
|
|
|
|
|
|
|
static std::string
|
2021-10-20 11:18:15 +02:00
|
|
|
fill_database(void)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2022-05-21 16:44:09 +02:00
|
|
|
const auto cmdline = format(
|
|
|
|
"/bin/sh -c '"
|
|
|
|
"%s init --muhome=%s --maildir=%s --quiet; "
|
|
|
|
"%s index --muhome=%s --quiet'",
|
|
|
|
MU_PROGRAM,
|
|
|
|
test_dir.c_str(),
|
|
|
|
MU_TESTMAILDIR2,
|
|
|
|
MU_PROGRAM,
|
|
|
|
test_dir.c_str());
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
2022-05-21 16:44:09 +02:00
|
|
|
g_print("%s\n", cmdline.c_str());
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2022-05-21 16:44:09 +02:00
|
|
|
GError *err{};
|
|
|
|
if (!g_spawn_command_line_sync(cmdline.c_str(), NULL, NULL, NULL, &err)) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_printerr("Error: %s\n", err ? err->message : "?");
|
2022-05-21 16:44:09 +02:00
|
|
|
g_clear_error(&err);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert(0);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
2022-05-21 16:44:09 +02:00
|
|
|
return test_dir;
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_something(const char* what)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2022-03-13 11:36:53 +01:00
|
|
|
g_setenv("GUILE_AUTO_COMPILE", "0", TRUE);
|
|
|
|
g_setenv("GUILE_LOAD_PATH", GUILE_LOAD_PATH, TRUE);
|
2022-05-21 16:44:09 +02:00
|
|
|
g_setenv("GUILE_EXTENSIONS_PATH",GUILE_EXTENSIONS_PATH, TRUE);
|
2021-10-20 11:18:15 +02:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
2022-05-21 16:44:09 +02:00
|
|
|
g_print("GUILE_LOAD_PATH: %s\n", GUILE_LOAD_PATH);
|
2021-10-20 11:18:15 +02:00
|
|
|
|
2022-05-21 16:44:09 +02:00
|
|
|
const auto dir = fill_database();
|
|
|
|
const auto cmdline = format("%s -q -e main %s/test-mu-guile.scm "
|
|
|
|
"--muhome=%s --test=%s",
|
|
|
|
GUILE_BINARY,
|
|
|
|
ABS_SRCDIR,
|
|
|
|
dir.c_str(), what);
|
2021-10-20 11:18:15 +02:00
|
|
|
|
2022-05-21 16:44:09 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("cmdline: %s\n", cmdline.c_str());
|
|
|
|
|
|
|
|
GError *err{};
|
|
|
|
int status{};
|
|
|
|
if (!g_spawn_command_line_sync(cmdline.c_str(), NULL, NULL, &status, &err) ||
|
|
|
|
status != 0) {
|
|
|
|
g_printerr("Error: %s\n", err ? err->message : "something went wrong");
|
|
|
|
g_clear_error(&err);
|
|
|
|
g_assert(0);
|
|
|
|
}
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_guile_queries(void)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
test_something("queries");
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_guile_messages(void)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
test_something("message");
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_guile_stats(void)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
test_something("stats");
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-10-20 11:18:15 +02:00
|
|
|
main(int argc, char* argv[])
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
|
|
|
int rv;
|
2022-05-21 16:44:09 +02:00
|
|
|
TempDir tempdir;
|
|
|
|
test_dir = tempdir.path();
|
|
|
|
|
2022-08-10 07:20:58 +02:00
|
|
|
mu_test_init(&argc, &argv);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
if (!set_en_us_utf8_locale())
|
|
|
|
return 0; /* don't error out... */
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/guile/queries", test_mu_guile_queries);
|
|
|
|
g_test_add_func("/guile/message", test_mu_guile_messages);
|
|
|
|
g_test_add_func("/guile/stats", test_mu_guile_stats);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = g_test_run();
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|