From bf347ab9e05b4b5bcd0dfa354f139aca85744440 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 18:08:26 +0000 Subject: [PATCH 01/24] Added cmd_connect tests --- Makefile.am | 3 +- tests/test_cmd_connect.c | 79 ++++++++++++++++++++++ tests/test_cmd_connect.h | 4 ++ tests/{test_command.c => test_cmd_rooms.c} | 2 +- tests/{test_command.h => test_cmd_rooms.h} | 2 +- tests/testsuite.c | 10 ++- 6 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 tests/test_cmd_connect.c create mode 100644 tests/test_cmd_connect.h rename tests/{test_command.c => test_cmd_rooms.c} (97%) rename tests/{test_command.h => test_cmd_rooms.h} (87%) diff --git a/Makefile.am b/Makefile.am index 8531c302..cb717a15 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,7 +65,8 @@ test_sources = \ tests/config/mock_accounts.c \ tests/test_autocomplete.c \ tests/test_common.c \ - tests/test_command.c \ + tests/test_cmd_connect.c \ + tests/test_cmd_rooms.c \ tests/test_history.c \ tests/test_jid.c \ tests/test_parser.c \ 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_command.c b/tests/test_cmd_rooms.c similarity index 97% rename from tests/test_command.c rename to tests/test_cmd_rooms.c index 6dc51ecb..e58e178d 100644 --- a/tests/test_command.c +++ b/tests/test_cmd_rooms.c @@ -67,7 +67,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state) free(account); } -void cmd_arg_used_when_passed(void **state) +void cmd_rooms_arg_used_when_passed(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "conf_server_arg" }; diff --git a/tests/test_command.h b/tests/test_cmd_rooms.h similarity index 87% rename from tests/test_command.h rename to tests/test_cmd_rooms.h index 0f47be84..a9a7af83 100644 --- a/tests/test_command.h +++ b/tests/test_cmd_rooms.h @@ -4,4 +4,4 @@ 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); +void cmd_rooms_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), From eff2ef3859e66542b5ce16efd800c3ece63caf71 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 18:15:16 +0000 Subject: [PATCH 02/24] Check expected arg to account_get_account in cmd_rooms test --- tests/config/mock_accounts.c | 1 + tests/test_cmd_rooms.c | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index e81aff9b..de83f44a 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -50,6 +50,7 @@ gchar** accounts_get_list(void) ProfAccount* accounts_get_account(const char * const name) { + check_expected(name); return (ProfAccount *)mock(); } diff --git a/tests/test_cmd_rooms.c b/tests/test_cmd_rooms.c index e58e178d..91581a99 100644 --- a/tests/test_cmd_rooms.c +++ b/tests/test_cmd_rooms.c @@ -56,6 +56,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state) will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_account_name, "account_name"); + expect_string(accounts_get_account, name, "account_name"); will_return(accounts_get_account, account); expect_string(iq_room_list_request, conferencejid, "default_conf_server"); From 079ea5304b7bc99b07d2f05b2910ab370023c14d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 19:38:23 +0000 Subject: [PATCH 03/24] Moved _ask_password to UI module --- src/command/commands.c | 18 ++---------------- src/ui/core.c | 13 +++++++++++++ src/ui/ui.h | 1 + tests/test_cmd_connect.c | 40 +++++++++++++++------------------------- tests/test_cmd_connect.h | 1 + tests/test_cmd_rooms.c | 2 +- tests/testsuite.c | 1 + tests/ui/mock_ui.c | 13 ++++++++++++- tests/xmpp/mock_xmpp.c | 3 +++ 9 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 4b0c5a5c..6c354ec4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -44,7 +44,6 @@ #include "xmpp/xmpp.h" #include "xmpp/bookmark.h" -static char * _ask_password(void); static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, @@ -80,12 +79,12 @@ cmd_connect(gchar **args, struct cmd_help_t help) } if (account->password == NULL) { - account->password = _ask_password(); + account->password = ui_ask_password(); } cons_show("Connecting with account %s as %s", account->name, jid); conn_status = jabber_connect_with_account(account); } else { - char *passwd = _ask_password(); + char *passwd = ui_ask_password(); jid = strdup(lower); cons_show("Connecting as %s", jid); conn_status = jabber_connect_with_details(jid, passwd, altdomain); @@ -2243,19 +2242,6 @@ cmd_xa(gchar **args, struct cmd_help_t help) return TRUE; } -// helper function that asks the user for a password and saves it in passwd -static char * -_ask_password(void) { - char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1)); - status_bar_get_password(); - status_bar_refresh(); - inp_block(); - inp_get_password(passwd); - inp_non_block(); - - return passwd; -} - // helper function for status change commands static void _update_presence(const resource_presence_t resource_presence, diff --git a/src/ui/core.c b/src/ui/core.c index 507cfb02..1ff41b7d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1330,6 +1330,19 @@ ui_win_unread(int index) } } +char * +ui_ask_password(void) +{ + char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1)); + status_bar_get_password(); + status_bar_refresh(); + inp_block(); + inp_get_password(passwd); + inp_non_block(); + + return passwd; +} + static void _ui_draw_win_title(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 5ec4debd..f6bb98ac 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -80,6 +80,7 @@ char * ui_recipient(int index); void ui_close_win(int index); gboolean ui_win_exists(int index); int ui_win_unread(int index); +char * ui_ask_password(void); // ui events void ui_contact_typing(const char * const from); diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 2acc2c48..2a09815f 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "xmpp/xmpp.h" @@ -14,7 +15,7 @@ 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."); + expect_string(cons_show, output, "You are either connected already, or a login is in process."); gboolean result = cmd_connect(NULL, *help); assert_true(result); @@ -41,39 +42,28 @@ 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) + +void cmd_connect_when_no_account(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - ProfAccount *account = malloc(sizeof(ProfAccount)); - account->muc_service = "default_conf_server"; - gchar *args[] = { NULL }; + gchar *args[] = { "user@server.org", 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"); + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - gboolean result = cmd_rooms(args, *help); + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); - assert_true(result); + will_return(ui_ask_password, strdup("password")); - free(help); - free(account); -} + expect_string(cons_show, output, "Connecting as user@server.org"); -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); + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_any(jabber_connect_with_details, altdomain); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + gboolean result = cmd_connect(args, *help); assert_true(result); free(help); } -*/ diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index af187d68..be8eba23 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -2,3 +2,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); +void cmd_connect_when_no_account(void **state); diff --git a/tests/test_cmd_rooms.c b/tests/test_cmd_rooms.c index 91581a99..b6782176 100644 --- a/tests/test_cmd_rooms.c +++ b/tests/test_cmd_rooms.c @@ -14,7 +14,7 @@ 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."); + expect_string(cons_show, output, "You are not currently connected."); gboolean result = cmd_rooms(NULL, *help); assert_true(result); diff --git a/tests/testsuite.c b/tests/testsuite.c index d13a3d46..8a29e0fd 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -18,6 +18,7 @@ int main(int argc, char* argv[]) { 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_connect_when_no_account), 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 ed7dd4b1..a361e90e 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -26,6 +26,8 @@ #include "ui/ui.h" +char output[256]; + // ui startup and control void ui_init(void) {} void ui_load_colours(void) {} @@ -173,6 +175,11 @@ gboolean ui_duck_exists(void) void ui_tidy_wins(void) {} void ui_prune_wins(void) {} +char * ui_ask_password(void) +{ + return (char *)mock(); +} + // create windows void create_title_bar(void) {} void create_status_bar(void) {} @@ -191,7 +198,11 @@ void title_bar_draw(void) {} // console window actions void cons_show(const char * const msg, ...) { - check_expected(msg); + va_list args; + va_start(args, msg); + vsnprintf(output, sizeof(output), msg, args); + check_expected(output); + va_end(args); } void cons_about(void) {} diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c index 8ba03cab..26c9c72d 100644 --- a/tests/xmpp/mock_xmpp.c +++ b/tests/xmpp/mock_xmpp.c @@ -32,6 +32,9 @@ void jabber_init(const int disable_tls) {} jabber_conn_status_t jabber_connect_with_details(const char * const jid, const char * const passwd, const char * const altdomain) { + check_expected(jid); + check_expected(passwd); + check_expected(altdomain); return (jabber_conn_status_t)mock(); } From 7842b0d1fcb6269d2d173a8edefb3af90612d3f2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 19:56:48 +0000 Subject: [PATCH 04/24] Added mock log module --- Makefile.am | 3 +- tests/log/mock_log.c | 59 ++++++++++++++++++++++++++++++++++++++++ tests/test_cmd_connect.c | 52 +++++++++++++++++++++++++++++++++++ tests/test_cmd_connect.h | 2 ++ tests/testsuite.c | 2 ++ tests/ui/mock_ui.c | 11 +++++++- 6 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 tests/log/mock_log.c diff --git a/Makefile.am b/Makefile.am index cb717a15..a4cc2df8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,7 @@ core_sources = \ src/config/theme.c src/config/theme.h test_sources = \ - src/contact.c src/contact.h src/log.c src/common.c \ + src/contact.c src/contact.h src/common.c \ src/log.h src/profanity.c src/common.h \ src/profanity.h src/chat_session.c \ src/chat_session.h src/muc.c src/muc.h src/jid.h src/jid.c \ @@ -62,6 +62,7 @@ test_sources = \ src/config/theme.c src/config/theme.h \ tests/ui/mock_ui.c \ tests/xmpp/mock_xmpp.c \ + tests/log/mock_log.c \ tests/config/mock_accounts.c \ tests/test_autocomplete.c \ tests/test_common.c \ diff --git a/tests/log/mock_log.c b/tests/log/mock_log.c new file mode 100644 index 00000000..a5e6a950 --- /dev/null +++ b/tests/log/mock_log.c @@ -0,0 +1,59 @@ +/* + * mock_log.c + * + * Copyright (C) 2012, 2013 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#include +#include +#include + +#include "log.h" + +void log_init(log_level_t filter) {} +log_level_t log_get_filter(void) +{ + return (log_level_t)mock(); +} +void log_close(void) {} +void log_debug(const char * const msg, ...) {} +void log_info(const char * const msg, ...) {} +void log_warning(const char * const msg, ...) {} +void log_error(const char * const msg, ...) {} +void log_msg(log_level_t level, const char * const area, + const char * const msg) {} + +log_level_t log_level_from_string(char *log_level) +{ + return (log_level_t)mock(); +} + +void chat_log_init(void) {} +void chat_log_chat(const gchar * const login, gchar *other, + const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) {} +void chat_log_close(void) {} +GSList * chat_log_get_previous(const gchar * const login, + const gchar * const recipient, GSList *history) +{ + return (GSList *)mock(); +} + +void groupchat_log_init(void) {} +void groupchat_log_chat(const gchar * const login, const gchar * const room, + const gchar * const nick, const gchar * const msg) {} diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 2a09815f..0092d5e4 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -67,3 +67,55 @@ void cmd_connect_when_no_account(void **state) free(help); } + +void cmd_connect_with_altdomain_when_provided(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", "altdomain" }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_string(cons_show, output, "Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_string(jabber_connect_with_details, altdomain, "altdomain"); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} + +void cmd_connect_fail_message(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", "altdomain" }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_string(cons_show, output, "Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_string(jabber_connect_with_details, altdomain, "altdomain"); + will_return(jabber_connect_with_details, JABBER_DISCONNECTED); + + expect_string(cons_show_error, output, "Connection attempt for user@server.org failed."); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index be8eba23..c351f11b 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -3,3 +3,5 @@ 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); void cmd_connect_when_no_account(void **state); +void cmd_connect_with_altdomain_when_provided(void **state); +void cmd_connect_fail_message(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 8a29e0fd..148ccf90 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -19,6 +19,8 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_shows_message_when_connected), unit_test(cmd_connect_shows_message_when_undefined), unit_test(cmd_connect_when_no_account), + unit_test(cmd_connect_with_altdomain_when_provided), + unit_test(cmd_connect_fail_message), 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 a361e90e..33b6f1b8 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -222,7 +222,16 @@ void cons_show_account(ProfAccount *account) {} void cons_debug(const char * const msg, ...) {} void cons_show_time(void) {} void cons_show_word(const char * const word) {} -void cons_show_error(const char * const cmd, ...) {} + +void cons_show_error(const char * const cmd, ...) +{ + va_list args; + va_start(args, cmd); + vsnprintf(output, sizeof(output), cmd, args); + check_expected(output); + va_end(args); +} + void cons_highlight_show(const char * const cmd) {} void cons_show_contacts(GSList * list) {} void cons_show_roster(GSList * list) {} From 9b631cf57173f1ddf371531da16da06070d39a52 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 20:02:25 +0000 Subject: [PATCH 05/24] Ignore arguments that are not part of test --- tests/test_cmd_connect.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 0092d5e4..c60b4679 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -75,15 +75,15 @@ void cmd_connect_with_altdomain_when_provided(void **state) will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - expect_string(accounts_get_account, name, "user@server.org"); + expect_any(accounts_get_account, name); will_return(accounts_get_account, NULL); will_return(ui_ask_password, strdup("password")); - expect_string(cons_show, output, "Connecting as user@server.org"); + expect_any(cons_show, output); - expect_string(jabber_connect_with_details, jid, "user@server.org"); - expect_string(jabber_connect_with_details, passwd, "password"); + expect_any(jabber_connect_with_details, jid); + expect_any(jabber_connect_with_details, passwd); expect_string(jabber_connect_with_details, altdomain, "altdomain"); will_return(jabber_connect_with_details, JABBER_CONNECTING); @@ -96,20 +96,20 @@ void cmd_connect_with_altdomain_when_provided(void **state) void cmd_connect_fail_message(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "altdomain" }; + gchar *args[] = { "user@server.org", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - expect_string(accounts_get_account, name, "user@server.org"); + expect_any(accounts_get_account, name); will_return(accounts_get_account, NULL); will_return(ui_ask_password, strdup("password")); - expect_string(cons_show, output, "Connecting as user@server.org"); + expect_any(cons_show, output); - expect_string(jabber_connect_with_details, jid, "user@server.org"); - expect_string(jabber_connect_with_details, passwd, "password"); - expect_string(jabber_connect_with_details, altdomain, "altdomain"); + expect_any(jabber_connect_with_details, jid); + expect_any(jabber_connect_with_details, passwd); + expect_any(jabber_connect_with_details, altdomain); will_return(jabber_connect_with_details, JABBER_DISCONNECTED); expect_string(cons_show_error, output, "Connection attempt for user@server.org failed."); From 5e739cbfb7763ee926fbeb3cb8bd1d81f943c55e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 20:32:30 +0000 Subject: [PATCH 06/24] Moved fulljid logic to accounts --- src/command/commands.c | 7 +------ src/config/accounts.c | 10 ++++++++++ src/config/accounts.h | 1 + tests/config/mock_accounts.c | 4 ++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 6c354ec4..910c57d5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -72,12 +72,7 @@ cmd_connect(gchar **args, struct cmd_help_t help) ProfAccount *account = accounts_get_account(lower); if (account != NULL) { - if (account->resource != NULL) { - jid = create_fulljid(account->jid, account->resource); - } else { - jid = strdup(account->jid); - } - + jid = accounts_create_full_jid(account); if (account->password == NULL) { account->password = ui_ask_password(); } diff --git a/src/config/accounts.c b/src/config/accounts.c index 0422a991..6431cd9e 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -292,6 +292,16 @@ accounts_get_account(const char * const name) } } +char * +accounts_create_full_jid(ProfAccount *account) +{ + if (account->resource != NULL) { + return create_fulljid(account->jid, account->resource); + } else { + return strdup(account->jid); + } +} + void accounts_free_account(ProfAccount *account) { diff --git a/src/config/accounts.h b/src/config/accounts.h index 96289952..caa8e84c 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -81,5 +81,6 @@ void accounts_set_priority_all(const char * const account_name, const gint value gint accounts_get_priority_for_presence_type(const char * const account_name, resource_presence_t presence_type); void accounts_clear_password(const char * const account_name); +char * accounts_create_full_jid(ProfAccount *account); #endif diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index de83f44a..3174cb35 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -110,4 +110,8 @@ gint accounts_get_priority_for_presence_type(const char * const account_name, } void accounts_clear_password(const char * const account_name) {} +char * accounts_create_full_jid(ProfAccount *account) +{ + return (char *)mock(); +} From 5c65599e6accb35c056220b40b2b2251d0c8f4fc Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 20:38:26 +0000 Subject: [PATCH 07/24] Tests lowercasing argument on cmd_connect --- tests/test_cmd_connect.c | 35 ++++++++++++++++++++++++++++++----- tests/test_cmd_connect.h | 1 + tests/test_cmd_rooms.c | 12 ++++++------ tests/testsuite.c | 3 ++- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index c60b4679..a05267ea 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -13,10 +13,10 @@ 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, output, "You are either connected already, or a login is in process."); - + gboolean result = cmd_connect(NULL, *help); assert_true(result); @@ -49,7 +49,7 @@ void cmd_connect_when_no_account(void **state) gchar *args[] = { "user@server.org", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - + expect_string(accounts_get_account, name, "user@server.org"); will_return(accounts_get_account, NULL); @@ -74,7 +74,7 @@ void cmd_connect_with_altdomain_when_provided(void **state) gchar *args[] = { "user@server.org", "altdomain" }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - + expect_any(accounts_get_account, name); will_return(accounts_get_account, NULL); @@ -99,7 +99,7 @@ void cmd_connect_fail_message(void **state) gchar *args[] = { "user@server.org", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - + expect_any(accounts_get_account, name); will_return(accounts_get_account, NULL); @@ -119,3 +119,28 @@ void cmd_connect_fail_message(void **state) free(help); } + +void cmd_connect_lowercases_argument(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "USER@server.ORG", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_any(cons_show, output); + + expect_any(jabber_connect_with_details, jid); + expect_any(jabber_connect_with_details, passwd); + expect_any(jabber_connect_with_details, altdomain); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index c351f11b..3f9e72a8 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -5,3 +5,4 @@ void cmd_connect_shows_message_when_undefined(void **state); void cmd_connect_when_no_account(void **state); void cmd_connect_with_altdomain_when_provided(void **state); void cmd_connect_fail_message(void **state); +void cmd_connect_lowercases_argument(void **state); diff --git a/tests/test_cmd_rooms.c b/tests/test_cmd_rooms.c index b6782176..e39d9088 100644 --- a/tests/test_cmd_rooms.c +++ b/tests/test_cmd_rooms.c @@ -12,10 +12,10 @@ 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, output, "You are not currently connected."); - + gboolean result = cmd_rooms(NULL, *help); assert_true(result); @@ -52,14 +52,14 @@ 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 }; + 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"); 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); @@ -71,11 +71,11 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state) void cmd_rooms_arg_used_when_passed(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "conf_server_arg" }; + 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); diff --git a/tests/testsuite.c b/tests/testsuite.c index 148ccf90..d02787e3 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -21,6 +21,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_when_no_account), unit_test(cmd_connect_with_altdomain_when_provided), unit_test(cmd_connect_fail_message), + unit_test(cmd_connect_lowercases_argument), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), @@ -29,7 +30,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_rooms_shows_message_when_undefined), unit_test(cmd_rooms_uses_account_default_when_no_arg), unit_test(cmd_rooms_arg_used_when_passed), - + unit_test(replace_one_substr), unit_test(replace_one_substr_beginning), unit_test(replace_one_substr_end), From 540d658e3512ac4ffa540ef23743bc602ee9e8a3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 20:52:30 +0000 Subject: [PATCH 08/24] Added ask for password test when connecting with an account --- tests/config/mock_accounts.c | 1 + tests/test_cmd_connect.c | 26 ++++++++++++++++++++++++++ tests/test_cmd_connect.h | 1 + tests/testsuite.c | 1 + 4 files changed, 29 insertions(+) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index 3174cb35..e2732acb 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -110,6 +110,7 @@ gint accounts_get_priority_for_presence_type(const char * const account_name, } void accounts_clear_password(const char * const account_name) {} + char * accounts_create_full_jid(ProfAccount *account) { return (char *)mock(); diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index a05267ea..e07543f8 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -144,3 +144,29 @@ void cmd_connect_lowercases_argument(void **state) free(help); } + +void cmd_connect_asks_password_when_not_in_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "jabber_org", NULL }; + ProfAccount *account = malloc(sizeof(ProfAccount)); + account->password = NULL; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_any(accounts_get_account, name); + will_return(accounts_get_account, account); + + will_return(accounts_create_full_jid, strdup("user@jabber.org")); + + will_return(ui_ask_password, strdup("password")); + + expect_any(cons_show, output); + will_return(jabber_connect_with_account, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); + free(account); +} diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index 3f9e72a8..5349442b 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -6,3 +6,4 @@ void cmd_connect_when_no_account(void **state); void cmd_connect_with_altdomain_when_provided(void **state); void cmd_connect_fail_message(void **state); void cmd_connect_lowercases_argument(void **state); +void cmd_connect_asks_password_when_not_in_account(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index d02787e3..b88037e2 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -22,6 +22,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_with_altdomain_when_provided), unit_test(cmd_connect_fail_message), unit_test(cmd_connect_lowercases_argument), + unit_test(cmd_connect_asks_password_when_not_in_account), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From cae2979a0b5601ae7c1b39a5b28f4ceb77218bfa Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 21:23:58 +0000 Subject: [PATCH 09/24] Added test for message when connecting via account --- tests/test_cmd_connect.c | 26 ++++++++++++++++++++++++++ tests/test_cmd_connect.h | 1 + tests/testsuite.c | 1 + 3 files changed, 28 insertions(+) diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index e07543f8..ad76da79 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -170,3 +170,29 @@ void cmd_connect_asks_password_when_not_in_account(void **state) free(help); free(account); } + +void cmd_connect_shows_message_when_connecting_with_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "jabber_org", NULL }; + ProfAccount *account = malloc(sizeof(ProfAccount)); + account->password = "password"; + account->name = "jabber_org"; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_any(accounts_get_account, name); + will_return(accounts_get_account, account); + + will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); + + expect_string(cons_show, output, "Connecting with account jabber_org as user@jabber.org/laptop"); + will_return(jabber_connect_with_account, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); + free(account); + +} diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index 5349442b..9bb525cf 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -7,3 +7,4 @@ void cmd_connect_with_altdomain_when_provided(void **state); void cmd_connect_fail_message(void **state); void cmd_connect_lowercases_argument(void **state); void cmd_connect_asks_password_when_not_in_account(void **state); +void cmd_connect_shows_message_when_connecting_with_account(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index b88037e2..1c6c1d0a 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -23,6 +23,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_fail_message), unit_test(cmd_connect_lowercases_argument), unit_test(cmd_connect_asks_password_when_not_in_account), + unit_test(cmd_connect_shows_message_when_connecting_with_account), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 5ec2d3cf7cf6fa6e0930c308376fc088ff4fdec2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 21:31:27 +0000 Subject: [PATCH 10/24] Added tests for connecting with account --- tests/test_cmd_connect.c | 33 ++++++++++++++++++++++++++++++++- tests/test_cmd_connect.h | 1 + tests/testsuite.c | 1 + tests/xmpp/mock_xmpp.c | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index ad76da79..54852803 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -162,6 +162,8 @@ void cmd_connect_asks_password_when_not_in_account(void **state) will_return(ui_ask_password, strdup("password")); expect_any(cons_show, output); + + expect_any(jabber_connect_with_account, account); will_return(jabber_connect_with_account, JABBER_CONNECTING); gboolean result = cmd_connect(args, *help); @@ -187,6 +189,8 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); expect_string(cons_show, output, "Connecting with account jabber_org as user@jabber.org/laptop"); + + expect_any(jabber_connect_with_account, account); will_return(jabber_connect_with_account, JABBER_CONNECTING); gboolean result = cmd_connect(args, *help); @@ -194,5 +198,32 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) free(help); free(account); - +} + +void cmd_connect_connects_with_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "jabber_org", NULL }; + ProfAccount *account = malloc(sizeof(ProfAccount)); + account->password = "password"; + account->name = "jabber_org"; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_any(accounts_get_account, name); + will_return(accounts_get_account, account); + + will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); + + expect_any(cons_show, output); + + expect_memory(jabber_connect_with_account, account, account, sizeof(ProfAccount)); + will_return(jabber_connect_with_account, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); + free(account); + } diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index 9bb525cf..967d0652 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -8,3 +8,4 @@ void cmd_connect_fail_message(void **state); void cmd_connect_lowercases_argument(void **state); void cmd_connect_asks_password_when_not_in_account(void **state); void cmd_connect_shows_message_when_connecting_with_account(void **state); +void cmd_connect_connects_with_account(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 1c6c1d0a..060fe8b2 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -24,6 +24,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_lowercases_argument), unit_test(cmd_connect_asks_password_when_not_in_account), unit_test(cmd_connect_shows_message_when_connecting_with_account), + unit_test(cmd_connect_connects_with_account), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c index 26c9c72d..8907c13e 100644 --- a/tests/xmpp/mock_xmpp.c +++ b/tests/xmpp/mock_xmpp.c @@ -40,6 +40,7 @@ jabber_conn_status_t jabber_connect_with_details(const char * const jid, jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account) { + check_expected(account); return (jabber_conn_status_t)mock(); } From 6d75ebb8e9ebd292a57adb54ff22cac52b463dbd Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 22:00:42 +0000 Subject: [PATCH 11/24] Test account free'd after connect --- src/command/commands.c | 2 +- tests/config/mock_accounts.c | 5 ++++- tests/test_cmd_connect.c | 34 +++++++++++++++++++++++++++++++++- tests/test_cmd_connect.h | 1 + tests/testsuite.c | 1 + 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 910c57d5..c48dc1a1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -78,6 +78,7 @@ cmd_connect(gchar **args, struct cmd_help_t help) } cons_show("Connecting with account %s as %s", account->name, jid); conn_status = jabber_connect_with_account(account); + accounts_free_account(account); } else { char *passwd = ui_ask_password(); jid = strdup(lower); @@ -92,7 +93,6 @@ cmd_connect(gchar **args, struct cmd_help_t help) log_debug("Connection attempt for %s failed", jid); } - accounts_free_account(account); free(jid); result = TRUE; diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index e2732acb..960cf211 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -54,7 +54,10 @@ ProfAccount* accounts_get_account(const char * const name) return (ProfAccount *)mock(); } -void accounts_free_account(ProfAccount *account) {} +void accounts_free_account(ProfAccount *account) +{ + check_expected(account); +} gboolean accounts_enable(const char * const name) { diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 54852803..3625a521 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -166,6 +166,8 @@ void cmd_connect_asks_password_when_not_in_account(void **state) expect_any(jabber_connect_with_account, account); will_return(jabber_connect_with_account, JABBER_CONNECTING); + expect_any(accounts_free_account, account); + gboolean result = cmd_connect(args, *help); assert_true(result); @@ -193,6 +195,8 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) expect_any(jabber_connect_with_account, account); will_return(jabber_connect_with_account, JABBER_CONNECTING); + expect_any(accounts_free_account, account); + gboolean result = cmd_connect(args, *help); assert_true(result); @@ -220,10 +224,38 @@ void cmd_connect_connects_with_account(void **state) expect_memory(jabber_connect_with_account, account, account, sizeof(ProfAccount)); will_return(jabber_connect_with_account, JABBER_CONNECTING); + expect_any(accounts_free_account, account); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); + free(account); +} + +void cmd_connect_frees_account_after_connecting(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "jabber_org", NULL }; + ProfAccount *account = malloc(sizeof(ProfAccount)); + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_any(accounts_get_account, name); + will_return(accounts_get_account, account); + + will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); + + expect_any(cons_show, output); + + expect_any(jabber_connect_with_account, account); + will_return(jabber_connect_with_account, JABBER_CONNECTING); + + expect_memory(accounts_free_account, account, account, sizeof(ProfAccount)); + gboolean result = cmd_connect(args, *help); assert_true(result); free(help); free(account); - } diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index 967d0652..2ee1a91b 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -9,3 +9,4 @@ void cmd_connect_lowercases_argument(void **state); void cmd_connect_asks_password_when_not_in_account(void **state); void cmd_connect_shows_message_when_connecting_with_account(void **state); void cmd_connect_connects_with_account(void **state); +void cmd_connect_frees_account_after_connecting(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 060fe8b2..ae4ab61e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -25,6 +25,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_asks_password_when_not_in_account), unit_test(cmd_connect_shows_message_when_connecting_with_account), unit_test(cmd_connect_connects_with_account), + unit_test(cmd_connect_frees_account_after_connecting), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 683da12c3aae53bb02ede52c924300580be9cc80 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 22:28:22 +0000 Subject: [PATCH 12/24] Added cmd_account test --- Makefile.am | 1 + tests/test_cmd_account.c | 49 ++++++++++++++++++++++++++++++++++++++++ tests/test_cmd_account.h | 2 ++ tests/testsuite.c | 4 ++++ tests/ui/mock_ui.c | 7 +++++- 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/test_cmd_account.c create mode 100644 tests/test_cmd_account.h diff --git a/Makefile.am b/Makefile.am index a4cc2df8..436d215c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,6 +67,7 @@ test_sources = \ tests/test_autocomplete.c \ tests/test_common.c \ tests/test_cmd_connect.c \ + tests/test_cmd_account.c \ tests/test_cmd_rooms.c \ tests/test_history.c \ tests/test_jid.c \ diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c new file mode 100644 index 00000000..a857ca1c --- /dev/null +++ b/tests/test_cmd_account.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "xmpp/xmpp.h" +#include "command/commands.h" + +void cmd_account_shows_usage_when_not_connected_and_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_shows_account_when_connected_and_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + ProfAccount *account = malloc(sizeof(ProfAccount)); + 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"); + will_return(accounts_get_account, account); + + expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); + + expect_any(accounts_free_account, account); + + 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 new file mode 100644 index 00000000..30944fe4 --- /dev/null +++ b/tests/test_cmd_account.h @@ -0,0 +1,2 @@ +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); diff --git a/tests/testsuite.c b/tests/testsuite.c index ae4ab61e..73c54014 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -6,6 +6,7 @@ #include "test_autocomplete.h" #include "test_common.h" #include "test_cmd_connect.h" +#include "test_cmd_account.h" #include "test_cmd_rooms.h" #include "test_history.h" #include "test_jid.h" @@ -27,6 +28,9 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_connects_with_account), unit_test(cmd_connect_frees_account_after_connecting), + 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_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), unit_test(cmd_rooms_shows_message_when_connecting), diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index 33b6f1b8..5d83bcea 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -218,7 +218,12 @@ void cons_show_chat_prefs(void) {} void cons_show_log_prefs(void) {} void cons_show_presence_prefs(void) {} void cons_show_connection_prefs(void) {} -void cons_show_account(ProfAccount *account) {} + +void cons_show_account(ProfAccount *account) +{ + check_expected(account); +} + void cons_debug(const char * const msg, ...) {} void cons_show_time(void) {} void cons_show_word(const char * const word) {} From 6f060b583ee88f9d9c8f56b7a3b74e558462c3db Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:07:53 +0000 Subject: [PATCH 13/24] 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) {} From 8aaca1054f8c34fe83549dba6fbf2579e8dd850c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:17:35 +0000 Subject: [PATCH 14/24] Added "/account show" test when no account supplied --- tests/test_cmd_account.c | 16 +++++++++++++++- tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 33ba348b..ee4fb673 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -53,7 +53,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) void cmd_account_list_shows_accounts(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "list" }; + gchar *args[] = { "list", NULL }; gchar **accounts = malloc(sizeof(gchar *) * 4); accounts[0] = strdup("account1"); @@ -70,3 +70,17 @@ void cmd_account_list_shows_accounts(void **state) free(help); } + +void cmd_account_show_shows_usage_when_no_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "show", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + 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 2232b6aa..682c1c4a 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -1,3 +1,4 @@ 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); +void cmd_account_show_shows_usage_when_no_arg(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index f594a35e..3d62f84f 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -31,6 +31,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_account_show_shows_usage_when_no_arg), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 838e6e1f5bdf5b26524a2404b620fffe00394cd5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:22:22 +0000 Subject: [PATCH 15/24] Test "/account show" when no account does not exist --- tests/test_cmd_account.c | 17 +++++++++++++++++ tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + 3 files changed, 19 insertions(+) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index ee4fb673..33568bf8 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -84,3 +84,20 @@ void cmd_account_show_shows_usage_when_no_arg(void **state) free(help); } + +void cmd_account_show_shows_message_when_account_does_not_exist(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "show", "account_name" }; + + expect_string(accounts_get_account, name, "account_name"); + will_return(accounts_get_account, NULL); + + expect_string(cons_show, output, "No such account."); + expect_string(cons_show, output, ""); + + 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 682c1c4a..b321780c 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -2,3 +2,4 @@ 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); void cmd_account_show_shows_usage_when_no_arg(void **state); +void cmd_account_show_shows_message_when_account_does_not_exist(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 3d62f84f..237814b0 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -32,6 +32,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_shows_account_when_connected_and_no_args), unit_test(cmd_account_list_shows_accounts), unit_test(cmd_account_show_shows_usage_when_no_arg), + unit_test(cmd_account_show_shows_message_when_account_does_not_exist), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 219780482638c7319e41c8557445fd2ff8775b57 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:26:02 +0000 Subject: [PATCH 16/24] Test "/account show " when account exists --- tests/test_cmd_account.c | 21 ++++++++++++++++++++- tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 33568bf8..1a14159d 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -78,7 +78,7 @@ void cmd_account_show_shows_usage_when_no_arg(void **state) gchar *args[] = { "show", NULL }; expect_string(cons_show, output, "Usage: some usage"); - + gboolean result = cmd_account(args, *help); assert_true(result); @@ -101,3 +101,22 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state) free(help); } + +void cmd_account_show_shows_message_when_account_exists(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "show", "account_name" }; + ProfAccount *account = malloc(sizeof(ProfAccount)); + + expect_string(accounts_get_account, name, "account_name"); + will_return(accounts_get_account, account); + + expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); + + expect_any(accounts_free_account, account); + + 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 b321780c..4109d807 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -3,3 +3,4 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state); void cmd_account_list_shows_accounts(void **state); void cmd_account_show_shows_usage_when_no_arg(void **state); void cmd_account_show_shows_message_when_account_does_not_exist(void **state); +void cmd_account_show_shows_message_when_account_exists(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 237814b0..404fa1a4 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -33,6 +33,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_list_shows_accounts), unit_test(cmd_account_show_shows_usage_when_no_arg), unit_test(cmd_account_show_shows_message_when_account_does_not_exist), + unit_test(cmd_account_show_shows_message_when_account_exists), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From bf0870afe4a73521262a5363409d4f8bbf471c62 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:30:09 +0000 Subject: [PATCH 17/24] Test "/account add" with missing arg --- tests/test_cmd_account.c | 14 ++++++++++++++ tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + 3 files changed, 16 insertions(+) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 1a14159d..842ad13f 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -120,3 +120,17 @@ void cmd_account_show_shows_message_when_account_exists(void **state) free(help); } + +void cmd_account_add_shows_usage_when_no_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "add", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + 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 4109d807..9b7a4f4b 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -4,3 +4,4 @@ void cmd_account_list_shows_accounts(void **state); void cmd_account_show_shows_usage_when_no_arg(void **state); void cmd_account_show_shows_message_when_account_does_not_exist(void **state); void cmd_account_show_shows_message_when_account_exists(void **state); +void cmd_account_add_shows_usage_when_no_arg(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 404fa1a4..2c6789be 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -34,6 +34,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_show_shows_usage_when_no_arg), unit_test(cmd_account_show_shows_message_when_account_does_not_exist), unit_test(cmd_account_show_shows_message_when_account_exists), + unit_test(cmd_account_add_shows_usage_when_no_arg), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 85629cb9a3eaf5a7c88abe4bc4de899828465590 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:36:20 +0000 Subject: [PATCH 18/24] Test "/account add " adds account --- tests/config/mock_accounts.c | 6 +++++- tests/test_cmd_account.c | 19 +++++++++++++++++-- tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index 960cf211..d2a5e75e 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -41,7 +41,11 @@ char * accounts_find_enabled(char *prefix) void accounts_reset_all_search(void) {} void accounts_reset_enabled_search(void) {} -void accounts_add(const char *jid, const char *altdomain) {} + +void accounts_add(const char *jid, const char *altdomain) +{ + check_expected(jid); +} gchar** accounts_get_list(void) { diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 842ad13f..f6f14366 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -88,7 +88,7 @@ void cmd_account_show_shows_usage_when_no_arg(void **state) void cmd_account_show_shows_message_when_account_does_not_exist(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "show", "account_name" }; + gchar *args[] = { "show", "account_name", NULL }; expect_string(accounts_get_account, name, "account_name"); will_return(accounts_get_account, NULL); @@ -105,7 +105,7 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state) void cmd_account_show_shows_message_when_account_exists(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "show", "account_name" }; + gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); expect_string(accounts_get_account, name, "account_name"); @@ -134,3 +134,18 @@ void cmd_account_add_shows_usage_when_no_arg(void **state) free(help); } + +void cmd_account_add_adds_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "add", "new_account", NULL }; + + expect_string(accounts_add, jid, "new_account"); + + expect_any_count(cons_show, output, 2); + + 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 9b7a4f4b..be3a420d 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -5,3 +5,4 @@ void cmd_account_show_shows_usage_when_no_arg(void **state); void cmd_account_show_shows_message_when_account_does_not_exist(void **state); void cmd_account_show_shows_message_when_account_exists(void **state); void cmd_account_add_shows_usage_when_no_arg(void **state); +void cmd_account_add_adds_account(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 2c6789be..cdf07b73 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -35,6 +35,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_show_shows_message_when_account_does_not_exist), unit_test(cmd_account_show_shows_message_when_account_exists), unit_test(cmd_account_add_shows_usage_when_no_arg), + unit_test(cmd_account_add_adds_account), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From b2f4570886dd5c69ccd62fe8d39b4a51b8df356f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:39:04 +0000 Subject: [PATCH 19/24] Test "/account add" shows message on success --- tests/test_cmd_account.c | 16 ++++++++++++++++ tests/test_cmd_account.h | 1 + tests/testsuite.c | 1 + 3 files changed, 18 insertions(+) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index f6f14366..6a6cb062 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -149,3 +149,19 @@ void cmd_account_add_adds_account(void **state) free(help); } + +void cmd_account_add_shows_message(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "add", "new_account", NULL }; + + expect_any(accounts_add, jid); + + expect_string(cons_show, output, "Account created.");; + expect_string(cons_show, output, ""); + + 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 be3a420d..5a8e552d 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -6,3 +6,4 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state); void cmd_account_show_shows_message_when_account_exists(void **state); void cmd_account_add_shows_usage_when_no_arg(void **state); void cmd_account_add_adds_account(void **state); +void cmd_account_add_shows_message(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index cdf07b73..a199d2d7 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -36,6 +36,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_show_shows_message_when_account_exists), unit_test(cmd_account_add_shows_usage_when_no_arg), unit_test(cmd_account_add_adds_account), + unit_test(cmd_account_add_shows_message), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 4216949b2ea220b0e32fb740d7d7f871f42ab747 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:51:29 +0000 Subject: [PATCH 20/24] Added tests for "/account enable" --- tests/config/mock_accounts.c | 1 + tests/test_cmd_account.c | 64 ++++++++++++++++++++++++++++++++++++ tests/test_cmd_account.h | 4 +++ tests/testsuite.c | 4 +++ 4 files changed, 73 insertions(+) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index d2a5e75e..792712ba 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -65,6 +65,7 @@ void accounts_free_account(ProfAccount *account) gboolean accounts_enable(const char * const name) { + check_expected(name); return (gboolean)mock(); } diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 6a6cb062..04b0e19a 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -165,3 +165,67 @@ void cmd_account_add_shows_message(void **state) free(help); } + +void cmd_account_enable_shows_usage_when_no_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "enable", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_enable_enables_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "enable", "account_name" }; + + expect_string(accounts_enable, name, "account_name"); + will_return(accounts_enable, TRUE); + + expect_any_count(cons_show, output, 2); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_enable_shows_message_when_enabled(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "enable", "account_name" }; + + expect_any(accounts_enable, name); + will_return(accounts_enable, TRUE); + + expect_string(cons_show, output, "Account enabled."); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "enable", "account_name" }; + + expect_any(accounts_enable, name); + will_return(accounts_enable, FALSE); + + expect_string(cons_show, output, "No such account: account_name"); + expect_string(cons_show, output, ""); + + 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 5a8e552d..b2b54382 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -7,3 +7,7 @@ void cmd_account_show_shows_message_when_account_exists(void **state); void cmd_account_add_shows_usage_when_no_arg(void **state); void cmd_account_add_adds_account(void **state); void cmd_account_add_shows_message(void **state); +void cmd_account_enable_shows_usage_when_no_arg(void **state); +void cmd_account_enable_enables_account(void **state); +void cmd_account_enable_shows_message_when_enabled(void **state); +void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index a199d2d7..6d4190bd 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -37,6 +37,10 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_add_shows_usage_when_no_arg), unit_test(cmd_account_add_adds_account), unit_test(cmd_account_add_shows_message), + unit_test(cmd_account_enable_shows_usage_when_no_arg), + unit_test(cmd_account_enable_enables_account), + unit_test(cmd_account_enable_shows_message_when_enabled), + unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 3c0bbed7178168d9be2cc6a6e120994ba2d0b96b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Dec 2013 23:55:59 +0000 Subject: [PATCH 21/24] Added tests for "/account disable" --- tests/config/mock_accounts.c | 1 + tests/test_cmd_account.c | 64 ++++++++++++++++++++++++++++++++++++ tests/test_cmd_account.h | 4 +++ tests/testsuite.c | 4 +++ 4 files changed, 73 insertions(+) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index 792712ba..c0faa5ab 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -71,6 +71,7 @@ gboolean accounts_enable(const char * const name) gboolean accounts_disable(const char * const name) { + check_expected(name); return (gboolean)mock(); } diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 04b0e19a..a20111f1 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -229,3 +229,67 @@ void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) free(help); } + +void cmd_account_disable_shows_usage_when_no_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "disable", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_disable_disables_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "disable", "account_name" }; + + expect_string(accounts_disable, name, "account_name"); + will_return(accounts_disable, TRUE); + + expect_any_count(cons_show, output, 2); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_disable_shows_message_when_disabled(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "disable", "account_name" }; + + expect_any(accounts_disable, name); + will_return(accounts_disable, TRUE); + + expect_string(cons_show, output, "Account disabled."); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "disable", "account_name" }; + + expect_any(accounts_disable, name); + will_return(accounts_disable, FALSE); + + expect_string(cons_show, output, "No such account: account_name"); + expect_string(cons_show, output, ""); + + 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 b2b54382..f04485bb 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -11,3 +11,7 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state); void cmd_account_enable_enables_account(void **state); void cmd_account_enable_shows_message_when_enabled(void **state); void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state); +void cmd_account_disable_shows_usage_when_no_arg(void **state); +void cmd_account_disable_disables_account(void **state); +void cmd_account_disable_shows_message_when_disabled(void **state); +void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 6d4190bd..864cea2e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -41,6 +41,10 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_enable_enables_account), unit_test(cmd_account_enable_shows_message_when_enabled), unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist), + unit_test(cmd_account_disable_shows_usage_when_no_arg), + unit_test(cmd_account_disable_disables_account), + unit_test(cmd_account_disable_shows_message_when_disabled), + unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From e14b4ef558ccec2f77a42a192b74b0eba0cf541a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Dec 2013 00:12:07 +0000 Subject: [PATCH 22/24] Added tests for "/account rename" --- tests/config/mock_accounts.c | 2 + tests/test_cmd_account.c | 93 +++++++++++++++++++++++++++++++++--- tests/test_cmd_account.h | 5 ++ tests/testsuite.c | 5 ++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index c0faa5ab..b8cc9596 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -78,6 +78,8 @@ gboolean accounts_disable(const char * const name) gboolean accounts_rename(const char * const account_name, const char * const new_name) { + check_expected(account_name); + check_expected(new_name); return (gboolean)mock(); } diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index a20111f1..b17d7b03 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -183,7 +183,7 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state) void cmd_account_enable_enables_account(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "enable", "account_name" }; + gchar *args[] = { "enable", "account_name", NULL }; expect_string(accounts_enable, name, "account_name"); will_return(accounts_enable, TRUE); @@ -199,7 +199,7 @@ void cmd_account_enable_enables_account(void **state) void cmd_account_enable_shows_message_when_enabled(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "enable", "account_name" }; + gchar *args[] = { "enable", "account_name", NULL }; expect_any(accounts_enable, name); will_return(accounts_enable, TRUE); @@ -216,7 +216,7 @@ void cmd_account_enable_shows_message_when_enabled(void **state) void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "enable", "account_name" }; + gchar *args[] = { "enable", "account_name", NULL }; expect_any(accounts_enable, name); will_return(accounts_enable, FALSE); @@ -247,7 +247,7 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state) void cmd_account_disable_disables_account(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "disable", "account_name" }; + gchar *args[] = { "disable", "account_name", NULL }; expect_string(accounts_disable, name, "account_name"); will_return(accounts_disable, TRUE); @@ -263,7 +263,7 @@ void cmd_account_disable_disables_account(void **state) void cmd_account_disable_shows_message_when_disabled(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "disable", "account_name" }; + gchar *args[] = { "disable", "account_name", NULL }; expect_any(accounts_disable, name); will_return(accounts_disable, TRUE); @@ -280,7 +280,7 @@ void cmd_account_disable_shows_message_when_disabled(void **state) void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "disable", "account_name" }; + gchar *args[] = { "disable", "account_name", NULL }; expect_any(accounts_disable, name); will_return(accounts_disable, FALSE); @@ -293,3 +293,84 @@ void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) free(help); } + +void cmd_account_rename_shows_usage_when_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "rename", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_shows_usage_when_one_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "rename", "original_name", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_renames_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "rename", "original_name", "new_name", NULL }; + + expect_string(accounts_rename, account_name, "original_name"); + expect_string(accounts_rename, new_name, "new_name"); + will_return(accounts_rename, TRUE); + + expect_any_count(cons_show, output, 2); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_shows_message_when_renamed(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "rename", "original_name", "new_name", NULL }; + + expect_string(accounts_rename, account_name, "original_name"); + expect_string(accounts_rename, new_name, "new_name"); + will_return(accounts_rename, TRUE); + + expect_string(cons_show, output, "Account renamed."); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_shows_message_when_not_renamed(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "rename", "original_name", "new_name", NULL }; + + expect_string(accounts_rename, account_name, "original_name"); + expect_string(accounts_rename, new_name, "new_name"); + will_return(accounts_rename, FALSE); + + expect_string(cons_show, output, "Either account original_name doesn't exist, or account new_name already exists."); + expect_string(cons_show, output, ""); + + 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 f04485bb..ca72af36 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -15,3 +15,8 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state); void cmd_account_disable_disables_account(void **state); void cmd_account_disable_shows_message_when_disabled(void **state); void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state); +void cmd_account_rename_shows_usage_when_no_args(void **state); +void cmd_account_rename_shows_usage_when_one_arg(void **state); +void cmd_account_rename_renames_account(void **state); +void cmd_account_rename_shows_message_when_renamed(void **state); +void cmd_account_rename_shows_message_when_not_renamed(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 864cea2e..bba13a7e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -45,6 +45,11 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_disable_disables_account), unit_test(cmd_account_disable_shows_message_when_disabled), unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist), + unit_test(cmd_account_rename_shows_usage_when_no_args), + unit_test(cmd_account_rename_shows_usage_when_one_arg), + unit_test(cmd_account_rename_renames_account), + unit_test(cmd_account_rename_shows_message_when_renamed), + unit_test(cmd_account_rename_shows_message_when_not_renamed), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), From 52d15242abe9add6eef0accef8d91b213e826171 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Dec 2013 00:18:38 +0000 Subject: [PATCH 23/24] Use expect_any when testing something else in cmd_account tests --- tests/test_cmd_account.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index b17d7b03..95924f59 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -36,7 +36,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) will_return(jabber_get_account_name, "account_name"); - expect_string(accounts_get_account, name, "account_name"); + expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); @@ -90,7 +90,7 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; - expect_string(accounts_get_account, name, "account_name"); + expect_any(accounts_get_account, name); will_return(accounts_get_account, NULL); expect_string(cons_show, output, "No such account."); @@ -108,7 +108,7 @@ void cmd_account_show_shows_message_when_account_exists(void **state) gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); - expect_string(accounts_get_account, name, "account_name"); + expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); @@ -344,8 +344,8 @@ void cmd_account_rename_shows_message_when_renamed(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "rename", "original_name", "new_name", NULL }; - expect_string(accounts_rename, account_name, "original_name"); - expect_string(accounts_rename, new_name, "new_name"); + expect_any(accounts_rename, account_name); + expect_any(accounts_rename, new_name); will_return(accounts_rename, TRUE); expect_string(cons_show, output, "Account renamed."); @@ -362,8 +362,8 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "rename", "original_name", "new_name", NULL }; - expect_string(accounts_rename, account_name, "original_name"); - expect_string(accounts_rename, new_name, "new_name"); + expect_any(accounts_rename, account_name); + expect_any(accounts_rename, new_name); will_return(accounts_rename, FALSE); expect_string(cons_show, output, "Either account original_name doesn't exist, or account new_name already exists."); From 52f6ad6fe19149a351fba673aa378508cd7c0558 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Dec 2013 01:04:25 +0000 Subject: [PATCH 24/24] Added validation tests for "/account set" and "/account set jid" --- tests/config/mock_accounts.c | 16 +++- tests/test_cmd_account.c | 146 +++++++++++++++++++++++++++++++++++ tests/test_cmd_account.h | 8 ++ tests/testsuite.c | 96 ++++++++++++----------- 4 files changed, 220 insertions(+), 46 deletions(-) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index b8cc9596..8cd8b93e 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -85,12 +85,24 @@ gboolean accounts_rename(const char * const account_name, gboolean accounts_account_exists(const char * const account_name) { + check_expected(account_name); return (gboolean)mock(); } -void accounts_set_jid(const char * const account_name, const char * const value) {} +void accounts_set_jid(const char * const account_name, const char * const value) +{ + check_expected(account_name); + check_expected(value); +} + void accounts_set_server(const char * const account_name, const char * const value) {} -void accounts_set_resource(const char * const account_name, const char * const value) {} + +void accounts_set_resource(const char * const account_name, const char * const value) +{ + check_expected(account_name); + check_expected(value); +} + void accounts_set_password(const char * const account_name, const char * const value) {} void accounts_set_muc_service(const char * const account_name, const char * const value) {} void accounts_set_muc_nick(const char * const account_name, const char * const value) {} diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 95924f59..2e43bca6 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -374,3 +374,149 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state) free(help); } + +void cmd_account_set_shows_usage_when_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_shows_usage_when_one_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_shows_usage_when_two_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "a_property", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_checks_account_exists(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL }; + + expect_string(accounts_account_exists, account_name, "a_account"); + will_return(accounts_account_exists, FALSE); + + expect_any_count(cons_show, output, 2); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_shows_message_when_account_doesnt_exist(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, FALSE); + + expect_string(cons_show, output, "Account a_account doesn't exist"); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_jid_shows_message_for_malformed_jid(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, TRUE); + + expect_string(cons_show, output, "Malformed jid: @malformed"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_jid_sets_barejid(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, TRUE); + + expect_string(accounts_set_jid, account_name, "a_account"); + expect_string(accounts_set_jid, value, "a_local@a_domain"); + + expect_string(cons_show, output, "Updated jid for account a_account: a_local@a_domain"); + + expect_any(accounts_set_resource, account_name); + expect_any(accounts_set_resource, value); + + expect_any(cons_show, output); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_jid_sets_resource(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, TRUE); + + expect_any(accounts_set_jid, account_name); + expect_any(accounts_set_jid, value); + + expect_any(cons_show, output); + + expect_string(accounts_set_resource, account_name, "a_account"); + expect_string(accounts_set_resource, value, "a_resource"); + + expect_string(cons_show, output, "Updated resource for account a_account: a_resource"); + expect_string(cons_show, output, ""); + + 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 ca72af36..62783609 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -20,3 +20,11 @@ void cmd_account_rename_shows_usage_when_one_arg(void **state); void cmd_account_rename_renames_account(void **state); void cmd_account_rename_shows_message_when_renamed(void **state); void cmd_account_rename_shows_message_when_not_renamed(void **state); +void cmd_account_set_shows_usage_when_no_args(void **state); +void cmd_account_set_shows_usage_when_one_arg(void **state); +void cmd_account_set_shows_usage_when_two_args(void **state); +void cmd_account_set_checks_account_exists(void **state); +void cmd_account_set_shows_message_when_account_doesnt_exist(void **state); +void cmd_account_set_jid_shows_message_for_malformed_jid(void **state); +void cmd_account_set_jid_sets_barejid(void **state); +void cmd_account_set_jid_sets_resource(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index bba13a7e..44c014df 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -15,50 +15,6 @@ 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_connect_when_no_account), - unit_test(cmd_connect_with_altdomain_when_provided), - unit_test(cmd_connect_fail_message), - unit_test(cmd_connect_lowercases_argument), - unit_test(cmd_connect_asks_password_when_not_in_account), - unit_test(cmd_connect_shows_message_when_connecting_with_account), - unit_test(cmd_connect_connects_with_account), - unit_test(cmd_connect_frees_account_after_connecting), - - 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_account_show_shows_usage_when_no_arg), - unit_test(cmd_account_show_shows_message_when_account_does_not_exist), - unit_test(cmd_account_show_shows_message_when_account_exists), - unit_test(cmd_account_add_shows_usage_when_no_arg), - unit_test(cmd_account_add_adds_account), - unit_test(cmd_account_add_shows_message), - unit_test(cmd_account_enable_shows_usage_when_no_arg), - unit_test(cmd_account_enable_enables_account), - unit_test(cmd_account_enable_shows_message_when_enabled), - unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist), - unit_test(cmd_account_disable_shows_usage_when_no_arg), - unit_test(cmd_account_disable_disables_account), - unit_test(cmd_account_disable_shows_message_when_disabled), - unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist), - unit_test(cmd_account_rename_shows_usage_when_no_args), - unit_test(cmd_account_rename_shows_usage_when_one_arg), - unit_test(cmd_account_rename_renames_account), - unit_test(cmd_account_rename_shows_message_when_renamed), - unit_test(cmd_account_rename_shows_message_when_not_renamed), - - 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_rooms_arg_used_when_passed), - unit_test(replace_one_substr), unit_test(replace_one_substr_beginning), unit_test(replace_one_substr_end), @@ -203,6 +159,58 @@ int main(int argc, char* argv[]) { unit_test(find_twice_returns_second_when_two_match), unit_test(find_five_times_finds_fifth), unit_test(find_twice_returns_first_when_two_match_and_reset), + + 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_connect_when_no_account), + unit_test(cmd_connect_with_altdomain_when_provided), + unit_test(cmd_connect_fail_message), + unit_test(cmd_connect_lowercases_argument), + unit_test(cmd_connect_asks_password_when_not_in_account), + unit_test(cmd_connect_shows_message_when_connecting_with_account), + unit_test(cmd_connect_connects_with_account), + unit_test(cmd_connect_frees_account_after_connecting), + + 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_rooms_arg_used_when_passed), + + 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_account_show_shows_usage_when_no_arg), + unit_test(cmd_account_show_shows_message_when_account_does_not_exist), + unit_test(cmd_account_show_shows_message_when_account_exists), + unit_test(cmd_account_add_shows_usage_when_no_arg), + unit_test(cmd_account_add_adds_account), + unit_test(cmd_account_add_shows_message), + unit_test(cmd_account_enable_shows_usage_when_no_arg), + unit_test(cmd_account_enable_enables_account), + unit_test(cmd_account_enable_shows_message_when_enabled), + unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist), + unit_test(cmd_account_disable_shows_usage_when_no_arg), + unit_test(cmd_account_disable_disables_account), + unit_test(cmd_account_disable_shows_message_when_disabled), + unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist), + unit_test(cmd_account_rename_shows_usage_when_no_args), + unit_test(cmd_account_rename_shows_usage_when_one_arg), + unit_test(cmd_account_rename_renames_account), + unit_test(cmd_account_rename_shows_message_when_renamed), + unit_test(cmd_account_rename_shows_message_when_not_renamed), + unit_test(cmd_account_set_shows_usage_when_no_args), + unit_test(cmd_account_set_shows_usage_when_one_arg), + unit_test(cmd_account_set_shows_usage_when_two_args), + unit_test(cmd_account_set_checks_account_exists), + unit_test(cmd_account_set_shows_message_when_account_doesnt_exist), + unit_test(cmd_account_set_jid_shows_message_for_malformed_jid), + unit_test(cmd_account_set_jid_sets_barejid), + unit_test(cmd_account_set_jid_sets_resource), }; return run_tests(tests); }