diff options
author | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-09-26 07:25:05 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-09-26 07:25:05 +0800 |
commit | cf4ca10f51a0809ba81a86ce6916f6f32a5ee840 (patch) | |
tree | f3287a6788dec08c66bf6c7d4aed125e8d603975 /camel/tests/mime-filter/test-charset.c | |
parent | 20c4b44474062abd353bc10966b5f7f4026d1336 (diff) | |
download | gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.tar gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.tar.gz gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.tar.bz2 gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.tar.lz gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.tar.xz gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.tar.zst gsoc2013-evolution-cf4ca10f51a0809ba81a86ce6916f6f32a5ee840.zip |
Added a test suite for camel-mime-filter-charset and added a few test cases for it. input charset files should be in the form "charset-%s.%d.in" where %s is the charset name that the file is in and %d is just some number as in a sequence id. Mostly just so we can have multiple test files per charset
svn path=/trunk/; revision=18227
Diffstat (limited to 'camel/tests/mime-filter/test-charset.c')
-rw-r--r-- | camel/tests/mime-filter/test-charset.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/camel/tests/mime-filter/test-charset.c b/camel/tests/mime-filter/test-charset.c new file mode 100644 index 0000000000..301cf3b2b7 --- /dev/null +++ b/camel/tests/mime-filter/test-charset.c @@ -0,0 +1,140 @@ +/* + test-crlf.c + + Test the CamelMimeFilterCharset class +*/ + +#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-charset.h> + +#define d(x) x + +#define CHUNK_SIZE 4096 + +int +main (int argc, char **argv) +{ + ssize_t comp_progress, comp_correct_chunk, comp_filter_chunk; + char comp_correct[CHUNK_SIZE], comp_filter[CHUNK_SIZE]; + CamelStream *source; + CamelStream *correct; + CamelStreamFilter *filter; + CamelMimeFilter *f; + struct dirent *dent; + int i, test = 0; + DIR *dir; + + camel_test_init(argc, argv); + + dir = opendir (SOURCEDIR); + + while ((dent = readdir (dir))) { + char *outfile, *charset, *work; + const char *ext; + + ext = strrchr (dent->d_name, '.'); + if (!(!strncmp (dent->d_name, "charset-", 8) && ext && !strcmp (ext, ".in"))) + continue; + + work = g_strdup_printf ("Charset filter, test case %d (%s)", test++, dent->d_name); + camel_test_start (work); + g_free (work); + + if (!(source = camel_stream_fs_new_with_name (dent->d_name, 0, O_RDONLY))) { + camel_test_fail ("Failed to open input case in \"%s\"", dent->d_name); + continue; + } + + outfile = g_strdup_printf ("%.*s.out", ext - dent->d_name, dent->d_name); + + if (!(correct = camel_stream_fs_new_with_name (outfile, 0, O_RDONLY))) { + camel_test_fail ("Failed to open correct output in \"%s\"", outfile); + g_free (outfile); + continue; + } + g_free (outfile); + + if (!(filter = camel_stream_filter_new_with_stream (CAMEL_STREAM (source)))) { + camel_test_fail ("Couldn't create CamelStreamFilter??"); + continue; + } + + charset = g_strdup (dent->d_name + 8); + ext = strchr (charset, '.'); + *((char *) ext) = '\0'; + + if (!(f = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "UTF-8"))) { + camel_test_fail ("Couldn't create CamelMimeFilterCharset??"); + g_free (charset); + continue; + } + g_free (charset); + + camel_stream_filter_add (filter, f); + camel_object_unref (f); + + 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; + } + + for (i = 0; i < comp_filter_chunk; i++) { + if (comp_correct[i] != comp_filter[i]) { + camel_test_fail ("Difference: correct is %c, filter is %c, " + "%d bytes into stream", + comp_correct[i], + comp_filter[i], + comp_progress + 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_test_pull (); + + camel_test_end (); + } + + closedir (dir); + + return 0; +} |