X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=test%2FT566-lib-message.sh;h=6905193788a4b22419897119d2e1d14d50c405bc;hb=HEAD;hp=bc9bfcb62fad36a513a62b186e03ccdcdaeb21f4;hpb=f48d2e2ff89a7e0a413b29ca844b2c785063eb3d;p=notmuch diff --git a/test/T566-lib-message.sh b/test/T566-lib-message.sh index bc9bfcb6..69051937 100755 --- a/test/T566-lib-message.sh +++ b/test/T566-lib-message.sh @@ -3,6 +3,10 @@ test_description="API tests for notmuch_message_*" . $(dirname "$0")/test-lib.sh || exit 1 +if [ -n "${NOTMUCH_TEST_INSTALLED}" ]; then + test_done +fi + add_email_corpus test_begin_subtest "building database" @@ -27,7 +31,7 @@ int main (int argc, char** argv) notmuch_status_t stat; char *msg = NULL; notmuch_message_t *message = NULL; - const char *id = "1258471718-6781-1-git-send-email-dottedmag@dottedmag.net"; + const char *id = "87pr7gqidx.fsf@yoom.home.cworth.org"; stat = notmuch_database_open_with_config (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, @@ -84,7 +88,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} EOF cat < EXPECTED == stdout == -1258471718-6781-1-git-send-email-dottedmag@dottedmag.net +87pr7gqidx.fsf@yoom.home.cworth.org 1 == stderr == EOF @@ -156,7 +160,7 @@ cat c_head0 - c_tail <<'EOF' | test_C ${MAIL_DIR} EOF cat < EXPECTED == stdout == -MAIL_DIR/01:2, +MAIL_DIR/cur/40:2, SUCCESS == stderr == EOF @@ -231,7 +235,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { notmuch_status_t status; status = notmuch_message_add_tag (message, "boom"); - printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION); + printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE); } EOF cat < EXPECTED @@ -247,7 +251,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { notmuch_status_t status; status = notmuch_message_remove_tag (message, "boom"); - printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION); + printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE); } EOF cat < EXPECTED @@ -324,12 +328,109 @@ cat < EXPECTED EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "_notmuch_message_remove_term catches exceptions" +cat c_head0 - c_tail <<'EOF' | test_private_C ${MAIL_DIR} + { + notmuch_private_status_t status; + /* Xapian throws the same exception for empty and non-existent terms; + * error string varies between Xapian versions. */ + status = _notmuch_message_remove_term (message, "tag", "nonexistent"); + printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS ); + } +EOF +cat < EXPECTED +== stdout == +1 +1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "_notmuch_message_add_filename on closed db" +cat c_head - c_tail <<'EOF' | test_private_C ${MAIL_DIR} + { + notmuch_private_status_t status; + status = _notmuch_message_add_filename (message, "some-filename"); + printf("%d\n%d\n", message != NULL, status != NOTMUCH_STATUS_SUCCESS); + } +EOF +cat < EXPECTED +== stdout == +1 +1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "_notmuch_message_remove_filename on closed db" +cat c_head - c_tail <<'EOF' | test_private_C ${MAIL_DIR} + { + notmuch_private_status_t status; + status = _notmuch_message_remove_filename (message, "some-filename"); + printf("%d\n%d\n", message != NULL, status != NOTMUCH_STATUS_SUCCESS); + } +EOF +cat < EXPECTED +== stdout == +1 +1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "Handle converting tags to maildir flags with closed db" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_status_t status; + status = notmuch_message_tags_to_maildir_flags (message); + printf("%d\n%d\n", message != NULL, status != NOTMUCH_STATUS_SUCCESS); + } +EOF +cat < EXPECTED +== stdout == +1 +1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +POSTLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/postlist.*) +test_begin_subtest "Handle converting tags to maildir flags with corrupted db" +backup_database +cat c_head0 - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH} + { + notmuch_status_t status; + + status = notmuch_message_add_tag (message, "draft"); + if (status) exit(1); + + int fd = open(argv[2],O_WRONLY|O_TRUNC); + if (fd < 0) { + fprintf (stderr, "error opening %s\n", argv[1]); + exit (1); + } + + status = notmuch_message_tags_to_maildir_flags (message); + printf("%d\n%d\n", message != NULL, status != NOTMUCH_STATUS_SUCCESS); + } +EOF +cat < EXPECTED +== stdout == +1 +1 +== stderr == +EOF +restore_database +notmuch new +notmuch tag -draft id:87pr7gqidx.fsf@yoom.home.cworth.org +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "Handle removing all tags with closed db" cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { notmuch_status_t status; status = notmuch_message_remove_all_tags (message); - printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION); + printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE); } EOF cat < EXPECTED @@ -345,7 +446,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { notmuch_status_t status; status = notmuch_message_freeze (message); - printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_SUCCESS); + printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE); } EOF cat < EXPECTED @@ -361,7 +462,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { notmuch_status_t status; status = notmuch_message_thaw (message); - printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW); + printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_CLOSED_DATABASE); } EOF cat < EXPECTED @@ -419,4 +520,31 @@ cat < EXPECTED EOF test_expect_equal_file EXPECTED OUTPUT +TERMLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/termlist.*) +test_begin_subtest "remove message with corrupted db" +backup_database +cat c_head0 - c_tail <<'EOF' | test_private_C ${MAIL_DIR} ${TERMLIST_PATH} + { + notmuch_status_t status; + + int fd = open(argv[2],O_WRONLY|O_TRUNC); + if (fd < 0) { + fprintf (stderr, "error opening %s\n", argv[1]); + exit (1); + } + + stat = _notmuch_message_delete (message); + printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION); + } +EOF +cat < EXPECTED +== stdout == +1 +== stderr == +A Xapian exception occurred at message.cc:XXX: EOF reading block YYY +EOF +sed 's/EOF reading block [0-9]*/EOF reading block YYY/' < OUTPUT > OUTPUT.clean +test_expect_equal_file EXPECTED OUTPUT.clean +restore_database + test_done