]> git.notmuchmail.org Git - notmuch/blob - test/T566-lib-message.sh
test: add regression tests for n_thread_get_toplevel_messages
[notmuch] / test / T566-lib-message.sh
1 #!/usr/bin/env bash
2 test_description="API tests for notmuch_message_*"
3
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 add_email_corpus
7
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
10
11 cat <<'EOF' > c_tail
12    if (stat) {
13        const char *stat_str = notmuch_database_status_string (db);
14        if (stat_str)
15            fputs (stat_str, stderr);
16     }
17
18 }
19 EOF
20
21 cat <<EOF > c_head
22 #include <stdio.h>
23 #include <notmuch.h>
24 #include <notmuch-test.h>
25 int main (int argc, char** argv)
26 {
27    notmuch_database_t *db;
28    notmuch_status_t stat;
29    char *msg = NULL;
30    notmuch_message_t *message = NULL;
31    const char *id = "1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
32
33    stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
34    if (stat != NOTMUCH_STATUS_SUCCESS) {
35      fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
36      exit (1);
37    }
38    EXPECT0(notmuch_database_find_message (db, id, &message));
39    EXPECT0(notmuch_database_close (db));
40 EOF
41
42 test_begin_subtest "Handle getting message-id from closed database"
43 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
44     {
45         const char *id2;
46         id2=notmuch_message_get_message_id (message);
47         printf("%d\n%d\n", message != NULL, id2==NULL);
48     }
49 EOF
50 cat <<EOF > EXPECTED
51 == stdout ==
52 1
53 1
54 == stderr ==
55 EOF
56 test_expect_equal_file EXPECTED OUTPUT
57
58 test_begin_subtest "Handle getting thread-id from closed database"
59 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
60     {
61         const char *id2;
62         id2=notmuch_message_get_thread_id (message);
63         printf("%d\n%d\n", message != NULL, id2==NULL);
64     }
65 EOF
66 cat <<EOF > EXPECTED
67 == stdout ==
68 1
69 1
70 == stderr ==
71 EOF
72 test_expect_equal_file EXPECTED OUTPUT
73
74 test_begin_subtest "Handle getting header from closed database"
75 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
76     {
77         const char *from;
78         from=notmuch_message_get_header (message, "from");
79         printf("%s\n%d\n", id, from == NULL);
80     }
81 EOF
82 cat <<EOF > EXPECTED
83 == stdout ==
84 1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
85 1
86 == stderr ==
87 EOF
88 test_expect_equal_file EXPECTED OUTPUT
89
90 # XXX this test only tests the trivial code path
91 test_begin_subtest "Handle getting replies from closed database"
92 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
93     {
94         notmuch_messages_t *replies;
95         replies = notmuch_message_get_replies (message);
96         printf("%d\n%d\n", message != NULL, replies==NULL);
97     }
98 EOF
99 cat <<EOF > EXPECTED
100 == stdout ==
101 1
102 1
103 == stderr ==
104 EOF
105 test_expect_equal_file EXPECTED OUTPUT
106
107 test_begin_subtest "Handle getting message filename from closed database"
108 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
109     {
110         const char *filename;
111         filename = notmuch_message_get_filename (message);
112         printf("%d\n%d\n", message != NULL, filename == NULL);
113     }
114 EOF
115 cat <<EOF > EXPECTED
116 == stdout ==
117 1
118 1
119 == stderr ==
120 EOF
121 test_expect_equal_file EXPECTED OUTPUT
122
123 test_begin_subtest "Handle getting all message filenames from closed database"
124 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
125     {
126         notmuch_filenames_t *filenames;
127         filenames = notmuch_message_get_filenames (message);
128         printf("%d\n%d\n", message != NULL, filenames == NULL);
129     }
130 EOF
131 cat <<EOF > EXPECTED
132 == stdout ==
133 1
134 1
135 == stderr ==
136 EOF
137 test_expect_equal_file EXPECTED OUTPUT
138
139 test_begin_subtest "Handle getting ghost flag from closed database"
140 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
141     {
142         notmuch_bool_t result;
143         result = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST);
144         printf("%d\n%d\n", message != NULL, result == FALSE);
145     }
146 EOF
147 cat <<EOF > EXPECTED
148 == stdout ==
149 1
150 1
151 == stderr ==
152 EOF
153 test_expect_equal_file EXPECTED OUTPUT
154
155 test_begin_subtest "Handle getting date from closed database"
156 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
157     {
158         time_t result;
159         result = notmuch_message_get_date (message);
160         printf("%d\n%d\n", message != NULL, result == 0);
161     }
162 EOF
163 cat <<EOF > EXPECTED
164 == stdout ==
165 1
166 1
167 == stderr ==
168 EOF
169 test_expect_equal_file EXPECTED OUTPUT
170
171 test_begin_subtest "Handle getting tags from closed database"
172 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
173     {
174         notmuch_tags_t *result;
175         result = notmuch_message_get_tags (message);
176         printf("%d\n%d\n", message != NULL, result == NULL);
177     }
178 EOF
179 cat <<EOF > EXPECTED
180 == stdout ==
181 1
182 1
183 == stderr ==
184 EOF
185 test_expect_equal_file EXPECTED OUTPUT
186
187 test_begin_subtest "Handle counting files from closed database"
188 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
189     {
190         int result;
191         result = notmuch_message_count_files (message);
192         printf("%d\n%d\n", message != NULL, result < 0);
193     }
194 EOF
195 cat <<EOF > EXPECTED
196 == stdout ==
197 1
198 1
199 == stderr ==
200 EOF
201 test_expect_equal_file EXPECTED OUTPUT
202
203 test_begin_subtest "Handle adding tag with closed database"
204 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
205     {
206         notmuch_status_t status;
207         status = notmuch_message_add_tag (message, "boom");
208         printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
209     }
210 EOF
211 cat <<EOF > EXPECTED
212 == stdout ==
213 1
214 1
215 == stderr ==
216 EOF
217 test_expect_equal_file EXPECTED OUTPUT
218
219 test_begin_subtest "Handle removing tag with closed database"
220 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
221     {
222         notmuch_status_t status;
223         status = notmuch_message_remove_tag (message, "boom");
224         printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
225     }
226 EOF
227 cat <<EOF > EXPECTED
228 == stdout ==
229 1
230 1
231 == stderr ==
232 EOF
233 test_expect_equal_file EXPECTED OUTPUT
234
235 test_begin_subtest "Handle read maildir flag with closed database"
236 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
237     {
238         notmuch_bool_t is_set = -1;
239         is_set = notmuch_message_has_maildir_flag (message, 'S');
240         printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
241     }
242 EOF
243 cat <<EOF > EXPECTED
244 == stdout ==
245 1
246 1
247 == stderr ==
248 EOF
249 test_expect_equal_file EXPECTED OUTPUT
250
251 test_begin_subtest "Handle checking maildir flag with closed db (new API)"
252 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
253     {
254         notmuch_status_t status;
255         notmuch_bool_t out;
256         status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
257         printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
258     }
259 EOF
260 cat <<EOF > EXPECTED
261 == stdout ==
262 1
263 1
264 == stderr ==
265 EOF
266 test_expect_equal_file EXPECTED OUTPUT
267
268 test_begin_subtest "Handle converting maildir flags to tags with closed db"
269 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
270     {
271         notmuch_status_t status;
272         status = notmuch_message_maildir_flags_to_tags (message);
273         printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
274     }
275 EOF
276 cat <<EOF > EXPECTED
277 == stdout ==
278 1
279 1
280 == stderr ==
281 EOF
282 test_expect_equal_file EXPECTED OUTPUT
283
284 test_begin_subtest "Handle removing all tags with closed db"
285 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
286     {
287         notmuch_status_t status;
288         status = notmuch_message_remove_all_tags (message);
289         printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
290     }
291 EOF
292 cat <<EOF > EXPECTED
293 == stdout ==
294 1
295 1
296 == stderr ==
297 EOF
298 test_expect_equal_file EXPECTED OUTPUT
299
300 test_begin_subtest "Handle freezing message with closed db"
301 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
302     {
303         notmuch_status_t status;
304         status = notmuch_message_freeze (message);
305         printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_SUCCESS);
306     }
307 EOF
308 cat <<EOF > EXPECTED
309 == stdout ==
310 1
311 1
312 == stderr ==
313 EOF
314 test_expect_equal_file EXPECTED OUTPUT
315
316 test_begin_subtest "Handle thawing message with closed db"
317 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
318     {
319         notmuch_status_t status;
320         status = notmuch_message_thaw (message);
321         printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
322     }
323 EOF
324 cat <<EOF > EXPECTED
325 == stdout ==
326 1
327 1
328 == stderr ==
329 EOF
330 test_expect_equal_file EXPECTED OUTPUT
331
332 test_begin_subtest "Handle destroying message with closed db"
333 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
334     {
335         notmuch_message_destroy (message);
336         printf("%d\n%d\n", message != NULL,  1);
337     }
338 EOF
339 cat <<EOF > EXPECTED
340 == stdout ==
341 1
342 1
343 == stderr ==
344 EOF
345 test_expect_equal_file EXPECTED OUTPUT
346
347 test_begin_subtest "Handle retrieving closed db from message"
348 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
349     {
350         notmuch_database_t *db2;
351         db2 = notmuch_message_get_database (message);
352         printf("%d\n%d\n", message != NULL,  db == db2);
353     }
354 EOF
355 cat <<EOF > EXPECTED
356 == stdout ==
357 1
358 1
359 == stderr ==
360 EOF
361 test_expect_equal_file EXPECTED OUTPUT
362
363 test_begin_subtest "Handle reindexing message with closed db"
364 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
365     {
366         notmuch_status_t status;
367         status = notmuch_message_reindex (message, NULL);
368         printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
369     }
370 EOF
371 cat <<EOF > EXPECTED
372 == stdout ==
373 1
374 1
375 == stderr ==
376 EOF
377 test_expect_equal_file EXPECTED OUTPUT
378
379 test_done