Change scroll readjustment management in msg view.
[modest] / tests / check_update-account.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <glib.h>
31 #include <string.h>
32 #include <unistd.h>
33
34 #include <tny-list.h>
35 #include <tny-iterator.h>
36 #include <tny-simple-list.h>
37 #include <tny-account-store.h>
38 #include <tny-store-account.h>
39 #include <tny-folder.h>
40 #include <tny-folder-store.h>
41
42 #include <modest-runtime.h>
43 #include "modest-account-mgr.h"
44 #include "modest-mail-operation.h"
45 #include "modest-mail-operation-queue.h"
46 #include <modest-init.h>
47 #include <modest-tny-account.h>
48
49 /* seconds we will wait for test to finish */
50 #define TEST_TIMEOUT 60
51
52 GMainLoop *main_loop;
53 gint retval = 0;
54
55 static void
56 on_progress_changed (ModestMailOperation *mail_op, ModestMailOperationState *state, gpointer user_data)
57 {
58         g_print ("Refreshed %d of %d\n", 
59                  modest_mail_operation_get_task_done  (mail_op), 
60                  modest_mail_operation_get_task_total (mail_op));
61
62 }
63
64 static void
65 update_account_cb (ModestMailOperation *self,
66                    TnyList *new_headers,
67                    gpointer userdata)
68 {
69         ModestMailOperationQueue *queue;
70
71         if (modest_mail_operation_get_error (self))
72                 retval = 1;
73         
74         if (modest_mail_operation_is_finished (self)) {
75                 queue = MODEST_MAIL_OPERATION_QUEUE (userdata);
76                 modest_mail_operation_queue_remove (queue, self);
77                 g_main_loop_quit (main_loop);
78         }
79
80 }
81
82 static gboolean
83 func (gpointer_data) 
84 {
85         TnyStoreAccount *account = NULL;
86         ModestAccountMgr *acc_mgr = NULL;
87         ModestMailOperation *mail_op = NULL;
88         ModestMailOperationQueue *queue = NULL;
89
90         modest_init (0, NULL);
91
92         acc_mgr       = modest_runtime_get_account_mgr();
93
94         queue   = modest_runtime_get_mail_operation_queue ();
95         mail_op = modest_mail_operation_new (NULL);
96         
97         g_signal_connect (G_OBJECT (mail_op), "progress_changed", 
98                           G_CALLBACK (on_progress_changed), queue);
99
100         modest_mail_operation_update_account (mail_op, modest_account_mgr_get_default_account (acc_mgr),
101                                               TRUE, FALSE, NULL, update_account_cb, queue);
102         modest_mail_operation_queue_add (queue, mail_op);
103
104         g_object_unref (G_OBJECT (mail_op));
105         
106         if (account)
107                 g_object_unref (account);
108
109         return FALSE;
110 }
111
112 static gboolean 
113 got_timeout (gpointer userdata)
114 {
115         retval = 1;
116
117         g_main_loop_quit (main_loop);
118         return FALSE;
119 }
120
121 int
122 main (int argc, char **argv)
123 {   
124         guint id;
125
126         g_type_init ();
127         g_thread_init(NULL);
128
129         main_loop = g_main_loop_new (NULL, FALSE);
130         id = g_timeout_add(10, func, main_loop);
131         g_timeout_add_seconds (TEST_TIMEOUT, got_timeout, NULL);
132
133         g_main_loop_run(main_loop);
134
135         return retval;
136 }