diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 00619fbf..479e59f2 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -52,31 +52,6 @@ void cmd_connect_shows_message_when_undefined(void **state) test_with_connection_status(JABBER_UNDEFINED); } -void cmd_connect_when_no_account(void **state) -{ - mock_cons_show(); - mock_accounts_get_account(); - mock_ui_ask_password(); - mock_jabber_connect_with_details(); - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", NULL }; - - mock_connection_status(JABBER_DISCONNECTED); - - accounts_get_account_expect_and_return("user@server.org", NULL); - - mock_ui_ask_password_returns("password"); - - expect_cons_show("Connecting as user@server.org"); - - jabber_connect_with_username_password_expect_and_return("user@server.org", "password", JABBER_CONNECTING); - - gboolean result = cmd_connect(args, *help); - assert_true(result); - - free(help); -} - void cmd_connect_shows_usage_when_no_server_value(void **state) { stub_ui_ask_password(); @@ -225,20 +200,93 @@ void cmd_connect_shows_message_when_port_contains_chars(void **state) free(help); } -void cmd_connect_with_altdomain_when_provided(void **state) +void cmd_connect_when_no_account(void **state) { - stub_ui_ask_password(); + mock_cons_show(); + mock_accounts_get_account(); + mock_ui_ask_password(); + mock_jabber_connect_with_details(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", NULL }; + + mock_connection_status(JABBER_DISCONNECTED); + + accounts_get_account_expect_and_return("user@server.org", NULL); + + mock_ui_ask_password_returns("password"); + + expect_cons_show("Connecting as user@server.org"); + + jabber_connect_with_details_expect_and_return("user@server.org", "password", NULL, 0, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} + +void cmd_connect_with_server_when_provided(void **state) +{ + mock_ui_ask_password(); stub_cons_show(); mock_accounts_get_account(); mock_jabber_connect_with_details(); CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "server", "altdomain", NULL }; + gchar *args[] = { "user@server.org", "server", "aserver", NULL }; mock_connection_status(JABBER_DISCONNECTED); accounts_get_account_return(NULL); - jabber_connect_with_altdomain_expect_and_return("altdomain", JABBER_CONNECTING); + mock_ui_ask_password_returns("password"); + + jabber_connect_with_details_expect_and_return("user@server.org", "password", "aserver", 0, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} + +void cmd_connect_with_port_when_provided(void **state) +{ + mock_ui_ask_password(); + stub_cons_show(); + mock_accounts_get_account(); + mock_jabber_connect_with_details(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", "port", "5432", NULL }; + + mock_connection_status(JABBER_DISCONNECTED); + + accounts_get_account_return(NULL); + + mock_ui_ask_password_returns("password"); + + jabber_connect_with_details_expect_and_return("user@server.org", "password", NULL, 5432, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} + +void cmd_connect_with_server_and_port_when_provided(void **state) +{ + mock_ui_ask_password(); + stub_cons_show(); + mock_accounts_get_account(); + mock_jabber_connect_with_details(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL }; + + mock_connection_status(JABBER_DISCONNECTED); + + accounts_get_account_return(NULL); + + mock_ui_ask_password_returns("password"); + + jabber_connect_with_details_expect_and_return("user@server.org", "password", "aserver", 5432, JABBER_CONNECTING); gboolean result = cmd_connect(args, *help); assert_true(result); diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index 7fa190cf..93ea923f 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -18,3 +18,6 @@ void cmd_connect_shows_message_when_port_0(void **state); void cmd_connect_shows_message_when_port_minus1(void **state); void cmd_connect_shows_message_when_port_65536(void **state); void cmd_connect_shows_message_when_port_contains_chars(void **state); +void cmd_connect_with_server_when_provided(void **state); +void cmd_connect_with_port_when_provided(void **state); +void cmd_connect_with_server_and_port_when_provided(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index dffd2127..b1d80390 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -173,7 +173,6 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_shows_message_when_connected), unit_test(cmd_connect_shows_message_when_undefined), unit_test(cmd_connect_when_no_account), - unit_test(cmd_connect_with_altdomain_when_provided), unit_test(cmd_connect_fail_message), unit_test(cmd_connect_lowercases_argument), unit_test(cmd_connect_asks_password_when_not_in_account), @@ -188,6 +187,9 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_shows_message_when_port_minus1), unit_test(cmd_connect_shows_message_when_port_65536), unit_test(cmd_connect_shows_message_when_port_contains_chars), + unit_test(cmd_connect_with_server_when_provided), + unit_test(cmd_connect_with_port_when_provided), + unit_test(cmd_connect_with_server_and_port_when_provided), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c index 2e889fa6..52cfdc83 100644 --- a/tests/xmpp/mock_xmpp.c +++ b/tests/xmpp/mock_xmpp.c @@ -105,24 +105,17 @@ expect_room_list_request(char *conf_server) } void -jabber_connect_with_username_password_expect_and_return(char *jid, - char *password, jabber_conn_status_t result) +jabber_connect_with_details_expect_and_return(char *jid, + char *password, char *altdomain, int port, jabber_conn_status_t result) { expect_string(_mock_jabber_connect_with_details, jid, jid); expect_string(_mock_jabber_connect_with_details, passwd, password); - expect_any(_mock_jabber_connect_with_details, altdomain); - expect_any(_mock_jabber_connect_with_details, port); - will_return(_mock_jabber_connect_with_details, result); -} - -void -jabber_connect_with_altdomain_expect_and_return(char *altdomain, - jabber_conn_status_t result) -{ - expect_any(_mock_jabber_connect_with_details, jid); - expect_any(_mock_jabber_connect_with_details, passwd); - expect_string(_mock_jabber_connect_with_details, altdomain, altdomain); - expect_any(_mock_jabber_connect_with_details, port); + if (altdomain == NULL) { + expect_any(_mock_jabber_connect_with_details, altdomain); + } else { + expect_string(_mock_jabber_connect_with_details, altdomain, altdomain); + } + expect_value(_mock_jabber_connect_with_details, port, port); will_return(_mock_jabber_connect_with_details, result); } diff --git a/tests/xmpp/mock_xmpp.h b/tests/xmpp/mock_xmpp.h index c52f5e5f..8e68da15 100644 --- a/tests/xmpp/mock_xmpp.h +++ b/tests/xmpp/mock_xmpp.h @@ -9,10 +9,8 @@ void mock_connection_presence_message(char *message); void expect_room_list_request(char *conf_server); void mock_jabber_connect_with_details(void); -void jabber_connect_with_username_password_expect_and_return(char *jid, - char *password, jabber_conn_status_t result); -void jabber_connect_with_altdomain_expect_and_return(char *altdomain, - jabber_conn_status_t result); +void jabber_connect_with_details_expect_and_return(char *jid, + char *password, char *altdomain, int port, jabber_conn_status_t result); void jabber_connect_with_details_return(jabber_conn_status_t result); void mock_jabber_connect_with_account(void);