2007-07-23 Murray Cumming <murrayc@murrayc.com>
[modest] / tests / check_account-mgr.c
index ffb052d..6c00667 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <modest-conf.h>
 #include <modest-account-mgr.h>
 #include <string.h>
 #include <modest-conf.h>
 #include <modest-account-mgr.h>
+#include <modest-protocol-info.h>
 
 /* ----------------------- Defines ---------------------- */
 
 
 /* ----------------------- Defines ---------------------- */
 
@@ -60,18 +61,16 @@ fx_setup_default_account_mgr ()
        /* cleanup old garbage (from previous runs)*/
        if (modest_account_mgr_account_exists(account_mgr,
                                              TEST_MODEST_ACCOUNT_NAME,
        /* cleanup old garbage (from previous runs)*/
        if (modest_account_mgr_account_exists(account_mgr,
                                              TEST_MODEST_ACCOUNT_NAME,
-                                             FALSE, NULL))
+                                             FALSE))
                modest_account_mgr_remove_account (account_mgr,
                                                   TEST_MODEST_ACCOUNT_NAME,
                modest_account_mgr_remove_account (account_mgr,
                                                   TEST_MODEST_ACCOUNT_NAME,
-                                                  FALSE,
-                                                  NULL);
+                                                  FALSE);
        if (modest_account_mgr_account_exists(account_mgr,
                                              TEST_MODEST_ACCOUNT_NAME,
        if (modest_account_mgr_account_exists(account_mgr,
                                              TEST_MODEST_ACCOUNT_NAME,
-                                             TRUE, NULL))
+                                             TRUE))
                modest_account_mgr_remove_account (account_mgr,
                                                   TEST_MODEST_ACCOUNT_NAME,
                modest_account_mgr_remove_account (account_mgr,
                                                   TEST_MODEST_ACCOUNT_NAME,
-                                                  TRUE,
-                                                  NULL);
+                                                  TRUE);
 }
 
 static void
 }
 
 static void
@@ -105,8 +104,7 @@ START_TEST (test_add_exists_remove_account_regular)
        gchar *hostname = NULL;
        gchar *username = NULL;
        gchar *password = NULL;
        gchar *hostname = NULL;
        gchar *username = NULL;
        gchar *password = NULL;
-       gchar *proto = NULL;
-       GError *error = NULL;
+       ModestTransportStoreProtocol proto;
        gboolean result;
        
        name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
        gboolean result;
        
        name = g_strdup (TEST_MODEST_ACCOUNT_NAME);
@@ -116,13 +114,11 @@ START_TEST (test_add_exists_remove_account_regular)
        result = modest_account_mgr_add_account (account_mgr,
                                                 name,
                                                 store_account,
        result = modest_account_mgr_add_account (account_mgr,
                                                 name,
                                                 store_account,
-                                                transport_account,
-                                                &error);
-       fail_unless (result && !error,
+                                                transport_account, TRUE);
+       fail_unless (result,
                     "modest_account_mgr_add_account failed:\n" \
                     "modest_account_mgr_add_account failed:\n" \
-                    "name: %s\nstore: %s\ntransport: %s\nerror: %s",
-                    name, store_account, transport_account,
-                    error ? error->message : "");
+                    "name: %s\nstore: %s\ntransport: %s\n",
+                    name, store_account, transport_account, TRUE);
        
        g_free (store_account);
        g_free (transport_account);
        
        g_free (store_account);
        g_free (transport_account);
@@ -130,35 +126,34 @@ START_TEST (test_add_exists_remove_account_regular)
        /* Test 2 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    name,
        /* Test 2 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    name,
-                                                   FALSE,
-                                                   &error);
-       fail_unless (result && !error,
+                                                   FALSE);
+       fail_unless (result,
                     "modest_account_mgr_account_exists failed: " \
                     "modest_account_mgr_account_exists failed: " \
-                    "Account with name \"%s\" should exist. Error: %s",
-                    name, error ? error->message : "");
+                    "Account with name \"%s\" should exist.\n", name);
        
 
        /* Test 3 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    name,
        
 
        /* Test 3 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    name,
-                                                   FALSE,
-                                                   &error);
-       fail_unless (result && !error,
+                                                   FALSE);
+       fail_unless (result,
                     "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
                     "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
-                    name,  error ? error->message : "");
+                    name);
 
 
        /* Test 4 */
        hostname = g_strdup ("myhostname.mydomain.com");
        username = g_strdup ("myusername");
        password = g_strdup ("mypassword");
 
 
        /* Test 4 */
        hostname = g_strdup ("myhostname.mydomain.com");
        username = g_strdup ("myusername");
        password = g_strdup ("mypassword");
-       proto = g_strdup ("smtp");
+       proto = MODEST_PROTOCOL_TRANSPORT_SMTP;
        result = modest_account_mgr_add_server_account (account_mgr,
                                                        name,
                                                        hostname,
                                                        username,
                                                        password,
        result = modest_account_mgr_add_server_account (account_mgr,
                                                        name,
                                                        hostname,
                                                        username,
                                                        password,
-                                                       proto);
+                                                       proto,
+                                                       MODEST_PROTOCOL_SECURITY_NONE,
+                                                       MODEST_PROTOCOL_AUTH_NONE); 
        fail_unless (result,
                     "modest_account_mgr_add_server_account failed:\n" \
                     "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
        fail_unless (result,
                     "modest_account_mgr_add_server_account failed:\n" \
                     "name: %s\nhostname: %s\nusername: %s\npassword: %s\nproto: %s",
@@ -167,47 +162,38 @@ START_TEST (test_add_exists_remove_account_regular)
        g_free (hostname);
        g_free (username);
        g_free (password);
        g_free (hostname);
        g_free (username);
        g_free (password);
-       g_free (proto);
        
        /* Test 5 */
        
        /* Test 5 */
-       result = modest_account_mgr_account_exists (account_mgr,
-                                                   name,
-                                                   TRUE,
-                                                   &error);
-       fail_unless (result && !error,
+       result = modest_account_mgr_account_exists (account_mgr,name,TRUE);
+       fail_unless (result,
                     "modest_account_mgr_account_exists failed: " \
                     "modest_account_mgr_account_exists failed: " \
-                    "Server account with name \"%s\" should exist. Error: %s",
-                    name, error ? error->message : "");
-
+                    "Server account with name \"%s\" should exist. Error: %s", name);
 
        /* Test 6 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    name,
 
        /* Test 6 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    name,
-                                                   TRUE,
-                                                   &error);
-       fail_unless (result && !error,
+                                                   TRUE);
+       fail_unless (result,
                     "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
                     "modest_account_mgr_remove_account failed:\nname: %s\nerror: %s",
-                    name, error ? error->message : "");
+                    name);
 
 
        /* Test 7 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    "a_name_that_does_not_exist",
 
 
        /* Test 7 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    "a_name_that_does_not_exist",
-                                                   FALSE,
-                                                   NULL);
-       fail_unless (!result,
+                                                   FALSE);
+       fail_unless (result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing an account that does not exist");
 
        /* Test 8 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    "a_name_that_does_not_exist",
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing an account that does not exist");
 
        /* Test 8 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    "a_name_that_does_not_exist",
-                                                   TRUE,
-                                                   NULL);
-       fail_unless (!result,
+                                                   TRUE);
+       fail_unless (result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a server account that does not exist");
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a server account that does not exist");
-
+       
        g_free (name);
 }
 END_TEST
        g_free (name);
 }
 END_TEST
@@ -241,8 +227,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        result = modest_account_mgr_add_account (NULL,
                                                 TEST_MODEST_ACCOUNT_NAME,
                                                 "store_account",
        result = modest_account_mgr_add_account (NULL,
                                                 TEST_MODEST_ACCOUNT_NAME,
                                                 "store_account",
-                                                "transport_account",
-                                                NULL);
+                                                "transport_account", TRUE);
        fail_unless (!result,
                     "modest_account_mgr_add_account does not return FALSE when" \
                     "passing a NULL ModestAccountMgr");
        fail_unless (!result,
                     "modest_account_mgr_add_account does not return FALSE when" \
                     "passing a NULL ModestAccountMgr");
@@ -251,8 +236,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        result = modest_account_mgr_add_account (account_mgr,
                                                 NULL,
                                                 "store_account",
        result = modest_account_mgr_add_account (account_mgr,
                                                 NULL,
                                                 "store_account",
-                                                "transport_account",
-                                                NULL);
+                                                "transport_account", TRUE);
        fail_unless (!result,
                     "modest_account_mgr_add_account does not return FALSE when" \
                     "passing a NULL account name");
        fail_unless (!result,
                     "modest_account_mgr_add_account does not return FALSE when" \
                     "passing a NULL account name");
@@ -261,8 +245,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        result = modest_account_mgr_add_account (account_mgr,
                                                 "ïnválid//accountñ//nÄméç",
                                                 "store_account",
        result = modest_account_mgr_add_account (account_mgr,
                                                 "ïnválid//accountñ//nÄméç",
                                                 "store_account",
-                                                "transport_account",
-                                                NULL);
+                                                "transport_account", TRUE);
        fail_unless (!result,
                     "modest_account_mgr_add_account does not return FALSE when" \
                     "passing an invalid account name");
        fail_unless (!result,
                     "modest_account_mgr_add_account does not return FALSE when" \
                     "passing an invalid account name");
@@ -273,7 +256,9 @@ START_TEST (test_add_exists_remove_account_invalid)
                                                        "hostname",
                                                        "username",
                                                        "password",
                                                        "hostname",
                                                        "username",
                                                        "password",
-                                                       "proto");
+                                                       MODEST_PROTOCOL_STORE_IMAP,
+                                                      MODEST_PROTOCOL_SECURITY_NONE,
+                                                      MODEST_PROTOCOL_AUTH_NONE);
        fail_unless (!result,
                     "modest_account_mgr_add_server_account does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
        fail_unless (!result,
                     "modest_account_mgr_add_server_account does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
@@ -284,7 +269,9 @@ START_TEST (test_add_exists_remove_account_invalid)
                                                        "hostname",
                                                        "username",
                                                        "password",
                                                        "hostname",
                                                        "username",
                                                        "password",
-                                                       "proto");
+                                                       MODEST_PROTOCOL_STORE_IMAP,
+                                                       MODEST_PROTOCOL_SECURITY_NONE,
+                                                       MODEST_PROTOCOL_AUTH_NONE); 
        fail_unless (!result,
                     "modest_account_mgr_add_server_account does not return " \
                     "FALSE when passing a NULL account name");
        fail_unless (!result,
                     "modest_account_mgr_add_server_account does not return " \
                     "FALSE when passing a NULL account name");
@@ -295,7 +282,9 @@ START_TEST (test_add_exists_remove_account_invalid)
                                                        "hostname", 
                                                        "username", 
                                                        "password", 
                                                        "hostname", 
                                                        "username", 
                                                        "password", 
-                                                       "proto"); 
+                                                       MODEST_PROTOCOL_STORE_IMAP,
+                                                       MODEST_PROTOCOL_SECURITY_NONE,
+                                                       MODEST_PROTOCOL_AUTH_NONE); 
        fail_unless (!result, 
                     "modest_account_mgr_add_server_account does not return " \
                     "FALSE when passing an invalid account name"); 
        fail_unless (!result, 
                     "modest_account_mgr_add_server_account does not return " \
                     "FALSE when passing an invalid account name"); 
@@ -303,8 +292,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 7 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    "a_name_that_does_not_exist",
        /* Test 7 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    "a_name_that_does_not_exist",
-                                                   FALSE,
-                                                   NULL);
+                                                   FALSE);
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return FALSE " \
                     "when trying to remove an account that does not exist");
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return FALSE " \
                     "when trying to remove an account that does not exist");
@@ -312,8 +300,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 8 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    "a_name_that_does_not_exist",
        /* Test 8 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    "a_name_that_does_not_exist",
-                                                   TRUE,
-                                                   NULL);
+                                                   TRUE);
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return FALSE " \
                     "when trying to remove a server account that does not exist");
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return FALSE " \
                     "when trying to remove a server account that does not exist");
@@ -321,8 +308,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 9 */
        result = modest_account_mgr_remove_account (NULL,
                                                    TEST_MODEST_ACCOUNT_NAME,
        /* Test 9 */
        result = modest_account_mgr_remove_account (NULL,
                                                    TEST_MODEST_ACCOUNT_NAME,
-                                                   FALSE,
-                                                   NULL);
+                                                   FALSE);
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
@@ -330,8 +316,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 10 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    NULL,
        /* Test 10 */
        result = modest_account_mgr_remove_account (account_mgr,
                                                    NULL,
-                                                   FALSE,
-                                                   NULL);
+                                                   FALSE);
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return " \
                     "FALSE when passing a NULL account name");
        fail_unless (!result,
                     "modest_account_mgr_remove_acccount does not return " \
                     "FALSE when passing a NULL account name");
@@ -339,8 +324,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 11 */
        result = modest_account_mgr_account_exists (NULL,
                                                    TEST_MODEST_ACCOUNT_NAME,
        /* Test 11 */
        result = modest_account_mgr_account_exists (NULL,
                                                    TEST_MODEST_ACCOUNT_NAME,
-                                                   TRUE,
-                                                   NULL);
+                                                   TRUE);
        fail_unless (!result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
        fail_unless (!result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
@@ -348,8 +332,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 12 */
        result = modest_account_mgr_account_exists (NULL,
                                                    TEST_MODEST_ACCOUNT_NAME,
        /* Test 12 */
        result = modest_account_mgr_account_exists (NULL,
                                                    TEST_MODEST_ACCOUNT_NAME,
-                                                   FALSE,
-                                                   NULL);
+                                                   FALSE);
        fail_unless (!result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
        fail_unless (!result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a NULL ModestAccountMgr");
@@ -357,8 +340,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 13 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    NULL,
        /* Test 13 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    NULL,
-                                                   FALSE,
-                                                   NULL);
+                                                   FALSE);
        fail_unless (!result,
                     "modest_account_mgr_exists_acccount does not return " \
                     "FALSE when passing a NULL account name");
        fail_unless (!result,
                     "modest_account_mgr_exists_acccount does not return " \
                     "FALSE when passing a NULL account name");
@@ -366,8 +348,7 @@ START_TEST (test_add_exists_remove_account_invalid)
        /* Test 14 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    NULL,
        /* Test 14 */
        result = modest_account_mgr_account_exists (account_mgr,
                                                    NULL,
-                                                   TRUE,
-                                                   NULL);
+                                                   TRUE);
        fail_unless (!result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a NULL server account name");
        fail_unless (!result,
                     "modest_account_mgr_exists_account does not return " \
                     "FALSE when passing a NULL server account name");