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_with_config (argv[1],
21 NOTMUCH_DATABASE_MODE_READ_WRITE,
22 NULL, NULL, &db, &msg);
23 if (stat != NOTMUCH_STATUS_SUCCESS) {
24 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
31 const char *stat_str = notmuch_database_status_string (db);
33 fputs (stat_str, stderr);
39 test_begin_subtest "roundtrip query string with closed db"
40 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
42 notmuch_query_t *query;
43 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
46 EXPECT0(notmuch_database_close (db));
47 query = notmuch_query_create (db, str);
48 ret = notmuch_query_get_query_string (query);
50 printf("%s\n%s\n", str, ret);
55 id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
56 id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
59 test_expect_equal_file EXPECTED OUTPUT
61 test_begin_subtest "retrieve closed db from query"
62 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
64 notmuch_query_t *query;
65 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
66 notmuch_database_t *db2;
68 query = notmuch_query_create (db, str);
69 EXPECT0(notmuch_database_close (db));
70 db2 = notmuch_query_get_database (query);
72 printf("%d\n", db == db2);
80 test_expect_equal_file EXPECTED OUTPUT
82 test_begin_subtest "set omit_excluded on closed db"
83 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
85 notmuch_query_t *query;
86 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
88 query = notmuch_query_create (db, str);
89 EXPECT0(notmuch_database_close (db));
90 notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_ALL);
100 test_expect_equal_file EXPECTED OUTPUT
102 test_begin_subtest "roundtrip sort on closed db"
103 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
105 notmuch_query_t *query;
106 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
109 query = notmuch_query_create (db, str);
110 EXPECT0(notmuch_database_close (db));
111 notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
112 sort = notmuch_query_get_sort (query);
113 printf("%d\n", sort == NOTMUCH_SORT_UNSORTED);
121 test_expect_equal_file EXPECTED OUTPUT
123 test_begin_subtest "add tag_exclude on closed db"
124 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
126 notmuch_query_t *query;
127 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
129 query = notmuch_query_create (db, str);
130 EXPECT0(notmuch_database_close (db));
131 stat = notmuch_query_add_tag_exclude (query, "spam");
132 printf("%d\n", stat == NOTMUCH_STATUS_SUCCESS);
140 test_expect_equal_file EXPECTED OUTPUT
142 test_begin_subtest "search threads on closed db"
143 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
145 notmuch_query_t *query;
146 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
147 notmuch_threads_t *threads;
149 query = notmuch_query_create (db, str);
150 EXPECT0(notmuch_database_close (db));
151 stat = notmuch_query_search_threads (query, &threads);
153 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
160 A Xapian exception occurred performing query: Database has been closed
161 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
163 test_expect_equal_file EXPECTED OUTPUT
165 test_begin_subtest "search messages on closed db"
166 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
168 notmuch_query_t *query;
169 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
170 notmuch_messages_t *messages;
172 query = notmuch_query_create (db, str);
173 EXPECT0(notmuch_database_close (db));
174 stat = notmuch_query_search_messages (query, &messages);
176 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
183 A Xapian exception occurred performing query: Database has been closed
184 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
186 test_expect_equal_file EXPECTED OUTPUT
188 test_begin_subtest "count messages on closed db"
189 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
191 notmuch_query_t *query;
192 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
195 query = notmuch_query_create (db, str);
196 EXPECT0(notmuch_database_close (db));
197 stat = notmuch_query_count_messages (query, &count);
199 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
206 A Xapian exception occurred performing query: Database has been closed
207 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
209 test_expect_equal_file EXPECTED OUTPUT
211 test_begin_subtest "count threads on closed db"
212 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
214 notmuch_query_t *query;
215 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
218 query = notmuch_query_create (db, str);
219 EXPECT0(notmuch_database_close (db));
220 stat = notmuch_query_count_threads (query, &count);
222 printf("%d\n", stat == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
229 A Xapian exception occurred performing query: Database has been closed
230 Query string was: id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
232 test_expect_equal_file EXPECTED OUTPUT
234 test_begin_subtest "destroy query with closed db"
235 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
237 notmuch_query_t *query;
238 const char *str = "id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net";
240 query = notmuch_query_create (db, str);
241 EXPECT0(notmuch_database_close (db));
242 notmuch_query_destroy (query);
252 test_expect_equal_file EXPECTED OUTPUT