* fix unit tests. all tests pass now.
[modest] / tests / check_account-mgr.c
index c35317a..ffb052d 100644 (file)
@@ -34,7 +34,7 @@
 
 /* ----------------------- Defines ---------------------- */
 
-#define TEST_MODEST_ACCOUNT_NAME  "modest-unit-tests-account"
+#define TEST_MODEST_ACCOUNT_NAME  "modest-unit-tests-àccount"
 
 /* ------------------ Global variables ------------------ */
 
@@ -45,18 +45,33 @@ static ModestAccountMgr *account_mgr = NULL;
 static void
 fx_setup_default_account_mgr ()
 {
-  int argc = 0;
-  ModestConf *conf = NULL;
-
-  g_type_init ();
-
-  conf = modest_conf_new ();
-  fail_unless (MODEST_IS_CONF (conf), 
-              "modest_conf_new failed");
-
-  account_mgr = modest_account_mgr_new (conf);
-  fail_unless (MODEST_IS_ACCOUNT_MGR (account_mgr),
-              "modest_account_mgr_new failed");
+       ModestConf *conf = NULL;
+
+       g_type_init ();
+
+       conf = modest_conf_new ();
+       fail_unless (MODEST_IS_CONF (conf), 
+                    "modest_conf_new failed");
+
+       account_mgr = modest_account_mgr_new (conf);
+       fail_unless (MODEST_IS_ACCOUNT_MGR (account_mgr),
+                    "modest_account_mgr_new failed");
+
+       /* cleanup old garbage (from previous runs)*/
+       if (modest_account_mgr_account_exists(account_mgr,
+                                             TEST_MODEST_ACCOUNT_NAME,
+                                             FALSE, NULL))
+               modest_account_mgr_remove_account (account_mgr,
+                                                  TEST_MODEST_ACCOUNT_NAME,
+                                                  FALSE,
+                                                  NULL);
+       if (modest_account_mgr_account_exists(account_mgr,
+                                             TEST_MODEST_ACCOUNT_NAME,
+                                             TRUE, NULL))
+               modest_account_mgr_remove_account (account_mgr,
+                                                  TEST_MODEST_ACCOUNT_NAME,
+                                                  TRUE,
+                                                  NULL);
 }
 
 static void
@@ -93,9 +108,8 @@ START_TEST (test_add_exists_remove_account_regular)
        gchar *proto = NULL;
        GError *error = NULL;
        gboolean result;
-
+       
        name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
-
        /* Test 1 */
        store_account = g_strdup ("imap://me@myserver");
        transport_account = g_strdup ("local-smtp");
@@ -133,6 +147,7 @@ START_TEST (test_add_exists_remove_account_regular)
                     "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
                     name,  error ? error->message : "");
 
+
        /* Test 4 */
        hostname = g_strdup ("myhostname.mydomain.com");
        username = g_strdup ("myusername");
@@ -153,7 +168,7 @@ START_TEST (test_add_exists_remove_account_regular)
        g_free (username);
        g_free (password);
        g_free (proto);
-
+       
        /* Test 5 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    name,
@@ -244,7 +259,7 @@ START_TEST (test_add_exists_remove_account_invalid)
 
        /* Test 3*/
        result = modest_account_mgr_add_account (account_mgr,
-                                                "ïnválid_accountñ_nÄméç",
+                                                "ïnválid//accountñ//nÄméç",
                                                 "store_account",
                                                 "transport_account",
                                                 NULL);
@@ -275,15 +290,15 @@ START_TEST (test_add_exists_remove_account_invalid)
                     "FALSE when passing a NULL account name");
 
        /* Test 6 */
-       result = modest_account_mgr_add_server_account (account_mgr,
-                                                       "ïnválid_accountñ_nÄméç",
-                                                       "hostname",
-                                                       "username",
-                                                       "password",
-                                                       "proto");
-       fail_unless (!result,
-                    "modest_account_mgr_add_server_account does not return " \
-                    "FALSE when passing an invalid account name");
+       result = modest_account_mgr_add_server_account (account_mgr, 
+                                                       "ïnválid//accountñ//nÄméç",
+                                                       "hostname", 
+                                                       "username", 
+                                                       "password", 
+                                                       "proto"); 
+       fail_unless (!result, 
+                    "modest_account_mgr_add_server_account does not return " \
+                    "FALSE when passing an invalid account name"); 
 
        /* Test 7 */
        result = modest_account_mgr_remove_account (account_mgr,