1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-01-19 00:13:42 +00:00
commit 692af0e9a0
13 changed files with 506 additions and 57 deletions

View File

@ -65,6 +65,7 @@ static char * _roster_autocomplete(char *input, int *size);
static char * _group_autocomplete(char *input, int *size);
static char * _bookmark_autocomplete(char *input, int *size);
static char * _otr_autocomplete(char *input, int *size);
static char * _connect_autocomplete(char *input, int *size);
GHashTable *commands = NULL;
@ -98,16 +99,20 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/connect",
cmd_connect, parse_args, 1, 2, NULL,
{ "/connect account [server]", "Login to a chat service.",
{ "/connect account [server]",
"-------------------------",
cmd_connect, parse_args, 1, 5, NULL,
{ "/connect account [server value] [port value]", "Login to a chat service.",
{ "/connect account [server value] [port value]",
"--------------------------------------------",
"Connect to an XMPP service using the specified account.",
"Use the server argument for chat services hosted at a different domain to the 'domainpart' of the Jabber ID.",
"An account is automatically created if one does not exist. See the /account command for more details.",
"Use the server property to specify a server if required.",
"Change the default port (5222, or 5223 for SSL) with the port property.",
"An account is automatically created if one does not exist.",
"See the /account command for more details.",
"",
"Example: /connect myuser@gmail.com",
"Example: /connect myuser@mycompany.com talk.google.com",
"Example: /connect myuser@mycompany.com server talk.google.com",
"Example: /connect bob@someplace port 5678",
"Example: /connect me@chatty server chatty.com port 5443",
NULL } } },
{ "/disconnect",
@ -691,6 +696,7 @@ static struct cmd_t command_defs[] =
"The set command may use one of the following for 'property'.",
"jid : The Jabber ID of the account, the account name will be used if this property is not set.",
"server : The chat server, if different to the domainpart of the JID.",
"port : The port used for connecting if not the default (5222, or 5223 for SSL).",
"status : The presence status to use on login, use 'last' to use whatever your last status was.",
"online|chat|away",
"|xa|dnd : Priority for the specified presence.",
@ -703,8 +709,9 @@ static struct cmd_t command_defs[] =
"password : Clears the password for the account.",
"",
"Example : /account add work",
" : /account set work jid myuser@mycompany.com",
" : /account set work server talk.google.com",
" : /account set work jid me@chatty",
" : /account set work server talk.chat.com",
" : /account set work port 5111",
" : /account set work resource desktop",
" : /account set work muc chatservice.mycompany.com",
" : /account set work nick dennis",
@ -844,6 +851,7 @@ static Autocomplete group_ac;
static Autocomplete bookmark_ac;
static Autocomplete otr_ac;
static Autocomplete otr_log_ac;
static Autocomplete connect_property_ac;
/*
* Initialise command autocompleter and history
@ -946,6 +954,7 @@ cmd_init(void)
account_set_ac = autocomplete_new();
autocomplete_add(account_set_ac, "jid");
autocomplete_add(account_set_ac, "server");
autocomplete_add(account_set_ac, "port");
autocomplete_add(account_set_ac, "status");
autocomplete_add(account_set_ac, "online");
autocomplete_add(account_set_ac, "chat");
@ -1012,6 +1021,10 @@ cmd_init(void)
autocomplete_add(otr_log_ac, "off");
autocomplete_add(otr_log_ac, "redact");
connect_property_ac = autocomplete_new();
autocomplete_add(connect_property_ac, "server");
autocomplete_add(connect_property_ac, "port");
cmd_history_init();
}
@ -1050,6 +1063,7 @@ cmd_uninit(void)
autocomplete_free(bookmark_ac);
autocomplete_free(otr_ac);
autocomplete_free(otr_log_ac);
autocomplete_free(connect_property_ac);
}
// Command autocompletion functions
@ -1125,6 +1139,7 @@ cmd_reset_autocomplete()
autocomplete_reset(bookmark_ac);
autocomplete_reset(otr_ac);
autocomplete_reset(otr_log_ac);
autocomplete_reset(connect_property_ac);
bookmark_autocomplete_reset();
}
@ -1371,13 +1386,6 @@ _cmd_complete_parameters(char *input, int *size)
return;
}
result = autocomplete_param_with_func(input, size, "/connect", accounts_find_enabled);
if (result != NULL) {
inp_replace_input(input, result, size);
g_free(result);
return;
}
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac };
@ -1393,7 +1401,8 @@ _cmd_complete_parameters(char *input, int *size)
autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete,
_autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete,
_account_autocomplete, _roster_autocomplete, _group_autocomplete,
_bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete };
_bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete,
_connect_autocomplete };
for (i = 0; i < ARRAY_SIZE(acs); i++) {
result = acs[i](input, size);
@ -1670,6 +1679,38 @@ _theme_autocomplete(char *input, int *size)
return NULL;
}
static char *
_connect_autocomplete(char *input, int *size)
{
char *result = NULL;
input[*size] = '\0';
gchar **args = parse_args(input, 2, 4);
if ((strncmp(input, "/connect", 8) == 0) && (args != NULL)) {
GString *beginning = g_string_new("/connect ");
g_string_append(beginning, args[0]);
if (args[1] != NULL && args[2] != NULL) {
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
result = autocomplete_param_with_ac(input, size, beginning->str, connect_property_ac);
g_string_free(beginning, TRUE);
if (result != NULL) {
return result;
}
}
result = autocomplete_param_with_func(input, size, "/connect", accounts_find_enabled);
if (result != NULL) {
return result;
}
return NULL;
}
static char *
_account_autocomplete(char *input, int *size)
{

View File

@ -70,10 +70,84 @@ cmd_connect(gchar **args, struct cmd_help_t help)
result = TRUE;
} else {
char *user = args[0];
char *altdomain = args[1];
char *opt1 = args[1];
char *opt1val = args[2];
char *opt2 = args[3];
char *opt2val = args[4];
char *lower = g_utf8_strdown(user, -1);
char *jid;
// parse options
char *altdomain = NULL;
int port = 0;
gboolean server_set = FALSE;
gboolean port_set = FALSE;
if (opt1 != NULL) {
if (opt1val == NULL) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (strcmp(opt1, "server") == 0) {
altdomain = opt1val;
server_set = TRUE;
} else if (strcmp(opt1, "port") == 0) {
if (_strtoi(opt1val, &port, 1, 65535) != 0) {
port = 0;
cons_show("");
return TRUE;
} else {
port_set = TRUE;
}
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (opt2 != NULL) {
if (server_set && strcmp("server", opt2) == 0) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (port_set && strcmp("port", opt2) == 0) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (opt2val == NULL) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (strcmp(opt2, "server") == 0) {
if (server_set) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
altdomain = opt2val;
server_set = TRUE;
} else if (strcmp(opt2, "port") == 0) {
if (port_set) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (_strtoi(opt2val, &port, 1, 65535) != 0) {
port = 0;
cons_show("");
return TRUE;
} else {
port_set = TRUE;
}
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
}
}
ProfAccount *account = accounts_get_account(lower);
if (account != NULL) {
jid = accounts_create_full_jid(account);
@ -87,7 +161,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
char *passwd = ui_ask_password();
jid = strdup(lower);
cons_show("Connecting as %s", jid);
conn_status = jabber_connect_with_details(jid, passwd, altdomain);
conn_status = jabber_connect_with_details(jid, passwd, altdomain, port);
free(passwd);
}
g_free(lower);
@ -141,7 +215,7 @@ cmd_account(gchar **args, struct cmd_help_t help)
if (account_name == NULL) {
cons_show("Usage: %s", help.usage);
} else {
accounts_add(account_name, NULL);
accounts_add(account_name, NULL, 0);
cons_show("Account created.");
cons_show("");
}
@ -216,6 +290,16 @@ cmd_account(gchar **args, struct cmd_help_t help)
accounts_set_server(account_name, value);
cons_show("Updated server for account %s: %s", account_name, value);
cons_show("");
} else if (strcmp(property, "port") == 0) {
int port;
if (_strtoi(value, &port, 1, 65535) != 0) {
cons_show("");
return TRUE;
} else {
accounts_set_port(account_name, port);
cons_show("Updated port for account %s: %s", account_name, value);
cons_show("");
}
} else if (strcmp(property, "resource") == 0) {
accounts_set_resource(account_name, value);
cons_show("Updated resource for account %s: %s", account_name, value);

View File

@ -43,6 +43,7 @@ static Autocomplete enabled_ac;
static gchar *string_keys[] = {
"jid",
"server",
"port",
"resource",
"password",
"presence.last",
@ -118,7 +119,7 @@ _accounts_reset_enabled_search(void)
}
static void
_accounts_add(const char *account_name, const char *altdomain)
_accounts_add(const char *account_name, const char *altdomain, const int port)
{
// set account name and resource
const char *barejid = account_name;
@ -139,6 +140,9 @@ _accounts_add(const char *account_name, const char *altdomain)
if (altdomain != NULL) {
g_key_file_set_string(accounts, account_name, "server", altdomain);
}
if (port != 0) {
g_key_file_set_integer(accounts, account_name, "port", port);
}
Jid *jidp = jid_create(barejid);
GString *muc_service = g_string_new("conference.");
@ -211,6 +215,9 @@ _accounts_get_account(const char * const name)
account->server = NULL;
}
int port = g_key_file_get_integer(accounts, name, "port", NULL);
account->port = port;
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
if (resource != NULL) {
account->resource = strdup(resource);
@ -435,6 +442,15 @@ _accounts_set_server(const char * const account_name, const char * const value)
}
}
static void
_accounts_set_port(const char * const account_name, const int value)
{
if (value != 0) {
g_key_file_set_integer(accounts, account_name, "port", value);
_save_accounts();
}
}
static void
_accounts_set_resource(const char * const account_name, const char * const value)
{
@ -736,6 +752,7 @@ accounts_init_module(void)
accounts_account_exists = _accounts_account_exists;
accounts_set_jid = _accounts_set_jid;
accounts_set_server = _accounts_set_server;
accounts_set_port = _accounts_set_port;
accounts_set_resource = _accounts_set_resource;
accounts_set_password = _accounts_set_password;
accounts_set_muc_service = _accounts_set_muc_service;

View File

@ -33,6 +33,7 @@ typedef struct prof_account_t {
gchar *password;
gchar *resource;
gchar *server;
int port;
gchar *last_presence;
gchar *login_presence;
gint priority_online;
@ -55,7 +56,7 @@ char * (*accounts_find_all)(char *prefix);
char * (*accounts_find_enabled)(char *prefix);
void (*accounts_reset_all_search)(void);
void (*accounts_reset_enabled_search)(void);
void (*accounts_add)(const char *jid, const char *altdomain);
void (*accounts_add)(const char *jid, const char *altdomain, const int port);
gchar** (*accounts_get_list)(void);
ProfAccount* (*accounts_get_account)(const char * const name);
void (*accounts_free_account)(ProfAccount *account);
@ -66,6 +67,7 @@ gboolean (*accounts_rename)(const char * const account_name,
gboolean (*accounts_account_exists)(const char * const account_name);
void (*accounts_set_jid)(const char * const account_name, const char * const value);
void (*accounts_set_server)(const char * const account_name, const char * const value);
void (*accounts_set_port)(const char * const account_name, const int value);
void (*accounts_set_resource)(const char * const account_name, const char * const 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);

View File

@ -797,6 +797,9 @@ _cons_show_account(ProfAccount *account)
if (account->server != NULL) {
cons_show ("server : %s", account->server);
}
if (account->port != 0) {
cons_show ("port : %d", account->port);
}
if (account->muc_service != NULL) {
cons_show ("muc service : %s", account->muc_service);
}

View File

@ -69,6 +69,7 @@ static struct {
char *jid;
char *passwd;
char *altdomain;
int port;
} saved_details;
static GTimer *reconnect_timer;
@ -81,7 +82,7 @@ static void _xmpp_file_logger(void * const userdata,
static xmpp_log_t * _xmpp_get_file_logger(void);
static jabber_conn_status_t _jabber_connect(const char * const fulljid,
const char * const passwd, const char * const altdomain);
const char * const passwd, const char * const altdomain, int port);
static void _jabber_reconnect(void);
static void _connection_handler(xmpp_conn_t * const conn,
@ -124,7 +125,7 @@ _jabber_connect_with_account(const ProfAccount * const account)
// connect with fulljid
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
jabber_conn_status_t result =
_jabber_connect(jidp->fulljid, account->password, account->server);
_jabber_connect(jidp->fulljid, account->password, account->server, account->port);
jid_destroy(jidp);
return result;
@ -132,7 +133,7 @@ _jabber_connect_with_account(const ProfAccount * const account)
static jabber_conn_status_t
_jabber_connect_with_details(const char * const jid,
const char * const passwd, const char * const altdomain)
const char * const passwd, const char * const altdomain, const int port)
{
assert(jid != NULL);
assert(passwd != NULL);
@ -145,6 +146,11 @@ _jabber_connect_with_details(const char * const jid,
} else {
saved_details.altdomain = NULL;
}
if (port != 0) {
saved_details.port = port;
} else {
saved_details.port = 0;
}
// use 'profanity' when no resourcepart in provided jid
Jid *jidp = jid_create(jid);
@ -159,7 +165,7 @@ _jabber_connect_with_details(const char * const jid,
// connect with fulljid
log_info("Connecting without account, JID: %s", saved_details.jid);
return _jabber_connect(saved_details.jid, passwd, saved_details.altdomain);
return _jabber_connect(saved_details.jid, passwd, saved_details.altdomain, saved_details.port);
}
static void
@ -381,7 +387,7 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
static jabber_conn_status_t
_jabber_connect(const char * const fulljid, const char * const passwd,
const char * const altdomain)
const char * const altdomain, int port)
{
assert(fulljid != NULL);
assert(passwd != NULL);
@ -425,7 +431,7 @@ _jabber_connect(const char * const fulljid, const char * const passwd,
xmpp_conn_disable_tls(jabber_conn.conn);
}
int connect_status = xmpp_connect_client(jabber_conn.conn, altdomain, 0,
int connect_status = xmpp_connect_client(jabber_conn.conn, altdomain, port,
_connection_handler, jabber_conn.ctx);
if (connect_status == 0)
@ -447,7 +453,7 @@ _jabber_reconnect(void)
} else {
char *fulljid = create_fulljid(account->jid, account->resource);
log_debug("Attempting reconnect with account %s", account->name);
_jabber_connect(fulljid, saved_account.passwd, account->server);
_jabber_connect(fulljid, saved_account.passwd, account->server, account->port);
free(fulljid);
g_timer_start(reconnect_timer);
}
@ -472,7 +478,7 @@ _connection_handler(xmpp_conn_t * const conn,
// logged in without account, use details to create new account
} else {
log_debug("Connection handler: logged in with jid: %s", saved_details.name);
accounts_add(saved_details.name, saved_details.altdomain);
accounts_add(saved_details.name, saved_details.altdomain, saved_details.port);
accounts_set_jid(saved_details.name, saved_details.jid);
handle_login_account_success(saved_details.name);

View File

@ -85,7 +85,7 @@ void roster_init_module(void);
// connection functions
void (*jabber_init)(const int disable_tls);
jabber_conn_status_t (*jabber_connect_with_details)(const char * const jid,
const char * const passwd, const char * const altdomain);
const char * const passwd, const char * const altdomain, const int port);
jabber_conn_status_t (*jabber_connect_with_account)(const ProfAccount * const account);
void (*jabber_disconnect)(void);
void (*jabber_shutdown)(void);

View File

@ -62,14 +62,14 @@ _mock_accounts_get_list(void)
}
void
_mock_accounts_add(const char *account_name, const char *altdomain)
_mock_accounts_add(const char *account_name, const char *altdomain, const int port)
{
check_expected(account_name);
check_expected(altdomain);
}
void
_stub_accounts_add(const char *account_name, const char *altdomain)
_stub_accounts_add(const char *account_name, const char *altdomain, const int port)
{
// do nothing
}

View File

@ -52,6 +52,230 @@ void cmd_connect_shows_message_when_undefined(void **state)
test_with_connection_status(JABBER_UNDEFINED);
}
void cmd_connect_shows_usage_when_no_server_value(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "server", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_server_no_port_value(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "server", "aserver", "port", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_no_port_value(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "port", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_port_no_server_value(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "port", "5678", "server", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_message_when_port_0(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "port", "0", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Value 0 out of range. Must be in 1..65535.");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_message_when_port_minus1(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "port", "-1", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Value -1 out of range. Must be in 1..65535.");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_message_when_port_65536(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "port", "65536", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Value 65536 out of range. Must be in 1..65535.");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_message_when_port_contains_chars(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "port", "52f66", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Could not convert \"52f66\" to a number.");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_server_provided_twice(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "server", "server1", "server", "server2", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_port_provided_twice(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "port", "1111", "port", "1111", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_invalid_first_property(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "wrong", "server", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_usage_when_invalid_second_property(void **state)
{
stub_ui_ask_password();
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "user@server.org", "server", "aserver", "wrong", "1234", NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("Usage: some usage");
expect_cons_show("");
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_when_no_account(void **state)
{
mock_cons_show();
@ -69,7 +293,7 @@ void cmd_connect_when_no_account(void **state)
expect_cons_show("Connecting as user@server.org");
jabber_connect_with_username_password_expect_and_return("user@server.org", "password", JABBER_CONNECTING);
jabber_connect_with_details_expect_and_return("user@server.org", "password", NULL, 0, JABBER_CONNECTING);
gboolean result = cmd_connect(args, *help);
assert_true(result);
@ -77,20 +301,68 @@ void cmd_connect_when_no_account(void **state)
free(help);
}
void cmd_connect_with_altdomain_when_provided(void **state)
void cmd_connect_with_server_when_provided(void **state)
{
stub_ui_ask_password();
mock_ui_ask_password();
stub_cons_show();
mock_accounts_get_account();
mock_jabber_connect_with_details();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "altdomain" };
gchar *args[] = { "user@server.org", "server", "aserver", NULL };
mock_connection_status(JABBER_DISCONNECTED);
accounts_get_account_return(NULL);
jabber_connect_with_altdomain_expect_and_return("altdomain", JABBER_CONNECTING);
mock_ui_ask_password_returns("password");
jabber_connect_with_details_expect_and_return("user@server.org", "password", "aserver", 0, JABBER_CONNECTING);
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_with_port_when_provided(void **state)
{
mock_ui_ask_password();
stub_cons_show();
mock_accounts_get_account();
mock_jabber_connect_with_details();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "port", "5432", NULL };
mock_connection_status(JABBER_DISCONNECTED);
accounts_get_account_return(NULL);
mock_ui_ask_password_returns("password");
jabber_connect_with_details_expect_and_return("user@server.org", "password", NULL, 5432, JABBER_CONNECTING);
gboolean result = cmd_connect(args, *help);
assert_true(result);
free(help);
}
void cmd_connect_with_server_and_port_when_provided(void **state)
{
mock_ui_ask_password();
stub_cons_show();
mock_accounts_get_account();
mock_jabber_connect_with_details();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL };
mock_connection_status(JABBER_DISCONNECTED);
accounts_get_account_return(NULL);
mock_ui_ask_password_returns("password");
jabber_connect_with_details_expect_and_return("user@server.org", "password", "aserver", 5432, JABBER_CONNECTING);
gboolean result = cmd_connect(args, *help);
assert_true(result);

View File

@ -10,3 +10,18 @@ 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);
void cmd_connect_shows_usage_when_port_no_server_value(void **state);
void cmd_connect_shows_message_when_port_0(void **state);
void cmd_connect_shows_message_when_port_minus1(void **state);
void cmd_connect_shows_message_when_port_65536(void **state);
void cmd_connect_shows_message_when_port_contains_chars(void **state);
void cmd_connect_with_server_when_provided(void **state);
void cmd_connect_with_port_when_provided(void **state);
void cmd_connect_with_server_and_port_when_provided(void **state);
void cmd_connect_shows_usage_when_server_provided_twice(void **state);
void cmd_connect_shows_usage_when_port_provided_twice(void **state);
void cmd_connect_shows_usage_when_invalid_first_property(void **state);
void cmd_connect_shows_usage_when_invalid_second_property(void **state);

View File

@ -173,13 +173,27 @@ int main(int argc, char* argv[]) {
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_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),
unit_test(cmd_connect_shows_usage_when_port_no_server_value),
unit_test(cmd_connect_shows_message_when_port_0),
unit_test(cmd_connect_shows_message_when_port_minus1),
unit_test(cmd_connect_shows_message_when_port_65536),
unit_test(cmd_connect_shows_message_when_port_contains_chars),
unit_test(cmd_connect_with_server_when_provided),
unit_test(cmd_connect_with_port_when_provided),
unit_test(cmd_connect_with_server_and_port_when_provided),
unit_test(cmd_connect_shows_usage_when_server_provided_twice),
unit_test(cmd_connect_shows_usage_when_port_provided_twice),
unit_test(cmd_connect_shows_usage_when_invalid_first_property),
unit_test(cmd_connect_shows_usage_when_invalid_second_property),
unit_test(cmd_rooms_shows_message_when_disconnected),
unit_test(cmd_rooms_shows_message_when_disconnecting),

View File

@ -28,11 +28,12 @@ _mock_iq_room_list_request(gchar *conf_server)
static jabber_conn_status_t
_mock_jabber_connect_with_details(const char * const jid,
const char * const passwd, const char * const altdomain)
const char * const passwd, const char * const altdomain, const int port)
{
check_expected(jid);
check_expected(passwd);
check_expected(altdomain);
check_expected(port);
return (jabber_conn_status_t)mock();
}
@ -104,22 +105,17 @@ expect_room_list_request(char *conf_server)
}
void
jabber_connect_with_username_password_expect_and_return(char *jid,
char *password, jabber_conn_status_t result)
jabber_connect_with_details_expect_and_return(char *jid,
char *password, char *altdomain, int port, jabber_conn_status_t result)
{
expect_string(_mock_jabber_connect_with_details, jid, jid);
expect_string(_mock_jabber_connect_with_details, passwd, password);
expect_any(_mock_jabber_connect_with_details, altdomain);
will_return(_mock_jabber_connect_with_details, result);
}
void
jabber_connect_with_altdomain_expect_and_return(char *altdomain,
jabber_conn_status_t result)
{
expect_any(_mock_jabber_connect_with_details, jid);
expect_any(_mock_jabber_connect_with_details, passwd);
expect_string(_mock_jabber_connect_with_details, altdomain, altdomain);
if (altdomain == NULL) {
expect_any(_mock_jabber_connect_with_details, altdomain);
} else {
expect_string(_mock_jabber_connect_with_details, altdomain, altdomain);
}
expect_value(_mock_jabber_connect_with_details, port, port);
will_return(_mock_jabber_connect_with_details, result);
}
@ -129,6 +125,7 @@ jabber_connect_with_details_return(jabber_conn_status_t result)
expect_any(_mock_jabber_connect_with_details, jid);
expect_any(_mock_jabber_connect_with_details, passwd);
expect_any(_mock_jabber_connect_with_details, altdomain);
expect_any(_mock_jabber_connect_with_details, port);
will_return(_mock_jabber_connect_with_details, result);
}

View File

@ -9,10 +9,8 @@ void mock_connection_presence_message(char *message);
void expect_room_list_request(char *conf_server);
void mock_jabber_connect_with_details(void);
void jabber_connect_with_username_password_expect_and_return(char *jid,
char *password, jabber_conn_status_t result);
void jabber_connect_with_altdomain_expect_and_return(char *altdomain,
jabber_conn_status_t result);
void jabber_connect_with_details_expect_and_return(char *jid,
char *password, char *altdomain, int port, jabber_conn_status_t result);
void jabber_connect_with_details_return(jabber_conn_status_t result);
void mock_jabber_connect_with_account(void);