mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added cmd_bookmark tests
This commit is contained in:
parent
7d4b6d6f4f
commit
af51fa3c68
@ -1725,7 +1725,7 @@ cmd_bookmark(gchar **args, struct cmd_help_t help)
|
|||||||
|
|
||||||
/* TODO: /bookmark list room@server */
|
/* TODO: /bookmark list room@server */
|
||||||
|
|
||||||
if (cmd == NULL || strcmp(cmd, "list") == 0) {
|
if (strcmp(cmd, "list") == 0) {
|
||||||
const GList *bookmarks = bookmark_get_list();
|
const GList *bookmarks = bookmark_get_list();
|
||||||
cons_show_bookmarks(bookmarks);
|
cons_show_bookmarks(bookmarks);
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,9 +7,12 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "ui/mock_ui.h"
|
#include "ui/mock_ui.h"
|
||||||
|
#include "ui/window.h"
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
#include "xmpp/mock_xmpp.h"
|
#include "xmpp/mock_xmpp.h"
|
||||||
|
|
||||||
|
#include "muc.h"
|
||||||
|
|
||||||
#include "command/commands.h"
|
#include "command/commands.h"
|
||||||
|
|
||||||
#include "xmpp/bookmark.h"
|
#include "xmpp/bookmark.h"
|
||||||
@ -121,3 +124,140 @@ void cmd_bookmark_list_shows_bookmarks(void **state)
|
|||||||
free(help);
|
free(help);
|
||||||
g_list_free_full(bookmarks, (GDestroyNotify)_free_bookmark);
|
g_list_free_full(bookmarks, (GDestroyNotify)_free_bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_add_shows_usage_when_no_args_not_muc(void **state)
|
||||||
|
{
|
||||||
|
mock_cons_show();
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
help->usage = "some usage";
|
||||||
|
gchar *args[] = { "add", NULL };
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
|
expect_cons_show("Usage: some usage");
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_remove_shows_message_when_no_args_not_muc(void **state)
|
||||||
|
{
|
||||||
|
mock_cons_show();
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
help->usage = "some usage";
|
||||||
|
gchar *args[] = { "remove", NULL };
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
|
expect_cons_show("Usage: some usage");
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_jid(void **state)
|
||||||
|
{
|
||||||
|
mock_bookmark_add();
|
||||||
|
char *jid = "room@conf.server";
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "add", jid, NULL };
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
|
||||||
|
expect_bookmark_add(jid, NULL, FALSE);
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state)
|
||||||
|
{
|
||||||
|
mock_bookmark_add();
|
||||||
|
char *jid = "room@conf.server";
|
||||||
|
char *nick = "bob";
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "add", jid, nick, NULL };
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
|
||||||
|
expect_bookmark_add(jid, nick, FALSE);
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void **state)
|
||||||
|
{
|
||||||
|
mock_bookmark_add();
|
||||||
|
char *jid = "room@conf.server";
|
||||||
|
char *nick = "bob";
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "add", jid, nick, "autojoin", NULL };
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
|
||||||
|
expect_bookmark_add(jid, nick, TRUE);
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_room_details(void **state)
|
||||||
|
{
|
||||||
|
mock_bookmark_add();
|
||||||
|
mock_ui_current_recipient();
|
||||||
|
char *jid = "room@conf.server";
|
||||||
|
char *nick = "bob";
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "add", NULL };
|
||||||
|
|
||||||
|
muc_init();
|
||||||
|
muc_join_room(jid, nick);
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
mock_current_win_type(WIN_MUC);
|
||||||
|
ui_current_recipient_returns(jid);
|
||||||
|
|
||||||
|
expect_bookmark_add(jid, nick, FALSE);
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
muc_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_room_details_autojoin(void **state)
|
||||||
|
{
|
||||||
|
mock_bookmark_add();
|
||||||
|
mock_ui_current_recipient();
|
||||||
|
char *jid = "room@conf.server";
|
||||||
|
char *nick = "bob";
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "add", "autojoin", NULL };
|
||||||
|
|
||||||
|
muc_init();
|
||||||
|
muc_join_room(jid, nick);
|
||||||
|
|
||||||
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
mock_current_win_type(WIN_MUC);
|
||||||
|
ui_current_recipient_returns(jid);
|
||||||
|
|
||||||
|
expect_bookmark_add(jid, nick, TRUE);
|
||||||
|
|
||||||
|
gboolean result = cmd_bookmark(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
muc_close();
|
||||||
|
}
|
||||||
|
@ -5,3 +5,10 @@ void cmd_bookmark_shows_message_when_started(void **state);
|
|||||||
void cmd_bookmark_shows_message_when_undefined(void **state);
|
void cmd_bookmark_shows_message_when_undefined(void **state);
|
||||||
void cmd_bookmark_shows_usage_when_no_args(void **state);
|
void cmd_bookmark_shows_usage_when_no_args(void **state);
|
||||||
void cmd_bookmark_list_shows_bookmarks(void **state);
|
void cmd_bookmark_list_shows_bookmarks(void **state);
|
||||||
|
void cmd_bookmark_add_shows_usage_when_no_args_not_muc(void **state);
|
||||||
|
void cmd_bookmark_remove_shows_message_when_no_args_not_muc(void **state);
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_jid(void **state);
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state);
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void **state);
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_room_details(void **state);
|
||||||
|
void cmd_bookmark_add_adds_bookmark_with_room_details_autojoin(void **state);
|
||||||
|
@ -446,6 +446,13 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test(cmd_bookmark_shows_message_when_undefined),
|
unit_test(cmd_bookmark_shows_message_when_undefined),
|
||||||
unit_test(cmd_bookmark_shows_usage_when_no_args),
|
unit_test(cmd_bookmark_shows_usage_when_no_args),
|
||||||
unit_test(cmd_bookmark_list_shows_bookmarks),
|
unit_test(cmd_bookmark_list_shows_bookmarks),
|
||||||
|
unit_test(cmd_bookmark_add_shows_usage_when_no_args_not_muc),
|
||||||
|
unit_test(cmd_bookmark_remove_shows_message_when_no_args_not_muc),
|
||||||
|
unit_test(cmd_bookmark_add_adds_bookmark_with_jid),
|
||||||
|
unit_test(cmd_bookmark_add_adds_bookmark_with_jid_nick),
|
||||||
|
unit_test(cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin),
|
||||||
|
unit_test(cmd_bookmark_add_adds_bookmark_with_room_details),
|
||||||
|
unit_test(cmd_bookmark_add_adds_bookmark_with_room_details_autojoin),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
#include "ui/window.h"
|
||||||
#include "tests/helpers.h"
|
#include "tests/helpers.h"
|
||||||
|
|
||||||
#include "xmpp/bookmark.h"
|
#include "xmpp/bookmark.h"
|
||||||
@ -103,6 +104,18 @@ char * _stub_ui_ask_password(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
win_type_t _mock_ui_current_win_type(void)
|
||||||
|
{
|
||||||
|
return (win_type_t)mock();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
char * _mock_ui_current_recipeint(void)
|
||||||
|
{
|
||||||
|
return (char *)mock();
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void _mock_ui_handle_error(const char * const err_msg)
|
void _mock_ui_handle_error(const char * const err_msg)
|
||||||
{
|
{
|
||||||
@ -198,6 +211,12 @@ mock_ui_ask_password(void)
|
|||||||
ui_ask_password = _mock_ui_ask_password;
|
ui_ask_password = _mock_ui_ask_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mock_ui_current_recipient(void)
|
||||||
|
{
|
||||||
|
ui_current_recipient = _mock_ui_current_recipeint;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stub_ui_ask_password(void)
|
stub_ui_ask_password(void)
|
||||||
{
|
{
|
||||||
@ -325,3 +344,16 @@ expect_ui_handle_recipient_not_found(char *recipient, char *err_msg)
|
|||||||
expect_string(_mock_ui_handle_recipient_not_found, recipient, recipient);
|
expect_string(_mock_ui_handle_recipient_not_found, recipient, recipient);
|
||||||
expect_string(_mock_ui_handle_recipient_not_found, err_msg, err_msg);
|
expect_string(_mock_ui_handle_recipient_not_found, err_msg, err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mock_current_win_type(win_type_t type)
|
||||||
|
{
|
||||||
|
ui_current_win_type = _mock_ui_current_win_type;
|
||||||
|
will_return(_mock_ui_current_win_type, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ui_current_recipient_returns(char *jid)
|
||||||
|
{
|
||||||
|
will_return(_mock_ui_current_recipeint, jid);
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "config/account.h"
|
#include "config/account.h"
|
||||||
#include "contact.h"
|
#include "contact.h"
|
||||||
|
#include "ui/window.h"
|
||||||
|
|
||||||
void stub_cons_show(void);
|
void stub_cons_show(void);
|
||||||
|
|
||||||
@ -43,4 +44,9 @@ void stub_ui_ask_password(void);
|
|||||||
void mock_ui_ask_password(void);
|
void mock_ui_ask_password(void);
|
||||||
void mock_ui_ask_password_returns(char *password);
|
void mock_ui_ask_password_returns(char *password);
|
||||||
|
|
||||||
|
void mock_current_win_type(win_type_t type);
|
||||||
|
|
||||||
|
void mock_ui_current_recipient(void);
|
||||||
|
void ui_current_recipient_returns(char *jid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,6 +64,14 @@ _mock_bookmark_get_list(void)
|
|||||||
return (GList *)mock();
|
return (GList *)mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_mock_bookmark_add(const char *jid, const char *nick, gboolean autojoin)
|
||||||
|
{
|
||||||
|
check_expected(jid);
|
||||||
|
check_expected(nick);
|
||||||
|
check_expected(autojoin);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mock_jabber_connect_with_details(void)
|
mock_jabber_connect_with_details(void)
|
||||||
{
|
{
|
||||||
@ -89,6 +97,12 @@ mock_connection_status(jabber_conn_status_t status)
|
|||||||
will_return(_mock_jabber_get_connection_status, status);
|
will_return(_mock_jabber_get_connection_status, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mock_bookmark_add(void)
|
||||||
|
{
|
||||||
|
bookmark_add = _mock_bookmark_add;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bookmark_get_list_returns(GList *bookmarks)
|
bookmark_get_list_returns(GList *bookmarks)
|
||||||
{
|
{
|
||||||
@ -165,3 +179,15 @@ presence_update_expect(resource_presence_t presence, char *msg, int idle)
|
|||||||
expect_string(_mock_presence_update, msg, msg);
|
expect_string(_mock_presence_update, msg, msg);
|
||||||
expect_value(_mock_presence_update, idle, idle);
|
expect_value(_mock_presence_update, idle, idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
expect_bookmark_add(char *expected_jid, char *expected_nick, gboolean expected_autojoin)
|
||||||
|
{
|
||||||
|
expect_string(_mock_bookmark_add, jid, expected_jid);
|
||||||
|
if (expected_nick != NULL) {
|
||||||
|
expect_string(_mock_bookmark_add, nick, expected_nick);
|
||||||
|
} else {
|
||||||
|
expect_any(_mock_bookmark_add, nick);
|
||||||
|
}
|
||||||
|
expect_value(_mock_bookmark_add, autojoin, expected_autojoin);
|
||||||
|
}
|
||||||
|
@ -23,4 +23,7 @@ void presence_update_expect(resource_presence_t presence, char *msg, int idle);
|
|||||||
|
|
||||||
void bookmark_get_list_returns(GList *bookmarks);
|
void bookmark_get_list_returns(GList *bookmarks);
|
||||||
|
|
||||||
|
void mock_bookmark_add(void);
|
||||||
|
void expect_bookmark_add(char *expected_jid, char *expected_nick, gboolean expected_autojoin);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user