2011-08-10 22:58:36 +02:00
|
|
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
/*
|
2013-03-30 10:32:07 +01:00
|
|
|
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-12-03 19:45:01 +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,
|
2011-08-29 22:39:11 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-12-03 19:45:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
#include "test-mu-common.h"
|
2019-07-28 13:28:25 +02:00
|
|
|
#include "mu-store.hh"
|
2010-12-03 19:45:01 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_store_new_destroy (void)
|
|
|
|
{
|
2011-08-10 22:58:36 +02:00
|
|
|
MuStore *store;
|
|
|
|
gchar* tmpdir;
|
|
|
|
GError *err;
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (tmpdir);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
err = NULL;
|
2020-02-03 16:38:12 +01:00
|
|
|
store = mu_store_new_create (tmpdir, "/tmp", NULL, &err);
|
2014-01-15 20:27:18 +01:00
|
|
|
g_assert_no_error (err);
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (store);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (0,==,mu_store_count (store, NULL));
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
mu_store_flush (store);
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-08-29 22:39:11 +02:00
|
|
|
g_free (tmpdir);
|
2010-12-03 19:45:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_store_version (void)
|
|
|
|
{
|
2011-08-10 22:58:36 +02:00
|
|
|
MuStore *store;
|
|
|
|
gchar* tmpdir;
|
|
|
|
GError *err;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (tmpdir);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
err = NULL;
|
2020-02-03 16:38:12 +01:00
|
|
|
store = mu_store_new_create (tmpdir, "/tmp", NULL, &err);
|
2011-08-29 22:39:11 +02:00
|
|
|
g_assert (store);
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
2019-07-28 13:28:25 +02:00
|
|
|
store = mu_store_new_readable (tmpdir, &err);
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (store);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (err == NULL);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (0,==,mu_store_count (store, NULL));
|
2011-08-30 20:59:05 +02:00
|
|
|
g_assert_cmpstr (MU_STORE_SCHEMA_VERSION,==,
|
2019-07-28 13:28:25 +02:00
|
|
|
mu_store_schema_version(store));
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
2011-08-29 22:39:11 +02:00
|
|
|
g_free (tmpdir);
|
2010-12-03 19:45:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-20 19:14:00 +01:00
|
|
|
G_GNUC_UNUSED static void
|
2011-08-03 22:03:22 +02:00
|
|
|
test_mu_store_store_msg_and_count (void)
|
2011-08-29 22:39:11 +02:00
|
|
|
{
|
2011-08-10 22:58:36 +02:00
|
|
|
MuMsg *msg;
|
|
|
|
MuStore *store;
|
|
|
|
gchar* tmpdir;
|
2010-12-04 11:37:57 +01:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (tmpdir);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2020-02-03 16:38:12 +01:00
|
|
|
store = mu_store_new_create (tmpdir, MU_TESTMAILDIR, NULL, NULL);
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (store);
|
2012-08-11 21:30:13 +02:00
|
|
|
g_free (tmpdir);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (0,==,mu_store_count (store, NULL));
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
/* add one */
|
2016-01-20 19:14:00 +01:00
|
|
|
/* XXX this passes, but not make-dist; investigate */
|
2011-08-10 22:58:36 +02:00
|
|
|
msg = mu_msg_new_from_file (
|
2012-03-14 20:33:06 +01:00
|
|
|
MU_TESTMAILDIR "/cur/1283599333.1840_11.cthulhu!2,",
|
2011-08-29 22:39:11 +02:00
|
|
|
NULL, NULL);
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (msg);
|
2011-09-18 20:29:28 +02:00
|
|
|
g_assert_cmpuint (mu_store_add_msg (store, msg, NULL),
|
|
|
|
!=, MU_STORE_INVALID_DOCID);
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (1,==,mu_store_count (store, NULL));
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert_cmpuint (TRUE,==,mu_store_contains_message
|
|
|
|
(store,
|
2020-01-30 23:20:34 +01:00
|
|
|
MU_TESTMAILDIR "/cur/1283599333.1840_11.cthulhu!2,"));
|
2011-08-10 22:58:36 +02:00
|
|
|
mu_msg_unref (msg);
|
|
|
|
|
|
|
|
/* add another one */
|
|
|
|
msg = mu_msg_new_from_file (MU_TESTMAILDIR2
|
2012-03-14 20:33:06 +01:00
|
|
|
"/bar/cur/mail3", NULL, NULL);
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (msg);
|
2011-09-18 20:29:28 +02:00
|
|
|
g_assert_cmpuint (mu_store_add_msg (store, msg, NULL),
|
|
|
|
!=, MU_STORE_INVALID_DOCID);
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (2,==,mu_store_count (store, NULL));
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert_cmpuint (TRUE,==,
|
|
|
|
mu_store_contains_message (store, MU_TESTMAILDIR2
|
2020-01-30 23:20:34 +01:00
|
|
|
"/bar/cur/mail3"));
|
2011-08-10 22:58:36 +02:00
|
|
|
mu_msg_unref (msg);
|
|
|
|
|
|
|
|
/* try to add the first one again. count should be 2 still */
|
|
|
|
msg = mu_msg_new_from_file
|
2012-03-14 20:33:06 +01:00
|
|
|
(MU_TESTMAILDIR "/cur/1283599333.1840_11.cthulhu!2,",
|
2011-08-10 22:58:36 +02:00
|
|
|
NULL, NULL);
|
|
|
|
g_assert (msg);
|
2011-09-18 20:29:28 +02:00
|
|
|
g_assert_cmpuint (mu_store_add_msg (store, msg, NULL),
|
|
|
|
!=, MU_STORE_INVALID_DOCID);
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (2,==,mu_store_count (store, NULL));
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
mu_msg_unref (msg);
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
2010-12-03 19:45:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-20 19:14:00 +01:00
|
|
|
G_GNUC_UNUSED static void
|
2011-08-03 22:03:22 +02:00
|
|
|
test_mu_store_store_msg_remove_and_count (void)
|
2011-08-29 22:39:11 +02:00
|
|
|
{
|
2011-08-10 22:58:36 +02:00
|
|
|
MuMsg *msg;
|
|
|
|
MuStore *store;
|
|
|
|
gchar* tmpdir;
|
|
|
|
GError *err;
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
g_assert (tmpdir);
|
2010-12-03 19:45:01 +01:00
|
|
|
|
2020-02-03 16:38:12 +01:00
|
|
|
store = mu_store_new_create (tmpdir, MU_TESTMAILDIR, NULL, NULL);
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert (store);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (0,==,mu_store_count (store, NULL));
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
/* add one */
|
|
|
|
err = NULL;
|
|
|
|
msg = mu_msg_new_from_file (
|
2012-03-14 20:33:06 +01:00
|
|
|
MU_TESTMAILDIR "/cur/1283599333.1840_11.cthulhu!2,",
|
2011-08-10 22:58:36 +02:00
|
|
|
NULL, &err);
|
|
|
|
g_assert (msg);
|
2011-09-18 20:29:28 +02:00
|
|
|
g_assert_cmpuint (mu_store_add_msg (store, msg, NULL),
|
|
|
|
!=, MU_STORE_INVALID_DOCID);
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (1,==,mu_store_count (store, NULL));
|
2011-08-10 22:58:36 +02:00
|
|
|
mu_msg_unref (msg);
|
|
|
|
|
|
|
|
/* remove one */
|
|
|
|
mu_store_remove_path (store,
|
2012-03-14 20:33:06 +01:00
|
|
|
MU_TESTMAILDIR "/cur/1283599333.1840_11.cthulhu!2,");
|
2011-09-03 09:51:00 +02:00
|
|
|
g_assert_cmpuint (0,==,mu_store_count (store, NULL));
|
2011-08-10 22:58:36 +02:00
|
|
|
g_assert_cmpuint (FALSE,==,mu_store_contains_message
|
|
|
|
(store,
|
2020-01-30 23:20:34 +01:00
|
|
|
MU_TESTMAILDIR "/cur/1283599333.1840_11.cthulhu!2,"));
|
2012-01-11 23:23:37 +01:00
|
|
|
g_free (tmpdir);
|
2011-08-30 20:59:05 +02:00
|
|
|
mu_store_unref (store);
|
2010-12-03 19:45:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2011-08-10 22:58:36 +02:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
/* mu_runtime_init/uninit */
|
|
|
|
g_test_add_func ("/mu-store/mu-store-new-destroy",
|
|
|
|
test_mu_store_new_destroy);
|
|
|
|
g_test_add_func ("/mu-store/mu-store-version",
|
|
|
|
test_mu_store_version);
|
2016-01-20 19:14:00 +01:00
|
|
|
#if 0
|
|
|
|
/* XXX this passes, but not make-dist; investigate */
|
2011-08-10 22:58:36 +02:00
|
|
|
g_test_add_func ("/mu-store/mu-store-store-and-count",
|
|
|
|
test_mu_store_store_msg_and_count);
|
|
|
|
g_test_add_func ("/mu-store/mu-store-store-remove-and-count",
|
2011-08-29 22:39:11 +02:00
|
|
|
test_mu_store_store_msg_remove_and_count);
|
2016-01-20 19:14:00 +01:00
|
|
|
#endif
|
2011-09-03 09:51:00 +02:00
|
|
|
if (!g_test_verbose())
|
|
|
|
g_log_set_handler (NULL,
|
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
|
|
|
(GLogFunc)black_hole, NULL);
|
2011-08-29 22:39:11 +02:00
|
|
|
|
2011-08-10 22:58:36 +02:00
|
|
|
return g_test_run ();
|
2010-12-03 19:45:01 +01:00
|
|
|
}
|