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>
16 int main (int argc, char** argv)
18 notmuch_database_t *db;
19 notmuch_status_t stat = NOTMUCH_STATUS_SUCCESS;
22 stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
23 if (stat != NOTMUCH_STATUS_SUCCESS) {
24 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
31 const char *stat_str = notmuch_database_status_string (db);
33 fputs (stat_str, stderr);
39 test_begin_subtest "get status_string with closed db"
40 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
43 EXPECT0(notmuch_database_close (db));
44 str = notmuch_database_status_string (db);
45 printf("%d\n", str == NULL);
53 test_expect_equal_file EXPECTED OUTPUT
55 test_begin_subtest "get path with closed db"
56 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
59 EXPECT0(notmuch_database_close (db));
60 path = notmuch_database_get_path (db);
69 test_expect_equal_file EXPECTED OUTPUT
71 test_begin_subtest "get version with closed db"
72 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
75 EXPECT0(notmuch_database_close (db));
76 version = notmuch_database_get_version (db);
77 printf ("%u\n", version);
78 stat = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
85 A Xapian exception occurred at lib/database.cc:XXX: Database has been closed
87 test_expect_equal_file EXPECTED OUTPUT
89 test_begin_subtest "re-close a closed db"
90 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
92 EXPECT0(notmuch_database_close (db));
93 stat = notmuch_database_close (db);
94 printf ("%d\n", stat);
102 test_expect_equal_file EXPECTED OUTPUT
104 test_begin_subtest "destroy a closed db"
105 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
107 unsigned int version;
108 EXPECT0(notmuch_database_close (db));
109 stat = notmuch_database_destroy (db);
110 printf ("%d\n", stat);
118 test_expect_equal_file EXPECTED OUTPUT
120 test_begin_subtest "destroy an open db"
121 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
123 unsigned int version;
124 stat = notmuch_database_destroy (db);
125 printf ("%d\n", stat);
133 test_expect_equal_file EXPECTED OUTPUT
135 test_begin_subtest "check a closed db for upgrade"
136 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
140 EXPECT0(notmuch_database_close (db));
141 ret = notmuch_database_needs_upgrade (db);
142 printf ("%d\n", ret == FALSE);
143 stat = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
150 A Xapian exception occurred at lib/database.cc:XXX: Database has been closed
152 test_expect_equal_file EXPECTED OUTPUT
154 test_begin_subtest "upgrade a closed db"
155 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
159 EXPECT0(notmuch_database_close (db));
160 stat = notmuch_database_upgrade (db, NULL, NULL);
161 printf ("%d\n", ret == NOTMUCH_STATUS_SUCCESS);
169 test_expect_equal_file EXPECTED OUTPUT
171 test_begin_subtest "begin atomic section for a closed db"
172 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
174 EXPECT0(notmuch_database_close (db));
175 stat = notmuch_database_begin_atomic (db);
176 printf ("%d\n", stat == NOTMUCH_STATUS_SUCCESS ||
177 stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
178 stat = NOTMUCH_STATUS_SUCCESS;
186 test_expect_equal_file EXPECTED OUTPUT
188 test_begin_subtest "end atomic section for a closed db"
189 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
191 EXPECT0(notmuch_database_close (db));
192 EXPECT0(notmuch_database_begin_atomic (db));
193 stat = notmuch_database_end_atomic (db);
194 printf ("%d\n", stat == NOTMUCH_STATUS_SUCCESS ||
195 stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
196 stat = NOTMUCH_STATUS_SUCCESS;
204 test_expect_equal_file EXPECTED OUTPUT
206 test_begin_subtest "get revision for a closed db"
207 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
212 EXPECT0(notmuch_database_close (db));
213 rev = notmuch_database_get_revision (db, &uuid);
214 printf ("%d\n", rev, uuid);
222 test_expect_equal_file EXPECTED OUTPUT
224 test_begin_subtest "get directory for a closed db"
225 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
227 notmuch_directory_t *dir;
228 EXPECT0(notmuch_database_close (db));
229 stat = notmuch_database_get_directory (db, "/nonexistent", &dir);
230 printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
237 A Xapian exception occurred finding/creating a directory: Database has been closed.
239 test_expect_equal_file EXPECTED OUTPUT
241 test_begin_subtest "index file with a closed db"
242 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
244 notmuch_message_t *msg;
245 const char *path = talloc_asprintf(db, "%s/01:2,", argv[1]);
246 EXPECT0(notmuch_database_close (db));
247 stat = notmuch_database_index_file (db, path, NULL, &msg);
248 printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
255 A Xapian exception occurred finding message: Database has been closed.
257 test_expect_equal_file EXPECTED OUTPUT
259 generate_message '[filename]=relative_path'
260 test_begin_subtest "index file (relative path)"
261 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
263 notmuch_message_t *msg;
264 stat = notmuch_database_index_file (db, "relative_path", NULL, &msg);
265 printf ("%d\n", stat == NOTMUCH_STATUS_SUCCESS);
273 test_expect_equal_file EXPECTED OUTPUT
275 test_begin_subtest "index file (absolute path outside mail root)"
276 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
278 notmuch_message_t *msg;
279 stat = notmuch_database_index_file (db, "/dev/zero", NULL, &msg);
280 printf ("%d\n", stat == NOTMUCH_STATUS_FILE_ERROR);
287 Error opening /dev/zero: path outside mail root
289 test_expect_equal_file EXPECTED OUTPUT
291 test_begin_subtest "remove message file with a closed db"
292 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
294 EXPECT0(notmuch_database_close (db));
295 stat = notmuch_database_remove_message (db, "01:2,");
296 printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
303 A Xapian exception occurred finding/creating a directory: Database has been closed.
305 test_expect_equal_file EXPECTED OUTPUT
307 test_begin_subtest "find message by filename with a closed db"
308 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
310 notmuch_message_t *msg;
311 EXPECT0(notmuch_database_close (db));
312 stat = notmuch_database_find_message_by_filename (db, "01:2,", &msg);
313 printf ("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
320 A Xapian exception occurred finding/creating a directory: Database has been closed.
322 test_expect_equal_file EXPECTED OUTPUT