X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=tests%2Fcheck_update-account.c;h=0cdd2471d3bba22865794a2a5e11fc6798f05b56;hp=6290707e6c8c3471acbaf17e3896277236256cdd;hb=38454a69440197510b16c5a5444e19f234c91690;hpb=5be19f3d421a5531ac9344971a31e381364bf049 diff --git a/tests/check_update-account.c b/tests/check_update-account.c index 6290707..0cdd247 100644 --- a/tests/check_update-account.c +++ b/tests/check_update-account.c @@ -39,69 +39,82 @@ #include #include -#include "modest-tny-platform-factory.h" +#include #include "modest-account-mgr.h" #include "modest-mail-operation.h" #include "modest-mail-operation-queue.h" +#include +#include + +/* seconds we will wait for test to finish */ +#define TEST_TIMEOUT 60 GMainLoop *main_loop; +gint retval = 0; static void -on_progress_changed (ModestMailOperation *mail_op, gpointer user_data) +on_progress_changed (ModestMailOperation *mail_op, ModestMailOperationState *state, gpointer user_data) { - ModestMailOperationStatus status; - ModestMailOperationQueue *queue = NULL; - g_print ("Refreshed %d of %d\n", modest_mail_operation_get_task_done (mail_op), modest_mail_operation_get_task_total (mail_op)); - if (modest_mail_operation_is_finished (mail_op)) { - queue = MODEST_MAIL_OPERATION_QUEUE (user_data); - modest_mail_operation_queue_remove (queue, mail_op); +} + +static void +update_account_cb (ModestMailOperation *self, + TnyList *new_headers, + gpointer userdata) +{ + ModestMailOperationQueue *queue; + + if (modest_mail_operation_get_error (self)) + retval = 1; + + if (modest_mail_operation_is_finished (self)) { + queue = MODEST_MAIL_OPERATION_QUEUE (userdata); + modest_mail_operation_queue_remove (queue, self); g_main_loop_quit (main_loop); } + } static gboolean func (gpointer_data) { - TnyStoreAccount *account; - TnyIterator *iter; - TnyPlatformFactory *fact = NULL; + TnyStoreAccount *account = NULL; ModestAccountMgr *acc_mgr = NULL; ModestMailOperation *mail_op = NULL; ModestMailOperationQueue *queue = NULL; - TnyAccountStore *account_store = NULL; - TnyList *accounts; - - fact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance ()); - acc_mgr = MODEST_ACCOUNT_MGR (modest_tny_platform_factory_get_modest_account_mgr_instance (fact)); - account_store = tny_platform_factory_new_account_store (fact); - - /* Get accounts */ - accounts = tny_simple_list_new (); - tny_account_store_get_accounts (account_store, accounts, - TNY_ACCOUNT_STORE_STORE_ACCOUNTS); - - iter = tny_list_create_iterator (accounts); - account = TNY_STORE_ACCOUNT (tny_iterator_get_current (iter)); + modest_init (0, NULL); - g_object_unref (G_OBJECT (iter)); - g_object_unref (G_OBJECT (accounts)); + acc_mgr = modest_runtime_get_account_mgr(); - queue = modest_mail_operation_queue_get_instance (); - mail_op = modest_mail_operation_new (); + queue = modest_runtime_get_mail_operation_queue (); + mail_op = modest_mail_operation_new (NULL); g_signal_connect (G_OBJECT (mail_op), "progress_changed", G_CALLBACK (on_progress_changed), queue); - if (modest_mail_operation_update_account (mail_op, account)) - modest_mail_operation_queue_add (queue, mail_op); + modest_mail_operation_update_account (mail_op, modest_account_mgr_get_default_account (acc_mgr), + TRUE, FALSE, update_account_cb, queue); + modest_mail_operation_queue_add (queue, mail_op); g_object_unref (G_OBJECT (mail_op)); + + if (account) + g_object_unref (account); + + return FALSE; +} + +static gboolean +got_timeout (gpointer userdata) +{ + retval = 1; + g_main_loop_quit (main_loop); return FALSE; } @@ -114,9 +127,10 @@ main (int argc, char **argv) g_thread_init(NULL); main_loop = g_main_loop_new (NULL, FALSE); - id = g_timeout_add(1000, func, main_loop); + id = g_timeout_add(10, func, main_loop); + g_timeout_add_seconds (TEST_TIMEOUT, got_timeout, NULL); g_main_loop_run(main_loop); - return 0; + return retval; }