summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-01 12:41:04 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-01 12:41:04 +0000
commit286de351344cc638bb90ecf0156af0a55a3534b3 (patch)
tree10df5c8b5fd86b17740adec1b4320ad7b705441d
parentae5cdd067bff820333fafb4b820b3a41aea4f129 (diff)
parentcdfa979d03137d90150ac030a21c92f1f6e5e60b (diff)
Merge branch 'master' into next
Conflicts: configure.ac telepathy-glib/base-channel.c tests/dbus/callable-example.c tests/dbus/connection-inject-bug16307.c tests/dbus/contacts-slow-path.c tests/dbus/contacts.c tests/dbus/text-mixin.c tests/lib/simple-account-manager.c
-rw-r--r--NEWS11
-rw-r--r--configure.ac2
-rw-r--r--docs/reference/telepathy-glib-sections.txt7
-rw-r--r--telepathy-glib/account-manager.c57
-rw-r--r--telepathy-glib/base-channel.c73
-rw-r--r--telepathy-glib/base-channel.h4
-rw-r--r--telepathy-glib/base-password-channel.c20
-rw-r--r--telepathy-glib/channel-contacts.c22
-rw-r--r--telepathy-glib/channel-internal.h4
-rw-r--r--telepathy-glib/connection.c67
-rw-r--r--telepathy-glib/connection.h7
-rw-r--r--telepathy-glib/gnio-util.c211
-rw-r--r--telepathy-glib/gnio-util.h20
-rw-r--r--telepathy-glib/stream-tube-channel.c132
-rw-r--r--telepathy-glib/util.c5
-rw-r--r--tests/dbus/account-channel-request.c4
-rw-r--r--tests/dbus/account-manager.c271
-rw-r--r--tests/dbus/base-client.c4
-rw-r--r--tests/dbus/call-example.c3
-rw-r--r--tests/dbus/channel-dispatch-operation.c3
-rw-r--r--tests/dbus/channel-introspect.c3
-rw-r--r--tests/dbus/channel-manager-request-properties.c3
-rw-r--r--tests/dbus/channel-request.c4
-rw-r--r--tests/dbus/channel.c4
-rw-r--r--tests/dbus/cli-group.c3
-rw-r--r--tests/dbus/client-channel-factory.c4
-rw-r--r--tests/dbus/cm-message.c4
-rw-r--r--tests/dbus/connection-aliasing.c5
-rw-r--r--tests/dbus/connection-balance.c5
-rw-r--r--tests/dbus/connection-bug-18845.c4
-rw-r--r--tests/dbus/connection-error.c8
-rw-r--r--tests/dbus/connection-handles.c4
-rw-r--r--tests/dbus/connection-interests.c5
-rw-r--r--tests/dbus/connection.c5
-rw-r--r--tests/dbus/contact-list-client.c4
-rw-r--r--tests/dbus/contact-lists.c10
-rw-r--r--tests/dbus/contacts-bug-19101.c4
-rw-r--r--tests/dbus/contacts-mixin.c4
-rw-r--r--tests/dbus/contacts.c9
-rw-r--r--tests/dbus/dbus-tube.c4
-rw-r--r--tests/dbus/file-transfer-channel.c4
-rw-r--r--tests/dbus/group-mixin.c3
-rw-r--r--tests/dbus/message-mixin.c3
-rw-r--r--tests/dbus/proxy-preparation.c5
-rw-r--r--tests/dbus/self-handle.c9
-rw-r--r--tests/dbus/self-presence.c4
-rw-r--r--tests/dbus/simple-approver.c4
-rw-r--r--tests/dbus/simple-handler.c4
-rw-r--r--tests/dbus/simple-observer.c4
-rw-r--r--tests/dbus/stream-tube.c66
-rw-r--r--tests/dbus/text-channel.c4
-rw-r--r--tests/dbus/text-respawn.c3
-rw-r--r--tests/lib/dbus-tube-chan.c4
-rw-r--r--tests/lib/file-transfer-chan.c3
-rw-r--r--tests/lib/simple-account-manager.c40
-rw-r--r--tests/lib/simple-account-manager.h3
-rw-r--r--tests/lib/simple-account.c54
-rw-r--r--tests/lib/simple-account.h8
-rw-r--r--tests/lib/util.c18
-rw-r--r--tests/lib/util.h2
60 files changed, 1028 insertions, 240 deletions
diff --git a/NEWS b/NEWS
index 2fa8db9de..53bbb8931 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+telepathy-glib 0.17.4 (2011-12-19)
+==================================
+
+Fixes:
+
+• Set the right source on tp_account_set_uri_scheme_association_async's
+ GAsyncResult. (Guillaume)
+
+• fdo#43755: Fix a crash when participating in a XMPP MUC containing
+members with an unknown real JID. (Guillaume)
+
telepathy-glib 0.17.3 (2011-11-28)
==================================
diff --git a/configure.ac b/configure.ac
index d7c7248fc..f98b08e08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,7 @@ m4_define([tp_glib_nano_version], [1])
# never seen in a release).
m4_define([tp_glib_lt_current], [66])
-m4_define([tp_glib_lt_revision], [0])
+m4_define([tp_glib_lt_revision], [1])
m4_define([tp_glib_lt_age], [66])
# Some magic
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 66229802e..e7927bc9a 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -187,6 +187,7 @@ TpBaseChannelClass
TpBaseChannelFillPropertiesFunc
TpBaseChannelCloseFunc
TpBaseChannelGetPathFunc
+TpBaseChannelGetInterfacesFunc
tp_base_channel_register
tp_base_channel_close
tp_base_channel_destroyed
@@ -1056,7 +1057,11 @@ tp_utf8_make_valid
tp_g_socket_address_from_variant
tp_address_variant_from_g_socket_address
tp_unix_connection_receive_credentials_with_byte
+tp_unix_connection_receive_credentials_with_byte_async
+tp_unix_connection_receive_credentials_with_byte_finish
tp_unix_connection_send_credentials_with_byte
+tp_unix_connection_send_credentials_with_byte_async
+tp_unix_connection_send_credentials_with_byte_finish
</SECTION>
<SECTION>
@@ -2832,6 +2837,8 @@ tp_connection_run_until_ready
TpConnectionWhenReadyCb
tp_connection_call_when_ready
tp_connection_is_ready
+tp_connection_disconnect_async
+tp_connection_disconnect_finish
tp_connection_get_account
tp_connection_get_status
tp_connection_get_connection_manager_name
diff --git a/telepathy-glib/account-manager.c b/telepathy-glib/account-manager.c
index 4e65b2cd8..405986649 100644
--- a/telepathy-glib/account-manager.c
+++ b/telepathy-glib/account-manager.c
@@ -327,6 +327,7 @@ _tp_account_manager_update_most_available_presence (TpAccountManager *manager)
TpAccount *account = NULL;
GHashTableIter iter;
gpointer value;
+ TpAccount *has_unset_presence = NULL;
/* this presence is equal to the presence of the account with the
* highest availability */
@@ -339,6 +340,14 @@ _tp_account_manager_update_most_available_presence (TpAccountManager *manager)
p = tp_account_get_current_presence (a, NULL, NULL);
+ if (p == TP_CONNECTION_PRESENCE_TYPE_UNSET)
+ {
+ has_unset_presence = a;
+ /* There is no point comparing the presence as UNSET is the
+ * 'smallest' presence of all */
+ continue;
+ }
+
if (tp_connection_presence_type_cmp_availability (p, presence) > 0)
{
account = a;
@@ -346,15 +355,23 @@ _tp_account_manager_update_most_available_presence (TpAccountManager *manager)
}
}
+ if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
+ has_unset_presence != NULL)
+ {
+ /* Use an account having UNSET as presence as the 'best' one,
+ * see tp_account_manager_get_most_available_presence() */
+ account = has_unset_presence;
+ }
+
priv->most_available_account = account;
g_free (priv->most_available_status);
g_free (priv->most_available_status_message);
if (account == NULL)
{
- priv->most_available_presence = presence;
- priv->most_available_status = NULL;
- priv->most_available_status_message = NULL;
+ priv->most_available_presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+ priv->most_available_status = g_strdup ("offline");
+ priv->most_available_status_message = g_strdup ("");
return;
}
@@ -865,6 +882,9 @@ _tp_account_manager_account_presence_changed_cb (TpAccount *account,
{
TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data);
TpAccountManagerPrivate *priv = manager->priv;
+ TpConnectionPresenceType p;
+ gchar *s;
+ gchar *msg;
if (tp_connection_presence_type_cmp_availability (presence,
priv->most_available_presence) > 0)
@@ -888,10 +908,19 @@ _tp_account_manager_account_presence_changed_cb (TpAccount *account,
}
return;
+
signal:
+ /* Use tp_account_manager_get_most_available_presence() as the effective
+ * most available presence may differ of the one stored in
+ * priv->most_available_presence. */
+ p = tp_account_manager_get_most_available_presence (manager,
+ &s, &msg);
+
g_signal_emit (manager, signals[MOST_AVAILABLE_PRESENCE_CHANGED], 0,
- priv->most_available_presence, priv->most_available_status,
- priv->most_available_status_message);
+ p, s, msg);
+
+ g_free (s);
+ g_free (msg);
}
static void
@@ -1127,6 +1156,10 @@ tp_account_manager_set_all_requested_presences (TpAccountManager *manager,
* If no accounts are enabled or usable the output will be
* (%TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", "").
*
+ * Since 0.UNRELEASED, if the only connected accounts does not implement
+ * %TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE, the output will be
+ * (%TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", "").
+ *
* The return value of this function is not guaranteed to have been retrieved
* until tp_proxy_prepare_async() has finished; until then, the
* value will be the same as if no accounts are enabled or usable.
@@ -1148,6 +1181,20 @@ tp_account_manager_get_most_available_presence (TpAccountManager *manager,
priv = manager->priv;
+ if (priv->most_available_presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
+ {
+ /* The best we have is an account having UNSET as its presence, which
+ * means it's connected but does not implement SimplePresence; pretend
+ * we are available. */
+ if (status != NULL)
+ *status = g_strdup ("available");
+
+ if (message != NULL)
+ *message = g_strdup ("");
+
+ return TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+ }
+
if (status != NULL)
*status = g_strdup (priv->most_available_status);
diff --git a/telepathy-glib/base-channel.c b/telepathy-glib/base-channel.c
index ae865ec16..1030d4cc7 100644
--- a/telepathy-glib/base-channel.c
+++ b/telepathy-glib/base-channel.c
@@ -29,9 +29,10 @@
* implementations by implementing some of its properties, and defining other
* relevant properties.
*
- * Subclasses should fill in #TpBaseChannelClass.channel_type,
- * #TpBaseChannelClass.target_handle_type and #TpBaseChannelClass.interfaces,
- * and implement the #TpBaseChannelClass.close virtual function.
+ * Subclasses should fill in #TpBaseChannelClass.channel_type and
+ * #TpBaseChannelClass.target_handle_type; and implement the
+ * #TpBaseChannelClass.get_interfaces and
+ * #TpBaseChannelClass.close virtual functions.
*
* If the channel type and/or interfaces being implemented define immutable
* D-Bus properties besides those on the Channel interface, the subclass should
@@ -60,8 +61,7 @@
* (e.g. #TP_IFACE_CHANNEL_TYPE_TEXT)
* @target_handle_type: The type of handle that is the target of channels of
* this type
- * @interfaces: Extra interfaces provided by this channel (this SHOULD NOT
- * include the channel type and interface itself)
+ * @interfaces: Deprecated. Replaced by @get_interfaces.
* @close: A virtual function called to close the channel, which will be called
* by tp_base_channel_close() and by the implementation of the Closed D-Bus
* method.
@@ -75,6 +75,10 @@
* #TpExportableChannel:object-path property is not set. The default
* implementation simply generates a unique path based on the object's address
* in memory. The returned string will be freed automatically.
+ * @get_interfaces: Extra interfaces provided by this channel (this SHOULD NOT
+ * include the channel type and interface itself). Implementation must first
+ * chainup on parent class implementation and then add extra interfaces into
+ * the #GPtrArray. Replaces @interfaces.
*
* The class structure for #TpBaseChannel
*
@@ -199,6 +203,36 @@
* Since: 0.11.14
*/
+/**
+ * TpBaseChannelGetInterfacesFunc:
+ * @chan: a channel
+ *
+ * Signature of an implementation of #TpBaseChannelClass.get_interfaces virtual
+ * function.
+ *
+ * Implementation must first chainup on parent class implementation and then
+ * add extra interfaces into the #GPtrArray.
+ *
+ * |[
+ * static GPtrArray *
+ * my_channel_get_interfaces (TpBaseChannel *self)
+ * {
+ * GPtrArray *interfaces;
+ *
+ * interfaces = TP_BASE_CHANNEL_CLASS (my_channel_parent_class)->get_interfaces (self);
+ *
+ * g_ptr_array_add (interfaces, TP_IFACE_BADGERS);
+ *
+ * return interfaces;
+ * }
+ * ]|
+ *
+ * Returns: (transfer container): a #GPtrArray of static strings for D-Bus
+ * interfaces implemented by this client.
+ *
+ * Since: UNRELEASED
+ */
+
#include "config.h"
#include "base-channel.h"
@@ -559,6 +593,23 @@ tp_base_channel_get_basic_object_path_suffix (TpBaseChannel *self)
return escaped;
}
+static GPtrArray *
+tp_base_channel_get_basic_interfaces (TpBaseChannel *self)
+{
+ GPtrArray *interfaces = g_ptr_array_new ();
+ const char **ptr;
+
+ /* copy the klass->interfaces property for backwards compatibility */
+ for (ptr = TP_BASE_CHANNEL_GET_CLASS (self)->interfaces;
+ ptr != NULL && *ptr != NULL;
+ ptr++)
+ {
+ g_ptr_array_add (interfaces, (char *) *ptr);
+ }
+
+ return interfaces;
+}
+
static void
tp_base_channel_init (TpBaseChannel *self)
{
@@ -671,8 +722,14 @@ tp_base_channel_get_property (GObject *object,
g_value_set_object (value, chan->priv->conn);
break;
case PROP_INTERFACES:
- g_value_set_boxed (value, klass->interfaces);
- break;
+ {
+ GPtrArray *interfaces = klass->get_interfaces (chan);
+
+ g_ptr_array_add (interfaces, NULL);
+ g_value_set_boxed (value, interfaces->pdata);
+ g_ptr_array_unref (interfaces);
+ break;
+ }
case PROP_CHANNEL_DESTROYED:
g_value_set_boolean (value, chan->priv->destroyed);
break;
@@ -878,6 +935,8 @@ tp_base_channel_class_init (TpBaseChannelClass *tp_base_channel_class)
tp_base_channel_fill_basic_immutable_properties;
tp_base_channel_class->get_object_path_suffix =
tp_base_channel_get_basic_object_path_suffix;
+ tp_base_channel_class->get_interfaces =
+ tp_base_channel_get_basic_interfaces;
}
static void
diff --git a/telepathy-glib/base-channel.h b/telepathy-glib/base-channel.h
index 1476ddf5f..01669b5f0 100644
--- a/telepathy-glib/base-channel.h
+++ b/telepathy-glib/base-channel.h
@@ -39,6 +39,7 @@ typedef void (*TpBaseChannelCloseFunc) (TpBaseChannel *chan);
typedef void (*TpBaseChannelFillPropertiesFunc) (TpBaseChannel *chan,
GHashTable *properties);
typedef gchar *(*TpBaseChannelGetPathFunc) (TpBaseChannel *chan);
+typedef GPtrArray *(*TpBaseChannelGetInterfacesFunc) (TpBaseChannel *chan);
struct _TpBaseChannelClass
{
@@ -55,9 +56,10 @@ struct _TpBaseChannelClass
TpBaseChannelCloseFunc close;
TpBaseChannelFillPropertiesFunc fill_immutable_properties;
TpBaseChannelGetPathFunc get_object_path_suffix;
+ TpBaseChannelGetInterfacesFunc get_interfaces;
/*< private >*/
- GCallback _reserved[10];
+ GCallback _reserved[9];
};
struct _TpBaseChannel
diff --git a/telepathy-glib/base-password-channel.c b/telepathy-glib/base-password-channel.c
index 583d40329..825b807d6 100644
--- a/telepathy-glib/base-password-channel.c
+++ b/telepathy-glib/base-password-channel.c
@@ -74,11 +74,6 @@ G_DEFINE_TYPE_WITH_CODE (TpBasePasswordChannel, tp_base_password_channel,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_SASL_AUTHENTICATION,
sasl_auth_iface_init));
-static const gchar *tp_base_password_channel_interfaces[] = {
- TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION,
- NULL
-};
-
static const gchar *tp_base_password_channel_available_mechanisms[] = {
"X-TELEPATHY-PASSWORD",
NULL
@@ -128,6 +123,19 @@ struct _TpBasePasswordChannelPrivate
gboolean may_save_response;
};
+static GPtrArray *
+tp_base_password_channel_get_interfaces (TpBaseChannel *base)
+{
+ GPtrArray *interfaces;
+
+ interfaces = TP_BASE_CHANNEL_CLASS (
+ tp_base_password_channel_parent_class)->get_interfaces (base);
+
+ g_ptr_array_add (interfaces, TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION);
+
+ return interfaces;
+}
+
static void
tp_base_password_channel_init (TpBasePasswordChannel *self)
{
@@ -283,7 +291,7 @@ tp_base_password_channel_class_init (TpBasePasswordChannelClass *tp_base_passwor
chan_class->channel_type = TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION;
chan_class->target_handle_type = TP_HANDLE_TYPE_NONE;
- chan_class->interfaces = tp_base_password_channel_interfaces;
+ chan_class->get_interfaces = tp_base_password_channel_get_interfaces;
chan_class->close = tp_base_password_channel_close;
chan_class->fill_immutable_properties =
tp_base_password_channel_fill_immutable_properties;
diff --git a/telepathy-glib/channel-contacts.c b/telepathy-glib/channel-contacts.c
index 3670a49b6..1f3afc7d2 100644
--- a/telepathy-glib/channel-contacts.c
+++ b/telepathy-glib/channel-contacts.c
@@ -219,13 +219,13 @@ _tp_channel_contacts_group_init (TpChannel *self,
}
}
-typedef struct
+struct _ContactsQueueItem
{
GSimpleAsyncResult *result;
GPtrArray *contacts;
GPtrArray *ids;
GArray *handles;
-} ContactsQueueItem;
+};
static ContactsQueueItem *
contacts_queue_item_new (GPtrArray *contacts,
@@ -260,9 +260,7 @@ static void
contacts_queue_head_ready (TpChannel *self,
const GError *error)
{
- ContactsQueueItem *item;
-
- item = g_queue_pop_head (self->priv->contacts_queue);
+ ContactsQueueItem *item = self->priv->current_item;
if (error != NULL)
{
@@ -271,6 +269,7 @@ contacts_queue_head_ready (TpChannel *self,
}
g_simple_async_result_complete (item->result);
+ self->priv->current_item = NULL;
process_contacts_queue (self);
contacts_queue_item_free (item);
@@ -353,8 +352,7 @@ process_contacts_queue (TpChannel *self)
GArray *features;
const GError *error = NULL;
- item = g_queue_peek_head (self->priv->contacts_queue);
- if (item == NULL)
+ if (self->priv->current_item != NULL)
return;
/* self can't die while there are queued items because item->result keeps a
@@ -374,6 +372,11 @@ process_contacts_queue (TpChannel *self)
return;
}
+ item = g_queue_pop_head (self->priv->contacts_queue);
+ if (item == NULL)
+ return;
+ self->priv->current_item = item;
+
features = tp_simple_client_factory_dup_contact_features (
tp_proxy_get_factory (self->priv->connection), self->priv->connection);
@@ -437,10 +440,7 @@ contacts_queue_item (TpChannel *self,
g_simple_async_result_set_op_res_gpointer (item->result, item, NULL);
g_queue_push_tail (self->priv->contacts_queue, item);
-
- /* If this is the only item in the queue, we can process it right away */
- if (self->priv->contacts_queue->length == 1)
- process_contacts_queue (self);
+ process_contacts_queue (self);
}
void
diff --git a/telepathy-glib/channel-internal.h b/telepathy-glib/channel-internal.h
index c445a4807..b39b45c27 100644
--- a/telepathy-glib/channel-internal.h
+++ b/telepathy-glib/channel-internal.h
@@ -35,6 +35,8 @@ typedef struct {
gchar *message;
} LocalPendingInfo;
+typedef struct _ContactsQueueItem ContactsQueueItem;
+
struct _TpChannelPrivate {
gulong conn_invalidated_id;
@@ -76,6 +78,8 @@ struct _TpChannelPrivate {
GHashTable *group_contact_owners;
GQueue *contacts_queue;
+ /* Item currently being prepared, not part of contacts_queue anymore */
+ ContactsQueueItem *current_item;
/* NULL, or TpHandle => TpChannelChatState;
* if non-NULL, we're watching for ChatStateChanged */
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index 82dec89e9..b4374feec 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -3347,3 +3347,70 @@ tp_connection_get_balance_uri (TpConnection *self)
return self->priv->balance_uri;
}
+
+static void
+_tp_connection_void_cb (TpConnection *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
+
+ if (error != NULL)
+ g_simple_async_result_set_from_error (result, error);
+
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (G_OBJECT (result));
+}
+
+/**
+ * tp_connection_disconnect_async:
+ * @self: a #TpConnection
+ * @callback: a callback to call when the request is satisfied
+ * @user_data: data to pass to @callback
+ *
+ * Disconnect the connection.
+ *
+ * This method is intended for use by AccountManager implementations,
+ * such as Mission Control. To disconnect a connection managed by an
+ * AccountManager, either use tp_account_request_presence_async()
+ * or tp_account_set_enabled_async(), depending whether the intention is
+ * to put the account offline temporarily, or disable it longer-term.
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_connection_disconnect_async (TpConnection *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ g_return_if_fail (TP_IS_CONNECTION (self));
+
+ result = g_simple_async_result_new (G_OBJECT (self), callback,
+ user_data, tp_connection_disconnect_async);
+
+ tp_cli_connection_call_disconnect (self, -1, _tp_connection_void_cb, result,
+ NULL, NULL);
+}
+
+/**
+ * tp_connection_disconnect_finish:
+ * @self: a #TpConnection
+ * @result: a #GAsyncResult
+ * @error: a #GError to fill
+ *
+ * Interpret the result of tp_connection_disconnect_async().
+ *
+ * Returns: %TRUE if the call was successful, otherwise %FALSE
+ *
+ * Since: 0.UNRELEASED
+ */
+gboolean
+tp_connection_disconnect_finish (TpConnection *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ _tp_implement_finish_void (self, tp_connection_disconnect_async);
+}
diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h
index 2005c51a6..7518ef99a 100644
--- a/telepathy-glib/connection.h
+++ b/telepathy-glib/connection.h
@@ -278,6 +278,13 @@ gboolean tp_connection_get_balance (TpConnection *self,
gint *balance, guint *scale, const gchar **currency);
const gchar * tp_connection_get_balance_uri (TpConnection *self);
+void tp_connection_disconnect_async (TpConnection *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean tp_connection_disconnect_finish (TpConnection *self,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#include <telepathy-glib/_gen/tp-cli-connection.h>
diff --git a/telepathy-glib/gnio-util.c b/telepathy-glib/gnio-util.c
index d08b9f88e..8831bb3a8 100644
--- a/telepathy-glib/gnio-util.c
+++ b/telepathy-glib/gnio-util.c
@@ -43,6 +43,7 @@
#include <telepathy-glib/util.h>
#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/errors.h>
+#include <telepathy-glib/util-internal.h>
#include <string.h>
@@ -365,6 +366,88 @@ tp_unix_connection_send_credentials_with_byte (GSocketConnection *connection,
#endif
}
+static void
+send_credentials_with_byte_async_thread (GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ guchar byte;
+ GError *error = NULL;
+
+ byte = GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (res));
+
+ if (!tp_unix_connection_send_credentials_with_byte (
+ (GSocketConnection *) object, byte, cancellable, &error))
+ {
+ g_simple_async_result_take_error (res, error);
+ }
+}
+
+/**
+ * tp_unix_connection_send_credentials_with_byte_async:
+ * @connection: A #GUnixConnection.
+ * @byte: the byte to send with the credentials
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously send credentials.
+ *
+ * For more details, see tp_unix_connection_send_credentials_with_byte() which
+ * is the synchronous version of this call.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * tp_unix_connection_send_credentials_with_byte_finish() to get the result of
+ * the operation.
+ *
+ * Since: 0.UNRELEASED
+ **/
+void
+tp_unix_connection_send_credentials_with_byte_async (
+ GSocketConnection *connection,
+ guchar byte,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res;
+
+ res = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
+ tp_unix_connection_send_credentials_with_byte_async);
+
+ /* Extra casting to guint to work around GNOME#661546 for GLib < 2.32 */
+ g_simple_async_result_set_op_res_gpointer (res,
+ GUINT_TO_POINTER ((guint) byte), NULL);
+
+ g_simple_async_result_run_in_thread (res,
+ send_credentials_with_byte_async_thread, G_PRIORITY_DEFAULT, cancellable);
+
+ g_object_unref (res);
+}
+
+/**
+ * tp_unix_connection_send_credentials_with_byte_finish:
+ * @connection: A #GUnixConnection.
+ * @result: a #GAsyncResult.
+ * @error: a #GError, or %NULL
+ *
+ * Finishes an asynchronous send credentials operation started with
+ * tp_unix_connection_send_credentials_with_byte_async().
+ *
+ * Returns: %TRUE if the operation was successful, otherwise %FALSE.
+ *
+ * Since: 0.UNRELEASED
+ **/
+gboolean
+tp_unix_connection_send_credentials_with_byte_finish (
+ GSocketConnection *connection,
+ GAsyncResult *result,
+ GError **error)
+{
+ _tp_implement_finish_void (connection,
+ tp_unix_connection_send_credentials_with_byte_async);
+}
+
#ifdef HAVE_GIO_UNIX
static GCredentials *
_tp_unix_connection_receive_credentials_with_byte (GUnixConnection *connection,
@@ -575,3 +658,131 @@ tp_unix_connection_receive_credentials_with_byte (GSocketConnection *connection,
return FALSE;
#endif
}
+
+typedef struct
+{
+ GCredentials *creds;
+ guchar byte;
+} ReceiveCredentialsWithByteData;
+
+static ReceiveCredentialsWithByteData *
+receive_credentials_with_byte_data_new (GCredentials *creds,
+ guchar byte)
+{
+ ReceiveCredentialsWithByteData *data;
+
+ data = g_slice_new0 (ReceiveCredentialsWithByteData);
+ data->creds = g_object_ref (creds);
+ data->byte = byte;
+
+ return data;
+}
+
+static void
+receive_credentials_with_byte_data_free (ReceiveCredentialsWithByteData *data)
+{
+ g_object_unref (data->creds);
+ g_slice_free (ReceiveCredentialsWithByteData, data);
+}
+
+static void
+receive_credentials_with_byte_async_thread (GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ guchar byte;
+ GCredentials *creds;
+ GError *error = NULL;
+
+ creds = tp_unix_connection_receive_credentials_with_byte (
+ (GSocketConnection *) object, &byte, cancellable, &error);
+ if (creds == NULL)
+ {
+ g_simple_async_result_take_error (res, error);
+ return;
+ }
+
+ g_simple_async_result_set_op_res_gpointer (res,
+ receive_credentials_with_byte_data_new (creds, byte),
+ (GDestroyNotify) receive_credentials_with_byte_data_free);
+
+ g_object_unref (creds);
+}
+
+/**
+ * tp_unix_connection_receive_credentials_with_byte_async:
+ * @connection: A #GUnixConnection.
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously receive credentials.
+ *
+ * For more details, see tp_unix_connection_receive_credentials_with_byte()
+ * which is the synchronous version of this call.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * tp_unix_connection_receive_credentials_with_byte_finish() to get the result
+ * of the operation.
+ *
+ * Since: 0.UNRELEASED
+ **/
+void
+tp_unix_connection_receive_credentials_with_byte_async (
+ GSocketConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res;
+
+ res = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
+ tp_unix_connection_receive_credentials_with_byte_async);
+
+ g_simple_async_result_run_in_thread (res,
+ receive_credentials_with_byte_async_thread, G_PRIORITY_DEFAULT,
+ cancellable);
+
+ g_object_unref (res);
+}
+
+/**
+ * tp_unix_connection_receive_credentials_with_byte_finish:
+ * @connection: A #GUnixConnection.
+ * @result: a #GAsyncResult.
+ * @byte: (out): if not %NULL, used to return the byte
+ * @error: a #GError, or %NULL
+ *
+ * Finishes an asynchronous receive credentials operation started with
+ * tp_unix_connection_receive_credentials_with_byte_async().
+ *
+ * Returns: (transfer full): a #GCredentials, or %NULL on error.
+ * Free the returned object with g_object_unref().
+ *
+ * Since: 0.UNRELEASED
+ **/
+GCredentials *
+tp_unix_connection_receive_credentials_with_byte_finish (
+ GSocketConnection *connection,
+ GAsyncResult *result,
+ guchar *byte,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = (GSimpleAsyncResult *) result;
+ ReceiveCredentialsWithByteData *data;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (connection),
+ tp_unix_connection_receive_credentials_with_byte_async),
+ NULL);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return NULL;
+
+ data = g_simple_async_result_get_op_res_gpointer (simple);
+
+ if (byte != NULL)
+ *byte = data->byte;
+
+ return g_object_ref (data->creds);
+}
diff --git a/telepathy-glib/gnio-util.h b/telepathy-glib/gnio-util.h
index 436012a17..a6580ab9c 100644
--- a/telepathy-glib/gnio-util.h
+++ b/telepathy-glib/gnio-util.h
@@ -41,12 +41,32 @@ gboolean tp_unix_connection_send_credentials_with_byte (
guchar byte,
GCancellable *cancellable,
GError **error);
+void tp_unix_connection_send_credentials_with_byte_async (
+ GSocketConnection *connection,
+ guchar byte,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean tp_unix_connection_send_credentials_with_byte_finish (
+ GSocketConnection *connection,
+ GAsyncResult *result,
+ GError **error);
GCredentials * tp_unix_connection_receive_credentials_with_byte (
GSocketConnection *connection,
guchar *byte,
GCancellable *cancellable,
GError **error);
+void tp_unix_connection_receive_credentials_with_byte_async (
+ GSocketConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GCredentials *tp_unix_connection_receive_credentials_with_byte_finish (
+ GSocketConnection *connection,
+ GAsyncResult *result,
+ guchar *byte,
+ GError **error);
G_END_DECLS
diff --git a/telepathy-glib/stream-tube-channel.c b/telepathy-glib/stream-tube-channel.c
index 3840cc165..45a778a80 100644
--- a/telepathy-glib/stream-tube-channel.c
+++ b/telepathy-glib/stream-tube-channel.c
@@ -616,6 +616,26 @@ new_local_connection_identified (TpStreamTubeChannel *self,
g_array_unref (features);
}
+#ifdef HAVE_GIO_UNIX
+static void
+send_credentials_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpStreamTubeChannel *self = user_data;
+ GError *error = NULL;
+
+ if (!tp_unix_connection_send_credentials_with_byte_finish (
+ (GSocketConnection *) source, result, &error))
+ {
+ DEBUG ("Failed to send credentials: %s", error->message);
+
+ operation_failed (self, error);
+ g_clear_error (&error);
+ }
+}
+#endif
+
static void
client_socket_connected (TpStreamTubeChannel *self)
{
@@ -631,20 +651,10 @@ client_socket_connected (TpStreamTubeChannel *self)
if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS)
{
guchar byte;
- GError *error = NULL;
byte = g_value_get_uchar (self->priv->access_control_param);
-
- /* FIXME: we should an async version of this API (bgo #629503) */
- if (!tp_unix_connection_send_credentials_with_byte (
- conn, byte, NULL, &error))
- {
- DEBUG ("Failed to send credentials: %s", error->message);
-
- operation_failed (self, error);
- g_clear_error (&error);
- return;
- }
+ tp_unix_connection_send_credentials_with_byte_async (conn, byte, NULL,
+ send_credentials_cb, self);
}
#endif
@@ -1263,47 +1273,12 @@ find_sig_for_conn (TpStreamTubeChannel *self,
}
static void
-service_incoming_cb (GSocketService *service,
+credentials_received (TpStreamTubeChannel *self,
GSocketConnection *conn,
- GObject *source_object,
- gpointer user_data)
+ guchar byte)
{
- TpStreamTubeChannel *self = user_data;
SigWaitingConn *sig;
ConnWaitingSig *c;
- guchar byte = 0;
-
- DEBUG ("New incoming connection");
-
-#ifdef HAVE_GIO_UNIX
- /* Check the credentials if needed */
- if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS)
- {
- GCredentials *creds;
- uid_t uid;
- GError *error = NULL;
-
- /* FIXME: we should an async version of this API (bgo #629503) */
- creds = tp_unix_connection_receive_credentials_with_byte (
- conn, &byte, NULL, &error);
- if (creds == NULL)
- {
- DEBUG ("Failed to receive credentials: %s", error->message);
-
- g_error_free (error);
- return;
- }
-
- uid = g_credentials_get_unix_user (creds, &error);
- g_object_unref (creds);
-
- if (uid != geteuid ())
- {
- DEBUG ("Wrong credentials received (user: %u)", uid);
- return;
- }
- }
-#endif
c = conn_waiting_sig_new (conn, byte);
@@ -1332,6 +1307,65 @@ service_incoming_cb (GSocketService *service,
conn_waiting_sig_free (c);
}
+#ifdef HAVE_GIO_UNIX
+static void
+receive_credentials_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpStreamTubeChannel *self = user_data;
+ GSocketConnection *conn = (GSocketConnection *) source;
+ GCredentials *creds;
+ guchar byte;
+ uid_t uid;
+ GError *error = NULL;
+
+ creds = tp_unix_connection_receive_credentials_with_byte_finish (conn, result,
+ &byte, &error);
+
+ if (creds == NULL)
+ {
+ DEBUG ("Failed to receive credentials: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ uid = g_credentials_get_unix_user (creds, &error);
+ if (uid != geteuid ())
+ {
+ DEBUG ("Wrong credentials received (user: %u)", uid);
+ return;
+ }
+
+ credentials_received (self, conn, byte);
+
+ g_object_unref (creds);
+}
+#endif
+
+static void
+service_incoming_cb (GSocketService *service,
+ GSocketConnection *conn,
+ GObject *source_object,
+ gpointer user_data)
+{
+ TpStreamTubeChannel *self = user_data;
+
+ DEBUG ("New incoming connection");
+
+#ifdef HAVE_GIO_UNIX
+ /* Check the credentials if needed */
+ if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS)
+ {
+ tp_unix_connection_receive_credentials_with_byte_async (conn, NULL,
+ receive_credentials_cb, self);
+ return;
+ }
+#endif
+
+ credentials_received (self, conn, 0);
+}
+
/**
* tp_stream_tube_channel_offer_async:
* @self: an outgoing #TpStreamTubeChannel
diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index 69b53c501..fc3bbe87a 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -1861,8 +1861,11 @@ _tp_determine_access_control_type (GHashTable *supported_sockets,
}
}
break;
+#else
+ case TP_SOCKET_ADDRESS_TYPE_UNIX:
+ case TP_SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX:
+ break;
#endif
-
case TP_SOCKET_ADDRESS_TYPE_IPV6:
case TP_SOCKET_ADDRESS_TYPE_IPV4:
{
diff --git a/tests/dbus/account-channel-request.c b/tests/dbus/account-channel-request.c
index aedb8d176..7f230b87f 100644
--- a/tests/dbus/account-channel-request.c
+++ b/tests/dbus/account-channel-request.c
@@ -141,9 +141,7 @@ teardown (Test *test,
tp_clear_object (&test->channel);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
tp_clear_object (&test->connection);
tp_clear_object (&test->base_connection);
diff --git a/tests/dbus/account-manager.c b/tests/dbus/account-manager.c
index 9ca56c54f..291daa9dc 100644
--- a/tests/dbus/account-manager.c
+++ b/tests/dbus/account-manager.c
@@ -12,9 +12,13 @@
#include <telepathy-glib/debug.h>
#include <telepathy-glib/defs.h>
+#include "tests/lib/simple-account.h"
#include "tests/lib/simple-account-manager.h"
#include "tests/lib/util.h"
+#define ACCOUNT1_PATH TP_ACCOUNT_OBJECT_PATH_BASE "badger/musher/account1"
+#define ACCOUNT2_PATH TP_ACCOUNT_OBJECT_PATH_BASE "badger/musher/account2"
+
typedef struct {
GFunc action;
gpointer user_data;
@@ -31,6 +35,12 @@ typedef struct {
guint timeout_id;
GQueue *script /* A list of GAsyncReadyCallback */;
+ TpTestsSimpleAccount *account1_service;
+ TpTestsSimpleAccount *account2_service;
+
+ TpAccount *account1;
+ TpAccount *account2;
+
GError *error /* initialized where needed */;
} Test;
@@ -147,6 +157,16 @@ setup_service (Test *test,
TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, NULL);
tp_dbus_daemon_register_object (test->dbus, TP_ACCOUNT_MANAGER_OBJECT_PATH,
test->service);
+
+ test->account1_service = tp_tests_object_new_static_class (
+ TP_TESTS_TYPE_SIMPLE_ACCOUNT, NULL);
+ tp_dbus_daemon_register_object (test->dbus, ACCOUNT1_PATH,
+ test->account1_service);
+
+ test->account2_service = tp_tests_object_new_static_class (
+ TP_TESTS_TYPE_SIMPLE_ACCOUNT, NULL);
+ tp_dbus_daemon_register_object (test->dbus, ACCOUNT2_PATH,
+ test->account2_service);
}
static void
@@ -185,6 +205,15 @@ teardown_service (Test *test,
&test->error));
tp_dbus_daemon_unregister_object (test->dbus, test->service);
g_object_unref (test->service);
+
+ tp_dbus_daemon_unregister_object (test->dbus, test->account1_service);
+ g_object_unref (test->account1_service);
+ tp_dbus_daemon_unregister_object (test->dbus, test->account2_service);
+ g_object_unref (test->account2_service);
+
+ g_clear_object (&test->account1);
+ g_clear_object (&test->account2);
+
test->service = NULL;
teardown (test, data);
}
@@ -522,6 +551,237 @@ test_ensure (Test *test,
script_append_action (test, assert_failed_action, NULL);
}
+/* tp_account_manager_get_most_available_presence() tests */
+static void
+create_tp_accounts (gpointer script_data,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ Test *test = (Test *) script_data;
+
+ test->account1 = tp_account_manager_ensure_account (test->am, ACCOUNT1_PATH);
+ g_object_ref (test->account1);
+
+ test->account2 = tp_account_manager_ensure_account (test->am, ACCOUNT2_PATH);
+ g_object_ref (test->account2);
+
+ script_continue (test);
+}
+
+static void
+test_prepare_most_available (Test *test,
+ gconstpointer data,
+ guint nb_accounts)
+{
+ GPtrArray *accounts;
+
+ accounts = g_ptr_array_new_with_free_func (g_free);
+
+ if (nb_accounts >= 1)
+ g_ptr_array_add (accounts, g_strdup (ACCOUNT1_PATH));
+
+ if (nb_accounts >= 2)
+ g_ptr_array_add (accounts, g_strdup (ACCOUNT2_PATH));
+
+ tp_tests_simple_account_manager_set_usable_accounts (test->service, accounts);
+ g_ptr_array_unref (accounts);
+
+ test_prepare (test, data);
+ script_append_action (test, manager_new_action, NULL);
+ script_append_action (test, prepare_action, NULL);
+ script_append_action (test, create_tp_accounts, NULL);
+}
+
+typedef struct
+{
+ TpConnectionPresenceType presence;
+ gchar *status;
+ gchar *message;
+} Presence;
+
+static Presence *
+presence_new (TpConnectionPresenceType presence,
+ const gchar *status,
+ const gchar *message)
+{
+ Presence *p = g_slice_new (Presence);
+
+ p->presence = presence;
+ p->status = g_strdup (status);
+ p->message = g_strdup (message);
+ return p;
+}
+
+static void
+presence_free (Presence *p)
+{
+ g_free (p->status);
+ g_free (p->message);
+ g_slice_free (Presence, p);
+}
+
+static void
+check_presence_action (gpointer script_data,
+ gpointer user_data)
+{
+ Test *test = script_data;
+ Presence *p = user_data;
+ TpConnectionPresenceType presence;
+ gchar *status, *message;
+
+ presence = tp_account_manager_get_most_available_presence (test->am,
+ &status, &message);
+
+ g_assert_cmpuint (presence, ==, p->presence);
+ g_assert_cmpstr (status, ==, p->status);
+ g_assert_cmpstr (message, ==, p->message);
+
+ presence_free (p);
+ g_free (status);
+ g_free (message);
+
+ script_continue (script_data);
+}
+
+static void
+account_presence_changed (TpAccount *account,
+ TpConnectionPresenceType presence,
+ const gchar *status,
+ const gchar *message,
+ Test *test)
+{
+ g_signal_handlers_disconnect_by_func (account,
+ account_presence_changed, test);
+
+ script_continue (test);
+}
+
+static void
+change_account_presence (Test *test,
+ TpTestsSimpleAccount *service,
+ TpAccount *account,
+ gpointer user_data)
+{
+ Presence *p = user_data;
+
+ tp_tests_simple_account_set_presence (service,
+ p->presence, p->status, p->message);
+
+ presence_free (p);
+
+ /* Wait for the presence change notification */
+ g_signal_connect (account, "presence-changed",
+ G_CALLBACK (account_presence_changed), test);
+}
+
+static void
+change_account1_presence (gpointer script_data,
+ gpointer user_data)
+{
+ Test *test = script_data;
+
+ change_account_presence (test, test->account1_service,
+ test->account1, user_data);
+}
+
+static void
+change_account2_presence (gpointer script_data,
+ gpointer user_data)
+{
+ Test *test = script_data;
+
+ change_account_presence (test, test->account2_service,
+ test->account2, user_data);
+}
+
+static void
+test_most_available_no_account (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ test_prepare_most_available (test, data, 0);
+
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", ""));
+}
+
+static void
+test_most_available_one_account (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ test_prepare_most_available (test, data, 1);
+
+ script_append_action (test, change_account1_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", ""));
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", ""));
+}
+
+static void
+test_most_available_two_account (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ test_prepare_most_available (test, data, 2);
+
+ script_append_action (test, change_account1_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", ""));
+ script_append_action (test, change_account2_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AWAY, "away", ""));
+
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", ""));
+
+ /* account1 disconnects */
+ script_append_action (test, change_account1_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", ""));
+
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AWAY, "away", ""));
+}
+
+static void
+test_most_available_one_unset (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ test_prepare_most_available (test, data, 1);
+
+ script_append_action (test, change_account1_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_UNSET, "unset", ""));
+
+ /* Pretend that we are available */
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", ""));
+}
+
+static void
+test_most_available_two_unset (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ test_prepare_most_available (test, data, 2);
+
+ script_append_action (test, change_account1_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_UNSET, "unset", ""));
+ script_append_action (test, change_account2_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AWAY, "away", ""));
+
+ /* Use account2 away presence */
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AWAY, "away", ""));
+
+ /* account2 disconnects */
+ script_append_action (test, change_account2_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", ""));
+
+ /* Pretent that we are available */
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available", ""));
+
+ /* account2 reconnects with busy */
+ script_append_action (test, change_account2_presence,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_BUSY, "busy", ""));
+
+ script_append_action (test, check_presence_action,
+ presence_new (TP_CONNECTION_PRESENCE_TYPE_BUSY, "busy", ""));
+}
+
int
main (int argc,
char **argv)
@@ -545,5 +805,16 @@ main (int argc,
g_test_add ("/am/ensure", Test, NULL, setup_service,
test_ensure, teardown_service);
+
+ g_test_add ("/am/most-available/no-account", Test, NULL, setup_service,
+ test_most_available_no_account, teardown_service);
+ g_test_add ("/am/most-available/one-account", Test, NULL, setup_service,
+ test_most_available_one_account, teardown_service);
+ g_test_add ("/am/most-available/two-account", Test, NULL, setup_service,
+ test_most_available_two_account, teardown_service);
+ g_test_add ("/am/most-available/one-unset", Test, NULL, setup_service,
+ test_most_available_one_unset, teardown_service);
+ g_test_add ("/am/most-available/two-unset", Test, NULL, setup_service,
+ test_most_available_two_unset, teardown_service);
return g_test_run ();
}
diff --git a/tests/dbus/base-client.c b/tests/dbus/base-client.c
index 93674d62a..f5995efe0 100644
--- a/tests/dbus/base-client.c
+++ b/tests/dbus/base-client.c
@@ -261,9 +261,7 @@ teardown (Test *test,
tp_clear_object (&test->cdo_service);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/call-example.c b/tests/dbus/call-example.c
index eb4692a5f..259f50050 100644
--- a/tests/dbus/call-example.c
+++ b/tests/dbus/call-example.c
@@ -1040,8 +1040,7 @@ static void
teardown (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
- tp_cli_connection_run_disconnect (test->conn, -1, &test->error, NULL);
- g_assert_no_error (test->error);
+ tp_tests_connection_assert_disconnect_succeeds (test->conn);
g_array_unref (test->audio_request);
g_array_unref (test->video_request);
diff --git a/tests/dbus/channel-dispatch-operation.c b/tests/dbus/channel-dispatch-operation.c
index db4810819..d5f57074f 100644
--- a/tests/dbus/channel-dispatch-operation.c
+++ b/tests/dbus/channel-dispatch-operation.c
@@ -217,8 +217,7 @@ teardown_services (Test *test,
if (test->text_chan_service_2 != NULL)
g_object_unref (test->text_chan_service_2);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c
index 86370f2c6..81550fe2b 100644
--- a/tests/dbus/channel-introspect.c
+++ b/tests/dbus/channel-introspect.c
@@ -464,8 +464,7 @@ main (int argc,
g_assert_cmpint (tp_proxy_is_prepared (chan, TP_CHANNEL_FEATURE_CHAT_STATES),
==, FALSE);
- MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
was_ready = FALSE;
diff --git a/tests/dbus/channel-manager-request-properties.c b/tests/dbus/channel-manager-request-properties.c
index 5cea63871..854c3d98e 100644
--- a/tests/dbus/channel-manager-request-properties.c
+++ b/tests/dbus/channel-manager-request-properties.c
@@ -86,8 +86,7 @@ static void
teardown (Test *test,
gconstpointer data)
{
- g_assert (tp_cli_connection_run_disconnect (test->conn, -1, &test->error, NULL));
- g_assert_no_error (test->error);
+ tp_tests_connection_assert_disconnect_succeeds (test->conn);
g_object_unref (test->service_conn);
test->service_conn = NULL;
diff --git a/tests/dbus/channel-request.c b/tests/dbus/channel-request.c
index f95fbb6ee..939cad854 100644
--- a/tests/dbus/channel-request.c
+++ b/tests/dbus/channel-request.c
@@ -107,9 +107,7 @@ static void
teardown (Test *test,
gconstpointer data)
{
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/channel.c b/tests/dbus/channel.c
index ae520ae88..b9091a6e7 100644
--- a/tests/dbus/channel.c
+++ b/tests/dbus/channel.c
@@ -147,9 +147,7 @@ teardown (Test *test,
tp_clear_object (&test->chan_contact_service);
tp_clear_object (&test->chan_room_service);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/cli-group.c b/tests/dbus/cli-group.c
index da38e316a..9324ea103 100644
--- a/tests/dbus/cli-group.c
+++ b/tests/dbus/cli-group.c
@@ -422,8 +422,7 @@ main (int argc,
check_removed_unknown_error_in_invalidated ();
check_removed_known_error_in_invalidated ();
- MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
/* clean up */
diff --git a/tests/dbus/client-channel-factory.c b/tests/dbus/client-channel-factory.c
index 9919d3446..d33cab761 100644
--- a/tests/dbus/client-channel-factory.c
+++ b/tests/dbus/client-channel-factory.c
@@ -100,9 +100,7 @@ teardown (Test *test,
tp_clear_object (&test->tube_chan_service);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/cm-message.c b/tests/dbus/cm-message.c
index cf3d7dd08..ba63231de 100644
--- a/tests/dbus/cm-message.c
+++ b/tests/dbus/cm-message.c
@@ -35,9 +35,7 @@ static void
teardown (Test *test,
gconstpointer data)
{
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
}
diff --git a/tests/dbus/connection-aliasing.c b/tests/dbus/connection-aliasing.c
index 55f1b1f14..7501d41ac 100644
--- a/tests/dbus/connection-aliasing.c
+++ b/tests/dbus/connection-aliasing.c
@@ -99,7 +99,6 @@ teardown (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
TpConnection *conn;
- gboolean ok;
GError *error = NULL;
g_clear_error (&test->error);
@@ -112,9 +111,7 @@ teardown (Test *test,
g_assert (conn != NULL);
g_assert_no_error (error);
- ok = tp_cli_connection_run_disconnect (conn, -1, &error, NULL);
- g_assert (ok);
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_assert (!tp_connection_run_until_ready (conn, FALSE, &error, NULL));
g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED);
diff --git a/tests/dbus/connection-balance.c b/tests/dbus/connection-balance.c
index f074bf010..aaf41eb96 100644
--- a/tests/dbus/connection-balance.c
+++ b/tests/dbus/connection-balance.c
@@ -248,7 +248,6 @@ teardown (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
TpConnection *conn;
- gboolean ok;
GError *error = NULL;
g_clear_error (&test->error);
@@ -261,9 +260,7 @@ teardown (Test *test,
g_assert (conn != NULL);
g_assert_no_error (error);
- ok = tp_cli_connection_run_disconnect (conn, -1, &error, NULL);
- g_assert (ok);
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_assert (!tp_connection_run_until_ready (conn, FALSE, &error, NULL));
g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED);
diff --git a/tests/dbus/connection-bug-18845.c b/tests/dbus/connection-bug-18845.c
index 037178835..c589fe17c 100644
--- a/tests/dbus/connection-bug-18845.c
+++ b/tests/dbus/connection-bug-18845.c
@@ -108,9 +108,7 @@ main (int argc,
MYASSERT (tp_connection_run_until_ready (conn, TRUE, &error, NULL), "");
g_assert_no_error (error);
- MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
- g_assert_no_error (error);
-
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_object_unref (conn);
service_conn_as_base = NULL;
diff --git a/tests/dbus/connection-error.c b/tests/dbus/connection-error.c
index cfe21a48b..be2a1b242 100644
--- a/tests/dbus/connection-error.c
+++ b/tests/dbus/connection-error.c
@@ -159,7 +159,13 @@ static void
teardown (Test *test,
gconstpointer nil G_GNUC_UNUSED)
{
- tp_cli_connection_run_disconnect (test->conn, -1, NULL, NULL);
+ GAsyncResult *result = NULL;
+
+ tp_connection_disconnect_async (test->conn, tp_tests_result_ready_cb,
+ &result);
+ tp_tests_run_until_result (&result);
+ /* Ignore success/failure: it might already have gone */
+ g_object_unref (result);
test->service_conn_as_base = NULL;
g_object_unref (test->service_conn);
diff --git a/tests/dbus/connection-handles.c b/tests/dbus/connection-handles.c
index 6f5f97d56..1bcfbdaca 100644
--- a/tests/dbus/connection-handles.c
+++ b/tests/dbus/connection-handles.c
@@ -178,9 +178,7 @@ main (int argc,
/* Teardown */
- MYASSERT (tp_cli_connection_run_disconnect (client_conn, -1, &error, NULL),
- "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (client_conn);
service_conn_as_base = NULL;
g_object_unref (service_conn);
diff --git a/tests/dbus/connection-interests.c b/tests/dbus/connection-interests.c
index d9fe2df78..114de4e5d 100644
--- a/tests/dbus/connection-interests.c
+++ b/tests/dbus/connection-interests.c
@@ -219,7 +219,6 @@ teardown (Test *test,
gconstpointer data)
{
TpConnection *conn;
- gboolean ok;
GError *error = NULL;
if (test->conn != NULL)
@@ -234,9 +233,7 @@ teardown (Test *test,
g_assert (conn != NULL);
g_assert_no_error (error);
- ok = tp_cli_connection_run_disconnect (conn, -1, &error, NULL);
- g_assert (ok);
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_assert (!tp_connection_run_until_ready (conn, FALSE, &error, NULL));
g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED);
diff --git a/tests/dbus/connection.c b/tests/dbus/connection.c
index cdf5d9ddb..e9af99f7f 100644
--- a/tests/dbus/connection.c
+++ b/tests/dbus/connection.c
@@ -82,7 +82,6 @@ teardown (Test *test,
gconstpointer data)
{
TpConnection *conn;
- gboolean ok;
GError *error = NULL;
if (test->conn != NULL)
@@ -97,9 +96,7 @@ teardown (Test *test,
g_assert (conn != NULL);
g_assert_no_error (error);
- ok = tp_cli_connection_run_disconnect (conn, -1, &error, NULL);
- g_assert (ok);
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_assert (!tp_connection_run_until_ready (conn, FALSE, &error, NULL));
g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED);
diff --git a/tests/dbus/contact-list-client.c b/tests/dbus/contact-list-client.c
index f9eeb6c1a..dcbe21226 100644
--- a/tests/dbus/contact-list-client.c
+++ b/tests/dbus/contact-list-client.c
@@ -87,9 +87,7 @@ teardown (Test *test,
g_main_loop_unref (test->mainloop);
test->mainloop = NULL;
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/contact-lists.c b/tests/dbus/contact-lists.c
index 80c1a8b25..f58436a02 100644
--- a/tests/dbus/contact-lists.c
+++ b/tests/dbus/contact-lists.c
@@ -381,7 +381,6 @@ teardown (Test *test,
gconstpointer data)
{
TpConnection *conn;
- gboolean ok;
GError *error = NULL;
g_array_unref (test->arr);
@@ -402,9 +401,7 @@ teardown (Test *test,
&error);
g_assert (conn != NULL);
g_assert_no_error (error);
- ok = tp_cli_connection_run_disconnect (conn, -1, &error, NULL);
- g_assert (ok);
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_assert (!tp_connection_run_until_ready (conn, FALSE, &error, NULL));
g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED);
g_clear_error (&error);
@@ -1790,8 +1787,6 @@ static void
test_request_blocked_contacts_pre_connect (Test *test,
gconstpointer nil G_GNUC_UNUSED)
{
- gboolean ok;
-
/* This verifies that calling RequestBlockedContacts()
* before Connect(), when Connect() ultimately succeeds, returns correctly.
*/
@@ -1801,8 +1796,7 @@ test_request_blocked_contacts_pre_connect (Test *test,
tp_cli_connection_call_connect (test->conn, -1, NULL, NULL, NULL, NULL);
g_main_loop_run (test->main_loop);
- ok = tp_cli_connection_run_disconnect (test->conn, -1, NULL, NULL);
- g_assert (ok);
+ tp_tests_connection_assert_disconnect_succeeds (test->conn);
}
static void
diff --git a/tests/dbus/contacts-bug-19101.c b/tests/dbus/contacts-bug-19101.c
index a9db27c78..67a36c083 100644
--- a/tests/dbus/contacts-bug-19101.c
+++ b/tests/dbus/contacts-bug-19101.c
@@ -177,9 +177,7 @@ main (int argc,
/* Teardown */
- MYASSERT (tp_cli_connection_run_disconnect (client_conn, -1, &error, NULL),
- "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (client_conn);
g_object_unref (client_conn);
service_conn_as_base = NULL;
diff --git a/tests/dbus/contacts-mixin.c b/tests/dbus/contacts-mixin.c
index 8ab5f229e..29193166b 100644
--- a/tests/dbus/contacts-mixin.c
+++ b/tests/dbus/contacts-mixin.c
@@ -206,9 +206,7 @@ main (int argc,
/* Teardown */
- MYASSERT (tp_cli_connection_run_disconnect (client_conn, -1, &error, NULL),
- "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (client_conn);
service_conn_as_base = NULL;
g_object_unref (service_conn);
diff --git a/tests/dbus/contacts.c b/tests/dbus/contacts.c
index 85cdc2594..e122914ab 100644
--- a/tests/dbus/contacts.c
+++ b/tests/dbus/contacts.c
@@ -2599,15 +2599,8 @@ static void
teardown (Fixture *f,
gconstpointer unused G_GNUC_UNUSED)
{
- gboolean ok;
- GError *error = NULL;
-
if (f->client_conn != NULL)
- {
- ok = tp_cli_connection_run_disconnect (f->client_conn, -1, &error, NULL);
- g_assert_no_error (error);
- g_assert (ok);
- }
+ tp_tests_connection_assert_disconnect_succeeds (f->client_conn);
tp_clear_object (&f->client_conn);
f->service_repo = NULL;
diff --git a/tests/dbus/dbus-tube.c b/tests/dbus/dbus-tube.c
index 0c684eef8..8a88b55ad 100644
--- a/tests/dbus/dbus-tube.c
+++ b/tests/dbus/dbus-tube.c
@@ -63,9 +63,7 @@ teardown (Test *test,
tp_clear_object (&test->tube_chan_service);
tp_clear_object (&test->tube);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
}
diff --git a/tests/dbus/file-transfer-channel.c b/tests/dbus/file-transfer-channel.c
index ac938f9cc..c5f1aa1fd 100644
--- a/tests/dbus/file-transfer-channel.c
+++ b/tests/dbus/file-transfer-channel.c
@@ -256,9 +256,7 @@ teardown (Test *test,
tp_clear_object (&test->chan_service);
tp_clear_object (&test->cm_stream);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/group-mixin.c b/tests/dbus/group-mixin.c
index 00dc979ce..8f86db123 100644
--- a/tests/dbus/group-mixin.c
+++ b/tests/dbus/group-mixin.c
@@ -554,8 +554,7 @@ main (int argc,
test_group_mixin ();
- MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
/* clean up */
diff --git a/tests/dbus/message-mixin.c b/tests/dbus/message-mixin.c
index 305007a35..4338b3fbb 100644
--- a/tests/dbus/message-mixin.c
+++ b/tests/dbus/message-mixin.c
@@ -766,8 +766,7 @@ main (int argc,
g_print ("\n\n==== End of tests ====\n");
- MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
g_object_unref (chan);
g_object_unref (conn);
diff --git a/tests/dbus/proxy-preparation.c b/tests/dbus/proxy-preparation.c
index 4e05e5f4f..caad5eb1d 100644
--- a/tests/dbus/proxy-preparation.c
+++ b/tests/dbus/proxy-preparation.c
@@ -52,9 +52,8 @@ setup (Test *test,
static void
disconnect_and_destroy_conn (Test *test)
{
- tp_cli_connection_run_disconnect (TP_CONNECTION (test->my_conn), -1,
- &test->error, NULL);
- g_assert_no_error (test->error);
+ tp_tests_connection_assert_disconnect_succeeds (
+ TP_CONNECTION (test->my_conn));
tp_clear_object (&test->connection);
tp_clear_object (&test->base_connection);
diff --git a/tests/dbus/self-handle.c b/tests/dbus/self-handle.c
index b9f145748..89fedcdc2 100644
--- a/tests/dbus/self-handle.c
+++ b/tests/dbus/self-handle.c
@@ -219,17 +219,10 @@ static void
teardown (Fixture *f,
gconstpointer unused G_GNUC_UNUSED)
{
- gboolean ok;
-
g_clear_error (&f->error);
if (f->client_conn != NULL)
- {
- ok = tp_cli_connection_run_disconnect (f->client_conn, -1, &f->error,
- NULL);
- g_assert_no_error (f->error);
- g_assert (ok);
- }
+ tp_tests_connection_assert_disconnect_succeeds (f->client_conn);
tp_clear_object (&f->result);
tp_clear_object (&f->client_conn);
diff --git a/tests/dbus/self-presence.c b/tests/dbus/self-presence.c
index 8c89e25fb..4d5f07db0 100644
--- a/tests/dbus/self-presence.c
+++ b/tests/dbus/self-presence.c
@@ -188,9 +188,7 @@ main (int argc,
/* Teardown */
- MYASSERT (tp_cli_connection_run_disconnect (client_conn, -1, &error, NULL),
- "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (client_conn);
g_object_unref (client_conn);
service_conn_as_base = NULL;
diff --git a/tests/dbus/simple-approver.c b/tests/dbus/simple-approver.c
index d9465c943..aa0d83cd5 100644
--- a/tests/dbus/simple-approver.c
+++ b/tests/dbus/simple-approver.c
@@ -159,9 +159,7 @@ teardown (Test *test,
g_object_unref (test->cdo_service);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
}
diff --git a/tests/dbus/simple-handler.c b/tests/dbus/simple-handler.c
index fc10933d7..59a8eb8b5 100644
--- a/tests/dbus/simple-handler.c
+++ b/tests/dbus/simple-handler.c
@@ -151,9 +151,7 @@ teardown (Test *test,
g_object_unref (test->text_chan_service);
g_object_unref (test->text_chan);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
}
diff --git a/tests/dbus/simple-observer.c b/tests/dbus/simple-observer.c
index 7e64dfaf2..c82baf556 100644
--- a/tests/dbus/simple-observer.c
+++ b/tests/dbus/simple-observer.c
@@ -127,9 +127,7 @@ teardown (Test *test,
g_object_unref (test->text_chan_service);
g_object_unref (test->text_chan);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
}
diff --git a/tests/dbus/stream-tube.c b/tests/dbus/stream-tube.c
index 79878ba5e..7fb222be7 100644
--- a/tests/dbus/stream-tube.c
+++ b/tests/dbus/stream-tube.c
@@ -107,9 +107,7 @@ teardown (Test *test,
tp_clear_object (&test->tube_conn);
tp_clear_object (&test->cm_stream);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
}
@@ -728,6 +726,39 @@ run_tube_test (const char *test_path,
}
static void
+wait_tube_conn (Test *test,
+ GIOStream **alice_stream,
+ GIOStream **bob_stream)
+{
+ GSocketConnection *conn;
+ TpContact *contact;
+
+ test->wait = 1;
+ g_main_loop_run (test->mainloop);
+ g_assert (test->tube_conn != NULL);
+
+ conn = tp_stream_tube_connection_get_socket_connection (test->tube_conn);
+ contact = tp_stream_tube_connection_get_contact (test->tube_conn);
+
+ if (!tp_strdiff (tp_contact_get_identifier (contact), "bob"))
+ {
+ g_assert (*bob_stream == NULL);
+
+ *bob_stream = g_object_ref (conn);
+ }
+ else if (!tp_strdiff (tp_contact_get_identifier (contact), "alice"))
+ {
+ g_assert (*alice_stream == NULL);
+
+ *alice_stream = g_object_ref (conn);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+}
+
+static void
test_offer_race (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
@@ -738,9 +769,7 @@ test_offer_race (Test *test,
GSocketClient *client;
TpHandle alice_handle, bob_handle;
GIOStream *alice_cm_stream, *bob_cm_stream;
- GIOStream *alice_stream, *bob_stream;
- GSocketConnection *conn;
- TpContact *contact;
+ GIOStream *alice_stream = NULL, *bob_stream = NULL;
if (contexts[i].address_type == TP_SOCKET_ADDRESS_TYPE_UNIX &&
contexts[i].access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS &&
@@ -821,27 +850,12 @@ test_offer_race (Test *test,
tp_tests_stream_tube_channel_peer_connected (test->tube_chan_service,
alice_cm_stream, alice_handle);
- /* Bob connection is identified */
- test->wait = 1;
- g_main_loop_run (test->mainloop);
- g_assert (test->tube_conn != NULL);
-
- conn = tp_stream_tube_connection_get_socket_connection (test->tube_conn);
- bob_stream = g_object_ref (conn);
- contact = tp_stream_tube_connection_get_contact (test->tube_conn);
-
- g_assert_cmpstr (tp_contact_get_identifier (contact), ==, "bob");
-
- /* Alice connection is identified */
- test->wait = 1;
- g_main_loop_run (test->mainloop);
- g_assert (test->tube_conn != NULL);
-
- conn = tp_stream_tube_connection_get_socket_connection (test->tube_conn);
- alice_stream = g_object_ref (conn);
- contact = tp_stream_tube_connection_get_contact (test->tube_conn);
+ /* Both connections are received and identified */
+ wait_tube_conn (test, &alice_stream, &bob_stream);
+ wait_tube_conn (test, &alice_stream, &bob_stream);
- g_assert_cmpstr (tp_contact_get_identifier (contact), ==, "alice");
+ g_assert (alice_stream != NULL);
+ g_assert (bob_stream != NULL);
/* Check that the streams have been mapped to the right contact */
use_tube_with_streams (test, alice_stream, alice_cm_stream);
diff --git a/tests/dbus/text-channel.c b/tests/dbus/text-channel.c
index 8c74fa731..673cff430 100644
--- a/tests/dbus/text-channel.c
+++ b/tests/dbus/text-channel.c
@@ -136,9 +136,7 @@ teardown (Test *test,
tp_clear_object (&test->chan_service);
tp_clear_object (&test->sms_chan_service);
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
+ tp_tests_connection_assert_disconnect_succeeds (test->connection);
g_object_unref (test->connection);
g_object_unref (test->base_connection);
diff --git a/tests/dbus/text-respawn.c b/tests/dbus/text-respawn.c
index 4a9217621..b847cf4ba 100644
--- a/tests/dbus/text-respawn.c
+++ b/tests/dbus/text-respawn.c
@@ -313,8 +313,7 @@ main (int argc,
g_print ("\n\n==== End of tests ====\n");
- MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
- g_assert_no_error (error);
+ tp_tests_connection_assert_disconnect_succeeds (conn);
tp_handle_unref (contact_repo, handle);
g_object_unref (chan);
diff --git a/tests/lib/dbus-tube-chan.c b/tests/lib/dbus-tube-chan.c
index 1e752daa3..fa9acfc8c 100644
--- a/tests/lib/dbus-tube-chan.c
+++ b/tests/lib/dbus-tube-chan.c
@@ -14,10 +14,6 @@
#include <telepathy-glib/channel-iface.h>
#include <telepathy-glib/svc-channel.h>
#include <telepathy-glib/gnio-util.h>
-
-#include <gio/gunixsocketaddress.h>
-#include <gio/gunixconnection.h>
-
#include <glib/gstdio.h>
enum
diff --git a/tests/lib/file-transfer-chan.c b/tests/lib/file-transfer-chan.c
index 3306b6be8..057db4334 100644
--- a/tests/lib/file-transfer-chan.c
+++ b/tests/lib/file-transfer-chan.c
@@ -18,9 +18,6 @@
#include <telepathy-glib/svc-channel.h>
#include <telepathy-glib/gnio-util.h>
-#include <gio/gunixsocketaddress.h>
-#include <gio/gunixconnection.h>
-
#include <glib/gstdio.h>
static void file_transfer_iface_init (gpointer iface, gpointer data);
diff --git a/tests/lib/simple-account-manager.c b/tests/lib/simple-account-manager.c
index f34c95152..3b960d98a 100644
--- a/tests/lib/simple-account-manager.c
+++ b/tests/lib/simple-account-manager.c
@@ -15,6 +15,7 @@
#include <telepathy-glib/interfaces.h>
#include <telepathy-glib/svc-generic.h>
#include <telepathy-glib/svc-account-manager.h>
+#include <telepathy-glib/util.h>
static void account_manager_iface_init (gpointer, gpointer);
@@ -49,7 +50,7 @@ enum
struct _TpTestsSimpleAccountManagerPrivate
{
- int dummy;
+ GPtrArray *usable_accounts;
};
static void
@@ -80,8 +81,15 @@ account_manager_iface_init (gpointer klass,
static void
tp_tests_simple_account_manager_init (TpTestsSimpleAccountManager *self)
{
+ guint i;
+
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, TpTestsSimpleAccountManagerPrivate);
+
+ self->priv->usable_accounts = g_ptr_array_new_with_free_func (g_free);
+
+ for (i = 0; USABLE_ACCOUNTS[i] != NULL; i++)
+ g_ptr_array_add (self->priv->usable_accounts, g_strdup (USABLE_ACCOUNTS[i]));
}
static void
@@ -90,6 +98,7 @@ tp_tests_simple_account_manager_get_property (GObject *object,
GValue *value,
GParamSpec *spec)
{
+ TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object);
GPtrArray *accounts;
guint i = 0;
@@ -99,12 +108,7 @@ tp_tests_simple_account_manager_get_property (GObject *object,
break;
case PROP_USABLE_ACCOUNTS:
- accounts = g_ptr_array_new ();
-
- for (i=0; USABLE_ACCOUNTS[i] != NULL; i++)
- g_ptr_array_add (accounts, g_strdup (USABLE_ACCOUNTS[i]));
-
- g_value_take_boxed (value, accounts);
+ g_value_set_boxed (value, self->priv->usable_accounts);
break;
case PROP_UNUSABLE_ACCOUNTS:
@@ -122,6 +126,17 @@ tp_tests_simple_account_manager_get_property (GObject *object,
}
}
+static void
+tp_tests_simple_account_manager_dispose (GObject *object)
+{
+ TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object);
+
+ tp_clear_pointer (&self->priv->usable_accounts, g_ptr_array_unref);
+
+ G_OBJECT_CLASS (tp_tests_simple_account_manager_parent_class)->dispose (
+ object);
+}
+
/**
* This class currently only provides the minimum for
* tp_account_manager_prepare to succeed. This turns out to be only a working
@@ -157,6 +172,7 @@ tp_tests_simple_account_manager_class_init (
g_type_class_add_private (klass, sizeof (TpTestsSimpleAccountManagerPrivate));
object_class->get_property = tp_tests_simple_account_manager_get_property;
+ object_class->dispose = tp_tests_simple_account_manager_dispose;
param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
"In this case we only implement AccountManager, so none.",
@@ -178,3 +194,13 @@ tp_tests_simple_account_manager_class_init (
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (TpTestsSimpleAccountManagerClass, dbus_props_class));
}
+
+void
+tp_tests_simple_account_manager_set_usable_accounts (
+ TpTestsSimpleAccountManager *self,
+ GPtrArray *accounts)
+{
+ tp_clear_pointer (&self->priv->usable_accounts, g_ptr_array_unref);
+
+ self->priv->usable_accounts = g_ptr_array_ref (accounts);
+}
diff --git a/tests/lib/simple-account-manager.h b/tests/lib/simple-account-manager.h
index b4f787c18..32f9aeda9 100644
--- a/tests/lib/simple-account-manager.h
+++ b/tests/lib/simple-account-manager.h
@@ -52,6 +52,9 @@ GType tp_tests_simple_account_manager_get_type (void);
(G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, \
TpTestsSimpleAccountManagerClass))
+void tp_tests_simple_account_manager_set_usable_accounts (
+ TpTestsSimpleAccountManager *self,
+ GPtrArray *accounts);
G_END_DECLS
diff --git a/tests/lib/simple-account.c b/tests/lib/simple-account.c
index c6cee4e57..2d44de0bc 100644
--- a/tests/lib/simple-account.c
+++ b/tests/lib/simple-account.c
@@ -68,7 +68,9 @@ enum
struct _TpTestsSimpleAccountPrivate
{
- gpointer unused;
+ TpConnectionPresenceType presence;
+ gchar *presence_status;
+ gchar *presence_msg;
};
static void
@@ -87,6 +89,10 @@ tp_tests_simple_account_init (TpTestsSimpleAccount *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TP_TESTS_TYPE_SIMPLE_ACCOUNT,
TpTestsSimpleAccountPrivate);
+
+ self->priv->presence = TP_CONNECTION_PRESENCE_TYPE_AWAY;
+ self->priv->presence_status = g_strdup ("currently-away");
+ self->priv->presence_msg = g_strdup ("this is my CurrentPresence");
}
/* you may have noticed this is not entirely realistic */
@@ -98,6 +104,7 @@ tp_tests_simple_account_get_property (GObject *object,
GValue *value,
GParamSpec *spec)
{
+ TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object);
GValue identifier = { 0, };
g_value_init (&identifier, G_TYPE_STRING);
@@ -146,9 +153,9 @@ tp_tests_simple_account_get_property (GObject *object,
break;
case PROP_CURRENT_PRESENCE:
g_value_take_boxed (value, tp_value_array_build (3,
- G_TYPE_UINT, TP_CONNECTION_PRESENCE_TYPE_AWAY,
- G_TYPE_STRING, "currently-away",
- G_TYPE_STRING, "this is my CurrentPresence",
+ G_TYPE_UINT, self->priv->presence,
+ G_TYPE_STRING, self->priv->presence_status,
+ G_TYPE_STRING, self->priv->presence_msg,
G_TYPE_INVALID));
break;
case PROP_REQUESTED_PRESENCE:
@@ -193,6 +200,17 @@ tp_tests_simple_account_get_property (GObject *object,
g_value_unset (&identifier);
}
+static void
+tp_tests_simple_account_finalize (GObject *object)
+{
+ TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object);
+
+ g_free (self->priv->presence_status);
+ g_free (self->priv->presence_msg);
+
+ G_OBJECT_CLASS (tp_tests_simple_account_parent_class)->finalize (object);
+}
+
/**
* This class currently only provides the minimum for
* tp_account_prepare to succeed. This turns out to be only a working
@@ -260,6 +278,7 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass)
g_type_class_add_private (klass, sizeof (TpTestsSimpleAccountPrivate));
object_class->get_property = tp_tests_simple_account_get_property;
+ object_class->finalize = tp_tests_simple_account_finalize;
param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
"In this case we only implement Account, so none.",
@@ -403,3 +422,30 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass)
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (TpTestsSimpleAccountClass, dbus_props_class));
}
+
+void
+tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self,
+ TpConnectionPresenceType presence,
+ const gchar *status,
+ const gchar *message)
+{
+ GHashTable *props;
+ GValueArray *v;
+
+ g_free (self->priv->presence_status);
+ g_free (self->priv->presence_msg);
+
+ self->priv->presence = presence;
+ self->priv->presence_status = g_strdup (status);
+ self->priv->presence_msg = g_strdup (message);
+
+ g_object_get (self, "current-presence", &v, NULL);
+
+ props = tp_asv_new (
+ "CurrentPresence", TP_STRUCT_TYPE_PRESENCE, v,
+ NULL);
+
+ tp_svc_account_emit_account_property_changed (self, props);
+
+ g_boxed_free (TP_STRUCT_TYPE_PRESENCE, v);
+}
diff --git a/tests/lib/simple-account.h b/tests/lib/simple-account.h
index 7af263d61..40f708c9c 100644
--- a/tests/lib/simple-account.h
+++ b/tests/lib/simple-account.h
@@ -12,8 +12,9 @@
#define __TP_TESTS_SIMPLE_ACCOUNT_H__
#include <glib-object.h>
-#include <telepathy-glib/dbus-properties-mixin.h>
+#include <telepathy-glib/connection.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
G_BEGIN_DECLS
@@ -51,6 +52,11 @@ GType tp_tests_simple_account_get_type (void);
(G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT, \
TpTestsSimpleAccountClass))
+void tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self,
+ TpConnectionPresenceType presence,
+ const gchar *status,
+ const gchar *message);
+
G_END_DECLS
#endif /* #ifndef __TP_TESTS_SIMPLE_ACCOUNT_H__ */
diff --git a/tests/lib/util.c b/tests/lib/util.c
index 648be0293..f758b4f33 100644
--- a/tests/lib/util.c
+++ b/tests/lib/util.c
@@ -12,6 +12,8 @@
#include "tests/lib/util.h"
+#include <telepathy-glib/connection.h>
+
#include <glib/gstdio.h>
#include <string.h>
@@ -453,3 +455,19 @@ _tp_create_local_socket (TpSocketAddressType address_type,
g_object_unref (effective_address);
return address_gvalue;
}
+
+void
+tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection)
+{
+ GAsyncResult *result = NULL;
+ GError *error = NULL;
+ gboolean ok;
+
+ tp_connection_disconnect_async (connection, tp_tests_result_ready_cb,
+ &result);
+ tp_tests_run_until_result (&result);
+ ok = tp_connection_disconnect_finish (connection, result, &error);
+ g_assert_no_error (error);
+ g_assert (ok);
+ g_object_unref (result);
+}
diff --git a/tests/lib/util.h b/tests/lib/util.h
index af033b844..d0428ac87 100644
--- a/tests/lib/util.h
+++ b/tests/lib/util.h
@@ -71,4 +71,6 @@ GValue *_tp_create_local_socket (TpSocketAddressType address_type,
void _tp_destroy_socket_control_list (gpointer data);
+void tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection);
+
#endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */