From 614ae232ef59dc221290f75d3ae33d169e1afaf0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 1 Feb 2014 16:24:51 +0000 Subject: [PATCH] Fixed cmd_bookmark message when not connected --- src/command/commands.c | 10 +++++----- tests/test_cmd_bookmark.c | 39 +++++++++++++++++++++++++++++++++++++++ tests/test_cmd_bookmark.h | 5 +++++ tests/testsuite.c | 5 +++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index bf83be07..85adebde 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1711,15 +1711,15 @@ gboolean cmd_bookmark(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); - gchar *cmd = args[0]; - if (cmd == NULL) { - cons_show("Usage: %s", help.usage); + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); return TRUE; } - if (conn_status != JABBER_CONNECTED) { - cons_show("You are not currenlty connect."); + gchar *cmd = args[0]; + if (cmd == NULL) { + cons_show("Usage: %s", help.usage); return TRUE; } diff --git a/tests/test_cmd_bookmark.c b/tests/test_cmd_bookmark.c index 59f5c02e..7d969ee8 100644 --- a/tests/test_cmd_bookmark.c +++ b/tests/test_cmd_bookmark.c @@ -13,6 +13,45 @@ #include "ui/mock_ui.h" +static void test_with_connection_status(jabber_conn_status_t status) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + + mock_connection_status(status); + expect_cons_show("You are not currently connected."); + + gboolean result = cmd_bookmark(NULL, *help); + assert_true(result); + + free(help); +} + +void cmd_bookmark_shows_message_when_disconnected(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTED); +} + +void cmd_bookmark_shows_message_when_disconnecting(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTING); +} + +void cmd_bookmark_shows_message_when_connecting(void **state) +{ + test_with_connection_status(JABBER_CONNECTING); +} + +void cmd_bookmark_shows_message_when_started(void **state) +{ + test_with_connection_status(JABBER_STARTED); +} + +void cmd_bookmark_shows_message_when_undefined(void **state) +{ + test_with_connection_status(JABBER_UNDEFINED); +} + void cmd_bookmark_shows_usage_when_no_args(void **state) { mock_cons_show(); diff --git a/tests/test_cmd_bookmark.h b/tests/test_cmd_bookmark.h index adc6f1a0..2f4f1e69 100644 --- a/tests/test_cmd_bookmark.h +++ b/tests/test_cmd_bookmark.h @@ -1 +1,6 @@ +void cmd_bookmark_shows_message_when_disconnected(void **state); +void cmd_bookmark_shows_message_when_disconnecting(void **state); +void cmd_bookmark_shows_message_when_connecting(void **state); +void cmd_bookmark_shows_message_when_started(void **state); +void cmd_bookmark_shows_message_when_undefined(void **state); void cmd_bookmark_shows_usage_when_no_args(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 06b0280b..94f2faad 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -439,6 +439,11 @@ int main(int argc, char* argv[]) { }; const UnitTest cmd_bookmark_tests[] = { + unit_test(cmd_bookmark_shows_message_when_disconnected), + unit_test(cmd_bookmark_shows_message_when_disconnecting), + unit_test(cmd_bookmark_shows_message_when_connecting), + unit_test(cmd_bookmark_shows_message_when_started), + unit_test(cmd_bookmark_shows_message_when_undefined), unit_test(cmd_bookmark_shows_usage_when_no_args), };