mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added cmd_connect tests for argument validation
This commit is contained in:
parent
b62591903d
commit
b4e9905db9
@ -91,9 +91,10 @@ cmd_connect(gchar **args, struct cmd_help_t help)
|
||||
altdomain = opt1val;
|
||||
altdomain_set = TRUE;
|
||||
} else if (strcmp(opt1, "port") == 0) {
|
||||
if (_strtoi(opt1val, &port, 1, 65536) != 0) {
|
||||
if (_strtoi(opt1val, &port, 1, 65535) != 0) {
|
||||
port = 0;
|
||||
cons_show("Port must be in the range 1 to 65535.");
|
||||
cons_show("");
|
||||
return TRUE;
|
||||
} else {
|
||||
port_set = TRUE;
|
||||
}
|
||||
@ -121,9 +122,10 @@ cmd_connect(gchar **args, struct cmd_help_t help)
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
if (_strtoi(opt2val, &port, 1, 65536) != 0) {
|
||||
if (_strtoi(opt2val, &port, 1, 65535) != 0) {
|
||||
port = 0;
|
||||
cons_show("Port must be in the range 1 to 65535.");
|
||||
cons_show("");
|
||||
return TRUE;
|
||||
} else {
|
||||
port_set = TRUE;
|
||||
}
|
||||
|
@ -77,6 +77,154 @@ void cmd_connect_when_no_account(void **state)
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_usage_when_no_server_value(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "user@server.org", "server", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_usage_when_server_no_port_value(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "user@server.org", "server", "aserver", "port", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_usage_when_no_port_value(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "user@server.org", "port", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_usage_when_port_no_server_value(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "user@server.org", "port", "5678", "server", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_message_when_port_0(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", "port", "0", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Value 0 out of range. Must be in 1..65535.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_message_when_port_minus1(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", "port", "-1", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Value -1 out of range. Must be in 1..65535.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_message_when_port_65536(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", "port", "65536", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Value 65536 out of range. Must be in 1..65535.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_message_when_port_contains_chars(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", "port", "52f66", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_cons_show("Could not convert \"52f66\" to a number.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_connect_with_altdomain_when_provided(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
|
@ -10,3 +10,11 @@ void cmd_connect_asks_password_when_not_in_account(void **state);
|
||||
void cmd_connect_shows_message_when_connecting_with_account(void **state);
|
||||
void cmd_connect_connects_with_account(void **state);
|
||||
void cmd_connect_frees_account_after_connecting(void **state);
|
||||
void cmd_connect_shows_usage_when_no_server_value(void **state);
|
||||
void cmd_connect_shows_usage_when_server_no_port_value(void **state);
|
||||
void cmd_connect_shows_usage_when_no_port_value(void **state);
|
||||
void cmd_connect_shows_usage_when_port_no_server_value(void **state);
|
||||
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);
|
||||
|
@ -180,6 +180,14 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_connect_shows_message_when_connecting_with_account),
|
||||
unit_test(cmd_connect_connects_with_account),
|
||||
unit_test(cmd_connect_frees_account_after_connecting),
|
||||
unit_test(cmd_connect_shows_usage_when_no_server_value),
|
||||
unit_test(cmd_connect_shows_usage_when_server_no_port_value),
|
||||
unit_test(cmd_connect_shows_usage_when_no_port_value),
|
||||
unit_test(cmd_connect_shows_usage_when_port_no_server_value),
|
||||
unit_test(cmd_connect_shows_message_when_port_0),
|
||||
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_rooms_shows_message_when_disconnected),
|
||||
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
||||
|
Loading…
Reference in New Issue
Block a user