[PATCH] lib: provide _notmuch_database_log_append
[notmuch-archives.git] / 3f / 03e424028266cfdd00861b054b82103cb8fc7c
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 B8AB7431FC4\r
6         for <notmuch@notmuchmail.org>; Tue, 14 Aug 2012 02:02:54 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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 2lBsEC1-nGXe for <notmuch@notmuchmail.org>;\r
16         Tue, 14 Aug 2012 02:02:53 -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 A3013431FB6\r
21         for <notmuch@notmuchmail.org>; Tue, 14 Aug 2012 02:02:53 -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 1T1D1Z-00062G-5Q; Tue, 14 Aug 2012 06:02:53 -0300\r
25 Received: (nullmailer pid 5278 invoked by uid 1000);\r
26         Mon, 13 Aug 2012 20:14:06 -0000\r
27 From: David Bremner <bremner@debian.org>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v2 4/6] test: add database routines for testing.\r
30 Date: Mon, 13 Aug 2012 22:13:49 +0200\r
31 Message-Id: <1344888831-4301-5-git-send-email-bremner@debian.org>\r
32 X-Mailer: git-send-email 1.7.10.4\r
33 In-Reply-To: <1344888831-4301-1-git-send-email-bremner@debian.org>\r
34 References: <1344888831-4301-1-git-send-email-bremner@debian.org>\r
35 Cc: David Bremner <bremner@debian.org>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\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: Tue, 14 Aug 2012 09:02:54 -0000\r
49 \r
50 Initially, provide a way to create "stub" messages in the notmuch\r
51 database without corresponding files.  This is essentially cut and\r
52 paste from lib/database.cc. This is a seperate file since we don't\r
53 want to export these symbols from libnotmuch or bloat the library with\r
54 non-exported code.\r
55 ---\r
56  test/database-test.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
57  test/database-test.h |   21 +++++++++++++++\r
58  2 files changed, 93 insertions(+)\r
59  create mode 100644 test/database-test.c\r
60  create mode 100644 test/database-test.h\r
61 \r
62 diff --git a/test/database-test.c b/test/database-test.c\r
63 new file mode 100644\r
64 index 0000000..f0f1c8e\r
65 --- /dev/null\r
66 +++ b/test/database-test.c\r
67 @@ -0,0 +1,72 @@\r
68 +/*\r
69 + * Database routines intended only for testing, not exported from\r
70 + * library.\r
71 + *\r
72 + * Copyright (c) 2012 David Bremner\r
73 + *\r
74 + * This program is free software: you can redistribute it and/or modify\r
75 + * it under the terms of the GNU General Public License as published by\r
76 + * the Free Software Foundation, either version 3 of the License, or\r
77 + * (at your option) any later version.\r
78 + *\r
79 + * This program is distributed in the hope that it will be useful,\r
80 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
81 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
82 + * GNU General Public License for more details.\r
83 + *\r
84 + * You should have received a copy of the GNU General Public License\r
85 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
86 + *\r
87 + * Author: David Bremner <david@tethera.net>\r
88 + */\r
89 +\r
90 +#include "notmuch-private.h"\r
91 +#include "database-test.h"\r
92 +\r
93 +notmuch_status_t\r
94 +notmuch_database_add_stub_message (notmuch_database_t *notmuch,\r
95 +                                  const char *message_id,\r
96 +                                  const char **tags)\r
97 +{\r
98 +    const char **tag;\r
99 +    notmuch_status_t ret;\r
100 +    notmuch_private_status_t private_status;\r
101 +    notmuch_message_t *message;\r
102 +\r
103 +    ret = _notmuch_database_ensure_writable (notmuch);\r
104 +    if (ret)\r
105 +       return ret;\r
106 +\r
107 +    message = _notmuch_message_create_for_message_id (notmuch,\r
108 +                                                     message_id,\r
109 +                                                     &private_status);\r
110 +    if (message == NULL) {\r
111 +       return COERCE_STATUS (private_status,\r
112 +                             "Unexpected status value from _notmuch_message_create_for_message_id");\r
113 +\r
114 +    }\r
115 +\r
116 +    if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {\r
117 +       _notmuch_message_add_term (message, "type", "mail");\r
118 +    } else {\r
119 +       return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;\r
120 +    }\r
121 +\r
122 +    if (tags) {\r
123 +       ret = notmuch_message_freeze (message);\r
124 +       if (ret)\r
125 +           return ret;\r
126 +\r
127 +       for (tag = tags; *tag; tag++) {\r
128 +           ret = notmuch_message_add_tag (message, *tag);\r
129 +           if (ret)\r
130 +               return ret;\r
131 +       }\r
132 +    }\r
133 +\r
134 +    ret = notmuch_message_thaw (message);\r
135 +    if (ret)\r
136 +       return ret;\r
137 +\r
138 +    return NOTMUCH_STATUS_SUCCESS;\r
139 +}\r
140 diff --git a/test/database-test.h b/test/database-test.h\r
141 new file mode 100644\r
142 index 0000000..84f7988\r
143 --- /dev/null\r
144 +++ b/test/database-test.h\r
145 @@ -0,0 +1,21 @@\r
146 +#ifndef _DATABASE_TEST_H\r
147 +#define _DATABASE_TEST_H\r
148 +/* Add a new stub message to the given notmuch database.\r
149 + *\r
150 + * At least the following return values are possible:\r
151 + *\r
152 + * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.\r
153 + *\r
154 + * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message\r
155 + *     ID as another message already in the database.\r
156 + *\r
157 + * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
158 + *     mode so no message can be added.\r
159 + */\r
160 +\r
161 +notmuch_status_t\r
162 +notmuch_database_add_stub_message (notmuch_database_t *database,\r
163 +                                  const char *message_id,\r
164 +                                  const char **tag_list);\r
165 +\r
166 +#endif\r
167 -- \r
168 1.7.10.4\r
169 \r