From 93397e4581e1c294972c4b262deb65f6d1a0d9d0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Mar 2014 01:23:12 +0000 Subject: [PATCH] Added cmd_roster test --- Makefile.am | 1 + tests/test_cmd_roster.c | 70 +++++++++++++++++++++++++++++++++++++++++ tests/test_cmd_roster.h | 5 +++ tests/testsuite.c | 7 +++++ tests/ui/mock_ui.c | 18 +++++++++++ tests/ui/mock_ui.h | 3 ++ 6 files changed, 104 insertions(+) create mode 100644 tests/test_cmd_roster.c create mode 100644 tests/test_cmd_roster.h diff --git a/Makefile.am b/Makefile.am index 1ec141bb..b508981b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -76,6 +76,7 @@ tests_sources = \ tests/test_preferences.c \ tests/test_server_events.c \ tests/test_muc.c \ + tests/test_cmd_roster.c \ tests/testsuite.c main_source = src/main.c diff --git a/tests/test_cmd_roster.c b/tests/test_cmd_roster.c new file mode 100644 index 00000000..9cfb711c --- /dev/null +++ b/tests/test_cmd_roster.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "ui/ui.h" +#include "ui/mock_ui.h" + +#include "xmpp/xmpp.h" +#include "xmpp/mock_xmpp.h" + +#include "roster_list.h" +#include "command/commands.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_roster(NULL, *help); + assert_true(result); + + free(help); +} + +void cmd_roster_shows_message_when_disconnecting(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTING); +} + +void cmd_roster_shows_message_when_connecting(void **state) +{ + test_with_connection_status(JABBER_CONNECTING); +} + +void cmd_roster_shows_message_when_disconnected(void **state) +{ + test_with_connection_status(JABBER_DISCONNECTED); +} + +void cmd_roster_shows_message_when_undefined(void **state) +{ + test_with_connection_status(JABBER_UNDEFINED); +} + +void cmd_roster_shows_roster_when_no_args(void **state) +{ + mock_cons_show_roster(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { NULL }; + + mock_connection_status(JABBER_CONNECTED); + roster_init(); + roster_add("bob@server.org", "bob", NULL, "both", FALSE); + GSList *roster = roster_get_contacts(); + cons_show_roster_expect(roster); + + gboolean result = cmd_roster(args, *help); + assert_true(result); + + free(help); + roster_free(); +} diff --git a/tests/test_cmd_roster.h b/tests/test_cmd_roster.h new file mode 100644 index 00000000..e3e687ef --- /dev/null +++ b/tests/test_cmd_roster.h @@ -0,0 +1,5 @@ +void cmd_roster_shows_message_when_disconnecting(void **state); +void cmd_roster_shows_message_when_connecting(void **state); +void cmd_roster_shows_message_when_disconnected(void **state); +void cmd_roster_shows_message_when_undefined(void **state); +void cmd_roster_shows_roster_when_no_args(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 63d8fd2d..4e20265d 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -29,6 +29,7 @@ #include "test_cmd_bookmark.h" #include "test_cmd_join.h" #include "test_muc.h" +#include "test_cmd_roster.h" int main(int argc, char* argv[]) { const UnitTest all_tests[] = { @@ -500,6 +501,12 @@ int main(int argc, char* argv[]) { unit_test(cmd_join_uses_supplied_nick), unit_test(cmd_join_uses_account_nick_when_not_supplied), unit_test(cmd_join_uses_password_when_supplied), + + unit_test(cmd_roster_shows_message_when_disconnecting), + unit_test(cmd_roster_shows_message_when_connecting), + unit_test(cmd_roster_shows_message_when_disconnected), + unit_test(cmd_roster_shows_message_when_undefined), + unit_test(cmd_roster_shows_roster_when_no_args), }; return run_tests(all_tests); diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index 5cf48cb9..cbdbd486 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -171,6 +171,12 @@ void _mock_ui_room_join(char *room) check_expected(room); } +static +void _mock_cons_show_roster(GSList *list) +{ + check_expected(list); +} + // bind mocks and stubs void @@ -276,6 +282,12 @@ mock_ui_current_print_line(void) ui_current_print_line = _mock_ui_current_print_line; } +void +mock_cons_show_roster(void) +{ + cons_show_roster = _mock_cons_show_roster; +} + // expectations void @@ -420,3 +432,9 @@ ui_room_join_expect(char *room) ui_room_join = _mock_ui_room_join; expect_string(_mock_ui_room_join, room, room); } + +void +cons_show_roster_expect(GSList *list) +{ + expect_any(_mock_cons_show_roster, list); +} diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h index 05b271c1..fa56e2f6 100644 --- a/tests/ui/mock_ui.h +++ b/tests/ui/mock_ui.h @@ -61,4 +61,7 @@ void ui_current_win_is_otr_returns(gboolean result); void ui_room_join_expect(char *room); +void mock_cons_show_roster(void); +void cons_show_roster_expect(GSList *list); + #endif