1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id E7ACA431FC2
\r
6 for <notmuch@notmuchmail.org>; Sun, 5 Aug 2012 11:13:39 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id HUw5GcxOJz3r for <notmuch@notmuchmail.org>;
\r
16 Sun, 5 Aug 2012 11:13:38 -0700 (PDT)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 8201C431FC7
\r
21 for <notmuch@notmuchmail.org>; Sun, 5 Aug 2012 11:13:38 -0700 (PDT)
\r
22 Received: from fctnnbsc30w-156034089108.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([156.34.89.108] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>)
\r
27 id 1Sy5KU-0006XK-RB; Sun, 05 Aug 2012 15:13:35 -0300
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1Sy5KP-0005wz-Ew; Sun, 05 Aug 2012 15:13:25 -0300
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH 1/3] test: add database routines for testing.
\r
34 Date: Sun, 5 Aug 2012 15:13:11 -0300
\r
35 Message-Id: <1344190393-22497-2-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1344190393-22497-1-git-send-email-david@tethera.net>
\r
38 References: <1344190393-22497-1-git-send-email-david@tethera.net>
\r
40 Cc: David Bremner <bremner@debian.org>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sun, 05 Aug 2012 18:13:40 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 Initially, provide a way to create "stub" messages in the notmuch
\r
58 database without corresponding files. This is essentially cut and
\r
59 paste from lib/database.cc. This is a seperate file since we don't
\r
60 want to export these symbols from libnotmuch or bloat the library with
\r
63 test/database-test.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
64 test/database-test.h | 21 +++++++++++++++
\r
65 2 files changed, 93 insertions(+)
\r
66 create mode 100644 test/database-test.c
\r
67 create mode 100644 test/database-test.h
\r
69 diff --git a/test/database-test.c b/test/database-test.c
\r
70 new file mode 100644
\r
71 index 0000000..f0f1c8e
\r
73 +++ b/test/database-test.c
\r
76 + * Database routines intended only for testing, not exported from
\r
79 + * Copyright (c) 2012 David Bremner
\r
81 + * This program is free software: you can redistribute it and/or modify
\r
82 + * it under the terms of the GNU General Public License as published by
\r
83 + * the Free Software Foundation, either version 3 of the License, or
\r
84 + * (at your option) any later version.
\r
86 + * This program is distributed in the hope that it will be useful,
\r
87 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
88 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
89 + * GNU General Public License for more details.
\r
91 + * You should have received a copy of the GNU General Public License
\r
92 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
94 + * Author: David Bremner <david@tethera.net>
\r
97 +#include "notmuch-private.h"
\r
98 +#include "database-test.h"
\r
101 +notmuch_database_add_stub_message (notmuch_database_t *notmuch,
\r
102 + const char *message_id,
\r
103 + const char **tags)
\r
105 + const char **tag;
\r
106 + notmuch_status_t ret;
\r
107 + notmuch_private_status_t private_status;
\r
108 + notmuch_message_t *message;
\r
110 + ret = _notmuch_database_ensure_writable (notmuch);
\r
114 + message = _notmuch_message_create_for_message_id (notmuch,
\r
116 + &private_status);
\r
117 + if (message == NULL) {
\r
118 + return COERCE_STATUS (private_status,
\r
119 + "Unexpected status value from _notmuch_message_create_for_message_id");
\r
123 + if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
124 + _notmuch_message_add_term (message, "type", "mail");
\r
126 + return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
130 + ret = notmuch_message_freeze (message);
\r
134 + for (tag = tags; *tag; tag++) {
\r
135 + ret = notmuch_message_add_tag (message, *tag);
\r
141 + ret = notmuch_message_thaw (message);
\r
145 + return NOTMUCH_STATUS_SUCCESS;
\r
147 diff --git a/test/database-test.h b/test/database-test.h
\r
148 new file mode 100644
\r
149 index 0000000..84f7988
\r
151 +++ b/test/database-test.h
\r
153 +#ifndef _DATABASE_TEST_H
\r
154 +#define _DATABASE_TEST_H
\r
155 +/* Add a new stub message to the given notmuch database.
\r
157 + * At least the following return values are possible:
\r
159 + * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
\r
161 + * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
\r
162 + * ID as another message already in the database.
\r
164 + * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
\r
165 + * mode so no message can be added.
\r
169 +notmuch_database_add_stub_message (notmuch_database_t *database,
\r
170 + const char *message_id,
\r
171 + const char **tag_list);
\r