Mercurial > pidgin.yaz
diff libpurple/tests/test_yahoo_util.c @ 28155:1e02e65ce301
Changes to the way we translate raw yahoo messages to HTML. The HTML
is now well formed (we actually close tags now). The code isn't as
simple as I would like, but I'm happy with it. I think it's a pretty
robust solution and should still be pretty efficient. I didn't find
any memory leaks with valgrind.
The formatting used in yahoo messages is really ghetto.
Also added a lot more tests. They pass with and without the
USE_CSS_FORMATTING define.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 04 Aug 2009 02:14:46 +0000 |
parents | 07de864fc024 |
children | c69c79921f93 |
line wrap: on
line diff
--- a/libpurple/tests/test_yahoo_util.c Tue Aug 04 02:06:01 2009 +0000 +++ b/libpurple/tests/test_yahoo_util.c Tue Aug 04 02:14:46 2009 +0000 @@ -17,49 +17,81 @@ { assert_string_equal_free("plain", yahoo_codes_to_html("plain")); + assert_string_equal_free("unknown ansi code", + yahoo_codes_to_html("unknown \x1B[12345m ansi code")); + assert_string_equal_free("plain <peanut>", + yahoo_codes_to_html("plain <peanut>")); + assert_string_equal_free("plain <peanut", + yahoo_codes_to_html("plain <peanut")); + assert_string_equal_free("plain> peanut", + yahoo_codes_to_html("plain> peanut")); /* bold/italic/underline */ - assert_string_equal_free("<b>bold", + assert_string_equal_free("<b>bold</b>", yahoo_codes_to_html("\x1B[1mbold")); - assert_string_equal_free("<i>italic", + assert_string_equal_free("<i>italic</i>", yahoo_codes_to_html("\x1B[2mitalic")); - assert_string_equal_free("<u>underline", + assert_string_equal_free("<u>underline</u>", yahoo_codes_to_html("\x1B[4munderline")); - assert_string_equal_free("<b>bold</b> <i>italic</i> <u>underline", + assert_string_equal_free("no markup", + yahoo_codes_to_html("no\x1B[x4m markup")); + assert_string_equal_free("<b>bold</b> <i>italic</i> <u>underline</u>", yahoo_codes_to_html("\x1B[1mbold\x1B[x1m \x1B[2mitalic\x1B[x2m \x1B[4munderline")); + assert_string_equal_free("<b>bold <i>bolditalic</i></b><i> italic</i>", + yahoo_codes_to_html("\x1B[1mbold \x1B[2mbolditalic\x1B[x1m italic")); + assert_string_equal_free("<b>bold <i>bolditalic</i></b><i> <u>italicunderline</u></i>", + yahoo_codes_to_html("\x1B[1mbold \x1B[2mbolditalic\x1B[x1m \x1B[4mitalicunderline")); + assert_string_equal_free("<b>bold <i>bolditalic <u>bolditalicunderline</u></i><u> boldunderline</u></b>", + yahoo_codes_to_html("\x1B[1mbold \x1B[2mbolditalic \x1B[4mbolditalicunderline\x1B[x2m boldunderline")); + assert_string_equal_free("<b>bold <i>bolditalic <u>bolditalicunderline</u></i></b><i><u> italicunderline</u></i>", + yahoo_codes_to_html("\x1B[1mbold \x1B[2mbolditalic \x1B[4mbolditalicunderline\x1B[x1m italicunderline")); #ifdef USE_CSS_FORMATTING /* font color */ - assert_string_equal_free("<span style=\"color: #0000FF\">blue", + assert_string_equal_free("<span style='color: #0000FF'>blue</span>", yahoo_codes_to_html("\x1B[31mblue")); - assert_string_equal_free("<span style=\"color: #70ea15\">custom color", + assert_string_equal_free("<span style='color: #70ea15'>custom color</span>", yahoo_codes_to_html("\x1B[#70ea15mcustom color")); + /* font face */ + assert_string_equal_free("<font face='Georgia'>test</font>", + yahoo_codes_to_html("<font face='Georgia'>test</font>")); + /* font size */ - assert_string_equal_free("<font><span style=\"font-size: 15pt\">test", - yahoo_codes_to_html("<font size=\"15\">test")); - assert_string_equal_free("<font><span style=\"font-size: 32pt\">size 32", - yahoo_codes_to_html("<font size=\"32\">size 32")); + assert_string_equal_free("<font><span style='font-size: 15pt'>test</span></font>", + yahoo_codes_to_html("<font size='15'>test")); + assert_string_equal_free("<font><span style='font-size: 32pt'>size 32</span></font>", + yahoo_codes_to_html("<font size='32'>size 32")); /* combinations */ - assert_string_equal_free("<span style=\"color: #FF0080\"><font><span style=\"font-size: 15pt\">test", - yahoo_codes_to_html("\x1B[35m<font size=\"15\">test")); + assert_string_equal_free("<font face='Georgia'><span style='font-size: 32pt'>test</span></font>", + yahoo_codes_to_html("<font face='Georgia' size='32'>test")); + assert_string_equal_free("<span style='color: #FF0080'><font><span style='font-size: 15pt'>test</span></font></span>", + yahoo_codes_to_html("\x1B[35m<font size='15'>test")); #else /* font color */ - assert_string_equal_free("<font color=\"#0000FF\">blue", + assert_string_equal_free("<font color='#0000FF'>blue</font>", yahoo_codes_to_html("\x1B[31mblue")); - assert_string_equal_free("<font color=\"#70ea15\">custom color", + assert_string_equal_free("<font color='#70ea15'>custom color</font>", yahoo_codes_to_html("\x1B[#70ea15mcustom color")); + assert_string_equal_free("test", + yahoo_codes_to_html("<ALT #ff0000,#00ff00,#0000ff>test</ALT>")); + + /* font face */ + assert_string_equal_free("<font face='Georgia'>test</font>", + yahoo_codes_to_html("<font face='Georgia'>test")); /* font size */ - assert_string_equal_free("<font size=\"4\" absz=\"15\">test", - yahoo_codes_to_html("<font size=\"15\">test")); - assert_string_equal_free("<font size=\"6\" absz=\"32\">size 32", - yahoo_codes_to_html("<font size=\"32\">size 32")); + assert_string_equal_free("<font size='4' absz='15'>test</font>", + yahoo_codes_to_html("<font size='15'>test")); + assert_string_equal_free("<font size='6' absz='32'>size 32</font>", + yahoo_codes_to_html("<font size='32'>size 32")); /* combinations */ - assert_string_equal_free("<font color=\"#FF0080\"><font size=\"4\" absz=\"15\">test", - yahoo_codes_to_html("\x1B[35m<font size=\"15\">test")); + assert_string_equal_free("<font face='Georgia' size='6' absz='32'>test</font>", + yahoo_codes_to_html("<font face='Georgia' size='32'>test")); + assert_string_equal_free("<font color='#FF0080'><font size='4' absz='15'>test</font></font>", + yahoo_codes_to_html("\x1B[35m<font size='15'>test")); #endif /* !USE_CSS_FORMATTING */ } END_TEST