]> git.cworth.org Git - notmuch/blob - test/database-test.c
debian: start changelog for 0.31~rc0-1
[notmuch] / test / database-test.c
1 /*
2  * Database routines intended only for testing, not exported from
3  * library.
4  *
5  * Copyright (c) 2012 David Bremner
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see https://www.gnu.org/licenses/ .
19  *
20  * Author: David Bremner <david@tethera.net>
21  */
22
23 #include "notmuch-private.h"
24 #include "database-test.h"
25
26 notmuch_status_t
27 notmuch_database_add_stub_message (notmuch_database_t *notmuch,
28                                    const char *message_id,
29                                    const char **tags)
30 {
31     const char **tag;
32     notmuch_status_t ret;
33     notmuch_private_status_t private_status;
34     notmuch_message_t *message;
35
36     ret = _notmuch_database_ensure_writable (notmuch);
37     if (ret)
38         return ret;
39
40     message = _notmuch_message_create_for_message_id (notmuch,
41                                                       message_id,
42                                                       &private_status);
43     if (message == NULL) {
44         return COERCE_STATUS (private_status,
45                               "Unexpected status value from _notmuch_message_create_for_message_id");
46
47     }
48
49     if (private_status != NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
50         return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
51
52     _notmuch_message_add_term (message, "type", "mail");
53
54     if (tags) {
55         ret = notmuch_message_freeze (message);
56         if (ret)
57             return ret;
58
59         for (tag = tags; *tag; tag++) {
60             ret = notmuch_message_add_tag (message, *tag);
61             if (ret)
62                 return ret;
63         }
64
65         ret = notmuch_message_thaw (message);
66         if (ret)
67             return ret;
68     }
69
70     return NOTMUCH_STATUS_SUCCESS;
71 }