
2000-11-29 Not Zed <NotZed@HelixCode.com> * tests/message/test2.c (main): Add a missed unref. * camel-stream-mem.c (camel_stream_mem_set_buffer): We must set ourselves as the owner of the byte-array. Weird, someone has modified this file (its been reindented), but i can't see any changelogs ... * tests/lib/messages.c (content_finalise): Fix memleak in tester, free byte array when our content object is deleted. * camel-folder-search.c (camel_folder_search_finalize): Yeah great, so the sexp is a gtk object, not a camel object. Isn't that going to be fun to fix? * camel-session.c (camel_session_finalise): Free the storage path. * providers/local/camel-local-store.c (camel_local_store_init): If store->folders is setup, free it first, then overwrite. Hmm, this seems a bit crappy to me. * camel-store.c (camel_store_init): Dont setup store->folders if its already setup. * camel-exception.c (camel_exception_setv): Removed a memleak. no need to strdup after a strdup_printf!!! * camel-address.c (camel_address_finalize): Free the address ptrarray, once finished. * providers/local/camel-local-folder.c (local_finalize): Make sure we dont leave the folder locked on close. (local_finalize): Free summary/search. * providers/local/camel-mh-summary.c (mh_summary_next_uid_string): Small memleak, always free name after using it. * camel-mime-part.c (set_content_object): Free txt after setting the header. * providers/local/camel-maildir-summary.c (maildir_summary_check): Fix a memleak, close the dir after scanning new. (message_info_free): Added so we can free the filename cached in the messageinfo. (camel_maildir_summary_finalise): Free the hostname. * tests/folder/test[12].c (main): Clear out camel-test before starting. * providers/local/camel-mbox-summary.c (mbox_summary_sync_quick): Because encode_x_evolution folds the line (sigh, because encode_param does, unlike every other function in camel-mime-utils), unfold the encoded result before comparing. (mbox_summary_sync_quick): Another small memleak, free xevnew once finished with it. * camel-mime-utils.c (header_decode_quoted_string): Removed a redundant check for c=0. (header_unfold): New function to un-fold headers. * providers/local/camel-local-summary.c (local_summary_encode_x_evolution): some problems with encoding tags, using the wrong output strings. (local_summary_encode_x_evolution): We dont need to append a ; either, param_list_format_append() will do it for us. ` svn path=/trunk/; revision=6711
201 lines
4.2 KiB
C
201 lines
4.2 KiB
C
/*
|
|
test1.c
|
|
|
|
Create a message, save it.
|
|
|
|
Retrieve message, compare content.
|
|
|
|
|
|
Operations:
|
|
writing/loading from different types of streams
|
|
reading/writing different content
|
|
reading/writing different encodings
|
|
reading/writing different charsets
|
|
|
|
Just testing streams:
|
|
different stream types
|
|
different file ops
|
|
seek, eof, etc.
|
|
*/
|
|
|
|
#include "camel-test.h"
|
|
#include "messages.h"
|
|
|
|
/* for stat */
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
#include <camel/camel-mime-message.h>
|
|
#include <camel/camel-stream-fs.h>
|
|
#include <camel/camel-stream-mem.h>
|
|
|
|
struct _text {
|
|
char *text;
|
|
int len;
|
|
};
|
|
|
|
#define MAX_TEXTS (14)
|
|
struct _text texts[MAX_TEXTS];
|
|
|
|
static void
|
|
setup(void)
|
|
{
|
|
int i, j;
|
|
char *p;
|
|
|
|
/* setup various edge and other general cases */
|
|
texts[0].text = "";
|
|
texts[0].len = 0;
|
|
texts[1].text = "";
|
|
texts[1].len = 1;
|
|
texts[2].text = "\n";
|
|
texts[2].len = 1;
|
|
texts[3].text = "A";
|
|
texts[3].len = 1;
|
|
texts[4].text = "This is a test.\n.";
|
|
texts[4].len = strlen(texts[4].text);
|
|
texts[5].text = "This is a test.\n\n.\n";
|
|
texts[5].len = strlen(texts[5].text);
|
|
texts[6].text = g_malloc0(1024);
|
|
texts[6].len = 1024;
|
|
texts[7].text = g_malloc0(102400);
|
|
texts[7].len = 102400;
|
|
texts[8].text = g_malloc(1024);
|
|
memset(texts[8].text, '\n', 1024);
|
|
texts[8].len = 1024;
|
|
texts[9].text = g_malloc(102400);
|
|
memset(texts[9].text, '\n', 102400);
|
|
texts[9].len = 102400;
|
|
texts[10].text = g_malloc(1024);
|
|
memset(texts[10].text, ' ', 1024);
|
|
texts[10].len = 1024;
|
|
texts[11].text = g_malloc(102400);
|
|
memset(texts[11].text, ' ', 102400);
|
|
texts[11].len = 102400;
|
|
|
|
srand(42);
|
|
p = texts[12].text = g_malloc(1024);
|
|
for (i=0;i<1024;i++) {
|
|
j = rand();
|
|
if (j<RAND_MAX/120)
|
|
*p++ = '\n';
|
|
else
|
|
*p++ = (j % 95) + 32;
|
|
}
|
|
texts[12].len = 1024;
|
|
p = texts[13].text = g_malloc(102400);
|
|
for (i=0;i<102400;i++) {
|
|
j = rand();
|
|
if (j<RAND_MAX/120)
|
|
*p++ = '\n';
|
|
else
|
|
*p++ = (j % 95) + 32;
|
|
}
|
|
texts[13].len = 102400;
|
|
}
|
|
|
|
static void cleanup(void)
|
|
{
|
|
int i;
|
|
|
|
for (i=6;i<14;i++) {
|
|
g_free(texts[i].text);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
CamelMimeMessage *msg, *msg2;
|
|
int i, j;
|
|
char *text;
|
|
int len;
|
|
|
|
camel_test_init(argc, argv);
|
|
|
|
setup();
|
|
|
|
camel_test_start("Simple memory-based content creation");
|
|
|
|
/* test all ways of setting simple content for a message (i.e. memory based) */
|
|
for (j=0;j<MAX_TEXTS;j++) {
|
|
push("testing text number %d", j);
|
|
text = texts[j].text;
|
|
len = texts[j].len;
|
|
for (i=0;i<SET_CONTENT_WAYS;i++) {
|
|
push("create simple message %d", i);
|
|
msg = test_message_create_simple();
|
|
|
|
push("set simple content");
|
|
test_message_set_content_simple((CamelMimePart *)msg, i, "text/plain", text, len);
|
|
pull();
|
|
|
|
push("compare original content");
|
|
test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg), text, len);
|
|
pull();
|
|
|
|
push("save message to test1.msg");
|
|
unlink("test1.msg");
|
|
test_message_write_file(msg, "test1.msg");
|
|
check_unref(msg, 1);
|
|
pull();
|
|
|
|
push("read from test1.msg");
|
|
msg2 = test_message_read_file("test1.msg");
|
|
pull();
|
|
|
|
push("compare read with original content");
|
|
test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg2), text, len);
|
|
check_unref(msg2, 1);
|
|
pull();
|
|
|
|
unlink("test1.msg");
|
|
pull();
|
|
}
|
|
pull();
|
|
}
|
|
|
|
camel_test_end();
|
|
|
|
camel_test_start("Different encodings");
|
|
for (j=0;j<MAX_TEXTS;j++) {
|
|
push("testing text number %d", j);
|
|
text = texts[j].text;
|
|
len = texts[j].len;
|
|
for (i=0;i<CAMEL_MIME_PART_NUM_ENCODINGS;i++) {
|
|
|
|
push("test simple message, encoding %s", camel_mime_part_encoding_to_string(i));
|
|
msg = test_message_create_simple();
|
|
|
|
push("set simple content");
|
|
test_message_set_content_simple((CamelMimePart *)msg, 0, "text/plain", text, len);
|
|
pull();
|
|
|
|
camel_mime_part_set_encoding((CamelMimePart *)msg, i);
|
|
|
|
push("save message to test1.msg");
|
|
unlink("test1.msg");
|
|
test_message_write_file(msg, "test1.msg");
|
|
check_unref(msg, 1);
|
|
pull();
|
|
|
|
push("read from test1.msg");
|
|
msg2 = test_message_read_file("test1.msg");
|
|
pull();
|
|
|
|
push("compare read with original content");
|
|
test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg2), text, len);
|
|
check_unref(msg2, 1);
|
|
pull();
|
|
|
|
unlink("test1.msg");
|
|
pull();
|
|
}
|
|
pull();
|
|
}
|
|
camel_test_end();
|
|
|
|
cleanup();
|
|
|
|
return 0;
|
|
}
|