From 6f060b583ee88f9d9c8f56b7a3b74e558462c3db Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:07:53 +0000 Subject: [PATCH] Test "/account list" --- tests/test_cmd_account.c | 25 ++++++++++++++++++++++++- tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + tests/ui/mock_ui.c | 7 ++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index a857ca1c..33ba348b 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -7,6 +7,7 @@ #include #include "xmpp/xmpp.h" +#include "ui/ui.h" #include "command/commands.h" void cmd_account_shows_usage_when_not_connected_and_no_args(void **state) @@ -32,7 +33,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) gchar *args[] = { NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - + will_return(jabber_get_account_name, "account_name"); expect_string(accounts_get_account, name, "account_name"); @@ -45,5 +46,27 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) gboolean result = cmd_account(args, *help); assert_true(result); + free(help); + free(account); +} + +void cmd_account_list_shows_accounts(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "list" }; + + gchar **accounts = malloc(sizeof(gchar *) * 4); + accounts[0] = strdup("account1"); + accounts[1] = strdup("account2"); + accounts[2] = strdup("account3"); + accounts[3] = NULL; + + will_return(accounts_get_list, accounts); + + expect_memory(cons_show_account_list, accounts, accounts, sizeof(accounts)); + + gboolean result = cmd_account(args, *help); + assert_true(result); + free(help); } diff --git a/tests/test_cmd_account.h b/tests/test_cmd_account.h index 30944fe4..2232b6aa 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -1,2 +1,3 @@ void cmd_account_shows_usage_when_not_connected_and_no_args(void **state); void cmd_account_shows_account_when_connected_and_no_args(void **state); +void cmd_account_list_shows_accounts(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 73c54014..f594a35e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -30,6 +30,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_shows_usage_when_not_connected_and_no_args), unit_test(cmd_account_shows_account_when_connected_and_no_args), + unit_test(cmd_account_list_shows_accounts), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index 5d83bcea..6e3e190c 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -250,7 +250,12 @@ void cons_show_login_success(ProfAccount *account) {} void cons_show_software_version(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) {} -void cons_show_account_list(gchar **accounts) {} + +void cons_show_account_list(gchar **accounts) +{ + check_expected(accounts); +} + void cons_show_room_list(GSList *room, const char * const conference_node) {} void cons_show_bookmarks(const GList *list) {} void cons_show_disco_items(GSList *items, const char * const jid) {}