mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Added cmd_roster tests
This commit is contained in:
parent
7db1bcee05
commit
a871ad8004
@ -73,6 +73,7 @@ tests_sources = \
|
||||
tests/test_cmd_join.c tests/test_cmd_join.h \
|
||||
tests/test_cmd_otr.c tests/test_cmd_otr.h \
|
||||
tests/test_cmd_rooms.c tests/test_cmd_rooms.h \
|
||||
tests/test_cmd_roster.c tests/test_cmd_roster.h \
|
||||
tests/test_autocomplete.c tests/test_autocomplete.h \
|
||||
tests/testsuite.c
|
||||
|
||||
|
@ -7,20 +7,17 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "ui/ui.h"
|
||||
#include "ui/mock_ui.h"
|
||||
#include "ui/stub_ui.h"
|
||||
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/mock_xmpp.h"
|
||||
|
||||
#include "roster_list.h"
|
||||
#include "command/commands.h"
|
||||
|
||||
static void test_with_connection_status(jabber_conn_status_t status)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
|
||||
mock_connection_status(status);
|
||||
will_return(jabber_get_connection_status, status);
|
||||
|
||||
expect_cons_show("You are not currently connected.");
|
||||
|
||||
@ -52,15 +49,16 @@ void cmd_roster_shows_message_when_undefined(void **state)
|
||||
|
||||
void cmd_roster_shows_roster_when_no_args(void **state)
|
||||
{
|
||||
mock_cons_show_roster();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
roster_init();
|
||||
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
|
||||
GSList *roster = roster_get_contacts();
|
||||
cons_show_roster_expect(roster);
|
||||
|
||||
expect_memory(cons_show_roster, list, roster, sizeof(roster));
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
assert_true(result);
|
||||
@ -71,12 +69,12 @@ void cmd_roster_shows_roster_when_no_args(void **state)
|
||||
|
||||
void cmd_roster_add_shows_message_when_no_jid(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "add", NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -92,9 +90,10 @@ void cmd_roster_add_sends_roster_add_request(void **state)
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "add", jid, nick, NULL };
|
||||
|
||||
mock_roster_send_add_new();
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
roster_send_add_new_expect(jid, nick);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(roster_send_add_new, barejid, jid);
|
||||
expect_string(roster_send_add_new, name, nick);
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
assert_true(result);
|
||||
@ -104,12 +103,12 @@ void cmd_roster_add_sends_roster_add_request(void **state)
|
||||
|
||||
void cmd_roster_remove_shows_message_when_no_jid(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "remove", NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -124,9 +123,9 @@ void cmd_roster_remove_sends_roster_remove_request(void **state)
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "remove", jid, NULL };
|
||||
|
||||
mock_roster_send_remove();
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
roster_send_remove_expect(jid);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(roster_send_remove, barejid, jid);
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
assert_true(result);
|
||||
@ -136,12 +135,12 @@ void cmd_roster_remove_sends_roster_remove_request(void **state)
|
||||
|
||||
void cmd_roster_nick_shows_message_when_no_jid(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "nick", NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -152,12 +151,12 @@ void cmd_roster_nick_shows_message_when_no_jid(void **state)
|
||||
|
||||
void cmd_roster_nick_shows_message_when_no_nick(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "nick", "bob@server.org", NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -168,13 +167,14 @@ void cmd_roster_nick_shows_message_when_no_nick(void **state)
|
||||
|
||||
void cmd_roster_nick_shows_message_when_no_contact_exists(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "nick", "bob@server.org", "bobster", NULL };
|
||||
|
||||
roster_init();
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Contact not found in roster: bob@server.org");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -188,8 +188,6 @@ void cmd_roster_nick_sends_name_change_request(void **state)
|
||||
{
|
||||
char *jid = "bob@server.org";
|
||||
char *nick = "bobster";
|
||||
mock_cons_show();
|
||||
mock_roster_send_name_change();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "nick", jid, nick, NULL };
|
||||
|
||||
@ -198,8 +196,12 @@ void cmd_roster_nick_sends_name_change_request(void **state)
|
||||
groups = g_slist_append(groups, "group1");
|
||||
roster_add(jid, "bob", groups, "both", FALSE);
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
roster_send_name_change_expect(jid, nick, groups);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
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));
|
||||
|
||||
expect_cons_show("Nickname for bob@server.org set to: bobster.");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -214,12 +216,12 @@ void cmd_roster_nick_sends_name_change_request(void **state)
|
||||
|
||||
void cmd_roster_clearnick_shows_message_when_no_jid(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "clearnick", NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Usage: some usage");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -230,13 +232,14 @@ void cmd_roster_clearnick_shows_message_when_no_jid(void **state)
|
||||
|
||||
void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "some usage";
|
||||
gchar *args[] = { "clearnick", "bob@server.org", NULL };
|
||||
|
||||
roster_init();
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Contact not found in roster: bob@server.org");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
@ -249,8 +252,6 @@ void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state)
|
||||
void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state)
|
||||
{
|
||||
char *jid = "bob@server.org";
|
||||
mock_cons_show();
|
||||
mock_roster_send_name_change();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "clearnick", jid, NULL };
|
||||
|
||||
@ -259,8 +260,12 @@ void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state
|
||||
groups = g_slist_append(groups, "group1");
|
||||
roster_add(jid, "bob", groups, "both", FALSE);
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
roster_send_name_change_expect(jid, NULL, groups);
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
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));
|
||||
|
||||
expect_cons_show("Nickname for bob@server.org removed.");
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
|
@ -501,7 +501,7 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_join_uses_supplied_nick),
|
||||
unit_test(cmd_join_uses_account_nick_when_not_supplied),
|
||||
unit_test(cmd_join_uses_password_when_supplied),
|
||||
/*
|
||||
|
||||
unit_test(cmd_roster_shows_message_when_disconnecting),
|
||||
unit_test(cmd_roster_shows_message_when_connecting),
|
||||
unit_test(cmd_roster_shows_message_when_disconnected),
|
||||
@ -518,7 +518,7 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_roster_clearnick_shows_message_when_no_jid),
|
||||
unit_test(cmd_roster_clearnick_shows_message_when_no_contact_exists),
|
||||
unit_test(cmd_roster_clearnick_sends_name_change_request_with_empty_nick),
|
||||
|
||||
/*
|
||||
unit_test(cmd_win_shows_message_when_win_doesnt_exist),
|
||||
unit_test(cmd_win_switches_to_given_win_when_exists),
|
||||
|
||||
|
@ -354,7 +354,12 @@ void cons_show_error(const char * const cmd, ...)
|
||||
}
|
||||
|
||||
void cons_show_contacts(GSList * list) {}
|
||||
void cons_show_roster(GSList * list) {}
|
||||
|
||||
void cons_show_roster(GSList * list)
|
||||
{
|
||||
check_expected(list);
|
||||
}
|
||||
|
||||
void cons_show_roster_group(const char * const group, GSList * list) {}
|
||||
void cons_show_wins(void) {}
|
||||
void cons_show_status(const char * const barejid) {}
|
||||
|
@ -196,11 +196,26 @@ char * bookmark_find(char *search_str)
|
||||
|
||||
void bookmark_autocomplete_reset(void) {}
|
||||
|
||||
void roster_send_name_change(const char * const barejid, const char * const new_name, GSList *groups) {}
|
||||
void roster_send_name_change(const char * const barejid, const char * const new_name, GSList *groups)
|
||||
{
|
||||
check_expected(barejid);
|
||||
check_expected(new_name);
|
||||
check_expected(groups);
|
||||
}
|
||||
|
||||
void roster_send_add_to_group(const char * const group, PContact contact) {}
|
||||
void roster_send_remove_from_group(const char * const group, PContact contact) {}
|
||||
void roster_send_add_new(const char * const barejid, const char * const name) {}
|
||||
void roster_send_remove(const char * const barejid) {}
|
||||
|
||||
void roster_send_add_new(const char * const barejid, const char * const name)
|
||||
{
|
||||
check_expected(barejid);
|
||||
check_expected(name);
|
||||
}
|
||||
|
||||
void roster_send_remove(const char * const barejid)
|
||||
{
|
||||
check_expected(barejid);
|
||||
}
|
||||
|
||||
void form_destroy(DataForm *form) {}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user