diff options
author | Not Zed <NotZed@HelixCode.com> | 2000-11-29 18:49:05 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-11-29 18:49:05 +0800 |
commit | d38a417de3a1872b7776f12eeaf7e0bdbab880cc (patch) | |
tree | ab668964af7e0d9bedd12aac4fea83013123afc7 /camel | |
parent | fe151f15997c2130bf5f71c752a960de05a1bf6b (diff) | |
download | gsoc2013-evolution-d38a417de3a1872b7776f12eeaf7e0bdbab880cc.tar.gz gsoc2013-evolution-d38a417de3a1872b7776f12eeaf7e0bdbab880cc.tar.zst gsoc2013-evolution-d38a417de3a1872b7776f12eeaf7e0bdbab880cc.zip |
Add a missed unref.
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
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 67 | ||||
-rw-r--r-- | camel/camel-address.c | 1 | ||||
-rw-r--r-- | camel/camel-exception.c | 17 | ||||
-rw-r--r-- | camel/camel-folder-search.c | 3 | ||||
-rw-r--r-- | camel/camel-lock.c | 2 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 4 | ||||
-rw-r--r-- | camel/camel-mime-utils.c | 31 | ||||
-rw-r--r-- | camel/camel-mime-utils.h | 1 | ||||
-rw-r--r-- | camel/camel-session.c | 1 | ||||
-rw-r--r-- | camel/camel-store.c | 3 | ||||
-rw-r--r-- | camel/camel-stream-mem.c | 6 | ||||
-rw-r--r-- | camel/providers/local/camel-local-folder.c | 13 | ||||
-rw-r--r-- | camel/providers/local/camel-local-store.c | 3 | ||||
-rw-r--r-- | camel/providers/local/camel-local-summary.c | 5 | ||||
-rw-r--r-- | camel/providers/local/camel-maildir-summary.c | 14 | ||||
-rw-r--r-- | camel/providers/local/camel-mbox-summary.c | 15 | ||||
-rw-r--r-- | camel/providers/local/camel-mh-summary.c | 4 | ||||
-rw-r--r-- | camel/tests/folder/Makefile.am | 6 | ||||
-rw-r--r-- | camel/tests/folder/test1.c | 5 | ||||
-rw-r--r-- | camel/tests/folder/test2.c | 13 | ||||
-rw-r--r-- | camel/tests/folder/test3.c | 208 | ||||
-rw-r--r-- | camel/tests/lib/messages.c | 10 | ||||
-rw-r--r-- | camel/tests/message/test1.c | 11 | ||||
-rw-r--r-- | camel/tests/message/test2.c | 2 |
24 files changed, 326 insertions, 119 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 1d3c75262b..4db4d32274 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,70 @@ +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. + 2000-11-28 JP Rosevear <jpr@helixcode.com> * camel-lock.c: No longer hard code the enabled lock types diff --git a/camel/camel-address.c b/camel/camel-address.c index 392b0a69f9..515e86cc02 100644 --- a/camel/camel-address.c +++ b/camel/camel-address.c @@ -43,6 +43,7 @@ static void camel_address_finalize (CamelObject *obj) { camel_address_remove((CamelAddress *)obj, -1); + g_ptr_array_free(((CamelAddress *)obj)->addresses, TRUE); } CamelType diff --git a/camel/camel-exception.c b/camel/camel-exception.c index cf5daff9d3..70b0d6149f 100644 --- a/camel/camel-exception.c +++ b/camel/camel-exception.c @@ -179,27 +179,18 @@ camel_exception_setv (CamelException *ex, va_list args; gchar *tmp_desc_string; - /* if no exception is given, do nothing */ if (!ex) return; + if (ex->desc) + g_free (ex->desc); /* create the temporary exception string */ va_start(args, format); - tmp_desc_string = g_strdup_vprintf (format, args); + ex->desc = g_strdup_vprintf (format, args); va_end (args); - - - /* now set the exception. We don't call - camel_exception_set because we want to - avoid a useless strdup () */ + ex->id = id; - - /* remove the previous exception description */ - if (ex->desc) - g_free (ex->desc); - ex->desc = g_strdup (tmp_desc_string); - } diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c index 4d61b5cfa1..8bd1e90b24 100644 --- a/camel/camel-folder-search.c +++ b/camel/camel-folder-search.c @@ -116,8 +116,9 @@ camel_folder_search_finalize (CamelObject *obj) CamelFolderSearch *search = (CamelFolderSearch *)obj; struct _CamelFolderSearchPrivate *p = _PRIVATE(obj); + /* yeah, this is a gtk object */ if (search->sexp) - camel_object_unref((CamelObject *)search->sexp); + gtk_object_unref(search->sexp); g_free(search->last_search); g_hash_table_foreach(p->mempool_hash, free_mempool, obj); diff --git a/camel/camel-lock.c b/camel/camel-lock.c index 8b9b159001..f1a43a3543 100644 --- a/camel/camel-lock.c +++ b/camel/camel-lock.c @@ -134,7 +134,7 @@ camel_lock_dot(const char *path, CamelException *ex) /* check for stale lock, kill it */ if (stat(lock, &st) == 0) { time_t now = time(0); - d(printf("There is an existing lock %ld seconds old\n", now-st.st_ctime)); + (printf("There is an existing lock %ld seconds old\n", now-st.st_ctime)); if (st.st_ctime < now - CAMEL_LOCK_DOT_STALE) { d(printf("Removing it now\n")); unlink(lock); diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 5fb2775ca1..86ac9c0b13 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -468,8 +468,8 @@ set_content_object (CamelMedium *medium, CamelDataWrapper *content) char *txt; txt = header_content_type_format(object_content_field?object_content_field->content_type:NULL); - camel_medium_set_header (CAMEL_MEDIUM (mime_part), - "Content-Type", txt); + camel_medium_set_header (CAMEL_MEDIUM (mime_part), "Content-Type", txt); + g_free(txt); } } diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index f1f08e25a0..82162a0239 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -1440,7 +1440,7 @@ header_decode_quoted_string(const char **in) /* first, calc length */ inptr++; intmp = inptr; - while ( (c = *intmp++) && c!= '"' && c != '\0') { + while ( (c = *intmp++) && c!= '"') { if (c=='\\' && *intmp) { intmp++; skip++; @@ -1448,7 +1448,7 @@ header_decode_quoted_string(const char **in) } outlen = intmp-inptr-skip; out = outptr = g_malloc(outlen+1); - while ( (c = *inptr++) && c!= '"' && c != '\0') { + while ( (c = *inptr++) && c!= '"') { if (c=='\\' && *inptr) { c = *inptr++; } @@ -3044,6 +3044,33 @@ header_fold(const char *in) return ret; } +char * +header_unfold(const char *in) +{ + char *out = g_malloc(strlen(in)+1); + const char *inptr = in; + char c, *o = out; + + o = out; + while ((c = *inptr++)) { + if (c == '\n') { + if (is_lwsp(*inptr)) { + do { + inptr++; + } while (is_lwsp(*inptr)); + *o++ = ' '; + } else { + *o++ = c; + } + } else { + *o++ = c; + } + } + *o = 0; + + return out; +} + #ifdef BUILD_TABLE /* for debugging tests */ diff --git a/camel/camel-mime-utils.h b/camel/camel-mime-utils.h index 6f452f1ffa..9bcdb063ac 100644 --- a/camel/camel-mime-utils.h +++ b/camel/camel-mime-utils.h @@ -142,6 +142,7 @@ void header_raw_clear(struct _header_raw **list); /* fold a header */ char *header_fold(const char *in); +char *header_unfold(const char *in); /* decode a header which is a simple token */ char *header_token_decode(const char *in); diff --git a/camel/camel-session.c b/camel/camel-session.c index ac85005da2..3ca63ca9e9 100644 --- a/camel/camel-session.c +++ b/camel/camel-session.c @@ -65,6 +65,7 @@ camel_session_finalise (CamelObject *o) { CamelSession *session = (CamelSession *)o; + g_free(session->storage_path); g_hash_table_foreach_remove (session->providers, camel_session_destroy_provider, NULL); g_hash_table_destroy (session->providers); diff --git a/camel/camel-store.c b/camel/camel-store.c index 7712079af7..362b3fae92 100644 --- a/camel/camel-store.c +++ b/camel/camel-store.c @@ -90,7 +90,8 @@ camel_store_init (void *o, void *k) { CamelStore *store = o; - store->folders = g_hash_table_new (g_str_hash, g_str_equal); + if (store->folders == NULL) + store->folders = g_hash_table_new (g_str_hash, g_str_equal); store->flags = 0; } diff --git a/camel/camel-stream-mem.c b/camel/camel-stream-mem.c index 77941894b7..0c07a2759f 100644 --- a/camel/camel-stream-mem.c +++ b/camel/camel-stream-mem.c @@ -127,14 +127,14 @@ void camel_stream_mem_set_byte_array (CamelStreamMem *s, GByteArray *buffer) s->buffer = buffer; } -void camel_stream_mem_set_buffer (CamelStreamMem *s, const char *buffer, - size_t len) +void camel_stream_mem_set_buffer (CamelStreamMem *s, const char *buffer, size_t len) { GByteArray *ba; ba = g_byte_array_new (); - g_byte_array_append (ba, (const guint8 *)buffer, len); + g_byte_array_append(ba, (const guint8 *)buffer, len); camel_stream_mem_set_byte_array(s, ba); + s->owner = TRUE; } static void diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c index 16ca2d8b2e..787b482169 100644 --- a/camel/providers/local/camel-local-folder.c +++ b/camel/providers/local/camel-local-folder.c @@ -138,9 +138,22 @@ local_finalize(CamelObject * object) { CamelLocalFolder *local_folder = CAMEL_LOCAL_FOLDER(object); + if (local_folder->summary) { + camel_local_summary_sync(local_folder->summary, FALSE, local_folder->changes, NULL); + camel_object_unref((CamelObject *)local_folder->summary); + } + + if (local_folder->search) { + camel_object_unref((CamelObject *)local_folder->search); + } + + /* must free index after summary, since it isn't refcounted */ if (local_folder->index) ibex_close(local_folder->index); + while (local_folder->locked> 0) + camel_local_folder_unlock(local_folder); + g_free(local_folder->base_path); g_free(local_folder->folder_path); g_free(local_folder->summary_path); diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c index 748cc45290..9af9df2744 100644 --- a/camel/providers/local/camel-local-store.c +++ b/camel/providers/local/camel-local-store.c @@ -77,6 +77,9 @@ camel_local_store_init (gpointer object, gpointer klass) CamelStore *store = CAMEL_STORE (object); /* local names are filenames, so they are case-sensitive. */ + if (store->folders) + g_hash_table_destroy(store->folders); + store->folders = g_hash_table_new (g_str_hash, g_str_equal); } diff --git a/camel/providers/local/camel-local-summary.c b/camel/providers/local/camel-local-summary.c index 81cde8e808..83b0e6313b 100644 --- a/camel/providers/local/camel-local-summary.c +++ b/camel/providers/local/camel-local-summary.c @@ -470,14 +470,13 @@ local_summary_encode_x_evolution(CamelLocalSummary *cls, const CamelMessageInfo } if (flag || tag) { - g_string_append(out, "; "); val = g_string_new(""); if (flag) { while (flag) { g_string_append(val, flag->name); if (flag->next) - g_string_append_c(out, ','); + g_string_append_c(val, ','); flag = flag->next; } header_set_param(¶ms, "flags", val->str); @@ -489,7 +488,7 @@ local_summary_encode_x_evolution(CamelLocalSummary *cls, const CamelMessageInfo g_string_append_c(val, '='); g_string_append(val, tag->value); if (tag->next) - g_string_append_c(out, ','); + g_string_append_c(val, ','); tag = tag->next; } header_set_param(¶ms, "tags", val->str); diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c index fe88539ca3..0fa9f1c0d9 100644 --- a/camel/providers/local/camel-maildir-summary.c +++ b/camel/providers/local/camel-maildir-summary.c @@ -38,6 +38,7 @@ #define CAMEL_MAILDIR_SUMMARY_VERSION (0x2000) static CamelMessageInfo *message_info_new(CamelFolderSummary *, struct _header_raw *); +static void message_info_free(CamelFolderSummary *, CamelMessageInfo *mi); static int maildir_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changeinfo, CamelException *ex); static int maildir_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex); @@ -86,6 +87,7 @@ camel_maildir_summary_class_init (CamelMaildirSummaryClass *class) /* override methods */ sklass->message_info_new = message_info_new; + sklass->message_info_free = message_info_free; sklass->next_uid_string = maildir_summary_next_uid_string; lklass->check = maildir_summary_check; @@ -118,6 +120,7 @@ camel_maildir_summary_finalise(CamelObject *obj) { CamelMaildirSummary *o = (CamelMaildirSummary *)obj; + g_free(o->priv->hostname); g_free(o->priv); } @@ -253,6 +256,16 @@ static CamelMessageInfo *message_info_new(CamelFolderSummary * s, struct _header return mi; } +static void message_info_free(CamelFolderSummary *s, CamelMessageInfo *mi) +{ + CamelMaildirMessageInfo *mdi = (CamelMaildirMessageInfo *)mi; + + g_free(mdi->filename); + + ((CamelFolderSummaryClass *) parent_class)->message_info_free(s, mi); +} + + static char *maildir_summary_next_uid_string(CamelFolderSummary *s) { CamelMaildirSummary *mds = (CamelMaildirSummary *)s; @@ -476,6 +489,7 @@ maildir_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changes, Ca g_free(dest); } } + closedir(dir); g_free(new); g_free(cur); diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c index b4c2d151a5..b2a5e13e4a 100644 --- a/camel/providers/local/camel-mbox-summary.c +++ b/camel/providers/local/camel-mbox-summary.c @@ -646,7 +646,7 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha int i, count; CamelMboxMessageInfo *info; int fd = -1; - char *xevnew; + char *xevnew, *xevtmp; const char *xev; int len; off_t lastpos; @@ -709,12 +709,20 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha goto error; } xevnew = camel_local_summary_encode_x_evolution(cls, (CamelMessageInfo *)info); - /* the raw header contains a leading ' ', so count that too */ - if (strlen(xev)-1 != strlen(xevnew)) { + /* SIGH: encode_param_list is about the only function which folds headers by itself. + This should be fixed somehow differently (either parser doesn't fold headers, + or param_list doesn't, or something */ + xevtmp = header_unfold(xevnew); + /* the raw header contains a leading ' ', so (dis)count that too */ + if (strlen(xev)-1 != strlen(xevtmp)) { g_free(xevnew); + g_free(xevtmp); g_warning("Hmm, the xev headers shouldn't have changed size, but they did"); goto error; } + g_free(xevtmp); + + /* we write out the xevnew string, assuming its been folded identically to the original too! */ lastpos = lseek(fd, 0, SEEK_CUR); lseek(fd, xevoffset+strlen("X-Evolution: "), SEEK_SET); @@ -722,6 +730,7 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha len = write(fd, xevnew, strlen(xevnew)); } while (len == -1 && errno == EINTR); lseek(fd, lastpos, SEEK_SET); + g_free(xevnew); camel_mime_parser_drop_step(mp); camel_mime_parser_drop_step(mp); diff --git a/camel/providers/local/camel-mh-summary.c b/camel/providers/local/camel-mh-summary.c index c28ee1f495..e9fb9f116c 100644 --- a/camel/providers/local/camel-mh-summary.c +++ b/camel/providers/local/camel-mh-summary.c @@ -145,7 +145,7 @@ static char *mh_summary_next_uid_string(CamelFolderSummary *s) CamelLocalSummary *cls = (CamelLocalSummary *)s; int fd = -1; guint32 uid; - char *name = NULL; + char *name; /* if we are working to add an existing file, then use current_uid */ if (mhs->priv->current_uid) @@ -153,12 +153,12 @@ static char *mh_summary_next_uid_string(CamelFolderSummary *s) /* else scan for one - and create it too, to make sure */ do { - g_free(name); close(fd); uid = camel_folder_summary_next_uid(s); name = g_strdup_printf("%s/%u", cls->folder_path, uid); /* O_EXCL isn't guaranteed, sigh. Oh well, bad luck, mh has problems anyway */ fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600); + g_free(name); } while (fd == -1 && errno == EEXIST); close(fd); diff --git a/camel/tests/folder/Makefile.am b/camel/tests/folder/Makefile.am index a036db99e5..aa430fa409 100644 --- a/camel/tests/folder/Makefile.am +++ b/camel/tests/folder/Makefile.am @@ -14,10 +14,10 @@ LDADD = \ check_PROGRAMS = \ test1 \ - test2 -# test3 + test2 \ + test3 -#TESTS = test1 +TESTS = test1 test2 test3 diff --git a/camel/tests/folder/test1.c b/camel/tests/folder/test1.c index 020c511a82..9ead130dfd 100644 --- a/camel/tests/folder/test1.c +++ b/camel/tests/folder/test1.c @@ -33,9 +33,12 @@ int main(int argc, char **argv) int i; char *path; + camel_test_init(argc, argv); + ex = camel_exception_new(); - camel_test_init(argc, argv); + /* clear out any camel-test data */ + system("/bin/rm -rf /tmp/camel-test"); session = camel_session_new("/tmp/camel-test", auth_callback, NULL, NULL); diff --git a/camel/tests/folder/test2.c b/camel/tests/folder/test2.c index c7a1af2c33..06053f76c0 100644 --- a/camel/tests/folder/test2.c +++ b/camel/tests/folder/test2.c @@ -43,10 +43,13 @@ int main(int argc, char **argv) GPtrArray *uids; const CamelMessageInfo *info; - ex = camel_exception_new(); - camel_test_init(argc, argv); + /* clear out any camel-test data */ + system("/bin/rm -rf /tmp/camel-test"); + + ex = camel_exception_new(); + session = camel_session_new("/tmp/camel-test", auth_callback, NULL, NULL); /* todo: cross-check everything with folder_info checks as well */ @@ -221,7 +224,7 @@ int main(int argc, char **argv) camel_folder_free_uids(folder, uids); pull(); - camel_object_unref((CamelObject *)folder); + check_unref(folder, 1); pull(); /* re-opening folder */ push("deleting test folder, with no messages in it"); @@ -229,12 +232,12 @@ int main(int argc, char **argv) check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); pull(); - camel_object_unref((CamelObject *)store); + check_unref(store, 1); camel_test_end(); } } - camel_object_unref((CamelObject *)session); + check_unref(session, 1); camel_exception_free(ex); return 0; diff --git a/camel/tests/folder/test3.c b/camel/tests/folder/test3.c index ecd0a46fe7..e231c4911a 100644 --- a/camel/tests/folder/test3.c +++ b/camel/tests/folder/test3.c @@ -13,6 +13,9 @@ #include <camel/camel-folder-summary.h> #include <camel/camel-mime-message.h> +#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) + + /* god, who designed this horrid interface */ static char *auth_callback(CamelAuthCallbackMode mode, char *data, gboolean secret, @@ -33,12 +36,12 @@ test_folder_search_sub(CamelFolder *folder, const char *expr, int expected) uids = camel_folder_search_by_expression(folder, expr, ex); check(uids != NULL); - check(uids->len == expected); + check_msg(uids->len == expected, "search %s expected %d got %d", expr, expected, uids->len); check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); /* check the uid's are actually unique, too */ hash = g_hash_table_new(g_str_hash, g_str_equal); - for (i=0;uids->len;i++) { + for (i=0;i<uids->len;i++) { check(g_hash_table_lookup(hash, uids->pdata[i]) == NULL); g_hash_table_insert(hash, uids->pdata[i], uids->pdata[i]); } @@ -54,9 +57,14 @@ test_folder_search(CamelFolder *folder, const char *expr, int expected) { char *matchall; +#if 0 + /* FIXME: ??? */ + camel_test_nonfatal("most searches require match-all construct"); push("Testing search: %s", expr); test_folder_search_sub(folder, expr, expected); pull(); + camel_test_fatal(); +#endif matchall = g_strdup_printf("(match-all %s)", expr); push("Testing search: %s", matchall); @@ -65,7 +73,77 @@ test_folder_search(CamelFolder *folder, const char *expr, int expected) pull(); } -#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) +static struct { + int counts[3]; + char *expr; +} searches[] = { + { { 100, 50, 0 }, "(header-contains \"subject\" \"subject\")" }, + { { 100, 50, 0 }, "(header-contains \"subject\" \"Subject\")" }, + + { { 100, 50, 0 }, "(body-contains \"content\")" }, + { { 100, 50, 0 }, "(body-contains \"Content\")" }, + + { { 0, 0, 0 }, "(user-flag \"every7\")" }, + { { 100/13+1, 50/13+1, 0 }, "(user-flag \"every13\")" }, + { { 1, 1, 0 }, "(= \"7tag1\" (user-tag \"every7\"))" }, + { { 100/11+1, 50/11+1, 0 }, "(= \"11tag\" (user-tag \"every11\"))" }, + + { { 100/13 + 100/17 + 1, 50/13 + 50/17 + 2, 0 }, "(user-flag \"every13\" \"every17\")" }, + { { 100/13 + 100/17 + 1, 50/13 + 50/17 + 2, 0 }, "(or (user-flag \"every13\") (user-flag \"every17\"))" }, + { { 1, 0, 0 }, "(and (user-flag \"every13\") (user-flag \"every17\"))" }, + + { { 0, 0, 0 }, "(and (header-contains \"subject\" \"Test1\") (header-contains \"subject\" \"Test2\"))" }, + /* we get 11 here as the header-contains is a substring match */ + { { 11, 6, 0 }, "(and (header-contains \"subject\" \"Test1\") (header-contains \"subject\" \"subject\"))" }, + { { 1, 1, 0 }, "(and (header-contains \"subject\" \"Test19\") (header-contains \"subject\" \"subject\"))" }, + { { 0, 0, 0 }, "(and (header-contains \"subject\" \"Test191\") (header-contains \"subject\" \"subject\"))" }, + { { 1, 1, 0 }, "(and (header-contains \"subject\" \"Test1\") (header-contains \"subject\" \"message99\"))" }, + + { { 22, 11, 0 }, "(or (header-contains \"subject\" \"Test1\") (header-contains \"subject\" \"Test2\"))" }, + { { 2, 1, 0 }, "(or (header-contains \"subject\" \"Test16\") (header-contains \"subject\" \"Test99\"))" }, + { { 1, 1, 0 }, "(or (header-contains \"subject\" \"Test123\") (header-contains \"subject\" \"Test99\"))" }, + { { 100, 50, 0 }, "(or (header-contains \"subject\" \"Test1\") (header-contains \"subject\" \"subject\"))" }, + { { 11, 6, 0 }, "(or (header-contains \"subject\" \"Test1\") (header-contains \"subject\" \"message99\"))" }, + + /* 72000 is 24*60*100 == half the 'sent date' of the messages */ + { { 100/2, 50/2, 0 }, "(> 72000 (get-sent-date))" }, + { { 100/2-1, 50/2, 0 }, "(< 72000 (get-sent-date))" }, + { { 1, 0, 0 }, "(= 72000 (get-sent-date))" }, + { { 0, 0, 0 }, "(= 72001 (get-sent-date))" }, + + { { (100/2-1)/17+1, (50/2-1)/17+1, 0 }, "(and (user-flag \"every17\") (< 72000 (get-sent-date)))" }, + { { (100/2-1)/17+1, (50/2-1)/17, 0 }, "(and (user-flag \"every17\") (> 72000 (get-sent-date)))" }, + { { (100/2-1)/13+1, (50/2-1)/13+1, 0 }, "(and (user-flag \"every13\") (< 72000 (get-sent-date)))" }, + { { (100/2-1)/13+1, (50/2-1)/13+1, 0 }, "(and (user-flag \"every13\") (> 72000 (get-sent-date)))" }, + + { { 100/2+100/2/17, 50/2+50/2/17, 0 }, "(or (user-flag \"every17\") (< 72000 (get-sent-date)))" }, + { { 100/2+100/2/17+1, 50/2+50/2/17+1, 0 }, "(or (user-flag \"every17\") (> 72000 (get-sent-date)))" }, + { { 100/2+100/2/13, 50/2+50/2/13+1, 0 }, "(or (user-flag \"every13\") (< 72000 (get-sent-date)))" }, + { { 100/2+100/2/13+1, 50/2+50/2/13+1, 0 }, "(or (user-flag \"every13\") (> 72000 (get-sent-date)))" }, +}; + +static void +run_search(CamelFolder *folder, int m) +{ + int i, j = 0; + + check(m == 50 || m == 100 || m == 0); + + /* *shrug* messy, but it'll do */ + if (m==50) + j = 1; + else if (m==0) + j = 2; + + push("performing searches, expected %d", m); + for (i=0;i<ARRAY_LEN(searches);i++) { + push("running search %d: %s", i, searches[i].expr); + test_folder_search(folder, searches[i].expr, searches[i].counts[j]); + pull(); + } + pull(); +} + static char *stores[] = { "mbox:///tmp/camel-test/mbox", @@ -84,9 +162,13 @@ int main(int argc, char **argv) int indexed; GPtrArray *uids; + gtk_init(&argc, &argv); + camel_test_init(argc, argv); + ex = camel_exception_new(); - camel_test_init(argc, argv); + /* clear out any camel-test data */ + system("/bin/rm -rf /tmp/camel-test"); session = camel_session_new("/tmp/camel-test", auth_callback, NULL, NULL); @@ -137,7 +219,6 @@ int main(int argc, char **argv) camel_mime_message_set_subject(msg, subject); camel_mime_message_set_date(msg, j*60*24, 0); - pull(); push("appending simple message %d", j); @@ -175,99 +256,70 @@ int main(int argc, char **argv) camel_folder_free_uids(folder, uids); pull(); - /* should try invalid search strings too */ - - /* try some searches */ - push("performing searches"); - test_folder_search(folder, "(header-contains \"subject\" \"subject\")", 100); - test_folder_search(folder, "(header-contains \"subject\" \"Subject\")", 100); - - test_folder_search(folder, "(body-contains \"content\")", 100); - test_folder_search(folder, "(body-contains \"Content\")", 100); - - test_folder_search(folder, "(user-flag \"every7\")", 0); - test_folder_search(folder, "(user-flag \"every13\")", 100/13); - test_folder_search(folder, "(= \"7tag1\" (user-tag \"every7\"))", 1); - test_folder_search(folder, "(= \"11tag\" (user-tag \"every11\"))", 100/11); - - test_folder_search(folder, "(user-flag \"every13\" \"every17\")", 100/13 + 100/17); - test_folder_search(folder, "(or (user-flag \"every13\") (user-flag \"every17\"))", 100/13 + 100/17); - test_folder_search(folder, "(and (user-flag \"every13\") (user-flag \"every17\"))", 0); - - test_folder_search(folder, "(and (header-contains \"subject\" \"Test1\")" - "(header-contains \"subject\" \"Test2\"))", 0); - test_folder_search(folder, "(and (header-contains \"subject\" \"Test1\")" - "(header-contains \"subject\" \"subject\"))", 1); - test_folder_search(folder, "(and (header-contains \"subject\" \"Test1\")" - "(header-contains \"subject\" \"message99\"))", 1); - - test_folder_search(folder, "(or (header-contains \"subject\" \"Test1\")" - "(header-contains \"subject\" \"Test2\"))", 2); - test_folder_search(folder, "(or (header-contains \"subject\" \"Test1\")" - "(header-contains \"subject\" \"subject\"))", 100); - test_folder_search(folder, "(or (header-contains \"subject\" \"Test1\")" - "(header-contains \"subject\" \"message99\"))", 1); - - /* 7200 is 24*60*50 == half the 'sent date' of the messages */ - test_folder_search(folder, "(> 7200 (get-sent-date))", 49); - test_folder_search(folder, "(< 7200 (get-sent-date))", 49); - test_folder_search(folder, "(= 7200 (get-sent-date))", 1); - test_folder_search(folder, "(= 7201 (get-sent-date))", 0); - - test_folder_search(folder, "(and (user-flag \"every17\") (< 7200 (get-sent-date)))", 49/17); - test_folder_search(folder, "(and (user-flag \"every17\") (> 7200 (get-sent-date)))", 49/17-1); - test_folder_search(folder, "(and (user-flag \"every13\") (< 7200 (get-sent-date)))", 49/13); - test_folder_search(folder, "(and (user-flag \"every13\") (> 7200 (get-sent-date)))", 49/13-1); - - test_folder_search(folder, "(or (user-flag \"every17\") (< 7200 (get-sent-date)))", 49); - test_folder_search(folder, "(or (user-flag \"every17\") (> 7200 (get-sent-date)))", 49); - test_folder_search(folder, "(or (user-flag \"every13\") (< 7200 (get-sent-date)))", 49); - test_folder_search(folder, "(or (user-flag \"every13\") (> 7200 (get-sent-date)))", 49); - - push("deleting every 2nd message & expunging"); + push("Search before sync"); + run_search(folder, 100); + pull(); + + push("syncing folder, searching"); + camel_folder_sync(folder, FALSE, ex); + run_search(folder, 100); + pull(); + + push("syncing wiht expunge, search"); + camel_folder_sync(folder, TRUE, ex); + run_search(folder, 100); + pull(); + + push("deleting every 2nd message"); uids = camel_folder_get_uids(folder); check(uids->len == 100); - for (j=0;j<uids->len;j++) { + for (j=0;j<uids->len;j+=2) { camel_folder_delete_message(folder, uids->pdata[j]); } + camel_folder_free_uids(folder, uids); + run_search(folder, 100); - push("searches after deletions, before sync"); - test_folder_search(folder, "(header-contains \"subject\" \"subject\")", 100); - test_folder_search(folder, "(body-contains \"content\")", 100); - pull(); - + push("syncing"); camel_folder_sync(folder, FALSE, ex); - - push("searches after sync, before expunge"); - test_folder_search(folder, "(header-contains \"subject\" \"subject\")", 100); - test_folder_search(folder, "(body-contains \"content\")", 100); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + run_search(folder, 100); pull(); + push("expunging"); camel_folder_expunge(folder, ex); check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - camel_folder_free_uids(folder, uids); + run_search(folder, 50); pull(); - /* more searches */ - push("searches after deletions"); - test_folder_search(folder, "(header-contains \"subject\" \"subject\")", 50); - test_folder_search(folder, "(body-contains \"content\")", 50); pull(); - push("deleting remaining messages & expunging"); + push("closing and re-opening folder"); + check_unref(folder, 1); + folder = camel_store_get_folder(store, "testbox", flags&~(CAMEL_STORE_FOLDER_CREATE), ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(folder != NULL); + + push("deleting remaining messages"); uids = camel_folder_get_uids(folder); - check(uids->len == 100); + check(uids->len == 50); for (j=0;j<uids->len;j++) { camel_folder_delete_message(folder, uids->pdata[j]); } + camel_folder_free_uids(folder, uids); + run_search(folder, 50); + + push("syncing"); + camel_folder_sync(folder, FALSE, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + run_search(folder, 50); + pull(); + + push("expunging"); camel_folder_expunge(folder, ex); check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - camel_folder_free_uids(folder, uids); + run_search(folder, 0); pull(); - push("searches wtih no messages"); - test_folder_search(folder, "(header-contains \"subject\" \"subject\")", 0); - test_folder_search(folder, "(body-contains \"content\")", 0); pull(); check_unref(folder, 1); @@ -278,12 +330,12 @@ int main(int argc, char **argv) check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); pull(); - camel_object_unref((CamelObject *)store); + check_unref(store, 1); camel_test_end(); } } - camel_object_unref((CamelObject *)session); + check_unref(session, 1); camel_exception_free(ex); return 0; diff --git a/camel/tests/lib/messages.c b/camel/tests/lib/messages.c index e2e447d97c..ab5b7528ce 100644 --- a/camel/tests/lib/messages.c +++ b/camel/tests/lib/messages.c @@ -33,6 +33,12 @@ test_message_create_simple(void) return msg; } +static void +content_finalise(CamelObject *folder, void *crap, void *ba) +{ + g_byte_array_free(ba, TRUE); +} + void test_message_set_content_simple(CamelMimePart *part, int how, const char *type, const char *text, int len) { @@ -65,7 +71,7 @@ test_message_set_content_simple(CamelMimePart *part, int how, const char *type, content = (CamelStreamMem *)camel_stream_mem_new(); camel_stream_mem_set_byte_array(content, ba); - /* ba gets leaked here */ + camel_object_hook_event((CamelObject *)content, "finalize", content_finalise, ba); break; } @@ -137,9 +143,11 @@ test_message_compare_content(CamelDataWrapper *dw, const char *text, int len) int test_message_compare_header(CamelMimeMessage *m1, CamelMimeMessage *m2) { + return 0; } int test_message_compare_messages(CamelMimeMessage *m1, CamelMimeMessage *m2) { + return 0; } diff --git a/camel/tests/message/test1.c b/camel/tests/message/test1.c index 681537d269..3294000550 100644 --- a/camel/tests/message/test1.c +++ b/camel/tests/message/test1.c @@ -94,6 +94,15 @@ setup(void) 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; @@ -185,5 +194,7 @@ int main(int argc, char **argv) } camel_test_end(); + cleanup(); + return 0; } diff --git a/camel/tests/message/test2.c b/camel/tests/message/test2.c index 00bd6aabf2..6baf7b92f4 100644 --- a/camel/tests/message/test2.c +++ b/camel/tests/message/test2.c @@ -229,6 +229,7 @@ int main(int argc, char **argv) check(camel_internet_address_get(addr, 0, &real, &where) == TRUE); check_msg(string_equal(name, real), "name = '%s' real = '%s'", name, real); check(strcmp(where, "nobody@nowhere.com") == 0); + test_free(name); check(camel_internet_address_get(addr, 1, &real, &where) == FALSE); check(camel_address_length(CAMEL_ADDRESS(addr)) == 1); @@ -248,6 +249,7 @@ int main(int argc, char **argv) push("Compare addresses"); test_address_compare(addr, addr2); pull(); + check_unref(addr2, 1); test_free(enc); pull(); |