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,
117 transport_account, TRUE);
119 "modest_account_mgr_add_account failed:\n" \
120 "name: %s\nstore: %s\ntransport: %s\n",
121 name, store_account, transport_account, TRUE);
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,
155 MODEST_PROTOCOL_SECURITY_NONE,
156 MODEST_PROTOCOL_AUTH_NONE);
158 "modest_account_mgr_add_server_account failed:\n" \
159 "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
160 name, hostname, username, password, proto);
167 result = modest_account_mgr_account_exists (account_mgr,name,TRUE);
169 "modest_account_mgr_account_exists failed: " \
170 "Server account with name \"%s\" should exist. Error: %s", name);
173 result = modest_account_mgr_remove_account (account_mgr,
177 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
182 result = modest_account_mgr_account_exists (account_mgr,
183 "a_name_that_does_not_exist",
186 "modest_account_mgr_exists_account does not return " \
187 "FALSE when passing an account that does not exist");
190 result = modest_account_mgr_account_exists (account_mgr,
191 "a_name_that_does_not_exist",
194 "modest_account_mgr_exists_account does not return " \
195 "FALSE when passing a server account that does not exist");
202 * Test regular usage of
203 * modest_account_mgr_add_account,
204 * modest_account_mgr_add_server_account
205 * modest_account_mgr_account_exists
206 * modest_account_mgr_remove_account
207 * - Test 1: Create account with NULL account_mgr
208 * - Test 2: Create account with NULL name
209 * - Test 3: Create account with invalid name string
210 * - Test 4: Create server account with NULL account_mgr
211 * - Test 5: Create server account with NULL name
212 * - Test 6: Create server account with invalid name string
213 * - Test 7: Remove a non-existing account
214 * - Test 8: Remove a non-existing server account
215 * - Test 9: Remove with NULL acount manager
216 * - Test 10: Remove with NULL name
217 * - Test 11: Check if an account exists with NULL account_mgr
218 * - Test 12: Check if a server account exists with a NULL account_mgr
219 * - Test 13: Check if a NULL account exists
220 * - Test 14: Check if a NULL server account exists
222 START_TEST (test_add_exists_remove_account_invalid)
227 result = modest_account_mgr_add_account (NULL,
228 TEST_MODEST_ACCOUNT_NAME,
230 "transport_account", TRUE);
231 fail_unless (!result,
232 "modest_account_mgr_add_account does not return FALSE when" \
233 "passing a NULL ModestAccountMgr");
236 result = modest_account_mgr_add_account (account_mgr,
239 "transport_account", TRUE);
240 fail_unless (!result,
241 "modest_account_mgr_add_account does not return FALSE when" \
242 "passing a NULL account name");
245 result = modest_account_mgr_add_account (account_mgr,
246 "ïnválid//accountñ//nÄméç",
248 "transport_account", TRUE);
249 fail_unless (!result,
250 "modest_account_mgr_add_account does not return FALSE when" \
251 "passing an invalid account name");
254 result = modest_account_mgr_add_server_account (NULL,
255 TEST_MODEST_ACCOUNT_NAME,
259 MODEST_PROTOCOL_STORE_IMAP,
260 MODEST_PROTOCOL_SECURITY_NONE,
261 MODEST_PROTOCOL_AUTH_NONE);
262 fail_unless (!result,
263 "modest_account_mgr_add_server_account does not return " \
264 "FALSE when passing a NULL ModestAccountMgr");
267 result = modest_account_mgr_add_server_account (account_mgr,
272 MODEST_PROTOCOL_STORE_IMAP,
273 MODEST_PROTOCOL_SECURITY_NONE,
274 MODEST_PROTOCOL_AUTH_NONE);
275 fail_unless (!result,
276 "modest_account_mgr_add_server_account does not return " \
277 "FALSE when passing a NULL account name");
280 result = modest_account_mgr_add_server_account (account_mgr,
281 "ïnválid//accountñ//nÄméç",
285 MODEST_PROTOCOL_STORE_IMAP,
286 MODEST_PROTOCOL_SECURITY_NONE,
287 MODEST_PROTOCOL_AUTH_NONE);
288 fail_unless (!result,
289 "modest_account_mgr_add_server_account does not return " \
290 "FALSE when passing an invalid account name");
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 an account that does not exist");
301 result = modest_account_mgr_remove_account (account_mgr,
302 "a_name_that_does_not_exist",
304 fail_unless (!result,
305 "modest_account_mgr_remove_acccount does not return FALSE " \
306 "when trying to remove a server account that does not exist");
309 result = modest_account_mgr_remove_account (NULL,
310 TEST_MODEST_ACCOUNT_NAME,
312 fail_unless (!result,
313 "modest_account_mgr_remove_acccount does not return " \
314 "FALSE when passing a NULL ModestAccountMgr");
317 result = modest_account_mgr_remove_account (account_mgr,
320 fail_unless (!result,
321 "modest_account_mgr_remove_acccount does not return " \
322 "FALSE when passing a NULL account name");
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 (NULL,
334 TEST_MODEST_ACCOUNT_NAME,
336 fail_unless (!result,
337 "modest_account_mgr_exists_account does not return " \
338 "FALSE when passing a NULL ModestAccountMgr");
341 result = modest_account_mgr_account_exists (account_mgr,
344 fail_unless (!result,
345 "modest_account_mgr_exists_acccount does not return " \
346 "FALSE when passing a NULL account name");
349 result = modest_account_mgr_account_exists (account_mgr,
352 fail_unless (!result,
353 "modest_account_mgr_exists_account does not return " \
354 "FALSE when passing a NULL server account name");
358 /* ------------------- Suite creation ------------------- */
361 account_mgr_suite (void)
363 Suite *suite = suite_create ("ModestAccountMgr");
366 /* Tests case for "add/exists/remove account" */
367 tc = tcase_create ("add_exists_remove_account");
368 tcase_add_checked_fixture (tc,
369 fx_setup_default_account_mgr,
370 fx_teardown_default_account_mgr);
371 tcase_add_test (tc, test_add_exists_remove_account_regular);
372 tcase_add_test (tc, test_add_exists_remove_account_invalid);
373 suite_add_tcase (suite, tc);
378 /* --------------------- Main program ------------------- */
387 suite = account_mgr_suite ();
388 srunner = srunner_create (suite);
390 srunner_run_all (srunner, CK_ENV);
391 failures = srunner_ntests_failed (srunner);
392 srunner_free (srunner);