2
** Copyright (C) 2008 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
4
** This program is free software; you can redistribute it and/or modify it
5
** under the terms of the GNU General Public License as published by the
6
** Free Software Foundation; either version 3, or (at your option) any
9
** This program is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
** GNU General Public License for more details.
14
** You should have received a copy of the GNU General Public License
15
** along with this program; if not, write to the Free Software Foundation,
16
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#define _XOPEN_SOURCE 500 /* for random() */
24
#endif /*HAVE_CONFIG_H*/
28
#include <glib-object.h>
31
#include <glib/gstdio.h>
32
#include <sys/types.h>
39
#include "index/mu-index.h"
40
#include "msg/mu-msg-gmime.h"
45
return g_strdup_printf ("%s%c%s.%x", g_get_tmp_dir(),
46
G_DIR_SEPARATOR, "mu-test-index",
47
(int)random()*getpid()*(int)time(NULL));
52
stats_callback (MuIndexStats *stats, void *user_data)
54
((int)*(int*)user_data)++;
60
void test_mu_index_reindex ()
64
char *name = random_tmpdir();
66
char *sqlite_db = g_strdup_printf ("%s/sqlite.db", name);
67
char *xapian_db = g_strdup_printf ("%s/xapian.db", name);
68
g_assert (g_mkdir (name, 0700) == 0);
75
index = mu_index_new (sqlite_db, xapian_db);
76
g_assert(index != NULL);
78
memset (&stats, 0, sizeof(MuIndexStats));
82
/* copy the test maildir to our random dir */
83
cmd = g_strdup_printf ("cp -R " ABS_SRCDIR "/TestMaildir %s",
85
g_assert (system (cmd) == 0);
88
maildir = g_strdup_printf ("%s/TestMaildir", name);
89
g_assert_cmpint (mu_index_run (index,maildir,
90
FALSE, &stats, stats_callback, &num),
92
g_assert_cmpint (num,==,10);
93
g_assert_cmpint (stats._added,==,10);
96
memset (&stats, 0, sizeof(MuIndexStats));
98
g_assert_cmpint (mu_index_run (index,maildir,
99
FALSE, &stats, stats_callback, &num),
101
g_assert_cmpint (num,==,10);
102
g_assert_cmpint (stats._added,==,0);
103
g_assert_cmpint (stats._uptodate,==,10);
105
sleep (1); /* sleep one seconds, or we are too fast for the
106
timestamps to change...*/
108
/* now, remove two files, update two */
109
cmd = g_strdup_printf ("cd %s; "
110
"rm cur/1220863042.12663_1.mindcrime:2,S;"
111
"rm cur/1220863060.12663_3.mindcrime:2,S", maildir);
112
g_assert (system (cmd) == 0);
114
cmd = g_strdup_printf ("cd %s; "
116
"touch cur/1220863087.12663_19.mindcrime:2,S;"
117
"touch new/1220863087.12663_25.mindcrime", maildir);
118
g_assert (system (cmd) == 0);
122
memset (&stats, 0, sizeof(MuIndexStats));
124
g_assert_cmpint (mu_index_run (index,maildir,
125
FALSE, &stats, stats_callback, &num),
128
g_assert_cmpint (num,==,8); /* there should be only two left */
129
g_assert_cmpint (stats._added,==,0);
130
g_assert_cmpint (stats._uptodate,==,6);
131
g_assert_cmpint (stats._updated,==,2);
133
mu_index_destroy (index);
134
mu_msg_gmime_uninit ();
148
main (int argc, char *argv[])
150
g_test_init (&argc, &argv, NULL);
152
g_test_add_func ("/index/reindex", test_mu_index_reindex);
154
g_log_set_handler (NULL,
155
G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO,
156
(GLogFunc)shutup, NULL);
158
return g_test_run ();