2013-12-14 16:17:53 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <stdlib.h>
|
2013-12-15 19:38:23 +00:00
|
|
|
#include <string.h>
|
2013-12-14 17:15:43 +00:00
|
|
|
#include <glib.h>
|
2013-12-14 16:17:53 +00:00
|
|
|
|
|
|
|
#include "xmpp/xmpp.h"
|
|
|
|
#include "ui/ui.h"
|
2013-12-15 16:10:32 +00:00
|
|
|
#include "command/commands.h"
|
2013-12-14 16:17:53 +00:00
|
|
|
|
2013-12-14 18:43:19 +00:00
|
|
|
static void test_with_connection_status(jabber_conn_status_t status)
|
2013-12-14 16:17:53 +00:00
|
|
|
{
|
2013-12-14 17:15:43 +00:00
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
2013-12-15 20:38:26 +00:00
|
|
|
|
2013-12-14 18:43:19 +00:00
|
|
|
will_return(jabber_get_connection_status, status);
|
2013-12-15 19:38:23 +00:00
|
|
|
expect_string(cons_show, output, "You are either connected already, or a login is in process.");
|
2013-12-15 20:38:26 +00:00
|
|
|
|
2013-12-15 18:08:26 +00:00
|
|
|
gboolean result = cmd_connect(NULL, *help);
|
2013-12-14 18:43:19 +00:00
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
2013-12-15 18:08:26 +00:00
|
|
|
void cmd_connect_shows_message_when_disconnecting(void **state)
|
2013-12-14 18:43:19 +00:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTING);
|
|
|
|
}
|
|
|
|
|
2013-12-15 18:08:26 +00:00
|
|
|
void cmd_connect_shows_message_when_connecting(void **state)
|
2013-12-14 18:43:19 +00:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_CONNECTING);
|
|
|
|
}
|
|
|
|
|
2013-12-15 18:08:26 +00:00
|
|
|
void cmd_connect_shows_message_when_connected(void **state)
|
2013-12-14 18:43:19 +00:00
|
|
|
{
|
2013-12-15 18:08:26 +00:00
|
|
|
test_with_connection_status(JABBER_CONNECTED);
|
2013-12-14 18:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 18:08:26 +00:00
|
|
|
void cmd_connect_shows_message_when_undefined(void **state)
|
2013-12-14 18:43:19 +00:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_UNDEFINED);
|
|
|
|
}
|
2013-12-15 19:38:23 +00:00
|
|
|
|
|
|
|
void cmd_connect_when_no_account(void **state)
|
2013-12-14 18:43:19 +00:00
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
2013-12-15 19:38:23 +00:00
|
|
|
gchar *args[] = { "user@server.org", NULL };
|
2013-12-14 18:43:19 +00:00
|
|
|
|
2013-12-15 19:38:23 +00:00
|
|
|
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
2013-12-15 20:38:26 +00:00
|
|
|
|
2013-12-15 19:38:23 +00:00
|
|
|
expect_string(accounts_get_account, name, "user@server.org");
|
|
|
|
will_return(accounts_get_account, NULL);
|
2013-12-14 16:17:53 +00:00
|
|
|
|
2013-12-15 19:38:23 +00:00
|
|
|
will_return(ui_ask_password, strdup("password"));
|
2013-12-14 16:17:53 +00:00
|
|
|
|
2013-12-15 19:38:23 +00:00
|
|
|
expect_string(cons_show, output, "Connecting as user@server.org");
|
2013-12-14 18:43:19 +00:00
|
|
|
|
2013-12-15 19:38:23 +00:00
|
|
|
expect_string(jabber_connect_with_details, jid, "user@server.org");
|
|
|
|
expect_string(jabber_connect_with_details, passwd, "password");
|
|
|
|
expect_any(jabber_connect_with_details, altdomain);
|
|
|
|
will_return(jabber_connect_with_details, JABBER_CONNECTING);
|
2013-12-14 18:43:19 +00:00
|
|
|
|
2013-12-15 19:38:23 +00:00
|
|
|
gboolean result = cmd_connect(args, *help);
|
2013-12-14 18:43:19 +00:00
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
2013-12-15 19:56:48 +00:00
|
|
|
|
|
|
|
void cmd_connect_with_altdomain_when_provided(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "user@server.org", "altdomain" };
|
|
|
|
|
|
|
|
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
2013-12-15 20:38:26 +00:00
|
|
|
|
2013-12-15 20:02:25 +00:00
|
|
|
expect_any(accounts_get_account, name);
|
2013-12-15 19:56:48 +00:00
|
|
|
will_return(accounts_get_account, NULL);
|
|
|
|
|
|
|
|
will_return(ui_ask_password, strdup("password"));
|
|
|
|
|
2013-12-15 20:02:25 +00:00
|
|
|
expect_any(cons_show, output);
|
2013-12-15 19:56:48 +00:00
|
|
|
|
2013-12-15 20:02:25 +00:00
|
|
|
expect_any(jabber_connect_with_details, jid);
|
|
|
|
expect_any(jabber_connect_with_details, passwd);
|
2013-12-15 19:56:48 +00:00
|
|
|
expect_string(jabber_connect_with_details, altdomain, "altdomain");
|
|
|
|
will_return(jabber_connect_with_details, JABBER_CONNECTING);
|
|
|
|
|
|
|
|
gboolean result = cmd_connect(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_connect_fail_message(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
2013-12-15 20:02:25 +00:00
|
|
|
gchar *args[] = { "user@server.org", NULL };
|
2013-12-15 19:56:48 +00:00
|
|
|
|
|
|
|
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
2013-12-15 20:38:26 +00:00
|
|
|
|
2013-12-15 20:02:25 +00:00
|
|
|
expect_any(accounts_get_account, name);
|
2013-12-15 19:56:48 +00:00
|
|
|
will_return(accounts_get_account, NULL);
|
|
|
|
|
|
|
|
will_return(ui_ask_password, strdup("password"));
|
|
|
|
|
2013-12-15 20:02:25 +00:00
|
|
|
expect_any(cons_show, output);
|
2013-12-15 19:56:48 +00:00
|
|
|
|
2013-12-15 20:02:25 +00:00
|
|
|
expect_any(jabber_connect_with_details, jid);
|
|
|
|
expect_any(jabber_connect_with_details, passwd);
|
|
|
|
expect_any(jabber_connect_with_details, altdomain);
|
2013-12-15 19:56:48 +00:00
|
|
|
will_return(jabber_connect_with_details, JABBER_DISCONNECTED);
|
|
|
|
|
|
|
|
expect_string(cons_show_error, output, "Connection attempt for user@server.org failed.");
|
|
|
|
|
|
|
|
gboolean result = cmd_connect(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
2013-12-15 20:38:26 +00:00
|
|
|
|
|
|
|
void cmd_connect_lowercases_argument(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "USER@server.ORG", NULL };
|
|
|
|
|
|
|
|
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
|
|
|
|
|
|
|
expect_string(accounts_get_account, name, "user@server.org");
|
|
|
|
will_return(accounts_get_account, NULL);
|
|
|
|
|
|
|
|
will_return(ui_ask_password, strdup("password"));
|
|
|
|
|
|
|
|
expect_any(cons_show, output);
|
|
|
|
|
|
|
|
expect_any(jabber_connect_with_details, jid);
|
|
|
|
expect_any(jabber_connect_with_details, passwd);
|
|
|
|
expect_any(jabber_connect_with_details, altdomain);
|
|
|
|
will_return(jabber_connect_with_details, JABBER_CONNECTING);
|
|
|
|
|
|
|
|
gboolean result = cmd_connect(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
2013-12-15 20:52:30 +00:00
|
|
|
|
|
|
|
void cmd_connect_asks_password_when_not_in_account(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "jabber_org", NULL };
|
|
|
|
ProfAccount *account = malloc(sizeof(ProfAccount));
|
|
|
|
account->password = NULL;
|
|
|
|
|
|
|
|
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
|
|
|
|
|
|
|
expect_any(accounts_get_account, name);
|
|
|
|
will_return(accounts_get_account, account);
|
|
|
|
|
|
|
|
will_return(accounts_create_full_jid, strdup("user@jabber.org"));
|
|
|
|
|
|
|
|
will_return(ui_ask_password, strdup("password"));
|
|
|
|
|
|
|
|
expect_any(cons_show, output);
|
|
|
|
will_return(jabber_connect_with_account, JABBER_CONNECTING);
|
|
|
|
|
|
|
|
gboolean result = cmd_connect(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
free(account);
|
|
|
|
}
|