1
# define BOOST_TEST_DYN_LINK
2
# define BOOST_TEST_MODULE TestOpenError
3
# include <boost/test/unit_test.hpp>
4
# include <boost/filesystem.hpp>
6
# include "test_common.hh"
8
# include "message_thread.hh"
12
using namespace boost::filesystem;
14
BOOST_AUTO_TEST_SUITE(Reading)
16
BOOST_AUTO_TEST_CASE(open_error)
20
std::string fname = "tests/mail/test_mail/this-one-should-not-exist.eml";
22
BOOST_CHECK (!exists(fname));
24
BOOST_CHECK_THROW(Astroid::Message m (fname), Astroid::message_error);
29
BOOST_AUTO_TEST_CASE(out_of_sync)
31
using Astroid::Message;
33
using Astroid::AddressList;
34
using Astroid::ustring;
38
/* open other email and make copy */
39
Message om ("tests/mail/test_out_of_sync.eml");
40
om.save_to ("tests/mail/test_mail/oos.eml");
43
system ("notmuch new");
45
/* test if file can be read now */
47
BOOST_CHECK_NO_THROW (mm = new Message ("tests/mail/test_mail/oos.eml"));
48
BOOST_CHECK ((AddressList (mm->other_to ()).str () == "ba@adsf.asd"));
49
LOG (test) << "other: " << AddressList (mm->other_to ()).str ();
52
/* remove it without updating notmuch */
53
unlink ("tests/mail/test_mail/oos.eml");
55
/* try to open file using notmuch */
58
ustring mid = "oos@asdf.com";
59
Db db(Db::DATABASE_READ_ONLY);
60
db.on_message (mid, [&](notmuch_message_t * msg) {
61
LOG (test) << "trying to open deleted file.";
63
oos = new Message (msg, 0);
65
LOG (test) << "deleted file opened.";
69
/* testing various methods */
70
LOG (test) << "message: testing methods on out-of-sync message.";
72
oos->save_to ("tests/mail/test_mail/wont-work.eml");
74
LOG (test) << "sender: " << oos->sender;
75
LOG (test) << "text: " << oos->viewable_text (false);
77
/* these do not seem to be cached */
78
LOG (test) << "to: " << AddressList (oos->to()).str();
79
LOG (test) << "cc: " << AddressList (oos->cc()).str();
80
LOG (test) << "bcc: " << AddressList (oos->bcc()).str();
81
LOG (test) << "other: " << AddressList (oos->other_to ()).str ();
82
LOG (test) << "date: " << oos->date ();
84
LOG (test) << "pretty date: " << oos->pretty_verbose_date();
88
oos->mime_messages ();
91
system ("notmuch new");
95
BOOST_AUTO_TEST_SUITE_END()