[gmime] Added unit tests for GMimeFilterHTML



commit dba434c2bfdae19c44a2c569c1517cc4cf7948cc
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Sun Dec 17 15:41:27 2017 -0500

    Added unit tests for GMimeFilterHTML

 tests/data/filters/html-input.txt              |   21 ++++++++
 tests/data/filters/html-output.blockquote.html |   22 ++++++++
 tests/data/filters/html-output.cite.html       |   22 ++++++++
 tests/data/filters/html-output.mark.html       |   22 ++++++++
 tests/test-filters.c                           |   64 ++++++++++++++++++++++++
 tests/test-html.c                              |    6 +--
 6 files changed, 153 insertions(+), 4 deletions(-)
---
diff --git a/tests/data/filters/html-input.txt b/tests/data/filters/html-input.txt
new file mode 100644
index 0000000..1191c31
--- /dev/null
+++ b/tests/data/filters/html-input.txt
@@ -0,0 +1,21 @@
+This is a sample message body with some embedded urls such as Google's
+search page at www.google.com. Did it capture that last period? I hope
+not! How about ftp.freebsd.org/pub/FreeBSD/ or even an email address
+like fejj gnome org? It should also work with mailto urls. Let's try
+it, shall we? We can use mailto:fejj gnome org as a simple case...
+
+We should also check that GMimeFilterHTML is able to detect full urls
+like https://github.com/jstedfast/gmime - GMime's very own website!
+
+Or file://localhost/dev/null file URLs.
+
+And how about quoting? Let's give that a try...
+
+> This is one level of quoting
+> > And this is two levels of quoting
+> > Yet more text that is quoted twice...
+> This is back down to one level...
+> > > And this is three levels! WOW! CRAZY!
+Okay, let's not get too carried away...
+
+Did that work as expected?
diff --git a/tests/data/filters/html-output.blockquote.html b/tests/data/filters/html-output.blockquote.html
new file mode 100644
index 0000000..efff0e1
--- /dev/null
+++ b/tests/data/filters/html-output.blockquote.html
@@ -0,0 +1,22 @@
+This is a sample message body with some embedded urls such as Google's<br>
+search page at <a href="http://www.google.com";>www.google.com</a>. Did it capture that last period? I 
hope<br>
+not! How about <a href="ftp://ftp.freebsd.org/pub/FreeBSD/";>ftp.freebsd.org/pub/FreeBSD/</a>&nbsp;or even an 
email address<br>
+like <a href="mailto:fejj gnome org">fejj gnome org</a>? It should also work with mailto urls. Let's try<br>
+it, shall we? We can use <a href="mailto:fejj gnome org">mailto:fejj gnome org</a>&nbsp;as a simple 
case...<br>
+<br>
+We should also check that GMimeFilterHTML is able to detect full urls<br>
+like <a href="https://github.com/jstedfast/gmime";>https://github.com/jstedfast/gmime</a>&nbsp;- GMime's very 
own website!<br>
+<br>
+Or <a href="file://localhost/dev/null">file://localhost/dev/null</a>&nbsp;file URLs.<br>
+<br>
+And how about quoting? Let's give that a try...<br>
+<br>
+<blockquote class="level_001">This is one level of quoting<br>
+<blockquote class="level_002">And this is two levels of quoting<br>
+Yet more text that is quoted twice...<br>
+</blockquote>This is back down to one level...<br>
+<blockquote class="level_002"><blockquote class="level_003">And this is three levels! WOW! CRAZY!<br>
+</blockquote></blockquote></blockquote>Okay, let's not get too carried away...<br>
+<br>
+Did that work as expected?<br>
+<br>
\ No newline at end of file
diff --git a/tests/data/filters/html-output.cite.html b/tests/data/filters/html-output.cite.html
new file mode 100644
index 0000000..a489d67
--- /dev/null
+++ b/tests/data/filters/html-output.cite.html
@@ -0,0 +1,22 @@
+&gt; This is a sample message body with some embedded urls such as Google's<br>
+&gt; search page at <a href="http://www.google.com";>www.google.com</a>. Did it capture that last period? I 
hope<br>
+&gt; not! How about <a href="ftp://ftp.freebsd.org/pub/FreeBSD/";>ftp.freebsd.org/pub/FreeBSD/</a>&nbsp;or 
even an email address<br>
+&gt; like <a href="mailto:fejj gnome org">fejj gnome org</a>? It should also work with mailto urls. Let's 
try<br>
+&gt; it, shall we? We can use <a href="mailto:fejj gnome org">mailto:fejj gnome org</a>&nbsp;as a simple 
case...<br>
+&gt; <br>
+&gt; We should also check that GMimeFilterHTML is able to detect full urls<br>
+&gt; like <a href="https://github.com/jstedfast/gmime";>https://github.com/jstedfast/gmime</a>&nbsp;- GMime's 
very own website!<br>
+&gt; <br>
+&gt; Or <a href="file://localhost/dev/null">file://localhost/dev/null</a>&nbsp;file URLs.<br>
+&gt; <br>
+&gt; And how about quoting? Let's give that a try...<br>
+&gt; <br>
+&gt; &gt; This is one level of quoting<br>
+&gt; &gt; &gt; And this is two levels of quoting<br>
+&gt; &gt; &gt; Yet more text that is quoted twice...<br>
+&gt; &gt; This is back down to one level...<br>
+&gt; &gt; &gt; &gt; And this is three levels! WOW! CRAZY!<br>
+&gt; Okay, let's not get too carried away...<br>
+&gt; <br>
+&gt; Did that work as expected?<br>
+&gt; <br>
\ No newline at end of file
diff --git a/tests/data/filters/html-output.mark.html b/tests/data/filters/html-output.mark.html
new file mode 100644
index 0000000..76a02d0
--- /dev/null
+++ b/tests/data/filters/html-output.mark.html
@@ -0,0 +1,22 @@
+This is a sample message body with some embedded urls such as Google's<br>
+search page at <a href="http://www.google.com";>www.google.com</a>. Did it capture that last period? I 
hope<br>
+not! How about <a href="ftp://ftp.freebsd.org/pub/FreeBSD/";>ftp.freebsd.org/pub/FreeBSD/</a>&nbsp;or even an 
email address<br>
+like <a href="mailto:fejj gnome org">fejj gnome org</a>? It should also work with mailto urls. Let's try<br>
+it, shall we? We can use <a href="mailto:fejj gnome org">mailto:fejj gnome org</a>&nbsp;as a simple 
case...<br>
+<br>
+We should also check that GMimeFilterHTML is able to detect full urls<br>
+like <a href="https://github.com/jstedfast/gmime";>https://github.com/jstedfast/gmime</a>&nbsp;- GMime's very 
own website!<br>
+<br>
+Or <a href="file://localhost/dev/null">file://localhost/dev/null</a>&nbsp;file URLs.<br>
+<br>
+And how about quoting? Let's give that a try...<br>
+<br>
+<font color="#008888">&gt; This is one level of quoting</font><br>
+<font color="#008888">&gt; &gt; And this is two levels of quoting</font><br>
+<font color="#008888">&gt; &gt; Yet more text that is quoted twice...</font><br>
+<font color="#008888">&gt; This is back down to one level...</font><br>
+<font color="#008888">&gt; &gt; &gt; And this is three levels! WOW! CRAZY!</font><br>
+Okay, let's not get too carried away...<br>
+<br>
+Did that work as expected?<br>
+<br>
\ No newline at end of file
diff --git a/tests/test-filters.c b/tests/test-filters.c
index 0144a6f..45e4ad8 100644
--- a/tests/test-filters.c
+++ b/tests/test-filters.c
@@ -319,6 +319,66 @@ error:
 }
 
 static void
+test_html (const char *datadir, const char *input, const char *output, guint32 citation)
+{
+       guint32 flags = GMIME_FILTER_HTML_CONVERT_NL | GMIME_FILTER_HTML_CONVERT_SPACES |
+               GMIME_FILTER_HTML_CONVERT_URLS | GMIME_FILTER_HTML_CONVERT_ADDRESSES;
+       const char *what = "GMimeFilterHtml", *mode;
+       GByteArray *expected, *actual;
+       GMimeStream *stream;
+       GMimeFilter *filter;
+       char *path;
+       
+       switch (citation) {
+       case GMIME_FILTER_HTML_BLOCKQUOTE_CITATION: mode = "blockquote"; break;
+       case GMIME_FILTER_HTML_MARK_CITATION: mode = "mark"; break;
+       case GMIME_FILTER_HTML_CITE: mode = "cite"; break;
+       default: mode = "none"; break;
+       }
+       
+       testsuite_check ("%s (%s %s)", what, input, mode);
+       
+       actual = g_byte_array_new ();
+       stream = g_mime_stream_mem_new_with_byte_array (actual);
+       g_mime_stream_mem_set_owner ((GMimeStreamMem *) stream, FALSE);
+       
+       filter = g_mime_filter_html_new (flags | citation, 0x008888);
+       
+       path = g_build_filename (datadir, input, NULL);
+       pump_data_through_filter (filter, path, stream, TRUE, TRUE);
+       g_mime_filter_reset (filter);
+       g_object_unref (stream);
+       g_object_unref (filter);
+       g_free (path);
+       
+       path = g_build_filename (datadir, output, NULL);
+       expected = read_all_bytes (path, TRUE);
+       g_free (path);
+       
+       if (actual->len != expected->len) {
+               testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u",
+                                       what, expected->len, actual->len);
+               stream = g_mime_stream_fs_open (output, O_WRONLY | O_CREAT, 0644, NULL);
+               g_mime_stream_write (stream, (const char *) actual->data, actual->len);
+               g_mime_stream_flush (stream);
+               g_object_unref (stream);
+               goto error;
+       }
+       
+       if (memcmp (actual->data, expected->data, actual->len) != 0) {
+               testsuite_check_failed ("%s failed: stream contents do not match", what);
+               goto error;
+       }
+       
+       testsuite_check_passed ();
+       
+error:
+       
+       g_byte_array_free (expected, TRUE);
+       g_byte_array_free (actual, TRUE);
+}
+
+static void
 test_smtp_data (const char *datadir, const char *input, const char *output)
 {
        const char *what = "GMimeFilterSmtpData";
@@ -446,6 +506,10 @@ int main (int argc, char **argv)
        test_gzip (datadir, "lorem-ipsum.txt");
        test_gunzip (datadir, "lorem-ipsum.txt");
        
+       test_html (datadir, "html-input.txt", "html-output.blockquote.html", 
GMIME_FILTER_HTML_BLOCKQUOTE_CITATION);
+       test_html (datadir, "html-input.txt", "html-output.mark.html", GMIME_FILTER_HTML_MARK_CITATION);
+       test_html (datadir, "html-input.txt", "html-output.cite.html", GMIME_FILTER_HTML_CITE);
+       
        test_smtp_data (datadir, "smtp-input.txt", "smtp-output.txt");
        
        test_windows (datadir, "french-fable.cp1252.txt", "iso-8859-1", "windows-cp1252");
diff --git a/tests/test-html.c b/tests/test-html.c
index 7d4f5b5..4f4999a 100644
--- a/tests/test-html.c
+++ b/tests/test-html.c
@@ -37,11 +37,9 @@ int main (int argc, char **argv)
        html = g_mime_filter_html_new (GMIME_FILTER_HTML_CONVERT_NL |
                                       GMIME_FILTER_HTML_CONVERT_SPACES |
                                       GMIME_FILTER_HTML_CONVERT_URLS |
-                                      GMIME_FILTER_HTML_MARK_CITATION |
                                       GMIME_FILTER_HTML_CONVERT_ADDRESSES |
-                                      GMIME_FILTER_HTML_ESCAPE_8BIT |
-                                      GMIME_FILTER_HTML_CITE, 0);
-       /*html = g_mime_filter_from_new (GMIME_FILTER_FROM_MODE_ESCAPE);*/
+                                      GMIME_FILTER_HTML_MARK_CITATION |
+                                      GMIME_FILTER_HTML_ESCAPE_8BIT, 0x008888);
        g_mime_stream_filter_add (GMIME_STREAM_FILTER (ostream), html);
        g_object_unref (html);
        


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]