~ubuntu-branches/debian/sid/astroidmail/sid

« back to all changes in this revision

Viewing changes to tests/test_non_existant_file.cc

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard
  • Date: 2017-10-11 19:57:04 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20171011195704-axyliv79qoe74aqm
Tags: 0.10.2-2
Fix create fake $HOME for testsuite to please gnupg2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# define BOOST_TEST_DYN_LINK
 
2
# define BOOST_TEST_MODULE TestOpenError
 
3
# include <boost/test/unit_test.hpp>
 
4
# include <boost/filesystem.hpp>
 
5
 
 
6
# include "test_common.hh"
 
7
# include "db.hh"
 
8
# include "message_thread.hh"
 
9
# include "glibmm.h"
 
10
# include "chunk.hh"
 
11
 
 
12
using namespace boost::filesystem;
 
13
 
 
14
BOOST_AUTO_TEST_SUITE(Reading)
 
15
 
 
16
  BOOST_AUTO_TEST_CASE(open_error)
 
17
  {
 
18
    setup ();
 
19
 
 
20
    std::string fname = "tests/mail/test_mail/this-one-should-not-exist.eml";
 
21
 
 
22
    BOOST_CHECK (!exists(fname));
 
23
 
 
24
    BOOST_CHECK_THROW(Astroid::Message m (fname), Astroid::message_error);
 
25
 
 
26
    teardown ();
 
27
  }
 
28
 
 
29
  BOOST_AUTO_TEST_CASE(out_of_sync)
 
30
  {
 
31
    using Astroid::Message;
 
32
    using Astroid::Db;
 
33
    using Astroid::AddressList;
 
34
    using Astroid::ustring;
 
35
 
 
36
    setup ();
 
37
 
 
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");
 
41
 
 
42
    /* update notmuch */
 
43
    system ("notmuch new");
 
44
 
 
45
    /* test if file can be read now */
 
46
    Message * mm;
 
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 ();
 
50
    delete mm;
 
51
 
 
52
    /* remove it without updating notmuch */
 
53
    unlink ("tests/mail/test_mail/oos.eml");
 
54
 
 
55
    /* try to open file using notmuch */
 
56
    Message * oos;
 
57
 
 
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.";
 
62
 
 
63
        oos = new Message (msg, 0);
 
64
 
 
65
        LOG (test) << "deleted file opened.";
 
66
 
 
67
        });
 
68
 
 
69
    /* testing various methods */
 
70
    LOG (test) << "message: testing methods on out-of-sync message.";
 
71
 
 
72
    oos->save_to ("tests/mail/test_mail/wont-work.eml");
 
73
 
 
74
    LOG (test) << "sender: " << oos->sender;
 
75
    LOG (test) << "text: " << oos->viewable_text (false);
 
76
 
 
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 ();
 
83
 
 
84
    LOG (test) << "pretty date: " << oos->pretty_verbose_date();
 
85
 
 
86
    oos->contents ();
 
87
    oos->attachments ();
 
88
    oos->mime_messages ();
 
89
 
 
90
    /* update notmuch */
 
91
    system ("notmuch new");
 
92
 
 
93
    teardown ();
 
94
  }
 
95
BOOST_AUTO_TEST_SUITE_END()
 
96