3 # Copyright (c) 2018 rhn
7 test_description="Lifetime constraints for library"
9 . $(dirname "$0")/test-lib.sh || exit 1
11 add_email_corpus threading
13 test_begin_subtest "building database"
14 test_expect_success "NOTMUCH_NEW"
16 test_begin_subtest "Message outlives parent Messages from replies"
18 test_C ${MAIL_DIR} <<'EOF'
22 int main (int argc, char** argv)
24 notmuch_database_t *db;
25 notmuch_status_t stat;
26 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
27 if (stat != NOTMUCH_STATUS_SUCCESS) {
28 fprintf (stderr, "error opening database: %d\n", stat);
32 notmuch_query_t *query = notmuch_query_create (db, "id:B00-root@example.org");
33 notmuch_threads_t *threads;
35 stat = notmuch_query_search_threads (query, &threads);
36 if (stat != NOTMUCH_STATUS_SUCCESS) {
37 fprintf (stderr, "error querying threads: %d\n", stat);
41 if (!notmuch_threads_valid (threads)) {
42 fprintf (stderr, "invalid threads");
46 notmuch_thread_t *thread = notmuch_threads_get (threads);
47 notmuch_messages_t *messages = notmuch_thread_get_messages (thread);
49 if (!notmuch_messages_valid (messages)) {
50 fprintf (stderr, "invalid messages");
54 notmuch_message_t *message = notmuch_messages_get (messages);
55 notmuch_messages_t *replies = notmuch_message_get_replies (message);
56 if (!notmuch_messages_valid (replies)) {
57 fprintf (stderr, "invalid replies");
61 notmuch_message_t *reply = notmuch_messages_get (replies);
63 notmuch_messages_destroy (replies); // the reply should not get destroyed here
64 notmuch_message_destroy (message);
65 notmuch_messages_destroy (messages); // nor here
67 const char *mid = notmuch_message_get_message_id (reply); // should not crash when accessing
68 fprintf (stdout, "Reply id: %s\n", mid);
69 notmuch_message_destroy (reply);
70 notmuch_thread_destroy (thread); // this destroys the reply
71 notmuch_threads_destroy (threads);
72 notmuch_query_destroy (query);
73 notmuch_database_destroy (db);
78 Reply id: B01-child@example.org
81 test_expect_equal_file EXPECTED OUTPUT