mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-25 17:56:22 +00:00
Refactored ProfAccount creation
This commit is contained in:
@@ -36,25 +36,6 @@ _mock_accounts_get_account(const char * const name)
|
||||
return (ProfAccount *)mock();
|
||||
}
|
||||
|
||||
static char *
|
||||
_mock_accounts_create_full_jid(ProfAccount *account)
|
||||
{
|
||||
check_expected(account);
|
||||
return (char *)mock();
|
||||
}
|
||||
|
||||
void
|
||||
_stub_accounts_free_account(ProfAccount *account)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void
|
||||
_mock_accounts_free_account(ProfAccount *account)
|
||||
{
|
||||
check_expected(account);
|
||||
}
|
||||
|
||||
gchar **
|
||||
_mock_accounts_get_list(void)
|
||||
{
|
||||
@@ -274,24 +255,6 @@ mock_accounts_get_account(void)
|
||||
accounts_get_account = _mock_accounts_get_account;
|
||||
}
|
||||
|
||||
void
|
||||
mock_accounts_create_full_jid(void)
|
||||
{
|
||||
accounts_create_full_jid = _mock_accounts_create_full_jid;
|
||||
}
|
||||
|
||||
void
|
||||
stub_accounts_free_account(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -460,23 +423,6 @@ accounts_get_account_return(ProfAccount *account)
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -24,13 +24,6 @@ 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);
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ 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));
|
||||
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
|
||||
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
|
||||
gchar *args[] = { NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
@@ -54,7 +54,6 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state)
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
free(account);
|
||||
}
|
||||
|
||||
void cmd_account_list_shows_accounts(void **state)
|
||||
@@ -117,10 +116,10 @@ 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));
|
||||
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
|
||||
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
|
||||
|
||||
accounts_get_account_return(account);
|
||||
|
||||
|
||||
@@ -418,21 +418,19 @@ void cmd_connect_lowercases_argument(void **state)
|
||||
void cmd_connect_asks_password_when_not_in_account(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
stub_ui_ask_password();
|
||||
mock_ui_ask_password();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
mock_jabber_connect_with_account();
|
||||
stub_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
account->password = NULL;
|
||||
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
|
||||
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
accounts_get_account_return(account);
|
||||
|
||||
accounts_create_full_jid_return("user@jabber.org");
|
||||
mock_ui_ask_password_returns("password");
|
||||
|
||||
jabber_connect_with_account_return(JABBER_CONNECTING);
|
||||
|
||||
@@ -440,28 +438,22 @@ void cmd_connect_asks_password_when_not_in_account(void **state)
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
free(account);
|
||||
}
|
||||
|
||||
void cmd_connect_shows_message_when_connecting_with_account(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
mock_jabber_connect_with_account();
|
||||
stub_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
account->password = "password";
|
||||
account->name = "jabber_org";
|
||||
ProfAccount *account = account_new("jabber_org", "user@jabber.org", "password",
|
||||
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
accounts_get_account_return(account);
|
||||
|
||||
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_return(JABBER_CONNECTING);
|
||||
@@ -470,61 +462,26 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state)
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
free(account);
|
||||
}
|
||||
|
||||
void cmd_connect_connects_with_account(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
mock_jabber_connect_with_account();
|
||||
stub_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
account->password = "password";
|
||||
account->name = "jabber_org";
|
||||
ProfAccount *account = account_new("jabber_org", "me@jabber.org", "password",
|
||||
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
accounts_get_account_return(account);
|
||||
|
||||
accounts_create_full_jid_return("user@jabber.org/laptop");
|
||||
|
||||
jabber_connect_with_account_expect_and_return(account, JABBER_CONNECTING);
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
free(account);
|
||||
}
|
||||
|
||||
void cmd_connect_frees_account_after_connecting(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
mock_jabber_connect_with_account();
|
||||
mock_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
accounts_get_account_return(account);
|
||||
|
||||
accounts_create_full_jid_return("user@jabber.org/laptop");
|
||||
|
||||
jabber_connect_with_account_return(JABBER_CONNECTING);
|
||||
|
||||
accounts_free_account_expect(account);
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
free(account);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ void cmd_connect_lowercases_argument(void **state);
|
||||
void cmd_connect_asks_password_when_not_in_account(void **state);
|
||||
void cmd_connect_shows_message_when_connecting_with_account(void **state);
|
||||
void cmd_connect_connects_with_account(void **state);
|
||||
void cmd_connect_frees_account_after_connecting(void **state);
|
||||
void cmd_connect_shows_usage_when_no_server_value(void **state);
|
||||
void cmd_connect_shows_usage_when_server_no_port_value(void **state);
|
||||
void cmd_connect_shows_usage_when_no_port_value(void **state);
|
||||
|
||||
@@ -201,7 +201,6 @@ int main(int argc, char* argv[]) {
|
||||
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_connect_shows_usage_when_no_server_value),
|
||||
unit_test(cmd_connect_shows_usage_when_server_no_port_value),
|
||||
unit_test(cmd_connect_shows_usage_when_no_port_value),
|
||||
|
||||
Reference in New Issue
Block a user