diff options
author | James Booth <boothj5@gmail.com> | 2013-12-26 13:37:22 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-12-26 13:37:22 +0000 |
commit | 8685e78c86ecd579078aaad961bd23eaba5e3e84 (patch) | |
tree | 9730da1a98c7b686fb05235f480ece90e4522cf2 /tests | |
parent | b83b262d47ea62330e1e1a21e3da12aef08e981d (diff) | |
download | profani-tty-8685e78c86ecd579078aaad961bd23eaba5e3e84.tar.gz |
Added mock_accounts and fixed tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/config/mock_accounts.c | 482 | ||||
-rw-r--r-- | tests/config/mock_accounts.h | 90 | ||||
-rw-r--r-- | tests/test_cmd_account.c | 270 | ||||
-rw-r--r-- | tests/test_cmd_connect.c | 58 | ||||
-rw-r--r-- | tests/test_cmd_rooms.c | 7 |
5 files changed, 688 insertions, 219 deletions
diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index 929a3b51..a40d4a67 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -23,168 +23,558 @@ #include <glib.h> #include <setjmp.h> #include <cmocka.h> +#include <string.h> #include "config/accounts.h" -void accounts_load(void) {} -void accounts_close(void) {} +// mocks and stubs -char * accounts_find_all(char *prefix) +static ProfAccount * +_mock_accounts_get_account(const char * const name) { - return (char *)mock(); + check_expected(name); + return (ProfAccount *)mock(); } -char * accounts_find_enabled(char *prefix) +static char * +_mock_accounts_create_full_jid(ProfAccount *account) { + check_expected(account); return (char *)mock(); } -void accounts_reset_all_search(void) {} -void accounts_reset_enabled_search(void) {} +void +_stub_accounts_free_account(ProfAccount *account) +{ + // do nothing +} -void accounts_add(const char *jid, const char *altdomain) +void +_mock_accounts_free_account(ProfAccount *account) { - check_expected(jid); + check_expected(account); } -gchar** accounts_get_list(void) +gchar ** +_mock_accounts_get_list(void) { return (gchar **)mock(); } -ProfAccount* accounts_get_account(const char * const name) +void +_mock_accounts_add(const char *account_name, const char *altdomain) { - check_expected(name); - return (ProfAccount *)mock(); + check_expected(account_name); + check_expected(altdomain); } -void accounts_free_account(ProfAccount *account) +void +_stub_accounts_add(const char *account_name, const char *altdomain) { - check_expected(account); + // do nothing } -gboolean accounts_enable(const char * const name) +static gboolean +_mock_accounts_enable(const char * const name) { check_expected(name); return (gboolean)mock(); } -gboolean accounts_disable(const char * const name) +static gboolean +_mock_accounts_disable(const char * const name) { check_expected(name); return (gboolean)mock(); } -gboolean accounts_rename(const char * const account_name, - const char * const new_name) +static gboolean +_mock_accounts_rename(const char * const account_name, const char * const new_name) { check_expected(account_name); check_expected(new_name); return (gboolean)mock(); } -gboolean accounts_account_exists(const char * const account_name) +static gboolean +_mock_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) +static void +_mock_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) +static void +_stub_accounts_set_jid(const char * const account_name, const char * const value) { - check_expected(account_name); - check_expected(value); + // do nothing } -void accounts_set_resource(const char * const account_name, const char * const value) +static void +_mock_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) +static void +_stub_accounts_set_resource(const char * const account_name, const char * const value) +{ + // do nothing +} + +static void +_mock_accounts_set_server(const char * const account_name, const char * const value) { check_expected(account_name); check_expected(value); } -void accounts_set_muc_service(const char * const account_name, const char * const value) +static void +_stub_accounts_set_server(const char * const account_name, const char * const value) +{ + // do nothing +} + +static void +_mock_accounts_set_password(const char * const account_name, const char * const value) { check_expected(account_name); check_expected(value); } -void accounts_set_muc_nick(const char * const account_name, const char * const value) +static void +_stub_accounts_set_password(const char * const account_name, const char * const value) +{ + // do nothing +} + +static void +_mock_accounts_set_muc_service(const char * const account_name, const char * const value) { check_expected(account_name); check_expected(value); } -void accounts_set_last_presence(const char * const account_name, const char * const value) {} +static void +_stub_accounts_set_muc_service(const char * const account_name, const char * const value) +{ + // do nothing +} -void accounts_set_login_presence(const char * const account_name, const char * const value) +static void +_mock_accounts_set_muc_nick(const char * const account_name, const char * const value) { check_expected(account_name); check_expected(value); } -resource_presence_t accounts_get_login_presence(const char * const account_name) +static void +_stub_accounts_set_muc_nick(const char * const account_name, const char * const value) { - return (resource_presence_t)mock(); + // do nothing } -resource_presence_t accounts_get_last_presence(const char * const account_name) +static void +_mock_accounts_set_priority_online(const char * const account_name, const gint value) { - return (resource_presence_t)mock(); + check_expected(account_name); + check_expected(value); } -void accounts_set_priority_online(const char * const account_name, const gint value) +static void +_mock_accounts_set_priority_chat(const char * const account_name, const gint value) { check_expected(account_name); check_expected(value); } -void accounts_set_priority_chat(const char * const account_name, const gint value) +static void +_mock_accounts_set_priority_away(const char * const account_name, const gint value) { check_expected(account_name); check_expected(value); } -void accounts_set_priority_away(const char * const account_name, const gint value) +static void +_mock_accounts_set_priority_xa(const char * const account_name, const gint value) { check_expected(account_name); check_expected(value); } -void accounts_set_priority_xa(const char * const account_name, const gint value) +static void +_mock_accounts_set_priority_dnd(const char * const account_name, const gint value) { check_expected(account_name); check_expected(value); } -void accounts_set_priority_dnd(const char * const account_name, const gint value) + +static void +_mock_accounts_set_login_presence(const char * const account_name, const char * const value) { check_expected(account_name); check_expected(value); } -void accounts_set_priority_all(const char * const account_name, const gint value) {} +static void +_stub_accounts_set_login_presence(const char * const account_name, const char * const value) +{ +} -gint accounts_get_priority_for_presence_type(const char * const account_name, - resource_presence_t presence_type) +// set up functions + +void +mock_accounts_get_account(void) { - return (gint)mock(); + accounts_get_account = _mock_accounts_get_account; } -void accounts_clear_password(const char * const account_name) {} +void +mock_accounts_create_full_jid(void) +{ + accounts_create_full_jid = _mock_accounts_create_full_jid; +} -char * accounts_create_full_jid(ProfAccount *account) +void +stub_accounts_free_account(void) { - return (char *)mock(); + accounts_free_account = _stub_accounts_free_account; +} + +void +mock_accounts_free_account(void) +{ + accounts_free_account = _mock_accounts_free_account; +} + +void +mock_accounts_get_list(void) +{ + accounts_get_list = _mock_accounts_get_list; +} + +void +mock_accounts_add(void) +{ + accounts_add = _mock_accounts_add; +} + +void +stub_accounts_add(void) +{ + accounts_add = _stub_accounts_add; +} + +void +mock_accounts_enable(void) +{ + accounts_enable = _mock_accounts_enable; +} + +void +mock_accounts_disable(void) +{ + accounts_disable = _mock_accounts_disable; +} + +void +mock_accounts_rename(void) +{ + accounts_rename = _mock_accounts_rename; +} + +void +mock_accounts_account_exists(void) +{ + accounts_account_exists = _mock_accounts_account_exists; +} + +void +mock_accounts_set_jid(void) +{ + accounts_set_jid = _mock_accounts_set_jid; +} + +void +stub_accounts_set_jid(void) +{ + accounts_set_jid = _stub_accounts_set_jid; +} + +void +mock_accounts_set_resource(void) +{ + accounts_set_resource = _mock_accounts_set_resource; +} + +void +stub_accounts_set_resource(void) +{ + accounts_set_resource = _stub_accounts_set_resource; +} + +void +mock_accounts_set_server(void) +{ + accounts_set_server = _mock_accounts_set_server; +} + +void +stub_accounts_set_server(void) +{ + accounts_set_server = _stub_accounts_set_server; +} + +void +mock_accounts_set_password(void) +{ + accounts_set_password = _mock_accounts_set_password; +} + +void +stub_accounts_set_password(void) +{ + accounts_set_password = _stub_accounts_set_password; +} + +void +mock_accounts_set_muc_service(void) +{ + accounts_set_muc_service = _mock_accounts_set_muc_service; +} + +void +stub_accounts_set_muc_service(void) +{ + accounts_set_muc_service = _stub_accounts_set_muc_service; +} + +void +mock_accounts_set_muc_nick(void) +{ + accounts_set_muc_nick = _mock_accounts_set_muc_nick; } +void +stub_accounts_set_muc_nick(void) +{ + accounts_set_muc_nick = _stub_accounts_set_muc_nick; +} + +void +mock_accounts_set_priorities(void) +{ + accounts_set_priority_online = _mock_accounts_set_priority_online; + accounts_set_priority_chat = _mock_accounts_set_priority_chat; + accounts_set_priority_away = _mock_accounts_set_priority_away; + accounts_set_priority_xa = _mock_accounts_set_priority_xa; + accounts_set_priority_dnd = _mock_accounts_set_priority_dnd; +} + +void +mock_accounts_set_login_presence(void) +{ + accounts_set_login_presence = _mock_accounts_set_login_presence; +} + +void +stub_accounts_set_login_presence(void) +{ + accounts_set_login_presence = _stub_accounts_set_login_presence; +} + +// mock behaviours + +void +accounts_get_account_expect_and_return(const char * const name, ProfAccount *account) +{ + expect_string(_mock_accounts_get_account, name, name); + will_return(_mock_accounts_get_account, account); +} + +void +accounts_get_account_return(ProfAccount *account) +{ + expect_any(_mock_accounts_get_account, name); + will_return(_mock_accounts_get_account, account); +} + +void +accounts_create_full_jid_return(char *fulljid) +{ + expect_any(_mock_accounts_create_full_jid, account); + if (fulljid != NULL) { + will_return(_mock_accounts_create_full_jid, strdup(fulljid)); + } else { + will_return(_mock_accounts_create_full_jid, NULL); + } +} + +void +accounts_free_account_expect(ProfAccount *account) +{ + expect_memory(_mock_accounts_free_account, account, account, sizeof(ProfAccount)); +} + +void +accounts_get_list_return(gchar **accounts) +{ + will_return(_mock_accounts_get_list, accounts); +} + +void +accounts_add_expect_account_name(char *account_name) +{ + expect_any(_mock_accounts_add, altdomain); + expect_string(_mock_accounts_add, account_name, account_name); +} + +void +accounts_enable_expect(char *name) +{ + expect_string(_mock_accounts_enable, name, name); + will_return(_mock_accounts_enable, TRUE); +} + +void +accounts_enable_return(gboolean result) +{ + expect_any(_mock_accounts_enable, name); + will_return(_mock_accounts_enable, result); +} + +void +accounts_disable_expect(char *name) +{ + expect_string(_mock_accounts_disable, name, name); + will_return(_mock_accounts_disable, TRUE); +} + +void +accounts_disable_return(gboolean result) +{ + expect_any(_mock_accounts_disable, name); + will_return(_mock_accounts_disable, result); +} + +void +accounts_rename_expect(char *account_name, char *new_name) +{ + expect_string(_mock_accounts_rename, account_name, account_name); + expect_string(_mock_accounts_rename, new_name, new_name); + will_return(_mock_accounts_rename, TRUE); +} + +void +accounts_rename_return(gboolean result) +{ + expect_any(_mock_accounts_rename, account_name); + expect_any(_mock_accounts_rename, new_name); + will_return(_mock_accounts_rename, result); +} + +void +accounts_account_exists_expect(char *account_name) +{ + expect_string(_mock_accounts_account_exists, account_name, account_name); + will_return(_mock_accounts_account_exists, TRUE); +} + +void +accounts_account_exists_return(gboolean result) +{ + expect_any(_mock_accounts_account_exists, account_name); + will_return(_mock_accounts_account_exists, result); +} + +void +accounts_set_jid_expect(char *account_name, char *jid) +{ + expect_string(_mock_accounts_set_jid, account_name, account_name); + expect_string(_mock_accounts_set_jid, value, jid); +} + +void +accounts_set_resource_expect(char *account_name, char *resource) +{ + expect_string(_mock_accounts_set_resource, account_name, account_name); + expect_string(_mock_accounts_set_resource, value, resource); +} + +void +accounts_set_server_expect(char *account_name, char *server) +{ + expect_string(_mock_accounts_set_server, account_name, account_name); + expect_string(_mock_accounts_set_server, value, server); +} + +void +accounts_set_password_expect(char *account_name, char *password) +{ + expect_string(_mock_accounts_set_password, account_name, account_name); + expect_string(_mock_accounts_set_password, value, password); +} + +void +accounts_set_muc_service_expect(char *account_name, char *service) +{ + expect_string(_mock_accounts_set_muc_service, account_name, account_name); + expect_string(_mock_accounts_set_muc_service, value, service); +} + +void +accounts_set_muc_nick_expect(char *account_name, char *nick) +{ + expect_string(_mock_accounts_set_muc_nick, account_name, account_name); + expect_string(_mock_accounts_set_muc_nick, value, nick); +} + +void +accounts_set_priority_online_expect(char *account_name, gint priority) +{ + expect_string(_mock_accounts_set_priority_online, account_name, account_name); + expect_value(_mock_accounts_set_priority_online, value, priority); +} + +void +accounts_set_priority_chat_expect(char *account_name, gint priority) +{ + expect_string(_mock_accounts_set_priority_chat, account_name, account_name); + expect_value(_mock_accounts_set_priority_chat, value, priority); +} + +void +accounts_set_priority_away_expect(char *account_name, gint priority) +{ + expect_string(_mock_accounts_set_priority_away, account_name, account_name); + expect_value(_mock_accounts_set_priority_away, value, priority); +} + +void +accounts_set_priority_xa_expect(char *account_name, gint priority) +{ + expect_string(_mock_accounts_set_priority_xa, account_name, account_name); + expect_value(_mock_accounts_set_priority_xa, value, priority); +} + +void +accounts_set_priority_dnd_expect(char *account_name, gint priority) +{ + expect_string(_mock_accounts_set_priority_dnd, account_name, account_name); + expect_value(_mock_accounts_set_priority_dnd, value, priority); +} + +void +accounts_set_login_presence_expect(char *account_name, char *presence) +{ + expect_string(_mock_accounts_set_login_presence, account_name, account_name); + expect_string(_mock_accounts_set_login_presence, value, presence); +} diff --git a/tests/config/mock_accounts.h b/tests/config/mock_accounts.h new file mode 100644 index 00000000..84bfcc0a --- /dev/null +++ b/tests/config/mock_accounts.h @@ -0,0 +1,90 @@ +/* + * mock_accounts.h + * + * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + +void mock_accounts_get_account(void); +void accounts_get_account_expect_and_return(const char * const name, ProfAccount *account); +void accounts_get_account_return(ProfAccount *account); + +void mock_accounts_create_full_jid(void); +void accounts_create_full_jid_return(char *fulljid); + +void mock_accounts_free_account(void); +void stub_accounts_free_account(void); +void accounts_free_account_expect(ProfAccount *account); + +void mock_accounts_get_list(void); +void accounts_get_list_return(gchar **accounts); + +void mock_accounts_add(void); +void stub_accounts_add(void); +void accounts_add_expect_account_name(char *account_name); + +void mock_accounts_enable(void); +void accounts_enable_expect(char *name); +void accounts_enable_return(gboolean result); + +void mock_accounts_disable(void); +void accounts_disable_expect(char *name); +void accounts_disable_return(gboolean result); + +void mock_accounts_rename(void); +void accounts_rename_expect(char *account_name, char *new_name); +void accounts_rename_return(gboolean result); + +void mock_accounts_account_exists(void); +void accounts_account_exists_expect(char *account_name); +void accounts_account_exists_return(gboolean result); + +void mock_accounts_set_jid(void); +void stub_accounts_set_jid(void); +void accounts_set_jid_expect(char *account_name, char *jid); + +void mock_accounts_set_resource(void); +void stub_accounts_set_resource(void); +void accounts_set_resource_expect(char *account_name, char *resource); + +void mock_accounts_set_server(void); +void stub_accounts_set_server(void); +void accounts_set_server_expect(char *account_name, char *server); + +void mock_accounts_set_password(void); +void stub_accounts_set_password(void); +void accounts_set_password_expect(char *account_name, char *password); + +void mock_accounts_set_muc_service(void); +void stub_accounts_set_muc_service(void); +void accounts_set_muc_service_expect(char *account_name, char *service); + +void mock_accounts_set_muc_nick(void); +void stub_accounts_set_muc_nick(void); +void accounts_set_muc_nick_expect(char *account_name, char *nick); + +void mock_accounts_set_priorities(void); +void accounts_set_priority_online_expect(char *account_name, gint priority); +void accounts_set_priority_chat_expect(char *account_name, gint priority); +void accounts_set_priority_away_expect(char *account_name, gint priority); +void accounts_set_priority_xa_expect(char *account_name, gint priority); +void accounts_set_priority_dnd_expect(char *account_name, gint priority); + +void mock_accounts_set_login_presence(void); +void stub_accounts_set_login_presence(void); +void accounts_set_login_presence_expect(char *account_name, char *presence); diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index b2650d8e..6d7a6d85 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -12,6 +12,9 @@ #include "ui/ui.h" #include "ui/mock_ui.h" +#include "config/accounts.h" +#include "config/mock_accounts.h" + #include "command/commands.h" void cmd_account_shows_usage_when_not_connected_and_no_args(void **state) @@ -34,6 +37,8 @@ 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) { mock_cons_show_account(); + mock_accounts_get_account(); + stub_accounts_free_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); ProfAccount *account = malloc(sizeof(ProfAccount)); gchar *args[] = { NULL }; @@ -41,13 +46,10 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) mock_connection_status(JABBER_CONNECTED); mock_connection_account_name("account_name"); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, account); + accounts_get_account_return(account); expect_cons_show_account(account); - expect_any(accounts_free_account, account); - gboolean result = cmd_account(args, *help); assert_true(result); @@ -58,6 +60,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) void cmd_account_list_shows_accounts(void **state) { mock_cons_show_account_list(); + mock_accounts_get_list(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "list", NULL }; @@ -67,7 +70,7 @@ void cmd_account_list_shows_accounts(void **state) accounts[2] = strdup("account3"); accounts[3] = NULL; - will_return(accounts_get_list, accounts); + accounts_get_list_return(accounts); expect_cons_show_account_list(accounts); @@ -95,11 +98,11 @@ void cmd_account_show_shows_usage_when_no_arg(void **state) void cmd_account_show_shows_message_when_account_does_not_exist(void **state) { mock_cons_show(); + mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; - expect_any(accounts_get_account, name); - will_return(accounts_get_account, NULL); + accounts_get_account_return(NULL); expect_cons_show("No such account."); expect_cons_show(""); @@ -113,17 +116,16 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state) void cmd_account_show_shows_account_when_exists(void **state) { mock_cons_show_account(); + mock_accounts_get_account(); + stub_accounts_free_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, account); + accounts_get_account_return(account); expect_cons_show_account(account); - expect_any(accounts_free_account, account); - gboolean result = cmd_account(args, *help); assert_true(result); @@ -148,10 +150,11 @@ void cmd_account_add_shows_usage_when_no_arg(void **state) void cmd_account_add_adds_account(void **state) { stub_cons_show(); + mock_accounts_add(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", "new_account", NULL }; - expect_string(accounts_add, jid, "new_account"); + accounts_add_expect_account_name("new_account"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -162,11 +165,10 @@ void cmd_account_add_adds_account(void **state) void cmd_account_add_shows_message(void **state) { mock_cons_show(); + stub_accounts_add(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", "new_account", NULL }; - expect_any(accounts_add, jid); - expect_cons_show("Account created.");; expect_cons_show(""); @@ -194,11 +196,11 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state) void cmd_account_enable_enables_account(void **state) { stub_cons_show(); + mock_accounts_enable(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "enable", "account_name", NULL }; - expect_string(accounts_enable, name, "account_name"); - will_return(accounts_enable, TRUE); + accounts_enable_expect("account_name"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -209,11 +211,11 @@ void cmd_account_enable_enables_account(void **state) void cmd_account_enable_shows_message_when_enabled(void **state) { mock_cons_show(); + mock_accounts_enable(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "enable", "account_name", NULL }; - expect_any(accounts_enable, name); - will_return(accounts_enable, TRUE); + accounts_enable_return(TRUE); expect_cons_show("Account enabled."); expect_cons_show(""); @@ -227,11 +229,11 @@ void cmd_account_enable_shows_message_when_enabled(void **state) void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) { mock_cons_show(); + mock_accounts_enable(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "enable", "account_name", NULL }; - expect_any(accounts_enable, name); - will_return(accounts_enable, FALSE); + accounts_enable_return(FALSE); expect_cons_show("No such account: account_name"); expect_cons_show(""); @@ -260,11 +262,11 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state) void cmd_account_disable_disables_account(void **state) { stub_cons_show(); + mock_accounts_disable(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "disable", "account_name", NULL }; - expect_string(accounts_disable, name, "account_name"); - will_return(accounts_disable, TRUE); + accounts_disable_expect("account_name"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -275,11 +277,11 @@ void cmd_account_disable_disables_account(void **state) void cmd_account_disable_shows_message_when_disabled(void **state) { mock_cons_show(); + mock_accounts_disable(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "disable", "account_name", NULL }; - expect_any(accounts_disable, name); - will_return(accounts_disable, TRUE); + accounts_disable_return(TRUE); expect_cons_show("Account disabled."); expect_cons_show(""); @@ -293,11 +295,11 @@ void cmd_account_disable_shows_message_when_disabled(void **state) void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) { mock_cons_show(); + mock_accounts_disable(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "disable", "account_name", NULL }; - expect_any(accounts_disable, name); - will_return(accounts_disable, FALSE); + accounts_disable_return(FALSE); expect_cons_show("No such account: account_name"); expect_cons_show(""); @@ -341,12 +343,11 @@ void cmd_account_rename_shows_usage_when_one_arg(void **state) void cmd_account_rename_renames_account(void **state) { stub_cons_show(); + mock_accounts_rename(); 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); + accounts_rename_expect("original_name", "new_name"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -357,12 +358,11 @@ void cmd_account_rename_renames_account(void **state) void cmd_account_rename_shows_message_when_renamed(void **state) { mock_cons_show(); + mock_accounts_rename(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "rename", "original_name", "new_name", NULL }; - expect_any(accounts_rename, account_name); - expect_any(accounts_rename, new_name); - will_return(accounts_rename, TRUE); + accounts_rename_return(TRUE); expect_cons_show("Account renamed."); expect_cons_show(""); @@ -376,12 +376,11 @@ void cmd_account_rename_shows_message_when_renamed(void **state) void cmd_account_rename_shows_message_when_not_renamed(void **state) { mock_cons_show(); + mock_accounts_rename(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "rename", "original_name", "new_name", NULL }; - expect_any(accounts_rename, account_name); - expect_any(accounts_rename, new_name); - will_return(accounts_rename, FALSE); + accounts_rename_return(FALSE); expect_cons_show("Either account original_name doesn't exist, or account new_name already exists."); expect_cons_show(""); @@ -440,11 +439,11 @@ void cmd_account_set_shows_usage_when_two_args(void **state) void cmd_account_set_checks_account_exists(void **state) { stub_cons_show(); + mock_accounts_account_exists(); CommandHelp *help = malloc(sizeof(CommandHelp)); 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); + accounts_account_exists_expect("a_account"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -455,11 +454,11 @@ void cmd_account_set_checks_account_exists(void **state) void cmd_account_set_shows_message_when_account_doesnt_exist(void **state) { mock_cons_show(); + mock_accounts_account_exists(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, FALSE); + accounts_account_exists_return(FALSE); expect_cons_show("Account a_account doesn't exist"); expect_cons_show(""); @@ -473,11 +472,11 @@ void cmd_account_set_shows_message_when_account_doesnt_exist(void **state) void cmd_account_set_jid_shows_message_for_malformed_jid(void **state) { mock_cons_show(); + mock_accounts_account_exists(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); expect_cons_show("Malformed jid: @malformed"); @@ -490,20 +489,18 @@ void cmd_account_set_jid_shows_message_for_malformed_jid(void **state) void cmd_account_set_jid_sets_barejid(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_jid(); + stub_accounts_set_resource(); CommandHelp *help = malloc(sizeof(CommandHelp)); 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); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_jid, account_name, "a_account"); - expect_string(accounts_set_jid, value, "a_local@a_domain"); + accounts_set_jid_expect("a_account", "a_local@a_domain"); expect_cons_show("Updated jid for account a_account: a_local@a_domain"); - expect_any(accounts_set_resource, account_name); - expect_any(accounts_set_resource, value); - expect_cons_show_calls(2); gboolean result = cmd_account(args, *help); @@ -515,19 +512,17 @@ void cmd_account_set_jid_sets_barejid(void **state) void cmd_account_set_jid_sets_resource(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_jid(); + mock_accounts_set_resource(); CommandHelp *help = malloc(sizeof(CommandHelp)); 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); + accounts_account_exists_return(TRUE); expect_cons_show_calls(1); - expect_string(accounts_set_resource, account_name, "a_account"); - expect_string(accounts_set_resource, value, "a_resource"); + accounts_set_resource_expect("a_account", "a_resource"); expect_cons_show("Updated resource for account a_account: a_resource"); expect_cons_show(""); @@ -541,14 +536,14 @@ void cmd_account_set_jid_sets_resource(void **state) void cmd_account_set_server_sets_server(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_server(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "server", "a_server", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_server, account_name, "a_account"); - expect_string(accounts_set_server, value, "a_server"); + accounts_set_server_expect("a_account", "a_server"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -559,14 +554,12 @@ void cmd_account_set_server_sets_server(void **state) void cmd_account_set_server_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_server(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "server", "a_server", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_server, account_name); - expect_any(accounts_set_server, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated server for account a_account: a_server"); expect_cons_show(""); @@ -580,14 +573,14 @@ void cmd_account_set_server_shows_message(void **state) void cmd_account_set_resource_sets_resource(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_resource(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "resource", "a_resource", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_resource, account_name, "a_account"); - expect_string(accounts_set_resource, value, "a_resource"); + accounts_set_resource_expect("a_account", "a_resource"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -598,14 +591,12 @@ void cmd_account_set_resource_sets_resource(void **state) void cmd_account_set_resource_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_resource(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "resource", "a_resource", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_resource, account_name); - expect_any(accounts_set_resource, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated resource for account a_account: a_resource"); expect_cons_show(""); @@ -619,14 +610,14 @@ void cmd_account_set_resource_shows_message(void **state) void cmd_account_set_password_sets_password(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_password(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "password", "a_password", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_password, account_name, "a_account"); - expect_string(accounts_set_password, value, "a_password"); + accounts_set_password_expect("a_account", "a_password"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -637,14 +628,12 @@ void cmd_account_set_password_sets_password(void **state) void cmd_account_set_password_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_password(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "password", "a_password", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_password, account_name); - expect_any(accounts_set_password, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated password for account a_account"); expect_cons_show(""); @@ -658,14 +647,14 @@ void cmd_account_set_password_shows_message(void **state) void cmd_account_set_muc_sets_muc(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_muc_service(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "muc", "a_muc", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_muc_service, account_name, "a_account"); - expect_string(accounts_set_muc_service, value, "a_muc"); + accounts_set_muc_service_expect("a_account", "a_muc"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -676,14 +665,12 @@ void cmd_account_set_muc_sets_muc(void **state) void cmd_account_set_muc_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_muc_service(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "muc", "a_muc", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_muc_service, account_name); - expect_any(accounts_set_muc_service, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated muc service for account a_account: a_muc"); expect_cons_show(""); @@ -697,14 +684,14 @@ void cmd_account_set_muc_shows_message(void **state) void cmd_account_set_nick_sets_nick(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_muc_nick(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "nick", "a_nick", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_muc_nick, account_name, "a_account"); - expect_string(accounts_set_muc_nick, value, "a_nick"); + accounts_set_muc_nick_expect("a_account", "a_nick"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -715,14 +702,12 @@ void cmd_account_set_nick_sets_nick(void **state) void cmd_account_set_nick_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_muc_nick(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "nick", "a_nick", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_muc_nick, account_name); - expect_any(accounts_set_muc_nick, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated muc nick for account a_account: a_nick"); expect_cons_show(""); @@ -736,11 +721,12 @@ void cmd_account_set_nick_shows_message(void **state) void cmd_account_set_status_shows_message_when_invalid_status(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_login_presence(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "bad_status", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); expect_cons_show("Invalid status: bad_status"); expect_cons_show(""); @@ -754,14 +740,14 @@ void cmd_account_set_status_shows_message_when_invalid_status(void **state) void cmd_account_set_status_sets_status_when_valid(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_login_presence(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "away", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_login_presence, account_name, "a_account"); - expect_string(accounts_set_login_presence, value, "away"); + accounts_set_login_presence_expect("a_account", "away"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -772,14 +758,14 @@ void cmd_account_set_status_sets_status_when_valid(void **state) void cmd_account_set_status_sets_status_when_last(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_login_presence(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "last", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_login_presence, account_name, "a_account"); - expect_string(accounts_set_login_presence, value, "last"); + accounts_set_login_presence_expect("a_account", "last"); gboolean result = cmd_account(args, *help); assert_true(result); @@ -790,14 +776,12 @@ void cmd_account_set_status_sets_status_when_last(void **state) void cmd_account_set_status_shows_message_when_set_valid(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_login_presence(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "away", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_login_presence, account_name); - expect_any(accounts_set_login_presence, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated login status for account a_account: away"); expect_cons_show(""); @@ -811,14 +795,12 @@ void cmd_account_set_status_shows_message_when_set_valid(void **state) void cmd_account_set_status_shows_message_when_set_last(void **state) { mock_cons_show(); + mock_accounts_account_exists(); + stub_accounts_set_login_presence(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "last", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); - - expect_any(accounts_set_login_presence, account_name); - expect_any(accounts_set_login_presence, value); + accounts_account_exists_return(TRUE); expect_cons_show("Updated login status for account a_account: last"); expect_cons_show(""); @@ -832,11 +814,11 @@ void cmd_account_set_status_shows_message_when_set_last(void **state) void cmd_account_set_invalid_presence_string_priority_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "blah", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); expect_cons_show("Invalid property: blah"); expect_cons_show(""); @@ -850,11 +832,11 @@ void cmd_account_set_invalid_presence_string_priority_shows_message(void **state void cmd_account_set_last_priority_shows_message(void **state) { mock_cons_show(); + mock_accounts_account_exists(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "last", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); expect_cons_show("Invalid property: last"); expect_cons_show(""); @@ -868,14 +850,14 @@ void cmd_account_set_last_priority_shows_message(void **state) void cmd_account_set_online_priority_sets_preference(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_priorities(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_priority_online, account_name, "a_account"); - expect_value(accounts_set_priority_online, value, 10); + accounts_set_priority_online_expect("a_account", 10); mock_connection_status(JABBER_DISCONNECTED); @@ -888,14 +870,14 @@ void cmd_account_set_online_priority_sets_preference(void **state) void cmd_account_set_chat_priority_sets_preference(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_priorities(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "chat", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_priority_chat, account_name, "a_account"); - expect_value(accounts_set_priority_chat, value, 10); + accounts_set_priority_chat_expect("a_account", 10); mock_connection_status(JABBER_DISCONNECTED); @@ -908,14 +890,14 @@ void cmd_account_set_chat_priority_sets_preference(void **state) void cmd_account_set_away_priority_sets_preference(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_priorities(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "away", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_priority_away, account_name, "a_account"); - expect_value(accounts_set_priority_away, value, 10); + accounts_set_priority_away_expect("a_account", 10); mock_connection_status(JABBER_DISCONNECTED); @@ -928,14 +910,14 @@ void cmd_account_set_away_priority_sets_preference(void **state) void cmd_account_set_xa_priority_sets_preference(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_priorities(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "xa", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_priority_xa, account_name, "a_account"); - expect_value(accounts_set_priority_xa, value, 10); + accounts_set_priority_xa_expect("a_account", 10); mock_connection_status(JABBER_DISCONNECTED); @@ -948,14 +930,14 @@ void cmd_account_set_xa_priority_sets_preference(void **state) void cmd_account_set_dnd_priority_sets_preference(void **state) { stub_cons_show(); + mock_accounts_account_exists(); + mock_accounts_set_priorities(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "dnd", "10", NULL }; - expect_any(accounts_account_exists, account_name); - will_return(accounts_account_exists, TRUE); + accounts_account_exists_return(TRUE); - expect_string(accounts_set_priority_dnd, account_name, "a_account"); - expect_value(accounts_set_priority_dnd, value, 10); + accounts_set_priority_dnd_expect("a_account", 10); mock_connection_status(JABBER_DISCONNECTED); diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 0095d144..6657c745 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -14,6 +14,8 @@ #include "command/commands.h" +#include "config/accounts.h" +#include "config/mock_accounts.h" static jabber_conn_status_t _mock_jabber_connect_with_details_no_altdomain(const char * const jid, const char * const passwd, const char * const altdomain) @@ -85,14 +87,14 @@ void cmd_connect_shows_message_when_undefined(void **state) void cmd_connect_when_no_account(void **state) { mock_cons_show(); + mock_accounts_get_account(); mock_ui_ask_password(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "user@server.org", NULL }; mock_connection_status(JABBER_DISCONNECTED); - expect_string(accounts_get_account, name, "user@server.org"); - will_return(accounts_get_account, NULL); + accounts_get_account_expect_and_return("user@server.org", NULL); mock_ui_ask_password_returns("password"); @@ -113,13 +115,13 @@ void cmd_connect_with_altdomain_when_provided(void **state) { stub_ui_ask_password(); stub_cons_show(); + mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "user@server.org", "altdomain" }; mock_connection_status(JABBER_DISCONNECTED); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, NULL); + accounts_get_account_return(NULL); jabber_connect_with_details = _mock_jabber_connect_with_details_altdomain; expect_string(_mock_jabber_connect_with_details_altdomain, altdomain, "altdomain"); @@ -136,13 +138,13 @@ void cmd_connect_fail_message(void **state) stub_cons_show(); mock_cons_show_error(); stub_ui_ask_password(); + mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "user@server.org", NULL }; mock_connection_status(JABBER_DISCONNECTED); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, NULL); + accounts_get_account_return(NULL); jabber_connect_with_details = _mock_jabber_connect_with_details_result; will_return(_mock_jabber_connect_with_details_result, JABBER_DISCONNECTED); @@ -159,13 +161,13 @@ void cmd_connect_lowercases_argument(void **state) { stub_cons_show(); stub_ui_ask_password(); + mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "USER@server.ORG", NULL }; mock_connection_status(JABBER_DISCONNECTED); - expect_string(accounts_get_account, name, "user@server.org"); - will_return(accounts_get_account, NULL); + accounts_get_account_expect_and_return("user@server.org", NULL); jabber_connect_with_details = _mock_jabber_connect_with_details_result; will_return(_mock_jabber_connect_with_details_result, JABBER_CONNECTING); @@ -180,6 +182,9 @@ void cmd_connect_asks_password_when_not_in_account(void **state) { stub_cons_show(); stub_ui_ask_password(); + mock_accounts_get_account(); + mock_accounts_create_full_jid(); + stub_accounts_free_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); @@ -187,16 +192,13 @@ void cmd_connect_asks_password_when_not_in_account(void **state) mock_connection_status(JABBER_DISCONNECTED); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, account); + accounts_get_account_return(account); - will_return(accounts_create_full_jid, strdup("user@jabber.org")); + accounts_create_full_jid_return("user@jabber.org"); jabber_connect_with_account = _mock_jabber_connect_with_account_result; will_return(_mock_jabber_connect_with_account_result, JABBER_CONNECTING); - expect_any(accounts_free_account, account); - gboolean result = cmd_connect(args, *help); assert_true(result); @@ -207,6 +209,9 @@ void cmd_connect_asks_password_when_not_in_account(void **state) void cmd_connect_shows_message_when_connecting_with_account(void **state) { mock_cons_show(); + mock_accounts_get_account(); + mock_accounts_create_full_jid(); + stub_accounts_free_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); @@ -215,18 +220,15 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) mock_connection_status(JABBER_DISCONNECTED); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, account); + accounts_get_account_return(account); - will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); + accounts_create_full_jid_return("user@jabber.org/laptop"); expect_cons_show("Connecting with account jabber_org as user@jabber.org/laptop"); jabber_connect_with_account = _mock_jabber_connect_with_account_result; will_return(_mock_jabber_connect_with_account_result, JABBER_CONNECTING); - expect_any(accounts_free_account, account); - gboolean result = cmd_connect(args, *help); assert_true(result); @@ -237,6 +239,9 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) void cmd_connect_connects_with_account(void **state) { stub_cons_show(); + mock_accounts_get_account(); + mock_accounts_create_full_jid(); + stub_accounts_free_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); @@ -245,17 +250,14 @@ void cmd_connect_connects_with_account(void **state) mock_connection_status(JABBER_DISCONNECTED); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, account); + accounts_get_account_return(account); - will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); + accounts_create_full_jid_return("user@jabber.org/laptop"); jabber_connect_with_account = _mock_jabber_connect_with_account_result_check; expect_memory(_mock_jabber_connect_with_account_result_check, account, account, sizeof(ProfAccount)); will_return(_mock_jabber_connect_with_account_result_check, JABBER_CONNECTING); - expect_any(accounts_free_account, account); - gboolean result = cmd_connect(args, *help); assert_true(result); @@ -266,21 +268,23 @@ void cmd_connect_connects_with_account(void **state) void cmd_connect_frees_account_after_connecting(void **state) { stub_cons_show(); + mock_accounts_get_account(); + mock_accounts_create_full_jid(); + mock_accounts_free_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); mock_connection_status(JABBER_DISCONNECTED); - expect_any(accounts_get_account, name); - will_return(accounts_get_account, account); + accounts_get_account_return(account); - will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop")); + accounts_create_full_jid_return("user@jabber.org/laptop"); jabber_connect_with_account = _mock_jabber_connect_with_account_result; will_return(_mock_jabber_connect_with_account_result, JABBER_CONNECTING); - expect_memory(accounts_free_account, account, account, sizeof(ProfAccount)); + accounts_free_account_expect(account); gboolean result = cmd_connect(args, *help); assert_true(result); diff --git a/tests/test_cmd_rooms.c b/tests/test_cmd_rooms.c index 01aeecbe..bbd05471 100644 --- a/tests/test_cmd_rooms.c +++ b/tests/test_cmd_rooms.c @@ -11,6 +11,9 @@ #include "ui/ui.h" #include "ui/mock_ui.h" +#include "config/accounts.h" +#include "config/mock_accounts.h" + #include "command/commands.h" static void test_with_connection_status(jabber_conn_status_t status) @@ -54,6 +57,7 @@ void cmd_rooms_shows_message_when_undefined(void **state) void cmd_rooms_uses_account_default_when_no_arg(void **state) { + mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); ProfAccount *account = malloc(sizeof(ProfAccount)); account->muc_service = "default_conf_server"; @@ -62,8 +66,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state) mock_connection_status(JABBER_CONNECTED); mock_connection_account_name("account_name"); - expect_string(accounts_get_account, name, "account_name"); - will_return(accounts_get_account, account); + accounts_get_account_return(account); expect_room_list_request("default_conf_server"); |