2 test_description="library reopen API"
4 . $(dirname "$0")/test-lib.sh || exit 1
11 #include <notmuch-test.h>
13 int main (int argc, char** argv)
15 notmuch_database_t *db;
17 notmuch_status_t stat;
18 notmuch_database_mode_t mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
22 for (int i = 1; i < argc; i++)
23 if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
25 if (argv[2] && (argv[2][0] == 'w' || argv[2][0] == 'W'))
26 mode = NOTMUCH_DATABASE_MODE_READ_WRITE;
28 stat = notmuch_database_open_with_config (argv[1],
34 if (stat != NOTMUCH_STATUS_SUCCESS) {
35 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
41 EXPECT0(notmuch_database_destroy(db));
45 # The sequence of tests is important here
47 test_begin_subtest "notmuch_database_reopen (read=>write)"
48 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} read ${NOTMUCH_CONFIG}
50 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_WRITE));
51 EXPECT0(notmuch_database_set_config (db, "test.key1", "testvalue1"));
52 EXPECT0(notmuch_database_set_config (db, "test.key2", "testvalue2"));
53 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
54 printf("test.key1 = %s\n", val);
55 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
56 printf("test.key2 = %s\n", val);
61 test.key1 = testvalue1
62 test.key2 = testvalue2
65 test_expect_equal_file EXPECTED OUTPUT
67 test_begin_subtest "notmuch_database_reopen (read=>read)"
68 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} read ${NOTMUCH_CONFIG}
70 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_ONLY));
71 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
72 printf("test.key1 = %s\n", val);
73 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
74 printf("test.key2 = %s\n", val);
79 test.key1 = testvalue1
80 test.key2 = testvalue2
83 test_expect_equal_file EXPECTED OUTPUT
85 test_begin_subtest "notmuch_database_reopen (write=>read)"
86 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} write ${NOTMUCH_CONFIG}
88 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_ONLY));
89 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
90 printf("test.key1 = %s\n", val);
91 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
92 printf("test.key2 = %s\n", val);
97 test.key1 = testvalue1
98 test.key2 = testvalue2
101 test_expect_equal_file EXPECTED OUTPUT
103 test_begin_subtest "notmuch_database_reopen (write=>write)"
104 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} write ${NOTMUCH_CONFIG}
106 EXPECT0(notmuch_database_reopen (db, NOTMUCH_DATABASE_MODE_READ_WRITE));
107 EXPECT0(notmuch_database_set_config (db, "test.key3", "testvalue3"));
108 EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
109 printf("test.key1 = %s\n", val);
110 EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
111 printf("test.key2 = %s\n", val);
112 EXPECT0(notmuch_database_get_config (db, "test.key3", &val));
113 printf("test.key3 = %s\n", val);
116 cat <<'EOF' >EXPECTED
118 test.key1 = testvalue1
119 test.key2 = testvalue2
120 test.key3 = testvalue3
123 test_expect_equal_file EXPECTED OUTPUT