2 test_description="notmuch_query_* API"
4 . $(dirname "$0")/test-lib.sh || exit 1
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
12 #include <notmuch-test.h>
14 int main (int argc, char** argv)
16 notmuch_database_t *db;
17 notmuch_status_t stat;
20 stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
21 if (stat != NOTMUCH_STATUS_SUCCESS) {
22 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
29 const char *stat_str = notmuch_database_status_string (db);
31 fputs (stat_str, stderr);
37 test_begin_subtest "roundtrip query string with closed db"
38 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
40 notmuch_query_t *query;
41 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
44 EXPECT0(notmuch_database_close (db));
45 query = notmuch_query_create (db, str);
46 ret = notmuch_query_get_query_string (query);
48 printf("%s\n%s\n", str, ret);
53 id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
54 id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
57 test_expect_equal_file EXPECTED OUTPUT
59 test_begin_subtest "retrieve closed db from query"
60 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
62 notmuch_query_t *query;
63 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
64 notmuch_database_t *db2;
66 query = notmuch_query_create (db, str);
67 EXPECT0(notmuch_database_close (db));
68 db2 = notmuch_query_get_database (query);
70 printf("%d\n", db == db2);
78 test_expect_equal_file EXPECTED OUTPUT
80 test_begin_subtest "set omit_excluded on closed db"
81 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
83 notmuch_query_t *query;
84 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
86 query = notmuch_query_create (db, str);
87 EXPECT0(notmuch_database_close (db));
88 notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_ALL);
98 test_expect_equal_file EXPECTED OUTPUT
100 test_begin_subtest "roundtrip sort on closed db"
101 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
103 notmuch_query_t *query;
104 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
107 query = notmuch_query_create (db, str);
108 EXPECT0(notmuch_database_close (db));
109 notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
110 sort = notmuch_query_get_sort (query);
111 printf("%d\n", sort == NOTMUCH_SORT_UNSORTED);
119 test_expect_equal_file EXPECTED OUTPUT
121 test_begin_subtest "add tag_exclude on closed db"
122 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
124 notmuch_query_t *query;
125 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
127 query = notmuch_query_create (db, str);
128 EXPECT0(notmuch_database_close (db));
129 stat = notmuch_query_add_tag_exclude (query, "spam");
130 printf("%d\n", stat == NOTMUCH_STATUS_SUCCESS);
138 test_expect_equal_file EXPECTED OUTPUT
140 test_begin_subtest "search threads on closed db"
141 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
143 notmuch_query_t *query;
144 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
145 notmuch_threads_t *threads;
147 query = notmuch_query_create (db, str);
148 EXPECT0(notmuch_database_close (db));
149 stat = notmuch_query_search_threads (query, &threads);
151 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
158 A Xapian exception occurred performing query: Database has been closed
159 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
161 test_expect_equal_file EXPECTED OUTPUT
163 test_begin_subtest "search messages on closed db"
164 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
166 notmuch_query_t *query;
167 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
168 notmuch_messages_t *messages;
170 query = notmuch_query_create (db, str);
171 EXPECT0(notmuch_database_close (db));
172 stat = notmuch_query_search_messages (query, &messages);
174 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
181 A Xapian exception occurred performing query: Database has been closed
182 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
184 test_expect_equal_file EXPECTED OUTPUT
186 test_begin_subtest "count messages on closed db"
187 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
189 notmuch_query_t *query;
190 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
193 query = notmuch_query_create (db, str);
194 EXPECT0(notmuch_database_close (db));
195 stat = notmuch_query_count_messages (query, &count);
197 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
204 A Xapian exception occurred performing query: Database has been closed
205 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
207 test_expect_equal_file EXPECTED OUTPUT
209 test_begin_subtest "count threads on closed db"
210 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
212 notmuch_query_t *query;
213 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
216 query = notmuch_query_create (db, str);
217 EXPECT0(notmuch_database_close (db));
218 stat = notmuch_query_count_threads (query, &count);
220 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
227 A Xapian exception occurred performing query: Database has been closed
228 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
230 test_expect_equal_file EXPECTED OUTPUT
232 test_begin_subtest "destroy query with closed db"
233 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
235 notmuch_query_t *query;
236 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
238 query = notmuch_query_create (db, str);
239 EXPECT0(notmuch_database_close (db));
240 notmuch_query_destroy (query);
250 test_expect_equal_file EXPECTED OUTPUT