]> git.cworth.org Git - notmuch-old/blob - test/T595-reopen.sh
doc/elisp: replace label for Emacs commands and key bindings.
[notmuch-old] / test / T595-reopen.sh
1 #!/usr/bin/env bash
2 test_description="library reopen API"
3
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 add_email_corpus
7
8 cat <<EOF > c_head
9 #include <notmuch-test.h>
10
11 int main (int argc, char** argv)
12 {
13    notmuch_database_t *db;
14    char *val;
15    notmuch_status_t stat;
16    notmuch_database_mode_t mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
17
18    char *msg = NULL;
19
20    for (int i = 1; i < argc; i++)
21       if (strcmp (argv[i], "%NULL%") == 0) argv[i] = NULL;
22
23    if (argv[2] && (argv[2][0] == 'w' || argv[2][0] == 'W'))
24      mode = NOTMUCH_DATABASE_MODE_READ_WRITE;
25
26    stat = notmuch_database_open_with_config (argv[1],
27                                              mode,
28                                              argv[3],
29                                              argv[4],
30                                              &db,
31                                              &msg);
32    if (stat != NOTMUCH_STATUS_SUCCESS) {
33      fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
34      exit (1);
35    }
36 EOF
37
38 cat <<EOF > c_tail
39    EXPECT0(notmuch_database_destroy(db));
40 }
41 EOF
42
43 # The sequence of tests is important here
44
45 test_begin_subtest "notmuch_database_reopen (read=>write)"
46 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} read ${NOTMUCH_CONFIG}
47 {
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);
55 }
56 EOF
57 cat <<'EOF' >EXPECTED
58 == stdout ==
59 test.key1 = testvalue1
60 test.key2 = testvalue2
61 == stderr ==
62 EOF
63 test_expect_equal_file EXPECTED OUTPUT
64
65 test_begin_subtest "notmuch_database_reopen (read=>read)"
66 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} read ${NOTMUCH_CONFIG}
67 {
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);
73 }
74 EOF
75 cat <<'EOF' >EXPECTED
76 == stdout ==
77 test.key1 = testvalue1
78 test.key2 = testvalue2
79 == stderr ==
80 EOF
81 test_expect_equal_file EXPECTED OUTPUT
82
83 test_begin_subtest "notmuch_database_reopen (write=>read)"
84 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} write ${NOTMUCH_CONFIG}
85 {
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);
91 }
92 EOF
93 cat <<'EOF' >EXPECTED
94 == stdout ==
95 test.key1 = testvalue1
96 test.key2 = testvalue2
97 == stderr ==
98 EOF
99 test_expect_equal_file EXPECTED OUTPUT
100
101 test_begin_subtest "notmuch_database_reopen (write=>write)"
102 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} write ${NOTMUCH_CONFIG}
103 {
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);
112 }
113 EOF
114 cat <<'EOF' >EXPECTED
115 == stdout ==
116 test.key1 = testvalue1
117 test.key2 = testvalue2
118 test.key3 = testvalue3
119 == stderr ==
120 EOF
121 test_expect_equal_file EXPECTED OUTPUT
122
123 test_done