From: david@tethera.net
To: notmuch@notmuchmail.org
Cc: David Bremner <bremner@debian.org>
Subject: [Patch v3 4/6] test: add database routines for testing.
Date: Sun, 19 Aug 2012 15:18:32 +0200 [thread overview]
Message-ID: <1345382314-5330-5-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1345382314-5330-1-git-send-email-david@tethera.net>
From: David Bremner <bremner@debian.org>
Initially, provide a way to create "stub" messages in the notmuch
database without corresponding files. This is essentially cut and
paste from lib/database.cc. This is a seperate file since we don't
want to export these symbols from libnotmuch or bloat the library with
non-exported code.
---
test/Makefile.local | 1 +
test/database-test.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
test/database-test.h | 21 +++++++++++++++
3 files changed, 94 insertions(+)
create mode 100644 test/database-test.c
create mode 100644 test/database-test.h
diff --git a/test/Makefile.local b/test/Makefile.local
index 2622185..bb67ded 100644
--- a/test/Makefile.local
+++ b/test/Makefile.local
@@ -41,4 +41,5 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
$(dir)/symbol-test $(dir)/symbol-test.o \
$(dir)/arg-test $(dir)/arg-test.o \
$(dir)/hex-xcode $(dir)/hex-xcode.o \
+ $(dir)/database-test.o \
$(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
diff --git a/test/database-test.c b/test/database-test.c
new file mode 100644
index 0000000..f0f1c8e
--- /dev/null
+++ b/test/database-test.c
@@ -0,0 +1,72 @@
+/*
+ * Database routines intended only for testing, not exported from
+ * library.
+ *
+ * Copyright (c) 2012 David Bremner
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: David Bremner <david@tethera.net>
+ */
+
+#include "notmuch-private.h"
+#include "database-test.h"
+
+notmuch_status_t
+notmuch_database_add_stub_message (notmuch_database_t *notmuch,
+ const char *message_id,
+ const char **tags)
+{
+ const char **tag;
+ notmuch_status_t ret;
+ notmuch_private_status_t private_status;
+ notmuch_message_t *message;
+
+ ret = _notmuch_database_ensure_writable (notmuch);
+ if (ret)
+ return ret;
+
+ message = _notmuch_message_create_for_message_id (notmuch,
+ message_id,
+ &private_status);
+ if (message == NULL) {
+ return COERCE_STATUS (private_status,
+ "Unexpected status value from _notmuch_message_create_for_message_id");
+
+ }
+
+ if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
+ _notmuch_message_add_term (message, "type", "mail");
+ } else {
+ return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
+ }
+
+ if (tags) {
+ ret = notmuch_message_freeze (message);
+ if (ret)
+ return ret;
+
+ for (tag = tags; *tag; tag++) {
+ ret = notmuch_message_add_tag (message, *tag);
+ if (ret)
+ return ret;
+ }
+ }
+
+ ret = notmuch_message_thaw (message);
+ if (ret)
+ return ret;
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
diff --git a/test/database-test.h b/test/database-test.h
new file mode 100644
index 0000000..84f7988
--- /dev/null
+++ b/test/database-test.h
@@ -0,0 +1,21 @@
+#ifndef _DATABASE_TEST_H
+#define _DATABASE_TEST_H
+/* Add a new stub message to the given notmuch database.
+ *
+ * At least the following return values are possible:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
+ *
+ * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
+ * ID as another message already in the database.
+ *
+ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
+ * mode so no message can be added.
+ */
+
+notmuch_status_t
+notmuch_database_add_stub_message (notmuch_database_t *database,
+ const char *message_id,
+ const char **tag_list);
+
+#endif
--
1.7.10.4
next prev parent reply other threads:[~2012-08-20 7:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-19 13:18 random corpus generator, v3 david
2012-08-19 13:18 ` [Patch v3 1/6] hex-escape: (en|de)code strings to/from restricted character set david
2012-08-19 13:18 ` [Patch v3 2/6] test/hex-xcode: new test binary david
2012-08-19 13:18 ` [Patch v3 3/6] test/hex-escaping: new test for hex escaping routines david
2012-08-19 13:18 ` david [this message]
2012-08-19 13:18 ` [Patch v3 5/6] test: add generator for random "stub" messages david
2012-09-08 13:38 ` Tomi Ollila
2012-08-19 13:18 ` [Patch v3 6/6] test: add broken roundtrip test david
2012-10-20 4:16 ` random corpus generator, v3 Ethan Glasser-Camp
-- strict thread matches above, loose matches on Subject: below --
2012-12-02 13:33 v3 of testing for new tagging/dump/restore david
2012-12-02 13:33 ` [patch v3 4/6] test: add database routines for testing david
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345382314-5330-5-git-send-email-david@tethera.net \
--to=david@tethera.net \
--cc=bremner@debian.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).