From f57c6219924045efc8a6f9f3107d5369a2de7a66 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 29 Jun 2001 18:09:45 +0000 Subject: Build the test-crlf test program. 2001-06-29 Jeffrey Stedfast * tests/mime-filter/Makefile.am: Build the test-crlf test program. * tests/mime-filter/test-crlf.c: New test suite for the crlf filter. * camel-mime-filter-crlf.c (filter): Fixed to correctly encode and decode dots. svn path=/trunk/; revision=10602 --- camel/tests/mime-filter/test-crlf.c | 163 ++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 camel/tests/mime-filter/test-crlf.c (limited to 'camel/tests/mime-filter/test-crlf.c') diff --git a/camel/tests/mime-filter/test-crlf.c b/camel/tests/mime-filter/test-crlf.c new file mode 100644 index 0000000000..2e8a4333fa --- /dev/null +++ b/camel/tests/mime-filter/test-crlf.c @@ -0,0 +1,163 @@ +/* + test-crlf.c + + Test the CamelMimeFilterCrlf class +*/ + +#include +#include + +#include "camel-test.h" + +#include +#include +#include +#include + +#define d(x) x + +#define NUM_CASES 1 +#define CHUNK_SIZE 32 + +enum { + CRLF_ENCODE, + CRLF_DECODE, + CRLF_DONE +}; + +int +main (int argc, char **argv) +{ + CamelStream *source; + CamelStream *correct; + CamelStreamFilter *filter; + CamelMimeFilter *sh; + gchar *work; + int i; + ssize_t comp_progress, comp_correct_chunk, comp_filter_chunk; + int comp_i; + char comp_correct[CHUNK_SIZE], comp_filter[CHUNK_SIZE]; + + camel_test_init(argc, argv); + + for (i = 0; i < NUM_CASES; i++) { + int j; + + work = g_strdup_printf ("CRLF/DOT filter, test case %d", i); + camel_test_start (work); + g_free (work); + + for (j = CRLF_ENCODE; j < CRLF_DONE; j++) { + CamelMimeFilterCRLFDirection direction; + char *infile, *outfile; + + switch (j) { + case CRLF_ENCODE: + camel_test_push ("Test of the encoder"); + direction = CAMEL_MIME_FILTER_CRLF_ENCODE; + infile = g_strdup_printf ("%s/crlf-%d.in", SOURCEDIR, i + 1); + outfile = g_strdup_printf ("%s/crlf-%d.out", SOURCEDIR, i + 1); + break; + case CRLF_DECODE: + camel_test_push ("Test of the decoder"); + direction = CAMEL_MIME_FILTER_CRLF_DECODE; + infile = g_strdup_printf ("%s/crlf-%d.out", SOURCEDIR, i + 1); + outfile = g_strdup_printf ("%s/crlf-%d.in", SOURCEDIR, i + 1); + break; + default: + break; + } + + camel_test_push ("Initializing objects"); + source = camel_stream_fs_new_with_name (infile, 0, O_RDONLY); + if (!source) { + camel_test_fail ("Failed to open input case in \"%s\"", infile); + g_free (infile); + continue; + } + g_free (infile); + + correct = camel_stream_fs_new_with_name (outfile, 0, O_RDONLY); + if (!correct) { + camel_test_fail ("Failed to open correct output in \"%s\"", outfile); + g_free (outfile); + continue; + } + g_free (outfile); + + filter = camel_stream_filter_new_with_stream (CAMEL_STREAM (source)); + if (!filter) { + camel_test_fail ("Couldn't create CamelStreamFilter??"); + continue; + } + + sh = camel_mime_filter_crlf_new (direction, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS); + if (!sh) { + camel_test_fail ("Couldn't create CamelMimeFilterCrlf??"); + continue; + } + + camel_stream_filter_add (filter, sh); + camel_test_pull (); + + camel_test_push ("Running filter and comparing to correct result"); + + comp_progress = 0; + + while (1) { + comp_correct_chunk = camel_stream_read (correct, comp_correct, CHUNK_SIZE); + comp_filter_chunk = 0; + + if (comp_correct_chunk == 0) + break; + + while (comp_filter_chunk < comp_correct_chunk) { + ssize_t delta; + + delta = camel_stream_read (CAMEL_STREAM (filter), + comp_filter + comp_filter_chunk, + CHUNK_SIZE - comp_filter_chunk); + + if (delta == 0) { + camel_test_fail ("Chunks are different sizes: correct is %d, " + "filter is %d, %d bytes into stream", + comp_correct_chunk, comp_filter_chunk, comp_progress); + } + + comp_filter_chunk += delta; + } + + d(printf ("\n\nCORRECT: >>%.*s<<", comp_correct_chunk, comp_correct)); + d(printf ("\nFILTER : >>%.*s<<\n", comp_filter_chunk, comp_filter)); + + for (comp_i = 0; comp_i < comp_filter_chunk; comp_i++) { + if (comp_correct[comp_i] != comp_filter[comp_i]) { + camel_test_fail ("Difference: correct is %c, filter is %c, " + "%d bytes into stream", + comp_correct[comp_i], + comp_filter[comp_i], + comp_progress + comp_i); + } + } + + comp_progress += comp_filter_chunk; + } + + camel_test_pull (); + + /* inefficient */ + camel_test_push ("Cleaning up"); + camel_object_unref (CAMEL_OBJECT (filter)); + camel_object_unref (CAMEL_OBJECT (correct)); + camel_object_unref (CAMEL_OBJECT (source)); + camel_object_unref (CAMEL_OBJECT (sh)); + camel_test_pull (); + + camel_test_pull (); + } + + camel_test_end (); + } + + return 0; +} -- cgit v1.2.3