]> git.notmuchmail.org Git - notmuch/blob - test/T590-libconfig.sh
lib: provide config API
[notmuch] / test / T590-libconfig.sh
1 #!/usr/bin/env bash
2 test_description="library config API"
3
4 . ./test-lib.sh || exit 1
5
6 add_email_corpus
7
8 cat <<EOF > c_head
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <notmuch.h>
13
14 void run(int line, notmuch_status_t ret)
15 {
16    if (ret) {
17         fprintf (stderr, "line %d: %s\n", line, ret);
18         exit (1);
19    }
20 }
21
22 #define RUN(v)  run(__LINE__, v);
23
24 int main (int argc, char** argv)
25 {
26    notmuch_database_t *db;
27    char *val;
28    notmuch_status_t stat;
29
30    RUN(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
31
32 EOF
33
34 cat <<EOF > c_tail
35    RUN(notmuch_database_destroy(db));
36 }
37 EOF
38
39 test_begin_subtest "notmuch_database_{set,get}_config"
40 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
41 {
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);
48 }
49 EOF
50 cat <<'EOF' >EXPECTED
51 == stdout ==
52 testkey1 = testvalue1
53 testkey2 = testvalue2
54 == stderr ==
55 EOF
56 test_expect_equal_file EXPECTED OUTPUT
57
58 test_done