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