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);
29 #include <notmuch-test.h>
30 int main (int argc, char** argv)
32 notmuch_database_t *db;
33 notmuch_status_t stat;
35 notmuch_thread_t *thread = NULL;
36 notmuch_threads_t *threads = NULL;
37 notmuch_query_t *query = NULL;
38 const char *id = "${THREAD}";
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 : "");
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));
52 test_begin_subtest "get thread-id from closed database"
53 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
56 id2 = notmuch_thread_get_thread_id (thread);
57 printf("%d\n%s\n", thread != NULL, id2);
60 thread_num=${THREAD#thread:}
67 test_expect_equal_file EXPECTED OUTPUT
69 test_begin_subtest "get total messages with closed database"
70 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
73 count = notmuch_thread_get_total_messages (thread);
74 printf("%d\n%d\n", thread != NULL, count);
83 test_expect_equal_file EXPECTED OUTPUT
85 test_begin_subtest "get total files with closed database"
86 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
89 count = notmuch_thread_get_total_files (thread);
90 printf("%d\n%d\n", thread != NULL, count);
99 test_expect_equal_file EXPECTED OUTPUT
101 test_begin_subtest "get top level messages with closed database"
102 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
104 notmuch_messages_t *messages;
105 messages = notmuch_thread_get_toplevel_messages (thread);
106 printf("%d\n%d\n", thread != NULL, messages != NULL);
115 test_expect_equal_file EXPECTED OUTPUT
117 test_begin_subtest "iterate over level messages with closed database"
118 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
132 20091117190054.GU3165@dottiness.seas.harvard.edu
135 test_expect_equal_file EXPECTED OUTPUT
137 test_begin_subtest "iterate over level messages with closed database"
138 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
152 20091117190054.GU3165@dottiness.seas.harvard.edu
155 test_expect_equal_file EXPECTED OUTPUT
157 test_begin_subtest "iterate over replies with closed database"
158 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
175 87iqd9rn3l.fsf@vertex.dottedmag
176 87ocn0qh6d.fsf@yoom.home.cworth.org
179 test_expect_equal_file EXPECTED OUTPUT
181 test_begin_subtest "iterate over all messages with closed database"
182 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
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
205 test_expect_equal_file EXPECTED OUTPUT
207 test_begin_subtest "get authors from closed database"
208 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
211 authors = notmuch_thread_get_authors (thread);
212 printf("%d\n%s\n", thread != NULL, authors);
218 Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth
221 test_expect_equal_file EXPECTED OUTPUT
223 test_begin_subtest "get subject from closed database"
224 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
227 subject = notmuch_thread_get_subject (thread);
228 printf("%d\n%s\n", thread != NULL, subject);
234 [notmuch] Working with Maildir storage?
237 test_expect_equal_file EXPECTED OUTPUT
239 test_begin_subtest "oldest date from closed database"
240 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
243 stamp = notmuch_thread_get_oldest_date (thread);
244 printf("%d\n%d\n", thread != NULL, stamp > 0);
253 test_expect_equal_file EXPECTED OUTPUT
255 test_begin_subtest "newest date from closed database"
256 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
259 stamp = notmuch_thread_get_newest_date (thread);
260 printf("%d\n%d\n", thread != NULL, stamp > 0);
269 test_expect_equal_file EXPECTED OUTPUT
271 test_begin_subtest "iterate tags from closed database"
272 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
274 notmuch_tags_t *tags;
276 for (tags = notmuch_thread_get_tags (thread);
277 notmuch_tags_valid (tags);
278 notmuch_tags_move_to_next (tags))
280 tag = notmuch_tags_get (tags);
281 printf ("%s\n", tag);
292 test_expect_equal_file EXPECTED OUTPUT
294 test_begin_subtest "collect tags with closed database"
295 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
297 notmuch_messages_t *messages = notmuch_thread_get_messages (thread);
299 notmuch_tags_t *tags = notmuch_messages_collect_tags (messages);
302 for (tags = notmuch_thread_get_tags (thread);
303 notmuch_tags_valid (tags);
304 notmuch_tags_move_to_next (tags))
306 tag = notmuch_tags_get (tags);
307 printf ("%s\n", tag);
309 notmuch_tags_destroy (tags);
310 notmuch_messages_destroy (messages);
323 test_expect_equal_file EXPECTED OUTPUT
325 test_begin_subtest "destroy thread with closed database"
326 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
329 notmuch_thread_destroy (thread);
338 test_expect_equal_file EXPECTED OUTPUT