2 test_description="API tests for notmuch_thread_*"
4 . $(dirname "$0")/test-lib.sh || exit 1
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
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"
18 const char *stat_str = notmuch_database_status_string (db);
20 fputs (stat_str, stderr);
27 #include <notmuch-test.h>
29 int main (int argc, char** argv)
31 notmuch_database_t *db;
32 notmuch_status_t stat;
34 notmuch_thread_t *thread = NULL;
35 notmuch_threads_t *threads = NULL;
36 notmuch_query_t *query = NULL;
37 const char *id = "${THREAD}";
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 : "");
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));
53 test_begin_subtest "get thread-id from closed database"
54 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
57 id2 = notmuch_thread_get_thread_id (thread);
58 printf("%d\n%s\n", thread != NULL, id2);
61 thread_num=${THREAD#thread:}
68 test_expect_equal_file EXPECTED OUTPUT
70 test_begin_subtest "get total messages with closed database"
71 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
74 count = notmuch_thread_get_total_messages (thread);
75 printf("%d\n%d\n", thread != NULL, count);
84 test_expect_equal_file EXPECTED OUTPUT
86 test_begin_subtest "get total files with closed database"
87 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
90 count = notmuch_thread_get_total_files (thread);
91 printf("%d\n%d\n", thread != NULL, count);
100 test_expect_equal_file EXPECTED OUTPUT
102 test_begin_subtest "get top level messages with closed database"
103 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
105 notmuch_messages_t *messages;
106 messages = notmuch_thread_get_toplevel_messages (thread);
107 printf("%d\n%d\n", thread != NULL, messages != NULL);
116 test_expect_equal_file EXPECTED OUTPUT
118 test_begin_subtest "iterate over level messages with closed database"
119 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
133 20091117190054.GU3165@dottiness.seas.harvard.edu
136 test_expect_equal_file EXPECTED OUTPUT
138 test_begin_subtest "iterate over level messages with closed database"
139 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
153 20091117190054.GU3165@dottiness.seas.harvard.edu
156 test_expect_equal_file EXPECTED OUTPUT
158 test_begin_subtest "iterate over replies with closed database"
159 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
176 87iqd9rn3l.fsf@vertex.dottedmag
177 87ocn0qh6d.fsf@yoom.home.cworth.org
180 test_expect_equal_file EXPECTED OUTPUT
182 test_begin_subtest "iterate over all messages with closed database"
183 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
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
206 test_expect_equal_file EXPECTED OUTPUT
208 test_begin_subtest "get authors from closed database"
209 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
212 authors = notmuch_thread_get_authors (thread);
213 printf("%d\n%s\n", thread != NULL, authors);
219 Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth
222 test_expect_equal_file EXPECTED OUTPUT
224 test_begin_subtest "get subject from closed database"
225 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
228 subject = notmuch_thread_get_subject (thread);
229 printf("%d\n%s\n", thread != NULL, subject);
235 [notmuch] Working with Maildir storage?
238 test_expect_equal_file EXPECTED OUTPUT
240 test_begin_subtest "oldest date from closed database"
241 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
244 stamp = notmuch_thread_get_oldest_date (thread);
245 printf("%d\n%d\n", thread != NULL, stamp > 0);
254 test_expect_equal_file EXPECTED OUTPUT
256 test_begin_subtest "newest date from closed database"
257 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
260 stamp = notmuch_thread_get_newest_date (thread);
261 printf("%d\n%d\n", thread != NULL, stamp > 0);
270 test_expect_equal_file EXPECTED OUTPUT
272 test_begin_subtest "iterate tags from closed database"
273 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
275 notmuch_tags_t *tags;
277 for (tags = notmuch_thread_get_tags (thread);
278 notmuch_tags_valid (tags);
279 notmuch_tags_move_to_next (tags))
281 tag = notmuch_tags_get (tags);
282 printf ("%s\n", tag);
293 test_expect_equal_file EXPECTED OUTPUT
295 test_begin_subtest "collect tags with closed database"
296 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
298 notmuch_messages_t *messages = notmuch_thread_get_messages (thread);
300 notmuch_tags_t *tags = notmuch_messages_collect_tags (messages);
303 for (tags = notmuch_thread_get_tags (thread);
304 notmuch_tags_valid (tags);
305 notmuch_tags_move_to_next (tags))
307 tag = notmuch_tags_get (tags);
308 printf ("%s\n", tag);
310 notmuch_tags_destroy (tags);
311 notmuch_messages_destroy (messages);
324 test_expect_equal_file EXPECTED OUTPUT
326 test_begin_subtest "destroy thread with closed database"
327 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
330 notmuch_thread_destroy (thread);
339 test_expect_equal_file EXPECTED OUTPUT