From 2e7d1434aedfbb634ede57faf6741dae5419d520 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 10 Apr 2003 11:35:00 +0000 Subject: filter data test cases. 2003-04-10 Not Zed * 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 --- camel/tests/mime-filter/Makefile.am | 5 +- camel/tests/mime-filter/data/html.0.in | 10 +++ camel/tests/mime-filter/data/html.0.out | 10 +++ camel/tests/mime-filter/data/html.1.in | 10 +++ camel/tests/mime-filter/data/html.1.out | 10 +++ camel/tests/mime-filter/test-tohtml.c | 132 ++++++++++++++++++++++++++++++++ 6 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 camel/tests/mime-filter/data/html.0.in create mode 100644 camel/tests/mime-filter/data/html.0.out create mode 100644 camel/tests/mime-filter/data/html.1.in create mode 100644 camel/tests/mime-filter/data/html.1.out create mode 100644 camel/tests/mime-filter/test-tohtml.c (limited to 'camel/tests/mime-filter') 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: + + + 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: + + <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.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: + + + \ 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: + + <http://www.ce.udel.edu/teaching_award.html> + <http://www.ce.udel.edu/nomination_form.html> 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 +#include + +#include +#include +#include +#include + +#include "camel-test.h" + +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3