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
|
/* store testing */
#include "camel-test.h"
#include <camel/camel-exception.h>
#include <camel/camel-service.h>
#include <camel/camel-session.h>
#include <camel/camel-store.h>
/* god, who designed this horrid interface */
static char *auth_callback(CamelAuthCallbackMode mode,
char *data, gboolean secret,
CamelService *service, char *item,
CamelException *ex)
{
return NULL;
}
#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0]))
static char *local_providers[] = {
"mbox",
"mh",
"maildir"
};
int main(int argc, char **argv)
{
CamelSession *session;
CamelStore *store;
CamelException *ex;
CamelFolder *folder, *root;
int i;
char *path;
camel_test_init(argc, argv);
ex = camel_exception_new();
/* clear out any camel-test data */
system("/bin/rm -rf /tmp/camel-test");
session = camel_session_new("/tmp/camel-test", auth_callback, NULL, NULL);
/* todo: cross-check everything with folder_info checks as well */
/* todo: subscriptions? */
/* todo: work out how to do imap/pop/nntp tests */
for (i=0;i<ARRAY_LEN(local_providers);i++) {
char *what = g_strdup_printf("testing local store: %s", local_providers[i]);
camel_test_start(what);
g_free(what);
push("getting store");
path = g_strdup_printf("%s:///tmp/camel-test/%s", local_providers[i], local_providers[i]);
store = camel_session_get_store(session, path, ex);
check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex));
check(store != NULL);
pull();
/* local providers == no root folder */
push("getting root folder");
root = camel_store_get_root_folder(store, ex);
check(camel_exception_is_set(ex));
check(root == NULL);
camel_exception_clear(ex);
pull();
/* same for default folder */
push("getting default folder");
root = camel_store_get_root_folder(store, ex);
check(camel_exception_is_set(ex));
check(root == NULL);
camel_exception_clear(ex);
pull();
push("getting a non-existant folder, no create");
folder = camel_store_get_folder(store, "unknown", 0, ex);
check(camel_exception_is_set(ex));
check(folder == NULL);
camel_exception_clear(ex);
pull();
push("getting a non-existant folder, with create");
folder = camel_store_get_folder(store, "testbox", CAMEL_STORE_FOLDER_CREATE, ex);
check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
check(folder != NULL);
camel_object_unref((CamelObject *)folder);
pull();
push("getting an existing folder");
folder = camel_store_get_folder(store, "testbox", 0, ex);
check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
check(folder != NULL);
camel_object_unref((CamelObject *)folder);
pull();
push("renaming a non-existant folder");
camel_store_rename_folder(store, "unknown1", "unknown2", ex);
check(camel_exception_is_set(ex));
camel_exception_clear(ex);
pull();
push("renaming an existing folder");
camel_store_rename_folder(store, "testbox", "testbox2", ex);
check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
pull();
push("opening the old name of a renamed folder");
folder = camel_store_get_folder(store, "testbox", 0, ex);
check(camel_exception_is_set(ex));
check(folder == NULL);
camel_exception_clear(ex);
pull();
push("opening the new name of a renamed folder");
folder = camel_store_get_folder(store, "testbox2", 0, ex);
check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
check(folder != NULL);
camel_object_unref((CamelObject *)folder);
pull();
push("deleting a non-existant folder");
camel_store_delete_folder(store, "unknown", ex);
check(camel_exception_is_set(ex));
camel_exception_clear(ex);
pull();
push("deleting an existing folder");
camel_store_delete_folder(store, "testbox2", ex);
check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
pull();
push("opening a folder that has been deleted");
folder = camel_store_get_folder(store, "testbox2", 0, ex);
check(camel_exception_is_set(ex));
check(folder == NULL);
camel_exception_clear(ex);
pull();
camel_object_unref((CamelObject *)store);
g_free(path);
camel_test_end();
}
camel_object_unref((CamelObject *)session);
camel_exception_free(ex);
return 0;
}
|