]> git.notmuchmail.org Git - notmuch/blob - test/T568-lib-thread.sh
python: convert shebangs to python3
[notmuch] / test / T568-lib-thread.sh
1 #!/usr/bin/env bash
2 test_description="API tests for notmuch_thread_*"
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_thread_t *thread = NULL;
31    notmuch_threads_t *threads = NULL;
32    notmuch_query_t *query = NULL;
33    const char *id = "thread:0000000000000009";
34
35    stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
36    if (stat != NOTMUCH_STATUS_SUCCESS) {
37      fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
38      exit (1);
39    }
40
41    query = notmuch_query_create (db, id);
42    EXPECT0(notmuch_query_search_threads (query, &threads));
43    thread = notmuch_threads_get (threads);
44    EXPECT0(notmuch_database_close (db));
45 EOF
46
47 test_begin_subtest "get thread-id from closed database"
48 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
49     {
50         const char *id2;
51         id2 = notmuch_thread_get_thread_id (thread);
52         printf("%d\n%s\n", thread != NULL, id2);
53     }
54 EOF
55 cat <<EOF > EXPECTED
56 == stdout ==
57 1
58 0000000000000009
59 == stderr ==
60 EOF
61 test_expect_equal_file EXPECTED OUTPUT
62
63 test_begin_subtest "get total messages with closed database"
64 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
65     {
66         int count;
67         count = notmuch_thread_get_total_messages (thread);
68         printf("%d\n%d\n", thread != NULL, count);
69     }
70 EOF
71 cat <<EOF > EXPECTED
72 == stdout ==
73 1
74 7
75 == stderr ==
76 EOF
77 test_expect_equal_file EXPECTED OUTPUT
78
79 test_begin_subtest "get total files with closed database"
80 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
81     {
82         int count;
83         count = notmuch_thread_get_total_files (thread);
84         printf("%d\n%d\n", thread != NULL, count);
85     }
86 EOF
87 cat <<EOF > EXPECTED
88 == stdout ==
89 1
90 7
91 == stderr ==
92 EOF
93 test_expect_equal_file EXPECTED OUTPUT
94
95 test_begin_subtest "get top level messages with closed database"
96 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
97     {
98         notmuch_messages_t *messages;
99         messages = notmuch_thread_get_toplevel_messages (thread);
100         printf("%d\n%d\n", thread != NULL, messages != NULL);
101     }
102 EOF
103 cat <<EOF > EXPECTED
104 == stdout ==
105 1
106 1
107 == stderr ==
108 EOF
109 test_expect_equal_file EXPECTED OUTPUT
110
111 test_begin_subtest "iterate over level messages with closed database"
112 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
113     {
114       notmuch_messages_t *messages;
115       for (messages = notmuch_thread_get_toplevel_messages (thread);
116            notmuch_messages_valid (messages);
117            notmuch_messages_move_to_next (messages)) {
118         notmuch_message_t *message = notmuch_messages_get (messages);
119         const char *mid = notmuch_message_get_message_id (message);
120         printf("%s\n", mid);
121       }
122     }
123 EOF
124 cat <<EOF > EXPECTED
125 == stdout ==
126 20091117190054.GU3165@dottiness.seas.harvard.edu
127 == stderr ==
128 EOF
129 test_expect_equal_file EXPECTED OUTPUT
130
131 test_begin_subtest "iterate over level messages with closed database"
132 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
133     {
134       notmuch_messages_t *messages;
135       for (messages = notmuch_thread_get_toplevel_messages (thread);
136            notmuch_messages_valid (messages);
137            notmuch_messages_move_to_next (messages)) {
138         notmuch_message_t *message = notmuch_messages_get (messages);
139         const char *mid = notmuch_message_get_message_id (message);
140         printf("%s\n", mid);
141       }
142     }
143 EOF
144 cat <<EOF > EXPECTED
145 == stdout ==
146 20091117190054.GU3165@dottiness.seas.harvard.edu
147 == stderr ==
148 EOF
149 test_expect_equal_file EXPECTED OUTPUT
150
151 test_begin_subtest "iterate over replies with closed database"
152 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
153     {
154       notmuch_messages_t *messages = notmuch_thread_get_toplevel_messages (thread);
155       notmuch_message_t *message = notmuch_messages_get (messages);
156       notmuch_messages_t *replies;
157       for (replies = notmuch_message_get_replies (message);
158            notmuch_messages_valid (replies);
159            notmuch_messages_move_to_next (replies)) {
160         notmuch_message_t *message = notmuch_messages_get (replies);
161         const char *mid = notmuch_message_get_message_id (message);
162
163         printf("%s\n", mid);
164       }
165     }
166 EOF
167 cat <<EOF > EXPECTED
168 == stdout ==
169 87iqd9rn3l.fsf@vertex.dottedmag
170 87ocn0qh6d.fsf@yoom.home.cworth.org
171 == stderr ==
172 EOF
173 test_expect_equal_file EXPECTED OUTPUT
174
175 test_begin_subtest "iterate over all messages with closed database"
176 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
177     {
178       notmuch_messages_t *messages;
179       for (messages = notmuch_thread_get_messages (thread);
180            notmuch_messages_valid (messages);
181            notmuch_messages_move_to_next (messages)) {
182         notmuch_message_t *message = notmuch_messages_get (messages);
183         const char *mid = notmuch_message_get_message_id (message);
184         printf("%s\n", mid);
185       }
186     }
187 EOF
188 cat <<EOF > EXPECTED
189 == stdout ==
190 20091117190054.GU3165@dottiness.seas.harvard.edu
191 87iqd9rn3l.fsf@vertex.dottedmag
192 20091117203301.GV3165@dottiness.seas.harvard.edu
193 87fx8can9z.fsf@vertex.dottedmag
194 yunaayketfm.fsf@aiko.keithp.com
195 20091118005040.GA25380@dottiness.seas.harvard.edu
196 87ocn0qh6d.fsf@yoom.home.cworth.org
197 == stderr ==
198 EOF
199 test_expect_equal_file EXPECTED OUTPUT
200
201 test_begin_subtest "get authors from closed database"
202 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
203     {
204         const char *authors;
205         authors = notmuch_thread_get_authors (thread);
206         printf("%d\n%s\n", thread != NULL, authors);
207     }
208 EOF
209 cat <<EOF > EXPECTED
210 == stdout ==
211 1
212 Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth
213 == stderr ==
214 EOF
215 test_expect_equal_file EXPECTED OUTPUT
216
217 test_begin_subtest "get subject from closed database"
218 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
219     {
220         const char *subject;
221         subject = notmuch_thread_get_subject (thread);
222         printf("%d\n%s\n", thread != NULL, subject);
223     }
224 EOF
225 cat <<EOF > EXPECTED
226 == stdout ==
227 1
228 [notmuch] Working with Maildir storage?
229 == stderr ==
230 EOF
231 test_expect_equal_file EXPECTED OUTPUT
232
233 test_begin_subtest "oldest date from closed database"
234 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
235     {
236         time_t stamp;
237         stamp = notmuch_thread_get_oldest_date (thread);
238         printf("%d\n%d\n", thread != NULL, stamp > 0);
239     }
240 EOF
241 cat <<EOF > EXPECTED
242 == stdout ==
243 1
244 1
245 == stderr ==
246 EOF
247 test_expect_equal_file EXPECTED OUTPUT
248
249 test_begin_subtest "newest date from closed database"
250 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
251     {
252         time_t stamp;
253         stamp = notmuch_thread_get_newest_date (thread);
254         printf("%d\n%d\n", thread != NULL, stamp > 0);
255     }
256 EOF
257 cat <<EOF > EXPECTED
258 == stdout ==
259 1
260 1
261 == stderr ==
262 EOF
263 test_expect_equal_file EXPECTED OUTPUT
264
265 test_begin_subtest "iterate tags from closed database"
266 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
267     {
268       notmuch_tags_t *tags;
269       const char *tag;
270       for (tags = notmuch_thread_get_tags (thread);
271            notmuch_tags_valid (tags);
272            notmuch_tags_move_to_next (tags))
273         {
274           tag = notmuch_tags_get (tags);
275           printf ("%s\n", tag);
276         }
277     }
278 EOF
279 cat <<EOF > EXPECTED
280 == stdout ==
281 inbox
282 signed
283 unread
284 == stderr ==
285 EOF
286 test_expect_equal_file EXPECTED OUTPUT
287
288 test_begin_subtest "collect tags with closed database"
289 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
290     {
291       notmuch_messages_t *messages = notmuch_thread_get_messages (thread);
292
293       notmuch_tags_t *tags = notmuch_messages_collect_tags (messages);
294
295       const char *tag;
296       for (tags = notmuch_thread_get_tags (thread);
297            notmuch_tags_valid (tags);
298            notmuch_tags_move_to_next (tags))
299         {
300           tag = notmuch_tags_get (tags);
301           printf ("%s\n", tag);
302         }
303       notmuch_tags_destroy (tags);
304       notmuch_messages_destroy (messages);
305
306       printf("SUCCESS\n");
307     }
308 EOF
309 cat <<EOF > EXPECTED
310 == stdout ==
311 inbox
312 signed
313 unread
314 SUCCESS
315 == stderr ==
316 EOF
317 test_expect_equal_file EXPECTED OUTPUT
318
319 test_begin_subtest "destroy thread with closed database"
320 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
321     {
322         time_t stamp;
323         notmuch_thread_destroy (thread);
324         printf("SUCCESS\n");
325     }
326 EOF
327 cat <<EOF > EXPECTED
328 == stdout ==
329 SUCCESS
330 == stderr ==
331 EOF
332 test_expect_equal_file EXPECTED OUTPUT
333
334 test_done