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