2014-03-15 21:23:12 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2014-03-15 21:23:12 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <glib.h>
|
2014-03-15 21:23:12 -04:00
|
|
|
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "ui/ui.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "ui/stub_ui.h"
|
2014-03-15 21:23:12 -04:00
|
|
|
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "xmpp/xmpp.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/roster_list.h"
|
|
|
|
#include "command/cmd_funcs.h"
|
2014-03-15 21:23:12 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
#define CMD_ROSTER "/roster"
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static void
|
|
|
|
test_with_connection_status(jabber_conn_status_t status)
|
2014-03-15 21:23:12 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { NULL };
|
2014-03-15 21:23:12 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, status);
|
2014-03-15 21:23:12 -04:00
|
|
|
|
|
|
|
expect_cons_show("You are not currently connected.");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-15 21:23:12 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_shows_message_when_disconnecting(void** state)
|
2014-03-15 21:23:12 -04:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTING);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_shows_message_when_connecting(void** state)
|
2014-03-15 21:23:12 -04:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_CONNECTING);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_shows_message_when_disconnected(void** state)
|
2014-03-15 21:23:12 -04:00
|
|
|
{
|
|
|
|
test_with_connection_status(JABBER_DISCONNECTED);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_shows_roster_when_no_args(void** state)
|
2014-03-15 21:23:12 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { NULL };
|
2014-03-15 21:23:12 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2014-03-15 21:23:12 -04:00
|
|
|
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* roster = roster_get_contacts(ROSTER_ORD_NAME);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
|
|
|
expect_memory(cons_show_roster, list, roster, sizeof(roster));
|
2014-03-15 21:23:12 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-15 21:23:12 -04:00
|
|
|
assert_true(result);
|
|
|
|
|
2019-10-13 17:23:02 -04:00
|
|
|
g_slist_free(roster);
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2014-03-15 21:23:12 -04:00
|
|
|
}
|
2014-03-15 21:46:18 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_add_shows_message_when_no_jid(void** state)
|
2014-03-15 21:46:18 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "add", NULL };
|
2014-03-15 21:46:18 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
|
2014-03-15 21:46:18 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-15 21:46:18 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_add_sends_roster_add_request(void** state)
|
2014-03-15 21:46:18 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* jid = "bob@server.org";
|
|
|
|
char* nick = "bob";
|
|
|
|
gchar* args[] = { "add", jid, nick, NULL };
|
2014-03-15 21:46:18 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
|
|
|
expect_string(roster_send_add_new, barejid, jid);
|
|
|
|
expect_string(roster_send_add_new, name, nick);
|
2014-03-15 21:46:18 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-15 21:46:18 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
2014-03-16 12:00:10 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_remove_shows_message_when_no_jid(void** state)
|
2014-03-16 12:00:10 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "remove", NULL };
|
2014-03-16 12:00:10 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
|
2014-03-16 12:00:10 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 12:00:10 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_remove_sends_roster_remove_request(void** state)
|
2014-03-16 12:00:10 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* jid = "bob@server.org";
|
|
|
|
gchar* args[] = { "remove", jid, NULL };
|
2014-03-16 12:00:10 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
|
|
|
expect_string(roster_send_remove, barejid, jid);
|
2014-03-16 12:00:10 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 12:00:10 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_nick_shows_message_when_no_jid(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "nick", NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_nick_shows_message_when_no_nick(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "nick", "bob@server.org", NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_nick_shows_message_when_no_contact_exists(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "nick", "bob@server.org", "bobster", NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2014-03-16 13:53:41 -04:00
|
|
|
expect_cons_show("Contact not found in roster: bob@server.org");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2014-03-16 13:53:41 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_nick_sends_name_change_request(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* jid = "bob@server.org";
|
|
|
|
char* nick = "bobster";
|
|
|
|
gchar* args[] = { "nick", jid, nick, NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* groups = NULL;
|
2016-01-04 19:06:50 -05:00
|
|
|
groups = g_slist_append(groups, strdup("group1"));
|
2014-03-16 13:53:41 -04:00
|
|
|
roster_add(jid, "bob", groups, "both", FALSE);
|
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
|
|
|
expect_string(roster_send_name_change, barejid, jid);
|
|
|
|
expect_string(roster_send_name_change, new_name, nick);
|
|
|
|
expect_memory(roster_send_name_change, groups, groups, sizeof(groups));
|
|
|
|
|
2014-03-16 13:53:41 -04:00
|
|
|
expect_cons_show("Nickname for bob@server.org set to: bobster.");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
PContact contact = roster_get_contact(jid);
|
|
|
|
assert_string_equal(p_contact_name(contact), nick);
|
2019-10-06 12:43:27 -04:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2014-03-16 13:53:41 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_clearnick_shows_message_when_no_jid(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "clearnick", NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_clearnick_shows_message_when_no_contact_exists(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "clearnick", "bob@server.org", NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
2014-03-16 13:53:41 -04:00
|
|
|
expect_cons_show("Contact not found in roster: bob@server.org");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2014-03-16 13:53:41 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void** state)
|
2014-03-16 13:53:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* jid = "bob@server.org";
|
|
|
|
gchar* args[] = { "clearnick", jid, NULL };
|
2014-03-16 13:53:41 -04:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* groups = NULL;
|
2016-01-04 19:06:50 -05:00
|
|
|
groups = g_slist_append(groups, strdup("group1"));
|
2014-03-16 13:53:41 -04:00
|
|
|
roster_add(jid, "bob", groups, "both", FALSE);
|
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2014-12-24 18:59:26 -05:00
|
|
|
|
|
|
|
expect_string(roster_send_name_change, barejid, jid);
|
|
|
|
expect_value(roster_send_name_change, new_name, NULL);
|
|
|
|
expect_memory(roster_send_name_change, groups, groups, sizeof(groups));
|
|
|
|
|
2014-03-16 13:53:41 -04:00
|
|
|
expect_cons_show("Nickname for bob@server.org removed.");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
|
2014-03-16 13:53:41 -04:00
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
PContact contact = roster_get_contact(jid);
|
|
|
|
assert_null(p_contact_name(contact));
|
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2014-03-16 13:53:41 -04:00
|
|
|
}
|