[Patch v2 04/17] test: add database routines for testing
authordavid <david@tethera.net>
Sat, 24 Nov 2012 21:20:04 +0000 (17:20 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:51 +0000 (09:50 -0800)
c2/e92a806609bcaa0aef1e1c28dff0caa2728c54 [new file with mode: 0644]

diff --git a/c2/e92a806609bcaa0aef1e1c28dff0caa2728c54 b/c2/e92a806609bcaa0aef1e1c28dff0caa2728c54
new file mode 100644 (file)
index 0000000..d85dc22
--- /dev/null
@@ -0,0 +1,187 @@
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 35EF3431FC7\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id orfxzOxrsRwi for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Nov 2012 13:20:37 -0800 (PST)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+       (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 43135431FCB\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:33 -0800 (PST)\r
+Received: from fctnnbsc30w-156034089108.dhcp-dynamic.fibreop.nb.bellaliant.net\r
+       ([156.34.89.108] helo=zancas.localnet)\r
+       by tesseract.cs.unb.ca with esmtpsa\r
+       (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1TcN9L-0006SK-Ih; Sat, 24 Nov 2012 17:20:32 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1TcN9G-0008Cd-3a; Sat, 24 Nov 2012 17:20:26 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v2 04/17] test: add database routines for testing\r
+Date: Sat, 24 Nov 2012 17:20:04 -0400\r
+Message-Id: <1353792017-31459-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1353792017-31459-1-git-send-email-david@tethera.net>\r
+References: <1353792017-31459-1-git-send-email-david@tethera.net>\r
+X-Spam_bar: -\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 24 Nov 2012 21:20:40 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+Initially, provide a way to create "stub" messages in the notmuch\r
+database without corresponding files.  This is essentially cut and\r
+paste from lib/database.cc. This is a seperate file since we don't\r
+want to export these symbols from libnotmuch or bloat the library with\r
+non-exported code.\r
+---\r
+ test/Makefile.local  |    1 +\r
+ test/database-test.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ test/database-test.h |   21 +++++++++++++++\r
+ 3 files changed, 93 insertions(+)\r
+ create mode 100644 test/database-test.c\r
+ create mode 100644 test/database-test.h\r
+\r
+diff --git a/test/Makefile.local b/test/Makefile.local\r
+index 8da4c56..8479f91 100644\r
+--- a/test/Makefile.local\r
++++ b/test/Makefile.local\r
+@@ -45,5 +45,6 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
+        $(dir)/symbol-test $(dir)/symbol-test.o \\r
+        $(dir)/arg-test $(dir)/arg-test.o \\r
+        $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
++       $(dir)/database-test.o \\r
+        $(dir)/parse-time $(dir)/parse-time.o \\r
+        $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
+diff --git a/test/database-test.c b/test/database-test.c\r
+new file mode 100644\r
+index 0000000..739e03b\r
+--- /dev/null\r
++++ b/test/database-test.c\r
+@@ -0,0 +1,71 @@\r
++/*\r
++ * Database routines intended only for testing, not exported from\r
++ * library.\r
++ *\r
++ * Copyright (c) 2012 David Bremner\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: David Bremner <david@tethera.net>\r
++ */\r
++\r
++#include "notmuch-private.h"\r
++#include "database-test.h"\r
++\r
++notmuch_status_t\r
++notmuch_database_add_stub_message (notmuch_database_t *notmuch,\r
++                                 const char *message_id,\r
++                                 const char **tags)\r
++{\r
++    const char **tag;\r
++    notmuch_status_t ret;\r
++    notmuch_private_status_t private_status;\r
++    notmuch_message_t *message;\r
++\r
++    ret = _notmuch_database_ensure_writable (notmuch);\r
++    if (ret)\r
++      return ret;\r
++\r
++    message = _notmuch_message_create_for_message_id (notmuch,\r
++                                                    message_id,\r
++                                                    &private_status);\r
++    if (message == NULL) {\r
++      return COERCE_STATUS (private_status,\r
++                            "Unexpected status value from _notmuch_message_create_for_message_id");\r
++\r
++    }\r
++\r
++    if (private_status != NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)\r
++      return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;\r
++\r
++    _notmuch_message_add_term (message, "type", "mail");\r
++\r
++    if (tags) {\r
++      ret = notmuch_message_freeze (message);\r
++      if (ret)\r
++          return ret;\r
++\r
++      for (tag = tags; *tag; tag++) {\r
++          ret = notmuch_message_add_tag (message, *tag);\r
++          if (ret)\r
++              return ret;\r
++      }\r
++    }\r
++\r
++    ret = notmuch_message_thaw (message);\r
++    if (ret)\r
++      return ret;\r
++\r
++    return NOTMUCH_STATUS_SUCCESS;\r
++}\r
+diff --git a/test/database-test.h b/test/database-test.h\r
+new file mode 100644\r
+index 0000000..84f7988\r
+--- /dev/null\r
++++ b/test/database-test.h\r
+@@ -0,0 +1,21 @@\r
++#ifndef _DATABASE_TEST_H\r
++#define _DATABASE_TEST_H\r
++/* Add a new stub message to the given notmuch database.\r
++ *\r
++ * At least the following return values are possible:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.\r
++ *\r
++ * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message\r
++ *    ID as another message already in the database.\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ *    mode so no message can be added.\r
++ */\r
++\r
++notmuch_status_t\r
++notmuch_database_add_stub_message (notmuch_database_t *database,\r
++                                 const char *message_id,\r
++                                 const char **tag_list);\r
++\r
++#endif\r
+-- \r
+1.7.10.4\r
+\r