]> git.cworth.org Git - notmuch/blobdiff - test/T566-lib-message.sh
test: error handling in _n_message_{add,remove}_filename
[notmuch] / test / T566-lib-message.sh
index 0ba601f96f026cae28e833f5e0daebd8ae895642..5894e67d4938c36c681171b44bf11d904762626e 100755 (executable)
@@ -19,9 +19,8 @@ cat <<'EOF' > c_tail
 EOF
 
 cat <<EOF > c_head0
-#include <stdio.h>
-#include <notmuch.h>
 #include <notmuch-test.h>
+
 int main (int argc, char** argv)
 {
    notmuch_database_t *db;
@@ -30,7 +29,9 @@ int main (int argc, char** argv)
    notmuch_message_t *message = NULL;
    const char *id = "1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
 
-   stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
+   stat = notmuch_database_open_with_config (argv[1],
+                                            NOTMUCH_DATABASE_MODE_READ_WRITE,
+                                            NULL, NULL, &db, &msg);
    if (stat != NOTMUCH_STATUS_SUCCESS) {
      fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
      exit (1);
@@ -279,7 +280,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
         notmuch_status_t status;
         notmuch_bool_t out;
         status = notmuch_message_has_maildir_flag_st (message, 'S', &out);
-        printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
+        printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
     }
 EOF
 cat <<EOF > EXPECTED
@@ -295,7 +296,74 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_status_t status;
         status = notmuch_message_maildir_flags_to_tags (message);
-        printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
+        printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "_notmuch_message_add_term catches exceptions"
+cat c_head0 - c_tail <<'EOF' | test_private_C ${MAIL_DIR}
+    {
+       notmuch_private_status_t status;
+       /* This relies on Xapian throwing an exception for adding empty terms */
+       status = _notmuch_message_add_term (message, "body", "");
+       printf("%d\n%d\n", message != NULL, status != NOTMUCH_STATUS_SUCCESS );
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+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 <<EOF > 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 <<EOF > 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 <<EOF > EXPECTED
@@ -311,7 +379,7 @@ 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_XAPIAN_EXCEPTION);
     }
 EOF
 cat <<EOF > EXPECTED
@@ -327,7 +395,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_SUCCESS);
     }
 EOF
 cat <<EOF > EXPECTED
@@ -343,7 +411,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_UNBALANCED_FREEZE_THAW);
     }
 EOF
 cat <<EOF > EXPECTED
@@ -358,7 +426,7 @@ test_begin_subtest "Handle destroying message with closed db"
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_message_destroy (message);
-        printf("%d\n%d\n", message != NULL,  1);
+        printf("%d\n%d\n", message != NULL, 1);
     }
 EOF
 cat <<EOF > EXPECTED
@@ -374,7 +442,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_database_t *db2;
         db2 = notmuch_message_get_database (message);
-        printf("%d\n%d\n", message != NULL,  db == db2);
+        printf("%d\n%d\n", message != NULL, db == db2);
     }
 EOF
 cat <<EOF > EXPECTED
@@ -390,7 +458,7 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_status_t status;
         status = notmuch_message_reindex (message, NULL);
-        printf("%d\n%d\n", message != NULL,  status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
+        printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
     }
 EOF
 cat <<EOF > EXPECTED