From 05952e8337a947b30fd196520c185d38ae1b03c0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Mar 2014 00:53:46 +0000 Subject: [PATCH 1/3] Small changes to help --- src/command/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index a9bab0ef..8d4ccf8e 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -85,7 +85,7 @@ static struct cmd_t command_defs[] = "-------------------------", "Use with no arguments to get a help summary.", "Supply an area to see help for commands related to specific features.", - "Supply a command (without the leading slash) to see help on that command.", + "Supply a command (without the leading slash) to see help for that command.", "", "Example : /help commands", "Example : /help presence", @@ -99,7 +99,7 @@ static struct cmd_t command_defs[] = { "/about", "About Profanity.", { "/about", "------", - "Show versioning and license information.", + "Show version and license information.", NULL } } }, { "/connect", From 93397e4581e1c294972c4b262deb65f6d1a0d9d0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Mar 2014 01:23:12 +0000 Subject: [PATCH 2/3] 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 From a578419d552f1a61a9b7615e20c6697451008702 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Mar 2014 01:46:18 +0000 Subject: [PATCH 3/3] Added /roster add test --- tests/test_cmd_roster.c | 33 +++++++++++++++++++++++++++++++++ tests/test_cmd_roster.h | 2 ++ tests/testsuite.c | 2 ++ tests/xmpp/mock_xmpp.c | 20 ++++++++++++++++++++ tests/xmpp/mock_xmpp.h | 3 +++ 5 files changed, 60 insertions(+) diff --git a/tests/test_cmd_roster.c b/tests/test_cmd_roster.c index 9cfb711c..b29019bb 100644 --- a/tests/test_cmd_roster.c +++ b/tests/test_cmd_roster.c @@ -68,3 +68,36 @@ void cmd_roster_shows_roster_when_no_args(void **state) free(help); roster_free(); } + +void cmd_roster_add_shows_message_when_no_jid(void) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "add", NULL }; + + mock_connection_status(JABBER_CONNECTED); + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_roster(args, *help); + assert_true(result); + + free(help); +} + +void cmd_roster_add_sends_roster_add_request(void) +{ + char *jid = "bob@server.org"; + char *nick = "bob"; + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "add", jid, nick, NULL }; + + mock_roster_send_add_new(); + mock_connection_status(JABBER_CONNECTED); + roster_send_add_new_expect(jid, nick); + + gboolean result = cmd_roster(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_roster.h b/tests/test_cmd_roster.h index e3e687ef..cfed5875 100644 --- a/tests/test_cmd_roster.h +++ b/tests/test_cmd_roster.h @@ -3,3 +3,5 @@ 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); +void cmd_roster_add_shows_message_when_no_jid(void **state); +void cmd_roster_add_sends_roster_add_request(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 4e20265d..937e4642 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -507,6 +507,8 @@ int main(int argc, char* argv[]) { 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), + unit_test(cmd_roster_add_shows_message_when_no_jid), + unit_test(cmd_roster_add_sends_roster_add_request), }; return run_tests(all_tests); diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c index 3b824c19..c25156be 100644 --- a/tests/xmpp/mock_xmpp.c +++ b/tests/xmpp/mock_xmpp.c @@ -96,6 +96,13 @@ _mock_presence_join_room(char *room, char*nick, char *passwd) check_expected(passwd); } +static void +_mock_roster_send_add_new(const char *const barejid, const char * const name) +{ + check_expected(barejid); + check_expected(name); +} + void mock_jabber_connect_with_details(void) { @@ -139,6 +146,12 @@ mock_presence_join_room(void) presence_join_room = _mock_presence_join_room; } +void +mock_roster_send_add_new(void) +{ + roster_send_add_new = _mock_roster_send_add_new; +} + void bookmark_get_list_returns(GList *bookmarks) { @@ -260,3 +273,10 @@ presence_join_room_expect(char *room, char *nick, char *passwd) expect_string(_mock_presence_join_room, passwd, passwd); } } + +void +roster_send_add_new_expect(char *jid, char *nick) +{ + expect_string(_mock_roster_send_add_new, barejid, jid); + expect_string(_mock_roster_send_add_new, name, nick); +} diff --git a/tests/xmpp/mock_xmpp.h b/tests/xmpp/mock_xmpp.h index 2b535761..aafe1ba7 100644 --- a/tests/xmpp/mock_xmpp.h +++ b/tests/xmpp/mock_xmpp.h @@ -36,4 +36,7 @@ void message_send_expect(char *message, char *recipient); void mock_presence_join_room(void); void presence_join_room_expect(char *room, char *nick, char *passwd); +void mock_roster_send_add_new(void); +void roster_send_add_new_expect(char *jid, char *nick); + #endif