aboutsummaryrefslogtreecommitdiffstats
path: root/camel/tests
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-08-12 01:57:45 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-08-12 01:57:45 +0800
commitb328a21e7c026aaa9cdd5e332ed7e39e0003d8eb (patch)
tree2c0f3caac1a793197a951958fa7f07cdbf61ac07 /camel/tests
parent7b1013be730b11384d0e0af340758bdef3f00330 (diff)
downloadgsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.gz
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.bz2
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.lz
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.xz
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.tar.zst
gsoc2013-evolution-b328a21e7c026aaa9cdd5e332ed7e39e0003d8eb.zip
New test suite for the mime parser (which is where the below 2 fixes were
* tests/message/test4.c: New test suite for the mime parser (which is where the below 2 fixes were noticed). * camel-mime-parser.c (folder_boundary_check): Calculate 'len' by subtracting the boundary start from inend rather than 'atleast'. (folder_scan_content): Calculate 'inend' differently depending on the EOF state. 2003-08-08 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-filter-tohtml.c (html_convert): Rather than checking *inptr == '\n', check inptr >= inend - this gets rid of an Invalid Read report from valgrind. * camel-mime-part.c (write_to_stream): Don't necessarily re-encode just because the encodings differ. Need to look into making it so that message/rfc822 and multipart parts ignore the Content-Transfer-Encoding header and just keep their 'encoding' bits set to DEFAULT. 2003-08-05 Jeffrey Stedfast <fejj@ximian.com> * providers/imap/camel-imap-folder.c (get_content): Updated. * camel-mime-message.c (camel_mime_message_init): Don't override the mime_type here. (process_header): Updated to use CamelDataWrapper's mime_type field. (find_best_encoding): Same. (best_encoding): Here too. * camel-digest-folder.c (camel_digest_folder_new): Updated for CamelMimePart::content_type change. * camel-mime-part.c (camel_mime_part_init): Override our parent class's default mime_type. (camel_mime_part_finalize): Don't need to unref the content_type anymore. (process_header): Updated to use CamelDataWrapper's mime_type field. (camel_mime_part_set_filename): Same. (camel_mime_part_get_filename): Same. (camel_mime_part_get_content_type): Same. (set_content_object): Here too. (write_to_stream): Updated. (construct_from_parser): Updated. * camel-mime-part.h: Remove the content_type field. 2003-07-31 Jeffrey Stedfast <fejj@ximian.com> * tests/lib/messages.c (test_message_compare_content): If the chunks differ, perform a hexdump on the data being compared so that we may analyse it easier. * camel-multipart-signed.c (write_to_stream): Return ssize_t. * camel-mime-utils.h: Added the CamelMimePartEncodingType enum here. * camel-mime-part.h: Removed the CamelMimePartEncodingType enum from here. * camel-mime-part.c (write_to_stream): Updated to return ssize_t. Also minor changes to only re-encode the content stream if the charset or encoding changed (this way we write it out in the original raw form if nothing changed). * camel-mime-part-utils.c (simple_data_wrapper_construct_from_parser): Drastically simplify. We no longer scan html content to try and find the charset, nor do we care about converting the content to UTF-8 and handling broken windows charsets. * camel-mime-message.c (find_best_encoding): Use decode_to_stream() here. Also updated to not assume the content charset is UTF-8 since it is very likely not the case anymore since data-wrappers no longer are converted to UTF-8 at parse time. * camel-folder-summary.c (summary_build_content_info_message): Use decode_to_stream instead here too. * camel-folder-search.c (match_words_1message): Use decode_to_stream instead of write_to_stream so we can search the contents. * camel-data-wrapper.c (camel_data_wrapper_init): Set the default encoding to DEFAULT. (write_to_stream): Updated to return ssize_t (camel_data_wrapper_decode_to_stream): New virtual function to decode a data wrapper to a stream (results in nearly identical behaviour to the old write_to_stream method). (decode_to_stream): Default implementation of above virtual method. Decodes base64/qp/etc streams. * camel-data-wrapper.h: Removed the rawtext bit and added an encoding member. svn path=/trunk/; revision=22171
Diffstat (limited to 'camel/tests')
-rw-r--r--camel/tests/lib/messages.c86
-rw-r--r--camel/tests/lib/messages.h1
-rw-r--r--camel/tests/message/Makefile.am5
-rw-r--r--camel/tests/message/test4.c126
4 files changed, 214 insertions, 4 deletions
diff --git a/camel/tests/lib/messages.c b/camel/tests/lib/messages.c
index 21d77582ad..3cf1b5fd51 100644
--- a/camel/tests/lib/messages.c
+++ b/camel/tests/lib/messages.c
@@ -1,8 +1,11 @@
+#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include "messages.h"
#include "camel-test.h"
+#include <camel/camel-multipart.h>
#include <camel/camel-mime-message.h>
#include <camel/camel-stream-fs.h>
#include <camel/camel-stream-mem.h>
@@ -120,6 +123,36 @@ test_message_read_file(const char *name)
return msg2;
}
+static void
+hexdump (const unsigned char *in, int inlen)
+{
+ const unsigned char *inptr = in, *start = inptr;
+ const unsigned char *inend = in + inlen;
+ int octets;
+
+ while (inptr < inend) {
+ octets = 0;
+ while (inptr < inend && octets < 16) {
+ printf ("%.2X ", *inptr++);
+ octets++;
+ }
+
+ while (octets < 16) {
+ printf (" ");
+ octets++;
+ }
+
+ printf (" ");
+
+ while (start < inptr) {
+ fputc (isprint ((int) *start) ? *start : '.', stdout);
+ start++;
+ }
+
+ fputc ('\n', stdout);
+ }
+}
+
int
test_message_compare_content(CamelDataWrapper *dw, const char *text, int len)
{
@@ -131,8 +164,16 @@ test_message_compare_content(CamelDataWrapper *dw, const char *text, int len)
return 0;
content = (CamelStreamMem *)camel_stream_mem_new();
- camel_data_wrapper_write_to_stream(dw, (CamelStream *)content);
-
+ camel_data_wrapper_decode_to_stream(dw, (CamelStream *)content);
+
+ if (content->buffer->len != len) {
+ printf ("original text:\n");
+ hexdump (text, len);
+
+ printf ("new text:\n");
+ hexdump (content->buffer->data, content->buffer->len);
+ }
+
check_msg(content->buffer->len == len, "buffer->len = %d, len = %d", content->buffer->len, len);
check_msg(memcmp(content->buffer->data, text, content->buffer->len) == 0, "len = %d", len);
@@ -142,6 +183,47 @@ test_message_compare_content(CamelDataWrapper *dw, const char *text, int len)
}
int
+test_message_compare (CamelMimeMessage *msg)
+{
+ CamelMimeMessage *msg2;
+ CamelStreamMem *mem1, *mem2;
+
+ mem1 = (CamelStreamMem *) camel_stream_mem_new ();
+ camel_data_wrapper_write_to_stream ((CamelDataWrapper *) msg, (CamelStream *) mem1);
+ camel_stream_reset ((CamelStream *) mem1);
+
+ msg2 = camel_mime_message_new ();
+ camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) msg2, (CamelStream *) mem1);
+ camel_stream_reset ((CamelStream *) mem1);
+
+ mem2 = (CamelStreamMem *) camel_stream_mem_new ();
+ camel_data_wrapper_write_to_stream ((CamelDataWrapper *) msg2, (CamelStream *) mem2);
+ camel_stream_reset ((CamelStream *) mem2);
+
+ camel_object_unref (msg2);
+
+ if (mem1->buffer->len != mem2->buffer->len) {
+ CamelDataWrapper *content;
+
+ printf ("mem1 stream:\n%.*s\n", mem1->buffer->len, mem1->buffer->data);
+ printf ("mem2 stream:\n%.*s\n\n", mem2->buffer->len, mem2->buffer->data);
+
+ content = camel_medium_get_content_object ((CamelMedium *) msg);
+ }
+
+ check_msg (mem1->buffer->len == mem2->buffer->len,
+ "mem1->buffer->len = %d, mem2->buffer->len = %d",
+ mem1->buffer->len, mem2->buffer->len);
+
+ check_msg (memcmp (mem1->buffer->data, mem2->buffer->data, mem1->buffer->len) == 0, "msg/stream compare");
+
+ camel_object_unref (mem1);
+ camel_object_unref (mem2);
+
+ return 0;
+}
+
+int
test_message_compare_header(CamelMimeMessage *m1, CamelMimeMessage *m2)
{
return 0;
diff --git a/camel/tests/lib/messages.h b/camel/tests/lib/messages.h
index 9cb5758826..cdac98f30a 100644
--- a/camel/tests/lib/messages.h
+++ b/camel/tests/lib/messages.h
@@ -10,3 +10,4 @@ void test_message_set_content_simple(CamelMimePart *part, int how, const char *t
int test_message_write_file(CamelMimeMessage *msg, const char *name);
CamelMimeMessage *test_message_read_file(const char *name);
int test_message_compare_content(CamelDataWrapper *dw, const char *text, int len);
+int test_message_compare (CamelMimeMessage *msg);
diff --git a/camel/tests/message/Makefile.am b/camel/tests/message/Makefile.am
index 47f0024901..32b4294aa2 100644
--- a/camel/tests/message/Makefile.am
+++ b/camel/tests/message/Makefile.am
@@ -19,6 +19,7 @@ LDADD = \
check_PROGRAMS = \
test1 \
test2 \
- test3
+ test3 \
+ test4
-TESTS = test1 test2 test3
+TESTS = test1 test2 test3 test4
diff --git a/camel/tests/message/test4.c b/camel/tests/message/test4.c
new file mode 100644
index 0000000000..bc728a928f
--- /dev/null
+++ b/camel/tests/message/test4.c
@@ -0,0 +1,126 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@ximian.com>
+ *
+ * Copyright 2003 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#include "camel-test.h"
+#include "messages.h"
+
+#include <camel/camel-multipart.h>
+#include <camel/camel-mime-message.h>
+#include <camel/camel-stream-fs.h>
+#include <camel/camel-stream-mem.h>
+
+
+#if 0
+static void
+dump_mime_struct (CamelMimePart *mime_part, int depth)
+{
+ CamelDataWrapper *content;
+ char *mime_type;
+ int i = 0;
+
+ while (i < depth) {
+ printf (" ");
+ i++;
+ }
+
+ content = camel_medium_get_content_object ((CamelMedium *) mime_part);
+
+ mime_type = camel_data_wrapper_get_mime_type (content);
+ printf ("Content-Type: %s\n", mime_type);
+ g_free (mime_type);
+
+ if (CAMEL_IS_MULTIPART (content)) {
+ guint num, index = 0;
+
+ num = camel_multipart_get_number ((CamelMultipart *) content);
+ while (index < num) {
+ mime_part = camel_multipart_get_part ((CamelMultipart *) content, index);
+ dump_mime_struct (mime_part, depth + 1);
+ index++;
+ }
+ } else if (CAMEL_IS_MIME_MESSAGE (content)) {
+ dump_mime_struct ((CamelMimePart *) content, depth + 1);
+ }
+}
+#endif
+
+int main (int argc, char **argv)
+{
+ struct dirent *dent;
+ DIR *dir;
+ int fd;
+
+ camel_test_init (argc, argv);
+
+ camel_test_start ("Message Test Suite");
+
+ if (!(dir = opendir ("../data/messages")))
+ return 77;
+
+ while ((dent = readdir (dir)) != NULL) {
+ CamelMimeMessage *message;
+ CamelStream *stream;
+ char *filename;
+ struct stat st;
+
+ filename = g_strdup_printf ("../data/messages/%s", dent->d_name);
+ if (stat (filename, &st) == -1 || !S_ISREG (st.st_mode)) {
+ g_free (filename);
+ continue;
+ }
+
+ if ((fd = open (filename, O_RDONLY)) == -1) {
+ g_free (filename);
+ continue;
+ }
+
+ push ("testing message `%s`", filename);
+ g_free (filename);
+
+ stream = camel_stream_fs_new_with_fd (fd);
+ message = camel_mime_message_new ();
+ camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream);
+ camel_stream_reset (stream);
+
+ /*dump_mime_struct ((CamelMimePart *) message, 0);*/
+ test_message_compare (message);
+
+ camel_object_unref (message);
+ camel_object_unref (stream);
+
+ pull ();
+ }
+
+ closedir (dir);
+
+ camel_test_end ();
+
+ return 0;
+}