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