~ubuntu-branches/ubuntu/quantal/maildir-utils/quantal

« back to all changes in this revision

Viewing changes to index/tests/test-reindex.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-01-19 20:12:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100119201243-d8qmzgxgexhy1bs0
Tags: 0.6~beta1-1
* new upstream release 0.6-beta
  - that merges the several different programs under one binary mu
  - no sqlite storage is used anymore
* debian packaging changes:
  - debian/patches
    . remove all patches
  - remove debian/HOWTO (upstream document) it is completely outdated
  - debian/control:
    . adjust build-dep for gmime-2.4
    . remove build-dep on quilt and sqlite
    . adjust the description to new reality
  - debian/rules:
    . do not try to install doc files that are not present anymore
    . disable quilt adaptions
  - add debian/NEWS that explains that the separate programs are gone

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
** Copyright (C) 2008 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
3
 
**
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
7
 
** later version.
8
 
**
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.
13
 
**
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.  
17
 
**  
18
 
*/
19
 
 
20
 
#define _XOPEN_SOURCE 500 /* for random() */
21
 
 
22
 
#ifdef HAVE_CONFIG_H
23
 
#include "config.h"
24
 
#endif /*HAVE_CONFIG_H*/
25
 
 
26
 
#include <stdio.h>
27
 
#include <glib.h>
28
 
#include <glib-object.h>
29
 
 
30
 
#include <stdlib.h>
31
 
#include <glib/gstdio.h>
32
 
#include <sys/types.h>
33
 
#include <sys/stat.h>
34
 
#include <unistd.h>
35
 
#include <string.h>
36
 
#include <errno.h>
37
 
#include <stdlib.h>
38
 
 
39
 
#include "index/mu-index.h"
40
 
#include "msg/mu-msg-gmime.h"
41
 
 
42
 
char*
43
 
random_tmpdir (void)
44
 
{
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));        
48
 
}
49
 
 
50
 
 
51
 
static MuResult
52
 
stats_callback (MuIndexStats *stats, void *user_data)
53
 
{
54
 
        ((int)*(int*)user_data)++;
55
 
        return MU_OK;
56
 
}
57
 
 
58
 
 
59
 
static
60
 
void test_mu_index_reindex ()
61
 
{
62
 
        MuIndex *index;
63
 
        MuIndexStats stats;
64
 
        char *name = random_tmpdir();
65
 
        int num;
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);
69
 
        char *cmd;
70
 
        char *maildir;
71
 
        
72
 
        g_type_init ();
73
 
        mu_msg_gmime_init ();
74
 
        
75
 
        index = mu_index_new (sqlite_db, xapian_db);
76
 
        g_assert(index != NULL);
77
 
                
78
 
        memset (&stats, 0, sizeof(MuIndexStats));
79
 
 
80
 
        num = 0;
81
 
        
82
 
        /* copy the test maildir to our random dir */
83
 
        cmd = g_strdup_printf ("cp -R " ABS_SRCDIR "/TestMaildir %s",
84
 
                               name);
85
 
        g_assert (system (cmd) == 0);
86
 
        g_free(cmd);
87
 
        
88
 
        maildir = g_strdup_printf ("%s/TestMaildir", name);
89
 
        g_assert_cmpint (mu_index_run (index,maildir,
90
 
                                       FALSE, &stats, stats_callback, &num),
91
 
                         ==, MU_OK);
92
 
        g_assert_cmpint (num,==,10);
93
 
        g_assert_cmpint (stats._added,==,10);
94
 
 
95
 
        /* run again */
96
 
        memset (&stats, 0, sizeof(MuIndexStats));
97
 
        num = 0;
98
 
        g_assert_cmpint (mu_index_run (index,maildir,
99
 
                                       FALSE, &stats, stats_callback, &num),
100
 
                         ==, MU_OK);
101
 
        g_assert_cmpint (num,==,10);
102
 
        g_assert_cmpint (stats._added,==,0);
103
 
        g_assert_cmpint (stats._uptodate,==,10);
104
 
 
105
 
        sleep (1); /* sleep one seconds, or we are too fast for the 
106
 
                      timestamps to change...*/
107
 
 
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);
113
 
        g_free (cmd);
114
 
        cmd = g_strdup_printf ("cd %s; "
115
 
                        "touch cur/;"
116
 
                        "touch cur/1220863087.12663_19.mindcrime:2,S;"
117
 
                        "touch new/1220863087.12663_25.mindcrime", maildir);    
118
 
        g_assert (system (cmd) == 0);
119
 
        g_free (cmd);
120
 
 
121
 
        /* run again */
122
 
        memset (&stats, 0, sizeof(MuIndexStats));
123
 
        num = 0;
124
 
        g_assert_cmpint (mu_index_run (index,maildir,
125
 
                                       FALSE, &stats, stats_callback, &num),
126
 
                         ==, MU_OK);
127
 
 
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);
132
 
 
133
 
        mu_index_destroy (index);
134
 
        mu_msg_gmime_uninit ();
135
 
 
136
 
        g_free (sqlite_db);
137
 
        g_free (xapian_db);
138
 
        g_free (maildir);
139
 
        g_free (name);
140
 
}
141
 
 
142
 
 
143
 
 
144
 
static void
145
 
shutup (void) {}
146
 
 
147
 
int
148
 
main (int argc, char *argv[])
149
 
{
150
 
        g_test_init (&argc, &argv, NULL);
151
 
 
152
 
        g_test_add_func ("/index/reindex", test_mu_index_reindex);
153
 
 
154
 
        g_log_set_handler (NULL,
155
 
                           G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO,
156
 
                           (GLogFunc)shutup, NULL);
157
 
 
158
 
        return g_test_run ();
159
 
}