aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-06-30 02:09:45 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-06-30 02:09:45 +0800
commitf57c6219924045efc8a6f9f3107d5369a2de7a66 (patch)
tree3ed1f2745374f782df216388c9b0227eeada8b70
parentf3ad1a30ae1dc55633b92e8175ea73492cdf2f37 (diff)
downloadgsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.tar
gsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.tar.gz
gsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.tar.bz2
gsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.tar.lz
gsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.tar.xz
gsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.tar.zst
gsoc2013-evolution-f57c6219924045efc8a6f9f3107d5369a2de7a66.zip
Build the test-crlf test program.
2001-06-29 Jeffrey Stedfast <fejj@ximian.com> * 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
-rw-r--r--camel/ChangeLog14
-rw-r--r--camel/camel-mime-filter-crlf.c56
-rw-r--r--camel/camel-mime-filter-crlf.h1
-rw-r--r--camel/tests/mime-filter/.cvsignore3
-rw-r--r--camel/tests/mime-filter/Makefile.am5
-rw-r--r--camel/tests/mime-filter/crlf-1.in19
-rw-r--r--camel/tests/mime-filter/crlf-1.out19
-rw-r--r--camel/tests/mime-filter/test-crlf.c163
8 files changed, 255 insertions, 25 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index a5b8f189cf..61a7327904 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,13 @@
+2001-06-29 Jeffrey Stedfast <fejj@ximian.com>
+
+ * 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.
+
2001-06-28 Peter Williams <peterw@ximian.com>
* camel-mime-filter-stripheader.c: New file. Filter that strips a
@@ -5,8 +15,8 @@
* camel-mime-filter-stripheader.h: New file. Header for the above.
- * providers/smtp/camel-smtp-transport.c (smtp_data): Use the stripheader
- filter to remove the "Bcc" header.
+ * providers/smtp/camel-smtp-transport.c (smtp_data): Use the
+ stripheader filter to remove the "Bcc" header.
* Makefile.am: Add the stripheader files.
diff --git a/camel/camel-mime-filter-crlf.c b/camel/camel-mime-filter-crlf.c
index 58623f2ac7..6977b04878 100644
--- a/camel/camel-mime-filter-crlf.c
+++ b/camel/camel-mime-filter-crlf.c
@@ -66,25 +66,30 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace,
CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f;
gboolean do_dots;
char *p, *q;
-
+
do_dots = crlf->mode == CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS;
-
+
if (crlf->direction == CAMEL_MIME_FILTER_CRLF_ENCODE) {
camel_mime_filter_set_size (f, 3 * len, FALSE);
-
+
p = in;
q = f->outbuf;
while (p < in + len) {
- if (*p == '\n')
+ if (*p == '\n') {
+ crlf->saw_lf = TRUE;
*q++ = '\r';
- else
- if (do_dots && *p == '.' && (p == in || *(p - 1) == '\n'))
+ } else {
+ if (do_dots && *p == '.' && crlf->saw_lf)
*q++ = '.';
+
+ crlf->saw_lf = FALSE;
+ }
+
*q++ = *p++;
}
} else {
camel_mime_filter_set_size (f, len, FALSE);
-
+
p = in;
q = f->outbuf;
while (p < in + len) {
@@ -92,30 +97,35 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace,
crlf->saw_cr = TRUE;
} else {
if (crlf->saw_cr) {
- if (*p != '\n')
- *q++ = '\r';
crlf->saw_cr = FALSE;
+
+ if (*p == '\n') {
+ crlf->saw_lf = TRUE;
+ *q++ = *p++;
+ continue;
+ } else
+ *q++ = '\r';
}
+
*q++ = *p;
}
-
- if (do_dots) {
- if (*p == '.' && (p == in || *(p - 1) == '\n')) {
+
+ if (do_dots && *p == '.') {
+ if (crlf->saw_lf) {
crlf->saw_dot = TRUE;
- } else {
- if (crlf->saw_dot) {
- if (*p == '.')
- p++;
- crlf->saw_dot = FALSE;
- }
- *q++ = *p;
+ crlf->saw_lf = FALSE;
+ p++;
+ } else if (crlf->saw_dot) {
+ crlf->saw_dot = FALSE;
}
}
-
+
+ crlf->saw_lf = FALSE;
+
p++;
}
}
-
+
*out = f->outbuf;
*outlen = q - f->outbuf;
*outprespace = f->outpre;
@@ -135,6 +145,8 @@ reset (CamelMimeFilter *f)
CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f;
crlf->saw_cr = FALSE;
+ crlf->saw_lf = TRUE;
+ crlf->saw_dot = FALSE;
}
CamelMimeFilter *
@@ -145,6 +157,8 @@ camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction, CamelMimeFil
crlf->direction = direction;
crlf->mode = mode;
crlf->saw_cr = FALSE;
+ crlf->saw_lf = TRUE;
+ crlf->saw_dot = FALSE;
return (CamelMimeFilter *)crlf;
}
diff --git a/camel/camel-mime-filter-crlf.h b/camel/camel-mime-filter-crlf.h
index df5c58b0a5..7b19f914bc 100644
--- a/camel/camel-mime-filter-crlf.h
+++ b/camel/camel-mime-filter-crlf.h
@@ -48,6 +48,7 @@ struct _CamelMimeFilterCRLF {
CamelMimeFilterCRLFDirection direction;
CamelMimeFilterCRLFMode mode;
gboolean saw_cr;
+ gboolean saw_lf;
gboolean saw_dot;
};
diff --git a/camel/tests/mime-filter/.cvsignore b/camel/tests/mime-filter/.cvsignore
index 2cee3ea3cb..c1f16ee7d4 100644
--- a/camel/tests/mime-filter/.cvsignore
+++ b/camel/tests/mime-filter/.cvsignore
@@ -4,4 +4,5 @@ Makefile.in
.libs
*.lo
*.la
-test-stripheader \ No newline at end of file
+test-stripheader
+test-crlf
diff --git a/camel/tests/mime-filter/Makefile.am b/camel/tests/mime-filter/Makefile.am
index a1a3ebb832..02faad7eb5 100644
--- a/camel/tests/mime-filter/Makefile.am
+++ b/camel/tests/mime-filter/Makefile.am
@@ -14,6 +14,8 @@ LDADD = \
$(GNOMEUI_LIBS) $(INTLLIBS) $(EXTRA_GNOME_LIBS)
EXTRA_DIST = \
+ crlf-1.in \
+ crlf-1.out \
stripheader-1.in \
stripheader-1.out \
stripheader-2.in \
@@ -28,9 +30,10 @@ EXTRA_DIST = \
stripheader-6.out
check_PROGRAMS = \
+ test-crlf \
test-stripheader
-TESTS = test-stripheader
+TESTS = test-crlf test-stripheader
diff --git a/camel/tests/mime-filter/crlf-1.in b/camel/tests/mime-filter/crlf-1.in
new file mode 100644
index 0000000000..d98703c725
--- /dev/null
+++ b/camel/tests/mime-filter/crlf-1.in
@@ -0,0 +1,19 @@
+This is some text to filter and stuff. Hopefully that . will not become '..'
+when the filter is run on this text. It should, however, '..' the next line
+. The previous . should become .. in the output file, or so I hope...
+
+.
+..
+...
+....
+
+Once this text is decoded again, the above set of dots should look like:
+
+ .
+ ..
+ ...
+ ....
+
+Only it shouldn't be indented, obviously.
+
+Jeff \ No newline at end of file
diff --git a/camel/tests/mime-filter/crlf-1.out b/camel/tests/mime-filter/crlf-1.out
new file mode 100644
index 0000000000..c0b688f334
--- /dev/null
+++ b/camel/tests/mime-filter/crlf-1.out
@@ -0,0 +1,19 @@
+This is some text to filter and stuff. Hopefully that . will not become '..'
+when the filter is run on this text. It should, however, '..' the next line
+.. The previous . should become .. in the output file, or so I hope...
+
+..
+...
+....
+.....
+
+Once this text is decoded again, the above set of dots should look like:
+
+ .
+ ..
+ ...
+ ....
+
+Only it shouldn't be indented, obviously.
+
+Jeff \ No newline at end of file
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 <stdio.h>
+#include <string.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-crlf.h>
+
+#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;
+}