mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added cmd_connect tests for connecting server and port
This commit is contained in:
parent
b4e9905db9
commit
0ee6c7a6f1
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user