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>
35 /* ----------------------- Defines ---------------------- */
37 #define TEST_MODEST_ACCOUNT_NAME "modest-unit-tests-àccount"
39 /* ------------------ Global variables ------------------ */
41 static ModestAccountMgr *account_mgr = NULL;
43 /* ---------------------- Fixtures --------------------- */
46 fx_setup_default_account_mgr ()
48 ModestConf *conf = NULL;
52 conf = modest_conf_new ();
53 fail_unless (MODEST_IS_CONF (conf),
54 "modest_conf_new failed");
56 account_mgr = modest_account_mgr_new (conf);
57 fail_unless (MODEST_IS_ACCOUNT_MGR (account_mgr),
58 "modest_account_mgr_new failed");
60 /* cleanup old garbage (from previous runs)*/
61 if (modest_account_mgr_account_exists(account_mgr,
62 TEST_MODEST_ACCOUNT_NAME,
64 modest_account_mgr_remove_account (account_mgr,
65 TEST_MODEST_ACCOUNT_NAME);
66 if (modest_account_mgr_account_exists(account_mgr,
67 TEST_MODEST_ACCOUNT_NAME,
69 modest_account_mgr_remove_account (account_mgr,
70 TEST_MODEST_ACCOUNT_NAME);
74 fx_teardown_default_account_mgr ()
76 g_object_unref (account_mgr);
79 /* ---------- add/exists/remove account tests ---------- */
82 * Test regular usage of
83 * modest_account_mgr_add_account
84 * modest_account_mgr_add_server_account
85 * modest_account_mgr_account_exists
86 * modest_account_mgr_remove_account
87 * - Test 1: Create anaccount
88 * - Test 2: Check account exists
89 * - Test 3: Remove account
90 * - Test 4: Create a server account
91 * - Test 5: Check server account exists
92 * - Test 6: Remove server account
93 * - Test 7: Check if a non-existing account exists
94 * - Test 8: Check if a non-existing server account exists
96 START_TEST (test_add_exists_remove_account_regular)
99 gchar *store_account = NULL;
100 gchar *transport_account = NULL;
101 gchar *hostname = NULL;
102 gchar *username = NULL;
103 gchar *password = NULL;
105 ModestProtocolType proto;
108 name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
110 store_account = g_strdup ("imap://me@myserver");
111 transport_account = g_strdup ("local-smtp");
112 result = modest_account_mgr_add_account (account_mgr,
117 MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY,
119 transport_account, TRUE);
121 "modest_account_mgr_add_account failed:\n" \
122 "name: %s\nstore: %s\ntransport: %s\n",
123 name, store_account, transport_account, TRUE);
125 g_free (store_account);
126 g_free (transport_account);
129 result = modest_account_mgr_account_exists (account_mgr,
133 "modest_account_mgr_account_exists failed: " \
134 "Account with name \"%s\" should exist.\n", name);
138 result = modest_account_mgr_remove_account (account_mgr,
141 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
146 hostname = g_strdup ("myhostname.mydomain.com");
147 username = g_strdup ("myusername");
148 password = g_strdup ("mypassword");
149 proto = MODEST_PROTOCOLS_TRANSPORT_SMTP;
151 result = modest_account_mgr_add_server_account (account_mgr,
158 MODEST_PROTOCOLS_CONNECTION_NONE,
159 MODEST_PROTOCOLS_AUTH_NONE);
161 "modest_account_mgr_add_server_account failed:\n" \
162 "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
163 name, hostname, username, password, proto);
170 result = modest_account_mgr_account_exists (account_mgr,name,TRUE);
172 "modest_account_mgr_account_exists failed: " \
173 "Server account with name \"%s\" should exist. Error: %s", name);
176 result = modest_account_mgr_remove_account (account_mgr,
179 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
184 result = modest_account_mgr_account_exists (account_mgr,
185 "a_name_that_does_not_exist",
188 "modest_account_mgr_exists_account does not return " \
189 "FALSE when passing an account that does not exist");
192 result = modest_account_mgr_account_exists (account_mgr,
193 "a_name_that_does_not_exist",
196 "modest_account_mgr_exists_account does not return " \
197 "FALSE when passing a server account that does not exist");
204 * Test regular usage of
205 * modest_account_mgr_add_account,
206 * modest_account_mgr_add_server_account
207 * modest_account_mgr_account_exists
208 * modest_account_mgr_remove_account
209 * - Test 1: Create account with NULL account_mgr
210 * - Test 2: Create account with NULL name
211 * - Test 3: Create account with invalid name string
212 * - Test 4: Create server account with NULL account_mgr
213 * - Test 5: Create server account with NULL name
214 * - Test 6: Create server account with invalid name string
215 * - Test 7: Remove a non-existing account
216 * - Test 8: Remove a non-existing server account (REMOVED)
217 * - Test 9: Remove with NULL acount manager
218 * - Test 10: Remove with NULL name
219 * - Test 11: Check if an account exists with NULL account_mgr
220 * - Test 12: Check if a server account exists with a NULL account_mgr
221 * - Test 13: Check if a NULL account exists
222 * - Test 14: Check if a NULL server account exists
224 START_TEST (test_add_exists_remove_account_invalid)
229 result = modest_account_mgr_add_account (NULL,
230 TEST_MODEST_ACCOUNT_NAME,
234 MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY,
236 "transport_account", TRUE);
237 fail_unless (!result,
238 "modest_account_mgr_add_account does not return FALSE when" \
239 "passing a NULL ModestAccountMgr");
242 result = modest_account_mgr_add_account (account_mgr,
247 MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY,
249 "transport_account", TRUE);
250 fail_unless (!result,
251 "modest_account_mgr_add_account does not return FALSE when" \
252 "passing a NULL account name");
255 result = modest_account_mgr_add_account (account_mgr,
256 "ïnválid//accountñ//nÄméç",
260 MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY,
262 "transport_account", TRUE);
263 fail_unless (!result,
264 "modest_account_mgr_add_account does not return FALSE when" \
265 "passing an invalid account name");
268 result = modest_account_mgr_add_server_account (NULL,
269 TEST_MODEST_ACCOUNT_NAME,
274 MODEST_PROTOCOLS_STORE_IMAP,
275 MODEST_PROTOCOLS_CONNECTION_NONE,
276 MODEST_PROTOCOLS_AUTH_NONE);
277 fail_unless (!result,
278 "modest_account_mgr_add_server_account does not return " \
279 "FALSE when passing a NULL ModestAccountMgr");
282 result = modest_account_mgr_add_server_account (account_mgr,
288 MODEST_PROTOCOLS_STORE_IMAP,
289 MODEST_PROTOCOLS_CONNECTION_NONE,
290 MODEST_PROTOCOLS_AUTH_NONE);
291 fail_unless (!result,
292 "modest_account_mgr_add_server_account does not return " \
293 "FALSE when passing a NULL account name");
296 result = modest_account_mgr_add_server_account (account_mgr,
297 "ïnválid//accountñ//nÄméç",
302 MODEST_PROTOCOLS_STORE_IMAP,
303 MODEST_PROTOCOLS_CONNECTION_NONE,
304 MODEST_PROTOCOLS_AUTH_NONE);
305 fail_unless (!result,
306 "modest_account_mgr_add_server_account does not return " \
307 "FALSE when passing an invalid account name");
310 result = modest_account_mgr_remove_account (account_mgr,
311 "a_name_that_does_not_exist");
312 fail_unless (!result,
313 "modest_account_mgr_remove_acccount does not return FALSE " \
314 "when trying to remove an account that does not exist");
317 result = modest_account_mgr_remove_account (NULL,
318 TEST_MODEST_ACCOUNT_NAME);
319 fail_unless (!result,
320 "modest_account_mgr_remove_acccount does not return " \
321 "FALSE when passing a NULL ModestAccountMgr");
324 result = modest_account_mgr_remove_account (account_mgr,
326 fail_unless (!result,
327 "modest_account_mgr_remove_acccount does not return " \
328 "FALSE when passing a NULL account name");
331 result = modest_account_mgr_account_exists (NULL,
332 TEST_MODEST_ACCOUNT_NAME,
334 fail_unless (!result,
335 "modest_account_mgr_exists_account does not return " \
336 "FALSE when passing a NULL ModestAccountMgr");
339 result = modest_account_mgr_account_exists (NULL,
340 TEST_MODEST_ACCOUNT_NAME,
342 fail_unless (!result,
343 "modest_account_mgr_exists_account does not return " \
344 "FALSE when passing a NULL ModestAccountMgr");
347 result = modest_account_mgr_account_exists (account_mgr,
350 fail_unless (!result,
351 "modest_account_mgr_exists_acccount does not return " \
352 "FALSE when passing a NULL account name");
355 result = modest_account_mgr_account_exists (account_mgr,
358 fail_unless (!result,
359 "modest_account_mgr_exists_account does not return " \
360 "FALSE when passing a NULL server account name");
364 /* ------------------- Suite creation ------------------- */
367 account_mgr_suite (void)
369 Suite *suite = suite_create ("ModestAccountMgr");
372 /* Tests case for "add/exists/remove account" */
373 tc = tcase_create ("add_exists_remove_account");
374 tcase_add_checked_fixture (tc,
375 fx_setup_default_account_mgr,
376 fx_teardown_default_account_mgr);
377 tcase_add_test (tc, test_add_exists_remove_account_regular);
378 tcase_add_test (tc, test_add_exists_remove_account_invalid);
379 suite_add_tcase (suite, tc);
384 /* --------------------- Main program ------------------- */
393 suite = account_mgr_suite ();
394 srunner = srunner_create (suite);
396 srunner_run_all (srunner, CK_ENV);
397 failures = srunner_ntests_failed (srunner);
398 srunner_free (srunner);