1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Refactored all cmd_account tests

This commit is contained in:
James Booth 2014-12-24 17:35:02 +00:00
parent 71dbd7fd77
commit c20e38a4f9
5 changed files with 335 additions and 416 deletions

View File

@ -59,24 +59,69 @@ gboolean accounts_disable(const char * const name)
gboolean accounts_rename(const char * const account_name,
const char * const new_name)
{
return FALSE;
check_expected(account_name);
check_expected(new_name);
return (gboolean)mock();
}
gboolean accounts_account_exists(const char * const account_name)
{
return FALSE;
check_expected(account_name);
return (gboolean)mock();
}
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)
{
check_expected(account_name);
check_expected(value);
}
void accounts_set_jid(const char * const account_name, const char * const value) {}
void accounts_set_server(const char * const account_name, const char * const value) {}
void accounts_set_port(const char * const account_name, const int value) {}
void accounts_set_resource(const char * const account_name, const char * const 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) {}
void accounts_set_otr_policy(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)
{
check_expected(account_name);
check_expected(value);
}
void accounts_set_muc_service(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)
{
check_expected(account_name);
check_expected(value);
}
void accounts_set_otr_policy(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) {}
void accounts_set_login_presence(const char * const account_name, const char * const value) {}
void accounts_set_login_presence(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)
{
return RESOURCE_ONLINE;
@ -84,14 +129,40 @@ resource_presence_t accounts_get_login_presence(const char * const account_name)
resource_presence_t accounts_get_last_presence(const char * const account_name)
{
return RESOURCE_ONLINE;
check_expected(account_name);
return (resource_presence_t)mock();
}
void accounts_set_priority_online(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)
{
check_expected(account_name);
check_expected(value);
}
void accounts_set_priority_away(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)
{
check_expected(account_name);
check_expected(value);
}
void accounts_set_priority_dnd(const char * const account_name, const gint value)
{
check_expected(account_name);
check_expected(value);
}
void accounts_set_priority_online(const char * const account_name, const gint value) {}
void accounts_set_priority_chat(const char * const account_name, const gint value) {}
void accounts_set_priority_away(const char * const account_name, const gint value) {}
void accounts_set_priority_xa(const char * const account_name, const gint value) {}
void accounts_set_priority_dnd(const char * const account_name, const gint value) {}
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)

View File

@ -274,30 +274,14 @@ void cmd_account_rename_shows_usage_when_one_arg(void **state)
free(help);
}
/*
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 };
accounts_rename_expect("original_name", "new_name");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_rename_return(TRUE);
expect_string(accounts_rename, account_name, "original_name");
expect_string(accounts_rename, new_name, "new_name");
will_return(accounts_rename, TRUE);
expect_cons_show("Account renamed.");
expect_cons_show("");
@ -310,12 +294,12 @@ 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 };
accounts_rename_return(FALSE);
expect_any(accounts_rename, account_name);
expect_any(accounts_rename, new_name);
will_return(accounts_rename, FALSE);
expect_cons_show("Either account original_name doesn't exist, or account new_name already exists.");
expect_cons_show("");
@ -328,7 +312,6 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state)
void cmd_account_set_shows_usage_when_no_args(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "set", NULL };
@ -343,7 +326,6 @@ void cmd_account_set_shows_usage_when_no_args(void **state)
void cmd_account_set_shows_usage_when_one_arg(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "set", "a_account", NULL };
@ -358,7 +340,6 @@ void cmd_account_set_shows_usage_when_one_arg(void **state)
void cmd_account_set_shows_usage_when_two_args(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "set", "a_account", "a_property", NULL };
@ -371,29 +352,13 @@ void cmd_account_set_shows_usage_when_two_args(void **state)
free(help);
}
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 };
accounts_account_exists_expect("a_account");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(FALSE);
expect_string(accounts_account_exists, account_name, "a_account");
will_return(accounts_account_exists, FALSE);
expect_cons_show("Account a_account doesn't exist");
expect_cons_show("");
@ -406,12 +371,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Malformed jid: @malformed");
@ -423,20 +387,17 @@ 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 };
gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_jid_expect("a_account", "a_local@a_domain");
expect_string(accounts_set_jid, account_name, "a_account");
expect_string(accounts_set_jid, value, "a_local@a_domain");
expect_cons_show("Updated jid for account a_account: a_local@a_domain");
expect_cons_show_calls(2);
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
@ -446,18 +407,19 @@ 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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show_calls(1);
expect_string(accounts_set_jid, account_name, "a_account");
expect_string(accounts_set_jid, value, "a_local@a_domain");
accounts_set_resource_expect("a_account", "a_resource");
expect_cons_show("Updated jid for account a_account: a_local@a_domain");
expect_string(accounts_set_resource, account_name, "a_account");
expect_string(accounts_set_resource, value, "a_resource");
expect_cons_show("Updated resource for account a_account: a_resource");
expect_cons_show("");
@ -470,31 +432,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_server_expect("a_account", "a_server");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_string(accounts_set_server, account_name, "a_account");
expect_string(accounts_set_server, value, "a_server");
expect_cons_show("Updated server for account a_account: a_server");
expect_cons_show("");
@ -507,31 +452,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_resource_expect("a_account", "a_resource");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_string(accounts_set_resource, account_name, "a_account");
expect_string(accounts_set_resource, value, "a_resource");
expect_cons_show("Updated resource for account a_account: a_resource");
expect_cons_show("");
@ -544,31 +472,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_password_expect("a_account", "a_password");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_string(accounts_set_password, account_name, "a_account");
expect_string(accounts_set_password, value, "a_password");
expect_cons_show("Updated password for account a_account");
expect_cons_show("");
@ -581,31 +492,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_muc_service_expect("a_account", "a_muc");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_string(accounts_set_muc_service, account_name, "a_account");
expect_string(accounts_set_muc_service, value, "a_muc");
expect_cons_show("Updated muc service for account a_account: a_muc");
expect_cons_show("");
@ -618,31 +512,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_muc_nick_expect("a_account", "a_nick");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_string(accounts_set_muc_nick, account_name, "a_account");
expect_string(accounts_set_muc_nick, value, "a_nick");
expect_cons_show("Updated muc nick for account a_account: a_nick");
expect_cons_show("");
@ -653,15 +530,63 @@ void cmd_account_set_nick_shows_message(void **state)
free(help);
}
void cmd_account_show_message_for_missing_otr_policy(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "Some usage";
gchar *args[] = { "set", "a_account", "otr", NULL };
expect_cons_show("Usage: Some usage");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_show_message_for_invalid_otr_policy(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "otr", "bad_otr_policy", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("OTR policy must be one of: manual, opportunistic or always.");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_otr_sets_otr(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "otr", "opportunistic", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_otr_policy, account_name, "a_account");
expect_string(accounts_set_otr_policy, value, "opportunistic");
expect_cons_show("Updated OTR policy for account a_account: opportunistic");
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid status: bad_status");
expect_cons_show("");
@ -674,49 +599,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_login_presence_expect("a_account", "away");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
accounts_set_login_presence_expect("a_account", "last");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
expect_string(accounts_set_login_presence, account_name, "a_account");
expect_string(accounts_set_login_presence, value, "away");
expect_cons_show("Updated login status for account a_account: away");
expect_cons_show("");
@ -727,15 +617,16 @@ void cmd_account_set_status_shows_message_when_set_valid(void **state)
free(help);
}
void cmd_account_set_status_shows_message_when_set_last(void **state)
void cmd_account_set_status_sets_status_when_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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_login_presence, account_name, "a_account");
expect_string(accounts_set_login_presence, value, "last");
expect_cons_show("Updated login status for account a_account: last");
expect_cons_show("");
@ -748,12 +639,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid property: blah");
expect_cons_show("");
@ -766,12 +656,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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid property: last");
expect_cons_show("");
@ -784,115 +673,16 @@ 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 };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
accounts_set_priority_online_expect("a_account", 10);
expect_string(accounts_set_priority_online, account_name, "a_account");
expect_value(accounts_set_priority_online, value, 10);
mock_connection_status(JABBER_DISCONNECTED);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
accounts_set_priority_chat_expect("a_account", 10);
mock_connection_status(JABBER_DISCONNECTED);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
accounts_set_priority_away_expect("a_account", 10);
mock_connection_status(JABBER_DISCONNECTED);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
accounts_set_priority_xa_expect("a_account", 10);
mock_connection_status(JABBER_DISCONNECTED);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
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 };
accounts_account_exists_return(TRUE);
accounts_set_priority_dnd_expect("a_account", 10);
mock_connection_status(JABBER_DISCONNECTED);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_online_priority_shows_message(void **state)
{
mock_cons_show();
mock_accounts_account_exists();
stub_accounts_set_priorities();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "10", NULL };
accounts_account_exists_return(TRUE);
mock_connection_status(JABBER_DISCONNECTED);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
expect_cons_show("Updated online priority for account a_account: 10");
expect_cons_show("");
@ -903,13 +693,101 @@ void cmd_account_set_online_priority_shows_message(void **state)
free(help);
}
void cmd_account_set_chat_priority_sets_preference(void **state)
{
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);
expect_string(accounts_set_priority_chat, account_name, "a_account");
expect_value(accounts_set_priority_chat, value, 10);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
expect_cons_show("Updated chat priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_away_priority_sets_preference(void **state)
{
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);
expect_string(accounts_set_priority_away, account_name, "a_account");
expect_value(accounts_set_priority_away, value, 10);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
expect_cons_show("Updated away priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_xa_priority_sets_preference(void **state)
{
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);
expect_string(accounts_set_priority_xa, account_name, "a_account");
expect_value(accounts_set_priority_xa, value, 10);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
expect_cons_show("Updated xa priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_dnd_priority_sets_preference(void **state)
{
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);
expect_string(accounts_set_priority_dnd, account_name, "a_account");
expect_value(accounts_set_priority_dnd, value, 10);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
expect_cons_show("Updated dnd priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_priority_too_low_shows_message(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "-150", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Value -150 out of range. Must be in -128..127.");
@ -921,11 +799,11 @@ void cmd_account_set_priority_too_low_shows_message(void **state)
void cmd_account_set_priority_too_high_shows_message(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "150", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Value 150 out of range. Must be in -128..127.");
@ -937,11 +815,11 @@ void cmd_account_set_priority_too_high_shows_message(void **state)
void cmd_account_set_priority_when_not_number_shows_message(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "abc", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Could not convert \"abc\" to a number.");
@ -953,11 +831,11 @@ void cmd_account_set_priority_when_not_number_shows_message(void **state)
void cmd_account_set_priority_when_empty_shows_message(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Could not convert \"\" to a number.");
@ -969,23 +847,29 @@ void cmd_account_set_priority_when_empty_shows_message(void **state)
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state)
{
stub_cons_show();
stub_accounts_set_priorities();
mock_accounts_get_last_presence();
mock_presence_update();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "10", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
mock_connection_status(JABBER_CONNECTED);
mock_connection_account_name("a_account");
expect_any(accounts_set_priority_online, account_name);
expect_any(accounts_set_priority_online, value);
accounts_get_last_presence_return(RESOURCE_ONLINE);
will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(jabber_get_account_name, "a_account");
mock_connection_presence_message("Free to chat");
expect_any(accounts_get_last_presence, account_name);
will_return(accounts_get_last_presence, RESOURCE_ONLINE);
presence_update_expect(RESOURCE_ONLINE, "Free to chat", 0);
will_return(jabber_get_presence_message, "Free to chat");
expect_value(presence_update, status, RESOURCE_ONLINE);
expect_string(presence_update, msg, "Free to chat");
expect_value(presence_update, idle, 0);
expect_cons_show("Updated online priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account(args, *help);
assert_true(result);
@ -995,7 +879,6 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
void cmd_account_clear_shows_usage_when_no_args(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "clear", NULL };
@ -1010,7 +893,6 @@ void cmd_account_clear_shows_usage_when_no_args(void **state)
void cmd_account_clear_shows_usage_when_one_arg(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "clear", "a_account", NULL };
@ -1023,29 +905,13 @@ void cmd_account_clear_shows_usage_when_one_arg(void **state)
free(help);
}
void cmd_account_clear_checks_account_exists(void **state)
{
stub_cons_show();
mock_accounts_account_exists();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "clear", "a_account", "a_property", NULL };
accounts_account_exists_expect("a_account");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state)
{
mock_cons_show();
mock_accounts_account_exists();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "clear", "a_account", "a_property", NULL };
accounts_account_exists_return(FALSE);
expect_string(accounts_account_exists, account_name, "a_account");
will_return(accounts_account_exists, FALSE);
expect_cons_show("Account a_account doesn't exist");
expect_cons_show("");
@ -1058,12 +924,11 @@ void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state)
void cmd_account_clear_shows_message_when_invalid_property(void **state)
{
mock_cons_show();
mock_accounts_account_exists();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "clear", "a_account", "badproperty", NULL };
accounts_account_exists_return(TRUE);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid property: badproperty");
expect_cons_show("");
@ -1072,6 +937,4 @@ void cmd_account_clear_shows_message_when_invalid_property(void **state)
assert_true(result);
free(help);
}
*/
}

View File

@ -6,43 +6,34 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state);
void cmd_account_show_shows_account_when_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);
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);
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);
void cmd_account_set_server_sets_server(void **state);
void cmd_account_set_server_shows_message(void **state);
void cmd_account_set_resource_sets_resource(void **state);
void cmd_account_set_resource_shows_message(void **state);
void cmd_account_set_password_sets_password(void **state);
void cmd_account_set_password_shows_message(void **state);
void cmd_account_set_muc_sets_muc(void **state);
void cmd_account_set_muc_shows_message(void **state);
void cmd_account_set_nick_sets_nick(void **state);
void cmd_account_set_nick_shows_message(void **state);
void cmd_account_show_message_for_missing_otr_policy(void **state);
void cmd_account_show_message_for_invalid_otr_policy(void **state);
void cmd_account_set_otr_sets_otr(void **state);
void cmd_account_set_status_shows_message_when_invalid_status(void **state);
void cmd_account_set_status_sets_status_when_valid(void **state);
void cmd_account_set_status_sets_status_when_last(void **state);
void cmd_account_set_status_shows_message_when_set_valid(void **state);
void cmd_account_set_status_shows_message_when_set_last(void **state);
void cmd_account_set_invalid_presence_string_priority_shows_message(void **state);
void cmd_account_set_last_priority_shows_message(void **state);
void cmd_account_set_online_priority_sets_preference(void **state);
@ -50,7 +41,6 @@ void cmd_account_set_chat_priority_sets_preference(void **state);
void cmd_account_set_away_priority_sets_preference(void **state);
void cmd_account_set_xa_priority_sets_preference(void **state);
void cmd_account_set_dnd_priority_sets_preference(void **state);
void cmd_account_set_online_priority_shows_message(void **state);
void cmd_account_set_priority_too_low_shows_message(void **state);
void cmd_account_set_priority_too_high_shows_message(void **state);
void cmd_account_set_priority_when_not_number_shows_message(void **state);
@ -58,6 +48,5 @@ void cmd_account_set_priority_when_empty_shows_message(void **state);
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state);
void cmd_account_clear_shows_usage_when_no_args(void **state);
void cmd_account_clear_shows_usage_when_one_arg(void **state);
void cmd_account_clear_checks_account_exists(void **state);
void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state);
void cmd_account_clear_shows_message_when_invalid_property(void **state);
void cmd_account_clear_shows_message_when_invalid_property(void **state);

View File

@ -255,33 +255,26 @@ int main(int argc, char* argv[]) {
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),
unit_test(cmd_account_set_server_sets_server),
unit_test(cmd_account_set_server_shows_message),
unit_test(cmd_account_set_resource_sets_resource),
unit_test(cmd_account_set_resource_shows_message),
unit_test(cmd_account_set_password_sets_password),
unit_test(cmd_account_set_password_shows_message),
unit_test(cmd_account_set_muc_sets_muc),
unit_test(cmd_account_set_muc_shows_message),
unit_test(cmd_account_set_nick_sets_nick),
unit_test(cmd_account_set_nick_shows_message),
unit_test(cmd_account_show_message_for_missing_otr_policy),
unit_test(cmd_account_show_message_for_invalid_otr_policy),
unit_test(cmd_account_set_otr_sets_otr),
unit_test(cmd_account_set_status_shows_message_when_invalid_status),
unit_test(cmd_account_set_status_sets_status_when_valid),
unit_test(cmd_account_set_status_sets_status_when_last),
unit_test(cmd_account_set_status_shows_message_when_set_valid),
unit_test(cmd_account_set_status_shows_message_when_set_last),
unit_test(cmd_account_set_invalid_presence_string_priority_shows_message),
unit_test(cmd_account_set_last_priority_shows_message),
unit_test(cmd_account_set_online_priority_sets_preference),
@ -289,7 +282,6 @@ int main(int argc, char* argv[]) {
unit_test(cmd_account_set_away_priority_sets_preference),
unit_test(cmd_account_set_xa_priority_sets_preference),
unit_test(cmd_account_set_dnd_priority_sets_preference),
unit_test(cmd_account_set_online_priority_shows_message),
unit_test(cmd_account_set_priority_too_low_shows_message),
unit_test(cmd_account_set_priority_too_high_shows_message),
unit_test(cmd_account_set_priority_when_not_number_shows_message),
@ -297,10 +289,9 @@ int main(int argc, char* argv[]) {
unit_test(cmd_account_set_priority_updates_presence_when_account_connected_with_presence),
unit_test(cmd_account_clear_shows_usage_when_no_args),
unit_test(cmd_account_clear_shows_usage_when_one_arg),
unit_test(cmd_account_clear_checks_account_exists),
unit_test(cmd_account_clear_shows_message_when_account_doesnt_exist),
unit_test(cmd_account_clear_shows_message_when_invalid_property),
/*
unit_test(cmd_sub_shows_message_when_not_connected),
unit_test(cmd_sub_shows_usage_when_no_arg),

View File

@ -39,7 +39,7 @@ jabber_conn_status_t jabber_get_connection_status(void)
char* jabber_get_presence_message(void)
{
return NULL;
return (char*)mock();
}
char* jabber_get_account_name(void)
@ -89,8 +89,13 @@ char * presence_sub_request_find(char * search_str)
void presence_join_room(char *room, char *nick, char * passwd) {}
void presence_change_room_nick(const char * const room, const char * const nick) {}
void presence_leave_chat_room(const char * const room_jid) {}
void presence_update(resource_presence_t status, const char * const msg,
int idle) {}
void presence_update(resource_presence_t status, const char * const msg, int idle)
{
check_expected(status);
check_expected(msg);
check_expected(idle);
}
gboolean presence_sub_request_exists(const char * const bare_jid)
{