From bf347ab9e05b4b5bcd0dfa354f139aca85744440 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 18:08:26 +0000 Subject: Added cmd_connect tests --- tests/test_cmd_connect.c | 79 +++++++++++++++++++++++++++++++++++++++++++++ tests/test_cmd_connect.h | 4 +++ tests/test_cmd_rooms.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/test_cmd_rooms.h | 7 ++++ tests/test_command.c | 83 ------------------------------------------------ tests/test_command.h | 7 ---- tests/testsuite.c | 10 ++++-- 7 files changed, 181 insertions(+), 92 deletions(-) create mode 100644 tests/test_cmd_connect.c create mode 100644 tests/test_cmd_connect.h create mode 100644 tests/test_cmd_rooms.c create mode 100644 tests/test_cmd_rooms.h delete mode 100644 tests/test_command.c delete mode 100644 tests/test_command.h (limited to 'tests') diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c new file mode 100644 index 00000000..2acc2c48 --- /dev/null +++ b/tests/test_cmd_connect.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include + +#include "xmpp/xmpp.h" +#include "ui/ui.h" +#include "command/commands.h" + +static void test_with_connection_status(jabber_conn_status_t status) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + + will_return(jabber_get_connection_status, status); + expect_string(cons_show, msg, "You are either connected already, or a login is in process."); + + gboolean result = cmd_connect(NULL, *help); + assert_true(result); + + free(help); +} + +void cmd_connect_shows_message_when_disconnecting(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTING); +} + +void cmd_connect_shows_message_when_connecting(void **state) +{ + test_with_connection_status(JABBER_CONNECTING); +} + +void cmd_connect_shows_message_when_connected(void **state) +{ + test_with_connection_status(JABBER_CONNECTED); +} + +void cmd_connect_shows_message_when_undefined(void **state) +{ + test_with_connection_status(JABBER_UNDEFINED); +} +/* +void cmd_rooms_uses_account_default_when_no_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + ProfAccount *account = malloc(sizeof(ProfAccount)); + account->muc_service = "default_conf_server"; + gchar *args[] = { NULL }; + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + will_return(jabber_get_account_name, "account_name"); + will_return(accounts_get_account, account); + expect_string(iq_room_list_request, conferencejid, "default_conf_server"); + + gboolean result = cmd_rooms(args, *help); + + assert_true(result); + + free(help); + free(account); +} + +void cmd_rooms_arg_used_when_passed(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "conf_server_arg" }; + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + expect_string(iq_room_list_request, conferencejid, "conf_server_arg"); + + gboolean result = cmd_rooms(args, *help); + + assert_true(result); + + free(help); +} +*/ diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h new file mode 100644 index 00000000..af187d68 --- /dev/null +++ b/tests/test_cmd_connect.h @@ -0,0 +1,4 @@ +void cmd_connect_shows_message_when_disconnecting(void **state); +void cmd_connect_shows_message_when_connecting(void **state); +void cmd_connect_shows_message_when_connected(void **state); +void cmd_connect_shows_message_when_undefined(void **state); diff --git a/tests/test_cmd_rooms.c b/tests/test_cmd_rooms.c new file mode 100644 index 00000000..e58e178d --- /dev/null +++ b/tests/test_cmd_rooms.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include + +#include "xmpp/xmpp.h" +#include "ui/ui.h" +#include "command/commands.h" + +static void test_with_connection_status(jabber_conn_status_t status) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + + will_return(jabber_get_connection_status, status); + expect_string(cons_show, msg, "You are not currently connected."); + + gboolean result = cmd_rooms(NULL, *help); + assert_true(result); + + free(help); +} + +void cmd_rooms_shows_message_when_disconnected(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTED); +} + +void cmd_rooms_shows_message_when_disconnecting(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTING); +} + +void cmd_rooms_shows_message_when_connecting(void **state) +{ + test_with_connection_status(JABBER_CONNECTING); +} + +void cmd_rooms_shows_message_when_started(void **state) +{ + test_with_connection_status(JABBER_STARTED); +} + +void cmd_rooms_shows_message_when_undefined(void **state) +{ + test_with_connection_status(JABBER_UNDEFINED); +} + +void cmd_rooms_uses_account_default_when_no_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + ProfAccount *account = malloc(sizeof(ProfAccount)); + account->muc_service = "default_conf_server"; + gchar *args[] = { NULL }; + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + will_return(jabber_get_account_name, "account_name"); + will_return(accounts_get_account, account); + expect_string(iq_room_list_request, conferencejid, "default_conf_server"); + + gboolean result = cmd_rooms(args, *help); + + assert_true(result); + + free(help); + free(account); +} + +void cmd_rooms_arg_used_when_passed(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "conf_server_arg" }; + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + expect_string(iq_room_list_request, conferencejid, "conf_server_arg"); + + gboolean result = cmd_rooms(args, *help); + + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_rooms.h b/tests/test_cmd_rooms.h new file mode 100644 index 00000000..a9a7af83 --- /dev/null +++ b/tests/test_cmd_rooms.h @@ -0,0 +1,7 @@ +void cmd_rooms_shows_message_when_disconnected(void **state); +void cmd_rooms_shows_message_when_disconnecting(void **state); +void cmd_rooms_shows_message_when_connecting(void **state); +void cmd_rooms_shows_message_when_started(void **state); +void cmd_rooms_shows_message_when_undefined(void **state); +void cmd_rooms_uses_account_default_when_no_arg(void **state); +void cmd_rooms_arg_used_when_passed(void **state); diff --git a/tests/test_command.c b/tests/test_command.c deleted file mode 100644 index 6dc51ecb..00000000 --- a/tests/test_command.c +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "xmpp/xmpp.h" -#include "ui/ui.h" -#include "command/commands.h" - -static void test_with_connection_status(jabber_conn_status_t status) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - - will_return(jabber_get_connection_status, status); - expect_string(cons_show, msg, "You are not currently connected."); - - gboolean result = cmd_rooms(NULL, *help); - assert_true(result); - - free(help); -} - -void cmd_rooms_shows_message_when_disconnected(void **state) -{ - test_with_connection_status(JABBER_DISCONNECTED); -} - -void cmd_rooms_shows_message_when_disconnecting(void **state) -{ - test_with_connection_status(JABBER_DISCONNECTING); -} - -void cmd_rooms_shows_message_when_connecting(void **state) -{ - test_with_connection_status(JABBER_CONNECTING); -} - -void cmd_rooms_shows_message_when_started(void **state) -{ - test_with_connection_status(JABBER_STARTED); -} - -void cmd_rooms_shows_message_when_undefined(void **state) -{ - test_with_connection_status(JABBER_UNDEFINED); -} - -void cmd_rooms_uses_account_default_when_no_arg(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - ProfAccount *account = malloc(sizeof(ProfAccount)); - account->muc_service = "default_conf_server"; - gchar *args[] = { NULL }; - - will_return(jabber_get_connection_status, JABBER_CONNECTED); - will_return(jabber_get_account_name, "account_name"); - will_return(accounts_get_account, account); - expect_string(iq_room_list_request, conferencejid, "default_conf_server"); - - gboolean result = cmd_rooms(args, *help); - - assert_true(result); - - free(help); - free(account); -} - -void cmd_arg_used_when_passed(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "conf_server_arg" }; - - will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_string(iq_room_list_request, conferencejid, "conf_server_arg"); - - gboolean result = cmd_rooms(args, *help); - - assert_true(result); - - free(help); -} diff --git a/tests/test_command.h b/tests/test_command.h deleted file mode 100644 index 0f47be84..00000000 --- a/tests/test_command.h +++ /dev/null @@ -1,7 +0,0 @@ -void cmd_rooms_shows_message_when_disconnected(void **state); -void cmd_rooms_shows_message_when_disconnecting(void **state); -void cmd_rooms_shows_message_when_connecting(void **state); -void cmd_rooms_shows_message_when_started(void **state); -void cmd_rooms_shows_message_when_undefined(void **state); -void cmd_rooms_uses_account_default_when_no_arg(void **state); -void cmd_arg_used_when_passed(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index ee18fe6a..d13a3d46 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -5,7 +5,8 @@ #include "test_autocomplete.h" #include "test_common.h" -#include "test_command.h" +#include "test_cmd_connect.h" +#include "test_cmd_rooms.h" #include "test_history.h" #include "test_jid.h" #include "test_parser.h" @@ -13,13 +14,18 @@ int main(int argc, char* argv[]) { const UnitTest tests[] = { + unit_test(cmd_connect_shows_message_when_disconnecting), + unit_test(cmd_connect_shows_message_when_connecting), + unit_test(cmd_connect_shows_message_when_connected), + unit_test(cmd_connect_shows_message_when_undefined), + unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), unit_test(cmd_rooms_shows_message_when_connecting), unit_test(cmd_rooms_shows_message_when_started), unit_test(cmd_rooms_shows_message_when_undefined), unit_test(cmd_rooms_uses_account_default_when_no_arg), - unit_test(cmd_arg_used_when_passed), + unit_test(cmd_rooms_arg_used_when_passed), unit_test(replace_one_substr), unit_test(replace_one_substr_beginning), -- cgit 1.4.1-2-gfad0