1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

cmd_account_shows_account_when_connected_and_no_args

This commit is contained in:
James Booth 2014-12-23 19:51:12 +00:00
parent 5be9ac3243
commit 69fe6c4d21
10 changed files with 73 additions and 14 deletions

View File

@ -1,6 +1,24 @@
#include "common.h"
#include "config/account.h"
// mock state
static ProfAccount *account = NULL;
void
reset_account_mocks(void)
{
account = NULL;
}
void
mock_accounts_get_account(ProfAccount *given_account)
{
account = given_account;
}
// stubs
void accounts_load(void) {}
void accounts_close(void) {}
@ -29,7 +47,7 @@ gchar** accounts_get_list(void)
ProfAccount* accounts_get_account(const char * const name)
{
return NULL;
return account;
}
gboolean accounts_enable(const char * const name)

View File

@ -0,0 +1,2 @@
void reset_account_mocks(void);
void mock_accounts_get_account(ProfAccount *given_account);

View File

@ -13,12 +13,20 @@
#include "ui/stub_ui.h"
#include "xmpp/stub_xmpp.h"
#include "config/stub_accounts.h"
void
reset_mocks(void **state)
pre_test(void **state)
{
reset_ui_mocks();
reset_xmpp_mocks();
reset_account_mocks();
}
void
post_test(void **state)
{
// nothing
}
void create_config_dir(void **state)

View File

@ -6,4 +6,5 @@ void close_preferences(void **state);
void glist_set_cmp(GCompareFunc func);
int glist_contents_equal(const void *actual, const void *expected);
void reset_mocks(void **state);
void pre_test(void **state);
void post_test(void **state);

View File

@ -13,6 +13,7 @@
#include "ui/stub_ui.h"
#include "config/accounts.h"
#include "config/stub_accounts.h"
#include "command/commands.h"
@ -32,11 +33,9 @@ void cmd_account_shows_usage_when_not_connected_and_no_args(void **state)
free(help);
}
/*
void cmd_account_shows_account_when_connected_and_no_args(void **state)
{
mock_cons_show_account();
mock_accounts_get_account();
CommandHelp *help = malloc(sizeof(CommandHelp));
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
@ -44,8 +43,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state)
mock_connection_status(JABBER_CONNECTED);
mock_connection_account_name("account_name");
accounts_get_account_return(account);
mock_accounts_get_account(account);
expect_cons_show_account(account);
@ -54,7 +52,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state)
free(help);
}
/*
void cmd_account_list_shows_accounts(void **state)
{
mock_cons_show_account_list();

View File

@ -240,10 +240,13 @@ int main(int argc, char* argv[]) {
unit_test(cmd_rooms_arg_used_when_passed),
*/
unit_test_setup_teardown(cmd_account_shows_usage_when_not_connected_and_no_args,
reset_mocks,
reset_mocks),
pre_test,
post_test),
unit_test_setup_teardown(cmd_account_shows_account_when_connected_and_no_args,
pre_test,
post_test),
/*
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),

View File

@ -11,11 +11,13 @@
// mock state
static gboolean mock_cons_show = FALSE;
static gboolean mock_cons_show_account = FALSE;
static char output[256];
void reset_ui_mocks(void)
{
mock_cons_show = FALSE;
mock_cons_show_account = FALSE;
}
void
@ -25,6 +27,13 @@ expect_cons_show(char *expected)
expect_string(cons_show, output, expected);
}
void
expect_cons_show_account(ProfAccount *account)
{
mock_cons_show_account = TRUE;
expect_memory(cons_show_account, account, account, sizeof(ProfAccount));
}
// stubs
void ui_init(void) {}
@ -303,7 +312,14 @@ void cons_show_log_prefs(void) {}
void cons_show_presence_prefs(void) {}
void cons_show_connection_prefs(void) {}
void cons_show_otr_prefs(void) {}
void cons_show_account(ProfAccount *account) {}
void cons_show_account(ProfAccount *account)
{
if (mock_cons_show_account) {
check_expected(account);
}
}
void cons_debug(const char * const msg, ...) {}
void cons_show_time(void) {}
void cons_show_word(const char * const word) {}

View File

@ -1,4 +1,7 @@
#include <glib.h>
#include "config/account.h"
void expect_cons_show(char *expected);
void expect_cons_show_account(ProfAccount *account);
void reset_ui_mocks(void);

View File

@ -3,11 +3,19 @@
// mock state
static jabber_conn_status_t connection_status = JABBER_CONNECTED;
static char *account_name = NULL;
void
reset_xmpp_mocks(void)
{
connection_status = JABBER_CONNECTED;
account_name = NULL;
}
void
mock_connection_account_name(char *given_account_name)
{
account_name = given_account_name;
}
// stubs
@ -57,7 +65,7 @@ char* jabber_get_presence_message(void)
char* jabber_get_account_name(void)
{
return NULL;
return account_name;
}
GList * jabber_get_available_resources(void)

View File

@ -1,4 +1,6 @@
#include "xmpp/xmpp.h"
void mock_connection_status(jabber_conn_status_t given_connection_status);
void mock_connection_account_name(char *given_account_name);
void reset_xmpp_mocks(void);