]> git.notmuchmail.org Git - notmuch/blob - test/T568-lib-thread.sh
test: add regression test for n_t_get_messages
[notmuch] / test / T568-lib-thread.sh
1 #!/usr/bin/env bash
2 test_description="API tests for notmuch_thread_*"
3
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 add_email_corpus
7
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
10
11 cat <<'EOF' > c_tail
12    if (stat) {
13        const char *stat_str = notmuch_database_status_string (db);
14        if (stat_str)
15            fputs (stat_str, stderr);
16     }
17
18 }
19 EOF
20
21 cat <<EOF > c_head
22 #include <stdio.h>
23 #include <notmuch.h>
24 #include <notmuch-test.h>
25 int main (int argc, char** argv)
26 {
27    notmuch_database_t *db;
28    notmuch_status_t stat;
29    char *msg = NULL;
30    notmuch_thread_t *thread = NULL;
31    notmuch_threads_t *threads = NULL;
32    notmuch_query_t *query = NULL;
33    const char *id = "thread:0000000000000009";
34
35    stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
36    if (stat != NOTMUCH_STATUS_SUCCESS) {
37      fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
38      exit (1);
39    }
40
41    query = notmuch_query_create (db, id);
42    EXPECT0(notmuch_query_search_threads (query, &threads));
43    thread = notmuch_threads_get (threads);
44    EXPECT0(notmuch_database_close (db));
45 EOF
46
47 test_begin_subtest "get thread-id from closed database"
48 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
49     {
50         const char *id2;
51         id2 = notmuch_thread_get_thread_id (thread);
52         printf("%d\n%s\n", thread != NULL, id2);
53     }
54 EOF
55 cat <<EOF > EXPECTED
56 == stdout ==
57 1
58 0000000000000009
59 == stderr ==
60 EOF
61 test_expect_equal_file EXPECTED OUTPUT
62
63 test_begin_subtest "get total messages with closed database"
64 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
65     {
66         int count;
67         count = notmuch_thread_get_total_messages (thread);
68         printf("%d\n%d\n", thread != NULL, count);
69     }
70 EOF
71 cat <<EOF > EXPECTED
72 == stdout ==
73 1
74 7
75 == stderr ==
76 EOF
77 test_expect_equal_file EXPECTED OUTPUT
78
79 test_begin_subtest "get total files with closed database"
80 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
81     {
82         int count;
83         count = notmuch_thread_get_total_files (thread);
84         printf("%d\n%d\n", thread != NULL, count);
85     }
86 EOF
87 cat <<EOF > EXPECTED
88 == stdout ==
89 1
90 7
91 == stderr ==
92 EOF
93 test_expect_equal_file EXPECTED OUTPUT
94
95 test_begin_subtest "get top level messages with closed database"
96 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
97     {
98         notmuch_messages_t *messages;
99         messages = notmuch_thread_get_toplevel_messages (thread);
100         printf("%d\n%d\n", thread != NULL, messages != NULL);
101     }
102 EOF
103 cat <<EOF > EXPECTED
104 == stdout ==
105 1
106 1
107 == stderr ==
108 EOF
109 test_expect_equal_file EXPECTED OUTPUT
110
111 test_begin_subtest "iterate over level messages with closed database"
112 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
113     {
114       notmuch_messages_t *messages;
115       for (messages = notmuch_thread_get_toplevel_messages (thread);
116            notmuch_messages_valid (messages);
117            notmuch_messages_move_to_next (messages)) {
118         notmuch_message_t *message = notmuch_messages_get (messages);
119         const char *mid = notmuch_message_get_message_id (message);
120         printf("%s\n", mid);
121       }
122     }
123 EOF
124 cat <<EOF > EXPECTED
125 == stdout ==
126 20091117190054.GU3165@dottiness.seas.harvard.edu
127 == stderr ==
128 EOF
129 test_expect_equal_file EXPECTED OUTPUT
130
131 test_begin_subtest "iterate over level messages with closed database"
132 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
133     {
134       notmuch_messages_t *messages;
135       for (messages = notmuch_thread_get_toplevel_messages (thread);
136            notmuch_messages_valid (messages);
137            notmuch_messages_move_to_next (messages)) {
138         notmuch_message_t *message = notmuch_messages_get (messages);
139         const char *mid = notmuch_message_get_message_id (message);
140         printf("%s\n", mid);
141       }
142     }
143 EOF
144 cat <<EOF > EXPECTED
145 == stdout ==
146 20091117190054.GU3165@dottiness.seas.harvard.edu
147 == stderr ==
148 EOF
149 test_expect_equal_file EXPECTED OUTPUT
150
151 test_begin_subtest "iterate over replies with closed database"
152 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
153     {
154       notmuch_messages_t *messages = notmuch_thread_get_toplevel_messages (thread);
155       notmuch_message_t *message = notmuch_messages_get (messages);
156       notmuch_messages_t *replies;
157       for (replies = notmuch_message_get_replies (message);
158            notmuch_messages_valid (replies);
159            notmuch_messages_move_to_next (replies)) {
160         notmuch_message_t *message = notmuch_messages_get (replies);
161         const char *mid = notmuch_message_get_message_id (message);
162
163         printf("%s\n", mid);
164       }
165     }
166 EOF
167 cat <<EOF > EXPECTED
168 == stdout ==
169 87iqd9rn3l.fsf@vertex.dottedmag
170 87ocn0qh6d.fsf@yoom.home.cworth.org
171 == stderr ==
172 EOF
173 test_expect_equal_file EXPECTED OUTPUT
174
175 test_begin_subtest "iterate over all messages with closed database"
176 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
177     {
178       notmuch_messages_t *messages;
179       for (messages = notmuch_thread_get_messages (thread);
180            notmuch_messages_valid (messages);
181            notmuch_messages_move_to_next (messages)) {
182         notmuch_message_t *message = notmuch_messages_get (messages);
183         const char *mid = notmuch_message_get_message_id (message);
184         printf("%s\n", mid);
185       }
186     }
187 EOF
188 cat <<EOF > EXPECTED
189 == stdout ==
190 20091117190054.GU3165@dottiness.seas.harvard.edu
191 87iqd9rn3l.fsf@vertex.dottedmag
192 20091117203301.GV3165@dottiness.seas.harvard.edu
193 87fx8can9z.fsf@vertex.dottedmag
194 yunaayketfm.fsf@aiko.keithp.com
195 20091118005040.GA25380@dottiness.seas.harvard.edu
196 87ocn0qh6d.fsf@yoom.home.cworth.org
197 == stderr ==
198 EOF
199 test_expect_equal_file EXPECTED OUTPUT
200
201 test_done