From: Jose Dapena Paz Date: Tue, 3 Feb 2009 11:49:02 +0000 (+0000) Subject: Fix some unit tests. X-Git-Tag: git_migration_finished~674 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=c5a5b586adace0a0a65316ea89ecbf52e5b08430;hp=cb68944c4c0c8e36453b07926bca8ebee668aa7b Fix some unit tests. pmo-trunk-r7369 --- diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 368b9c2..bc6d51b 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -721,6 +721,26 @@ modest_account_mgr_remove_account (ModestAccountMgr * self, return TRUE; } +gboolean +modest_account_mgr_remove_server_account (ModestAccountMgr * self, + const gchar* name) +{ + ModestAccountMgrPrivate *priv; + + g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE); + g_return_val_if_fail (name, FALSE); + + if (!modest_account_mgr_account_exists (self, name, TRUE)) { + g_printerr ("modest: %s: server account '%s' does not exist\n", __FUNCTION__, name); + return FALSE; + } + + priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); + real_remove_account (priv->modest_conf, name, TRUE); + + return TRUE; +} + /* strip the first /n/ character from each element diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index 56bfb8f..81698a9 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -201,6 +201,18 @@ gboolean modest_account_mgr_remove_account (ModestAccountMgr *sel const gchar* name); /** + * modest_account_mgr_remove_account: + * @self: a ModestAccountMgr instance + * @name: the name of the server account to remove + * + * remove an existing server account. This is only for internal use. + * + * Returns: TRUE if the operation succeeded, FALSE otherwise, + */ +gboolean modest_account_mgr_remove_server_account (ModestAccountMgr *self, + const gchar* name); + +/** * modest_account_mgr_account_names: * @self: a ModestAccountMgr instance * @only_enabled: Whether only enabled accounts should be returned. diff --git a/tests/check_account-mgr.c b/tests/check_account-mgr.c index b944b96..369ac3b 100644 --- a/tests/check_account-mgr.c +++ b/tests/check_account-mgr.c @@ -29,8 +29,11 @@ #include #include +#include #include #include +#include +#include /* ----------------------- Defines ---------------------- */ @@ -45,15 +48,13 @@ static ModestAccountMgr *account_mgr = NULL; static void fx_setup_default_account_mgr () { - ModestConf *conf = NULL; + fail_unless (gtk_init_check (NULL, NULL)); - g_type_init (); + fail_unless (g_setenv (MODEST_DIR_ENV, ".modesttest", TRUE)); + fail_unless (g_setenv (MODEST_NAMESPACE_ENV, "/apps/modesttest", TRUE)); + fail_unless (modest_init (0, NULL), "Failed running modest_init"); - conf = modest_conf_new (); - fail_unless (MODEST_IS_CONF (conf), - "modest_conf_new failed"); - - account_mgr = modest_account_mgr_new (conf); + account_mgr = modest_runtime_get_account_mgr (); fail_unless (MODEST_IS_ACCOUNT_MGR (account_mgr), "modest_account_mgr_new failed"); @@ -65,15 +66,10 @@ fx_setup_default_account_mgr () TEST_MODEST_ACCOUNT_NAME); if (modest_account_mgr_account_exists(account_mgr, TEST_MODEST_ACCOUNT_NAME, - TRUE)) - modest_account_mgr_remove_account (account_mgr, - TEST_MODEST_ACCOUNT_NAME); -} - -static void -fx_teardown_default_account_mgr () -{ - g_object_unref (account_mgr); + TRUE)) { + modest_account_mgr_remove_server_account (account_mgr, + TEST_MODEST_ACCOUNT_NAME); + } } /* ---------- add/exists/remove account tests ---------- */ @@ -159,7 +155,7 @@ START_TEST (test_add_exists_remove_account_regular) MODEST_PROTOCOLS_AUTH_NONE); fail_unless (result, "modest_account_mgr_add_server_account failed:\n" \ - "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s", + "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %d", name, hostname, username, password, proto); g_free (hostname); @@ -173,10 +169,10 @@ START_TEST (test_add_exists_remove_account_regular) "Server account with name \"%s\" should exist. Error: %s", name); /* Test 6 */ - result = modest_account_mgr_remove_account (account_mgr, - name); + result = modest_account_mgr_remove_server_account (account_mgr, + name); fail_unless (result, - "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s", + "modest_account_mgr_remove_server_account failed:\nname: %s\nerror: %s", name); @@ -184,7 +180,7 @@ START_TEST (test_add_exists_remove_account_regular) result = modest_account_mgr_account_exists (account_mgr, "a_name_that_does_not_exist", FALSE); - fail_unless (result, + fail_unless (!result, "modest_account_mgr_exists_account does not return " \ "FALSE when passing an account that does not exist"); @@ -192,7 +188,7 @@ START_TEST (test_add_exists_remove_account_regular) result = modest_account_mgr_account_exists (account_mgr, "a_name_that_does_not_exist", TRUE); - fail_unless (result, + fail_unless (!result, "modest_account_mgr_exists_account does not return " \ "FALSE when passing a server account that does not exist"); @@ -371,9 +367,8 @@ account_mgr_suite (void) /* Tests case for "add/exists/remove account" */ tc = tcase_create ("add_exists_remove_account"); - tcase_add_checked_fixture (tc, - fx_setup_default_account_mgr, - fx_teardown_default_account_mgr); + tcase_add_unchecked_fixture (tc, + fx_setup_default_account_mgr, NULL); tcase_add_test (tc, test_add_exists_remove_account_regular); tcase_add_test (tc, test_add_exists_remove_account_invalid); suite_add_tcase (suite, tc); diff --git a/tests/check_modest-conf.c b/tests/check_modest-conf.c index 45786a3..668a146 100644 --- a/tests/check_modest-conf.c +++ b/tests/check_modest-conf.c @@ -30,7 +30,21 @@ #include #include #include +#include #include +#include + +static void +fx_setup_modest_conf () +{ + fail_unless (gtk_init_check (NULL, NULL)); + + fail_unless (g_setenv (MODEST_DIR_ENV, ".modesttest", TRUE)); + fail_unless (g_setenv (MODEST_NAMESPACE_ENV, "/apps/modesttest", TRUE)); + + fail_unless (modest_init (0, NULL), "Failed running modest_init"); + +} START_TEST (test_modest_conf_new) { @@ -160,6 +174,9 @@ modest_conf_suite (void) Suite *suite = suite_create ("ModestConf"); TCase *tc_core = tcase_create ("core"); + tcase_add_checked_fixture (tc_core, + fx_setup_modest_conf, + NULL); tcase_add_test (tc_core, test_modest_conf_new); tcase_add_test (tc_core, test_modest_conf_store_retrieve_string); tcase_add_test (tc_core, test_modest_conf_store_retrieve_bool);