Navigation Menu

Skip to content

Commit

Permalink
test with current locale, dont fail on converterror in viewable_text
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Nov 5, 2014
1 parent 9d378f1 commit 416d6d3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
7 changes: 6 additions & 1 deletion site_scons/site_tools/unittest.py
Expand Up @@ -11,8 +11,13 @@ def unitTestAction(target, source, env):
change.
'''

# merge in os environ to get utf-8 or users settings
myenv = os.environ.copy ()
for k,v in env['ENV'].items():
myenv[k] = v

app = str(source[0].abspath)
process = subprocess.Popen (app, shell = True, env = env['ENV'])
process = subprocess.Popen (app, shell = True, env = myenv)
process.wait ()
ret = process.returncode
if ret == 0:
Expand Down
10 changes: 9 additions & 1 deletion src/chunk.cc
Expand Up @@ -268,7 +268,15 @@ namespace Astroid {

stringstream sstr;
sstr << io_stream.rdbuf();
return ustring (sstr.str());
ustring b;
try {
b = sstr.str();
} catch (Glib::ConvertError &ex) {
log << error << "could not convert chunk to utf-8, contents: " << sstr.str() << endl;
throw ex;
}

return b;
} else {
return ustring ("Error: Non-viewable part!");
log << error << "chunk: tried to display non-viewable part." << endl;
Expand Down
6 changes: 3 additions & 3 deletions src/message_thread.cc
Expand Up @@ -167,7 +167,7 @@ namespace Astroid {
* html: output html (using gmimes html filter)
*/
refptr<Chunk> c = root;
stringstream body;
ustring body;

function< void (refptr<Chunk>) > app_body =
[&] (refptr<Chunk> c)
Expand All @@ -194,7 +194,7 @@ namespace Astroid {

if (use) {
if (c->viewable && (c->preferred || html)) {
body << c->viewable_text(html);
body += c->viewable_text (html);
}

for_each (c->kids.begin(),
Expand All @@ -205,7 +205,7 @@ namespace Astroid {

app_body (c);

return ustring(body.str());
return body;
}

vector<refptr<Chunk>> Message::attachments () {
Expand Down
26 changes: 24 additions & 2 deletions test/test_convert_error.cc
Expand Up @@ -6,6 +6,7 @@
# include "db.hh"
# include "message_thread.hh"
# include "glibmm.h"

using namespace std;


Expand All @@ -14,12 +15,33 @@ BOOST_AUTO_TEST_SUITE(Reading)

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");

BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES (reading_convert_error, 1)
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_CASE(reading_convert_error)
{
Expand Down

0 comments on commit 416d6d3

Please sign in to comment.