mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added validation tests for "/account set" and "/account set jid"
This commit is contained in:
parent
52d15242ab
commit
52f6ad6fe1
@ -85,12 +85,24 @@ gboolean accounts_rename(const char * const account_name,
|
||||
|
||||
gboolean accounts_account_exists(const char * const account_name)
|
||||
{
|
||||
check_expected(account_name);
|
||||
return (gboolean)mock();
|
||||
}
|
||||
|
||||
void accounts_set_jid(const char * const account_name, const char * const value) {}
|
||||
void accounts_set_jid(const char * const account_name, const char * const value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_server(const char * const account_name, const char * const value) {}
|
||||
void accounts_set_resource(const char * const account_name, const char * const value) {}
|
||||
|
||||
void accounts_set_resource(const char * const account_name, const char * const value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_password(const char * const account_name, const char * const value) {}
|
||||
void accounts_set_muc_service(const char * const account_name, const char * const value) {}
|
||||
void accounts_set_muc_nick(const char * const account_name, const char * const value) {}
|
||||
|
@ -374,3 +374,149 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state)
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_shows_usage_when_no_args(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", NULL };
|
||||
|
||||
expect_string(cons_show, output, "Usage: some usage");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_shows_usage_when_one_arg(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", NULL };
|
||||
|
||||
expect_string(cons_show, output, "Usage: some usage");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_shows_usage_when_two_args(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", "a_property", NULL };
|
||||
|
||||
expect_string(cons_show, output, "Usage: some usage");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_checks_account_exists(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL };
|
||||
|
||||
expect_string(accounts_account_exists, account_name, "a_account");
|
||||
will_return(accounts_account_exists, FALSE);
|
||||
|
||||
expect_any_count(cons_show, output, 2);
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_shows_message_when_account_doesnt_exist(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, FALSE);
|
||||
|
||||
expect_string(cons_show, output, "Account a_account doesn't exist");
|
||||
expect_string(cons_show, output, "");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_jid_shows_message_for_malformed_jid(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(cons_show, output, "Malformed jid: @malformed");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_jid_sets_barejid(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(accounts_set_jid, account_name, "a_account");
|
||||
expect_string(accounts_set_jid, value, "a_local@a_domain");
|
||||
|
||||
expect_string(cons_show, output, "Updated jid for account a_account: a_local@a_domain");
|
||||
|
||||
expect_any(accounts_set_resource, account_name);
|
||||
expect_any(accounts_set_resource, value);
|
||||
|
||||
expect_any(cons_show, output);
|
||||
expect_string(cons_show, output, "");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_jid_sets_resource(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_any(accounts_set_jid, account_name);
|
||||
expect_any(accounts_set_jid, value);
|
||||
|
||||
expect_any(cons_show, output);
|
||||
|
||||
expect_string(accounts_set_resource, account_name, "a_account");
|
||||
expect_string(accounts_set_resource, value, "a_resource");
|
||||
|
||||
expect_string(cons_show, output, "Updated resource for account a_account: a_resource");
|
||||
expect_string(cons_show, output, "");
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
@ -20,3 +20,11 @@ void cmd_account_rename_shows_usage_when_one_arg(void **state);
|
||||
void cmd_account_rename_renames_account(void **state);
|
||||
void cmd_account_rename_shows_message_when_renamed(void **state);
|
||||
void cmd_account_rename_shows_message_when_not_renamed(void **state);
|
||||
void cmd_account_set_shows_usage_when_no_args(void **state);
|
||||
void cmd_account_set_shows_usage_when_one_arg(void **state);
|
||||
void cmd_account_set_shows_usage_when_two_args(void **state);
|
||||
void cmd_account_set_checks_account_exists(void **state);
|
||||
void cmd_account_set_shows_message_when_account_doesnt_exist(void **state);
|
||||
void cmd_account_set_jid_shows_message_for_malformed_jid(void **state);
|
||||
void cmd_account_set_jid_sets_barejid(void **state);
|
||||
void cmd_account_set_jid_sets_resource(void **state);
|
||||
|
@ -15,50 +15,6 @@
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test(cmd_connect_shows_message_when_disconnecting),
|
||||
unit_test(cmd_connect_shows_message_when_connecting),
|
||||
unit_test(cmd_connect_shows_message_when_connected),
|
||||
unit_test(cmd_connect_shows_message_when_undefined),
|
||||
unit_test(cmd_connect_when_no_account),
|
||||
unit_test(cmd_connect_with_altdomain_when_provided),
|
||||
unit_test(cmd_connect_fail_message),
|
||||
unit_test(cmd_connect_lowercases_argument),
|
||||
unit_test(cmd_connect_asks_password_when_not_in_account),
|
||||
unit_test(cmd_connect_shows_message_when_connecting_with_account),
|
||||
unit_test(cmd_connect_connects_with_account),
|
||||
unit_test(cmd_connect_frees_account_after_connecting),
|
||||
|
||||
unit_test(cmd_account_shows_usage_when_not_connected_and_no_args),
|
||||
unit_test(cmd_account_shows_account_when_connected_and_no_args),
|
||||
unit_test(cmd_account_list_shows_accounts),
|
||||
unit_test(cmd_account_show_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_show_shows_message_when_account_does_not_exist),
|
||||
unit_test(cmd_account_show_shows_message_when_account_exists),
|
||||
unit_test(cmd_account_add_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_add_adds_account),
|
||||
unit_test(cmd_account_add_shows_message),
|
||||
unit_test(cmd_account_enable_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_enable_enables_account),
|
||||
unit_test(cmd_account_enable_shows_message_when_enabled),
|
||||
unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist),
|
||||
unit_test(cmd_account_disable_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_disable_disables_account),
|
||||
unit_test(cmd_account_disable_shows_message_when_disabled),
|
||||
unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist),
|
||||
unit_test(cmd_account_rename_shows_usage_when_no_args),
|
||||
unit_test(cmd_account_rename_shows_usage_when_one_arg),
|
||||
unit_test(cmd_account_rename_renames_account),
|
||||
unit_test(cmd_account_rename_shows_message_when_renamed),
|
||||
unit_test(cmd_account_rename_shows_message_when_not_renamed),
|
||||
|
||||
unit_test(cmd_rooms_shows_message_when_disconnected),
|
||||
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
||||
unit_test(cmd_rooms_shows_message_when_connecting),
|
||||
unit_test(cmd_rooms_shows_message_when_started),
|
||||
unit_test(cmd_rooms_shows_message_when_undefined),
|
||||
unit_test(cmd_rooms_uses_account_default_when_no_arg),
|
||||
unit_test(cmd_rooms_arg_used_when_passed),
|
||||
|
||||
unit_test(replace_one_substr),
|
||||
unit_test(replace_one_substr_beginning),
|
||||
unit_test(replace_one_substr_end),
|
||||
@ -203,6 +159,58 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(find_twice_returns_second_when_two_match),
|
||||
unit_test(find_five_times_finds_fifth),
|
||||
unit_test(find_twice_returns_first_when_two_match_and_reset),
|
||||
|
||||
unit_test(cmd_connect_shows_message_when_disconnecting),
|
||||
unit_test(cmd_connect_shows_message_when_connecting),
|
||||
unit_test(cmd_connect_shows_message_when_connected),
|
||||
unit_test(cmd_connect_shows_message_when_undefined),
|
||||
unit_test(cmd_connect_when_no_account),
|
||||
unit_test(cmd_connect_with_altdomain_when_provided),
|
||||
unit_test(cmd_connect_fail_message),
|
||||
unit_test(cmd_connect_lowercases_argument),
|
||||
unit_test(cmd_connect_asks_password_when_not_in_account),
|
||||
unit_test(cmd_connect_shows_message_when_connecting_with_account),
|
||||
unit_test(cmd_connect_connects_with_account),
|
||||
unit_test(cmd_connect_frees_account_after_connecting),
|
||||
|
||||
unit_test(cmd_rooms_shows_message_when_disconnected),
|
||||
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
||||
unit_test(cmd_rooms_shows_message_when_connecting),
|
||||
unit_test(cmd_rooms_shows_message_when_started),
|
||||
unit_test(cmd_rooms_shows_message_when_undefined),
|
||||
unit_test(cmd_rooms_uses_account_default_when_no_arg),
|
||||
unit_test(cmd_rooms_arg_used_when_passed),
|
||||
|
||||
unit_test(cmd_account_shows_usage_when_not_connected_and_no_args),
|
||||
unit_test(cmd_account_shows_account_when_connected_and_no_args),
|
||||
unit_test(cmd_account_list_shows_accounts),
|
||||
unit_test(cmd_account_show_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_show_shows_message_when_account_does_not_exist),
|
||||
unit_test(cmd_account_show_shows_message_when_account_exists),
|
||||
unit_test(cmd_account_add_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_add_adds_account),
|
||||
unit_test(cmd_account_add_shows_message),
|
||||
unit_test(cmd_account_enable_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_enable_enables_account),
|
||||
unit_test(cmd_account_enable_shows_message_when_enabled),
|
||||
unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist),
|
||||
unit_test(cmd_account_disable_shows_usage_when_no_arg),
|
||||
unit_test(cmd_account_disable_disables_account),
|
||||
unit_test(cmd_account_disable_shows_message_when_disabled),
|
||||
unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist),
|
||||
unit_test(cmd_account_rename_shows_usage_when_no_args),
|
||||
unit_test(cmd_account_rename_shows_usage_when_one_arg),
|
||||
unit_test(cmd_account_rename_renames_account),
|
||||
unit_test(cmd_account_rename_shows_message_when_renamed),
|
||||
unit_test(cmd_account_rename_shows_message_when_not_renamed),
|
||||
unit_test(cmd_account_set_shows_usage_when_no_args),
|
||||
unit_test(cmd_account_set_shows_usage_when_one_arg),
|
||||
unit_test(cmd_account_set_shows_usage_when_two_args),
|
||||
unit_test(cmd_account_set_checks_account_exists),
|
||||
unit_test(cmd_account_set_shows_message_when_account_doesnt_exist),
|
||||
unit_test(cmd_account_set_jid_shows_message_for_malformed_jid),
|
||||
unit_test(cmd_account_set_jid_sets_barejid),
|
||||
unit_test(cmd_account_set_jid_sets_resource),
|
||||
};
|
||||
return run_tests(tests);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user