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"
13 const char *stat_str = notmuch_database_status_string (db);
15 fputs (stat_str, stderr);
24 #include <notmuch-test.h>
25 int main (int argc, char** argv)
27 notmuch_database_t *db;
28 notmuch_status_t stat;
30 notmuch_thread_t *thread = NULL;
31 notmuch_threads_t *threads = NULL;
32 notmuch_query_t *query = NULL;
33 const char *id = "thread:0000000000000009";
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 : "");
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));
47 test_begin_subtest "get thread-id from closed database"
48 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
51 id2 = notmuch_thread_get_thread_id (thread);
52 printf("%d\n%s\n", thread != NULL, id2);
61 test_expect_equal_file EXPECTED OUTPUT
63 test_begin_subtest "get total messages with closed database"
64 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
67 count = notmuch_thread_get_total_messages (thread);
68 printf("%d\n%d\n", thread != NULL, count);
77 test_expect_equal_file EXPECTED OUTPUT
79 test_begin_subtest "get total files with closed database"
80 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
83 count = notmuch_thread_get_total_files (thread);
84 printf("%d\n%d\n", thread != NULL, count);
93 test_expect_equal_file EXPECTED OUTPUT
95 test_begin_subtest "get top level messages with closed database"
96 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
98 notmuch_messages_t *messages;
99 messages = notmuch_thread_get_toplevel_messages (thread);
100 printf("%d\n%d\n", thread != NULL, messages != NULL);
109 test_expect_equal_file EXPECTED OUTPUT
111 test_begin_subtest "iterate over level messages with closed database"
112 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
126 20091117190054.GU3165@dottiness.seas.harvard.edu
129 test_expect_equal_file EXPECTED OUTPUT
131 test_begin_subtest "iterate over level messages with closed database"
132 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
146 20091117190054.GU3165@dottiness.seas.harvard.edu
149 test_expect_equal_file EXPECTED OUTPUT
151 test_begin_subtest "iterate over replies with closed database"
152 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
169 87iqd9rn3l.fsf@vertex.dottedmag
170 87ocn0qh6d.fsf@yoom.home.cworth.org
173 test_expect_equal_file EXPECTED OUTPUT
175 test_begin_subtest "iterate over all messages with closed database"
176 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
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
199 test_expect_equal_file EXPECTED OUTPUT
201 test_begin_subtest "get authors from closed database"
202 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
205 authors = notmuch_thread_get_authors (thread);
206 printf("%d\n%s\n", thread != NULL, authors);
212 Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth
215 test_expect_equal_file EXPECTED OUTPUT
217 test_begin_subtest "get subject from closed database"
218 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
221 subject = notmuch_thread_get_subject (thread);
222 printf("%d\n%s\n", thread != NULL, subject);
228 [notmuch] Working with Maildir storage?
231 test_expect_equal_file EXPECTED OUTPUT
233 test_begin_subtest "oldest date from closed database"
234 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
237 stamp = notmuch_thread_get_oldest_date (thread);
238 printf("%d\n%d\n", thread != NULL, stamp > 0);
247 test_expect_equal_file EXPECTED OUTPUT
249 test_begin_subtest "newest date from closed database"
250 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
253 stamp = notmuch_thread_get_newest_date (thread);
254 printf("%d\n%d\n", thread != NULL, stamp > 0);
263 test_expect_equal_file EXPECTED OUTPUT
265 test_begin_subtest "iterate tags from closed database"
266 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
268 notmuch_tags_t *tags;
270 for (tags = notmuch_thread_get_tags (thread);
271 notmuch_tags_valid (tags);
272 notmuch_tags_move_to_next (tags))
274 tag = notmuch_tags_get (tags);
275 printf ("%s\n", tag);
286 test_expect_equal_file EXPECTED OUTPUT
288 test_begin_subtest "destroy thread with closed database"
289 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
292 notmuch_thread_destroy (thread);
301 test_expect_equal_file EXPECTED OUTPUT