summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.hgignore1
-rw-r--r--configure.ac1
-rw-r--r--libpurple/protocols/yahoo/Makefile.am2
-rw-r--r--libpurple/protocols/yahoo/tests/.hgignore7
-rw-r--r--libpurple/protocols/yahoo/tests/Makefile.am23
-rw-r--r--libpurple/protocols/yahoo/tests/test_yahoo_util.c246
-rw-r--r--libpurple/tests/test_yahoo_util.c214
7 files changed, 280 insertions, 214 deletions
diff --git a/.hgignore b/.hgignore
index af38381a64..d2bc378b04 100644
--- a/.hgignore
+++ b/.hgignore
@@ -150,5 +150,6 @@ stamp-h1
test-driver
win32-install-dir(\.release)?
+subinclude:libpurple/protocols/yahoo/tests/.hgignore
subinclude:libpurple/tests/.hgignore
diff --git a/configure.ac b/configure.ac
index 0a7d9b236b..762260793e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2264,6 +2264,7 @@ AC_CONFIG_FILES([Makefile
libpurple/protocols/silc/Makefile
libpurple/protocols/simple/Makefile
libpurple/protocols/yahoo/Makefile
+ libpurple/protocols/yahoo/tests/Makefile
libpurple/protocols/zephyr/Makefile
libpurple/tests/Makefile
libpurple/purple.h
diff --git a/libpurple/protocols/yahoo/Makefile.am b/libpurple/protocols/yahoo/Makefile.am
index 45cfb86f32..84ae3ed754 100644
--- a/libpurple/protocols/yahoo/Makefile.am
+++ b/libpurple/protocols/yahoo/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = tests
+
EXTRA_DIST = \
Makefile.mingw
diff --git a/libpurple/protocols/yahoo/tests/.hgignore b/libpurple/protocols/yahoo/tests/.hgignore
new file mode 100644
index 0000000000..263755d2bc
--- /dev/null
+++ b/libpurple/protocols/yahoo/tests/.hgignore
@@ -0,0 +1,7 @@
+syntax: regexp
+^test_yahoo_util$
+
+syntax: glob
+*.log
+*.trs
+
diff --git a/libpurple/protocols/yahoo/tests/Makefile.am b/libpurple/protocols/yahoo/tests/Makefile.am
new file mode 100644
index 0000000000..7012404bc7
--- /dev/null
+++ b/libpurple/protocols/yahoo/tests/Makefile.am
@@ -0,0 +1,23 @@
+include $(top_srcdir)/glib-tap.mk
+
+COMMON_LIBS=\
+ $(top_builddir)/libpurple/libpurple.la \
+ $(top_builddir)/libpurple/protocols/yahoo/libyahoo.la \
+ $(GLIB_LIBS) \
+ $(GPLUGIN_LIBS)
+
+test_programs=\
+ test_yahoo_util
+
+test_yahoo_util_SOURCES=test_yahoo_util.c
+test_yahoo_util_LDADD=$(COMMON_LIBS)
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/libpurple \
+ -I$(top_builddir)/libpurple \
+ $(DEBUG_CFLAGS) \
+ $(GLIB_CFLAGS) \
+ $(GPLUGIN_CFLAGS) \
+ $(PLUGIN_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(NSS_CFLAGS)
diff --git a/libpurple/protocols/yahoo/tests/test_yahoo_util.c b/libpurple/protocols/yahoo/tests/test_yahoo_util.c
new file mode 100644
index 0000000000..550878330b
--- /dev/null
+++ b/libpurple/protocols/yahoo/tests/test_yahoo_util.c
@@ -0,0 +1,246 @@
+#include <glib.h>
+
+#include "../ymsg.h"
+
+typedef struct {
+ gchar *input;
+ gchar *output;
+} YahooStringTestData;
+
+static void
+test_codes_to_html(void) {
+ YahooStringTestData data[] = {
+ {
+ "",
+ "",
+ }, {
+ "\x1B[12345m",
+ "",
+ }, {
+ "plain",
+ "plain",
+ }, {
+ "unknown \x1B[12345m ansi code",
+ "unknown ansi code",
+ }, {
+ "plain <peanut>",
+ "plain &lt;peanut&gt;",
+ }, {
+ "plain <peanut",
+ "plain &lt;peanut",
+ }, {
+ "plain> peanut",
+ "plain&gt; peanut",
+ }, {
+ "<font face='inva>lid'>test",
+ "<font face='inva&gt;lid'>test</font>",
+ }, {
+ "<font face='inva>lid",
+ "&lt;font face=&apos;inva&gt;lid",
+ }, {
+ "\x1B[1mbold",
+ "<b>bold</b>",
+ }, {
+ "\x1B[2mitalic",
+ "<i>italic</i>",
+ }, {
+ "\x1B[4munderline",
+ "<u>underline</u>",
+ }, {
+ "no\x1B[x4m markup",
+ "no markup",
+ }, {
+ /* bold italic underline */
+ "\x1B[1mbold\x1B[x1m \x1B[2mitalic\x1B[x2m \x1B[4munderline",
+ "<b>bold</b> <i>italic</i> <u>underline</u>",
+ }, {
+ "\x1B[1mbold \x1B[2mbolditalic\x1B[x1m italic",
+ "<b>bold <i>bolditalic</i></b><i> italic</i>",
+ }, {
+ "\x1B[1mbold \x1B[2mbolditalic\x1B[x1m \x1B[4mitalicunderline",
+ "<b>bold <i>bolditalic</i></b><i> <u>italicunderline</u></i>",
+ }, {
+ "\x1B[1mbold \x1B[2mbolditalic \x1B[4mbolditalicunderline\x1B[x2m boldunderline",
+ "<b>bold <i>bolditalic <u>bolditalicunderline</u></i><u> boldunderline</u></b>",
+ }, {
+ "\x1B[1mbold \x1B[2mbolditalic \x1B[4mbolditalicunderline\x1B[x1m italicunderline",
+ "<b>bold <i>bolditalic <u>bolditalicunderline</u></i></b><i><u> italicunderline</u></i>",
+ }, {
+ /* links */
+ "\x1B[lmhttps://pidgin.im/\x1B[xlm",
+ "https://pidgin.im/",
+ }, {
+ /* font color */
+ "\x1B[31mblue",
+ "<font color='#0000FF'>blue</font>",
+ }, {
+ "\x1B[#70ea15mcustom color",
+ "<font color='#70ea15'>custom color</font>",
+ }, {
+ "<ALT #ff0000,#00ff00,#0000ff>test</ALT>",
+ "test",
+ }, {
+ /* font face */
+ "<font face='Georgia'>test",
+ "<font face='Georgia'>test</font>",
+ }, {
+ /* font size */
+ "<font size='15'>test",
+ "<font size='4' absz='15'>test</font>",
+ }, {
+ "<font size='32'>size 32",
+ "<font size='6' absz='32'>size 32</font>",
+ }, {
+ /* combinations */
+ "<font face='Georgia' size='32'>test",
+ "<font face='Georgia' size='6' absz='32'>test</font>",
+ }, {
+ "\x1B[35m<font size='15'>test",
+ "<font color='#FF0080'><font size='4' absz='15'>test</font></font>",
+ }, {
+ "<FADE #ff0000,#00ff00,#0000ff>:<</FADE>",
+ ":&lt;",
+ }, {
+ NULL,
+ NULL,
+ }
+ };
+ gint i;
+
+ yahoo_init_colorht();
+
+ for(i = 0; data[i].input; i++) {
+ gchar *result = yahoo_codes_to_html(data[i].input);
+
+ g_assert_cmpstr(result, ==, data[i].output);
+
+ g_free(result);
+ }
+
+ yahoo_dest_colorht();
+}
+
+static void
+test_html_to_codes(void) {
+ YahooStringTestData data[] = {
+ {
+ "plain",
+ "plain",
+ }, {
+ "plain &lt;peanut&gt;",
+ "plain <peanut>",
+ }, {
+ "plain &lt;peanut",
+ "plain <peanut",
+ }, {
+ "plain&gt; peanut",
+ "plain> peanut",
+ }, {
+ "plain &gt;",
+ "plain >",
+ }, {
+ "plain &gt; ",
+ "plain > ",
+ }, {
+ "plain &lt;",
+ "plain <",
+ }, {
+ "plain &lt; ",
+ "plain < ",
+ }, {
+ "plain &lt",
+ "plain &lt",
+ }, {
+ "plain &amp;",
+ "plain &",
+ }, {
+ /* bold/italic/underline */
+ "<b>bold</b>",
+ "\x1B[1mbold\x1B[x1m",
+ }, {
+ "<i>italic</i>",
+ "\x1B[2mitalic\x1B[x2m",
+ }, {
+ "<u>underline</u>",
+ "\x1B[4munderline\x1B[x4m",
+ }, {
+ "no</u> markup",
+ "no markup",
+ }, {
+ "<b>bold</b> <i>italic</i> <u>underline</u>",
+ "\x1B[1mbold\x1B[x1m \x1B[2mitalic\x1B[x2m \x1B[4munderline\x1B[x4m",
+ }, {
+ "<b>bold <i>bolditalic</i></b><i> italic</i>",
+ "\x1B[1mbold \x1B[2mbolditalic\x1B[x2m\x1B[x1m\x1B[2m italic\x1B[x2m",
+ }, {
+ "<b>bold <i>bolditalic</i></b><i> <u>italicunderline</u></i>",
+ "\x1B[1mbold \x1B[2mbolditalic\x1B[x2m\x1B[x1m\x1B[2m \x1B[4mitalicunderline\x1B[x4m\x1B[x2m",
+ }, {
+ /* link */
+ "<A HREF=\"https://pidgin.im/\">https://pidgin.im/</A>",
+ "https://pidgin.im/",
+ }, {
+ "<A HREF=\"mailto:mark@example.com\">mark@example.com</A>",
+ "mark@example.com",
+ }, {
+ /* font nothing */
+ "<font>nothing</font>",
+ "nothing",
+ }, {
+ /* font color */
+ "<font color=\"#E71414\">red</font>",
+ "\x1B[#E71414mred\x1B[#000000m",
+ }, {
+ "<font color=\"#FF0000\">red</font> <font color=\"#0000FF\">blue</font> black",
+ "\x1B[#FF0000mred\x1B[#000000m \x1B[#0000FFmblue\x1B[#000000m black",
+ }, {
+ /* font size */
+ "<font size=\"2\">test</font>",
+ "<font size=\"10\">test</font>",
+ }, {
+ "<font size=\"6\">test</font>",
+ "<font size=\"30\">test</font>",
+ }, {
+ /* combinations */
+ "<font color=\"#FF0000\"><font size=\"1\">redsmall</font> rednormal</font>",
+ "\x1B[#FF0000m<font size=\"8\">redsmall</font> rednormal\x1B[#000000m",
+ }, {
+ "<font color=\"#FF0000\"><font size=\"1\">redsmall</font> <font color=\"#00FF00\">greennormal</font> rednormal</font>",
+ "\x1B[#FF0000m<font size=\"8\">redsmall</font> \x1B[#00FF00mgreennormal\x1B[#FF0000m rednormal\x1B[#000000m",
+ }, {
+ "<b>bold <font color=\"#FF0000\">red <font face=\"Comic Sans MS\" size=\"5\">larger <font color=\"#000000\">backtoblack <font size=\"3\">normalsize</font></font></font></font></b>",
+ "\x1B[1mbold \x1B[#FF0000mred <font face=\"Comic Sans MS\" size=\"20\">larger \x1B[#000000mbacktoblack <font size=\"12\">normalsize</font>\x1B[#FF0000m</font>\x1B[#000000m\x1B[x1m",
+ }, {
+ /* buzz/unknown tags */
+ "<ding>",
+ "<ding>",
+ }, {
+ "Unknown <tags>",
+ "Unknown <tags>",
+ }, {
+ NULL,
+ NULL,
+ }
+ };
+ gint i;
+
+ for(i = 0; data[i].input; i++) {
+ gchar *result = yahoo_html_to_codes(data[i].input);
+
+ g_assert_cmpstr(result, ==, data[i].output);
+
+ g_free(result);
+ }
+}
+
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/yahoo/format/network to html",
+ test_codes_to_html);
+ g_test_add_func("/yahoo/format/html to network",
+ test_html_to_codes);
+
+ return g_test_run();
+}
diff --git a/libpurple/tests/test_yahoo_util.c b/libpurple/tests/test_yahoo_util.c
deleted file mode 100644
index ed644eaf48..0000000000
--- a/libpurple/tests/test_yahoo_util.c
+++ /dev/null
@@ -1,214 +0,0 @@
-#include <string.h>
-
-#include "tests.h"
-#include "../protocols/yahoo/ymsg.h"
-
-static void setup_codes_to_html(void)
-{
- yahoo_init_colorht();
-}
-
-static void teardown_codes_to_html(void)
-{
- yahoo_dest_colorht();
-}
-
-START_TEST(test_codes_to_html)
-{
- assert_string_equal_free("",
- yahoo_codes_to_html(""));
- assert_string_equal_free("",
- yahoo_codes_to_html("\x1B[12345m"));
- 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 &lt;peanut&gt;",
- yahoo_codes_to_html("plain <peanut>"));
- assert_string_equal_free("plain &lt;peanut",
- yahoo_codes_to_html("plain <peanut"));
- assert_string_equal_free("plain&gt; peanut",
- yahoo_codes_to_html("plain> peanut"));
- assert_string_equal_free("<font face='inva&gt;lid'>test</font>",
- yahoo_codes_to_html("<font face='inva>lid'>test"));
- assert_string_equal_free("&lt;font face=&apos;inva&gt;lid",
- yahoo_codes_to_html("<font face='inva>lid"));
-
- /* bold/italic/underline */
- assert_string_equal_free("<b>bold</b>",
- yahoo_codes_to_html("\x1B[1mbold"));
- assert_string_equal_free("<i>italic</i>",
- yahoo_codes_to_html("\x1B[2mitalic"));
- assert_string_equal_free("<u>underline</u>",
- yahoo_codes_to_html("\x1B[4munderline"));
- 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"));
-
- /* link */
- assert_string_equal_free("https://pidgin.im/",
- yahoo_codes_to_html("\x1B[lmhttps://pidgin.im/\x1B[xlm"));
-
-#ifdef USE_CSS_FORMATTING
- /* font color */
- 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</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</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("<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</font>",
- yahoo_codes_to_html("\x1B[31mblue"));
- 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</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 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"));
- assert_string_equal_free(":&lt;",
- yahoo_codes_to_html("<FADE #ff0000,#00ff00,#0000ff>:<</FADE>"));
-#endif /* !USE_CSS_FORMATTING */
-}
-END_TEST
-
-START_TEST(test_html_to_codes)
-{
- assert_string_equal_free("plain",
- yahoo_html_to_codes("plain"));
- assert_string_equal_free("plain <peanut>",
- yahoo_html_to_codes("plain &lt;peanut&gt;"));
- assert_string_equal_free("plain <peanut",
- yahoo_html_to_codes("plain &lt;peanut"));
- assert_string_equal_free("plain> peanut",
- yahoo_html_to_codes("plain&gt; peanut"));
- assert_string_equal_free("plain >",
- yahoo_html_to_codes("plain &gt;"));
- assert_string_equal_free("plain > ",
- yahoo_html_to_codes("plain &gt; "));
- assert_string_equal_free("plain <",
- yahoo_html_to_codes("plain &lt;"));
- assert_string_equal_free("plain < ",
- yahoo_html_to_codes("plain &lt; "));
- assert_string_equal_free("plain &lt",
- yahoo_html_to_codes("plain &lt"));
- assert_string_equal_free("plain &",
- yahoo_html_to_codes("plain &amp;"));
-
- /* bold/italic/underline */
- assert_string_equal_free("\x1B[1mbold\x1B[x1m",
- yahoo_html_to_codes("<b>bold</b>"));
- assert_string_equal_free("\x1B[2mitalic\x1B[x2m",
- yahoo_html_to_codes("<i>italic</i>"));
- assert_string_equal_free("\x1B[4munderline\x1B[x4m",
- yahoo_html_to_codes("<u>underline</u>"));
- assert_string_equal_free("no markup",
- yahoo_html_to_codes("no</u> markup"));
- assert_string_equal_free("\x1B[1mbold\x1B[x1m \x1B[2mitalic\x1B[x2m \x1B[4munderline\x1B[x4m",
- yahoo_html_to_codes("<b>bold</b> <i>italic</i> <u>underline</u>"));
- assert_string_equal_free("\x1B[1mbold \x1B[2mbolditalic\x1B[x2m\x1B[x1m\x1B[2m italic\x1B[x2m",
- yahoo_html_to_codes("<b>bold <i>bolditalic</i></b><i> italic</i>"));
- assert_string_equal_free("\x1B[1mbold \x1B[2mbolditalic\x1B[x2m\x1B[x1m\x1B[2m \x1B[4mitalicunderline\x1B[x4m\x1B[x2m",
- yahoo_html_to_codes("<b>bold <i>bolditalic</i></b><i> <u>italicunderline</u></i>"));
-
- /* link */
- assert_string_equal_free("https://pidgin.im/",
- yahoo_html_to_codes("<A HREF=\"https://pidgin.im/\">https://pidgin.im/</A>"));
- assert_string_equal_free("mark@example.com",
- yahoo_html_to_codes("<A HREF=\"mailto:mark@example.com\">mark@example.com</A>"));
-#if 0
- assert_string_equal_free("Pidgin (https://pidgin.im/)",
- yahoo_html_to_codes("<A HREF=\"https://pidgin.im/\">Pidgin</A>"));
-#endif
-
- /* font nothing */
- assert_string_equal_free("nothing",
- yahoo_html_to_codes("<font>nothing</font>"));
-
- /* font color */
- assert_string_equal_free("\x1B[#E71414mred\x1B[#000000m",
- yahoo_html_to_codes("<font color=\"#E71414\">red</font>"));
- assert_string_equal_free("\x1B[#FF0000mred\x1B[#000000m \x1B[#0000FFmblue\x1B[#000000m black",
- yahoo_html_to_codes("<font color=\"#FF0000\">red</font> <font color=\"#0000FF\">blue</font> black"));
-
- /* font size */
- assert_string_equal_free("<font size=\"10\">test</font>",
- yahoo_html_to_codes("<font size=\"2\">test</font>"));
- assert_string_equal_free("<font size=\"30\">test</font>",
- yahoo_html_to_codes("<font size=\"6\">test</font>"));
-
- /* combinations */
- assert_string_equal_free("\x1B[#FF0000m<font size=\"8\">redsmall</font> rednormal\x1B[#000000m",
- yahoo_html_to_codes("<font color=\"#FF0000\"><font size=\"1\">redsmall</font> rednormal</font>"));
-
- assert_string_equal_free("\x1B[#FF0000m<font size=\"8\">redsmall</font> \x1B[#00FF00mgreennormal\x1B[#FF0000m rednormal\x1B[#000000m",
- yahoo_html_to_codes("<font color=\"#FF0000\"><font size=\"1\">redsmall</font> <font color=\"#00FF00\">greennormal</font> rednormal</font>"));
-
- assert_string_equal_free("\x1B[1mbold \x1B[#FF0000mred <font face=\"Comic Sans MS\" size=\"20\">larger \x1B[#000000mbacktoblack <font size=\"12\">normalsize</font>\x1B[#FF0000m</font>\x1B[#000000m\x1B[x1m",
- yahoo_html_to_codes("<b>bold <font color=\"#FF0000\">red <font face=\"Comic Sans MS\" size=\"5\">larger <font color=\"#000000\">backtoblack <font size=\"3\">normalsize</font></font></font></font></b>"));
-
- /* buzz/unknown tags */
- assert_string_equal_free("<ding>",
- yahoo_html_to_codes("<ding>"));
- assert_string_equal_free("Unknown <tags>",
- yahoo_html_to_codes("Unknown <tags>"));
-}
-END_TEST
-
-Suite *
-yahoo_util_suite(void)
-{
- Suite *s;
- TCase *tc;
-
- s = suite_create("Yahoo Utility Functions");
-
- tc = tcase_create("Convert IM from network format to HTML");
- tcase_add_unchecked_fixture(tc, setup_codes_to_html, teardown_codes_to_html);
- tcase_add_test(tc, test_codes_to_html);
- suite_add_tcase(s, tc);
-
- tc = tcase_create("Convert IM from HTML to network format");
- tcase_add_test(tc, test_html_to_codes);
- suite_add_tcase(s, tc);
-
- return s;
-}