2013-12-14 11:17:53 -05:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2013-12-14 11:17:53 -05:00
|
|
|
#include <stdlib.h>
|
2014-10-31 21:48:36 -04:00
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <glib.h>
|
2013-12-14 11:17:53 -05:00
|
|
|
|
|
|
|
#include "xmpp/xmpp.h"
|
2013-12-18 18:06:43 -05:00
|
|
|
|
2013-12-14 11:17:53 -05:00
|
|
|
#include "ui/ui.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "ui/stub_ui.h"
|
2013-12-18 18:06:43 -05:00
|
|
|
|
2013-12-26 08:37:22 -05:00
|
|
|
#include "config/accounts.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "command/cmd_funcs.h"
|
2013-12-14 11:17:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
#define CMD_ROOMS "/rooms"
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static void
|
|
|
|
test_with_connection_status(jabber_conn_status_t status)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, status);
|
2014-12-24 18:38:23 -05:00
|
|
|
|
2013-12-19 16:05:39 -05:00
|
|
|
expect_cons_show("You are not currently connected.");
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_rooms(NULL, CMD_ROOMS, NULL);
|
2013-12-14 13:43:19 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_rooms_shows_message_when_disconnected(void** state)
|
2013-12-14 13:43:19 -05:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTED);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_rooms_shows_message_when_disconnecting(void** state)
|
2013-12-14 13:43:19 -05:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTING);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_rooms_shows_message_when_connecting(void** state)
|
2013-12-14 13:43:19 -05:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_CONNECTING);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_rooms_uses_account_default_when_no_arg(void** state)
|
2013-12-14 13:43:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { NULL };
|
2015-10-18 19:57:01 -04:00
|
|
|
|
2022-12-27 16:52:12 -05:00
|
|
|
ProfAccount* account = account_new(g_strdup("testaccount"), NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL,
|
2023-04-13 11:16:24 -04:00
|
|
|
0, 0, 0, 0, 0, g_strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
|
2013-12-14 13:43:19 -05:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2016-05-05 19:53:03 -04:00
|
|
|
will_return(session_get_account_name, "account_name");
|
2014-12-24 18:38:23 -05:00
|
|
|
expect_any(accounts_get_account, name);
|
|
|
|
will_return(accounts_get_account, account);
|
2013-12-18 17:49:43 -05:00
|
|
|
|
2018-02-04 16:59:33 -05:00
|
|
|
expect_cons_show("");
|
|
|
|
expect_cons_show("Room list request sent: default_conf_server");
|
|
|
|
|
2014-12-24 18:38:23 -05:00
|
|
|
expect_string(iq_room_list_request, conferencejid, "default_conf_server");
|
2018-01-27 18:51:03 -05:00
|
|
|
expect_any(iq_room_list_request, filter);
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
|
2013-12-14 12:15:43 -05:00
|
|
|
assert_true(result);
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_rooms_service_arg_used_when_passed(void** state)
|
2013-12-14 13:43:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "service", "conf_server_arg", NULL };
|
2013-12-14 13:43:19 -05:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2013-12-18 17:49:43 -05:00
|
|
|
|
2018-02-04 16:59:33 -05:00
|
|
|
expect_cons_show("");
|
|
|
|
expect_cons_show("Room list request sent: conf_server_arg");
|
|
|
|
|
2014-12-24 18:38:23 -05:00
|
|
|
expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
|
2018-01-27 18:51:03 -05:00
|
|
|
expect_any(iq_room_list_request, filter);
|
|
|
|
|
|
|
|
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
|
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_rooms_filter_arg_used_when_passed(void** state)
|
2018-01-27 18:51:03 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "filter", "text", NULL };
|
2020-07-07 07:53:30 -04:00
|
|
|
|
2022-12-27 16:52:12 -05:00
|
|
|
ProfAccount* account = account_new(g_strdup("testaccount"), NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL,
|
2023-04-13 11:16:24 -04:00
|
|
|
0, 0, 0, 0, 0, g_strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
|
2018-01-27 18:51:03 -05:00
|
|
|
|
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
|
|
|
will_return(session_get_account_name, "account_name");
|
|
|
|
expect_any(accounts_get_account, name);
|
|
|
|
will_return(accounts_get_account, account);
|
|
|
|
|
2018-02-04 16:59:33 -05:00
|
|
|
expect_cons_show("");
|
|
|
|
expect_cons_show("Room list request sent: default_conf_server, filter: 'text'");
|
|
|
|
|
2018-01-27 18:51:03 -05:00
|
|
|
expect_any(iq_room_list_request, conferencejid);
|
|
|
|
expect_string(iq_room_list_request, filter, "text");
|
2013-12-15 15:38:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
|
2013-12-14 13:43:19 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|