1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Added /bookmark remove tests

This commit is contained in:
James Booth 2014-02-02 00:37:37 +00:00
parent 38d8d8d984
commit a8ecbccc9c
6 changed files with 70 additions and 0 deletions

View File

@ -1778,6 +1778,11 @@ cmd_bookmark(gchar **args, struct cmd_help_t help)
g_string_free(msg, TRUE);
} else if (strcmp(cmd, "remove") == 0) {
bookmark_remove(jid, autojoin);
if (autojoin) {
cons_show("Autojoin disabled for %s.", jid);
} else {
cons_show("Bookmark removed for %s.", jid);
}
} else {
cons_show("Usage: %s", help.usage);
}

View File

@ -290,3 +290,41 @@ void cmd_bookmark_add_adds_bookmark_with_room_details_autojoin(void **state)
free(help);
muc_close();
}
void cmd_bookmark_remove_removes_bookmark(void **state)
{
mock_bookmark_remove();
mock_cons_show();
char *jid = "room@conf.server";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "remove", jid, NULL };
mock_connection_status(JABBER_CONNECTED);
expect_bookmark_remove(jid, FALSE);
expect_cons_show("Bookmark removed for room@conf.server.");
gboolean result = cmd_bookmark(args, *help);
assert_true(result);
free(help);
}
void cmd_bookmark_remove_removes_autojoin(void **state)
{
mock_bookmark_remove();
mock_cons_show();
char *jid = "room@conf.server";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "remove", jid, "autojoin", NULL };
mock_connection_status(JABBER_CONNECTED);
expect_bookmark_remove(jid, TRUE);
expect_cons_show("Autojoin disabled for room@conf.server.");
gboolean result = cmd_bookmark(args, *help);
assert_true(result);
free(help);
}

View File

@ -13,3 +13,5 @@ void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(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);
void cmd_bookmark_remove_removes_bookmark(void **state);
void cmd_bookmark_remove_removes_autojoin(void **state);

View File

@ -454,6 +454,8 @@ int main(int argc, char* argv[]) {
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),
unit_test(cmd_bookmark_remove_removes_bookmark),
unit_test(cmd_bookmark_remove_removes_autojoin),
};

View File

@ -72,6 +72,13 @@ _mock_bookmark_add(const char *jid, const char *nick, gboolean autojoin)
check_expected(autojoin);
}
static void
_mock_bookmark_remove(const char *jid, gboolean autojoin)
{
check_expected(jid);
check_expected(autojoin);
}
void
mock_jabber_connect_with_details(void)
{
@ -103,6 +110,12 @@ mock_bookmark_add(void)
bookmark_add = _mock_bookmark_add;
}
void
mock_bookmark_remove(void)
{
bookmark_remove = _mock_bookmark_remove;
}
void
bookmark_get_list_returns(GList *bookmarks)
{
@ -191,3 +204,10 @@ expect_bookmark_add(char *expected_jid, char *expected_nick, gboolean expected_a
}
expect_value(_mock_bookmark_add, autojoin, expected_autojoin);
}
void
expect_bookmark_remove(char *expected_jid, gboolean expected_autojoin)
{
expect_string(_mock_bookmark_remove, jid, expected_jid);
expect_value(_mock_bookmark_remove, autojoin, expected_autojoin);
}

View File

@ -26,4 +26,7 @@ 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);
void mock_bookmark_remove(void);
void expect_bookmark_remove(char *expected_jid, gboolean expected_autojoin);
#endif