[PATCH 1/3] test: add database routines for testing.
authordavid <david@tethera.net>
Sun, 5 Aug 2012 18:13:11 +0000 (15:13 +2100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:52 +0000 (09:48 -0800)
d6/43e7a2727ac0d59cbca7e5f96e757fcf3815ef [new file with mode: 0644]

diff --git a/d6/43e7a2727ac0d59cbca7e5f96e757fcf3815ef b/d6/43e7a2727ac0d59cbca7e5f96e757fcf3815ef
new file mode 100644 (file)
index 0000000..7ade2df
--- /dev/null
@@ -0,0 +1,176 @@
+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 E7ACA431FC2\r
+       for <notmuch@notmuchmail.org>; Sun,  5 Aug 2012 11:13:39 -0700 (PDT)\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 HUw5GcxOJz3r for <notmuch@notmuchmail.org>;\r
+       Sun,  5 Aug 2012 11:13:38 -0700 (PDT)\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 8201C431FC7\r
+       for <notmuch@notmuchmail.org>; Sun,  5 Aug 2012 11:13:38 -0700 (PDT)\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 1Sy5KU-0006XK-RB; Sun, 05 Aug 2012 15:13:35 -0300\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1Sy5KP-0005wz-Ew; Sun, 05 Aug 2012 15:13:25 -0300\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] test: add database routines for testing.\r
+Date: Sun,  5 Aug 2012 15:13:11 -0300\r
+Message-Id: <1344190393-22497-2-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1344190393-22497-1-git-send-email-david@tethera.net>\r
+References: <1344190393-22497-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: Sun, 05 Aug 2012 18:13: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/database-test.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ test/database-test.h |   21 +++++++++++++++\r
+ 2 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/database-test.c b/test/database-test.c\r
+new file mode 100644\r
+index 0000000..f0f1c8e\r
+--- /dev/null\r
++++ b/test/database-test.c\r
+@@ -0,0 +1,72 @@\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
++      _notmuch_message_add_term (message, "type", "mail");\r
++    } else {\r
++      return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;\r
++    }\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