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-account"
39 /* ------------------ Global variables ------------------ */
41 static ModestAccountMgr *account_mgr = NULL;
43 /* ---------------------- Fixtures --------------------- */
46 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");
63 fx_teardown_default_account_mgr ()
65 g_object_unref (account_mgr);
68 /* ---------- add/exists/remove account tests ---------- */
71 * Test regular usage of
72 * modest_account_mgr_add_account
73 * modest_account_mgr_add_server_account
74 * modest_account_mgr_account_exists
75 * modest_account_mgr_remove_account
76 * - Test 1: Create anaccount
77 * - Test 2: Check account exists
78 * - Test 3: Remove account
79 * - Test 4: Create a server account
80 * - Test 5: Check server account exists
81 * - Test 6: Remove server account
82 * - Test 7: Check if a non-existing account exists
83 * - Test 8: Check if a non-existing server account exists
85 START_TEST (test_add_exists_remove_account_regular)
88 gchar *store_account = NULL;
89 gchar *transport_account = NULL;
90 gchar *hostname = NULL;
91 gchar *username = NULL;
92 gchar *password = NULL;
97 name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
100 store_account = g_strdup ("imap://me@myserver");
101 transport_account = g_strdup ("local-smtp");
102 result = modest_account_mgr_add_account (account_mgr,
107 fail_unless (result && !error,
108 "modest_account_mgr_add_account failed:\n" \
109 "name: %s\nstore: %s\ntransport: %s\nerror: %s",
110 name, store_account, transport_account,
111 error ? error->message : "");
113 g_free (store_account);
114 g_free (transport_account);
117 result = modest_account_mgr_account_exists (account_mgr,
121 fail_unless (result && !error,
122 "modest_account_mgr_account_exists failed: " \
123 "Account with name \"%s\" should exist. Error: %s",
124 name, error ? error->message : "");
128 result = modest_account_mgr_remove_account (account_mgr,
132 fail_unless (result && !error,
133 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
134 name, error ? error->message : "");
137 hostname = g_strdup ("myhostname.mydomain.com");
138 username = g_strdup ("myusername");
139 password = g_strdup ("mypassword");
140 proto = g_strdup ("smtp");
141 result = modest_account_mgr_add_server_account (account_mgr,
148 "modest_account_mgr_add_server_account failed:\n" \
149 "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
150 name, hostname, username, password, proto);
158 result = modest_account_mgr_account_exists (account_mgr,
162 fail_unless (result && !error,
163 "modest_account_mgr_account_exists failed: " \
164 "Server account with name \"%s\" should exist. Error: %s",
165 name, error ? error->message : "");
169 result = modest_account_mgr_remove_account (account_mgr,
173 fail_unless (result && !error,
174 "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
175 name, error ? error->message : "");
179 result = modest_account_mgr_account_exists (account_mgr,
180 "a_name_that_does_not_exist",
183 fail_unless (!result,
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 fail_unless (!result,
193 "modest_account_mgr_exists_account does not return " \
194 "FALSE when passing a server account that does not exist");
201 * Test regular usage of
202 * modest_account_mgr_add_account,
203 * modest_account_mgr_add_server_account
204 * modest_account_mgr_account_exists
205 * modest_account_mgr_remove_account
206 * - Test 1: Create account with NULL account_mgr
207 * - Test 2: Create account with NULL name
208 * - Test 3: Create account with invalid name string
209 * - Test 4: Create server account with NULL account_mgr
210 * - Test 5: Create server account with NULL name
211 * - Test 6: Create server account with invalid name string
212 * - Test 7: Remove a non-existing account
213 * - Test 8: Remove a non-existing server account
214 * - Test 9: Remove with NULL acount manager
215 * - Test 10: Remove with NULL name
216 * - Test 11: Check if an account exists with NULL account_mgr
217 * - Test 12: Check if a server account exists with a NULL account_mgr
218 * - Test 13: Check if a NULL account exists
219 * - Test 14: Check if a NULL server account exists
221 START_TEST (test_add_exists_remove_account_invalid)
226 result = modest_account_mgr_add_account (NULL,
227 TEST_MODEST_ACCOUNT_NAME,
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,
241 fail_unless (!result,
242 "modest_account_mgr_add_account does not return FALSE when" \
243 "passing a NULL account name");
246 result = modest_account_mgr_add_account (account_mgr,
247 "ïnválid_accountñ_nÄméç",
251 fail_unless (!result,
252 "modest_account_mgr_add_account does not return FALSE when" \
253 "passing an invalid account name");
256 result = modest_account_mgr_add_server_account (NULL,
257 TEST_MODEST_ACCOUNT_NAME,
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,
273 fail_unless (!result,
274 "modest_account_mgr_add_server_account does not return " \
275 "FALSE when passing a NULL account name");
278 result = modest_account_mgr_add_server_account (account_mgr,
279 "ïnválid_accountñ_nÄméç",
284 fail_unless (!result,
285 "modest_account_mgr_add_server_account does not return " \
286 "FALSE when passing an invalid account name");
289 result = modest_account_mgr_remove_account (account_mgr,
290 "a_name_that_does_not_exist",
293 fail_unless (!result,
294 "modest_account_mgr_remove_acccount does not return FALSE " \
295 "when trying to remove an account that does not exist");
298 result = modest_account_mgr_remove_account (account_mgr,
299 "a_name_that_does_not_exist",
302 fail_unless (!result,
303 "modest_account_mgr_remove_acccount does not return FALSE " \
304 "when trying to remove a server account that does not exist");
307 result = modest_account_mgr_remove_account (NULL,
308 TEST_MODEST_ACCOUNT_NAME,
311 fail_unless (!result,
312 "modest_account_mgr_remove_acccount does not return " \
313 "FALSE when passing a NULL ModestAccountMgr");
316 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,
329 fail_unless (!result,
330 "modest_account_mgr_exists_account does not return " \
331 "FALSE when passing a NULL ModestAccountMgr");
334 result = modest_account_mgr_account_exists (NULL,
335 TEST_MODEST_ACCOUNT_NAME,
338 fail_unless (!result,
339 "modest_account_mgr_exists_account does not return " \
340 "FALSE when passing a NULL ModestAccountMgr");
343 result = modest_account_mgr_account_exists (account_mgr,
347 fail_unless (!result,
348 "modest_account_mgr_exists_acccount does not return " \
349 "FALSE when passing a NULL account name");
352 result = modest_account_mgr_account_exists (account_mgr,
356 fail_unless (!result,
357 "modest_account_mgr_exists_account does not return " \
358 "FALSE when passing a NULL server account name");
362 /* ------------------- Suite creation ------------------- */
365 account_mgr_suite (void)
367 Suite *suite = suite_create ("ModestAccountMgr");
370 /* Tests case for "add/exists/remove account" */
371 tc = tcase_create ("add_exists_remove_account");
372 tcase_add_checked_fixture (tc,
373 fx_setup_default_account_mgr,
374 fx_teardown_default_account_mgr);
375 tcase_add_test (tc, test_add_exists_remove_account_regular);
376 tcase_add_test (tc, test_add_exists_remove_account_invalid);
377 suite_add_tcase (suite, tc);
382 /* --------------------- Main program ------------------- */
391 suite = account_mgr_suite ();
392 srunner = srunner_create (suite);
394 srunner_run_all (srunner, CK_ENV);
395 failures = srunner_ntests_failed (srunner);
396 srunner_free (srunner);