aboutsummaryrefslogtreecommitdiffstats
path: root/camel/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'camel/tests/lib')
-rw-r--r--camel/tests/lib/Makefile.am4
-rw-r--r--camel/tests/lib/folders.c183
-rw-r--r--camel/tests/lib/folders.h13
3 files changed, 199 insertions, 1 deletions
diff --git a/camel/tests/lib/Makefile.am b/camel/tests/lib/Makefile.am
index 1fae79671d..db09b0cf5e 100644
--- a/camel/tests/lib/Makefile.am
+++ b/camel/tests/lib/Makefile.am
@@ -4,7 +4,9 @@ check_LIBRARIES = libcameltest.a
libcameltest_a_SOURCES = \
camel-test.c camel-test.h \
messages.c messages.h \
- addresses.c addresses.h
+ addresses.c addresses.h \
+ folders.c folders.h
+
diff --git a/camel/tests/lib/folders.c b/camel/tests/lib/folders.c
new file mode 100644
index 0000000000..738f8d2913
--- /dev/null
+++ b/camel/tests/lib/folders.c
@@ -0,0 +1,183 @@
+
+#include "camel-test.h"
+#include "folders.h"
+
+#include "camel/camel-exception.h"
+
+/* check the total/unread is what we think it should be */
+void
+test_folder_counts(CamelFolder *folder, int total, int unread)
+{
+ GPtrArray *s;
+ int i, myunread;
+ const CamelMessageInfo *info;
+
+ push("test folder counts %d total %d unread", total, unread);
+
+ /* first, use the standard functions */
+ check(camel_folder_get_message_count(folder) == total);
+ check(camel_folder_get_unread_message_count(folder) == total);
+
+ /* next, use the summary */
+ s = camel_folder_get_summary(folder);
+ check(s != NULL);
+ check(s->len == total);
+ myunread = s->len;
+ for (i=0;i<s->len;i++) {
+ info = s->pdata[i];
+ if (info->flags & CAMEL_MESSAGE_SEEN)
+ myunread--;
+ }
+ check(unread == myunread);
+ camel_folder_free_summary(folder, s);
+
+ /* last, use the uid list */
+ s = camel_folder_get_uids(folder);
+ check(s != NULL);
+ check(s->len == total);
+ myunread = s->len;
+ for (i=0;i<s->len;i++) {
+ info = camel_folder_get_message_info(folder, s->pdata[i]);
+ if (info->flags & CAMEL_MESSAGE_SEEN)
+ myunread--;
+ }
+ check(unread == myunread);
+ camel_folder_free_uids(folder, s);
+
+ pull();
+}
+
+static int
+safe_strcmp(const char *a, const char *b)
+{
+ if (a == NULL && b == NULL)
+ return 0;
+ if (a == NULL)
+ return 1;
+ if (b == NULL)
+ return -1;
+ return strcmp(a, b);
+}
+
+void
+test_message_info(CamelMimeMessage *msg, const CamelMessageInfo *info)
+{
+ check_msg(safe_strcmp(info->subject, camel_mime_message_get_subject(msg)) == 0,
+ "info->subject = '%s', get_subject() = '%s'", info->subject, camel_mime_message_get_subject(msg));
+
+ /* FIXME: testing from/cc/to, etc is more tricky */
+
+ check(info->date_sent == camel_mime_message_get_date(msg, NULL));
+
+ /* date received isn't set for messages that haven't been sent anywhere ... */
+ /*check(info->date_received == camel_mime_message_get_date_received(msg, NULL));*/
+
+ /* so is messageid/references, etc */
+}
+
+/* check a message is present */
+void
+test_folder_message(CamelFolder *folder, const char *uid)
+{
+ CamelMimeMessage *msg;
+ const CamelMessageInfo *info;
+ GPtrArray *s;
+ int i;
+ CamelException *ex = camel_exception_new();
+ int found;
+
+ push("uid %s is in folder", uid);
+
+ /* first try getting info */
+ info = camel_folder_get_message_info(folder, uid);
+ check(info != NULL);
+ check(strcmp(info->uid, uid) == 0);
+
+ /* then, getting message */
+ msg = camel_folder_get_message(folder, uid, ex);
+ check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
+ check(msg != NULL);
+
+ /* cross check with info */
+ test_message_info(msg, info);
+
+ camel_object_unref((CamelObject *)msg);
+
+ /* see if it is in the summary (only once) */
+ s = camel_folder_get_summary(folder);
+ check(s != NULL);
+ found = 0;
+ for (i=0;i<s->len;i++) {
+ info = s->pdata[i];
+ if (strcmp(info->uid, uid) == 0)
+ found++;
+ }
+ check(found == 1);
+ camel_folder_free_summary(folder, s);
+
+ /* check it is in the uid list */
+ s = camel_folder_get_uids(folder);
+ check(s != NULL);
+ found = 0;
+ for (i=0;i<s->len;i++) {
+ if (strcmp(s->pdata[i], uid) == 0)
+ found++;
+ }
+ check(found == 1);
+ camel_folder_free_uids(folder, s);
+
+ camel_exception_free(ex);
+
+ pull();
+}
+
+/* check message not present */
+void
+test_folder_not_message(CamelFolder *folder, const char *uid)
+{
+ CamelMimeMessage *msg;
+ const CamelMessageInfo *info;
+ GPtrArray *s;
+ int i;
+ CamelException *ex = camel_exception_new();
+ int found;
+
+ push("uid %s is not in folder", uid);
+
+ /* first try getting info */
+ info = camel_folder_get_message_info(folder, uid);
+ check(info == NULL);
+
+ /* then, getting message */
+ msg = camel_folder_get_message(folder, uid, ex);
+ check(camel_exception_is_set(ex));
+ check(msg == NULL);
+ camel_exception_clear(ex);
+
+ /* see if it is not in the summary (only once) */
+ s = camel_folder_get_summary(folder);
+ check(s != NULL);
+ found = 0;
+ for (i=0;i<s->len;i++) {
+ info = s->pdata[i];
+ if (strcmp(info->uid, uid) == 0)
+ found++;
+ }
+ check(found == 0);
+ camel_folder_free_summary(folder, s);
+
+ /* check it is not in the uid list */
+ s = camel_folder_get_uids(folder);
+ check(s != NULL);
+ found = 0;
+ for (i=0;i<s->len;i++) {
+ if (strcmp(s->pdata[i], uid) == 0)
+ found++;
+ }
+ check(found == 0);
+ camel_folder_free_uids(folder, s);
+
+ camel_exception_free(ex);
+
+ pull();
+}
diff --git a/camel/tests/lib/folders.h b/camel/tests/lib/folders.h
new file mode 100644
index 0000000000..55c80e0872
--- /dev/null
+++ b/camel/tests/lib/folders.h
@@ -0,0 +1,13 @@
+
+#include <camel/camel-folder.h>
+#include <camel/camel-folder-summary.h>
+#include <camel/camel-mime-message.h>
+
+/* check the total/unread is what we think it should be, everywhere it can be determined */
+void test_folder_counts(CamelFolder *folder, int total, int unread);
+/* cross-check info/msg */
+void test_message_info(CamelMimeMessage *msg, const CamelMessageInfo *info);
+/* check a message is present everywhere it should be */
+void test_folder_message(CamelFolder *folder, const char *uid);
+/* check message not present everywhere it shouldn't be */
+void test_folder_not_message(CamelFolder *folder, const char *uid);