From 2d54c565ce1fbcca5f14436e503ccced1495f2b5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 8 Mar 2014 00:19:21 +0000 Subject: [PATCH] Added test to show usage when no room supplied to /join --- src/command/commands.c | 12 ++++++++++-- tests/test_cmd_join.c | 19 +++++++++++++++++++ tests/test_cmd_join.h | 1 + tests/testsuite.c | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 736f2fd3..6eae7d09 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1583,6 +1583,12 @@ cmd_join(gchar **args, struct cmd_help_t help) return TRUE; } + if (args[0] == NULL) { + cons_show("Usage: %s", help.usage); + cons_show(""); + return TRUE; + } + Jid *room_arg = jid_create(args[0]); if (room_arg == NULL) { cons_show_error("Specified room has incorrect format"); @@ -1594,8 +1600,10 @@ cmd_join(gchar **args, struct cmd_help_t help) char *nick = NULL; char *passwd = NULL; GString *room_str = g_string_new(""); - Jid *my_jid = jid_create(jabber_get_fulljid()); - ProfAccount *account = accounts_get_account(jabber_get_account_name()); + const char *full_jid = jabber_get_fulljid(); + Jid *my_jid = jid_create(full_jid); + char *account_name = jabber_get_account_name(); + ProfAccount *account = accounts_get_account(account_name); // full room jid supplied (room@server) if (room_arg->localpart != NULL) { diff --git a/tests/test_cmd_join.c b/tests/test_cmd_join.c index ec9dfb58..88ca8c17 100644 --- a/tests/test_cmd_join.c +++ b/tests/test_cmd_join.c @@ -48,6 +48,25 @@ void cmd_join_shows_message_when_undefined(void **state) { test_with_connection_status(JABBER_UNDEFINED); } + +void cmd_join_shows_usage_when_no_args(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { NULL }; + + mock_connection_status(JABBER_CONNECTED); + + expect_cons_show("Usage: some usage"); + expect_cons_show(""); + + gboolean result = cmd_join(args, *help); + assert_true(result); + + free(help); +} + /* void cmd_connect_shows_usage_when_no_server_value(void **state) { diff --git a/tests/test_cmd_join.h b/tests/test_cmd_join.h index 3f053552..c8e3c408 100644 --- a/tests/test_cmd_join.h +++ b/tests/test_cmd_join.h @@ -2,3 +2,4 @@ void cmd_join_shows_message_when_disconnecting(void **state); void cmd_join_shows_message_when_connecting(void **state); void cmd_join_shows_message_when_disconnected(void **state); void cmd_join_shows_message_when_undefined(void **state); +void cmd_join_shows_usage_when_no_args(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 45d68d1d..73a9362a 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -491,6 +491,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_join_shows_message_when_connecting), unit_test(cmd_join_shows_message_when_disconnected), unit_test(cmd_join_shows_message_when_undefined), + unit_test(cmd_join_shows_usage_when_no_args), }; return run_tests(all_tests);