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:
parent
5be9ac3243
commit
69fe6c4d21
@ -1,6 +1,24 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "config/account.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_load(void) {}
|
||||||
void accounts_close(void) {}
|
void accounts_close(void) {}
|
||||||
|
|
||||||
@ -29,7 +47,7 @@ gchar** accounts_get_list(void)
|
|||||||
|
|
||||||
ProfAccount* accounts_get_account(const char * const name)
|
ProfAccount* accounts_get_account(const char * const name)
|
||||||
{
|
{
|
||||||
return NULL;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean accounts_enable(const char * const name)
|
gboolean accounts_enable(const char * const name)
|
||||||
|
2
tests/config/stub_accounts.h
Normal file
2
tests/config/stub_accounts.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
void reset_account_mocks(void);
|
||||||
|
void mock_accounts_get_account(ProfAccount *given_account);
|
@ -13,12 +13,20 @@
|
|||||||
|
|
||||||
#include "ui/stub_ui.h"
|
#include "ui/stub_ui.h"
|
||||||
#include "xmpp/stub_xmpp.h"
|
#include "xmpp/stub_xmpp.h"
|
||||||
|
#include "config/stub_accounts.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
reset_mocks(void **state)
|
pre_test(void **state)
|
||||||
{
|
{
|
||||||
reset_ui_mocks();
|
reset_ui_mocks();
|
||||||
reset_xmpp_mocks();
|
reset_xmpp_mocks();
|
||||||
|
reset_account_mocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
post_test(void **state)
|
||||||
|
{
|
||||||
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_config_dir(void **state)
|
void create_config_dir(void **state)
|
||||||
|
@ -6,4 +6,5 @@ void close_preferences(void **state);
|
|||||||
void glist_set_cmp(GCompareFunc func);
|
void glist_set_cmp(GCompareFunc func);
|
||||||
int glist_contents_equal(const void *actual, const void *expected);
|
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);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "ui/stub_ui.h"
|
#include "ui/stub_ui.h"
|
||||||
|
|
||||||
#include "config/accounts.h"
|
#include "config/accounts.h"
|
||||||
|
#include "config/stub_accounts.h"
|
||||||
|
|
||||||
#include "command/commands.h"
|
#include "command/commands.h"
|
||||||
|
|
||||||
@ -32,11 +33,9 @@ void cmd_account_shows_usage_when_not_connected_and_no_args(void **state)
|
|||||||
free(help);
|
free(help);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void cmd_account_shows_account_when_connected_and_no_args(void **state)
|
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));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
|
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);
|
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_status(JABBER_CONNECTED);
|
||||||
mock_connection_account_name("account_name");
|
mock_connection_account_name("account_name");
|
||||||
|
mock_accounts_get_account(account);
|
||||||
accounts_get_account_return(account);
|
|
||||||
|
|
||||||
expect_cons_show_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);
|
free(help);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void cmd_account_list_shows_accounts(void **state)
|
void cmd_account_list_shows_accounts(void **state)
|
||||||
{
|
{
|
||||||
mock_cons_show_account_list();
|
mock_cons_show_account_list();
|
||||||
|
@ -240,10 +240,13 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test(cmd_rooms_arg_used_when_passed),
|
unit_test(cmd_rooms_arg_used_when_passed),
|
||||||
*/
|
*/
|
||||||
unit_test_setup_teardown(cmd_account_shows_usage_when_not_connected_and_no_args,
|
unit_test_setup_teardown(cmd_account_shows_usage_when_not_connected_and_no_args,
|
||||||
reset_mocks,
|
pre_test,
|
||||||
reset_mocks),
|
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_list_shows_accounts),
|
||||||
unit_test(cmd_account_show_shows_usage_when_no_arg),
|
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_does_not_exist),
|
||||||
|
@ -11,11 +11,13 @@
|
|||||||
// mock state
|
// mock state
|
||||||
|
|
||||||
static gboolean mock_cons_show = FALSE;
|
static gboolean mock_cons_show = FALSE;
|
||||||
|
static gboolean mock_cons_show_account = FALSE;
|
||||||
static char output[256];
|
static char output[256];
|
||||||
|
|
||||||
void reset_ui_mocks(void)
|
void reset_ui_mocks(void)
|
||||||
{
|
{
|
||||||
mock_cons_show = FALSE;
|
mock_cons_show = FALSE;
|
||||||
|
mock_cons_show_account = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -25,6 +27,13 @@ expect_cons_show(char *expected)
|
|||||||
expect_string(cons_show, output, 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
|
// stubs
|
||||||
|
|
||||||
void ui_init(void) {}
|
void ui_init(void) {}
|
||||||
@ -303,7 +312,14 @@ void cons_show_log_prefs(void) {}
|
|||||||
void cons_show_presence_prefs(void) {}
|
void cons_show_presence_prefs(void) {}
|
||||||
void cons_show_connection_prefs(void) {}
|
void cons_show_connection_prefs(void) {}
|
||||||
void cons_show_otr_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_debug(const char * const msg, ...) {}
|
||||||
void cons_show_time(void) {}
|
void cons_show_time(void) {}
|
||||||
void cons_show_word(const char * const word) {}
|
void cons_show_word(const char * const word) {}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "config/account.h"
|
||||||
|
|
||||||
void expect_cons_show(char *expected);
|
void expect_cons_show(char *expected);
|
||||||
|
void expect_cons_show_account(ProfAccount *account);
|
||||||
void reset_ui_mocks(void);
|
void reset_ui_mocks(void);
|
||||||
|
@ -3,11 +3,19 @@
|
|||||||
// mock state
|
// mock state
|
||||||
|
|
||||||
static jabber_conn_status_t connection_status = JABBER_CONNECTED;
|
static jabber_conn_status_t connection_status = JABBER_CONNECTED;
|
||||||
|
static char *account_name = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
reset_xmpp_mocks(void)
|
reset_xmpp_mocks(void)
|
||||||
{
|
{
|
||||||
connection_status = JABBER_CONNECTED;
|
connection_status = JABBER_CONNECTED;
|
||||||
|
account_name = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mock_connection_account_name(char *given_account_name)
|
||||||
|
{
|
||||||
|
account_name = given_account_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stubs
|
// stubs
|
||||||
@ -57,7 +65,7 @@ char* jabber_get_presence_message(void)
|
|||||||
|
|
||||||
char* jabber_get_account_name(void)
|
char* jabber_get_account_name(void)
|
||||||
{
|
{
|
||||||
return NULL;
|
return account_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
GList * jabber_get_available_resources(void)
|
GList * jabber_get_available_resources(void)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
|
|
||||||
void mock_connection_status(jabber_conn_status_t given_connection_status);
|
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);
|
void reset_xmpp_mocks(void);
|
Loading…
Reference in New Issue
Block a user