--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/tests/test_badge_manager.c Thu Nov 21 23:39:13 2024 -0600 @@ -0,0 +1,99 @@ +/* + * Purple - Internet Messaging Library + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <https://www.gnu.org/licenses/>. + */ + +#include <glib.h> + +#include <purple.h> + +/****************************************************************************** + * Tests + *****************************************************************************/ +static void +test_purple_badge_manager_new(void) { + PurpleBadgeManager *manager = NULL; + + manager = purple_badge_manager_new(); + + g_assert_true(PURPLE_IS_BADGE_MANAGER(manager)); + + g_assert_finalize_object(manager); +} + +static void +test_purple_badge_manager_add_remove(void) { + PurpleBadge *badge = NULL; + PurpleBadge *found = NULL; + PurpleBadgeManager *manager = NULL; + gboolean ret = FALSE; + const char *id = "test-badge"; + + manager = purple_badge_manager_new(); + + /* Make sure we can't remove our badge as it hasn't been added yet. */ + ret = purple_badge_manager_remove(manager, id); + g_assert_false(ret); + + /* Also make sure we can't find our badge. */ + badge = purple_badge_manager_find(manager, id); + g_assert_null(badge); + + /* Create and add our badge. */ + badge = purple_badge_new(id, 0, "test-badge", "T"); + ret = purple_badge_manager_add(manager, badge); + g_assert_true(ret); + + /* Make sure it was added. */ + found = purple_badge_manager_find(manager, id); + g_assert_true(PURPLE_IS_BADGE(found)); + g_assert_true(found == badge); + + /* Add the badge again and verify that it returns false. */ + ret = purple_badge_manager_add(manager, badge); + g_assert_false(ret); + + /* Remove the badge. */ + ret = purple_badge_manager_remove(manager, id); + g_assert_true(ret); + + /* Make sure it's gone. */ + found = purple_badge_manager_find(manager, id); + g_assert_null(found); + + /* Make sure that another remove returns false. */ + ret = purple_badge_manager_remove(manager, id); + g_assert_false(ret); + + g_assert_finalize_object(manager); + g_assert_finalize_object(badge); +} + +/****************************************************************************** + * Main + *****************************************************************************/ +int +main(int argc, char *argv[]) { + g_test_init(&argc, &argv, NULL); + g_test_set_nonfatal_assertions(); + + g_test_add_func("/conversation-manager/new", + test_purple_badge_manager_new); + g_test_add_func("/conversation-manager/add-remove", + test_purple_badge_manager_add_remove); + + return g_test_run(); +}