2011-09-12 19:33:06 +02:00
|
|
|
/*
|
2016-05-15 15:21:20 +02:00
|
|
|
** Copyright (C) 2008-2016 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-01-27 07:15:08 +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-09-12 19:33:06 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-01-27 07:15:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2010-01-31 11:15:00 +01:00
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2010-01-28 21:21:57 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
#include "test-mu-common.h"
|
2012-05-20 16:41:18 +02:00
|
|
|
#include "mu-maildir.h"
|
2019-12-16 20:44:35 +01:00
|
|
|
#include "utils/mu-util.h"
|
2010-01-27 07:15:08 +01:00
|
|
|
|
|
|
|
static void
|
2012-02-26 11:18:17 +01:00
|
|
|
test_mu_maildir_mkdir_01 (void)
|
2010-01-27 07:15:08 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gchar *tmpdir, *mdir, *tmp;
|
|
|
|
const gchar *subs[] = {"tmp", "cur", "new"};
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir ();
|
2010-01-27 07:15:08 +01:00
|
|
|
mdir = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
"cuux");
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-12-05 15:29:53 +01:00
|
|
|
g_assert_cmpuint (mu_maildir_mkdir (mdir, 0755, FALSE, NULL),
|
2010-01-27 07:15:08 +01:00
|
|
|
==, TRUE);
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
|
|
gchar* dir;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
dir = g_strdup_printf ("%s%c%s", mdir, G_DIR_SEPARATOR,
|
|
|
|
subs[i]);
|
|
|
|
g_assert_cmpuint (g_access (dir, R_OK), ==, 0);
|
|
|
|
g_assert_cmpuint (g_access (dir, W_OK), ==, 0);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = g_strdup_printf ("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
|
|
g_assert_cmpuint (g_access (tmp, F_OK), !=, 0);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
g_free (tmp);
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (mdir);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-02-26 11:18:17 +01:00
|
|
|
test_mu_maildir_mkdir_02 (void)
|
2010-01-27 07:15:08 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gchar *tmpdir, *mdir, *tmp;
|
|
|
|
const gchar *subs[] = {"tmp", "cur", "new"};
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir ();
|
2010-01-27 07:15:08 +01:00
|
|
|
mdir = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
"cuux");
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-12-05 15:29:53 +01:00
|
|
|
g_assert_cmpuint (mu_maildir_mkdir (mdir, 0755, TRUE, NULL),
|
2010-01-27 07:15:08 +01:00
|
|
|
==, TRUE);
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
|
|
gchar* dir;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
dir = g_strdup_printf ("%s%c%s", mdir, G_DIR_SEPARATOR,
|
|
|
|
subs[i]);
|
|
|
|
g_assert_cmpuint (g_access (dir, R_OK), ==, 0);
|
|
|
|
|
|
|
|
g_assert_cmpuint (g_access (dir, W_OK), ==, 0);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
tmp = g_strdup_printf ("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
|
|
g_assert_cmpuint (g_access (tmp, F_OK), ==, 0);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
g_free (tmp);
|
|
|
|
g_free (tmpdir);
|
2011-09-12 19:33:06 +02:00
|
|
|
g_free (mdir);
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-26 11:18:17 +01:00
|
|
|
static void
|
|
|
|
test_mu_maildir_mkdir_03 (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gchar *tmpdir, *mdir, *tmp;
|
|
|
|
const gchar *subs[] = {"tmp", "cur", "new"};
|
|
|
|
|
|
|
|
tmpdir = test_mu_common_get_random_tmpdir ();
|
|
|
|
mdir = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
"cuux");
|
|
|
|
|
|
|
|
/* create part of the structure already... */
|
|
|
|
{
|
|
|
|
gchar *dir;
|
|
|
|
dir = g_strdup_printf ("%s%ccur", mdir, G_DIR_SEPARATOR);
|
|
|
|
g_assert_cmpuint (g_mkdir_with_parents (dir, 0755), ==, 0);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this should still work */
|
|
|
|
g_assert_cmpuint (mu_maildir_mkdir (mdir, 0755, FALSE, NULL),
|
|
|
|
==, TRUE);
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
|
|
gchar* dir;
|
|
|
|
|
|
|
|
dir = g_strdup_printf ("%s%c%s", mdir, G_DIR_SEPARATOR,
|
|
|
|
subs[i]);
|
|
|
|
g_assert_cmpuint (g_access (dir, R_OK), ==, 0);
|
|
|
|
g_assert_cmpuint (g_access (dir, W_OK), ==, 0);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = g_strdup_printf ("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
|
|
g_assert_cmpuint (g_access (tmp, F_OK), !=, 0);
|
|
|
|
|
|
|
|
g_free (tmp);
|
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (mdir);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_maildir_mkdir_04 (void)
|
|
|
|
{
|
|
|
|
gchar *tmpdir, *mdir;
|
|
|
|
|
|
|
|
tmpdir = test_mu_common_get_random_tmpdir ();
|
|
|
|
mdir = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR,
|
|
|
|
"cuux");
|
|
|
|
|
|
|
|
/* create part of the structure already... */
|
|
|
|
{
|
|
|
|
gchar *dir;
|
|
|
|
g_assert_cmpuint (g_mkdir_with_parents (mdir, 0755), ==, 0);
|
|
|
|
dir = g_strdup_printf ("%s%ccur", mdir, G_DIR_SEPARATOR);
|
|
|
|
g_assert_cmpuint (g_mkdir_with_parents (dir, 0000), ==, 0);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this should fail now, because cur is not read/writable */
|
|
|
|
g_assert_cmpuint (mu_maildir_mkdir (mdir, 0755, FALSE, NULL),
|
2012-11-08 21:31:51 +01:00
|
|
|
==, (geteuid()==0 ? TRUE : FALSE));
|
2012-02-26 11:18:17 +01:00
|
|
|
g_free (tmpdir);
|
|
|
|
g_free (mdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
ignore_error (const char* log_domain, GLogLevelFlags log_level, const gchar* msg,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
return FALSE; /* don't abort */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-26 11:18:17 +01:00
|
|
|
test_mu_maildir_mkdir_05 (void)
|
2011-09-12 19:33:06 +02:00
|
|
|
{
|
2010-01-27 07:15:08 +01:00
|
|
|
/* this must fail */
|
|
|
|
g_test_log_set_fatal_handler ((GTestLogFatalFunc)ignore_error, NULL);
|
|
|
|
|
2010-12-05 15:29:53 +01:00
|
|
|
g_assert_cmpuint (mu_maildir_mkdir (NULL, 0755, TRUE, NULL),
|
2010-01-27 07:15:08 +01:00
|
|
|
==, FALSE);
|
|
|
|
}
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
static gchar*
|
|
|
|
copy_test_data (void)
|
|
|
|
{
|
|
|
|
gchar *dir, *cmd;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
dir = test_mu_common_get_random_tmpdir();
|
2012-01-31 19:55:56 +01:00
|
|
|
cmd = g_strdup_printf ("mkdir -m 0700 %s", dir);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("cmd: %s\n", cmd);
|
2010-01-28 21:21:57 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
|
|
|
g_free (cmd);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-02-02 20:48:41 +01:00
|
|
|
cmd = g_strdup_printf ("cp -R %s %s", MU_TESTMAILDIR, dir);
|
2012-01-31 19:55:56 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("cmd: %s\n", cmd);
|
2010-01-28 21:21:57 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
|
|
|
g_free (cmd);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int _file_count;
|
|
|
|
int _dir_entered;
|
|
|
|
int _dir_left;
|
|
|
|
} WalkData;
|
|
|
|
|
2011-08-11 19:21:01 +02:00
|
|
|
static MuError
|
2010-01-28 21:21:57 +01:00
|
|
|
dir_cb (const char *fullpath, gboolean enter, WalkData *data)
|
|
|
|
{
|
2011-09-12 19:33:06 +02:00
|
|
|
if (enter)
|
2011-08-13 01:25:03 +02:00
|
|
|
++data->_dir_entered;
|
2010-01-28 21:21:57 +01:00
|
|
|
else
|
|
|
|
++data->_dir_left;
|
|
|
|
|
2012-01-22 23:11:45 +01:00
|
|
|
if (g_test_verbose())
|
2015-04-22 20:06:31 +02:00
|
|
|
g_print ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving",
|
2012-01-22 23:11:45 +01:00
|
|
|
fullpath, enter ? data->_dir_entered : data->_dir_left);
|
2010-08-14 14:19:08 +02:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
return MU_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-11 19:21:01 +02:00
|
|
|
static MuError
|
2011-01-15 10:53:18 +01:00
|
|
|
msg_cb (const char *fullpath, const char* mdir, struct stat *statinfo,
|
2010-02-08 20:25:53 +01:00
|
|
|
WalkData *data)
|
2010-01-28 21:21:57 +01:00
|
|
|
{
|
|
|
|
++data->_file_count;
|
|
|
|
return MU_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_maildir_walk_01 (void)
|
|
|
|
{
|
|
|
|
char *tmpdir;
|
|
|
|
WalkData data;
|
2011-08-11 19:21:01 +02:00
|
|
|
MuError rv;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
tmpdir = copy_test_data ();
|
|
|
|
memset (&data, 0, sizeof(WalkData));
|
2010-08-14 14:19:08 +02:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
rv = mu_maildir_walk (tmpdir,
|
2011-09-12 19:33:06 +02:00
|
|
|
(MuMaildirWalkMsgCallback)msg_cb,
|
2010-01-28 21:21:57 +01:00
|
|
|
(MuMaildirWalkDirCallback)dir_cb,
|
2012-05-22 09:19:49 +02:00
|
|
|
TRUE,
|
2010-01-28 21:21:57 +01:00
|
|
|
&data);
|
|
|
|
|
|
|
|
g_assert_cmpuint (MU_OK, ==, rv);
|
2016-05-15 15:21:20 +02:00
|
|
|
g_assert_cmpuint (data._file_count, ==, 19);
|
2012-01-31 19:55:56 +01:00
|
|
|
|
2012-03-14 20:33:06 +01:00
|
|
|
g_assert_cmpuint (data._dir_entered,==, 5);
|
2012-03-19 19:49:19 +01:00
|
|
|
g_assert_cmpuint (data._dir_left,==, 5);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-05-22 09:19:49 +02:00
|
|
|
test_mu_maildir_walk (void)
|
2010-01-28 21:21:57 +01:00
|
|
|
{
|
2012-01-31 19:55:56 +01:00
|
|
|
char *tmpdir, *cmd, *dir;
|
2010-01-28 21:21:57 +01:00
|
|
|
WalkData data;
|
2011-08-11 19:21:01 +02:00
|
|
|
MuError rv;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
tmpdir = copy_test_data ();
|
|
|
|
memset (&data, 0, sizeof(WalkData));
|
2011-09-12 19:33:06 +02:00
|
|
|
|
|
|
|
/* mark the 'new' dir with '.noindex', to ignore it */
|
2012-01-31 19:55:56 +01:00
|
|
|
dir = g_strdup_printf ("%s%ctestdir%cnew", tmpdir,
|
|
|
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
|
|
|
cmd = g_strdup_printf ("chmod 700 %s", dir);
|
2010-01-28 21:21:57 +01:00
|
|
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
|
|
|
g_free (cmd);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2012-01-31 19:55:56 +01:00
|
|
|
cmd = g_strdup_printf ("touch %s%c.noindex", dir, G_DIR_SEPARATOR);
|
|
|
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
|
|
|
g_free (cmd);
|
|
|
|
g_free (dir);
|
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
rv = mu_maildir_walk (tmpdir,
|
2011-09-12 19:33:06 +02:00
|
|
|
(MuMaildirWalkMsgCallback)msg_cb,
|
2010-01-28 21:21:57 +01:00
|
|
|
(MuMaildirWalkDirCallback)dir_cb,
|
2012-05-22 09:19:49 +02:00
|
|
|
TRUE,
|
|
|
|
&data);
|
|
|
|
|
|
|
|
g_assert_cmpuint (MU_OK, ==, rv);
|
2016-05-15 15:21:20 +02:00
|
|
|
g_assert_cmpuint (data._file_count, ==, 15);
|
2012-05-22 09:19:49 +02:00
|
|
|
|
|
|
|
g_assert_cmpuint (data._dir_entered,==, 4);
|
|
|
|
g_assert_cmpuint (data._dir_left,==, 4);
|
|
|
|
|
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_maildir_walk_with_noupdate (void)
|
|
|
|
{
|
|
|
|
char *tmpdir, *cmd, *dir;
|
|
|
|
WalkData data;
|
|
|
|
MuError rv;
|
|
|
|
|
|
|
|
tmpdir = copy_test_data ();
|
|
|
|
|
|
|
|
/* mark the 'new' dir with '.noindex', to ignore it */
|
|
|
|
dir = g_strdup_printf ("%s%ctestdir%cnew", tmpdir,
|
|
|
|
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
|
|
|
cmd = g_strdup_printf ("chmod 700 %s", dir);
|
|
|
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
|
|
|
g_free (cmd);
|
|
|
|
|
|
|
|
memset (&data, 0, sizeof(WalkData));
|
|
|
|
rv = mu_maildir_walk (tmpdir,
|
|
|
|
(MuMaildirWalkMsgCallback)msg_cb,
|
|
|
|
(MuMaildirWalkDirCallback)dir_cb,
|
|
|
|
FALSE, /* ie., non-full update */
|
|
|
|
&data);
|
|
|
|
|
|
|
|
g_assert_cmpuint (MU_OK, ==, rv);
|
2016-05-15 15:21:20 +02:00
|
|
|
g_assert_cmpuint (data._file_count, ==, 19);
|
2012-05-22 09:19:49 +02:00
|
|
|
g_assert_cmpuint (data._dir_entered,==, 5);
|
|
|
|
g_assert_cmpuint (data._dir_left,==, 5);
|
|
|
|
|
|
|
|
/* again, full update. results should be the same, since there
|
|
|
|
* is no noupdate yet */
|
|
|
|
memset (&data, 0, sizeof(WalkData));
|
|
|
|
rv = mu_maildir_walk (tmpdir,
|
|
|
|
(MuMaildirWalkMsgCallback)msg_cb,
|
|
|
|
(MuMaildirWalkDirCallback)dir_cb,
|
|
|
|
TRUE, /* ie., full update */
|
|
|
|
&data);
|
|
|
|
|
|
|
|
g_assert_cmpuint (MU_OK, ==, rv);
|
2016-05-15 15:21:20 +02:00
|
|
|
g_assert_cmpuint (data._file_count, ==, 19);
|
2012-05-22 09:19:49 +02:00
|
|
|
g_assert_cmpuint (data._dir_entered,==, 5);
|
|
|
|
g_assert_cmpuint (data._dir_left,==, 5);
|
|
|
|
|
|
|
|
/* add a '.noupdate' file; this affects the outcome when the
|
|
|
|
* 4th arg to mu_maildir_walk is FALSE */
|
|
|
|
cmd = g_strdup_printf ("touch %s%c.noupdate", dir, G_DIR_SEPARATOR);
|
|
|
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
|
|
|
g_free (cmd);
|
|
|
|
|
|
|
|
memset (&data, 0, sizeof(WalkData));
|
|
|
|
rv = mu_maildir_walk (tmpdir,
|
|
|
|
(MuMaildirWalkMsgCallback)msg_cb,
|
|
|
|
(MuMaildirWalkDirCallback)dir_cb,
|
|
|
|
FALSE, /* non-full update */
|
2010-01-28 21:21:57 +01:00
|
|
|
&data);
|
|
|
|
|
|
|
|
g_assert_cmpuint (MU_OK, ==, rv);
|
2016-05-15 15:21:20 +02:00
|
|
|
g_assert_cmpuint (data._file_count, ==, 15);
|
2012-01-31 19:55:56 +01:00
|
|
|
|
2012-03-14 20:33:06 +01:00
|
|
|
g_assert_cmpuint (data._dir_entered,==, 4);
|
2012-03-19 19:49:19 +01:00
|
|
|
g_assert_cmpuint (data._dir_left,==, 4);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
2012-05-22 09:19:49 +02:00
|
|
|
/* now run again, but do a full update */
|
|
|
|
memset (&data, 0, sizeof(WalkData));
|
|
|
|
rv = mu_maildir_walk (tmpdir,
|
|
|
|
(MuMaildirWalkMsgCallback)msg_cb,
|
|
|
|
(MuMaildirWalkDirCallback)dir_cb,
|
|
|
|
TRUE, /* full update */
|
|
|
|
&data);
|
|
|
|
|
|
|
|
g_assert_cmpuint (MU_OK, ==, rv);
|
2016-05-15 15:21:20 +02:00
|
|
|
g_assert_cmpuint (data._file_count, ==, 19);
|
2012-05-22 09:19:49 +02:00
|
|
|
|
|
|
|
g_assert_cmpuint (data._dir_entered,==, 5);
|
|
|
|
g_assert_cmpuint (data._dir_left,==, 5);
|
|
|
|
|
|
|
|
g_free (dir);
|
2010-01-28 21:21:57 +01:00
|
|
|
g_free (tmpdir);
|
|
|
|
}
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2011-05-06 07:11:47 +02:00
|
|
|
|
|
|
|
|
2012-05-22 09:19:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-06 07:11:47 +02:00
|
|
|
static void
|
|
|
|
test_mu_maildir_get_flags_from_path (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct {
|
|
|
|
const char *path;
|
2011-08-11 21:44:23 +02:00
|
|
|
MuFlags flags;
|
2011-05-06 07:11:47 +02:00
|
|
|
} paths[] = {
|
|
|
|
{
|
2011-08-13 01:25:03 +02:00
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FSR",
|
|
|
|
MU_FLAG_REPLIED | MU_FLAG_SEEN | MU_FLAG_FLAGGED
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"/home/foo/Maildir/test/new/123456",
|
|
|
|
MU_FLAG_NEW
|
|
|
|
},
|
|
|
|
{
|
|
|
|
/* NOTE: when in new/, the :2,.. stuff is ignored */
|
|
|
|
"/home/foo/Maildir/test/new/123456:2,FR",
|
|
|
|
MU_FLAG_NEW
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,DTP",
|
|
|
|
MU_FLAG_DRAFT | MU_FLAG_TRASHED |
|
|
|
|
MU_FLAG_PASSED
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,S",
|
|
|
|
MU_FLAG_SEEN
|
|
|
|
}
|
2011-05-06 07:11:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
2011-09-12 19:33:06 +02:00
|
|
|
MuFlags flags;
|
2011-05-06 07:11:47 +02:00
|
|
|
flags = mu_maildir_get_flags_from_path(paths[i].path);
|
|
|
|
g_assert_cmpuint(flags, ==, paths[i].flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-25 18:28:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
assert_matches_regexp (const char *str, const char *rx)
|
|
|
|
{
|
|
|
|
if (!g_regex_match_simple (rx, str, 0, 0)) {
|
2013-05-27 14:48:19 +02:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("%s does not match %s", str, rx);
|
2013-05-25 18:28:40 +02:00
|
|
|
g_assert (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_maildir_get_new_path_new (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *oldpath;
|
|
|
|
MuFlags flags;
|
|
|
|
const char *newpath;
|
|
|
|
} paths[] = {
|
|
|
|
{
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
MU_FLAG_REPLIED,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,R"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
MU_FLAG_NEW,
|
|
|
|
"/home/foo/Maildir/test/new/123456"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/new/123456:2,FR",
|
|
|
|
MU_FLAG_SEEN | MU_FLAG_REPLIED,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,RS"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/new/1313038887_0.697:2,",
|
|
|
|
MU_FLAG_SEEN | MU_FLAG_FLAGGED | MU_FLAG_PASSED,
|
|
|
|
"/home/foo/Maildir/test/cur/1313038887_0.697:2,FPS"
|
|
|
|
}, {
|
|
|
|
"/home/djcb/Maildir/trash/new/1312920597.2206_16.cthulhu",
|
|
|
|
MU_FLAG_SEEN,
|
|
|
|
"/home/djcb/Maildir/trash/cur/1312920597.2206_16.cthulhu:2,S"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
char *str, *newbase;
|
2013-05-27 14:48:19 +02:00
|
|
|
str = mu_maildir_get_new_path (paths[i].oldpath, NULL,
|
|
|
|
paths[i].flags, TRUE);
|
2013-05-25 18:28:40 +02:00
|
|
|
newbase = g_path_get_basename (str);
|
2015-10-02 16:43:38 +02:00
|
|
|
assert_matches_regexp (newbase,
|
|
|
|
"\\d+\\."
|
|
|
|
"[[:xdigit:]]{16}\\."
|
2019-11-17 04:53:28 +01:00
|
|
|
"[[:alnum:]][[:alnum:]-]+(:2,.*)?");
|
2013-05-25 18:28:40 +02:00
|
|
|
g_free (newbase);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-06 07:11:47 +02:00
|
|
|
static void
|
2011-08-13 01:25:03 +02:00
|
|
|
test_mu_maildir_get_new_path_01 (void)
|
2011-05-06 07:11:47 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *oldpath;
|
2011-08-11 21:44:23 +02:00
|
|
|
MuFlags flags;
|
2011-05-06 07:11:47 +02:00
|
|
|
const char *newpath;
|
|
|
|
} paths[] = {
|
|
|
|
{
|
2011-08-11 19:21:01 +02:00
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
2011-08-11 21:44:23 +02:00
|
|
|
MU_FLAG_REPLIED,
|
2011-08-11 19:21:01 +02:00
|
|
|
"/home/foo/Maildir/test/cur/123456:2,R"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
2011-08-11 21:44:23 +02:00
|
|
|
MU_FLAG_NEW,
|
2011-08-13 01:25:03 +02:00
|
|
|
"/home/foo/Maildir/test/new/123456"
|
2011-08-11 19:21:01 +02:00
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/new/123456:2,FR",
|
2011-08-11 21:44:23 +02:00
|
|
|
MU_FLAG_SEEN | MU_FLAG_REPLIED,
|
2011-08-11 19:21:01 +02:00
|
|
|
"/home/foo/Maildir/test/cur/123456:2,RS"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/new/1313038887_0.697:2,",
|
2011-08-11 21:44:23 +02:00
|
|
|
MU_FLAG_SEEN | MU_FLAG_FLAGGED | MU_FLAG_PASSED,
|
2011-09-12 19:33:06 +02:00
|
|
|
"/home/foo/Maildir/test/cur/1313038887_0.697:2,FPS"
|
2011-08-11 21:44:23 +02:00
|
|
|
}, {
|
2011-08-11 19:21:01 +02:00
|
|
|
"/home/djcb/Maildir/trash/new/1312920597.2206_16.cthulhu",
|
2011-08-11 21:44:23 +02:00
|
|
|
MU_FLAG_SEEN,
|
2011-08-11 19:21:01 +02:00
|
|
|
"/home/djcb/Maildir/trash/cur/1312920597.2206_16.cthulhu:2,S"
|
|
|
|
}
|
2011-05-06 07:11:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
gchar *str;
|
2011-08-13 01:25:03 +02:00
|
|
|
str = mu_maildir_get_new_path(paths[i].oldpath, NULL,
|
2013-05-25 18:28:40 +02:00
|
|
|
paths[i].flags, FALSE);
|
2011-08-13 01:25:03 +02:00
|
|
|
g_assert_cmpstr(str, ==, paths[i].newpath);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_maildir_get_new_path_02 (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *oldpath;
|
|
|
|
MuFlags flags;
|
|
|
|
const char *targetdir;
|
|
|
|
const char *newpath;
|
|
|
|
} paths[] = {
|
|
|
|
{
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
MU_FLAG_REPLIED, "/home/foo/Maildir/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,R"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
MU_FLAG_NEW, "/home/bar/Maildir/coffee",
|
|
|
|
"/home/bar/Maildir/coffee/new/123456"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/new/123456",
|
|
|
|
MU_FLAG_SEEN | MU_FLAG_REPLIED,
|
|
|
|
"/home/cuux/Maildir/tea",
|
|
|
|
"/home/cuux/Maildir/tea/cur/123456:2,RS"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/new/1313038887_0.697:2,",
|
|
|
|
MU_FLAG_SEEN | MU_FLAG_FLAGGED | MU_FLAG_PASSED,
|
|
|
|
"/home/boy/Maildir/stuff",
|
|
|
|
"/home/boy/Maildir/stuff/cur/1313038887_0.697:2,FPS"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
gchar *str;
|
|
|
|
str = mu_maildir_get_new_path(paths[i].oldpath,
|
|
|
|
paths[i].targetdir,
|
2013-05-25 18:28:40 +02:00
|
|
|
paths[i].flags, FALSE);
|
2011-05-06 07:11:47 +02:00
|
|
|
g_assert_cmpstr(str, ==, paths[i].newpath);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 08:10:22 +02:00
|
|
|
static void
|
|
|
|
test_mu_maildir_get_new_path_custom (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *oldpath;
|
|
|
|
MuFlags flags;
|
|
|
|
const char *targetdir;
|
|
|
|
const char *newpath;
|
|
|
|
} paths[] = {
|
|
|
|
{
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
MU_FLAG_REPLIED, "/home/foo/Maildir/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,R"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,hFeRllo123",
|
|
|
|
MU_FLAG_FLAGGED, "/home/foo/Maildir/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,Fhello123"
|
|
|
|
}, {
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,abc",
|
|
|
|
MU_FLAG_PASSED, "/home/foo/Maildir/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,Pabc"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
gchar *str;
|
|
|
|
str = mu_maildir_get_new_path(paths[i].oldpath,
|
|
|
|
paths[i].targetdir,
|
2013-05-25 18:28:40 +02:00
|
|
|
paths[i].flags, FALSE);
|
2012-06-13 08:10:22 +02:00
|
|
|
g_assert_cmpstr(str, ==, paths[i].newpath);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-12 19:33:06 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_maildir_get_maildir_from_path (void)
|
|
|
|
{
|
|
|
|
unsigned u;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *path, *exp;
|
|
|
|
} cases[] = {
|
|
|
|
{"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
"/home/foo/Maildir/test"},
|
|
|
|
{"/home/foo/Maildir/lala/new/1313038887_0.697:2,",
|
|
|
|
"/home/foo/Maildir/lala"}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (u = 0; u != G_N_ELEMENTS(cases); ++u) {
|
|
|
|
gchar *mdir;
|
|
|
|
mdir = mu_maildir_get_maildir_from_path (cases[u].path);
|
|
|
|
g_assert_cmpstr(mdir,==,cases[u].exp);
|
|
|
|
g_free (mdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
/* mu_util_maildir_mkmdir */
|
2016-05-15 15:21:20 +02:00
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-mkdir-01",
|
2012-02-26 11:18:17 +01:00
|
|
|
test_mu_maildir_mkdir_01);
|
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-mkdir-02",
|
|
|
|
test_mu_maildir_mkdir_02);
|
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-mkdir-03",
|
|
|
|
test_mu_maildir_mkdir_03);
|
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-mkdir-04",
|
|
|
|
test_mu_maildir_mkdir_04);
|
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-mkdir-05",
|
|
|
|
test_mu_maildir_mkdir_05);
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
/* mu_util_maildir_walk */
|
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-walk-01",
|
|
|
|
test_mu_maildir_walk_01);
|
2012-05-22 09:19:49 +02:00
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-walk",
|
|
|
|
test_mu_maildir_walk);
|
|
|
|
g_test_add_func ("/mu-maildir/mu-maildir-walk-with-noupdate",
|
|
|
|
test_mu_maildir_walk_with_noupdate);
|
2011-05-06 07:11:47 +02:00
|
|
|
|
|
|
|
/* get/set flags */
|
2013-05-25 18:28:40 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-new",
|
|
|
|
test_mu_maildir_get_new_path_new);
|
|
|
|
|
2011-08-13 01:25:03 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-01",
|
|
|
|
test_mu_maildir_get_new_path_01);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-02",
|
|
|
|
test_mu_maildir_get_new_path_02);
|
2012-06-13 08:10:22 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-custom",
|
|
|
|
test_mu_maildir_get_new_path_custom);
|
2011-05-06 07:11:47 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-flags-from-path",
|
|
|
|
test_mu_maildir_get_flags_from_path);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-maildir-from-path",
|
|
|
|
test_mu_maildir_get_maildir_from_path);
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
g_log_set_handler (NULL,
|
2012-03-19 19:49:19 +01:00
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL|
|
|
|
|
G_LOG_FLAG_RECURSION,
|
2010-09-26 14:23:17 +02:00
|
|
|
(GLogFunc)black_hole, NULL);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
return g_test_run ();
|
|
|
|
}
|