unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* batch 9: API cleanup for exception handling
@ 2020-07-24 11:13 David Bremner
  2020-07-24 11:13 ` [PATCH 1/8] test: regression test for n_t_get_thread_id David Bremner
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:13 UTC (permalink / raw)
  To: notmuch

This is another batch where everything seems to just work (TM), which
is great because no API changes are needed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/8] test: regression test for n_t_get_thread_id
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
@ 2020-07-24 11:13 ` David Bremner
  2020-07-24 11:14 ` [PATCH 2/8] test: add regression test for n_thread_get_total_{messages,files} David Bremner
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:13 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This is just cached data, so as long as we don't prematurely free
anything, it should be fine.
---
 test/T568-lib-thread.sh | 63 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100755 test/T568-lib-thread.sh

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
new file mode 100755
index 00000000..00755834
--- /dev/null
+++ b/test/T568-lib-thread.sh
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+test_description="API tests for notmuch_thread_*"
+
+. $(dirname "$0")/test-lib.sh || exit 1
+
+add_email_corpus
+
+test_begin_subtest "building database"
+test_expect_success "NOTMUCH_NEW"
+
+cat <<'EOF' > c_tail
+   if (stat) {
+       const char *stat_str = notmuch_database_status_string (db);
+       if (stat_str)
+           fputs (stat_str, stderr);
+    }
+
+}
+EOF
+
+cat <<EOF > c_head
+#include <stdio.h>
+#include <notmuch.h>
+#include <notmuch-test.h>
+int main (int argc, char** argv)
+{
+   notmuch_database_t *db;
+   notmuch_status_t stat;
+   char *msg = NULL;
+   notmuch_thread_t *thread = NULL;
+   notmuch_threads_t *threads = NULL;
+   notmuch_query_t *query = NULL;
+   const char *id = "thread:0000000000000009";
+
+   stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
+   if (stat != NOTMUCH_STATUS_SUCCESS) {
+     fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
+     exit (1);
+   }
+
+   query = notmuch_query_create (db, id);
+   EXPECT0(notmuch_query_search_threads (query, &threads));
+   thread = notmuch_threads_get (threads);
+   EXPECT0(notmuch_database_close (db));
+EOF
+
+test_begin_subtest "get thread-id from closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        const char *id2;
+        id2 = notmuch_thread_get_thread_id (thread);
+        printf("%d\n%s\n", thread != NULL, id2);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+0000000000000009
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/8] test: add regression test for n_thread_get_total_{messages,files}
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
  2020-07-24 11:13 ` [PATCH 1/8] test: regression test for n_t_get_thread_id David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-24 11:14 ` [PATCH 3/8] test: add regression tests for n_thread_get_toplevel_messages David Bremner
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This is returning cached info, so does not need to access the (closed)
database.
---
 test/T568-lib-thread.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 00755834..5816cfbc 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -60,4 +60,36 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "get total messages with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        int count;
+        count = notmuch_thread_get_total_messages (thread);
+        printf("%d\n%d\n", thread != NULL, count);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+7
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "get total files with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        int count;
+        count = notmuch_thread_get_total_files (thread);
+        printf("%d\n%d\n", thread != NULL, count);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+7
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/8] test: add regression tests for n_thread_get_toplevel_messages
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
  2020-07-24 11:13 ` [PATCH 1/8] test: regression test for n_t_get_thread_id David Bremner
  2020-07-24 11:14 ` [PATCH 2/8] test: add regression test for n_thread_get_total_{messages,files} David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-24 11:14 ` [PATCH 4/8] test: add regression test for n_t_get_messages David Bremner
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

Include a test for the previously omitted non-trivial code path for
notmuch_thread_get_replies.
---
 test/T566-lib-message.sh |  1 -
 test/T568-lib-thread.sh  | 80 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/test/T566-lib-message.sh b/test/T566-lib-message.sh
index 7a351725..4c9fc0df 100755
--- a/test/T566-lib-message.sh
+++ b/test/T566-lib-message.sh
@@ -93,7 +93,6 @@ A Xapian exception occurred at lib/message.cc:XXX: Database has been closed
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-# XXX TODO: test on a message from notmuch_thread_get_toplevel_messages
 # XXX this test only tests the trivial code path
 test_begin_subtest "Handle getting replies from closed database"
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 5816cfbc..4703950b 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -92,4 +92,84 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "get top level messages with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        notmuch_messages_t *messages;
+        messages = notmuch_thread_get_toplevel_messages (thread);
+        printf("%d\n%d\n", thread != NULL, messages != NULL);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "iterate over level messages with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+      notmuch_messages_t *messages;
+      for (messages = notmuch_thread_get_toplevel_messages (thread);
+           notmuch_messages_valid (messages);
+           notmuch_messages_move_to_next (messages)) {
+        notmuch_message_t *message = notmuch_messages_get (messages);
+        const char *mid = notmuch_message_get_message_id (message);
+        printf("%s\n", mid);
+      }
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+20091117190054.GU3165@dottiness.seas.harvard.edu
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "iterate over level messages with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+      notmuch_messages_t *messages;
+      for (messages = notmuch_thread_get_toplevel_messages (thread);
+           notmuch_messages_valid (messages);
+           notmuch_messages_move_to_next (messages)) {
+        notmuch_message_t *message = notmuch_messages_get (messages);
+        const char *mid = notmuch_message_get_message_id (message);
+        printf("%s\n", mid);
+      }
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+20091117190054.GU3165@dottiness.seas.harvard.edu
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "iterate over replies with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+      notmuch_messages_t *messages = notmuch_thread_get_toplevel_messages (thread);
+      notmuch_message_t *message = notmuch_messages_get (messages);
+      notmuch_messages_t *replies;
+      for (replies = notmuch_message_get_replies (message);
+           notmuch_messages_valid (replies);
+           notmuch_messages_move_to_next (replies)) {
+        notmuch_message_t *message = notmuch_messages_get (replies);
+        const char *mid = notmuch_message_get_message_id (message);
+
+        printf("%s\n", mid);
+      }
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+87iqd9rn3l.fsf@vertex.dottedmag
+87ocn0qh6d.fsf@yoom.home.cworth.org
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/8] test: add regression test for n_t_get_messages
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
                   ` (2 preceding siblings ...)
  2020-07-24 11:14 ` [PATCH 3/8] test: add regression tests for n_thread_get_toplevel_messages David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-24 11:14 ` [PATCH 5/8] test: add regression tests for n_t_get_{authors, subject} David Bremner
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This is similar to the case of toplevel messages. Currently everything
is cached, so no database access is necessary. This might change in
the future, but it should not crash in either case.
---
 test/T568-lib-thread.sh | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 4703950b..c7d4f26b 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -172,4 +172,30 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "iterate over all messages with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+      notmuch_messages_t *messages;
+      for (messages = notmuch_thread_get_messages (thread);
+           notmuch_messages_valid (messages);
+           notmuch_messages_move_to_next (messages)) {
+        notmuch_message_t *message = notmuch_messages_get (messages);
+        const char *mid = notmuch_message_get_message_id (message);
+        printf("%s\n", mid);
+      }
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+20091117190054.GU3165@dottiness.seas.harvard.edu
+87iqd9rn3l.fsf@vertex.dottedmag
+20091117203301.GV3165@dottiness.seas.harvard.edu
+87fx8can9z.fsf@vertex.dottedmag
+yunaayketfm.fsf@aiko.keithp.com
+20091118005040.GA25380@dottiness.seas.harvard.edu
+87ocn0qh6d.fsf@yoom.home.cworth.org
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/8] test: add regression tests for n_t_get_{authors, subject}
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
                   ` (3 preceding siblings ...)
  2020-07-24 11:14 ` [PATCH 4/8] test: add regression test for n_t_get_messages David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-24 11:14 ` [PATCH 6/8] test: add regression tests for oldest and newest dates David Bremner
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This is returning explicitely cached data, so no database access is needed.
---
 test/T568-lib-thread.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index c7d4f26b..0f9fa443 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -198,4 +198,37 @@ yunaayketfm.fsf@aiko.keithp.com
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "get authors from closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        const char *authors;
+        authors = notmuch_thread_get_authors (thread);
+        printf("%d\n%s\n", thread != NULL, authors);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "get subject from closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        const char *subject;
+        subject = notmuch_thread_get_subject (thread);
+        printf("%d\n%s\n", thread != NULL, subject);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+[notmuch] Working with Maildir storage?
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/8] test: add regression tests for oldest and newest dates
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
                   ` (4 preceding siblings ...)
  2020-07-24 11:14 ` [PATCH 5/8] test: add regression tests for n_t_get_{authors, subject} David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-24 11:14 ` [PATCH 7/8] test: regression test for n_thread_get_tags David Bremner
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

These are strictly to watch for crashes, so don't be too fussy about
the actual timestamps.
---
 test/T568-lib-thread.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 0f9fa443..3eb28f3b 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -230,5 +230,37 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "oldest date from closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        time_t stamp;
+        stamp = notmuch_thread_get_oldest_date (thread);
+        printf("%d\n%d\n", thread != NULL, stamp > 0);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "newest date from closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        time_t stamp;
+        stamp = notmuch_thread_get_newest_date (thread);
+        printf("%d\n%d\n", thread != NULL, stamp > 0);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/8] test: regression test for n_thread_get_tags
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
                   ` (5 preceding siblings ...)
  2020-07-24 11:14 ` [PATCH 6/8] test: add regression tests for oldest and newest dates David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-24 11:14 ` [PATCH 8/8] test: destroy thread from closed database David Bremner
  2020-07-31 12:15 ` batch 9: API cleanup for exception handling David Bremner
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

Code is taken from the API docs, with the twist that the underlying
database is closed. Not crashing is the main point.
---
 test/T568-lib-thread.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 3eb28f3b..82e4ecb8 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -262,5 +262,28 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "iterate tags from closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+      notmuch_tags_t *tags;
+      const char *tag;
+      for (tags = notmuch_thread_get_tags (thread);
+           notmuch_tags_valid (tags);
+           notmuch_tags_move_to_next (tags))
+        {
+          tag = notmuch_tags_get (tags);
+          printf ("%s\n", tag);
+        }
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+inbox
+signed
+unread
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/8] test: destroy thread from closed database
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
                   ` (6 preceding siblings ...)
  2020-07-24 11:14 ` [PATCH 7/8] test: regression test for n_thread_get_tags David Bremner
@ 2020-07-24 11:14 ` David Bremner
  2020-07-31 12:15 ` batch 9: API cleanup for exception handling David Bremner
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-24 11:14 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

Check for (non)-crash.
---
 test/T568-lib-thread.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 82e4ecb8..66066854 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -285,5 +285,19 @@ unread
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "destroy thread with closed database"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        time_t stamp;
+        notmuch_thread_destroy (thread);
+        printf("SUCCESS\n");
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+SUCCESS
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: batch 9: API cleanup for exception handling
  2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
                   ` (7 preceding siblings ...)
  2020-07-24 11:14 ` [PATCH 8/8] test: destroy thread from closed database David Bremner
@ 2020-07-31 12:15 ` David Bremner
  8 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2020-07-31 12:15 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> This is another batch where everything seems to just work (TM), which
> is great because no API changes are needed.
>

applied to master.

d

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-07-31 12:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 11:13 batch 9: API cleanup for exception handling David Bremner
2020-07-24 11:13 ` [PATCH 1/8] test: regression test for n_t_get_thread_id David Bremner
2020-07-24 11:14 ` [PATCH 2/8] test: add regression test for n_thread_get_total_{messages,files} David Bremner
2020-07-24 11:14 ` [PATCH 3/8] test: add regression tests for n_thread_get_toplevel_messages David Bremner
2020-07-24 11:14 ` [PATCH 4/8] test: add regression test for n_t_get_messages David Bremner
2020-07-24 11:14 ` [PATCH 5/8] test: add regression tests for n_t_get_{authors, subject} David Bremner
2020-07-24 11:14 ` [PATCH 6/8] test: add regression tests for oldest and newest dates David Bremner
2020-07-24 11:14 ` [PATCH 7/8] test: regression test for n_thread_get_tags David Bremner
2020-07-24 11:14 ` [PATCH 8/8] test: destroy thread from closed database David Bremner
2020-07-31 12:15 ` batch 9: API cleanup for exception handling David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).