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 35EF3431FC7
\r
6 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:40 -0800 (PST)
\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 orfxzOxrsRwi for <notmuch@notmuchmail.org>;
\r
16 Sat, 24 Nov 2012 13:20:37 -0800 (PST)
\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 43135431FCB
\r
21 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:33 -0800 (PST)
\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 1TcN9L-0006SK-Ih; Sat, 24 Nov 2012 17:20:32 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1TcN9G-0008Cd-3a; Sat, 24 Nov 2012 17:20:26 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v2 04/17] test: add database routines for testing
\r
34 Date: Sat, 24 Nov 2012 17:20:04 -0400
\r
35 Message-Id: <1353792017-31459-5-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1353792017-31459-1-git-send-email-david@tethera.net>
\r
38 References: <1353792017-31459-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: Sat, 24 Nov 2012 21:20: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/Makefile.local | 1 +
\r
64 test/database-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
65 test/database-test.h | 21 +++++++++++++++
\r
66 3 files changed, 93 insertions(+)
\r
67 create mode 100644 test/database-test.c
\r
68 create mode 100644 test/database-test.h
\r
70 diff --git a/test/Makefile.local b/test/Makefile.local
\r
71 index 8da4c56..8479f91 100644
\r
72 --- a/test/Makefile.local
\r
73 +++ b/test/Makefile.local
\r
74 @@ -45,5 +45,6 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
75 $(dir)/symbol-test $(dir)/symbol-test.o \
\r
76 $(dir)/arg-test $(dir)/arg-test.o \
\r
77 $(dir)/hex-xcode $(dir)/hex-xcode.o \
\r
78 + $(dir)/database-test.o \
\r
79 $(dir)/parse-time $(dir)/parse-time.o \
\r
80 $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
\r
81 diff --git a/test/database-test.c b/test/database-test.c
\r
82 new file mode 100644
\r
83 index 0000000..739e03b
\r
85 +++ b/test/database-test.c
\r
88 + * Database routines intended only for testing, not exported from
\r
91 + * Copyright (c) 2012 David Bremner
\r
93 + * This program is free software: you can redistribute it and/or modify
\r
94 + * it under the terms of the GNU General Public License as published by
\r
95 + * the Free Software Foundation, either version 3 of the License, or
\r
96 + * (at your option) any later version.
\r
98 + * This program is distributed in the hope that it will be useful,
\r
99 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
101 + * GNU General Public License for more details.
\r
103 + * You should have received a copy of the GNU General Public License
\r
104 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
106 + * Author: David Bremner <david@tethera.net>
\r
109 +#include "notmuch-private.h"
\r
110 +#include "database-test.h"
\r
113 +notmuch_database_add_stub_message (notmuch_database_t *notmuch,
\r
114 + const char *message_id,
\r
115 + const char **tags)
\r
117 + const char **tag;
\r
118 + notmuch_status_t ret;
\r
119 + notmuch_private_status_t private_status;
\r
120 + notmuch_message_t *message;
\r
122 + ret = _notmuch_database_ensure_writable (notmuch);
\r
126 + message = _notmuch_message_create_for_message_id (notmuch,
\r
128 + &private_status);
\r
129 + if (message == NULL) {
\r
130 + return COERCE_STATUS (private_status,
\r
131 + "Unexpected status value from _notmuch_message_create_for_message_id");
\r
135 + if (private_status != NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
\r
136 + return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
138 + _notmuch_message_add_term (message, "type", "mail");
\r
141 + ret = notmuch_message_freeze (message);
\r
145 + for (tag = tags; *tag; tag++) {
\r
146 + ret = notmuch_message_add_tag (message, *tag);
\r
152 + ret = notmuch_message_thaw (message);
\r
156 + return NOTMUCH_STATUS_SUCCESS;
\r
158 diff --git a/test/database-test.h b/test/database-test.h
\r
159 new file mode 100644
\r
160 index 0000000..84f7988
\r
162 +++ b/test/database-test.h
\r
164 +#ifndef _DATABASE_TEST_H
\r
165 +#define _DATABASE_TEST_H
\r
166 +/* Add a new stub message to the given notmuch database.
\r
168 + * At least the following return values are possible:
\r
170 + * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
\r
172 + * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
\r
173 + * ID as another message already in the database.
\r
175 + * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
\r
176 + * mode so no message can be added.
\r
180 +notmuch_database_add_stub_message (notmuch_database_t *database,
\r
181 + const char *message_id,
\r
182 + const char **tag_list);
\r