1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-03-16 01:47:04 +00:00
commit 80f2a5c8bc
9 changed files with 166 additions and 2 deletions

View File

@ -81,6 +81,7 @@ tests_sources = \
tests/test_preferences.c \
tests/test_server_events.c \
tests/test_muc.c \
tests/test_cmd_roster.c \
tests/testsuite.c
main_source = src/main.c

View File

@ -84,7 +84,7 @@ static struct cmd_t command_defs[] =
"-------------------------",
"Use with no arguments to get a help summary.",
"Supply an area to see help for commands related to specific features.",
"Supply a command (without the leading slash) to see help on that command.",
"Supply a command (without the leading slash) to see help for that command.",
"",
"Example : /help commands",
"Example : /help presence",
@ -98,7 +98,7 @@ static struct cmd_t command_defs[] =
{ "/about", "About Profanity.",
{ "/about",
"------",
"Show versioning and license information.",
"Show version and license information.",
NULL } } },
{ "/connect",

103
tests/test_cmd_roster.c Normal file
View File

@ -0,0 +1,103 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "ui/ui.h"
#include "ui/mock_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);
expect_cons_show("You are not currently connected.");
gboolean result = cmd_roster(NULL, *help);
assert_true(result);
free(help);
}
void cmd_roster_shows_message_when_disconnecting(void **state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void cmd_roster_shows_message_when_connecting(void **state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void cmd_roster_shows_message_when_disconnected(void **state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void cmd_roster_shows_message_when_undefined(void **state)
{
test_with_connection_status(JABBER_UNDEFINED);
}
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);
roster_init();
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
GSList *roster = roster_get_contacts();
cons_show_roster_expect(roster);
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
roster_free();
}
void cmd_roster_add_shows_message_when_no_jid(void)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "add", NULL };
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Usage: some usage");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}
void cmd_roster_add_sends_roster_add_request(void)
{
char *jid = "bob@server.org";
char *nick = "bob";
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);
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}

7
tests/test_cmd_roster.h Normal file
View File

@ -0,0 +1,7 @@
void cmd_roster_shows_message_when_disconnecting(void **state);
void cmd_roster_shows_message_when_connecting(void **state);
void cmd_roster_shows_message_when_disconnected(void **state);
void cmd_roster_shows_message_when_undefined(void **state);
void cmd_roster_shows_roster_when_no_args(void **state);
void cmd_roster_add_shows_message_when_no_jid(void **state);
void cmd_roster_add_sends_roster_add_request(void **state);

View File

@ -29,6 +29,7 @@
#include "test_cmd_bookmark.h"
#include "test_cmd_join.h"
#include "test_muc.h"
#include "test_cmd_roster.h"
int main(int argc, char* argv[]) {
const UnitTest all_tests[] = {
@ -500,6 +501,14 @@ 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),
unit_test(cmd_roster_shows_message_when_undefined),
unit_test(cmd_roster_shows_roster_when_no_args),
unit_test(cmd_roster_add_shows_message_when_no_jid),
unit_test(cmd_roster_add_sends_roster_add_request),
};
return run_tests(all_tests);

View File

@ -171,6 +171,12 @@ void _mock_ui_room_join(char *room)
check_expected(room);
}
static
void _mock_cons_show_roster(GSList *list)
{
check_expected(list);
}
// bind mocks and stubs
void
@ -276,6 +282,12 @@ mock_ui_current_print_line(void)
ui_current_print_line = _mock_ui_current_print_line;
}
void
mock_cons_show_roster(void)
{
cons_show_roster = _mock_cons_show_roster;
}
// expectations
void
@ -420,3 +432,9 @@ ui_room_join_expect(char *room)
ui_room_join = _mock_ui_room_join;
expect_string(_mock_ui_room_join, room, room);
}
void
cons_show_roster_expect(GSList *list)
{
expect_any(_mock_cons_show_roster, list);
}

View File

@ -61,4 +61,7 @@ void ui_current_win_is_otr_returns(gboolean result);
void ui_room_join_expect(char *room);
void mock_cons_show_roster(void);
void cons_show_roster_expect(GSList *list);
#endif

View File

@ -96,6 +96,13 @@ _mock_presence_join_room(char *room, char*nick, char *passwd)
check_expected(passwd);
}
static void
_mock_roster_send_add_new(const char *const barejid, const char * const name)
{
check_expected(barejid);
check_expected(name);
}
void
mock_jabber_connect_with_details(void)
{
@ -139,6 +146,12 @@ mock_presence_join_room(void)
presence_join_room = _mock_presence_join_room;
}
void
mock_roster_send_add_new(void)
{
roster_send_add_new = _mock_roster_send_add_new;
}
void
bookmark_get_list_returns(GList *bookmarks)
{
@ -260,3 +273,10 @@ presence_join_room_expect(char *room, char *nick, char *passwd)
expect_string(_mock_presence_join_room, passwd, passwd);
}
}
void
roster_send_add_new_expect(char *jid, char *nick)
{
expect_string(_mock_roster_send_add_new, barejid, jid);
expect_string(_mock_roster_send_add_new, name, nick);
}

View File

@ -36,4 +36,7 @@ void message_send_expect(char *message, char *recipient);
void mock_presence_join_room(void);
void presence_join_room_expect(char *room, char *nick, char *passwd);
void mock_roster_send_add_new(void);
void roster_send_add_new_expect(char *jid, char *nick);
#endif