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 this test only tests the trivial code path
91 test_begin_subtest "Handle getting replies from closed database"
92 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
94 notmuch_messages_t *replies;
95 replies = notmuch_message_get_replies (message);
96 printf("%d\n%d\n", message != NULL, replies==NULL);
105 test_expect_equal_file EXPECTED OUTPUT
107 test_begin_subtest "Handle getting message filename from closed database"
108 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
110 const char *filename;
111 filename = notmuch_message_get_filename (message);
112 printf("%d\n%d\n", message != NULL, filename == NULL);
121 test_expect_equal_file EXPECTED OUTPUT
123 test_begin_subtest "Handle getting all message filenames from closed database"
124 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
126 notmuch_filenames_t *filenames;
127 filenames = notmuch_message_get_filenames (message);
128 printf("%d\n%d\n", message != NULL, filenames == NULL);
137 test_expect_equal_file EXPECTED OUTPUT
139 test_begin_subtest "Handle getting ghost flag from closed database"
140 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
142 notmuch_bool_t result;
143 result = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST);
144 printf("%d\n%d\n", message != NULL, result == FALSE);
153 test_expect_equal_file EXPECTED OUTPUT
155 test_begin_subtest "Handle getting date from closed database"
156 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
159 result = notmuch_message_get_date (message);
160 printf("%d\n%d\n", message != NULL, result == 0);
169 test_expect_equal_file EXPECTED OUTPUT
171 test_begin_subtest "Handle getting tags from closed database"
172 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
174 notmuch_tags_t *result;
175 result = notmuch_message_get_tags (message);
176 printf("%d\n%d\n", message != NULL, result == NULL);
185 test_expect_equal_file EXPECTED OUTPUT
187 test_begin_subtest "Handle counting files from closed database"
188 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
191 result = notmuch_message_count_files (message);
192 printf("%d\n%d\n", message != NULL, result < 0);
201 test_expect_equal_file EXPECTED OUTPUT
203 test_begin_subtest "Handle adding tag with closed database"
204 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
206 notmuch_status_t status;
207 status = notmuch_message_add_tag (message, "boom");
208 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
217 test_expect_equal_file EXPECTED OUTPUT
219 test_begin_subtest "Handle removing tag with closed database"
220 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
222 notmuch_status_t status;
223 status = notmuch_message_remove_tag (message, "boom");
224 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
233 test_expect_equal_file EXPECTED OUTPUT
235 test_begin_subtest "Handle read maildir flag with closed database"
236 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
238 notmuch_bool_t is_set = -1;
239 is_set = notmuch_message_has_maildir_flag (message, 'S');
240 printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
249 test_expect_equal_file EXPECTED OUTPUT
251 test_begin_subtest "Handle checking maildir flag with closed db (new API)"
252 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
254 notmuch_status_t status;
256 status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
257 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
266 test_expect_equal_file EXPECTED OUTPUT
268 test_begin_subtest "Handle converting maildir flags to tags with closed db"
269 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
271 notmuch_status_t status;
272 status = notmuch_message_maildir_flags_to_tags (message);
273 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
282 test_expect_equal_file EXPECTED OUTPUT
284 test_begin_subtest "Handle removing all tags with closed db"
285 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
287 notmuch_status_t status;
288 status = notmuch_message_remove_all_tags (message);
289 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
298 test_expect_equal_file EXPECTED OUTPUT
300 test_begin_subtest "Handle freezing message with closed db"
301 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
303 notmuch_status_t status;
304 status = notmuch_message_freeze (message);
305 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS);
314 test_expect_equal_file EXPECTED OUTPUT
316 test_begin_subtest "Handle thawing message with closed db"
317 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
319 notmuch_status_t status;
320 status = notmuch_message_thaw (message);
321 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW);
330 test_expect_equal_file EXPECTED OUTPUT
332 test_begin_subtest "Handle destroying message with closed db"
333 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
335 notmuch_message_destroy (message);
336 printf("%d\n%d\n", message != NULL, 1);
345 test_expect_equal_file EXPECTED OUTPUT
347 test_begin_subtest "Handle retrieving closed db from message"
348 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
350 notmuch_database_t *db2;
351 db2 = notmuch_message_get_database (message);
352 printf("%d\n%d\n", message != NULL, db == db2);
361 test_expect_equal_file EXPECTED OUTPUT
363 test_begin_subtest "Handle reindexing message with closed db"
364 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
366 notmuch_status_t status;
367 status = notmuch_message_reindex (message, NULL);
368 printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
377 test_expect_equal_file EXPECTED OUTPUT