2 test_description="library config 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;
19 EXPECT0(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
24 EXPECT0(notmuch_database_destroy(db));
28 test_begin_subtest "notmuch_database_{set,get}_config"
29 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
31 EXPECT0(notmuch_database_set_config (db, "testkey1", "testvalue1"));
32 EXPECT0(notmuch_database_set_config (db, "testkey2", "testvalue2"));
33 EXPECT0(notmuch_database_get_config (db, "testkey1", &val));
34 printf("testkey1 = %s\n", val);
35 EXPECT0(notmuch_database_get_config (db, "testkey2", &val));
36 printf("testkey2 = %s\n", val);
45 test_expect_equal_file EXPECTED OUTPUT
48 test_begin_subtest "notmuch_database_get_config_list: empty list"
49 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
51 notmuch_config_list_t *list;
52 EXPECT0(notmuch_database_get_config_list (db, "nonexistent", &list));
53 printf("valid = %d\n", notmuch_config_list_valid (list));
54 notmuch_config_list_destroy (list);
62 test_expect_equal_file EXPECTED OUTPUT
65 test_begin_subtest "notmuch_database_get_config_list: all pairs"
66 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
68 notmuch_config_list_t *list;
69 EXPECT0(notmuch_database_set_config (db, "zzzafter", "afterval"));
70 EXPECT0(notmuch_database_set_config (db, "aaabefore", "beforeval"));
71 EXPECT0(notmuch_database_get_config_list (db, "", &list));
72 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
73 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
75 notmuch_config_list_destroy (list);
86 test_expect_equal_file EXPECTED OUTPUT
88 test_begin_subtest "notmuch_database_get_config_list: one prefix"
89 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
91 notmuch_config_list_t *list;
92 EXPECT0(notmuch_database_get_config_list (db, "testkey", &list));
93 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
94 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
96 notmuch_config_list_destroy (list);
105 test_expect_equal_file EXPECTED OUTPUT
107 test_begin_subtest "dump config"
108 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
110 EXPECT0(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
113 notmuch dump --include=config >OUTPUT
114 cat <<'EOF' >EXPECTED
115 #notmuch-dump batch-tag:3 config
116 #@ aaabefore beforeval
117 #@ key%20with%20spaces value,%20with,%20spaces%21
118 #@ testkey1 testvalue1
119 #@ testkey2 testvalue2
122 test_expect_equal_file EXPECTED OUTPUT
124 test_begin_subtest "restore config"
125 notmuch dump --include=config >EXPECTED
126 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
128 EXPECT0(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));
131 notmuch restore --include=config <EXPECTED
132 notmuch dump --include=config >OUTPUT
133 test_expect_equal_file EXPECTED OUTPUT