]> git.notmuchmail.org Git - notmuch/blob - test/T610-message-property.sh
lib: basic message-property API
[notmuch] / test / T610-message-property.sh
1 #!/usr/bin/env bash
2 test_description="message property 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-test.h>
13
14 int main (int argc, char** argv)
15 {
16    notmuch_database_t *db;
17    notmuch_message_t *message = NULL;
18    const char *val;
19    notmuch_status_t stat;
20
21    EXPECT0(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
22    EXPECT0(notmuch_database_find_message(db, "4EFC743A.3060609@april.org", &message));
23    if (message == NULL) {
24         fprintf (stderr, "unable to find message");
25         exit (1);
26    }
27 EOF
28
29 cat <<EOF > c_tail
30    EXPECT0(notmuch_database_destroy(db));
31 }
32 EOF
33
34 test_begin_subtest "notmuch_message_{add,get,remove}_property"
35 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
36 {
37    EXPECT0(notmuch_message_add_property (message, "testkey1", "testvalue1"));
38    EXPECT0(notmuch_message_get_property (message, "testkey1", &val));
39    printf("testkey1[1] = %s\n", val);
40    EXPECT0(notmuch_message_add_property (message, "testkey2", "this value has spaces and = sign"));
41    EXPECT0(notmuch_message_get_property (message, "testkey1", &val));
42    printf("testkey1[2] = %s\n", val);
43    EXPECT0(notmuch_message_get_property (message, "testkey1", &val));
44
45    EXPECT0(notmuch_message_get_property (message, "testkey2", &val));
46    printf("testkey2 = %s\n", val);
47
48    /* Add second value for key */
49    EXPECT0(notmuch_message_add_property (message, "testkey2", "zztestvalue3"));
50    EXPECT0(notmuch_message_get_property (message, "testkey2", &val));
51    printf("testkey2 = %s\n", val);
52
53    /* remove first value for key */
54    EXPECT0(notmuch_message_remove_property (message, "testkey2", "this value has spaces and = sign"));
55    EXPECT0(notmuch_message_get_property (message, "testkey2", &val));
56    printf("testkey2 = %s\n", val);
57
58    /* remove non-existant value for key */
59    EXPECT0(notmuch_message_remove_property (message, "testkey2", "this value has spaces and = sign"));
60    EXPECT0(notmuch_message_get_property (message, "testkey2", &val));
61    printf("testkey2 = %s\n", val);
62
63    /* remove only value for key */
64    EXPECT0(notmuch_message_remove_property (message, "testkey2", "zztestvalue3"));
65    EXPECT0(notmuch_message_get_property (message, "testkey2", &val));
66    printf("testkey2 = %s\n", val == NULL ? "NULL" : val);
67 }
68 EOF
69 cat <<'EOF' >EXPECTED
70 == stdout ==
71 testkey1[1] = testvalue1
72 testkey1[2] = testvalue1
73 testkey2 = this value has spaces and = sign
74 testkey2 = this value has spaces and = sign
75 testkey2 = zztestvalue3
76 testkey2 = zztestvalue3
77 testkey2 = NULL
78 == stderr ==
79 EOF
80 test_expect_equal_file EXPECTED OUTPUT
81
82
83
84 test_done