aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-04-10 19:35:00 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-04-10 19:35:00 +0800
commit2e7d1434aedfbb634ede57faf6741dae5419d520 (patch)
treec899efdc2fdbce344fbced33e345868d4259a37c
parent0933b12476c210975487cd29c3e05a0f248eac04 (diff)
downloadgsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.tar
gsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.tar.gz
gsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.tar.bz2
gsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.tar.lz
gsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.tar.xz
gsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.tar.zst
gsoc2013-evolution-2e7d1434aedfbb634ede57faf6741dae5419d520.zip
filter data test cases.
2003-04-10 Not Zed <NotZed@Ximian.com> * tests/mime-filter/data: filter data test cases. * tests/mime-filter/test-tohtml.c: New test for html filter. ** See bug #40969 * camel-mime-filter-tohtml.c (html_convert): Change the logic slightly, scan a whole line within the main loop. svn path=/trunk/; revision=20799
-rw-r--r--camel/ChangeLog11
-rw-r--r--camel/camel-mime-filter-tohtml.c32
-rw-r--r--camel/providers/imap/camel-imap-store.c2
-rw-r--r--camel/tests/mime-filter/Makefile.am5
-rw-r--r--camel/tests/mime-filter/data/html.0.in10
-rw-r--r--camel/tests/mime-filter/data/html.0.out10
-rw-r--r--camel/tests/mime-filter/data/html.1.in10
-rw-r--r--camel/tests/mime-filter/data/html.1.out10
-rw-r--r--camel/tests/mime-filter/test-tohtml.c132
9 files changed, 205 insertions, 17 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 51046e119d..528d7aa03c 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,14 @@
+2003-04-10 Not Zed <NotZed@Ximian.com>
+
+ * tests/mime-filter/data: filter data test cases.
+
+ * tests/mime-filter/test-tohtml.c: New test for html filter.
+
+ ** See bug #40969
+
+ * camel-mime-filter-tohtml.c (html_convert): Change the logic
+ slightly, scan a whole line within the main loop.
+
2003-04-09 Jeffrey Stedfast <fejj@ximian.com>
* camel-gpg-context.c (gpg_ctx_get_utf8_diagnostics): Removed. I
diff --git a/camel/camel-mime-filter-tohtml.c b/camel/camel-mime-filter-tohtml.c
index 60c4686824..ca10d3d438 100644
--- a/camel/camel-mime-filter-tohtml.c
+++ b/camel/camel-mime-filter-tohtml.c
@@ -220,6 +220,14 @@ html_convert (CamelMimeFilter *filter, char *in, size_t inlen, size_t prespace,
char *start, *outend;
const char *inend;
int depth;
+
+ if (inlen == 0) {
+ *out = in;
+ *outlen = 0;
+ *outprespace = 0;
+
+ return;
+ }
camel_mime_filter_set_size (filter, inlen * 2 + 6, FALSE);
@@ -232,25 +240,24 @@ html_convert (CamelMimeFilter *filter, char *in, size_t inlen, size_t prespace,
outptr = g_stpcpy (outptr, "<pre>");
html->pre_open = TRUE;
}
-
+
start = inptr;
- while (inptr < inend && *inptr != '\n')
- inptr++;
-
- while (inptr < inend) {
+ do {
+ while (inptr < inend && *inptr != '\n')
+ inptr++;
+
+ if (*inptr != '\n' && !flush)
+ break;
+
html->column = 0;
depth = 0;
if (html->flags & CAMEL_MIME_FILTER_TOHTML_MARK_CITATION) {
if ((depth = citation_depth (start)) > 0) {
- char font[25];
-
/* FIXME: we could easily support multiple colour depths here */
- g_snprintf (font, 25, "<font color=\"#%06x\">", html->colour);
-
outptr = check_size (filter, outptr, &outend, 25);
- outptr = g_stpcpy (outptr, font);
+ outptr += sprintf(outptr, "<font color=\"#%06x\">", (html->colour & 0xffffff));
} else if (*start == '>') {
/* >From line */
start++;
@@ -319,11 +326,8 @@ html_convert (CamelMimeFilter *filter, char *in, size_t inlen, size_t prespace,
}
*outptr++ = '\n';
-
start = ++inptr;
- while (inptr < inend && *inptr != '\n')
- inptr++;
- }
+ } while (inptr < inend);
if (flush) {
/* flush the rest of our input buffer */
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 7004b7d6a7..3b045fd084 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -2433,7 +2433,7 @@ get_one_folder_offline (const char *physical_path, const char *path, gpointer da
si = camel_store_summary_path((CamelStoreSummary *)imap_store->summary, path+1);
if (si) {
if ((((CamelStore *)imap_store)->flags & CAMEL_STORE_SUBSCRIPTIONS) == 0
- || si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) {
+ || (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED)) {
fi = imap_build_folder_info(imap_store, path+1);
fi->flags = si->flags;
if (si->flags & CAMEL_FOLDER_NOSELECT) {
diff --git a/camel/tests/mime-filter/Makefile.am b/camel/tests/mime-filter/Makefile.am
index 2c83f1202f..21635f839f 100644
--- a/camel/tests/mime-filter/Makefile.am
+++ b/camel/tests/mime-filter/Makefile.am
@@ -27,9 +27,10 @@ EXTRA_DIST = \
check_PROGRAMS = \
test-crlf \
- test-charset
+ test-charset \
+ test-tohtml
-TESTS = test-crlf test-charset
+TESTS = test-crlf test-charset test-tohtml
diff --git a/camel/tests/mime-filter/data/html.0.in b/camel/tests/mime-filter/data/html.0.in
new file mode 100644
index 0000000000..217f85b4ff
--- /dev/null
+++ b/camel/tests/mime-filter/data/html.0.in
@@ -0,0 +1,10 @@
+
+College of Engineering Students,
+
+We are contacting you to request that you consider nominating a College
+of Engineering faculty member for the College's 2003 Excellence in
+Teaching Award. The award criteria and nomination form are attached.
+They can also be found on the web at:
+
+ <http://www.ce.udel.edu/teaching_award.html>
+ <http://www.ce.udel.edu/nomination_form.html>
diff --git a/camel/tests/mime-filter/data/html.0.out b/camel/tests/mime-filter/data/html.0.out
new file mode 100644
index 0000000000..3f19310dd4
--- /dev/null
+++ b/camel/tests/mime-filter/data/html.0.out
@@ -0,0 +1,10 @@
+
+College of Engineering Students,
+
+We are contacting you to request that you consider nominating a College
+of Engineering faculty member for the College's 2003 Excellence in
+Teaching Award. The award criteria and nomination form are attached.
+They can also be found on the web at:
+
+&#9;&lt;<a href="http://www.ce.udel.edu/teaching_award.html">http://www.ce.udel.edu/teaching_award.html</a>&gt;
+&#9;&lt;<a href="http://www.ce.udel.edu/nomination_form.html">http://www.ce.udel.edu/nomination_form.html</a>&gt;
diff --git a/camel/tests/mime-filter/data/html.1.in b/camel/tests/mime-filter/data/html.1.in
new file mode 100644
index 0000000000..8dece6113d
--- /dev/null
+++ b/camel/tests/mime-filter/data/html.1.in
@@ -0,0 +1,10 @@
+
+College of Engineering Students,
+
+We are contacting you to request that you consider nominating a College
+of Engineering faculty member for the College's 2003 Excellence in
+Teaching Award. The award criteria and nomination form are attached.
+They can also be found on the web at:
+
+ <http://www.ce.udel.edu/teaching_award.html>
+ <http://www.ce.udel.edu/nomination_form.html> \ No newline at end of file
diff --git a/camel/tests/mime-filter/data/html.1.out b/camel/tests/mime-filter/data/html.1.out
new file mode 100644
index 0000000000..3f19310dd4
--- /dev/null
+++ b/camel/tests/mime-filter/data/html.1.out
@@ -0,0 +1,10 @@
+
+College of Engineering Students,
+
+We are contacting you to request that you consider nominating a College
+of Engineering faculty member for the College's 2003 Excellence in
+Teaching Award. The award criteria and nomination form are attached.
+They can also be found on the web at:
+
+&#9;&lt;<a href="http://www.ce.udel.edu/teaching_award.html">http://www.ce.udel.edu/teaching_award.html</a>&gt;
+&#9;&lt;<a href="http://www.ce.udel.edu/nomination_form.html">http://www.ce.udel.edu/nomination_form.html</a>&gt;
diff --git a/camel/tests/mime-filter/test-tohtml.c b/camel/tests/mime-filter/test-tohtml.c
new file mode 100644
index 0000000000..5b7842fefe
--- /dev/null
+++ b/camel/tests/mime-filter/test-tohtml.c
@@ -0,0 +1,132 @@
+/*
+ test-html.c
+
+ Test the CamelMimeFilterToHTML class
+*/
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#include "camel-test.h"
+
+#include <camel/camel-stream-fs.h>
+#include <camel/camel-stream-mem.h>
+#include <camel/camel-stream-filter.h>
+#include <camel/camel-mime-filter-tohtml.h>
+
+#define d(x) x
+
+#define CHUNK_SIZE 4096
+
+static void
+test_filter(CamelMimeFilter *f, const char *inname, const char *outname)
+{
+ CamelStreamMem *in, *out;
+ CamelStream *indisk, *outdisk, *filter;
+ int id;
+
+ camel_test_push("Data file `%s'", inname);
+
+ camel_test_push("setup");
+
+ indisk = camel_stream_fs_new_with_name(inname, O_RDONLY, 0);
+ check(indisk);
+ outdisk = camel_stream_fs_new_with_name(outname, O_RDONLY, 0);
+ check(outdisk);
+
+ out = (CamelStreamMem *)camel_stream_mem_new();
+ check(camel_stream_write_to_stream(outdisk, (CamelStream *)out) > 0);
+
+ camel_test_pull();
+
+ camel_test_push("reading through filter stream");
+
+ in = (CamelStreamMem *)camel_stream_mem_new();
+
+ filter = (CamelStream *)camel_stream_filter_new_with_stream(indisk);
+ check_count(indisk, 2);
+ id = camel_stream_filter_add((CamelStreamFilter *)filter, f);
+ check_count(f, 2);
+
+ check(camel_stream_write_to_stream(filter, (CamelStream *)in) > 0);
+ check_msg(in->buffer->len == out->buffer->len
+ && memcmp(in->buffer->data, out->buffer->data, in->buffer->len) == 0,
+ "Buffer content mismatch, %d != %d, in = '%.*s' != out = '%.*s'", in->buffer->len, out->buffer->len,
+ in->buffer->len, in->buffer->data, out->buffer->len, out->buffer->data);
+
+ camel_test_pull();
+
+ camel_stream_filter_remove((CamelStreamFilter *)filter, id);
+ check_count(f, 1);
+ camel_mime_filter_reset(f);
+
+ check_unref(filter, 1);
+ check_count(indisk, 1);
+ check_count(f, 1);
+ check_unref(in, 1);
+
+ check(camel_stream_reset(indisk) == 0);
+
+ camel_test_push("writing through filter stream");
+
+ in = (CamelStreamMem *)camel_stream_mem_new();
+ filter = (CamelStream *)camel_stream_filter_new_with_stream((CamelStream *)in);
+ check_count(in, 2);
+ id = camel_stream_filter_add((CamelStreamFilter *)filter, f);
+ check_count(f, 2);
+
+ check(camel_stream_write_to_stream(indisk, filter) > 0);
+ check(camel_stream_flush(filter) == 0);
+ check_msg(in->buffer->len == out->buffer->len
+ && memcmp(in->buffer->data, out->buffer->data, in->buffer->len) == 0,
+ "Buffer content mismatch, %d != %d, in = '%.*s' != out = '%.*s'", in->buffer->len, out->buffer->len,
+ in->buffer->len, in->buffer->data, out->buffer->len, out->buffer->data);
+
+ camel_stream_filter_remove((CamelStreamFilter *)filter, id);
+ check_unref(filter, 1);
+ check_unref(in, 1);
+ check_unref(indisk, 1);
+ check_unref(outdisk, 1);
+ check_unref(out, 1);
+
+ camel_test_pull();
+
+ camel_test_pull();
+}
+
+int
+main (int argc, char **argv)
+{
+ int i;
+
+ camel_test_init(argc, argv);
+
+ camel_test_start("HTML Stream filtering");
+
+ for (i=0;i<100;i++) {
+ char inname[32], outname[32];
+ CamelMimeFilter *f;
+ struct stat st;
+
+ sprintf(inname, "data/html.%d.in", i);
+ sprintf(outname, "data/html.%d.out", i);
+
+ if (stat(inname, &st) == -1)
+ break;
+
+ f = camel_mime_filter_tohtml_new(CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
+
+ test_filter(f, inname, outname);
+
+ check_unref(f, 1);
+ }
+
+ camel_test_end();
+
+ return 0;
+}