1 Return-Path: <bremner@tesseract.cs.unb.ca>
\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 5631A431FBC
\r
6 for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 00:18:19 -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 S1hhQMAOLx0f for <notmuch@notmuchmail.org>;
\r
16 Mon, 20 Aug 2012 00:18:17 -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 EF7AC431FB6
\r
21 for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 00:18:16 -0700 (PDT)
\r
22 Received: from remotemail by tesseract.cs.unb.ca with local (Exim 4.72)
\r
23 (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
24 id 1T3MFb-0002Ez-SG; Mon, 20 Aug 2012 04:18:16 -0300
\r
25 Received: (nullmailer pid 7816 invoked by uid 1000);
\r
26 Sun, 19 Aug 2012 13:19:07 -0000
\r
27 From: david@tethera.net
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [Patch v3 4/6] test: add database routines for testing.
\r
30 Date: Sun, 19 Aug 2012 15:18:32 +0200
\r
31 Message-Id: <1345382314-5330-5-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.7.10.4
\r
33 In-Reply-To: <1345382314-5330-1-git-send-email-david@tethera.net>
\r
34 References: <1345382314-5330-1-git-send-email-david@tethera.net>
\r
35 Cc: David Bremner <bremner@debian.org>
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.13
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Mon, 20 Aug 2012 07:18:19 -0000
\r
50 From: David Bremner <bremner@debian.org>
\r
52 Initially, provide a way to create "stub" messages in the notmuch
\r
53 database without corresponding files. This is essentially cut and
\r
54 paste from lib/database.cc. This is a seperate file since we don't
\r
55 want to export these symbols from libnotmuch or bloat the library with
\r
58 test/Makefile.local | 1 +
\r
59 test/database-test.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
60 test/database-test.h | 21 +++++++++++++++
\r
61 3 files changed, 94 insertions(+)
\r
62 create mode 100644 test/database-test.c
\r
63 create mode 100644 test/database-test.h
\r
65 diff --git a/test/Makefile.local b/test/Makefile.local
\r
66 index 2622185..bb67ded 100644
\r
67 --- a/test/Makefile.local
\r
68 +++ b/test/Makefile.local
\r
69 @@ -41,4 +41,5 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
70 $(dir)/symbol-test $(dir)/symbol-test.o \
\r
71 $(dir)/arg-test $(dir)/arg-test.o \
\r
72 $(dir)/hex-xcode $(dir)/hex-xcode.o \
\r
73 + $(dir)/database-test.o \
\r
74 $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
\r
75 diff --git a/test/database-test.c b/test/database-test.c
\r
76 new file mode 100644
\r
77 index 0000000..f0f1c8e
\r
79 +++ b/test/database-test.c
\r
82 + * Database routines intended only for testing, not exported from
\r
85 + * Copyright (c) 2012 David Bremner
\r
87 + * This program is free software: you can redistribute it and/or modify
\r
88 + * it under the terms of the GNU General Public License as published by
\r
89 + * the Free Software Foundation, either version 3 of the License, or
\r
90 + * (at your option) any later version.
\r
92 + * This program is distributed in the hope that it will be useful,
\r
93 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
94 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
95 + * GNU General Public License for more details.
\r
97 + * You should have received a copy of the GNU General Public License
\r
98 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
100 + * Author: David Bremner <david@tethera.net>
\r
103 +#include "notmuch-private.h"
\r
104 +#include "database-test.h"
\r
107 +notmuch_database_add_stub_message (notmuch_database_t *notmuch,
\r
108 + const char *message_id,
\r
109 + const char **tags)
\r
111 + const char **tag;
\r
112 + notmuch_status_t ret;
\r
113 + notmuch_private_status_t private_status;
\r
114 + notmuch_message_t *message;
\r
116 + ret = _notmuch_database_ensure_writable (notmuch);
\r
120 + message = _notmuch_message_create_for_message_id (notmuch,
\r
122 + &private_status);
\r
123 + if (message == NULL) {
\r
124 + return COERCE_STATUS (private_status,
\r
125 + "Unexpected status value from _notmuch_message_create_for_message_id");
\r
129 + if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
130 + _notmuch_message_add_term (message, "type", "mail");
\r
132 + return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
136 + ret = notmuch_message_freeze (message);
\r
140 + for (tag = tags; *tag; tag++) {
\r
141 + ret = notmuch_message_add_tag (message, *tag);
\r
147 + ret = notmuch_message_thaw (message);
\r
151 + return NOTMUCH_STATUS_SUCCESS;
\r
153 diff --git a/test/database-test.h b/test/database-test.h
\r
154 new file mode 100644
\r
155 index 0000000..84f7988
\r
157 +++ b/test/database-test.h
\r
159 +#ifndef _DATABASE_TEST_H
\r
160 +#define _DATABASE_TEST_H
\r
161 +/* Add a new stub message to the given notmuch database.
\r
163 + * At least the following return values are possible:
\r
165 + * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
\r
167 + * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
\r
168 + * ID as another message already in the database.
\r
170 + * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
\r
171 + * mode so no message can be added.
\r
175 +notmuch_database_add_stub_message (notmuch_database_t *database,
\r
176 + const char *message_id,
\r
177 + const char **tag_list);
\r