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);
22 #include <notmuch-test.h>
24 int main (int argc, char** argv)
26 notmuch_database_t *db;
27 notmuch_status_t stat;
29 notmuch_message_t *message = NULL;
30 const char *id = "1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
32 stat = notmuch_database_open_with_config (argv[1],
33 NOTMUCH_DATABASE_MODE_READ_WRITE,
34 NULL, NULL, &db, &msg);
35 if (stat != NOTMUCH_STATUS_SUCCESS) {
36 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
39 EXPECT0(notmuch_database_find_message (db, id, &message));
43 echo " EXPECT0(notmuch_database_close (db));" >> c_head
45 test_begin_subtest "Handle getting message-id from closed database"
46 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
49 id2=notmuch_message_get_message_id (message);
50 printf("%d\n%d\n", message != NULL, id2==NULL);
59 test_expect_equal_file EXPECTED OUTPUT
61 test_begin_subtest "Handle getting thread-id from closed database"
62 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
65 id2=notmuch_message_get_thread_id (message);
66 printf("%d\n%d\n", message != NULL, id2==NULL);
75 test_expect_equal_file EXPECTED OUTPUT
77 test_begin_subtest "Handle getting header from closed database"
78 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
81 from=notmuch_message_get_header (message, "from");
82 printf("%s\n%d\n", id, from == NULL);
87 1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
91 test_expect_equal_file EXPECTED OUTPUT
93 # XXX this test only tests the trivial code path
94 test_begin_subtest "Handle getting replies from closed database"
95 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
97 notmuch_messages_t *replies;
98 replies = notmuch_message_get_replies (message);
99 printf("%d\n%d\n", message != NULL, replies==NULL);
108 test_expect_equal_file EXPECTED OUTPUT
110 test_begin_subtest "Handle getting message filename from closed database"
111 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
113 const char *filename;
114 filename = notmuch_message_get_filename (message);
115 printf("%d\n%d\n", message != NULL, filename == NULL);
124 test_expect_equal_file EXPECTED OUTPUT
126 test_begin_subtest "Handle getting all message filenames from closed database"
127 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
129 notmuch_filenames_t *filenames;
130 filenames = notmuch_message_get_filenames (message);
131 printf("%d\n%d\n", message != NULL, filenames == NULL);
140 test_expect_equal_file EXPECTED OUTPUT
142 test_begin_subtest "iterate over all message filenames from closed database"
143 cat c_head0 - c_tail <<'EOF' | test_C ${MAIL_DIR}
145 notmuch_filenames_t *filenames;
146 filenames = notmuch_message_get_filenames (message);
147 EXPECT0(notmuch_database_close (db));
148 for (; notmuch_filenames_valid (filenames);
149 notmuch_filenames_move_to_next (filenames)) {
150 const char *filename = notmuch_filenames_get (filenames);
151 printf("%s\n", filename);
153 notmuch_filenames_destroy (filenames);
163 test_expect_equal_file EXPECTED OUTPUT
165 test_begin_subtest "Handle getting ghost flag from closed database"
166 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
168 notmuch_bool_t result;
169 result = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST);
170 printf("%d\n%d\n", message != NULL, result == FALSE);
179 test_expect_equal_file EXPECTED OUTPUT
181 test_begin_subtest "Handle getting date from closed database"
182 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
185 result = notmuch_message_get_date (message);
186 printf("%d\n%d\n", message != NULL, result == 0);
195 test_expect_equal_file EXPECTED OUTPUT
197 test_begin_subtest "Handle getting tags from closed database"
198 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
200 notmuch_tags_t *result;
201 result = notmuch_message_get_tags (message);
202 printf("%d\n%d\n", message != NULL, result == NULL);
211 test_expect_equal_file EXPECTED OUTPUT
213 test_begin_subtest "Handle counting files from closed database"
214 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
217 result = notmuch_message_count_files (message);
218 printf("%d\n%d\n", message != NULL, result < 0);
227 test_expect_equal_file EXPECTED OUTPUT
229 test_begin_subtest "Handle adding tag with closed database"
230 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
232 notmuch_status_t status;
233 status = notmuch_message_add_tag (message, "boom");
234 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
243 test_expect_equal_file EXPECTED OUTPUT
245 test_begin_subtest "Handle removing tag with closed database"
246 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
248 notmuch_status_t status;
249 status = notmuch_message_remove_tag (message, "boom");
250 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
259 test_expect_equal_file EXPECTED OUTPUT
261 test_begin_subtest "Handle read maildir flag with closed database"
262 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
264 notmuch_bool_t is_set = -1;
265 is_set = notmuch_message_has_maildir_flag (message, 'S');
266 printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
275 test_expect_equal_file EXPECTED OUTPUT
277 test_begin_subtest "Handle checking maildir flag with closed db (new API)"
278 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
280 notmuch_status_t status;
282 status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
283 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
292 test_expect_equal_file EXPECTED OUTPUT
294 test_begin_subtest "Handle converting maildir flags to tags with closed db"
295 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
297 notmuch_status_t status;
298 status = notmuch_message_maildir_flags_to_tags (message);
299 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
308 test_expect_equal_file EXPECTED OUTPUT
310 test_begin_subtest "Handle removing all tags with closed db"
311 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
313 notmuch_status_t status;
314 status = notmuch_message_remove_all_tags (message);
315 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
324 test_expect_equal_file EXPECTED OUTPUT
326 test_begin_subtest "Handle freezing message with closed db"
327 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
329 notmuch_status_t status;
330 status = notmuch_message_freeze (message);
331 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS);
340 test_expect_equal_file EXPECTED OUTPUT
342 test_begin_subtest "Handle thawing message with closed db"
343 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
345 notmuch_status_t status;
346 status = notmuch_message_thaw (message);
347 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
356 test_expect_equal_file EXPECTED OUTPUT
358 test_begin_subtest "Handle destroying message with closed db"
359 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
361 notmuch_message_destroy (message);
362 printf("%d\n%d\n", message != NULL, 1);
371 test_expect_equal_file EXPECTED OUTPUT
373 test_begin_subtest "Handle retrieving closed db from message"
374 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
376 notmuch_database_t *db2;
377 db2 = notmuch_message_get_database (message);
378 printf("%d\n%d\n", message != NULL, db == db2);
387 test_expect_equal_file EXPECTED OUTPUT
389 test_begin_subtest "Handle reindexing message with closed db"
390 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
392 notmuch_status_t status;
393 status = notmuch_message_reindex (message, NULL);
394 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
403 test_expect_equal_file EXPECTED OUTPUT