Sun, 10 Aug 2025 23:44:08 +0800
Add Purple.Conversation.find_message_by_id
The method was added so that a protocol or plugin could easily lookup
for the reference for a message. This will be especially useful when a
protocol received a quoted message but only with an id.
| 43076 | 1 | /* |
| 2 | * Purple - Internet Messaging Library | |
| 3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | #include <glib.h> | |
| 20 | ||
| 21 | #include <purple.h> | |
| 22 | ||
| 23 | /****************************************************************************** | |
| 24 | * Tests | |
| 25 | *****************************************************************************/ | |
| 26 | static void | |
| 27 | test_purple_badge_manager_new(void) { | |
| 28 | PurpleBadgeManager *manager = NULL; | |
| 29 | ||
| 30 | manager = purple_badge_manager_new(); | |
| 31 | ||
| 32 | g_assert_true(PURPLE_IS_BADGE_MANAGER(manager)); | |
| 33 | ||
| 34 | g_assert_finalize_object(manager); | |
| 35 | } | |
| 36 | ||
| 37 | static void | |
| 38 | test_purple_badge_manager_add_remove(void) { | |
| 39 | PurpleBadge *badge = NULL; | |
| 40 | PurpleBadge *found = NULL; | |
| 41 | PurpleBadgeManager *manager = NULL; | |
| 42 | gboolean ret = FALSE; | |
| 43 | const char *id = "test-badge"; | |
| 44 | ||
| 45 | manager = purple_badge_manager_new(); | |
| 46 | ||
| 47 | /* Make sure we can't remove our badge as it hasn't been added yet. */ | |
| 48 | ret = purple_badge_manager_remove(manager, id); | |
| 49 | g_assert_false(ret); | |
| 50 | ||
| 51 | /* Also make sure we can't find our badge. */ | |
| 52 | badge = purple_badge_manager_find(manager, id); | |
| 53 | g_assert_null(badge); | |
| 54 | ||
| 55 | /* Create and add our badge. */ | |
| 56 | badge = purple_badge_new(id, 0, "test-badge", "T"); | |
| 57 | ret = purple_badge_manager_add(manager, badge); | |
| 58 | g_assert_true(ret); | |
| 59 | ||
| 60 | /* Make sure it was added. */ | |
| 61 | found = purple_badge_manager_find(manager, id); | |
| 62 | g_assert_true(PURPLE_IS_BADGE(found)); | |
| 63 | g_assert_true(found == badge); | |
| 64 | ||
| 65 | /* Add the badge again and verify that it returns false. */ | |
| 66 | ret = purple_badge_manager_add(manager, badge); | |
| 67 | g_assert_false(ret); | |
| 68 | ||
| 69 | /* Remove the badge. */ | |
| 70 | ret = purple_badge_manager_remove(manager, id); | |
| 71 | g_assert_true(ret); | |
| 72 | ||
| 73 | /* Make sure it's gone. */ | |
| 74 | found = purple_badge_manager_find(manager, id); | |
| 75 | g_assert_null(found); | |
| 76 | ||
| 77 | /* Make sure that another remove returns false. */ | |
| 78 | ret = purple_badge_manager_remove(manager, id); | |
| 79 | g_assert_false(ret); | |
| 80 | ||
| 81 | g_assert_finalize_object(manager); | |
| 82 | g_assert_finalize_object(badge); | |
| 83 | } | |
| 84 | ||
| 85 | /****************************************************************************** | |
| 86 | * Main | |
| 87 | *****************************************************************************/ | |
| 88 | int | |
| 89 | main(int argc, char *argv[]) { | |
| 90 | g_test_init(&argc, &argv, NULL); | |
| 91 | g_test_set_nonfatal_assertions(); | |
| 92 | ||
| 93 | g_test_add_func("/conversation-manager/new", | |
| 94 | test_purple_badge_manager_new); | |
| 95 | g_test_add_func("/conversation-manager/add-remove", | |
| 96 | test_purple_badge_manager_add_remove); | |
| 97 | ||
| 98 | return g_test_run(); | |
| 99 | } |