2013-12-14 11:17:53 -05:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <stdlib.h>
|
2014-10-31 21:48:36 -04:00
|
|
|
#include <string.h>
|
2013-12-14 12:15:43 -05:00
|
|
|
#include <glib.h>
|
2013-12-14 11:17:53 -05:00
|
|
|
|
|
|
|
#include "xmpp/xmpp.h"
|
2013-12-18 18:06:43 -05:00
|
|
|
#include "xmpp/mock_xmpp.h"
|
|
|
|
|
2013-12-14 11:17:53 -05:00
|
|
|
#include "ui/ui.h"
|
2013-12-19 16:05:39 -05:00
|
|
|
#include "ui/mock_ui.h"
|
2013-12-18 18:06:43 -05:00
|
|
|
|
2013-12-26 08:37:22 -05:00
|
|
|
#include "config/accounts.h"
|
|
|
|
#include "config/mock_accounts.h"
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
#include "command/commands.h"
|
2013-12-14 11:17:53 -05:00
|
|
|
|
2013-12-14 13:43:19 -05:00
|
|
|
static void test_with_connection_status(jabber_conn_status_t status)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-19 16:05:39 -05:00
|
|
|
mock_cons_show();
|
2013-12-14 12:15:43 -05:00
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2013-12-18 17:49:43 -05:00
|
|
|
mock_connection_status(status);
|
2013-12-19 16:05:39 -05:00
|
|
|
expect_cons_show("You are not currently connected.");
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean result = cmd_rooms(NULL, *help);
|
2013-12-14 13:43:19 -05:00
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_rooms_shows_message_when_disconnected(void **state)
|
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_rooms_shows_message_when_disconnecting(void **state)
|
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_rooms_shows_message_when_connecting(void **state)
|
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_CONNECTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_rooms_shows_message_when_started(void **state)
|
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_STARTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_rooms_shows_message_when_undefined(void **state)
|
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_UNDEFINED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_rooms_uses_account_default_when_no_arg(void **state)
|
|
|
|
{
|
2013-12-26 08:37:22 -05:00
|
|
|
mock_accounts_get_account();
|
2013-12-14 13:43:19 -05:00
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
2013-12-15 15:38:26 -05:00
|
|
|
gchar *args[] = { NULL };
|
2014-10-31 21:48:36 -04:00
|
|
|
ProfAccount *account = malloc(sizeof(ProfAccount));
|
|
|
|
account->name = NULL;
|
|
|
|
account->jid = NULL;
|
|
|
|
account->password = NULL;
|
|
|
|
account->resource = NULL;
|
|
|
|
account->server = NULL;
|
|
|
|
account->last_presence = NULL;
|
|
|
|
account->login_presence = NULL;
|
|
|
|
account->muc_nick = NULL;
|
|
|
|
account->otr_policy = NULL;
|
|
|
|
account->otr_manual = NULL;
|
|
|
|
account->otr_opportunistic = NULL;
|
|
|
|
account->otr_always = NULL;
|
|
|
|
account->muc_service = strdup("default_conf_server");
|
2013-12-14 13:43:19 -05:00
|
|
|
|
2013-12-18 17:49:43 -05:00
|
|
|
mock_connection_status(JABBER_CONNECTED);
|
|
|
|
mock_connection_account_name("account_name");
|
|
|
|
|
2013-12-26 08:37:22 -05:00
|
|
|
accounts_get_account_return(account);
|
2013-12-18 17:49:43 -05:00
|
|
|
|
|
|
|
expect_room_list_request("default_conf_server");
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean result = cmd_rooms(args, *help);
|
2013-12-14 11:17:53 -05:00
|
|
|
|
2013-12-14 12:15:43 -05:00
|
|
|
assert_true(result);
|
2013-12-14 11:17:53 -05:00
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
2013-12-15 13:08:26 -05:00
|
|
|
void cmd_rooms_arg_used_when_passed(void **state)
|
2013-12-14 13:43:19 -05:00
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
2013-12-15 15:38:26 -05:00
|
|
|
gchar *args[] = { "conf_server_arg" };
|
2013-12-14 13:43:19 -05:00
|
|
|
|
2013-12-18 17:49:43 -05:00
|
|
|
mock_connection_status(JABBER_CONNECTED);
|
|
|
|
|
|
|
|
expect_room_list_request("conf_server_arg");
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean result = cmd_rooms(args, *help);
|
2013-12-14 13:43:19 -05:00
|
|
|
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|