1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-29 19:56:07 -04:00

Added tests for "/account rename"

This commit is contained in:
James Booth 2013-12-16 00:12:07 +00:00
parent 3c0bbed717
commit e14b4ef558
4 changed files with 99 additions and 6 deletions

View File

@ -78,6 +78,8 @@ gboolean accounts_disable(const char * const name)
gboolean accounts_rename(const char * const account_name,
const char * const new_name)
{
check_expected(account_name);
check_expected(new_name);
return (gboolean)mock();
}

View File

@ -183,7 +183,7 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state)
void cmd_account_enable_enables_account(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "enable", "account_name" };
gchar *args[] = { "enable", "account_name", NULL };
expect_string(accounts_enable, name, "account_name");
will_return(accounts_enable, TRUE);
@ -199,7 +199,7 @@ void cmd_account_enable_enables_account(void **state)
void cmd_account_enable_shows_message_when_enabled(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "enable", "account_name" };
gchar *args[] = { "enable", "account_name", NULL };
expect_any(accounts_enable, name);
will_return(accounts_enable, TRUE);
@ -216,7 +216,7 @@ void cmd_account_enable_shows_message_when_enabled(void **state)
void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "enable", "account_name" };
gchar *args[] = { "enable", "account_name", NULL };
expect_any(accounts_enable, name);
will_return(accounts_enable, FALSE);
@ -247,7 +247,7 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state)
void cmd_account_disable_disables_account(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "disable", "account_name" };
gchar *args[] = { "disable", "account_name", NULL };
expect_string(accounts_disable, name, "account_name");
will_return(accounts_disable, TRUE);
@ -263,7 +263,7 @@ void cmd_account_disable_disables_account(void **state)
void cmd_account_disable_shows_message_when_disabled(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "disable", "account_name" };
gchar *args[] = { "disable", "account_name", NULL };
expect_any(accounts_disable, name);
will_return(accounts_disable, TRUE);
@ -280,7 +280,7 @@ void cmd_account_disable_shows_message_when_disabled(void **state)
void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "disable", "account_name" };
gchar *args[] = { "disable", "account_name", NULL };
expect_any(accounts_disable, name);
will_return(accounts_disable, FALSE);
@ -293,3 +293,84 @@ void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state)
free(help);
}
void cmd_account_rename_shows_usage_when_no_args(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "rename", NULL };
expect_string(cons_show, output, "Usage: some usage");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_rename_shows_usage_when_one_arg(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "rename", "original_name", NULL };
expect_string(cons_show, output, "Usage: some usage");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_rename_renames_account(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "rename", "original_name", "new_name", NULL };
expect_string(accounts_rename, account_name, "original_name");
expect_string(accounts_rename, new_name, "new_name");
will_return(accounts_rename, TRUE);
expect_any_count(cons_show, output, 2);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_rename_shows_message_when_renamed(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "rename", "original_name", "new_name", NULL };
expect_string(accounts_rename, account_name, "original_name");
expect_string(accounts_rename, new_name, "new_name");
will_return(accounts_rename, TRUE);
expect_string(cons_show, output, "Account renamed.");
expect_string(cons_show, output, "");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_rename_shows_message_when_not_renamed(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "rename", "original_name", "new_name", NULL };
expect_string(accounts_rename, account_name, "original_name");
expect_string(accounts_rename, new_name, "new_name");
will_return(accounts_rename, FALSE);
expect_string(cons_show, output, "Either account original_name doesn't exist, or account new_name already exists.");
expect_string(cons_show, output, "");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}

View File

@ -15,3 +15,8 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state);
void cmd_account_disable_disables_account(void **state);
void cmd_account_disable_shows_message_when_disabled(void **state);
void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state);
void cmd_account_rename_shows_usage_when_no_args(void **state);
void cmd_account_rename_shows_usage_when_one_arg(void **state);
void cmd_account_rename_renames_account(void **state);
void cmd_account_rename_shows_message_when_renamed(void **state);
void cmd_account_rename_shows_message_when_not_renamed(void **state);

View File

@ -45,6 +45,11 @@ int main(int argc, char* argv[]) {
unit_test(cmd_account_disable_disables_account),
unit_test(cmd_account_disable_shows_message_when_disabled),
unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist),
unit_test(cmd_account_rename_shows_usage_when_no_args),
unit_test(cmd_account_rename_shows_usage_when_one_arg),
unit_test(cmd_account_rename_renames_account),
unit_test(cmd_account_rename_shows_message_when_renamed),
unit_test(cmd_account_rename_shows_message_when_not_renamed),
unit_test(cmd_rooms_shows_message_when_disconnected),
unit_test(cmd_rooms_shows_message_when_disconnecting),