1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# define BOOST_TEST_DYN_LINK
# define BOOST_TEST_MODULE TestNotmuch
# include <boost/test/unit_test.hpp>
# include <boost/filesystem.hpp>
# include <iostream>
# include "test_common.hh"
# include <notmuch.h>
# include "db.hh"
namespace bfs = boost::filesystem;
using std::cout;
using std::endl;
BOOST_AUTO_TEST_SUITE(Notmuch)
BOOST_AUTO_TEST_CASE(read_all_threads)
{
bfs::path path_db = bfs::absolute (bfs::path("./tests/mail/test_mail"));
notmuch_database_t * nm_db;
notmuch_status_t s =
notmuch_database_open (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
BOOST_CHECK (s == NOTMUCH_STATUS_SUCCESS);
/* read all messages */
cout << "db: running test query.." << endl;
notmuch_query_t * q = notmuch_query_create (nm_db, "*");
unsigned int c;
notmuch_status_t st = notmuch_query_count_messages (q, &c); // desctrutive
notmuch_query_destroy (q);
q = notmuch_query_create (nm_db, "*");
BOOST_CHECK (st == NOTMUCH_STATUS_SUCCESS);
cout << "query: " << notmuch_query_get_query_string (q) << ", approx: "
<< c << " messages." << endl;
notmuch_messages_t * messages;
notmuch_message_t * message;
for (st = notmuch_query_search_messages (q, &messages);
(st == NOTMUCH_STATUS_SUCCESS) &&
notmuch_messages_valid (messages);
notmuch_messages_move_to_next (messages))
{
message = notmuch_messages_get (messages);
cout << "thread:" << notmuch_message_get_thread_id (message) << ", message: " << notmuch_message_get_header (message, "Subject") << endl;
notmuch_message_destroy (message);
}
notmuch_database_close (nm_db);
}
/* BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES (notmuch_threads_move_to_next_fail, 1) */
BOOST_AUTO_TEST_CASE(notmuch_threads_move_to_next_fail)
{
bfs::path path_db = bfs::absolute (bfs::path("./tests/mail/test_mail"));
notmuch_database_t * nm_db;
notmuch_status_t s =
notmuch_database_open (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
BOOST_CHECK (s == NOTMUCH_STATUS_SUCCESS);
cout << "db: running test query.." << endl;
notmuch_query_t * q = notmuch_query_create (nm_db, "*");
unsigned int c;
notmuch_status_t st = notmuch_query_count_threads (q, &c); // destructive
notmuch_query_destroy (q);
q = notmuch_query_create (nm_db, "*");
BOOST_CHECK (st == NOTMUCH_STATUS_SUCCESS);
cout << "query: " << notmuch_query_get_query_string (q) << ", approx: "
<< c << " threads." << endl;
notmuch_threads_t * threads;
notmuch_thread_t * thread;
st = notmuch_query_search_threads (q, &threads);
std::string thread_id_of_first;
int i = 0;
int stop = 3;
for (; notmuch_threads_valid (threads);
notmuch_threads_move_to_next (threads)) {
thread = notmuch_threads_get (threads);
thread_id_of_first = notmuch_thread_get_thread_id (thread);
notmuch_thread_destroy (thread);
i++;
if (i == stop) break;
}
cout << "thread id of first thread: " << thread_id_of_first << endl;
notmuch_query_destroy (q);
/* restart query */
cout << "restarting query.." << endl;
q = notmuch_query_create (nm_db, "*");
st = notmuch_query_search_threads (q, &threads);
i = 0;
for ( ; notmuch_threads_valid (threads);
notmuch_threads_move_to_next (threads))
{
i++;
cout << "move to next: " << i << endl;
if (i == stop) break;
}
notmuch_threads_move_to_next (threads);
for ( ; notmuch_threads_valid (threads);
notmuch_threads_move_to_next (threads))
{
thread = notmuch_threads_get (threads);
std::string thread_id = notmuch_thread_get_thread_id (thread);
i++;
BOOST_CHECK_MESSAGE (thread_id != thread_id_of_first, "thread id is equal to " << stop << " thread, we are on thread: " << i);
notmuch_thread_destroy (thread);
}
notmuch_database_close (nm_db);
}
BOOST_AUTO_TEST_SUITE_END()
|