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