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_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 : "");
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));
51 test_begin_subtest "get thread-id from closed database"
52 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
55 id2 = notmuch_thread_get_thread_id (thread);
56 printf("%d\n%s\n", thread != NULL, id2);
59 thread_num=${THREAD#thread:}
66 test_expect_equal_file EXPECTED OUTPUT
68 test_begin_subtest "get total messages with closed database"
69 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
72 count = notmuch_thread_get_total_messages (thread);
73 printf("%d\n%d\n", thread != NULL, count);
82 test_expect_equal_file EXPECTED OUTPUT
84 test_begin_subtest "get total files with closed database"
85 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
88 count = notmuch_thread_get_total_files (thread);
89 printf("%d\n%d\n", thread != NULL, count);
98 test_expect_equal_file EXPECTED OUTPUT
100 test_begin_subtest "get top level messages with closed database"
101 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
103 notmuch_messages_t *messages;
104 messages = notmuch_thread_get_toplevel_messages (thread);
105 printf("%d\n%d\n", thread != NULL, messages != NULL);
114 test_expect_equal_file EXPECTED OUTPUT
116 test_begin_subtest "iterate over level messages with closed database"
117 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
131 20091117190054.GU3165@dottiness.seas.harvard.edu
134 test_expect_equal_file EXPECTED OUTPUT
136 test_begin_subtest "iterate over level messages with closed database"
137 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
151 20091117190054.GU3165@dottiness.seas.harvard.edu
154 test_expect_equal_file EXPECTED OUTPUT
156 test_begin_subtest "iterate over replies with closed database"
157 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
174 87iqd9rn3l.fsf@vertex.dottedmag
175 87ocn0qh6d.fsf@yoom.home.cworth.org
178 test_expect_equal_file EXPECTED OUTPUT
180 test_begin_subtest "iterate over all messages with closed database"
181 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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);
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
204 test_expect_equal_file EXPECTED OUTPUT
206 test_begin_subtest "get authors from closed database"
207 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
210 authors = notmuch_thread_get_authors (thread);
211 printf("%d\n%s\n", thread != NULL, authors);
217 Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth
220 test_expect_equal_file EXPECTED OUTPUT
222 test_begin_subtest "get subject from closed database"
223 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
226 subject = notmuch_thread_get_subject (thread);
227 printf("%d\n%s\n", thread != NULL, subject);
233 [notmuch] Working with Maildir storage?
236 test_expect_equal_file EXPECTED OUTPUT
238 test_begin_subtest "oldest date from closed database"
239 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
242 stamp = notmuch_thread_get_oldest_date (thread);
243 printf("%d\n%d\n", thread != NULL, stamp > 0);
252 test_expect_equal_file EXPECTED OUTPUT
254 test_begin_subtest "newest date from closed database"
255 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
258 stamp = notmuch_thread_get_newest_date (thread);
259 printf("%d\n%d\n", thread != NULL, stamp > 0);
268 test_expect_equal_file EXPECTED OUTPUT
270 test_begin_subtest "iterate tags from closed database"
271 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
273 notmuch_tags_t *tags;
275 for (tags = notmuch_thread_get_tags (thread);
276 notmuch_tags_valid (tags);
277 notmuch_tags_move_to_next (tags))
279 tag = notmuch_tags_get (tags);
280 printf ("%s\n", tag);
291 test_expect_equal_file EXPECTED OUTPUT
293 test_begin_subtest "collect tags with closed database"
294 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
296 notmuch_messages_t *messages = notmuch_thread_get_messages (thread);
298 notmuch_tags_t *tags = notmuch_messages_collect_tags (messages);
301 for (tags = notmuch_thread_get_tags (thread);
302 notmuch_tags_valid (tags);
303 notmuch_tags_move_to_next (tags))
305 tag = notmuch_tags_get (tags);
306 printf ("%s\n", tag);
308 notmuch_tags_destroy (tags);
309 notmuch_messages_destroy (messages);
322 test_expect_equal_file EXPECTED OUTPUT
324 test_begin_subtest "destroy thread with closed database"
325 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
328 notmuch_thread_destroy (thread);
337 test_expect_equal_file EXPECTED OUTPUT