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