2 test_description="library config API"
4 . ./test-lib.sh || exit 1
14 void run(int line, notmuch_status_t ret)
17 fprintf (stderr, "line %d: %s\n", line, ret);
22 #define RUN(v) run(__LINE__, v);
24 int main (int argc, char** argv)
26 notmuch_database_t *db;
28 notmuch_status_t stat;
30 RUN(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
35 RUN(notmuch_database_destroy(db));
39 test_begin_subtest "notmuch_database_{set,get}_config"
40 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
42 RUN(notmuch_database_set_config (db, "testkey1", "testvalue1"));
43 RUN(notmuch_database_set_config (db, "testkey2", "testvalue2"));
44 RUN(notmuch_database_get_config (db, "testkey1", &val));
45 printf("testkey1 = %s\n", val);
46 RUN(notmuch_database_get_config (db, "testkey2", &val));
47 printf("testkey2 = %s\n", val);
56 test_expect_equal_file EXPECTED OUTPUT
59 test_begin_subtest "notmuch_database_get_config_list: empty list"
60 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
62 notmuch_config_list_t *list;
63 RUN(notmuch_database_get_config_list (db, "nonexistent", &list));
64 printf("valid = %d\n", notmuch_config_list_valid (list));
65 notmuch_config_list_destroy (list);
73 test_expect_equal_file EXPECTED OUTPUT
76 test_begin_subtest "notmuch_database_get_config_list: all pairs"
77 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
79 notmuch_config_list_t *list;
80 RUN(notmuch_database_set_config (db, "zzzafter", "afterval"));
81 RUN(notmuch_database_set_config (db, "aaabefore", "beforeval"));
82 RUN(notmuch_database_get_config_list (db, "", &list));
83 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
84 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
86 notmuch_config_list_destroy (list);
97 test_expect_equal_file EXPECTED OUTPUT
99 test_begin_subtest "notmuch_database_get_config_list: one prefix"
100 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
102 notmuch_config_list_t *list;
103 RUN(notmuch_database_get_config_list (db, "testkey", &list));
104 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
105 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
107 notmuch_config_list_destroy (list);
110 cat <<'EOF' >EXPECTED
116 test_expect_equal_file EXPECTED OUTPUT
118 test_begin_subtest "dump config"
119 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
121 RUN(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
124 notmuch dump --include=config >OUTPUT
125 cat <<'EOF' >EXPECTED
126 #notmuch-dump batch-tag:2 config
127 #@ aaabefore beforeval
128 #@ key%20with%20spaces value,%20with,%20spaces%21
129 #@ testkey1 testvalue1
130 #@ testkey2 testvalue2
133 test_expect_equal_file EXPECTED OUTPUT
135 test_begin_subtest "restore config"
136 notmuch dump --include=config >EXPECTED
137 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
139 RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));
142 notmuch restore --include=config <EXPECTED
143 notmuch dump --include=config >OUTPUT
144 test_expect_equal_file EXPECTED OUTPUT