about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd_connect.c148
-rw-r--r--tests/test_cmd_connect.h8
-rw-r--r--tests/testsuite.c8
3 files changed, 164 insertions, 0 deletions
diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c
index 325a9062..00619fbf 100644
--- a/tests/test_cmd_connect.c
+++ b/tests/test_cmd_connect.c
@@ -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();
diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h
index 2ee1a91b..7fa190cf 100644
--- a/tests/test_cmd_connect.h
+++ b/tests/test_cmd_connect.h
@@ -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);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 105f5f65..dffd2127 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -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),