File: test_convert_error.cc

package info (click to toggle)
astroidmail 0.17%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,160 kB
  • sloc: cpp: 21,133; ansic: 1,619; python: 93; sh: 73; makefile: 7
file content (116 lines) | stat: -rw-r--r-- 2,752 bytes parent folder | download | duplicates (6)
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
# define BOOST_TEST_DYN_LINK
# define BOOST_TEST_MODULE TestConvertError
# include <boost/test/unit_test.hpp>
# include <iostream>

# include "test_common.hh"
# include "db.hh"
# include "message_thread.hh"
# include "glibmm.h"

using std::cout;
using std::endl;
using std::locale;

using Astroid::ustring;

BOOST_AUTO_TEST_SUITE(Reading)

  BOOST_AUTO_TEST_CASE(reading_convert_error)
  {
    setup ();

    ustring fname = "tests/mail/test_mail/convert_error.eml";

    Astroid::Message m (fname);

    BOOST_CHECK_NO_THROW (m.plain_text (false));

    teardown ();
  }

  BOOST_AUTO_TEST_CASE(reply_convert_error)
  {
    setup ();

    ustring fname = "tests/mail/test_mail/bad-convert-error.eml";

    Astroid::Message msg (fname);
    /* quote original message */
    std::ostringstream quoted;

    ustring quoting_a = ustring::compose ("Excerpts from %1's message of %2:",
        Astroid::Address(msg.sender.raw()).fail_safe_name(), msg.pretty_verbose_date());

    quoted  << quoting_a.raw ()
            << endl;

    std::string vt = msg.plain_text(false);
    std::stringstream sstr (vt);
    while (sstr.good()) {
      std::string line;
      std::getline (sstr, line);
      quoted << ">";

      if (line[0] != '>')
        quoted << " ";

      quoted << line << endl;
    }

    ustring body = ustring(quoted.str());


    /* test writing out */
    std::string name = "tests/mail/test_mail/tmp-reply-convert-error";
    LOG (test) << "writing to tmp file " << name;
    std::fstream tmpfile (name, std::fstream::out);

    tmpfile << "From: test@test.no" << endl;

    //BOOST_CHECK_THROW ( (tmpfile << body) , std::exception);
    BOOST_CHECK_NO_THROW ( tmpfile << body.raw() );

    tmpfile << endl;
    tmpfile.close ();

    LOG (test) << "removing tmp file";
    std::remove (name.c_str());

    teardown ();
  }

  /* this test should be last since it messes up the locale for the other
   * tests */
  BOOST_AUTO_TEST_CASE(glib_convert_error)
  {
    cout << "the current user preferred locale is: "
         << locale("").name() << endl;

    setlocale (LC_ALL, "");

    cout << "the current user preferred locale is: "
         << locale("").name() << endl;

    locale::global (locale (""));

    cout << "the current user preferred locale is: "
         << locale("").name() << endl;


    Glib::init ();

    BOOST_TEST_MESSAGE ("testing glib conversion of: æøå..");
    const char * input = "æøå";

    BOOST_WARN_MESSAGE (Glib::get_charset (), "The current locale is not utf8");

    std::string current_locale;
    Glib::get_charset (current_locale);
    BOOST_TEST_MESSAGE ("locale: " + current_locale);

    BOOST_CHECK_NO_THROW(ustring out = Glib::locale_to_utf8 (input));
  }

BOOST_AUTO_TEST_SUITE_END()