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;
28 stat = notmuch_database_open_with_config (argv[1],
29 NOTMUCH_DATABASE_MODE_READ_ONLY,
31 if (msg) fputs (msg, stderr);
33 if (stat != NOTMUCH_STATUS_SUCCESS) {
34 fprintf (stderr, "error opening database: %d\n", stat);
38 notmuch_query_t *query = notmuch_query_create (db, "id:B00-root@example.org");
39 notmuch_threads_t *threads;
41 stat = notmuch_query_search_threads (query, &threads);
42 if (stat != NOTMUCH_STATUS_SUCCESS) {
43 fprintf (stderr, "error querying threads: %d\n", stat);
47 if (!notmuch_threads_valid (threads)) {
48 fprintf (stderr, "invalid threads");
52 notmuch_thread_t *thread = notmuch_threads_get (threads);
53 notmuch_messages_t *messages = notmuch_thread_get_messages (thread);
55 if (!notmuch_messages_valid (messages)) {
56 fprintf (stderr, "invalid messages");
60 notmuch_message_t *message = notmuch_messages_get (messages);
61 notmuch_messages_t *replies = notmuch_message_get_replies (message);
62 if (!notmuch_messages_valid (replies)) {
63 fprintf (stderr, "invalid replies");
67 notmuch_message_t *reply = notmuch_messages_get (replies);
69 notmuch_messages_destroy (replies); // the reply should not get destroyed here
70 notmuch_message_destroy (message);
71 notmuch_messages_destroy (messages); // nor here
73 const char *mid = notmuch_message_get_message_id (reply); // should not crash when accessing
74 fprintf (stdout, "Reply id: %s\n", mid);
75 notmuch_message_destroy (reply);
76 notmuch_thread_destroy (thread); // this destroys the reply
77 notmuch_threads_destroy (threads);
78 notmuch_query_destroy (query);
79 notmuch_database_destroy (db);
84 Reply id: B01-child@example.org
87 test_expect_equal_file EXPECTED OUTPUT