2 test_description="library reopen API"
4 . $(dirname "$0")/test-lib.sh || exit 1
9 #include <notmuch-test.h>
11 int main (int argc, char** argv)
13 notmuch_database_t *db;
15 notmuch_status_t stat;
16 notmuch_database_mode_t mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
20 for (int i = 1; i < argc; i++)
21 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
23 if (argv[2] && (argv[2][0] == 'w' || argv[2][0] == 'W'))
24 mode = NOTMUCH_DATABASE_MODE_READ_WRITE;
26 stat = notmuch_database_open_with_config (argv[1],
32 if (stat != NOTMUCH_STATUS_SUCCESS) {
33 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
39 EXPECT0(notmuch_database_destroy(db));
43 # The sequence of tests is important here
45 test_begin_subtest "notmuch_database_reopen (read=>write)"
46 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} read ${NOTMUCH_CONFIG}
48 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_WRITE));
49 EXPECT0(notmuch_database_set_config (db, "test.key1", "testvalue1"));
50 EXPECT0(notmuch_database_set_config (db, "test.key2", "testvalue2"));
51 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
52 printf("test.key1 = %s\n", val);
53 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
54 printf("test.key2 = %s\n", val);
59 test.key1 = testvalue1
60 test.key2 = testvalue2
63 test_expect_equal_file EXPECTED OUTPUT
65 test_begin_subtest "notmuch_database_reopen (read=>read)"
66 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} read ${NOTMUCH_CONFIG}
68 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_ONLY));
69 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
70 printf("test.key1 = %s\n", val);
71 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
72 printf("test.key2 = %s\n", val);
77 test.key1 = testvalue1
78 test.key2 = testvalue2
81 test_expect_equal_file EXPECTED OUTPUT
83 test_begin_subtest "notmuch_database_reopen (write=>read)"
84 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} write ${NOTMUCH_CONFIG}
86 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_ONLY));
87 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
88 printf("test.key1 = %s\n", val);
89 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
90 printf("test.key2 = %s\n", val);
95 test.key1 = testvalue1
96 test.key2 = testvalue2
99 test_expect_equal_file EXPECTED OUTPUT
101 test_begin_subtest "notmuch_database_reopen (write=>write)"
102 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} write ${NOTMUCH_CONFIG}
104 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_WRITE));
105 EXPECT0(notmuch_database_set_config (db, "test.key3", "testvalue3"));
106 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
107 printf("test.key1 = %s\n", val);
108 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
109 printf("test.key2 = %s\n", val);
110 EXPECT0(notmuch_database_get_config (db, "test.key3", &val));
111 printf("test.key3 = %s\n", val);
114 cat <<'EOF' >EXPECTED
116 test.key1 = testvalue1
117 test.key2 = testvalue2
118 test.key3 = testvalue3
121 test_expect_equal_file EXPECTED OUTPUT