diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2000-12-04 20:59:01 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-12-04 20:59:01 +0800 |
commit | a2391a3e1120751cf516d245226e30dcff8507b2 (patch) | |
tree | 6c7b0c06b97edbc8a23a216000b4aed20f4e4d56 | |
parent | bfb8c339693b75919860ade1e9affb4587445f0e (diff) | |
download | gsoc2013-evolution-a2391a3e1120751cf516d245226e30dcff8507b2.tar.gz gsoc2013-evolution-a2391a3e1120751cf516d245226e30dcff8507b2.tar.zst gsoc2013-evolution-a2391a3e1120751cf516d245226e30dcff8507b2.zip |
added some imap tests, tho they dont get far yet and dont
recover automatically.
svn path=/trunk/; revision=6772
-rw-r--r-- | camel/tests/folder/Makefile.am | 8 | ||||
-rw-r--r-- | camel/tests/folder/README | 9 | ||||
-rw-r--r-- | camel/tests/folder/test1.c | 97 | ||||
-rw-r--r-- | camel/tests/folder/test2.c | 194 | ||||
-rw-r--r-- | camel/tests/folder/test4.c | 73 | ||||
-rw-r--r-- | camel/tests/folder/test5.c | 73 | ||||
-rw-r--r-- | camel/tests/folder/test6.c | 74 | ||||
-rw-r--r-- | camel/tests/folder/test7.c | 74 | ||||
-rw-r--r-- | camel/tests/lib/folders.c | 336 | ||||
-rw-r--r-- | camel/tests/lib/folders.h | 7 |
10 files changed, 654 insertions, 291 deletions
diff --git a/camel/tests/folder/Makefile.am b/camel/tests/folder/Makefile.am index aa430fa409..45f2e9895e 100644 --- a/camel/tests/folder/Makefile.am +++ b/camel/tests/folder/Makefile.am @@ -13,11 +13,13 @@ LDADD = \ $(GNOMEUI_LIBS) $(INTLLIBS) $(EXTRA_GNOME_LIBS) check_PROGRAMS = \ - test1 \ - test2 \ + test1 test4 test5 \ + test2 test6 test7 \ test3 -TESTS = test1 test2 test3 +TESTS = test1 test4 test5 \ + test2 test6 test7 \ + test3 diff --git a/camel/tests/folder/README b/camel/tests/folder/README index 994c4cdec4..fab1358198 100644 --- a/camel/tests/folder/README +++ b/camel/tests/folder/README @@ -1,4 +1,9 @@ test1 camel store folder operations (local only) -test2 basic folder operations -test3 folder searching and indexing +test2 basic folder operations, local +test3 folder searching and indexing, local +test4 camel store folder operations, IMAP +test5 camel store folder operations, NNTP +test6 basic folder operations, IMAP +test7 basic folder operations, NNTP + diff --git a/camel/tests/folder/test1.c b/camel/tests/folder/test1.c index 9ead130dfd..e7d1ac0604 100644 --- a/camel/tests/folder/test1.c +++ b/camel/tests/folder/test1.c @@ -1,6 +1,7 @@ /* store testing */ #include "camel-test.h" +#include "folders.h" #include <camel/camel-exception.h> #include <camel/camel-service.h> @@ -27,9 +28,7 @@ static char *local_providers[] = { int main(int argc, char **argv) { CamelSession *session; - CamelStore *store; CamelException *ex; - CamelFolder *folder, *root; int i; char *path; @@ -46,103 +45,11 @@ int main(int argc, char **argv) /* todo: subscriptions? */ /* todo: work out how to do imap/pop/nntp tests */ for (i=0;i<ARRAY_LEN(local_providers);i++) { - char *what = g_strdup_printf("testing local store: %s", local_providers[i]); - - camel_test_start(what); - g_free(what); - - push("getting store"); path = g_strdup_printf("%s:///tmp/camel-test/%s", local_providers[i], local_providers[i]); - store = camel_session_get_store(session, path, ex); - check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex)); - check(store != NULL); - pull(); - - /* local providers == no root folder */ - push("getting root folder"); - root = camel_store_get_root_folder(store, ex); - check(camel_exception_is_set(ex)); - check(root == NULL); - camel_exception_clear(ex); - pull(); - - /* same for default folder */ - push("getting default folder"); - root = camel_store_get_root_folder(store, ex); - check(camel_exception_is_set(ex)); - check(root == NULL); - camel_exception_clear(ex); - pull(); - - push("getting a non-existant folder, no create"); - folder = camel_store_get_folder(store, "unknown", 0, ex); - check(camel_exception_is_set(ex)); - check(folder == NULL); - camel_exception_clear(ex); - pull(); - - push("getting a non-existant folder, with create"); - folder = camel_store_get_folder(store, "testbox", CAMEL_STORE_FOLDER_CREATE, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - check(folder != NULL); - camel_object_unref((CamelObject *)folder); - pull(); - - push("getting an existing folder"); - folder = camel_store_get_folder(store, "testbox", 0, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - check(folder != NULL); - camel_object_unref((CamelObject *)folder); - pull(); - - push("renaming a non-existant folder"); - camel_store_rename_folder(store, "unknown1", "unknown2", ex); - check(camel_exception_is_set(ex)); - camel_exception_clear(ex); - pull(); - - push("renaming an existing folder"); - camel_store_rename_folder(store, "testbox", "testbox2", ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - pull(); - - push("opening the old name of a renamed folder"); - folder = camel_store_get_folder(store, "testbox", 0, ex); - check(camel_exception_is_set(ex)); - check(folder == NULL); - camel_exception_clear(ex); - pull(); - - push("opening the new name of a renamed folder"); - folder = camel_store_get_folder(store, "testbox2", 0, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - check(folder != NULL); - camel_object_unref((CamelObject *)folder); - pull(); - - push("deleting a non-existant folder"); - camel_store_delete_folder(store, "unknown", ex); - check(camel_exception_is_set(ex)); - camel_exception_clear(ex); - pull(); - - push("deleting an existing folder"); - camel_store_delete_folder(store, "testbox2", ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - pull(); - - push("opening a folder that has been deleted"); - folder = camel_store_get_folder(store, "testbox2", 0, ex); - check(camel_exception_is_set(ex)); - check(folder == NULL); - camel_exception_clear(ex); - pull(); - camel_object_unref((CamelObject *)store); + test_folder_basic(session, path, TRUE); g_free(path); - - camel_test_end(); } camel_object_unref((CamelObject *)session); diff --git a/camel/tests/folder/test2.c b/camel/tests/folder/test2.c index a3a8f014b8..47e0f44feb 100644 --- a/camel/tests/folder/test2.c +++ b/camel/tests/folder/test2.c @@ -34,14 +34,8 @@ static char *stores[] = { int main(int argc, char **argv) { CamelSession *session; - CamelStore *store; CamelException *ex; - CamelFolder *folder; - CamelMimeMessage *msg; - int i, j; - int indexed; - GPtrArray *uids; - const CamelMessageInfo *info; + int i; camel_test_init(argc, argv); @@ -52,193 +46,11 @@ int main(int argc, char **argv) session = camel_session_new("/tmp/camel-test", auth_callback, NULL, NULL); - /* todo: cross-check everything with folder_info checks as well */ - /* todo: work out how to do imap/pop/nntp tests */ - /* we iterate over all stores we want to test, with indexing or indexing turned on or off */ for (i=0;i<ARRAY_LEN(stores);i++) { char *name = stores[i]; - for (indexed = 0;indexed<2;indexed++) { - char *what = g_strdup_printf("folder ops: %s (%sindexed)", name, indexed?"":"non-"); - int flags; - - camel_test_start(what); - test_free(what); - - push("getting store"); - store = camel_session_get_store(session, stores[i], ex); - check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex)); - check(store != NULL); - pull(); - - push("creating %sindexed folder", indexed?"":"non-"); - if (indexed) - flags = CAMEL_STORE_FOLDER_CREATE|CAMEL_STORE_FOLDER_BODY_INDEX; - else - flags = CAMEL_STORE_FOLDER_CREATE; - folder = camel_store_get_folder(store, "testbox", flags, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - check(folder != NULL); - - /* verify empty/can't get nonexistant stuff */ - test_folder_counts(folder, 0, 0); - test_folder_not_message(folder, "0"); - test_folder_not_message(folder, ""); - - for (j=0;j<10;j++) { - char *content, *subject; - - push("creating test message"); - msg = test_message_create_simple(); - content = g_strdup_printf("Test message %d contents\n\n", j); - test_message_set_content_simple((CamelMimePart *)msg, 0, "text/plain", - content, strlen(content)); - test_free(content); - subject = g_strdup_printf("Test message %d", j); - camel_mime_message_set_subject(msg, subject); - pull(); - - push("appending simple message %d", j); - camel_folder_append_message(folder, msg, NULL, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - test_folder_counts(folder, j+1, j+1); - - push("checking it is in the right uid slot & exists"); - uids = camel_folder_get_uids(folder); - check(uids != NULL); - check(uids->len == j+1); - test_folder_message(folder, uids->pdata[j]); - pull(); - - push("checking it is the right message (subject): %s", subject); - info = camel_folder_get_message_info(folder, uids->pdata[j]); - check_msg(strcmp(camel_message_info_subject(info), subject)==0, - "info->subject %s", camel_message_info_subject(info)); - camel_folder_free_uids(folder, uids); - pull(); - - test_free(subject); - - check_unref(msg, 1); - pull(); - } - - check_unref(folder, 1); - pull(); - - push("deleting test folder, with messages in it"); - camel_store_delete_folder(store, "testbox", ex); - check(camel_exception_is_set(ex)); - camel_exception_clear(ex); - pull(); - - push("re-opening folder"); - folder = camel_store_get_folder(store, "testbox", flags, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - check(folder != NULL); - - /* verify counts */ - test_folder_counts(folder, 10, 10); - - /* re-check uid's, after a reload */ - uids = camel_folder_get_uids(folder); - check(uids != NULL); - check(uids->len == 10); - for (j=0;j<10;j++) { - char *subject = g_strdup_printf("Test message %d", j); - - push("verify reload of %s", subject); - test_folder_message(folder, uids->pdata[j]); - - info = camel_folder_get_message_info(folder, uids->pdata[j]); - check_msg(strcmp(camel_message_info_subject(info), subject)==0, - "info->subject %s", camel_message_info_subject(info)); - test_free(subject); - pull(); - } - - push("deleting first message & expunging"); - camel_folder_delete_message(folder, uids->pdata[0]); - test_folder_counts(folder, 10, 10); - camel_folder_expunge(folder, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - test_folder_not_message(folder, uids->pdata[0]); - test_folder_counts(folder, 9, 9); - - camel_folder_free_uids(folder, uids); - - uids = camel_folder_get_uids(folder); - check(uids != NULL); - check(uids->len == 9); - for (j=0;j<9;j++) { - char *subject = g_strdup_printf("Test message %d", j+1); - - push("verify after expunge of %s", subject); - test_folder_message(folder, uids->pdata[j]); - - info = camel_folder_get_message_info(folder, uids->pdata[j]); - check_msg(strcmp(camel_message_info_subject(info), subject)==0, - "info->subject %s", camel_message_info_subject(info)); - test_free(subject); - pull(); - } - pull(); - - push("deleting last message & expunging"); - camel_folder_delete_message(folder, uids->pdata[8]); - /* sync? */ - test_folder_counts(folder, 9, 9); - camel_folder_expunge(folder, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - test_folder_not_message(folder, uids->pdata[8]); - test_folder_counts(folder, 8, 8); - - camel_folder_free_uids(folder, uids); - - uids = camel_folder_get_uids(folder); - check(uids != NULL); - check(uids->len == 8); - for (j=0;j<8;j++) { - char *subject = g_strdup_printf("Test message %d", j+1); - - push("verify after expunge of %s", subject); - test_folder_message(folder, uids->pdata[j]); - - info = camel_folder_get_message_info(folder, uids->pdata[j]); - check_msg(strcmp(camel_message_info_subject(info), subject)==0, - "info->subject %s", camel_message_info_subject(info)); - test_free(subject); - pull(); - } - pull(); - - push("deleting all messages & expunging"); - for (j=0;j<8;j++) { - camel_folder_delete_message(folder, uids->pdata[j]); - } - /* sync? */ - test_folder_counts(folder, 8, 8); - camel_folder_expunge(folder, ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - for (j=0;j<8;j++) { - test_folder_not_message(folder, uids->pdata[j]); - } - test_folder_counts(folder, 0, 0); - - camel_folder_free_uids(folder, uids); - pull(); - - check_unref(folder, 1); - pull(); /* re-opening folder */ - - push("deleting test folder, with no messages in it"); - camel_store_delete_folder(store, "testbox", ex); - check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); - pull(); - - check_unref(store, 1); - camel_test_end(); - } + + test_folder_message_ops(session, name, TRUE); } check_unref(session, 1); diff --git a/camel/tests/folder/test4.c b/camel/tests/folder/test4.c new file mode 100644 index 0000000000..bae2b7bb0b --- /dev/null +++ b/camel/tests/folder/test4.c @@ -0,0 +1,73 @@ +/* store testing, for remote folders */ + +#include "camel-test.h" +#include "folders.h" + +#include <camel/camel-exception.h> +#include <camel/camel-service.h> +#include <camel/camel-session.h> +#include <camel/camel-store.h> + +/* god, who designed this horrid interface */ +static char *auth_callback(CamelAuthCallbackMode mode, + char *data, gboolean secret, + CamelService *service, char *item, + CamelException *ex) +{ + return NULL; +} + +static int regtimeout() +{ + return 1; +} + +static int unregtimeout() +{ + return 1; +} + + +#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) + +static char *remote_providers[] = { + "IMAP_TEST_URL", +}; + +int main(int argc, char **argv) +{ + CamelSession *session; + CamelException *ex; + int i; + char *path; + + camel_test_init(argc, argv); + + ex = camel_exception_new(); + + /* clear out any camel-test data */ + system("/bin/rm -rf /tmp/camel-test"); + + session = camel_session_new("/tmp/camel-test", auth_callback, regtimeout, unregtimeout); + + /* todo: cross-check everything with folder_info checks as well */ + /* todo: subscriptions? */ + for (i=0;i<ARRAY_LEN(remote_providers);i++) { + path = getenv(remote_providers[i]); + + if (path == NULL) { + printf("Aborted (ignored).\n"); + printf("Set '%s', to re-run test.\n", remote_providers[i]); + /* tells make check to ignore us in the total count */ + _exit(77); + } + camel_test_nonfatal("The IMAP code is just rooted"); + test_folder_basic(session, path, FALSE); + camel_test_fatal(); + } + + camel_object_unref((CamelObject *)session); + camel_exception_free(ex); + + return 0; +} diff --git a/camel/tests/folder/test5.c b/camel/tests/folder/test5.c new file mode 100644 index 0000000000..9e2544d7e5 --- /dev/null +++ b/camel/tests/folder/test5.c @@ -0,0 +1,73 @@ +/* store testing, for remote folders */ + +#include "camel-test.h" +#include "folders.h" + +#include <camel/camel-exception.h> +#include <camel/camel-service.h> +#include <camel/camel-session.h> +#include <camel/camel-store.h> + +/* god, who designed this horrid interface */ +static char *auth_callback(CamelAuthCallbackMode mode, + char *data, gboolean secret, + CamelService *service, char *item, + CamelException *ex) +{ + return NULL; +} + +static int regtimeout() +{ + return 1; +} + +static int unregtimeout() +{ + return 1; +} + + +#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) + +static char *remote_providers[] = { + "NNTP_TEST_URL", +}; + +int main(int argc, char **argv) +{ + CamelSession *session; + CamelException *ex; + int i; + char *path; + + camel_test_init(argc, argv); + + ex = camel_exception_new(); + + /* clear out any camel-test data */ + system("/bin/rm -rf /tmp/camel-test"); + + session = camel_session_new("/tmp/camel-test", auth_callback, regtimeout, unregtimeout); + + /* todo: cross-check everything with folder_info checks as well */ + /* todo: subscriptions? */ + for (i=0;i<ARRAY_LEN(remote_providers);i++) { + path = getenv(remote_providers[i]); + + if (path == NULL) { + printf("Aborted (ignored).\n"); + printf("Set '%s', to re-run test.\n", remote_providers[i]); + /* tells make check to ignore us in the total count */ + _exit(77); + } + camel_test_nonfatal("Not sure how many tests apply to NNTP"); + test_folder_basic(session, path, FALSE); + camel_test_fatal(); + } + + camel_object_unref((CamelObject *)session); + camel_exception_free(ex); + + return 0; +} diff --git a/camel/tests/folder/test6.c b/camel/tests/folder/test6.c new file mode 100644 index 0000000000..6f4e387fca --- /dev/null +++ b/camel/tests/folder/test6.c @@ -0,0 +1,74 @@ +/* folder testing */ + +#include "camel-test.h" +#include "messages.h" + +#include <camel/camel-exception.h> +#include <camel/camel-service.h> +#include <camel/camel-session.h> +#include <camel/camel-store.h> + +#include <camel/camel-folder.h> +#include <camel/camel-folder-summary.h> +#include <camel/camel-mime-message.h> + +/* god, who designed this horrid interface */ +static char *auth_callback(CamelAuthCallbackMode mode, + char *data, gboolean secret, + CamelService *service, char *item, + CamelException *ex) +{ + return NULL; +} + +static int regtimeout() +{ + return 1; +} + +static int unregtimeout() +{ + return 1; +} + +#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) + +static char *remote_providers[] = { + "IMAP_TEST_URL", +}; + +int main(int argc, char **argv) +{ + CamelSession *session; + CamelException *ex; + int i; + char *path; + + 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, regtimeout, unregtimeout); + + for (i=0;i<ARRAY_LEN(remote_providers);i++) { + path = getenv(remote_providers[i]); + + if (path == NULL) { + printf("Aborted (ignored).\n"); + printf("Set '%s', to re-run test.\n", remote_providers[i]); + /* tells make check to ignore us in the total count */ + _exit(77); + } + /*camel_test_nonfatal("The IMAP code is just rooted");*/ + test_folder_message_ops(session, path, FALSE); + /*camel_test_fatal();*/ + } + + check_unref(session, 1); + camel_exception_free(ex); + + return 0; +} diff --git a/camel/tests/folder/test7.c b/camel/tests/folder/test7.c new file mode 100644 index 0000000000..7acacebbcd --- /dev/null +++ b/camel/tests/folder/test7.c @@ -0,0 +1,74 @@ +/* folder testing */ + +#include "camel-test.h" +#include "messages.h" + +#include <camel/camel-exception.h> +#include <camel/camel-service.h> +#include <camel/camel-session.h> +#include <camel/camel-store.h> + +#include <camel/camel-folder.h> +#include <camel/camel-folder-summary.h> +#include <camel/camel-mime-message.h> + +/* god, who designed this horrid interface */ +static char *auth_callback(CamelAuthCallbackMode mode, + char *data, gboolean secret, + CamelService *service, char *item, + CamelException *ex) +{ + return NULL; +} + +static int regtimeout() +{ + return 1; +} + +static int unregtimeout() +{ + return 1; +} + +#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) + +static char *remote_providers[] = { + "NNTP_TEST_URL", +}; + +int main(int argc, char **argv) +{ + CamelSession *session; + CamelException *ex; + int i; + char *path; + + 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, regtimeout, unregtimeout); + + for (i=0;i<ARRAY_LEN(remote_providers);i++) { + path = getenv(remote_providers[i]); + + if (path == NULL) { + printf("Aborted (ignored).\n"); + printf("Set '%s', to re-run test.\n", remote_providers[i]); + /* tells make check to ignore us in the total count */ + _exit(77); + } + camel_test_nonfatal("Dont know how many tests apply to NNTP"); + test_folder_message_ops(session, path, FALSE); + camel_test_fatal(); + } + + check_unref(session, 1); + camel_exception_free(ex); + + return 0; +} diff --git a/camel/tests/lib/folders.c b/camel/tests/lib/folders.c index 7be1b0c4cf..6f24cd483a 100644 --- a/camel/tests/lib/folders.c +++ b/camel/tests/lib/folders.c @@ -1,6 +1,7 @@ #include "camel-test.h" #include "folders.h" +#include "messages.h" #include "camel/camel-exception.h" @@ -181,3 +182,338 @@ test_folder_not_message(CamelFolder *folder, const char *uid) pull(); } + +/* test basic store operations on folders */ +/* TODO: Add subscription stuff */ +void +test_folder_basic(CamelSession *session, const char *storename, int local) +{ + CamelStore *store; + CamelException *ex = camel_exception_new(); + CamelFolder *folder, *root; + char *what = g_strdup_printf("testing store: %s", storename); + + camel_test_start(what); + test_free(what); + + push("getting store"); + store = camel_session_get_store(session, storename, ex); + check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex)); + check(store != NULL); + pull(); + + /* local providers == no root folder */ + push("getting root folder"); + root = camel_store_get_root_folder(store, ex); + if (local) { + check(camel_exception_is_set(ex)); + check(root == NULL); + camel_exception_clear(ex); + } else { + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(root != NULL); + check_unref(root, 1); + } + pull(); + + /* same for default folder */ + push("getting default folder"); + root = camel_store_get_root_folder(store, ex); + if (local) { + check(camel_exception_is_set(ex)); + check(root == NULL); + camel_exception_clear(ex); + } else { + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(root != NULL); + check_unref(root, 1); + } + pull(); + + push("getting a non-existant folder, no create"); + folder = camel_store_get_folder(store, "unknown", 0, ex); + check(camel_exception_is_set(ex)); + check(folder == NULL); + camel_exception_clear(ex); + pull(); + + push("getting a non-existant folder, with create"); + folder = camel_store_get_folder(store, "testbox", CAMEL_STORE_FOLDER_CREATE, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(folder != NULL); + check_unref(folder, 1); + pull(); + + push("getting an existing folder"); + folder = camel_store_get_folder(store, "testbox", 0, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(folder != NULL); + check_unref(folder, 1); + pull(); + + push("renaming a non-existant folder"); + camel_store_rename_folder(store, "unknown1", "unknown2", ex); + check(camel_exception_is_set(ex)); + camel_exception_clear(ex); + pull(); + + push("renaming an existing folder"); + camel_store_rename_folder(store, "testbox", "testbox2", ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + pull(); + + push("opening the old name of a renamed folder"); + folder = camel_store_get_folder(store, "testbox", 0, ex); + check(camel_exception_is_set(ex)); + check(folder == NULL); + camel_exception_clear(ex); + pull(); + + push("opening the new name of a renamed folder"); + folder = camel_store_get_folder(store, "testbox2", 0, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(folder != NULL); + check_unref(folder, 1); + pull(); + + push("deleting a non-existant folder"); + camel_store_delete_folder(store, "unknown", ex); + check(camel_exception_is_set(ex)); + camel_exception_clear(ex); + pull(); + + push("deleting an existing folder"); + camel_store_delete_folder(store, "testbox2", ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + pull(); + + push("opening a folder that has been deleted"); + folder = camel_store_get_folder(store, "testbox2", 0, ex); + check(camel_exception_is_set(ex)); + check(folder == NULL); + camel_exception_clear(ex); + pull(); + + check_unref(store, 1); + + camel_test_end(); + + camel_exception_free(ex); +} + + +/* todo: cross-check everything with folder_info checks as well */ +/* this should probably take a folder instead of a session ... */ +void +test_folder_message_ops(CamelSession *session, const char *name, int local) +{ + CamelStore *store; + CamelException *ex = camel_exception_new(); + CamelFolder *folder; + CamelMimeMessage *msg; + int j; + int indexed, max; + GPtrArray *uids; + const CamelMessageInfo *info; + + max=local?2:1; + + for (indexed = 0;indexed<max;indexed++) { + char *what = g_strdup_printf("folder ops: %s %s", name, local?(indexed?"indexed":"non-indexed"):""); + int flags; + + camel_test_start(what); + test_free(what); + + push("getting store"); + store = camel_session_get_store(session, name, ex); + check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex)); + check(store != NULL); + pull(); + + push("creating %sindexed folder", indexed?"":"non-"); + if (indexed) + flags = CAMEL_STORE_FOLDER_CREATE|CAMEL_STORE_FOLDER_BODY_INDEX; + else + flags = CAMEL_STORE_FOLDER_CREATE; + folder = camel_store_get_folder(store, "testbox", flags, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(folder != NULL); + + /* verify empty/can't get nonexistant stuff */ + test_folder_counts(folder, 0, 0); + test_folder_not_message(folder, "0"); + test_folder_not_message(folder, ""); + + for (j=0;j<10;j++) { + char *content, *subject; + + push("creating test message"); + msg = test_message_create_simple(); + content = g_strdup_printf("Test message %d contents\n\n", j); + test_message_set_content_simple((CamelMimePart *)msg, 0, "text/plain", + content, strlen(content)); + test_free(content); + subject = g_strdup_printf("Test message %d", j); + camel_mime_message_set_subject(msg, subject); + pull(); + + push("appending simple message %d", j); + camel_folder_append_message(folder, msg, NULL, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + + /* sigh, this shouldn't be required, but the imap code is too dumb to do it itself */ + if (!local) { + push("forcing a refresh of folder updates"); + camel_folder_refresh_info(folder, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + pull(); + } + + if (!local) + camel_test_nonfatal("unread counts dont seem right for imap"); + + test_folder_counts(folder, j+1, j+1); + + if (!local) + camel_test_fatal(); + + push("checking it is in the right uid slot & exists"); + uids = camel_folder_get_uids(folder); + check(uids != NULL); + check(uids->len == j+1); + test_folder_message(folder, uids->pdata[j]); + pull(); + + push("checking it is the right message (subject): %s", subject); + info = camel_folder_get_message_info(folder, uids->pdata[j]); + check_msg(strcmp(camel_message_info_subject(info), subject)==0, + "info->subject %s", camel_message_info_subject(info)); + camel_folder_free_uids(folder, uids); + pull(); + + test_free(subject); + + check_unref(msg, 1); + pull(); + } + + check_unref(folder, 1); + pull(); + + push("deleting test folder, with messages in it"); + camel_store_delete_folder(store, "testbox", ex); + check(camel_exception_is_set(ex)); + camel_exception_clear(ex); + pull(); + + push("re-opening folder"); + folder = camel_store_get_folder(store, "testbox", flags, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + check(folder != NULL); + + /* verify counts */ + test_folder_counts(folder, 10, 10); + + /* re-check uid's, after a reload */ + uids = camel_folder_get_uids(folder); + check(uids != NULL); + check(uids->len == 10); + for (j=0;j<10;j++) { + char *subject = g_strdup_printf("Test message %d", j); + + push("verify reload of %s", subject); + test_folder_message(folder, uids->pdata[j]); + + info = camel_folder_get_message_info(folder, uids->pdata[j]); + check_msg(strcmp(camel_message_info_subject(info), subject)==0, + "info->subject %s", camel_message_info_subject(info)); + test_free(subject); + pull(); + } + + push("deleting first message & expunging"); + camel_folder_delete_message(folder, uids->pdata[0]); + test_folder_counts(folder, 10, 10); + camel_folder_expunge(folder, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + test_folder_not_message(folder, uids->pdata[0]); + test_folder_counts(folder, 9, 9); + + camel_folder_free_uids(folder, uids); + + uids = camel_folder_get_uids(folder); + check(uids != NULL); + check(uids->len == 9); + for (j=0;j<9;j++) { + char *subject = g_strdup_printf("Test message %d", j+1); + + push("verify after expunge of %s", subject); + test_folder_message(folder, uids->pdata[j]); + + info = camel_folder_get_message_info(folder, uids->pdata[j]); + check_msg(strcmp(camel_message_info_subject(info), subject)==0, + "info->subject %s", camel_message_info_subject(info)); + test_free(subject); + pull(); + } + pull(); + + push("deleting last message & expunging"); + camel_folder_delete_message(folder, uids->pdata[8]); + /* sync? */ + test_folder_counts(folder, 9, 9); + camel_folder_expunge(folder, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + test_folder_not_message(folder, uids->pdata[8]); + test_folder_counts(folder, 8, 8); + + camel_folder_free_uids(folder, uids); + + uids = camel_folder_get_uids(folder); + check(uids != NULL); + check(uids->len == 8); + for (j=0;j<8;j++) { + char *subject = g_strdup_printf("Test message %d", j+1); + + push("verify after expunge of %s", subject); + test_folder_message(folder, uids->pdata[j]); + + info = camel_folder_get_message_info(folder, uids->pdata[j]); + check_msg(strcmp(camel_message_info_subject(info), subject)==0, + "info->subject %s", camel_message_info_subject(info)); + test_free(subject); + pull(); + } + pull(); + + push("deleting all messages & expunging"); + for (j=0;j<8;j++) { + camel_folder_delete_message(folder, uids->pdata[j]); + } + /* sync? */ + test_folder_counts(folder, 8, 8); + camel_folder_expunge(folder, ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + for (j=0;j<8;j++) { + test_folder_not_message(folder, uids->pdata[j]); + } + test_folder_counts(folder, 0, 0); + + camel_folder_free_uids(folder, uids); + pull(); + + check_unref(folder, 1); + pull(); /* re-opening folder */ + + push("deleting test folder, with no messages in it"); + camel_store_delete_folder(store, "testbox", ex); + check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); + pull(); + + check_unref(store, 1); + camel_test_end(); + } + + camel_exception_free(ex); +} diff --git a/camel/tests/lib/folders.h b/camel/tests/lib/folders.h index 55c80e0872..2cb2d97028 100644 --- a/camel/tests/lib/folders.h +++ b/camel/tests/lib/folders.h @@ -1,4 +1,7 @@ +#include "camel/camel-session.h" +#include "camel/camel-store.h" + #include <camel/camel-folder.h> #include <camel/camel-folder-summary.h> #include <camel/camel-mime-message.h> @@ -11,3 +14,7 @@ void test_message_info(CamelMimeMessage *msg, const CamelMessageInfo *info); 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); +/* test basic folder ops on a store */ +void test_folder_basic(CamelSession *session, const char *storename, int local); +/* test basic message operations on a folder */ +void test_folder_message_ops(CamelSession *session, const char *storename, int local); |