2 test_description="notmuch_database_* API"
4 . $(dirname "$0")/test-lib.sh || exit 1
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
14 #include <notmuch-test.h>
15 int main (int argc, char** argv)
17 notmuch_database_t *db;
18 notmuch_status_t stat = NOTMUCH_STATUS_SUCCESS;
21 stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
22 if (stat != NOTMUCH_STATUS_SUCCESS) {
23 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
30 const char *stat_str = notmuch_database_status_string (db);
32 fputs (stat_str, stderr);
38 test_begin_subtest "get status_string with closed db"
39 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
42 EXPECT0(notmuch_database_close (db));
43 str = notmuch_database_status_string (db);
44 printf("%d\n", str == NULL);
52 test_expect_equal_file EXPECTED OUTPUT
54 test_begin_subtest "get path with closed db"
55 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
58 EXPECT0(notmuch_database_close (db));
59 path = notmuch_database_get_path (db);
68 test_expect_equal_file EXPECTED OUTPUT
70 test_begin_subtest "get version with closed db"
71 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
74 EXPECT0(notmuch_database_close (db));
75 version = notmuch_database_get_version (db);
76 printf ("%u\n", version);
77 stat = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
84 A Xapian exception occurred at lib/database.cc:XXX: Database has been closed
86 test_expect_equal_file EXPECTED OUTPUT
88 test_begin_subtest "re-close a closed db"
89 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
91 EXPECT0(notmuch_database_close (db));
92 stat = notmuch_database_close (db);
93 printf ("%d\n", stat);
101 test_expect_equal_file EXPECTED OUTPUT
103 test_begin_subtest "destroy a closed db"
104 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
106 unsigned int version;
107 EXPECT0(notmuch_database_close (db));
108 stat = notmuch_database_destroy (db);
109 printf ("%d\n", stat);
117 test_expect_equal_file EXPECTED OUTPUT
119 test_begin_subtest "destroy an open db"
120 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
122 unsigned int version;
123 stat = notmuch_database_destroy (db);
124 printf ("%d\n", stat);
132 test_expect_equal_file EXPECTED OUTPUT
134 test_begin_subtest "check a closed db for upgrade"
135 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
139 EXPECT0(notmuch_database_close (db));
140 ret = notmuch_database_needs_upgrade (db);
141 printf ("%d\n", ret == FALSE);
142 stat = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
149 A Xapian exception occurred at lib/database.cc:XXX: Database has been closed
151 test_expect_equal_file EXPECTED OUTPUT
153 test_begin_subtest "upgrade a closed db"
154 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
158 EXPECT0(notmuch_database_close (db));
159 stat = notmuch_database_upgrade (db, NULL, NULL);
160 printf ("%d\n", ret == NOTMUCH_STATUS_SUCCESS);
168 test_expect_equal_file EXPECTED OUTPUT
170 test_begin_subtest "begin atomic section for a closed db"
171 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
173 EXPECT0(notmuch_database_close (db));
174 stat = notmuch_database_begin_atomic (db);
175 printf ("%d\n", stat == NOTMUCH_STATUS_SUCCESS ||
176 stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
177 stat = NOTMUCH_STATUS_SUCCESS;
185 test_expect_equal_file EXPECTED OUTPUT
187 test_begin_subtest "end atomic section for a closed db"
188 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
190 EXPECT0(notmuch_database_close (db));
191 EXPECT0(notmuch_database_begin_atomic (db));
192 stat = notmuch_database_end_atomic (db);
193 printf ("%d\n", stat == NOTMUCH_STATUS_SUCCESS ||
194 stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
195 stat = NOTMUCH_STATUS_SUCCESS;
203 test_expect_equal_file EXPECTED OUTPUT
205 test_begin_subtest "get revision for a closed db"
206 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
211 EXPECT0(notmuch_database_close (db));
212 rev = notmuch_database_get_revision (db, &uuid);
213 printf ("%d\n", rev, uuid);
221 test_expect_equal_file EXPECTED OUTPUT