1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
* This library is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This library 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/* threaded folder testing */
#include <string.h>
#include "camel-test.h"
#include "camel-test-provider.h"
#include "session.h"
#define MAX_LOOP (10000)
#define MAX_THREADS (5)
#define GC(x) ((gchar *) (x))
static const gchar *local_drivers[] = { "local" };
static CamelSession *session;
/* FIXME: flags aren't really right yet */
/* ASCII sorted on full_name */
static CamelFolderInfo fi_list_1[] = {
{ NULL, NULL, NULL, GC ("."), GC ("Inbox"), CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC (".#evolution/Junk"), GC ("Junk"), CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC (".#evolution/Trash"), GC ("Trash"), CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC ("testbox"), GC ("testbox"), CAMEL_FOLDER_CHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC ("testbox/foo"), GC ("foo"), CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC ("testbox2"), GC ("testbox2"), CAMEL_FOLDER_NOCHILDREN, -1, -1 },
};
static CamelFolderInfo fi_list_2[] = {
{ NULL, NULL, NULL, GC ("."), GC ("Inbox"), CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC (".#evolution/Junk"), GC ("Junk"), CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC (".#evolution/Trash"), GC ("Trash"), CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC ("testbox"), GC ("testbox"), CAMEL_FOLDER_NOCHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC ("testbox2"), GC ("testbox2"), CAMEL_FOLDER_NOCHILDREN, -1, -1 },
};
static CamelFolderInfo fi_list_3[] = {
{ NULL, NULL, NULL, GC ("testbox"), GC ("testbox"), CAMEL_FOLDER_CHILDREN, -1, -1 },
{ NULL, NULL, NULL, GC ("testbox/foo"), GC ("foo"), CAMEL_FOLDER_NOCHILDREN, -1, -1 },
};
static gint
cmp_fi (gconstpointer a,
gconstpointer b)
{
const CamelFolderInfo *fa = ((const CamelFolderInfo **) a)[0];
const CamelFolderInfo *fb = ((const CamelFolderInfo **) b)[0];
return strcmp (fa->full_name, fb->full_name);
}
static void
add_fi (GPtrArray *folders,
CamelFolderInfo *fi)
{
while (fi) {
g_ptr_array_add (folders, fi);
if (fi->child)
add_fi (folders, fi->child);
fi = fi->next;
}
}
static void
check_fi (CamelFolderInfo *fi,
CamelFolderInfo *list,
gint len)
{
GPtrArray *folders = g_ptr_array_new ();
gint i;
add_fi (folders, fi);
check_msg (folders->len == len, "unexpected number of folders returned from folderinfo");
qsort (folders->pdata, folders->len, sizeof (folders->pdata[0]), cmp_fi);
for (i = 0; i < len; i++) {
CamelFolderInfo *f = folders->pdata[i];
camel_test_push ("checking folder '%s'", list[i].display_name);
check (!strcmp (f->full_name, list[i].full_name));
/* this might be translated, but we can't know */
camel_test_nonfatal ("Inbox not english");
check (!strcmp (f->display_name, list[i].display_name));
camel_test_fatal ();
camel_test_nonfatal ("Flags mismatch");
check (f->flags == list[i].flags);
camel_test_fatal ();
camel_test_pull ();
}
g_ptr_array_free (folders, TRUE);
}
gint
main (gint argc,
gchar **argv)
{
CamelFolder *f1, *f2;
CamelStore *store;
CamelService *service;
CamelFolderInfo *fi;
GError *error = NULL;
camel_test_init (argc, argv);
camel_test_provider_init (1, local_drivers);
/* clear out any camel-test data */
system ("/bin/rm -rf /tmp/camel-test");
session = camel_test_session_new ("/tmp/camel-test");
service = camel_session_add_service (
session, "test-uid",
"maildir:///tmp/camel-test/maildir",
CAMEL_PROVIDER_STORE, NULL);
store = CAMEL_STORE (service);
camel_test_start ("Maildir backward compatability tests");
camel_test_push ("./ prefix path, one level");
f1 = camel_store_get_folder_sync (
store, "testbox",
CAMEL_STORE_FOLDER_CREATE, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
f2 = camel_store_get_folder_sync (
store, "./testbox",
CAMEL_STORE_FOLDER_CREATE, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (f1 == f2);
check_unref (f2, 2);
check_unref (f1, 1);
camel_test_pull ();
camel_test_push ("./ prefix path, one level, no create");
f1 = camel_store_get_folder_sync (
store, "testbox2",
CAMEL_STORE_FOLDER_CREATE, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
f2 = camel_store_get_folder_sync (
store, "./testbox2", 0, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (f1 == f2);
check_unref (f2, 2);
check_unref (f1, 1);
camel_test_pull ();
camel_test_push ("./ prefix path, two levels");
f1 = camel_store_get_folder_sync (
store, "testbox/foo",
CAMEL_STORE_FOLDER_CREATE, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
f2 = camel_store_get_folder_sync (
store, "./testbox/foo",
CAMEL_STORE_FOLDER_CREATE, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (f1 == f2);
check_unref (f2, 2);
check_unref (f1, 1);
camel_test_pull ();
camel_test_push ("'.' == Inbox");
f2 = camel_store_get_inbox_folder_sync (store, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
f1 = camel_store_get_folder_sync (store, ".", 0, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (f1 == f2);
check_unref (f2, 2);
check_unref (f1, 1);
camel_test_pull ();
camel_test_push ("folder info, recursive");
fi = camel_store_get_folder_info_sync (
store, "",
CAMEL_STORE_FOLDER_INFO_RECURSIVE,
NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (fi != NULL);
check_fi (fi, fi_list_1, G_N_ELEMENTS (fi_list_1));
camel_test_pull ();
camel_test_push ("folder info, flat");
fi = camel_store_get_folder_info_sync (store, "", 0, NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (fi != NULL);
check_fi (fi, fi_list_2, G_N_ELEMENTS (fi_list_2));
camel_test_pull ();
camel_test_push ("folder info, recursive, non root");
fi = camel_store_get_folder_info_sync (
store, "testbox",
CAMEL_STORE_FOLDER_INFO_RECURSIVE,
NULL, &error);
check_msg (error == NULL, "%s", error->message);
g_clear_error (&error);
check (fi != NULL);
check_fi (fi, fi_list_3, G_N_ELEMENTS (fi_list_3));
camel_test_pull ();
check_unref (store, 1);
check_unref (session, 1);
camel_test_end ();
return 0;
}
|