diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 4981b690..974ed570 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -133,7 +133,7 @@ autocomplete_get_list(Autocomplete ac) } gboolean -autocomplete_contains(Autocomplete ac, char *value) +autocomplete_contains(Autocomplete ac, const char *value) { GSList *curr = ac->items; diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index fadd6e88..57c6015a 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -57,5 +57,5 @@ char * autocomplete_param_no_with_func(char *input, int *size, char *command, void autocomplete_reset(Autocomplete ac); -gboolean autocomplete_contains(Autocomplete ac, char *value); +gboolean autocomplete_contains(Autocomplete ac, const char *value); #endif diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 0ed58ecb..e31a5795 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -61,6 +61,10 @@ bookmark_request(void) static gboolean _bookmark_add(const char *jid, const char *nick, gboolean autojoin) { + gboolean added = TRUE; + if (autocomplete_contains(bookmark_ac, jid)) { + added = FALSE; + } /* TODO: send request */ /* TODO: manage bookmark_list */ @@ -68,12 +72,16 @@ _bookmark_add(const char *jid, const char *nick, gboolean autojoin) autocomplete_remove(bookmark_ac, jid); autocomplete_add(bookmark_ac, jid); - return FALSE; + return added; } static gboolean _bookmark_remove(const char *jid, gboolean autojoin) { + gboolean removed = FALSE; + if (autocomplete_contains(bookmark_ac, jid)) { + removed = TRUE; + } /* TODO: manage bookmark_list */ if (autojoin) { /* TODO: just set autojoin=0 */ @@ -82,7 +90,7 @@ _bookmark_remove(const char *jid, gboolean autojoin) autocomplete_remove(bookmark_ac, jid); } - return FALSE; + return removed; } static const GList * diff --git a/tests/test_cmd_bookmark.c b/tests/test_cmd_bookmark.c index 32a19e82..4dc12217 100644 --- a/tests/test_cmd_bookmark.c +++ b/tests/test_cmd_bookmark.c @@ -366,3 +366,22 @@ void cmd_bookmark_remove_shows_message_when_no_bookmark(void **state) free(help); } + +void cmd_bookmark_remove_autojoin_shows_message_when_no_bookmark(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_and_return_bookmark_remove(jid, TRUE, FALSE); + expect_cons_show("No bookmark exists for room@conf.server."); + + gboolean result = cmd_bookmark(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_bookmark.h b/tests/test_cmd_bookmark.h index ca17b62e..ef8729ca 100644 --- a/tests/test_cmd_bookmark.h +++ b/tests/test_cmd_bookmark.h @@ -17,3 +17,4 @@ void cmd_bookmark_remove_removes_bookmark(void **state); void cmd_bookmark_remove_removes_autojoin(void **state); void cmd_bookmark_add_shows_message_when_upated(void **state); void cmd_bookmark_remove_shows_message_when_no_bookmark(void **state); +void cmd_bookmark_remove_autojoin_shows_message_when_no_bookmark(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 47c90a07..a3be51cc 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -458,6 +458,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_bookmark_remove_removes_autojoin), unit_test(cmd_bookmark_add_shows_message_when_upated), unit_test(cmd_bookmark_remove_shows_message_when_no_bookmark), + unit_test(cmd_bookmark_remove_autojoin_shows_message_when_no_bookmark), };