From e14b4ef558ccec2f77a42a192b74b0eba0cf541a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Dec 2013 00:12:07 +0000 Subject: Added tests for "/account rename" --- tests/config/mock_accounts.c | 2 + tests/test_cmd_account.c | 93 +++++++++++++++++++++++++++++++++++++++++--- tests/test_cmd_account.h | 5 +++ tests/testsuite.c | 5 +++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c index c0faa5ab..b8cc9596 100644 --- a/tests/config/mock_accounts.c +++ b/tests/config/mock_accounts.c @@ -78,6 +78,8 @@ gboolean accounts_disable(const char * const name) gboolean accounts_rename(const char * const account_name, const char * const new_name) { + check_expected(account_name); + check_expected(new_name); return (gboolean)mock(); } diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index a20111f1..b17d7b03 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -183,7 +183,7 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state) void cmd_account_enable_enables_account(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "enable", "account_name" }; + gchar *args[] = { "enable", "account_name", NULL }; expect_string(accounts_enable, name, "account_name"); will_return(accounts_enable, TRUE); @@ -199,7 +199,7 @@ void cmd_account_enable_enables_account(void **state) void cmd_account_enable_shows_message_when_enabled(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "enable", "account_name" }; + gchar *args[] = { "enable", "account_name", NULL }; expect_any(accounts_enable, name); will_return(accounts_enable, TRUE); @@ -216,7 +216,7 @@ void cmd_account_enable_shows_message_when_enabled(void **state) void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "enable", "account_name" }; + gchar *args[] = { "enable", "account_name", NULL }; expect_any(accounts_enable, name); will_return(accounts_enable, FALSE); @@ -247,7 +247,7 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state) void cmd_account_disable_disables_account(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "disable", "account_name" }; + gchar *args[] = { "disable", "account_name", NULL }; expect_string(accounts_disable, name, "account_name"); will_return(accounts_disable, TRUE); @@ -263,7 +263,7 @@ void cmd_account_disable_disables_account(void **state) void cmd_account_disable_shows_message_when_disabled(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "disable", "account_name" }; + gchar *args[] = { "disable", "account_name", NULL }; expect_any(accounts_disable, name); will_return(accounts_disable, TRUE); @@ -280,7 +280,7 @@ void cmd_account_disable_shows_message_when_disabled(void **state) void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "disable", "account_name" }; + gchar *args[] = { "disable", "account_name", NULL }; expect_any(accounts_disable, name); will_return(accounts_disable, FALSE); @@ -293,3 +293,84 @@ void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) free(help); } + +void cmd_account_rename_shows_usage_when_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "rename", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_shows_usage_when_one_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "rename", "original_name", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_renames_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "rename", "original_name", "new_name", NULL }; + + expect_string(accounts_rename, account_name, "original_name"); + expect_string(accounts_rename, new_name, "new_name"); + will_return(accounts_rename, TRUE); + + expect_any_count(cons_show, output, 2); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_shows_message_when_renamed(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "rename", "original_name", "new_name", NULL }; + + expect_string(accounts_rename, account_name, "original_name"); + expect_string(accounts_rename, new_name, "new_name"); + will_return(accounts_rename, TRUE); + + expect_string(cons_show, output, "Account renamed."); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_rename_shows_message_when_not_renamed(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "rename", "original_name", "new_name", NULL }; + + expect_string(accounts_rename, account_name, "original_name"); + expect_string(accounts_rename, new_name, "new_name"); + will_return(accounts_rename, FALSE); + + expect_string(cons_show, output, "Either account original_name doesn't exist, or account new_name already exists."); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_account.h b/tests/test_cmd_account.h index f04485bb..ca72af36 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -15,3 +15,8 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state); void cmd_account_disable_disables_account(void **state); void cmd_account_disable_shows_message_when_disabled(void **state); void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state); +void cmd_account_rename_shows_usage_when_no_args(void **state); +void cmd_account_rename_shows_usage_when_one_arg(void **state); +void cmd_account_rename_renames_account(void **state); +void cmd_account_rename_shows_message_when_renamed(void **state); +void cmd_account_rename_shows_message_when_not_renamed(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 864cea2e..bba13a7e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -45,6 +45,11 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_disable_disables_account), unit_test(cmd_account_disable_shows_message_when_disabled), unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist), + unit_test(cmd_account_rename_shows_usage_when_no_args), + unit_test(cmd_account_rename_shows_usage_when_one_arg), + unit_test(cmd_account_rename_renames_account), + unit_test(cmd_account_rename_shows_message_when_renamed), + unit_test(cmd_account_rename_shows_message_when_not_renamed), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), -- cgit 1.4.1-2-gfad0