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_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
33 if (stat != NOTMUCH_STATUS_SUCCESS) {
34 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
37 EXPECT0(notmuch_database_find_message (db, id, &message));
41 echo " EXPECT0(notmuch_database_close (db));" >> c_head
43 test_begin_subtest "Handle getting message-id from closed database"
44 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
47 id2=notmuch_message_get_message_id (message);
48 printf("%d\n%d\n", message != NULL, id2==NULL);
57 test_expect_equal_file EXPECTED OUTPUT
59 test_begin_subtest "Handle getting thread-id from closed database"
60 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
63 id2=notmuch_message_get_thread_id (message);
64 printf("%d\n%d\n", message != NULL, id2==NULL);
73 test_expect_equal_file EXPECTED OUTPUT
75 test_begin_subtest "Handle getting header from closed database"
76 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
79 from=notmuch_message_get_header (message, "from");
80 printf("%s\n%d\n", id, from == NULL);
85 1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
89 test_expect_equal_file EXPECTED OUTPUT
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 "iterate over all message filenames from closed database"
141 cat c_head0 - c_tail <<'EOF' | test_C ${MAIL_DIR}
143 notmuch_filenames_t *filenames;
144 filenames = notmuch_message_get_filenames (message);
145 EXPECT0(notmuch_database_close (db));
146 for (; notmuch_filenames_valid (filenames);
147 notmuch_filenames_move_to_next (filenames)) {
148 const char *filename = notmuch_filenames_get (filenames);
149 printf("%s\n", filename);
151 notmuch_filenames_destroy (filenames);
161 test_expect_equal_file EXPECTED OUTPUT
163 test_begin_subtest "Handle getting ghost flag from closed database"
164 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
166 notmuch_bool_t result;
167 result = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST);
168 printf("%d\n%d\n", message != NULL, result == FALSE);
177 test_expect_equal_file EXPECTED OUTPUT
179 test_begin_subtest "Handle getting date from closed database"
180 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
183 result = notmuch_message_get_date (message);
184 printf("%d\n%d\n", message != NULL, result == 0);
193 test_expect_equal_file EXPECTED OUTPUT
195 test_begin_subtest "Handle getting tags from closed database"
196 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
198 notmuch_tags_t *result;
199 result = notmuch_message_get_tags (message);
200 printf("%d\n%d\n", message != NULL, result == NULL);
209 test_expect_equal_file EXPECTED OUTPUT
211 test_begin_subtest "Handle counting files from closed database"
212 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
215 result = notmuch_message_count_files (message);
216 printf("%d\n%d\n", message != NULL, result < 0);
225 test_expect_equal_file EXPECTED OUTPUT
227 test_begin_subtest "Handle adding tag with closed database"
228 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
230 notmuch_status_t status;
231 status = notmuch_message_add_tag (message, "boom");
232 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
241 test_expect_equal_file EXPECTED OUTPUT
243 test_begin_subtest "Handle removing tag with closed database"
244 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
246 notmuch_status_t status;
247 status = notmuch_message_remove_tag (message, "boom");
248 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
257 test_expect_equal_file EXPECTED OUTPUT
259 test_begin_subtest "Handle read maildir flag with closed database"
260 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
262 notmuch_bool_t is_set = -1;
263 is_set = notmuch_message_has_maildir_flag (message, 'S');
264 printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
273 test_expect_equal_file EXPECTED OUTPUT
275 test_begin_subtest "Handle checking maildir flag with closed db (new API)"
276 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
278 notmuch_status_t status;
280 status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
281 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
290 test_expect_equal_file EXPECTED OUTPUT
292 test_begin_subtest "Handle converting maildir flags to tags with closed db"
293 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
295 notmuch_status_t status;
296 status = notmuch_message_maildir_flags_to_tags (message);
297 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
306 test_expect_equal_file EXPECTED OUTPUT
308 test_begin_subtest "Handle removing all tags with closed db"
309 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
311 notmuch_status_t status;
312 status = notmuch_message_remove_all_tags (message);
313 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
322 test_expect_equal_file EXPECTED OUTPUT
324 test_begin_subtest "Handle freezing message with closed db"
325 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
327 notmuch_status_t status;
328 status = notmuch_message_freeze (message);
329 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS);
338 test_expect_equal_file EXPECTED OUTPUT
340 test_begin_subtest "Handle thawing message with closed db"
341 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
343 notmuch_status_t status;
344 status = notmuch_message_thaw (message);
345 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
354 test_expect_equal_file EXPECTED OUTPUT
356 test_begin_subtest "Handle destroying message with closed db"
357 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
359 notmuch_message_destroy (message);
360 printf("%d\n%d\n", message != NULL, 1);
369 test_expect_equal_file EXPECTED OUTPUT
371 test_begin_subtest "Handle retrieving closed db from message"
372 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
374 notmuch_database_t *db2;
375 db2 = notmuch_message_get_database (message);
376 printf("%d\n%d\n", message != NULL, db == db2);
385 test_expect_equal_file EXPECTED OUTPUT
387 test_begin_subtest "Handle reindexing message with closed db"
388 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
390 notmuch_status_t status;
391 status = notmuch_message_reindex (message, NULL);
392 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
401 test_expect_equal_file EXPECTED OUTPUT