1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
32 #include <modest-conf.h>
33 #include <modest-account-mgr.h>
34 #include <modest-protocol-info.h>
36 /* ----------------------- Defines ---------------------- */
38 #define TEST_MODEST_ACCOUNT_NAME "modest-unit-tests-àccount"
40 /* ------------------ Global variables ------------------ */
42 static ModestAccountMgr *account_mgr = NULL;
44 /* ---------------------- Fixtures --------------------- */
47 fx_setup_default_account_mgr ()
49 ModestConf *conf = NULL;
53 conf = modest_conf_new ();
54 fail_unless (MODEST_IS_CONF (conf),
55 "modest_conf_new failed");
57 account_mgr = modest_account_mgr_new (conf);
58 fail_unless (MODEST_IS_ACCOUNT_MGR (account_mgr),
59 "modest_account_mgr_new failed");
61 /* cleanup old garbage (from previous runs)*/
62 if (modest_account_mgr_account_exists(account_mgr,
63 TEST_MODEST_ACCOUNT_NAME,
65 modest_account_mgr_remove_account (account_mgr,
66 TEST_MODEST_ACCOUNT_NAME,
68 if (modest_account_mgr_account_exists(account_mgr,
69 TEST_MODEST_ACCOUNT_NAME,
71 modest_account_mgr_remove_account (account_mgr,
72 TEST_MODEST_ACCOUNT_NAME,
77 fx_teardown_default_account_mgr ()
79 g_object_unref (account_mgr);
82 /* ---------- add/exists/remove account tests ---------- */
85 * Test regular usage of
86 * modest_account_mgr_add_account
87 * modest_account_mgr_add_server_account
88 * modest_account_mgr_account_exists
89 * modest_account_mgr_remove_account
90 * - Test 1: Create anaccount
91 * - Test 2: Check account exists
92 * - Test 3: Remove account
93 * - Test 4: Create a server account
94 * - Test 5: Check server account exists
95 * - Test 6: Remove server account
96 * - Test 7: Check if a non-existing account exists
97 * - Test 8: Check if a non-existing server account exists
99 START_TEST (test_add_exists_remove_account_regular)
102 gchar *store_account = NULL;
103 gchar *transport_account = NULL;
104 gchar *hostname = NULL;
105 gchar *username = NULL;
106 gchar *password = NULL;
107 ModestProtocol proto;
110 name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
112 store_account = g_strdup ("imap://me@myserver");
113 transport_account = g_strdup ("local-smtp");
114 result = modest_account_mgr_add_account (account_mgr,
119 "modest_account_mgr_add_account failed:\n" \
120 "name: %s\nstore: %s\ntransport: %s\n",
121 name, store_account, transport_account);
123 g_free (store_account);
124 g_free (transport_account);
127 result = modest_account_mgr_account_exists (account_mgr,
131 "modest_account_mgr_account_exists failed: " \
132 "Account with name \"%s\" should exist.\n", name);
136 result = modest_account_mgr_remove_account (account_mgr,
140 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
145 hostname = g_strdup ("myhostname.mydomain.com");
146 username = g_strdup ("myusername");
147 password = g_strdup ("mypassword");
148 proto = MODEST_PROTOCOL_TRANSPORT_SMTP;
149 result = modest_account_mgr_add_server_account (account_mgr,
156 "modest_account_mgr_add_server_account failed:\n" \
157 "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
158 name, hostname, username, password, proto);
165 result = modest_account_mgr_account_exists (account_mgr,name,TRUE);
167 "modest_account_mgr_account_exists failed: " \
168 "Server account with name \"%s\" should exist. Error: %s", name);
171 result = modest_account_mgr_remove_account (account_mgr,
175 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
180 result = modest_account_mgr_account_exists (account_mgr,
181 "a_name_that_does_not_exist",
184 "modest_account_mgr_exists_account does not return " \
185 "FALSE when passing an account that does not exist");
188 result = modest_account_mgr_account_exists (account_mgr,
189 "a_name_that_does_not_exist",
192 "modest_account_mgr_exists_account does not return " \
193 "FALSE when passing a server account that does not exist");
200 * Test regular usage of
201 * modest_account_mgr_add_account,
202 * modest_account_mgr_add_server_account
203 * modest_account_mgr_account_exists
204 * modest_account_mgr_remove_account
205 * - Test 1: Create account with NULL account_mgr
206 * - Test 2: Create account with NULL name
207 * - Test 3: Create account with invalid name string
208 * - Test 4: Create server account with NULL account_mgr
209 * - Test 5: Create server account with NULL name
210 * - Test 6: Create server account with invalid name string
211 * - Test 7: Remove a non-existing account
212 * - Test 8: Remove a non-existing server account
213 * - Test 9: Remove with NULL acount manager
214 * - Test 10: Remove with NULL name
215 * - Test 11: Check if an account exists with NULL account_mgr
216 * - Test 12: Check if a server account exists with a NULL account_mgr
217 * - Test 13: Check if a NULL account exists
218 * - Test 14: Check if a NULL server account exists
220 START_TEST (test_add_exists_remove_account_invalid)
225 result = modest_account_mgr_add_account (NULL,
226 TEST_MODEST_ACCOUNT_NAME,
228 "transport_account");
229 fail_unless (!result,
230 "modest_account_mgr_add_account does not return FALSE when" \
231 "passing a NULL ModestAccountMgr");
234 result = modest_account_mgr_add_account (account_mgr,
237 "transport_account");
238 fail_unless (!result,
239 "modest_account_mgr_add_account does not return FALSE when" \
240 "passing a NULL account name");
243 result = modest_account_mgr_add_account (account_mgr,
244 "ïnválid//accountñ//nÄméç",
246 "transport_account");
247 fail_unless (!result,
248 "modest_account_mgr_add_account does not return FALSE when" \
249 "passing an invalid account name");
252 result = modest_account_mgr_add_server_account (NULL,
253 TEST_MODEST_ACCOUNT_NAME,
257 MODEST_PROTOCOL_STORE_IMAP);
258 fail_unless (!result,
259 "modest_account_mgr_add_server_account does not return " \
260 "FALSE when passing a NULL ModestAccountMgr");
263 result = modest_account_mgr_add_server_account (account_mgr,
268 MODEST_PROTOCOL_STORE_IMAP);
269 fail_unless (!result,
270 "modest_account_mgr_add_server_account does not return " \
271 "FALSE when passing a NULL account name");
274 result = modest_account_mgr_add_server_account (account_mgr,
275 "ïnválid//accountñ//nÄméç",
279 MODEST_PROTOCOL_STORE_IMAP);
280 fail_unless (!result,
281 "modest_account_mgr_add_server_account does not return " \
282 "FALSE when passing an invalid account name");
285 result = modest_account_mgr_remove_account (account_mgr,
286 "a_name_that_does_not_exist",
288 fail_unless (!result,
289 "modest_account_mgr_remove_acccount does not return FALSE " \
290 "when trying to remove an account that does not exist");
293 result = modest_account_mgr_remove_account (account_mgr,
294 "a_name_that_does_not_exist",
296 fail_unless (!result,
297 "modest_account_mgr_remove_acccount does not return FALSE " \
298 "when trying to remove a server account that does not exist");
301 result = modest_account_mgr_remove_account (NULL,
302 TEST_MODEST_ACCOUNT_NAME,
304 fail_unless (!result,
305 "modest_account_mgr_remove_acccount does not return " \
306 "FALSE when passing a NULL ModestAccountMgr");
309 result = modest_account_mgr_remove_account (account_mgr,
312 fail_unless (!result,
313 "modest_account_mgr_remove_acccount does not return " \
314 "FALSE when passing a NULL account name");
317 result = modest_account_mgr_account_exists (NULL,
318 TEST_MODEST_ACCOUNT_NAME,
320 fail_unless (!result,
321 "modest_account_mgr_exists_account does not return " \
322 "FALSE when passing a NULL ModestAccountMgr");
325 result = modest_account_mgr_account_exists (NULL,
326 TEST_MODEST_ACCOUNT_NAME,
328 fail_unless (!result,
329 "modest_account_mgr_exists_account does not return " \
330 "FALSE when passing a NULL ModestAccountMgr");
333 result = modest_account_mgr_account_exists (account_mgr,
336 fail_unless (!result,
337 "modest_account_mgr_exists_acccount does not return " \
338 "FALSE when passing a NULL account name");
341 result = modest_account_mgr_account_exists (account_mgr,
344 fail_unless (!result,
345 "modest_account_mgr_exists_account does not return " \
346 "FALSE when passing a NULL server account name");
350 /* ------------------- Suite creation ------------------- */
353 account_mgr_suite (void)
355 Suite *suite = suite_create ("ModestAccountMgr");
358 /* Tests case for "add/exists/remove account" */
359 tc = tcase_create ("add_exists_remove_account");
360 tcase_add_checked_fixture (tc,
361 fx_setup_default_account_mgr,
362 fx_teardown_default_account_mgr);
363 tcase_add_test (tc, test_add_exists_remove_account_regular);
364 tcase_add_test (tc, test_add_exists_remove_account_invalid);
365 suite_add_tcase (suite, tc);
370 /* --------------------- Main program ------------------- */
379 suite = account_mgr_suite ();
380 srunner = srunner_create (suite);
382 srunner_run_all (srunner, CK_ENV);
383 failures = srunner_ntests_failed (srunner);
384 srunner_free (srunner);