--- a/libpurple/meson.build Mon Dec 04 01:05:11 2023 -0600
+++ b/libpurple/meson.build Mon Dec 04 01:08:02 2023 -0600
@@ -81,7 +81,6 @@
'purpleprotocolclient.c',
'purpleprotocolcontacts.c',
- 'purpleprotocolcontactsearch.c',
'purpleprotocolconversation.c',
'purpleprotocolfiletransfer.c',
@@ -207,7 +206,6 @@
'purpleprotocolclient.h',
'purpleprotocolcontacts.h',
- 'purpleprotocolcontactsearch.h',
'purpleprotocolconversation.h',
'purpleprotocolfiletransfer.h',
--- a/libpurple/purpleprotocolcontacts.c Mon Dec 04 01:05:11 2023 -0600
+++ b/libpurple/purpleprotocolcontacts.c Mon Dec 04 01:08:02 2023 -0600
@@ -37,6 +37,71 @@
*****************************************************************************/
+purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, + PurpleAccount *account, + GCancellable *cancellable, + GAsyncReadyCallback callback, + PurpleProtocolContactsInterface *iface = NULL; + g_return_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts)); + g_return_if_fail(PURPLE_IS_ACCOUNT(account)); + g_return_if_fail(!purple_strempty(text)); + iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); + if(iface != NULL && iface->search_async != NULL) { + iface->search_async(protocol_contacts, account, text, cancellable, + g_warning("%s does not implement search_async", + G_OBJECT_TYPE_NAME(protocol_contacts)); +purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, + PurpleProtocolContactsInterface *iface = NULL; + g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), NULL); + iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); + if(iface != NULL && iface->search_finish != NULL) { + GListModel *ret = NULL; + ret = iface->search_finish(protocol_contacts, result, error); + if(G_IS_LIST_MODEL(ret)) { + GType type = G_TYPE_INVALID; + type = g_list_model_get_item_type(G_LIST_MODEL(ret)); + if(g_type_is_a(type, PURPLE_TYPE_CONTACT_INFO)) { + /* The GListModel we got back doesn't have an item type that is + * PurpleContactInfo or a subclass of it. + g_set_error(error, PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0, + "%s returned a list of type %s which is not " + "PurpleContactInfo or a subclass of", + G_OBJECT_TYPE_NAME(protocol_contacts), + g_warning("%s does not implement search_finish", + G_OBJECT_TYPE_NAME(protocol_contacts)); purple_protocol_contacts_get_profile_async(PurpleProtocolContacts *protocol_contacts,
GCancellable *cancellable,
--- a/libpurple/purpleprotocolcontacts.h Mon Dec 04 01:05:11 2023 -0600
+++ b/libpurple/purpleprotocolcontacts.h Mon Dec 04 01:08:02 2023 -0600
@@ -50,6 +50,17 @@
+ * PURPLE_PROTOCOL_CONTACTS_DOMAIN: + * A domain for errors from the [class@ProtocolContacts] API. +#define PURPLE_PROTOCOL_CONTACTS_DOMAIN \ + g_quark_from_static_string("purple-protocol-contacts") \ + PURPLE_AVAILABLE_MACRO_IN_3_0 * PurpleProtocolContactsInterface:
* This interface defines the behavior for interacting with contacts at the
@@ -63,6 +74,9 @@
+ void (*search_async)(PurpleProtocolContacts *protocol_contacts, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); + GListModel *(*search_finish)(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error); void (*get_profile_async)(PurpleProtocolContacts *protocol_contacts, PurpleContactInfo *info, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
char *(*get_profile_finish)(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error);
@@ -76,6 +90,44 @@
+ * purple_protocol_contacts_search_async: + * @protocol_contacts: The instance. + * @account: The [class@Account] to search under. + * @text: The text to search for which must not be an empty string. + * @cancellable: (nullable): optional GCancellable object, %NULL to ignore. + * @callback: (scope async): a #GAsyncReadyCallback to call when the request is + * @data: User data to pass to @callback. + * Starts the process of searching for contacts using @account that match + * Call [method@ProtocolContacts.search_finish] to get the results. +void purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); + * purple_protocol_contacts_search_finish: + * @search: The instance. + * @result: The [iface@Gio.AsyncResult] from the previous + * [method@ProtocolContacts.search_async] call. + * @error: Return address for a #GError, or %NULL. + * Finishes a previous call to [method@ProtocolContacts.search_async] and + * Returns: (transfer full): A [iface@Gio.ListModel] of the matched contacts or + * %NULL with @error set on error. +GListModel *purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error); * purple_protocol_contacts_get_profile_async:
* @protocol_contacts: The instance.
* @info: The [class@ContactInfo] whose profile to get.
--- a/libpurple/purpleprotocolcontactsearch.c Mon Dec 04 01:05:11 2023 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
- * Purple - Internet Messaging Library
- * Copyright (C) Pidgin Developers <devel@pidgin.im>
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program 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 General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <https://www.gnu.org/licenses/>.
-#include "purpleprotocolcontactsearch.h"
-/******************************************************************************
- * GInterface Implementation
- *****************************************************************************/
-G_DEFINE_INTERFACE(PurpleProtocolContactSearch, purple_protocol_contact_search,
-purple_protocol_contact_search_default_init(G_GNUC_UNUSED PurpleProtocolContactSearchInterface *iface)
-/******************************************************************************
- *****************************************************************************/
-purple_protocol_contact_search_search_async(PurpleProtocolContactSearch *search,
- PurpleAccount *account,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- PurpleProtocolContactSearchInterface *iface = NULL;
- g_return_if_fail(PURPLE_IS_PROTOCOL_CONTACT_SEARCH(search));
- g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- g_return_if_fail(!purple_strempty(text));
- iface = PURPLE_PROTOCOL_CONTACT_SEARCH_GET_IFACE(search);
- if(iface != NULL && iface->search_async != NULL) {
- iface->search_async(search, account, text, cancellable, callback,
- g_warning("%s does not implement search_async",
- G_OBJECT_TYPE_NAME(search));
-purple_protocol_contact_search_search_finish(PurpleProtocolContactSearch *search,
- PurpleProtocolContactSearchInterface *iface = NULL;
- g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACT_SEARCH(search), NULL);
- iface = PURPLE_PROTOCOL_CONTACT_SEARCH_GET_IFACE(search);
- if(iface != NULL && iface->search_finish != NULL) {
- GListModel *ret = iface->search_finish(search, result, error);
- if(G_IS_LIST_MODEL(ret)) {
- GType type = G_TYPE_INVALID;
- type = g_list_model_get_item_type(G_LIST_MODEL(ret));
- if(g_type_is_a(type, PURPLE_TYPE_CONTACT_INFO)) {
- /* The GListModel we got back doesn't have an item type that is
- * PurpleContactInfo or a subclass of it.
- g_set_error(error, PURPLE_PROTOCOL_CONTACT_SEARCH_DOMAIN, 0,
- "%s returned a list of type %s which is not "
- "PurpleContactInfo or a a subclass of",
- G_OBJECT_TYPE_NAME(search), g_type_name(type));
- g_warning("%s does not implement search_finish",
- G_OBJECT_TYPE_NAME(search));
--- a/libpurple/purpleprotocolcontactsearch.h Mon Dec 04 01:05:11 2023 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
- * Purple - Internet Messaging Library
- * Copyright (C) Pidgin Developers <devel@pidgin.im>
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program 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 General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <https://www.gnu.org/licenses/>.
-#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
-# error "only <purple.h> may be included directly"
-#ifndef PURPLE_PROTOCOL_CONTACT_SEARCH_H
-#define PURPLE_PROTOCOL_CONTACT_SEARCH_H
-#include <glib-object.h>
-#include "purpleprotocol.h"
-#include "purpleversion.h"
-#define PURPLE_PROTOCOL_CONTACT_SEARCH_DOMAIN \
- g_quark_from_static_string("purple-protocol-contact-search") \
- PURPLE_AVAILABLE_MACRO_IN_3_0
-#define PURPLE_TYPE_PROTOCOL_CONTACT_SEARCH (purple_protocol_contact_search_get_type())
-G_DECLARE_INTERFACE(PurpleProtocolContactSearch,
- purple_protocol_contact_search, PURPLE,
- PROTOCOL_CONTACT_SEARCH, PurpleProtocol)
- * PurpleProtocolContactSearch:
- * The #PurpleProtocolContactSearch interface defines the behavior to search
- * for new contacts to add to your contact list. A user interface will use
- * these methods to help users find new contacts.
- * PurpleProtocolContactSearchInterface:
- * This interface defines the behavior to implement searching for new contacts.
-struct _PurpleProtocolContactSearchInterface {
- void (*search_async)(PurpleProtocolContactSearch *search, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
- GListModel *(*search_finish)(PurpleProtocolContactSearch *search, GAsyncResult *result, GError **error);
- * purple_protocol_contact_search_search_async:
- * @search: The instance.
- * @account: The [class@Account] to search under.
- * @text: The text to search for which must not be an empty string.
- * @cancellable: (nullable): optional GCancellable object, %NULL to ignore.
- * @callback: (scope async): a #GAsyncReadyCallback to call when the request is
- * @data: User data to pass to @callback.
- * Starts the process of searching for contacts using @account that match
- * Call [method@ProtocolContactSearch.search_finish] to get the results.
-void purple_protocol_contact_search_search_async(PurpleProtocolContactSearch *search, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
- * purple_protocol_contact_search_search_finish:
- * @search: The instance.
- * @result: The [iface@Gio.AsyncResult] from the previous
- * [method@ProtocolContactSearch.search_async] call.
- * @error: Return address for a #GError, or %NULL.
- * Finishes a previous call to [method@ProtocolContactSearch.search_async] and
- * Returns: (transfer full): A [iface@Gio.ListModel] of the matched contacts or
- * %NULL with @error set on error.
-GListModel *purple_protocol_contact_search_search_finish(PurpleProtocolContactSearch *search, GAsyncResult *result, GError **error);
-#endif /* PURPLE_PROTOCOL_CONTACT_SEARCH_H */
--- a/libpurple/tests/meson.build Mon Dec 04 01:05:11 2023 -0600
+++ b/libpurple/tests/meson.build Mon Dec 04 01:08:02 2023 -0600
@@ -29,7 +29,6 @@
- 'protocol_contact_search',
'protocol_file_transfer',
--- a/libpurple/tests/test_protocol_contact_search.c Mon Dec 04 01:05:11 2023 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,320 +0,0 @@
- * Purple - Internet Messaging Library
- * Copyright (C) Pidgin Developers <devel@pidgin.im>
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program 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 General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <https://www.gnu.org/licenses/>.
-/******************************************************************************
- *****************************************************************************/
-/* Since we're using GTask to test asynchronous functions, we need to use a
-static GMainLoop *loop = NULL;
-#define TEST_PURPLE_PROTOCOL_CONTACT_SEARCH_DOMAIN (g_quark_from_static_string("test-purple-protocol-contact-search"))
-/******************************************************************************
- *****************************************************************************/
-test_purple_protocol_contact_search_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;
-/******************************************************************************
- * TestProtocolContactSearchEmpty implementation
- *****************************************************************************/
-G_DECLARE_FINAL_TYPE(TestPurpleProtocolContactSearchEmpty,
- test_purple_protocol_contact_search_empty,
- TEST_PURPLE, PROTOCOL_CONTACT_SEARCH_EMPTY, PurpleProtocol)
-struct _TestPurpleProtocolContactSearchEmpty {
-test_purple_protocol_contact_search_empty_iface_init(G_GNUC_UNUSED PurpleProtocolContactSearchInterface *iface)
-G_DEFINE_TYPE_WITH_CODE(TestPurpleProtocolContactSearchEmpty,
- test_purple_protocol_contact_search_empty,
- G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_CONTACT_SEARCH,
- test_purple_protocol_contact_search_empty_iface_init))
-test_purple_protocol_contact_search_empty_init(G_GNUC_UNUSED TestPurpleProtocolContactSearchEmpty *empty)
-test_purple_protocol_contact_search_empty_class_init(G_GNUC_UNUSED TestPurpleProtocolContactSearchEmptyClass *klass)
-/******************************************************************************
- * TestProtocolContactSearchEmpty Tests
- *****************************************************************************/
-test_purple_protocol_contact_search_empty_search_async(void) {
- if(g_test_subprocess()) {
- PurpleAccount *account = NULL;
- PurpleProtocolContactSearch *search = NULL;
- search = g_object_new(test_purple_protocol_contact_search_empty_get_type(),
- account = purple_account_new("test", "test");
- purple_protocol_contact_search_search_async(search, account, "alice",
- g_clear_object(&account);
- g_clear_object(&search);
- g_test_trap_subprocess(NULL, 0, 0);
- g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolContactSearchEmpty*search_async*");
-test_purple_protocol_contact_search_empty_search_finish(void) {
- if(g_test_subprocess()) {
- PurpleProtocolContactSearch *search = NULL;
- search = g_object_new(test_purple_protocol_contact_search_empty_get_type(),
- task = g_task_new(search, NULL, NULL, NULL);
- purple_protocol_contact_search_search_finish(search,
- g_clear_object(&search);
- g_test_trap_subprocess(NULL, 0, 0);
- g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolContactSearchEmpty*search_finish*");
-/******************************************************************************
- * TestProtocolContactSearch implementation
- *****************************************************************************/
-G_DECLARE_FINAL_TYPE(TestPurpleProtocolContactSearch,
- test_purple_protocol_contact_search, TEST_PURPLE,
- PROTOCOL_CONTACT_SEARCH, PurpleProtocol)
-struct _TestPurpleProtocolContactSearch {
- gboolean search_finish;
-test_purple_protocol_contact_search_search_async(PurpleProtocolContactSearch *r,
- G_GNUC_UNUSED PurpleAccount *account,
- G_GNUC_UNUSED const char *text,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- TestPurpleProtocolContactSearch *search = TEST_PURPLE_PROTOCOL_CONTACT_SEARCH(r);
- search->search_async = TRUE;
- task = g_task_new(r, cancellable, callback, data);
- if(search->should_error) {
- GError *error = g_error_new_literal(TEST_PURPLE_PROTOCOL_CONTACT_SEARCH_DOMAIN,
- g_task_return_error(task, error);
- g_task_return_pointer(task,
- g_list_store_new(PURPLE_TYPE_CONTACT_INFO),
-test_purple_protocol_contact_search_search_finish(PurpleProtocolContactSearch *r,
- TestPurpleProtocolContactSearch *search = TEST_PURPLE_PROTOCOL_CONTACT_SEARCH(r);
- search->search_finish = TRUE;
- return g_task_propagate_pointer(G_TASK(result), error);
-test_purple_protocol_contact_search_iface_init(PurpleProtocolContactSearchInterface *iface) {
- iface->search_async = test_purple_protocol_contact_search_search_async;
- iface->search_finish = test_purple_protocol_contact_search_search_finish;
-G_DEFINE_TYPE_WITH_CODE(TestPurpleProtocolContactSearch, test_purple_protocol_contact_search,
- G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_CONTACT_SEARCH,
- test_purple_protocol_contact_search_iface_init))
-test_purple_protocol_contact_search_init(G_GNUC_UNUSED TestPurpleProtocolContactSearch *search)
-test_purple_protocol_contact_search_class_init(G_GNUC_UNUSED TestPurpleProtocolContactSearchClass *klass)
-/******************************************************************************
- * TestProtocolContactSearch search test
- *****************************************************************************/
-test_purple_protocol_contact_search_search_cb(GObject *obj, GAsyncResult *res,
- TestPurpleProtocolContactSearch *test_search = TEST_PURPLE_PROTOCOL_CONTACT_SEARCH(obj);
- PurpleAccount *account = data;
- PurpleProtocolContactSearch *search = PURPLE_PROTOCOL_CONTACT_SEARCH(obj);
- GListModel *result = NULL;
- result = purple_protocol_contact_search_search_finish(search, res, &error);
- if(test_search->should_error) {
- g_assert_error(error, TEST_PURPLE_PROTOCOL_CONTACT_SEARCH_DOMAIN, 0);
- 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);
- g_clear_object(&account);
- g_main_loop_quit(loop);
-test_purple_protocol_contact_search_search_idle(gpointer data) {
- PurpleProtocolContactSearch *search = data;
- PurpleAccount *account = NULL;
- account = purple_account_new("test", "test");
- purple_protocol_contact_search_search_async(search, account, "bob", NULL,
- test_purple_protocol_contact_search_search_cb,
- return G_SOURCE_REMOVE;
-test_purple_protocol_contact_search_search(void) {
- TestPurpleProtocolContactSearch *search = NULL;
- search = g_object_new(test_purple_protocol_contact_search_get_type(), NULL);
- g_idle_add(test_purple_protocol_contact_search_search_idle, search);
- g_timeout_add_seconds(10, test_purple_protocol_contact_search_timeout_cb, loop);
- g_assert_true(search->search_async);
- g_assert_true(search->search_finish);
- g_clear_object(&search)
-test_purple_protocol_contact_search_search_error(void) {
- TestPurpleProtocolContactSearch *search = NULL;
- search = g_object_new(test_purple_protocol_contact_search_get_type(), NULL);
- search->should_error = TRUE;
- g_idle_add(test_purple_protocol_contact_search_search_idle, search);
- g_timeout_add_seconds(10, test_purple_protocol_contact_search_timeout_cb, loop);
- g_assert_true(search->search_async);
- g_assert_true(search->search_finish);
- g_clear_object(&search)
-/******************************************************************************
- *****************************************************************************/
-main(gint argc, gchar **argv) {
- g_test_init(&argc, &argv, NULL);
- loop = g_main_loop_new(NULL, FALSE);
- g_test_add_func("/protocol-contact-search/empty/search-async",
- test_purple_protocol_contact_search_empty_search_async);
- g_test_add_func("/protocol-contact-search/empty/search-finish",
- test_purple_protocol_contact_search_empty_search_finish);
- g_test_add_func("/protocol-contact-search/normal/search",
- test_purple_protocol_contact_search_search);
- g_test_add_func("/protocol-contact-search/normal/search-error",
- test_purple_protocol_contact_search_search_error);
- g_main_loop_unref(loop);
- test_ui_purple_uninit();
--- a/libpurple/tests/test_protocol_contacts.c Mon Dec 04 01:05:11 2023 -0600
+++ b/libpurple/tests/test_protocol_contacts.c Mon Dec 04 01:08:02 2023 -0600
@@ -85,6 +85,48 @@
* TestProtocolContactsEmpty Tests
*****************************************************************************/
+test_purple_protocol_contacts_empty_search_async(void) { + if(g_test_subprocess()) { + PurpleAccount *account = NULL; + PurpleProtocolContacts *protocol = NULL; + protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), + account = purple_account_new("test", "test"); + purple_protocol_contacts_search_async(protocol, account, "alice", NULL, + g_clear_object(&account); + g_clear_object(&protocol); + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolContactsEmpty*search_async*"); +test_purple_protocol_contacts_empty_search_finish(void) { + if(g_test_subprocess()) { + PurpleProtocolContacts *protocol = NULL; + protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), + task = g_task_new(protocol, NULL, NULL, NULL); + purple_protocol_contacts_search_finish(protocol, G_ASYNC_RESULT(task), + g_clear_object(&protocol); + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolContactsEmpty*search_finish*"); test_purple_protocol_contacts_empty_get_profile_async(void) {
if(g_test_subprocess()) {
PurpleContactInfo *info = NULL;
@@ -178,11 +220,54 @@
guint get_profile_finish;
+test_purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, + G_GNUC_UNUSED PurpleAccount *account, + G_GNUC_UNUSED const char *text, + GCancellable *cancellable, + GAsyncReadyCallback callback, + TestPurpleProtocolContacts *protocol = 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, + g_task_return_error(task, error); + g_task_return_pointer(task, + g_list_store_new(PURPLE_TYPE_CONTACT_INFO), +test_purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, + TestPurpleProtocolContacts *protocol = NULL; + protocol = TEST_PURPLE_PROTOCOL_CONTACTS(protocol_contacts); + protocol->search_finish += 1; + return g_task_propagate_pointer(G_TASK(result), error); test_purple_protocol_contacts_get_profile_async(PurpleProtocolContacts *r,
G_GNUC_UNUSED PurpleContactInfo *info,
GCancellable *cancellable,
@@ -240,6 +325,9 @@
test_purple_protocol_contacts_iface_init(PurpleProtocolContactsInterface *iface) {
+ 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;
@@ -255,6 +343,8 @@
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;
@@ -268,6 +358,91 @@
* TestProtocolContacts search test
*****************************************************************************/
+test_purple_protocol_contacts_search_cb(GObject *obj, GAsyncResult *res, + TestPurpleProtocolContacts *test_protocol = NULL; + PurpleAccount *account = data; + PurpleProtocolContacts *protocol = 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); + 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); + g_clear_object(&account); + g_main_loop_quit(loop); +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, + return G_SOURCE_REMOVE; +test_purple_protocol_contacts_search_normal(void) { + TestPurpleProtocolContacts *protocol = NULL; + protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); + g_idle_add(test_purple_protocol_contacts_search_idle, protocol); + g_timeout_add_seconds(10, test_purple_protocol_contacts_timeout_cb, loop); + g_assert_cmpuint(protocol->search_async, ==, 1); + g_assert_cmpuint(protocol->search_finish, ==, 1); + g_clear_object(&protocol); +test_purple_protocol_contacts_search_error(void) { + TestPurpleProtocolContacts *protocol = 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); + g_assert_cmpuint(protocol->search_async, ==, 1); + g_assert_cmpuint(protocol->search_finish, ==, 1); + g_clear_object(&protocol); +/****************************************************************************** + * TestProtocolContacts get profile test + *****************************************************************************/ test_purple_protocol_contacts_get_profile_cb(GObject *obj, GAsyncResult *res,
@@ -401,6 +576,10 @@
loop = g_main_loop_new(NULL, FALSE);
+ g_test_add_func("/protocol-contacts/empty/search-async", + test_purple_protocol_contacts_empty_search_async); + g_test_add_func("/protocol-contacts/empty/search-finish", + test_purple_protocol_contacts_empty_search_finish); 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-profile-finish",
@@ -410,6 +589,10 @@
g_test_add_func("/protocol-contacts/empty/get-menu",
test_purple_protocol_contacts_empty_get_menu);
+ 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",