# HG changeset patch
# Node ID ea89be90870baa63f613c61229442b30ba26c4d1
# Parent  4ff60371673fb56fb0de96de16052ca9f37a3243
diff --git a/libpurple/tests/test_protocol_contacts.c b/libpurple/tests/test_protocol_contacts.c
--- a/libpurple/tests/test_protocol_contacts.c
+++ b/libpurple/tests/test_protocol_contacts.c
@@ -24,32 +24,12 @@
 
 #include <purple.h>
 
-#include "test_ui.h"
-
 /******************************************************************************
  * Globals
  *****************************************************************************/
-
-/* Since we're using GTask to test asynchronous functions, we need to use a
- * main loop.
- */
-static GMainLoop *loop = NULL;
-
 #define TEST_PURPLE_PROTOCOL_CONTACTS_DOMAIN (g_quark_from_static_string("test-protocol-contacts"))
 
 /******************************************************************************
- * Helpers
- *****************************************************************************/
-static gboolean
-test_purple_protocol_contacts_timeout_cb(gpointer data) {
-	g_main_loop_quit(data);
-
-	g_warning("timed out waiting for the callback function to be called");
-
-	return G_SOURCE_REMOVE;
-}
-
-/******************************************************************************
  * TestProtocolContactsEmpty implementation
  *****************************************************************************/
 G_DECLARE_FINAL_TYPE(TestPurpleProtocolContactsEmpty,
@@ -386,10 +366,9 @@
 
 static void
 test_purple_protocol_contacts_search_cb(GObject *obj, GAsyncResult *res,
-                                        gpointer data)
+                                        G_GNUC_UNUSED gpointer data)
 {
 	TestPurpleProtocolContacts *test_protocol = NULL;
-	PurpleAccount *account = data;
 	PurpleProtocolContacts *protocol = NULL;
 	GError *error = NULL;
 	GListModel *result = NULL;
@@ -411,59 +390,52 @@
 		g_assert_true(g_type_is_a(type, PURPLE_TYPE_CONTACT_INFO));
 		g_clear_object(&result);
 	}
-
-	g_clear_object(&account);
-
-	g_main_loop_quit(loop);
-}
-
-static gboolean
-test_purple_protocol_contacts_search_idle(gpointer data) {
-	PurpleProtocolContacts *protocol = data;
-	PurpleAccount *account = NULL;
-
-	account = purple_account_new("test", "test");
-
-	purple_protocol_contacts_search_async(protocol, account, "bob", NULL,
-	                                      test_purple_protocol_contacts_search_cb,
-	                                      account);
-
-	return G_SOURCE_REMOVE;
 }
 
 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");
 
-	g_idle_add(test_purple_protocol_contacts_search_idle, protocol);
-	g_timeout_add_seconds(10, test_purple_protocol_contacts_timeout_cb, loop);
+	purple_protocol_contacts_search_async(PURPLE_PROTOCOL_CONTACTS(protocol),
+	                                      account, "bob", NULL,
+	                                      test_purple_protocol_contacts_search_cb,
+	                                      account);
 
-	g_main_loop_run(loop);
+	g_main_context_iteration(NULL, FALSE);
 
 	g_assert_cmpuint(protocol->search_async, ==, 1);
 	g_assert_cmpuint(protocol->search_finish, ==, 1);
 
-	g_clear_object(&protocol);
+	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;
 
-	g_idle_add(test_purple_protocol_contacts_search_idle, protocol);
-	g_timeout_add_seconds(10, test_purple_protocol_contacts_timeout_cb, loop);
+	account = purple_account_new("test", "test");
 
-	g_main_loop_run(loop);
+	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_clear_object(&protocol);
+	g_assert_finalize_object(protocol);
+	g_clear_object(&account);
 }
 
 /******************************************************************************
@@ -471,10 +443,9 @@
  *****************************************************************************/
 static void
 test_purple_protocol_contacts_get_profile_cb(GObject *obj, GAsyncResult *res,
-                                             gpointer data)
+                                             G_GNUC_UNUSED gpointer data)
 {
 	TestPurpleProtocolContacts *test_protocol_contacts = NULL;
-	PurpleContactInfo *info = data;
 	PurpleProtocolContacts *protocol_contacts = NULL;
 	GError *error = NULL;
 	char *result = NULL;
@@ -495,63 +466,52 @@
 		g_clear_pointer(&result, g_free);
 
 	}
-
-	g_clear_object(&info);
-
-	g_main_loop_quit(loop);
-}
-
-static gboolean
-test_purple_protocol_contacts_get_profile_idle(gpointer data) {
-	PurpleProtocolContacts *protocol_contacts = data;
-	PurpleContactInfo *info = NULL;
-
-	info = purple_contact_info_new(NULL);
-
-	purple_protocol_contacts_get_profile_async(protocol_contacts, info, NULL,
-	                                           test_purple_protocol_contacts_get_profile_cb,
-	                                           info);
-
-	return G_SOURCE_REMOVE;
 }
 
 static void
 test_purple_protocol_contacts_get_profile_normal(void) {
-	TestPurpleProtocolContacts *protocol_contacts = NULL;
+	TestPurpleProtocolContacts *protocol = NULL;
+	PurpleContactInfo *info = NULL;
 
-	protocol_contacts = g_object_new(test_purple_protocol_contacts_get_type(),
-	                                 NULL);
+	protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL);
+	info = purple_contact_info_new(NULL);
 
-	g_idle_add(test_purple_protocol_contacts_get_profile_idle,
-	           protocol_contacts);
-	g_timeout_add_seconds(10, test_purple_protocol_contacts_timeout_cb, loop);
+	purple_protocol_contacts_get_profile_async(PURPLE_PROTOCOL_CONTACTS(protocol),
+	                                           info, NULL,
+	                                           test_purple_protocol_contacts_get_profile_cb,
+	                                           info);
 
-	g_main_loop_run(loop);
+	g_main_context_iteration(NULL, FALSE);
 
-	g_assert_cmpuint(protocol_contacts->get_profile_async, ==, 1);
-	g_assert_cmpuint(protocol_contacts->get_profile_finish, ==, 1);
+	g_assert_cmpuint(protocol->get_profile_async, ==, 1);
+	g_assert_cmpuint(protocol->get_profile_finish, ==, 1);
 
-	g_clear_object(&protocol_contacts)
-;}
+	g_assert_finalize_object(protocol);
+	g_assert_finalize_object(info);
+}
 
 static void
 test_purple_protocol_contacts_get_profile_error_normal(void) {
-	TestPurpleProtocolContacts *protocol_contacts = NULL;
+	TestPurpleProtocolContacts *protocol = NULL;
+	PurpleContactInfo *info = NULL;
 
-	protocol_contacts = g_object_new(test_purple_protocol_contacts_get_type(),
-	                                 NULL);
-	protocol_contacts->should_error = TRUE;
+	protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL);
+	protocol->should_error = TRUE;
+
+	info = purple_contact_info_new(NULL);
 
-	g_idle_add(test_purple_protocol_contacts_get_profile_idle,
-	           protocol_contacts);
-	g_timeout_add_seconds(10, test_purple_protocol_contacts_timeout_cb, loop);
+	purple_protocol_contacts_get_profile_async(PURPLE_PROTOCOL_CONTACTS(protocol),
+	                                           info, NULL,
+	                                           test_purple_protocol_contacts_get_profile_cb,
+	                                           info);
 
-	g_main_loop_run(loop);
+	g_main_context_iteration(NULL, FALSE);
 
-	g_assert_cmpuint(protocol_contacts->get_profile_async, ==, 1);
-	g_assert_cmpuint(protocol_contacts->get_profile_finish, ==, 1);
+	g_assert_cmpuint(protocol->get_profile_async, ==, 1);
+	g_assert_cmpuint(protocol->get_profile_finish, ==, 1);
 
-	g_clear_object(&protocol_contacts);
+	g_assert_finalize_object(protocol);
+	g_assert_finalize_object(info);
 }
 
 static void
@@ -595,16 +555,10 @@
  *****************************************************************************/
 gint
 main(int argc, char **argv) {
-	int ret = 0;
-
 	g_test_init(&argc, &argv, NULL);
 
 	g_test_set_nonfatal_assertions();
 
-	test_ui_purple_init();
-
-	loop = g_main_loop_new(NULL, FALSE);
-
 	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",
@@ -631,11 +585,5 @@
 	g_test_add_func("/protocol-contacts/normal/get-menu",
 	                test_purple_protocol_contacts_get_menu_normal);
 
-	ret = g_test_run();
-
-	g_main_loop_unref(loop);
-
-	test_ui_purple_uninit();
-
-	return ret;
+	return g_test_run();
 }
