diff --git a/Makefile.am b/Makefile.am index 4aa18752..5d00adda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -69,6 +69,7 @@ test_sources = \ tests/test_cmd_connect.c \ tests/test_cmd_account.c \ tests/test_cmd_rooms.c \ + tests/test_cmd_sub.c \ tests/test_history.c \ tests/test_jid.c \ tests/test_parser.c \ diff --git a/src/command/commands.c b/src/command/commands.c index c5b253e7..f09bf0e4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -311,7 +311,6 @@ gboolean cmd_sub(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); - win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are currently not connected."); @@ -337,6 +336,7 @@ cmd_sub(gchar **args, struct cmd_help_t help) return TRUE; } + win_type_t win_type = ui_current_win_type(); if ((win_type != WIN_CHAT) && (jid == NULL)) { cons_show("You must specify a contact."); return TRUE; diff --git a/tests/test_cmd_sub.c b/tests/test_cmd_sub.c new file mode 100644 index 00000000..4f459be3 --- /dev/null +++ b/tests/test_cmd_sub.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "xmpp/xmpp.h" +#include "xmpp/mock_xmpp.h" + +#include "ui/ui.h" +#include "ui/mock_ui.h" + +#include "command/commands.h" + +void cmd_sub_shows_message_when_not_connected(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { NULL }; + + mock_connection_status(JABBER_DISCONNECTED); + + expect_cons_show("You are currently not connected."); + + gboolean result = cmd_sub(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_sub.h b/tests/test_cmd_sub.h new file mode 100644 index 00000000..b8c95c1a --- /dev/null +++ b/tests/test_cmd_sub.h @@ -0,0 +1 @@ +void cmd_sub_shows_message_when_not_connected(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index e906c358..1ffd2a71 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -8,6 +8,7 @@ #include "test_cmd_connect.h" #include "test_cmd_account.h" #include "test_cmd_rooms.h" +#include "test_cmd_sub.h" #include "test_history.h" #include "test_jid.h" #include "test_parser.h" @@ -252,6 +253,9 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_clear_checks_account_exists), unit_test(cmd_account_clear_shows_message_when_account_doesnt_exist), unit_test(cmd_account_clear_shows_message_when_invalid_property), + + unit_test(cmd_sub_shows_message_when_not_connected), + }; return run_tests(tests); }