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));
42 echo " EXPECT0(notmuch_database_close (db));" >> c_head
44 test_begin_subtest "Handle getting message-id from closed database"
45 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
48 id2=notmuch_message_get_message_id (message);
49 printf("%d\n%d\n", message != NULL, id2==NULL);
58 test_expect_equal_file EXPECTED OUTPUT
60 test_begin_subtest "Handle getting thread-id from closed database"
61 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
64 id2=notmuch_message_get_thread_id (message);
65 printf("%d\n%d\n", message != NULL, id2==NULL);
74 test_expect_equal_file EXPECTED OUTPUT
76 test_begin_subtest "Handle getting header from closed database"
77 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
80 from=notmuch_message_get_header (message, "from");
81 printf("%s\n%d\n", id, from == NULL);
86 1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
90 test_expect_equal_file EXPECTED OUTPUT
92 # XXX this test only tests the trivial code path
93 test_begin_subtest "Handle getting replies from closed database"
94 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
96 notmuch_messages_t *replies;
97 replies = notmuch_message_get_replies (message);
98 printf("%d\n%d\n", message != NULL, replies==NULL);
107 test_expect_equal_file EXPECTED OUTPUT
109 test_begin_subtest "Handle getting message filename from closed database"
110 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
112 const char *filename;
113 filename = notmuch_message_get_filename (message);
114 printf("%d\n%d\n", message != NULL, filename == NULL);
123 test_expect_equal_file EXPECTED OUTPUT
125 test_begin_subtest "Handle getting all message filenames from closed database"
126 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
128 notmuch_filenames_t *filenames;
129 filenames = notmuch_message_get_filenames (message);
130 printf("%d\n%d\n", message != NULL, filenames == NULL);
139 test_expect_equal_file EXPECTED OUTPUT
141 test_begin_subtest "iterate over all message filenames from closed database"
142 cat c_head0 - c_tail <<'EOF' | test_C ${MAIL_DIR}
144 notmuch_filenames_t *filenames;
145 filenames = notmuch_message_get_filenames (message);
146 EXPECT0(notmuch_database_close (db));
147 for (; notmuch_filenames_valid (filenames);
148 notmuch_filenames_move_to_next (filenames)) {
149 const char *filename = notmuch_filenames_get (filenames);
150 printf("%s\n", filename);
152 notmuch_filenames_destroy (filenames);
162 test_expect_equal_file EXPECTED OUTPUT
164 test_begin_subtest "Handle getting ghost flag from closed database"
165 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
167 notmuch_bool_t result;
168 result = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST);
169 printf("%d\n%d\n", message != NULL, result == FALSE);
178 test_expect_equal_file EXPECTED OUTPUT
180 test_begin_subtest "Handle getting date from closed database"
181 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
184 result = notmuch_message_get_date (message);
185 printf("%d\n%d\n", message != NULL, result == 0);
194 test_expect_equal_file EXPECTED OUTPUT
196 test_begin_subtest "Handle getting tags from closed database"
197 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
199 notmuch_tags_t *result;
200 result = notmuch_message_get_tags (message);
201 printf("%d\n%d\n", message != NULL, result == NULL);
210 test_expect_equal_file EXPECTED OUTPUT
212 test_begin_subtest "Handle counting files from closed database"
213 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
216 result = notmuch_message_count_files (message);
217 printf("%d\n%d\n", message != NULL, result < 0);
226 test_expect_equal_file EXPECTED OUTPUT
228 test_begin_subtest "Handle adding tag with closed database"
229 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
231 notmuch_status_t status;
232 status = notmuch_message_add_tag (message, "boom");
233 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
242 test_expect_equal_file EXPECTED OUTPUT
244 test_begin_subtest "Handle removing tag with closed database"
245 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
247 notmuch_status_t status;
248 status = notmuch_message_remove_tag (message, "boom");
249 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
258 test_expect_equal_file EXPECTED OUTPUT
260 test_begin_subtest "Handle read maildir flag with closed database"
261 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
263 notmuch_bool_t is_set = -1;
264 is_set = notmuch_message_has_maildir_flag (message, 'S');
265 printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
274 test_expect_equal_file EXPECTED OUTPUT
276 test_begin_subtest "Handle checking maildir flag with closed db (new API)"
277 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
279 notmuch_status_t status;
281 status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
282 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
291 test_expect_equal_file EXPECTED OUTPUT
293 test_begin_subtest "Handle converting maildir flags to tags with closed db"
294 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
296 notmuch_status_t status;
297 status = notmuch_message_maildir_flags_to_tags (message);
298 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
307 test_expect_equal_file EXPECTED OUTPUT
309 test_begin_subtest "Handle removing all tags with closed db"
310 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
312 notmuch_status_t status;
313 status = notmuch_message_remove_all_tags (message);
314 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
323 test_expect_equal_file EXPECTED OUTPUT
325 test_begin_subtest "Handle freezing message with closed db"
326 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
328 notmuch_status_t status;
329 status = notmuch_message_freeze (message);
330 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS);
339 test_expect_equal_file EXPECTED OUTPUT
341 test_begin_subtest "Handle thawing message with closed db"
342 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
344 notmuch_status_t status;
345 status = notmuch_message_thaw (message);
346 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
355 test_expect_equal_file EXPECTED OUTPUT
357 test_begin_subtest "Handle destroying message with closed db"
358 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
360 notmuch_message_destroy (message);
361 printf("%d\n%d\n", message != NULL, 1);
370 test_expect_equal_file EXPECTED OUTPUT
372 test_begin_subtest "Handle retrieving closed db from message"
373 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
375 notmuch_database_t *db2;
376 db2 = notmuch_message_get_database (message);
377 printf("%d\n%d\n", message != NULL, db == db2);
386 test_expect_equal_file EXPECTED OUTPUT
388 test_begin_subtest "Handle reindexing message with closed db"
389 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
391 notmuch_status_t status;
392 status = notmuch_message_reindex (message, NULL);
393 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
402 test_expect_equal_file EXPECTED OUTPUT