From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id A288D6DE00F5 for ; Mon, 17 Dec 2018 10:06:32 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.362 X-Spam-Level: X-Spam-Status: No, score=0.362 tagged_above=-999 required=5 tests=[KHOP_DYNAMIC=0.001, RDNS_DYNAMIC=0.363, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AGpykhJ9kHzS for ; Mon, 17 Dec 2018 10:06:31 -0800 (PST) Received: from porcupinefactory.org (91.218.216.54.siec.idealan.pl [91.218.216.54]) by arlo.cworth.org (Postfix) with ESMTPS id E5C906DE0140 for ; Mon, 17 Dec 2018 10:06:30 -0800 (PST) Received: from movable.Speedport_W_723V_1_46_000 (unknown [192.168.6.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by porcupinefactory.org (Postfix) with ESMTPSA id A93FF675583; Mon, 17 Dec 2018 18:57:25 +0100 (CET) From: rhn To: notmuch@notmuchmail.org Cc: rhn Subject: [PATCH 2/3] test: Check for replies obeying lifetime guarantees Date: Mon, 17 Dec 2018 17:57:47 +0000 Message-Id: <20181217175748.10814-3-gihu.rhn@porcupinefactory.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181217175748.10814-1-gihu.rhn@porcupinefactory.org> References: <20181217175748.10814-1-gihu.rhn@porcupinefactory.org> X-Mailman-Approved-At: Mon, 17 Dec 2018 10:14:15 -0800 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2018 18:06:32 -0000 The test attempts to check that a message coming from a thread outlives its messages list and gets destroyed together with the thread. --- test/T720-lib-lifetime.sh | 83 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 test/T720-lib-lifetime.sh diff --git a/test/T720-lib-lifetime.sh b/test/T720-lib-lifetime.sh new file mode 100755 index 00000000..3d94d4df --- /dev/null +++ b/test/T720-lib-lifetime.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2018 rhn +# + + +test_description="Lifetime constraints for library" + +. $(dirname "$0")/test-lib.sh || exit 1 + +add_email_corpus threading + +test_begin_subtest "building database" +test_expect_success "NOTMUCH_NEW" + +test_begin_subtest "Message outlives parent Messages from replies" + +test_C ${MAIL_DIR} <<'EOF' +#include +#include +#include +int main (int argc, char** argv) +{ + notmuch_database_t *db; + notmuch_status_t stat; + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db); + if (stat != NOTMUCH_STATUS_SUCCESS) { + fprintf (stderr, "error opening database: %d\n", stat); + exit (1); + } + + notmuch_query_t *query = notmuch_query_create (db, "id:B00-root@example.org"); + notmuch_threads_t *threads; + + stat = notmuch_query_search_threads (query, &threads); + if (stat != NOTMUCH_STATUS_SUCCESS) { + fprintf (stderr, "error querying threads: %d\n", stat); + exit (1); + } + + if (!notmuch_threads_valid (threads)) { + fprintf (stderr, "invalid threads"); + exit (1); + } + + notmuch_thread_t *thread = notmuch_threads_get (threads); + notmuch_messages_t *messages = notmuch_thread_get_messages (thread); + + if (!notmuch_messages_valid (messages)) { + fprintf (stderr, "invalid messages"); + exit (1); + } + + notmuch_message_t *message = notmuch_messages_get (messages); + notmuch_messages_t *replies = notmuch_message_get_replies (message); + if (!notmuch_messages_valid (replies)) { + fprintf (stderr, "invalid replies"); + exit (1); + } + + notmuch_message_t *reply = notmuch_messages_get (replies); + + notmuch_messages_destroy (replies); // the reply should not get destroyed here + notmuch_message_destroy (message); + notmuch_messages_destroy (messages); // nor here + + const char *mid = notmuch_message_get_message_id (reply); // should not crash when accessing + fprintf (stdout, "Reply id: %s\n", mid); + notmuch_message_destroy (reply); + notmuch_thread_destroy (thread); // this destroys the reply + notmuch_threads_destroy (threads); + notmuch_query_destroy (query); + notmuch_database_destroy (db); +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +Reply id: B01-child@example.org +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_done -- 2.17.2