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