]> git.notmuchmail.org Git - notmuch/blob - test/T568-lib-thread.sh
5816cfbcbc9b6090bf6de6ad5ad0f4c2d33bce12
[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_done