mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
parent
f4759cf337
commit
7c5ece24c5
@ -4500,11 +4500,17 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int num_args = g_strv_length(args);
|
||||
gchar *cmd = args[0];
|
||||
if (window->type == WIN_MUC && (cmd == NULL || g_strcmp0(cmd, "add") == 0)) {
|
||||
if (window->type == WIN_MUC
|
||||
&& num_args < 2
|
||||
&& (cmd == NULL || g_strcmp0(cmd, "add") == 0)) {
|
||||
// default to current nickname, password, and autojoin "on"
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
@ -4519,7 +4525,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (window->type == WIN_MUC && g_strcmp0(cmd, "remove") == 0) {
|
||||
if (window->type == WIN_MUC
|
||||
&& num_args < 2
|
||||
&& g_strcmp0(cmd, "remove") == 0) {
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
gboolean removed = bookmark_remove(mucwin->roomjid);
|
||||
@ -4533,6 +4541,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
|
||||
if (cmd == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4547,6 +4558,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
}
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4561,11 +4575,17 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
if (jid == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if (strchr(jid, '@') == NULL) {
|
||||
cons_show("Invalid room, must be of the form room@domain.tld");
|
||||
cons_show("");
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4576,6 +4596,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
} else {
|
||||
cons_show("No bookmark exists for %s.", jid);
|
||||
}
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4584,6 +4607,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
if (!joined) {
|
||||
cons_show("No bookmark exists for %s.", jid);
|
||||
}
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4594,6 +4620,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
if (!parsed) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4603,6 +4632,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
options_destroy(options);
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4617,6 +4649,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_show("Bookmark already exists, use /bookmark update to edit.");
|
||||
}
|
||||
options_destroy(options);
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4628,11 +4663,17 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_show("No bookmark exists for %s.", jid);
|
||||
}
|
||||
options_destroy(options);
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
cons_bad_cmd_usage(command);
|
||||
options_destroy(options);
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
cons_alert();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
static void test_with_connection_status(jabber_conn_status_t status)
|
||||
{
|
||||
ProfWin window;
|
||||
window.type = WIN_CONSOLE;
|
||||
will_return(connection_get_status, status);
|
||||
expect_cons_show("You are not currently connected.");
|
||||
|
||||
gboolean result = cmd_bookmark(NULL, CMD_BOOKMARK, NULL);
|
||||
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, NULL);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -165,6 +167,85 @@ void cmd_bookmark_add_adds_bookmark_with_jid(void **state)
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
void cmd_bookmark_uses_roomjid_in_room(void **state)
|
||||
{
|
||||
muc_init();
|
||||
|
||||
gchar *args[] = { NULL };
|
||||
ProfMucWin muc_win;
|
||||
muc_win.window.type = WIN_MUC;
|
||||
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
|
||||
muc_win.roomjid = "room@conf.server";
|
||||
|
||||
will_return(connection_get_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(bookmark_add, jid, muc_win.roomjid);
|
||||
expect_any(bookmark_add, nick);
|
||||
expect_any(bookmark_add, password);
|
||||
expect_any(bookmark_add, autojoin_str);
|
||||
will_return(bookmark_add, TRUE);
|
||||
|
||||
expect_win_println("Bookmark added for room@conf.server.");
|
||||
|
||||
gboolean result = cmd_bookmark(&muc_win, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
|
||||
muc_close();
|
||||
}
|
||||
|
||||
void cmd_bookmark_add_uses_roomjid_in_room(void **state)
|
||||
{
|
||||
muc_init();
|
||||
|
||||
gchar *args[] = { "add", NULL };
|
||||
ProfMucWin muc_win;
|
||||
muc_win.window.type = WIN_MUC;
|
||||
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
|
||||
muc_win.roomjid = "room@conf.server";
|
||||
|
||||
will_return(connection_get_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(bookmark_add, jid, muc_win.roomjid);
|
||||
expect_any(bookmark_add, nick);
|
||||
expect_any(bookmark_add, password);
|
||||
expect_any(bookmark_add, autojoin_str);
|
||||
will_return(bookmark_add, TRUE);
|
||||
|
||||
expect_win_println("Bookmark added for room@conf.server.");
|
||||
|
||||
gboolean result = cmd_bookmark(&muc_win, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
|
||||
muc_close();
|
||||
}
|
||||
|
||||
void cmd_bookmark_add_uses_supplied_jid_in_room(void **state)
|
||||
{
|
||||
muc_init();
|
||||
|
||||
char *jid = "room1@conf.server";
|
||||
gchar *args[] = { "add", jid, NULL };
|
||||
ProfMucWin muc_win;
|
||||
muc_win.window.type = WIN_MUC;
|
||||
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
|
||||
muc_win.roomjid = "room2@conf.server";
|
||||
|
||||
will_return(connection_get_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(bookmark_add, jid, jid);
|
||||
expect_any(bookmark_add, nick);
|
||||
expect_any(bookmark_add, password);
|
||||
expect_any(bookmark_add, autojoin_str);
|
||||
will_return(bookmark_add, TRUE);
|
||||
|
||||
expect_cons_show("Bookmark added for room1@conf.server.");
|
||||
|
||||
gboolean result = cmd_bookmark(&muc_win, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
|
||||
muc_close();
|
||||
}
|
||||
|
||||
void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state)
|
||||
{
|
||||
char *jid = "room@conf.server";
|
||||
@ -265,3 +346,50 @@ void cmd_bookmark_remove_shows_message_when_no_bookmark(void **state)
|
||||
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
void cmd_bookmark_remove_uses_roomjid_in_room(void **state)
|
||||
{
|
||||
muc_init();
|
||||
|
||||
gchar *args[] = { "remove", NULL };
|
||||
ProfMucWin muc_win;
|
||||
muc_win.window.type = WIN_MUC;
|
||||
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
|
||||
muc_win.roomjid = "room@conf.server";
|
||||
|
||||
will_return(connection_get_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(bookmark_remove, jid, muc_win.roomjid);
|
||||
will_return(bookmark_remove, TRUE);
|
||||
|
||||
expect_win_println("Bookmark removed for room@conf.server.");
|
||||
|
||||
gboolean result = cmd_bookmark(&muc_win, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
|
||||
muc_close();
|
||||
}
|
||||
|
||||
void cmd_bookmark_remove_uses_supplied_jid_in_room(void **state)
|
||||
{
|
||||
muc_init();
|
||||
|
||||
char *jid = "room1@conf.server";
|
||||
gchar *args[] = { "remove", jid, NULL };
|
||||
ProfMucWin muc_win;
|
||||
muc_win.window.type = WIN_MUC;
|
||||
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
|
||||
muc_win.roomjid = "room2@conf.server";
|
||||
|
||||
will_return(connection_get_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(bookmark_remove, jid, jid);
|
||||
will_return(bookmark_remove, TRUE);
|
||||
|
||||
expect_cons_show("Bookmark removed for room1@conf.server.");
|
||||
|
||||
gboolean result = cmd_bookmark(&muc_win, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
|
||||
muc_close();
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ void cmd_bookmark_shows_usage_when_no_args(void **state);
|
||||
void cmd_bookmark_list_shows_bookmarks(void **state);
|
||||
void cmd_bookmark_add_shows_message_when_invalid_jid(void **state);
|
||||
void cmd_bookmark_add_adds_bookmark_with_jid(void **state);
|
||||
void cmd_bookmark_uses_roomjid_in_room(void **state);
|
||||
void cmd_bookmark_add_uses_roomjid_in_room(void **state);
|
||||
void cmd_bookmark_add_uses_supplied_jid_in_room(void **state);
|
||||
void cmd_bookmark_remove_uses_roomjid_in_room(void **state);
|
||||
void cmd_bookmark_remove_uses_supplied_jid_in_room(void **state);
|
||||
void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state);
|
||||
void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void **state);
|
||||
void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void **state);
|
||||
|
@ -493,6 +493,11 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_bookmark_list_shows_bookmarks),
|
||||
unit_test(cmd_bookmark_add_shows_message_when_invalid_jid),
|
||||
unit_test(cmd_bookmark_add_adds_bookmark_with_jid),
|
||||
unit_test(cmd_bookmark_uses_roomjid_in_room),
|
||||
unit_test(cmd_bookmark_add_uses_roomjid_in_room),
|
||||
unit_test(cmd_bookmark_add_uses_supplied_jid_in_room),
|
||||
unit_test(cmd_bookmark_remove_uses_roomjid_in_room),
|
||||
unit_test(cmd_bookmark_remove_uses_supplied_jid_in_room),
|
||||
unit_test(cmd_bookmark_add_adds_bookmark_with_jid_nick),
|
||||
unit_test(cmd_bookmark_add_adds_bookmark_with_jid_autojoin),
|
||||
unit_test(cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin),
|
||||
|
Loading…
Reference in New Issue
Block a user