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");
62 fx_teardown_default_account_mgr ()
64 g_object_unref (account_mgr);
67 /* ---------- add/exists/remove account tests ---------- */
70 * Test regular usage of
71 * modest_account_mgr_add_account
72 * modest_account_mgr_add_server_account
73 * modest_account_mgr_account_exists
74 * modest_account_mgr_remove_account
75 * - Test 1: Create anaccount
76 * - Test 2: Check account exists
77 * - Test 3: Remove account
78 * - Test 4: Create a server account
79 * - Test 5: Check server account exists
80 * - Test 6: Remove server account
81 * - Test 7: Check if a non-existing account exists
82 * - Test 8: Check if a non-existing server account exists
84 START_TEST (test_add_exists_remove_account_regular)
87 gchar *store_account = NULL;
88 gchar *transport_account = NULL;
89 gchar *hostname = NULL;
90 gchar *username = NULL;
91 gchar *password = NULL;
96 name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
99 store_account = g_strdup ("imap://me@myserver");
100 transport_account = g_strdup ("local-smtp");
101 result = modest_account_mgr_add_account (account_mgr,
106 fail_unless (result && !error,
107 "modest_account_mgr_add_account failed:\n" \
108 "name: %s\nstore: %s\ntransport: %s\nerror: %s",
109 name, store_account, transport_account,
110 error ? error->message : "");
112 g_free (store_account);
113 g_free (transport_account);
116 result = modest_account_mgr_account_exists (account_mgr,
120 fail_unless (result && !error,
121 "modest_account_mgr_account_exists failed: " \
122 "Account with name \"%s\" should exist. Error: %s",
123 name, error ? error->message : "");
127 result = modest_account_mgr_remove_account (account_mgr,
131 fail_unless (result && !error,
132 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
133 name, error ? error->message : "");
136 hostname = g_strdup ("myhostname.mydomain.com");
137 username = g_strdup ("myusername");
138 password = g_strdup ("mypassword");
139 proto = g_strdup ("smtp");
140 result = modest_account_mgr_add_server_account (account_mgr,
147 "modest_account_mgr_add_server_account failed:\n" \
148 "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
149 name, hostname, username, password, proto);
157 result = modest_account_mgr_account_exists (account_mgr,
161 fail_unless (result && !error,
162 "modest_account_mgr_account_exists failed: " \
163 "Server account with name \"%s\" should exist. Error: %s",
164 name, error ? error->message : "");
168 result = modest_account_mgr_remove_account (account_mgr,
172 fail_unless (result && !error,
173 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
174 name, error ? error->message : "");
178 result = modest_account_mgr_account_exists (account_mgr,
179 "a_name_that_does_not_exist",
182 fail_unless (!result,
183 "modest_account_mgr_exists_account does not return " \
184 "FALSE when passing an account that does not exist");
187 result = modest_account_mgr_account_exists (account_mgr,
188 "a_name_that_does_not_exist",
191 fail_unless (!result,
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,
230 fail_unless (!result,
231 "modest_account_mgr_add_account does not return FALSE when" \
232 "passing a NULL ModestAccountMgr");
235 result = modest_account_mgr_add_account (account_mgr,
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éç",
250 fail_unless (!result,
251 "modest_account_mgr_add_account does not return FALSE when" \
252 "passing an invalid account name");
255 result = modest_account_mgr_add_server_account (NULL,
256 TEST_MODEST_ACCOUNT_NAME,
261 fail_unless (!result,
262 "modest_account_mgr_add_server_account does not return " \
263 "FALSE when passing a NULL ModestAccountMgr");
266 result = modest_account_mgr_add_server_account (account_mgr,
272 fail_unless (!result,
273 "modest_account_mgr_add_server_account does not return " \
274 "FALSE when passing a NULL account name");
277 result = modest_account_mgr_add_server_account (account_mgr,
278 "ïnválid//accountñ//nÄméç",
283 fail_unless (!result,
284 "modest_account_mgr_add_server_account does not return " \
285 "FALSE when passing an invalid account name");
288 result = modest_account_mgr_remove_account (account_mgr,
289 "a_name_that_does_not_exist",
292 fail_unless (!result,
293 "modest_account_mgr_remove_acccount does not return FALSE " \
294 "when trying to remove an account that does not exist");
297 result = modest_account_mgr_remove_account (account_mgr,
298 "a_name_that_does_not_exist",
301 fail_unless (!result,
302 "modest_account_mgr_remove_acccount does not return FALSE " \
303 "when trying to remove a server account that does not exist");
306 result = modest_account_mgr_remove_account (NULL,
307 TEST_MODEST_ACCOUNT_NAME,
310 fail_unless (!result,
311 "modest_account_mgr_remove_acccount does not return " \
312 "FALSE when passing a NULL ModestAccountMgr");
315 result = modest_account_mgr_remove_account (account_mgr,
319 fail_unless (!result,
320 "modest_account_mgr_remove_acccount does not return " \
321 "FALSE when passing a NULL account name");
324 result = modest_account_mgr_account_exists (NULL,
325 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,
337 fail_unless (!result,
338 "modest_account_mgr_exists_account does not return " \
339 "FALSE when passing a NULL ModestAccountMgr");
342 result = modest_account_mgr_account_exists (account_mgr,
346 fail_unless (!result,
347 "modest_account_mgr_exists_acccount does not return " \
348 "FALSE when passing a NULL account name");
351 result = modest_account_mgr_account_exists (account_mgr,
355 fail_unless (!result,
356 "modest_account_mgr_exists_account does not return " \
357 "FALSE when passing a NULL server account name");
361 /* ------------------- Suite creation ------------------- */
364 account_mgr_suite (void)
366 Suite *suite = suite_create ("ModestAccountMgr");
369 /* Tests case for "add/exists/remove account" */
370 tc = tcase_create ("add_exists_remove_account");
371 tcase_add_checked_fixture (tc,
372 fx_setup_default_account_mgr,
373 fx_teardown_default_account_mgr);
374 tcase_add_test (tc, test_add_exists_remove_account_regular);
375 tcase_add_test (tc, test_add_exists_remove_account_invalid);
376 suite_add_tcase (suite, tc);
381 /* --------------------- Main program ------------------- */
390 suite = account_mgr_suite ();
391 srunner = srunner_create (suite);
393 srunner_run_all (srunner, CK_ENV);
394 failures = srunner_ntests_failed (srunner);
395 srunner_free (srunner);