mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-28 00:56:21 +00:00
Added mock_accounts and fixed tests
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "command/commands.h"
|
||||
|
||||
#include "config/accounts.h"
|
||||
#include "config/mock_accounts.h"
|
||||
|
||||
static jabber_conn_status_t _mock_jabber_connect_with_details_no_altdomain(const char * const jid,
|
||||
const char * const passwd, const char * const altdomain)
|
||||
@@ -85,14 +87,14 @@ void cmd_connect_shows_message_when_undefined(void **state)
|
||||
void cmd_connect_when_no_account(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_ui_ask_password();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_string(accounts_get_account, name, "user@server.org");
|
||||
will_return(accounts_get_account, NULL);
|
||||
accounts_get_account_expect_and_return("user@server.org", NULL);
|
||||
|
||||
mock_ui_ask_password_returns("password");
|
||||
|
||||
@@ -113,13 +115,13 @@ void cmd_connect_with_altdomain_when_provided(void **state)
|
||||
{
|
||||
stub_ui_ask_password();
|
||||
stub_cons_show();
|
||||
mock_accounts_get_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", "altdomain" };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_any(accounts_get_account, name);
|
||||
will_return(accounts_get_account, NULL);
|
||||
accounts_get_account_return(NULL);
|
||||
|
||||
jabber_connect_with_details = _mock_jabber_connect_with_details_altdomain;
|
||||
expect_string(_mock_jabber_connect_with_details_altdomain, altdomain, "altdomain");
|
||||
@@ -136,13 +138,13 @@ void cmd_connect_fail_message(void **state)
|
||||
stub_cons_show();
|
||||
mock_cons_show_error();
|
||||
stub_ui_ask_password();
|
||||
mock_accounts_get_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "user@server.org", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_any(accounts_get_account, name);
|
||||
will_return(accounts_get_account, NULL);
|
||||
accounts_get_account_return(NULL);
|
||||
|
||||
jabber_connect_with_details = _mock_jabber_connect_with_details_result;
|
||||
will_return(_mock_jabber_connect_with_details_result, JABBER_DISCONNECTED);
|
||||
@@ -159,13 +161,13 @@ void cmd_connect_lowercases_argument(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
stub_ui_ask_password();
|
||||
mock_accounts_get_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "USER@server.ORG", NULL };
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_string(accounts_get_account, name, "user@server.org");
|
||||
will_return(accounts_get_account, NULL);
|
||||
accounts_get_account_expect_and_return("user@server.org", NULL);
|
||||
|
||||
jabber_connect_with_details = _mock_jabber_connect_with_details_result;
|
||||
will_return(_mock_jabber_connect_with_details_result, JABBER_CONNECTING);
|
||||
@@ -180,6 +182,9 @@ void cmd_connect_asks_password_when_not_in_account(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
stub_ui_ask_password();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
stub_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
@@ -187,16 +192,13 @@ void cmd_connect_asks_password_when_not_in_account(void **state)
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_any(accounts_get_account, name);
|
||||
will_return(accounts_get_account, account);
|
||||
accounts_get_account_return(account);
|
||||
|
||||
will_return(accounts_create_full_jid, strdup("user@jabber.org"));
|
||||
accounts_create_full_jid_return("user@jabber.org");
|
||||
|
||||
jabber_connect_with_account = _mock_jabber_connect_with_account_result;
|
||||
will_return(_mock_jabber_connect_with_account_result, JABBER_CONNECTING);
|
||||
|
||||
expect_any(accounts_free_account, account);
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
@@ -207,6 +209,9 @@ void cmd_connect_asks_password_when_not_in_account(void **state)
|
||||
void cmd_connect_shows_message_when_connecting_with_account(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
stub_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
@@ -215,18 +220,15 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state)
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_any(accounts_get_account, name);
|
||||
will_return(accounts_get_account, account);
|
||||
accounts_get_account_return(account);
|
||||
|
||||
will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop"));
|
||||
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 = _mock_jabber_connect_with_account_result;
|
||||
will_return(_mock_jabber_connect_with_account_result, JABBER_CONNECTING);
|
||||
|
||||
expect_any(accounts_free_account, account);
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
@@ -237,6 +239,9 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state)
|
||||
void cmd_connect_connects_with_account(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
stub_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
@@ -245,17 +250,14 @@ void cmd_connect_connects_with_account(void **state)
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_any(accounts_get_account, name);
|
||||
will_return(accounts_get_account, account);
|
||||
accounts_get_account_return(account);
|
||||
|
||||
will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop"));
|
||||
accounts_create_full_jid_return("user@jabber.org/laptop");
|
||||
|
||||
jabber_connect_with_account = _mock_jabber_connect_with_account_result_check;
|
||||
expect_memory(_mock_jabber_connect_with_account_result_check, account, account, sizeof(ProfAccount));
|
||||
will_return(_mock_jabber_connect_with_account_result_check, JABBER_CONNECTING);
|
||||
|
||||
expect_any(accounts_free_account, account);
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
@@ -266,21 +268,23 @@ void cmd_connect_connects_with_account(void **state)
|
||||
void cmd_connect_frees_account_after_connecting(void **state)
|
||||
{
|
||||
stub_cons_show();
|
||||
mock_accounts_get_account();
|
||||
mock_accounts_create_full_jid();
|
||||
mock_accounts_free_account();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "jabber_org", NULL };
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
|
||||
mock_connection_status(JABBER_DISCONNECTED);
|
||||
|
||||
expect_any(accounts_get_account, name);
|
||||
will_return(accounts_get_account, account);
|
||||
accounts_get_account_return(account);
|
||||
|
||||
will_return(accounts_create_full_jid, strdup("user@jabber.org/laptop"));
|
||||
accounts_create_full_jid_return("user@jabber.org/laptop");
|
||||
|
||||
jabber_connect_with_account = _mock_jabber_connect_with_account_result;
|
||||
will_return(_mock_jabber_connect_with_account_result, JABBER_CONNECTING);
|
||||
|
||||
expect_memory(accounts_free_account, account, account, sizeof(ProfAccount));
|
||||
accounts_free_account_expect(account);
|
||||
|
||||
gboolean result = cmd_connect(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
Reference in New Issue
Block a user