--- a/libpurple/tests/test_protocol_contacts.c Thu Jul 31 16:54:02 2025 -0500 +++ b/libpurple/tests/test_protocol_contacts.c Thu Jul 31 16:55:45 2025 -0500 @@ -65,59 +65,6 @@ * TestProtocolContactsEmpty Tests *****************************************************************************/ static void -test_purple_protocol_contacts_empty_get_minimum_search_length(void) { - PurpleProtocolContacts *protocol = NULL; - guint minimum_search_length = 0; - - protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), - NULL); - minimum_search_length = purple_protocol_contacts_get_minimum_search_length(protocol); - - /* There is a default implementation that returns 3. */ - g_assert_cmpuint(minimum_search_length, ==, 3); - - g_assert_finalize_object(protocol); -} - -static void -test_purple_protocol_contacts_empty_search_cb(GObject *source, - GAsyncResult *result, - G_GNUC_UNUSED gpointer data) -{ - PurpleProtocolContacts *protocol = NULL; - GError *error = NULL; - GListModel *model = NULL; - - g_assert_true(PURPLE_IS_PROTOCOL_CONTACTS(source)); - - protocol = PURPLE_PROTOCOL_CONTACTS(source); - - model = purple_protocol_contacts_search_finish(protocol, result, &error); - g_assert_error(error, PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0); - g_clear_error(&error); - g_assert_null(model); -} - -static void -test_purple_protocol_contacts_empty_search_async(void) { - PurpleAccount *account = NULL; - PurpleProtocolContacts *protocol = NULL; - - protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), - NULL); - - account = purple_account_new("test", "test"); - purple_protocol_contacts_search_async(protocol, account, "alice", NULL, - test_purple_protocol_contacts_empty_search_cb, - NULL); - - g_main_context_iteration(NULL, FALSE); - - g_assert_finalize_object(account); - g_assert_finalize_object(protocol); -} - -static void test_purple_protocol_contacts_empty_get_profile_cb(GObject *source, GAsyncResult *result, G_GNUC_UNUSED gpointer data) @@ -203,60 +150,10 @@ gboolean should_error; - guint search_async; - guint search_finish; guint get_profile_async; guint get_profile_finish; }; -static guint -test_purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts) { - g_assert_true(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts)); - - return 2; -} - -static void -test_purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, - G_GNUC_UNUSED PurpleAccount *account, - G_GNUC_UNUSED const char *text, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data) -{ - TestPurpleProtocolContacts *protocol = NULL; - GTask *task = NULL; - - protocol = TEST_PURPLE_PROTOCOL_CONTACTS(protocol_contacts); - protocol->search_async += 1; - - task = g_task_new(protocol_contacts, cancellable, callback, data); - if(protocol->should_error) { - GError *error = g_error_new_literal(TEST_PURPLE_PROTOCOL_CONTACTS_DOMAIN, - 0, "error"); - g_task_return_error(task, error); - } else { - g_task_return_pointer(task, - g_list_store_new(PURPLE_TYPE_CONTACT_INFO), - g_object_unref); - } - - g_clear_object(&task); -} - -static GListModel * -test_purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, - GAsyncResult *result, - GError **error) -{ - TestPurpleProtocolContacts *protocol = NULL; - - protocol = TEST_PURPLE_PROTOCOL_CONTACTS(protocol_contacts); - protocol->search_finish += 1; - - return g_task_propagate_pointer(G_TASK(result), error); -} - static void test_purple_protocol_contacts_get_profile_async(PurpleProtocolContacts *r, G_GNUC_UNUSED PurpleContactInfo *info, @@ -315,11 +212,6 @@ static void test_purple_protocol_contacts_iface_init(PurpleProtocolContactsInterface *iface) { - iface->get_minimum_search_length = - test_purple_protocol_contacts_get_minimum_search_length; - iface->search_async = test_purple_protocol_contacts_search_async; - iface->search_finish = test_purple_protocol_contacts_search_finish; - iface->get_profile_async = test_purple_protocol_contacts_get_profile_async; iface->get_profile_finish = test_purple_protocol_contacts_get_profile_finish; @@ -335,8 +227,6 @@ static void test_purple_protocol_contacts_init(TestPurpleProtocolContacts *protocol_contacts) { - protocol_contacts->search_async = 0; - protocol_contacts->search_finish = 0; protocol_contacts->get_profile_async = 0; protocol_contacts->get_profile_finish = 0; } @@ -347,98 +237,6 @@ } /****************************************************************************** - * TestProtocolContacts search test - *****************************************************************************/ -static void -test_protocol_contacts_search_minimum_length(void) { - PurpleProtocolContacts *protocol = NULL; - guint minimum_search_length = 0; - - protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); - - minimum_search_length = - test_purple_protocol_contacts_get_minimum_search_length(protocol); - - g_assert_cmpuint(minimum_search_length, ==, 2); - - g_assert_finalize_object(protocol); -} - -static void -test_purple_protocol_contacts_search_cb(GObject *obj, GAsyncResult *res, - G_GNUC_UNUSED gpointer data) -{ - TestPurpleProtocolContacts *test_protocol = NULL; - PurpleProtocolContacts *protocol = NULL; - GError *error = NULL; - GListModel *result = NULL; - - test_protocol = TEST_PURPLE_PROTOCOL_CONTACTS(obj); - protocol = PURPLE_PROTOCOL_CONTACTS(obj); - - result = purple_protocol_contacts_search_finish(protocol, res, &error); - if(test_protocol->should_error) { - g_assert_error(error, TEST_PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0); - g_clear_error(&error); - g_assert_null(result); - } else { - GType type = G_TYPE_INVALID; - g_assert_no_error(error); - g_assert_true(G_IS_LIST_MODEL(result)); - - type = g_list_model_get_item_type(result); - g_assert_true(g_type_is_a(type, PURPLE_TYPE_CONTACT_INFO)); - g_clear_object(&result); - } -} - -static void -test_purple_protocol_contacts_search_normal(void) { - TestPurpleProtocolContacts *protocol = NULL; - PurpleAccount *account = NULL; - - protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); - account = purple_account_new("test", "test"); - - purple_protocol_contacts_search_async(PURPLE_PROTOCOL_CONTACTS(protocol), - account, "bob", NULL, - test_purple_protocol_contacts_search_cb, - account); - - g_main_context_iteration(NULL, FALSE); - - g_assert_cmpuint(protocol->search_async, ==, 1); - g_assert_cmpuint(protocol->search_finish, ==, 1); - - g_assert_finalize_object(protocol); - g_clear_object(&account); -} - -static void -test_purple_protocol_contacts_search_error(void) { - TestPurpleProtocolContacts *protocol = NULL; - PurpleAccount *account = NULL; - - protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); - protocol->should_error = TRUE; - - account = purple_account_new("test", "test"); - - purple_protocol_contacts_search_async(PURPLE_PROTOCOL_CONTACTS(protocol), - account, "bob", NULL, - test_purple_protocol_contacts_search_cb, - account); - - g_main_context_iteration(NULL, FALSE); - - g_assert_cmpuint(protocol->search_async, ==, 1); - g_assert_cmpuint(protocol->search_finish, ==, 1); - - g_assert_finalize_object(protocol); - g_clear_object(&account); -} - -/****************************************************************************** * TestProtocolContacts get profile test *****************************************************************************/ static void @@ -559,10 +357,6 @@ g_test_set_nonfatal_assertions(); - g_test_add_func("/protocol-contacts/empty/get-minimum-search-length", - test_purple_protocol_contacts_empty_get_minimum_search_length); - g_test_add_func("/protocol-contacts/empty/search-async", - test_purple_protocol_contacts_empty_search_async); g_test_add_func("/protocol-contacts/empty/get-profile-async", test_purple_protocol_contacts_empty_get_profile_async); g_test_add_func("/protocol-contacts/empty/get-actions", @@ -570,12 +364,6 @@ g_test_add_func("/protocol-contacts/empty/get-menu", test_purple_protocol_contacts_empty_get_menu); - g_test_add_func("/protocol-contacts/normal/get-minimum-search-length", - test_protocol_contacts_search_minimum_length); - g_test_add_func("/protocol-contacts/normal/search-async-normal", - test_purple_protocol_contacts_search_normal); - g_test_add_func("/protocol-contacts/normal/search-async-error", - test_purple_protocol_contacts_search_error); g_test_add_func("/protocol-contacts/normal/get-profile-normal", test_purple_protocol_contacts_get_profile_normal); g_test_add_func("/protocol-contacts/normal/get-profile-error",