--- a/libpurple/tests/test_contact_manager.c Fri Feb 21 00:03:24 2025 -0600 +++ b/libpurple/tests/test_contact_manager.c Wed Feb 26 00:35:17 2025 -0600 @@ -247,6 +247,39 @@ g_clear_object(&manager); } +static void +test_purple_contact_manager_find_or_create(void) { + PurpleAccount *account = NULL; + PurpleContact *contact1 = NULL; + PurpleContact *contact2 = NULL; + gboolean found; + PurpleContactManager *manager = NULL; + + manager = g_object_new(PURPLE_TYPE_CONTACT_MANAGER, NULL); + + account = purple_account_new("test", "test"); + + found = TRUE; + contact1 = purple_contact_manager_find_or_create(manager, account, "id-1", + &found); + g_assert_true(PURPLE_IS_CONTACT(contact1)); + g_assert_false(found); + contact2 = purple_contact_manager_find_or_create(manager, account, "id-1", + &found); + g_assert_true(found); + g_assert_true(contact1 == contact2); + + /* Cleanup. */ + g_object_unref(contact2); + /* Calling ContactManager.remove so g_assert_finalize doesn't complain about + * weak references. + */ + purple_contact_manager_remove(manager, contact1); + g_assert_finalize_object(contact1); + g_assert_finalize_object(manager); + g_assert_finalize_object(account); +} + /****************************************************************************** * Person Tests *****************************************************************************/ @@ -443,6 +476,8 @@ test_purple_contact_manager_find_with_username); g_test_add_func("/contact-manager/find/with-id", test_purple_contact_manager_find_with_id); + g_test_add_func("/contact-manager/find-or-create", + test_purple_contact_manager_find_or_create); g_test_add_func("/contact-manager/person/add-remove", test_purple_contact_manager_person_add_remove);