2 test_description="API tests for notmuch_message_*"
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_message_t *message = NULL;
31 const char *id = "1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
33 stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
34 if (stat != NOTMUCH_STATUS_SUCCESS) {
35 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
38 EXPECT0(notmuch_database_find_message (db, id, &message));
39 EXPECT0(notmuch_database_close (db));
42 test_begin_subtest "Handle getting message-id from closed database"
43 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
46 id2=notmuch_message_get_message_id (message);
47 printf("%d\n%d\n", message != NULL, id2==NULL);
56 test_expect_equal_file EXPECTED OUTPUT
58 test_begin_subtest "Handle getting thread-id from closed database"
59 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
62 id2=notmuch_message_get_thread_id (message);
63 printf("%d\n%d\n", message != NULL, id2==NULL);
72 test_expect_equal_file EXPECTED OUTPUT
74 test_begin_subtest "Handle getting header from closed database"
75 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
78 from=notmuch_message_get_header (message, "from");
79 printf("%s\n%d\n", id, from == NULL);
84 1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
88 test_expect_equal_file EXPECTED OUTPUT
90 # XXX TODO: test on a message from notmuch_thread_get_toplevel_messages
91 # XXX this test only tests the trivial code path
92 test_begin_subtest "Handle getting replies from closed database"
93 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
95 notmuch_messages_t *replies;
96 replies = notmuch_message_get_replies (message);
97 printf("%d\n%d\n", message != NULL, replies==NULL);
106 test_expect_equal_file EXPECTED OUTPUT
108 test_begin_subtest "Handle getting message filename from closed database"
109 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
111 const char *filename;
112 filename = notmuch_message_get_filename (message);
113 printf("%d\n%d\n", message != NULL, filename == NULL);
122 test_expect_equal_file EXPECTED OUTPUT
124 test_begin_subtest "Handle getting all message filenames from closed database"
125 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
127 notmuch_filenames_t *filenames;
128 filenames = notmuch_message_get_filenames (message);
129 printf("%d\n%d\n", message != NULL, filenames == NULL);
138 test_expect_equal_file EXPECTED OUTPUT
140 test_begin_subtest "Handle getting ghost flag from closed database"
141 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
143 notmuch_bool_t result;
144 result = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST);
145 printf("%d\n%d\n", message != NULL, result == FALSE);
154 test_expect_equal_file EXPECTED OUTPUT
156 test_begin_subtest "Handle getting date from closed database"
157 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
160 result = notmuch_message_get_date (message);
161 printf("%d\n%d\n", message != NULL, result == 0);
170 test_expect_equal_file EXPECTED OUTPUT
172 test_begin_subtest "Handle getting tags from closed database"
173 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
175 notmuch_tags_t *result;
176 result = notmuch_message_get_tags (message);
177 printf("%d\n%d\n", message != NULL, result == NULL);
186 test_expect_equal_file EXPECTED OUTPUT
188 test_begin_subtest "Handle counting files from closed database"
189 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
192 result = notmuch_message_count_files (message);
193 printf("%d\n%d\n", message != NULL, result < 0);
202 test_expect_equal_file EXPECTED OUTPUT
204 test_begin_subtest "Handle adding tag with closed database"
205 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
207 notmuch_status_t status;
208 status = notmuch_message_add_tag (message, "boom");
209 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
218 test_expect_equal_file EXPECTED OUTPUT
220 test_begin_subtest "Handle removing tag with closed database"
221 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
223 notmuch_status_t status;
224 status = notmuch_message_remove_tag (message, "boom");
225 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
234 test_expect_equal_file EXPECTED OUTPUT
236 test_begin_subtest "Handle read maildir flag with closed database"
237 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
239 notmuch_bool_t is_set = -1;
240 is_set = notmuch_message_has_maildir_flag (message, 'S');
241 printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
250 test_expect_equal_file EXPECTED OUTPUT
252 test_begin_subtest "Handle checking maildir flag with closed db (new API)"
253 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
255 notmuch_status_t status;
257 status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
258 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
267 test_expect_equal_file EXPECTED OUTPUT
269 test_begin_subtest "Handle converting maildir flags to tags with closed db"
270 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
272 notmuch_status_t status;
273 status = notmuch_message_maildir_flags_to_tags (message);
274 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
283 test_expect_equal_file EXPECTED OUTPUT
285 test_begin_subtest "Handle removing all tags with closed db"
286 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
288 notmuch_status_t status;
289 status = notmuch_message_remove_all_tags (message);
290 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
299 test_expect_equal_file EXPECTED OUTPUT
301 test_begin_subtest "Handle freezing message with closed db"
302 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
304 notmuch_status_t status;
305 status = notmuch_message_freeze (message);
306 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS);
315 test_expect_equal_file EXPECTED OUTPUT
317 test_begin_subtest "Handle thawing message with closed db"
318 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
320 notmuch_status_t status;
321 status = notmuch_message_thaw (message);
322 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
331 test_expect_equal_file EXPECTED OUTPUT
333 test_begin_subtest "Handle destroying message with closed db"
334 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
336 notmuch_message_destroy (message);
337 printf("%d\n%d\n", message != NULL, 1);
346 test_expect_equal_file EXPECTED OUTPUT
348 test_begin_subtest "Handle retrieving closed db from message"
349 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
351 notmuch_database_t *db2;
352 db2 = notmuch_message_get_database (message);
353 printf("%d\n%d\n", message != NULL, db == db2);
362 test_expect_equal_file EXPECTED OUTPUT
364 test_begin_subtest "Handle reindexing message with closed db"
365 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
367 notmuch_status_t status;
368 status = notmuch_message_reindex (message, NULL);
369 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
378 test_expect_equal_file EXPECTED OUTPUT