diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-03-25 10:32:46 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-03-25 14:56:08 +0000 |
commit | 7f112ac3d429275ec6f62cbfe8b3cf7c76a927ca (patch) | |
tree | 712ea8f306db7d7e84e5226b586c0f872a474ee4 | |
parent | df15a2e6ece1afa76425fd1186710afd567ff321 (diff) |
tests/lib/telepathy/contactlist: remove unused files
Xavier imported these in the initial port to telepathy-glib-1
(commit af26adde) but they're unused. It's easier to keep up with
telepathy-glib-1 snapshots if we limit what we need to update.
Reviewed-by: Xavier Claessens
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=708871
33 files changed, 0 insertions, 6366 deletions
diff --git a/tests/lib/telepathy/contactlist/broken-client-types-conn.c b/tests/lib/telepathy/contactlist/broken-client-types-conn.c deleted file mode 100644 index 18298693..00000000 --- a/tests/lib/telepathy/contactlist/broken-client-types-conn.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * broken-client-types-conn.c - a connection with a broken client - * types implementation which inexplicably returns presence information! - * - * Copyright © 2011 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "broken-client-types-conn.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -G_DEFINE_TYPE_WITH_CODE (TpTestsBrokenClientTypesConnection, - tp_tests_broken_client_types_connection, - TP_TESTS_TYPE_CONTACTS_CONNECTION, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CLIENT_TYPES1, - NULL); - ); - -static void -tp_tests_broken_client_types_connection_init ( - TpTestsBrokenClientTypesConnection *self) -{ -} - -static void -broken_fill_client_types ( - GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - guint i; - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - GType type = G_TYPE_VALUE_ARRAY; - G_GNUC_END_IGNORE_DEPRECATIONS - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - /* Muahaha. Actually we add Presence information. */ - GValueArray *presence = tp_value_array_build (3, - G_TYPE_UINT, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, - G_TYPE_STRING, "available", - G_TYPE_STRING, "hi mum!", - G_TYPE_INVALID); - - tp_contacts_mixin_set_contact_attribute (attributes, - handle, - TP_TOKEN_CONNECTION_INTERFACE_PRESENCE1_PRESENCE, - tp_g_value_slice_new_take_boxed (type, presence)); - } -} - -static void -tp_tests_broken_client_types_connection_class_init ( - TpTestsBrokenClientTypesConnectionClass *klass) -{ - TpTestsContactsConnectionClass *cc_class = - TP_TESTS_CONTACTS_CONNECTION_CLASS (klass); - - cc_class->fill_client_types = broken_fill_client_types; -} diff --git a/tests/lib/telepathy/contactlist/broken-client-types-conn.h b/tests/lib/telepathy/contactlist/broken-client-types-conn.h deleted file mode 100644 index ad36d7d5..00000000 --- a/tests/lib/telepathy/contactlist/broken-client-types-conn.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * broken-client-types-conn.h - header for a connection with a broken client - * types implementation which inexplicably returns presence information! - * - * Copyright © 2011 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef TP_TESTS_BROKEN_CLIENT_TYPES_CONN_H -#define TP_TESTS_BROKEN_CLIENT_TYPES_CONN_H - -#include "contacts-conn.h" - -typedef struct _TpTestsBrokenClientTypesConnection TpTestsBrokenClientTypesConnection; -typedef struct _TpTestsBrokenClientTypesConnectionClass TpTestsBrokenClientTypesConnectionClass; -typedef struct _TpTestsBrokenClientTypesConnectionPrivate TpTestsBrokenClientTypesConnectionPrivate; - -struct _TpTestsBrokenClientTypesConnectionClass { - TpTestsContactsConnectionClass parent_class; -}; - -struct _TpTestsBrokenClientTypesConnection { - TpTestsContactsConnection parent; - - TpTestsBrokenClientTypesConnectionPrivate *priv; -}; - -GType tp_tests_broken_client_types_connection_get_type (void); - -/* HI MUM */ -#define TP_TESTS_TYPE_BROKEN_CLIENT_TYPES_CONNECTION \ - (tp_tests_broken_client_types_connection_get_type ()) -#define TP_TESTS_BROKEN_CLIENT_TYPES_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_BROKEN_CLIENT_TYPES_CONNECTION, \ - TpTestsBrokenClientTypesConnection)) -#define TP_TESTS_BROKEN_CLIENT_TYPES_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_BROKEN_CLIENT_TYPES_CONNECTION, \ - TpTestsBrokenClientTypesConnectionClass)) -#define TP_TESTS_IS_BROKEN_CLIENT_TYPES_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_BROKEN_CLIENT_TYPES_CONNECTION)) -#define TP_TESTS_IS_BROKEN_CLIENT_TYPES_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_BROKEN_CLIENT_TYPES_CONNECTION)) -#define TP_TESTS_BROKEN_CLIENT_TYPES_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_BROKEN_CLIENT_TYPES_CONNECTION, \ - TpTestsBrokenClientTypesConnectionClass)) - -#endif // TP_TESTS_BROKEN_CLIENT_TYPES_CONN_H diff --git a/tests/lib/telepathy/contactlist/bug-19101-conn.c b/tests/lib/telepathy/contactlist/bug-19101-conn.c deleted file mode 100644 index e707c19b..00000000 --- a/tests/lib/telepathy/contactlist/bug-19101-conn.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * bug-19101-conn.c - a broken connection to reproduce bug #19101 - * - * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2008 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "bug-19101-conn.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "debug.h" - -static void contacts_iface_init (gpointer g_iface, gpointer iface_data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsBug19101Connection, - tp_tests_bug19101_connection, TP_TESTS_TYPE_CONTACTS_CONNECTION, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS, - contacts_iface_init); - ) - -static void -tp_tests_bug19101_connection_init (TpTestsBug19101Connection *self) -{ -} - -static void -tp_tests_bug19101_connection_class_init (TpTestsBug19101ConnectionClass *klass) -{ -} - -/* A broken implementation of GetContactByID, which returns an empty dict - * of attributes for each id. - */ -static void -tp_tests_bug19101_connection_get_contact_by_id ( - TpSvcConnectionInterfaceContacts *iface, - const gchar *id, - const char **interfaces, - DBusGMethodInvocation *context) -{ - TpBaseConnection *base_conn = TP_BASE_CONNECTION (iface); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( - base_conn, TP_ENTITY_TYPE_CONTACT); - TpHandle handle; - GHashTable *table; - - handle = tp_handle_ensure (contact_repo, id, NULL, NULL); - table = g_hash_table_new (NULL, NULL); - - tp_svc_connection_interface_contacts_return_from_get_contact_by_id ( - context, handle, table); - - g_hash_table_unref (table); -} - -static void -contacts_iface_init (gpointer g_iface, gpointer iface_data) -{ - TpSvcConnectionInterfaceContactsClass *klass = - (TpSvcConnectionInterfaceContactsClass *) g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_contacts_implement_##x ( \ - klass, tp_tests_bug19101_connection_##x) - IMPLEMENT(get_contact_by_id); -#undef IMPLEMENT -} diff --git a/tests/lib/telepathy/contactlist/bug-19101-conn.h b/tests/lib/telepathy/contactlist/bug-19101-conn.h deleted file mode 100644 index 23b670e3..00000000 --- a/tests/lib/telepathy/contactlist/bug-19101-conn.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * bug-19101-conn.h - header for a broken connection to reproduce bug #19101 - * - * Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007-2008 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_BUG19101_CONN_H__ -#define __TP_TESTS_BUG19101_CONN_H__ - -#include "contacts-conn.h" - -G_BEGIN_DECLS - -typedef struct _TpTestsBug19101Connection TpTestsBug19101Connection; -typedef struct _TpTestsBug19101ConnectionClass TpTestsBug19101ConnectionClass; - -struct _TpTestsBug19101ConnectionClass { - TpTestsContactsConnectionClass parent_class; -}; - -struct _TpTestsBug19101Connection { - TpTestsContactsConnection parent; -}; - -GType tp_tests_bug19101_connection_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_BUG19101_CONNECTION \ - (tp_tests_bug19101_connection_get_type ()) -#define BUG_19101_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_BUG19101_CONNECTION, \ - TpTestsBug19101Connection)) -#define BUG_19101_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_BUG19101_CONNECTION, \ - TpTestsBug19101ConnectionClass)) -#define BUG_19101_IS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_BUG19101_CONNECTION)) -#define BUG_19101_IS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_BUG19101_CONNECTION)) -#define BUG_19101_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_BUG19101_CONNECTION, \ - TpTestsBug19101ConnectionClass)) - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_BUG19101_CONN_H__ */ diff --git a/tests/lib/telepathy/contactlist/dbus-tube-chan.c b/tests/lib/telepathy/contactlist/dbus-tube-chan.c deleted file mode 100644 index d2de191e..00000000 --- a/tests/lib/telepathy/contactlist/dbus-tube-chan.c +++ /dev/null @@ -1,455 +0,0 @@ -/* - * dbus-tube-chan.c - Simple dbus tube channel - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "dbus-tube-chan.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> -#include <glib/gstdio.h> - -#if defined(G_OS_UNIX) -# define LISTEN_ADDRESS "unix:tmpdir=/tmp" -#else -# define LISTEN_ADDRESS "tcp:host=127.0.0.1" -#endif - -enum -{ - PROP_SERVICE_NAME = 1, - PROP_DBUS_NAMES, - PROP_SUPPORTED_ACCESS_CONTROLS, - PROP_PARAMETERS, - PROP_STATE, -}; - -enum -{ - SIG_NEW_CONNECTION, - LAST_SIGNAL -}; - -static guint _signals[LAST_SIGNAL] = { 0, }; - -struct _TpTestsDBusTubeChannelPrivate { - /* Controls whether the channel should become open before returning from - * Open/Accept, after returning, or never. - */ - TpTestsDBusTubeChannelOpenMode open_mode; - TpTubeChannelState state; - - /* TpHandle -> gchar * */ - GHashTable *dbus_names; - - GDBusServer *dbus_server; -}; - -static void -tp_tests_dbus_tube_channel_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TpTestsDBusTubeChannel *self = (TpTestsDBusTubeChannel *) object; - - switch (property_id) - { - case PROP_SERVICE_NAME: - g_value_set_string (value, "com.test.Test"); - break; - - case PROP_DBUS_NAMES: - g_value_set_boxed (value, self->priv->dbus_names); - break; - - case PROP_SUPPORTED_ACCESS_CONTROLS: - { - GArray *array; - TpSocketAccessControl a; - - array = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1); - - a = TP_SOCKET_ACCESS_CONTROL_LOCALHOST; - g_array_append_val (array, a); - - g_value_set_boxed (value, array); - - g_array_unref (array); - } - break; - - case PROP_PARAMETERS: - g_value_take_boxed (value, tp_asv_new ( - "badger", G_TYPE_UINT, 42, - NULL)); - break; - - case PROP_STATE: - g_value_set_uint (value, self->priv->state); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void dbus_tube_iface_init (gpointer iface, gpointer data); - -G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TpTestsDBusTubeChannel, - tp_tests_dbus_tube_channel, - TP_TYPE_BASE_CHANNEL, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_DBUS_TUBE1, - dbus_tube_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_TUBE1, - NULL); - ) - -/* type definition stuff */ - -static GPtrArray * -tp_tests_dbus_tube_channel_get_interfaces (TpBaseChannel *self) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CHANNEL_CLASS ( - tp_tests_dbus_tube_channel_parent_class)->get_interfaces (self); - - g_ptr_array_add (interfaces, TP_IFACE_CHANNEL_INTERFACE_TUBE1); - return interfaces; -}; - -static void -tp_tests_dbus_tube_channel_init (TpTestsDBusTubeChannel *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), - TP_TESTS_TYPE_DBUS_TUBE_CHANNEL, TpTestsDBusTubeChannelPrivate); - - self->priv->open_mode = TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_FIRST; - self->priv->dbus_names = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, g_free); -} - -static GObject * -constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *object = - G_OBJECT_CLASS (tp_tests_dbus_tube_channel_parent_class)->constructor ( - type, n_props, props); - TpTestsDBusTubeChannel *self = TP_TESTS_DBUS_TUBE_CHANNEL (object); - - if (tp_base_channel_is_requested (TP_BASE_CHANNEL (self))) - self->priv->state = TP_TUBE_CHANNEL_STATE_NOT_OFFERED; - else - self->priv->state = TP_TUBE_CHANNEL_STATE_LOCAL_PENDING; - - tp_base_channel_register (TP_BASE_CHANNEL (self)); - - return object; -} - -static void -dispose (GObject *object) -{ - TpTestsDBusTubeChannel *self = (TpTestsDBusTubeChannel *) object; - - tp_clear_pointer (&self->priv->dbus_names, g_hash_table_unref); - - if (self->priv->dbus_server != NULL) - { - /* FIXME: this is pretty stupid but apparently unless you start and then - * stop the server before freeing it, it doesn't stop listening. Calling - * _start() twice is a no-op. - * - * https://bugzilla.gnome.org/show_bug.cgi?id=673372 - */ - g_dbus_server_start (self->priv->dbus_server); - - g_dbus_server_stop (self->priv->dbus_server); - g_clear_object (&self->priv->dbus_server); - } - - ((GObjectClass *) tp_tests_dbus_tube_channel_parent_class)->dispose ( - object); -} - -static void -channel_close (TpBaseChannel *channel) -{ - tp_base_channel_destroyed (channel); -} - -static void -fill_immutable_properties (TpBaseChannel *chan, - GHashTable *properties) -{ - TpBaseChannelClass *klass = TP_BASE_CHANNEL_CLASS ( - tp_tests_dbus_tube_channel_parent_class); - - klass->fill_immutable_properties (chan, properties); - - tp_dbus_properties_mixin_fill_properties_hash ( - G_OBJECT (chan), properties, - TP_IFACE_CHANNEL_TYPE_DBUS_TUBE1, "ServiceName", - TP_IFACE_CHANNEL_TYPE_DBUS_TUBE1, "SupportedAccessControls", - NULL); - - if (!tp_base_channel_is_requested (chan)) - { - /* Parameters is immutable only for incoming tubes */ - tp_dbus_properties_mixin_fill_properties_hash ( - G_OBJECT (chan), properties, - TP_IFACE_CHANNEL_INTERFACE_TUBE1, "Parameters", - NULL); - } -} - -static void -tp_tests_dbus_tube_channel_class_init (TpTestsDBusTubeChannelClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - GParamSpec *param_spec; - static TpDBusPropertiesMixinPropImpl dbus_tube_props[] = { - { "ServiceName", "service-name", NULL, }, - { "DBusNames", "dbus-names", NULL, }, - { "SupportedAccessControls", "supported-access-controls", NULL, }, - { NULL } - }; - static TpDBusPropertiesMixinPropImpl tube_props[] = { - { "Parameters", "parameters", NULL, }, - { "State", "state", NULL, }, - { NULL } - }; - - object_class->constructor = constructor; - object_class->get_property = tp_tests_dbus_tube_channel_get_property; - object_class->dispose = dispose; - - base_class->channel_type = TP_IFACE_CHANNEL_TYPE_DBUS_TUBE1; - base_class->get_interfaces = tp_tests_dbus_tube_channel_get_interfaces; - base_class->close = channel_close; - base_class->fill_immutable_properties = fill_immutable_properties; - - /* base_class->target_entity_type is defined in subclasses */ - - param_spec = g_param_spec_string ("service-name", "Service Name", - "the service name associated with this tube object.", - "", - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SERVICE_NAME, param_spec); - - param_spec = g_param_spec_boxed ("dbus-names", "DBus Names", - "DBusTube.DBusNames", - TP_HASH_TYPE_DBUS_TUBE_PARTICIPANTS, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DBUS_NAMES, param_spec); - - param_spec = g_param_spec_boxed ("supported-access-controls", - "Supported access-controls", - "GArray containing supported access controls.", - DBUS_TYPE_G_UINT_ARRAY, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, - PROP_SUPPORTED_ACCESS_CONTROLS, param_spec); - - param_spec = g_param_spec_boxed ( - "parameters", "Parameters", - "parameters of the tube", - TP_HASH_TYPE_STRING_VARIANT_MAP, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_PARAMETERS, - param_spec); - - param_spec = g_param_spec_uint ( - "state", "TpTubeState", - "state of the tube", - 0, TP_NUM_TUBE_CHANNEL_STATES - 1, 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STATE, - param_spec); - - _signals[SIG_NEW_CONNECTION] = g_signal_new ("new-connection", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - 0, - g_signal_accumulator_true_handled, NULL, - NULL, - G_TYPE_BOOLEAN, - 1, G_TYPE_DBUS_CONNECTION); - - tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CHANNEL_TYPE_DBUS_TUBE1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - dbus_tube_props); - - tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CHANNEL_INTERFACE_TUBE1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - tube_props); - - g_type_class_add_private (object_class, - sizeof (TpTestsDBusTubeChannelPrivate)); -} - -static void -change_state (TpTestsDBusTubeChannel *self, - TpTubeChannelState state) -{ - self->priv->state = state; - - tp_svc_channel_interface_tube1_emit_tube_channel_state_changed (self, state); -} - -static gboolean -dbus_new_connection_cb (GDBusServer *server, - GDBusConnection *connection, - gpointer user_data) -{ - TpTestsDBusTubeChannel *self = user_data; - gboolean ret = FALSE; - - g_signal_emit (self, _signals[SIG_NEW_CONNECTION], 0, connection, &ret); - return ret; -} - -static void -open_tube (TpTestsDBusTubeChannel *self) -{ - GError *error = NULL; - gchar *guid; - - guid = g_dbus_generate_guid (); - - self->priv->dbus_server = g_dbus_server_new_sync (LISTEN_ADDRESS, - G_DBUS_SERVER_FLAGS_NONE, guid, NULL, NULL, &error); - g_assert_no_error (error); - - g_free (guid); - - g_signal_connect (self->priv->dbus_server, "new-connection", - G_CALLBACK (dbus_new_connection_cb), self); -} - -static void -really_open_tube (TpTestsDBusTubeChannel *self) -{ - g_dbus_server_start (self->priv->dbus_server); - - change_state (self, TP_TUBE_CHANNEL_STATE_OPEN); -} - -static void -dbus_tube_offer (TpSvcChannelTypeDBusTube1 *chan, - GHashTable *parameters, - guint access_control, - DBusGMethodInvocation *context) -{ - TpTestsDBusTubeChannel *self = (TpTestsDBusTubeChannel *) chan; - - open_tube (self); - - if (self->priv->open_mode == TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_FIRST) - really_open_tube (self); - - tp_svc_channel_type_dbus_tube1_return_from_offer (context, - g_dbus_server_get_client_address (self->priv->dbus_server)); - - if (self->priv->open_mode == TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_SECOND) - really_open_tube (self); - else if (self->priv->open_mode == TP_TESTS_DBUS_TUBE_CHANNEL_NEVER_OPEN) - tp_base_channel_close (TP_BASE_CHANNEL (self)); -} - -static void -dbus_tube_accept (TpSvcChannelTypeDBusTube1 *chan, - guint access_control, - DBusGMethodInvocation *context) -{ - TpTestsDBusTubeChannel *self = (TpTestsDBusTubeChannel *) chan; - - open_tube (self); - - if (self->priv->open_mode == TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_FIRST) - really_open_tube (self); - - tp_svc_channel_type_dbus_tube1_return_from_accept (context, - g_dbus_server_get_client_address (self->priv->dbus_server)); - - if (self->priv->open_mode == TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_SECOND) - really_open_tube (self); - else if (self->priv->open_mode == TP_TESTS_DBUS_TUBE_CHANNEL_NEVER_OPEN) - tp_base_channel_close (TP_BASE_CHANNEL (self)); -} - -void -tp_tests_dbus_tube_channel_set_open_mode ( - TpTestsDBusTubeChannel *self, - TpTestsDBusTubeChannelOpenMode open_mode) -{ - self->priv->open_mode = open_mode; -} - -static void -dbus_tube_iface_init (gpointer iface, - gpointer data) -{ - TpSvcChannelTypeDBusTube1Class *klass = iface; - -#define IMPLEMENT(x) tp_svc_channel_type_dbus_tube1_implement_##x (klass, dbus_tube_##x) - IMPLEMENT (offer); - IMPLEMENT (accept); -#undef IMPLEMENT -} - -/* Contact DBus Tube */ - -G_DEFINE_TYPE (TpTestsContactDBusTubeChannel, - tp_tests_contact_dbus_tube_channel, - TP_TESTS_TYPE_DBUS_TUBE_CHANNEL) - -static void -tp_tests_contact_dbus_tube_channel_init ( - TpTestsContactDBusTubeChannel *self) -{ -} - -static void -tp_tests_contact_dbus_tube_channel_class_init ( - TpTestsContactDBusTubeChannelClass *klass) -{ - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - - base_class->target_entity_type = TP_ENTITY_TYPE_CONTACT; -} - -/* Room DBus Tube */ - -G_DEFINE_TYPE (TpTestsRoomDBusTubeChannel, - tp_tests_room_dbus_tube_channel, - TP_TESTS_TYPE_DBUS_TUBE_CHANNEL) - -static void -tp_tests_room_dbus_tube_channel_init ( - TpTestsRoomDBusTubeChannel *self) -{ -} - -static void -tp_tests_room_dbus_tube_channel_class_init ( - TpTestsRoomDBusTubeChannelClass *klass) -{ - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - - base_class->target_entity_type = TP_ENTITY_TYPE_ROOM; -} diff --git a/tests/lib/telepathy/contactlist/dbus-tube-chan.h b/tests/lib/telepathy/contactlist/dbus-tube-chan.h deleted file mode 100644 index 71800970..00000000 --- a/tests/lib/telepathy/contactlist/dbus-tube-chan.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * dbus-tube-chan.h - Simple dbus tube channel - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_DBUS_TUBE_CHAN_H__ -#define __TP_DBUS_TUBE_CHAN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -/* Base Class */ -typedef struct _TpTestsDBusTubeChannel TpTestsDBusTubeChannel; -typedef struct _TpTestsDBusTubeChannelClass TpTestsDBusTubeChannelClass; -typedef struct _TpTestsDBusTubeChannelPrivate TpTestsDBusTubeChannelPrivate; - -GType tp_tests_dbus_tube_channel_get_type (void); - -#define TP_TESTS_TYPE_DBUS_TUBE_CHANNEL \ - (tp_tests_dbus_tube_channel_get_type ()) -#define TP_TESTS_DBUS_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_DBUS_TUBE_CHANNEL, \ - TpTestsDBusTubeChannel)) -#define TP_TESTS_DBUS_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_DBUS_TUBE_CHANNEL, \ - TpTestsDBusTubeChannelClass)) -#define TP_TESTS_IS_DBUS_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_DBUS_TUBE_CHANNEL)) -#define TP_TESTS_IS_DBUS_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_DBUS_TUBE_CHANNEL)) -#define TP_TESTS_DBUS_TUBE_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_DBUS_TUBE_CHANNEL, \ - TpTestsDBusTubeChannelClass)) - -struct _TpTestsDBusTubeChannelClass { - TpBaseChannelClass parent_class; - TpDBusPropertiesMixinClass dbus_properties_class; -}; - -struct _TpTestsDBusTubeChannel { - TpBaseChannel parent; - - TpTestsDBusTubeChannelPrivate *priv; -}; - -typedef enum { - TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_FIRST, - TP_TESTS_DBUS_TUBE_CHANNEL_OPEN_SECOND, - TP_TESTS_DBUS_TUBE_CHANNEL_NEVER_OPEN -} TpTestsDBusTubeChannelOpenMode; - -void tp_tests_dbus_tube_channel_set_open_mode ( - TpTestsDBusTubeChannel *self, - TpTestsDBusTubeChannelOpenMode open_mode); - -/* Contact DBus Tube */ - -typedef struct _TpTestsContactDBusTubeChannel TpTestsContactDBusTubeChannel; -typedef struct _TpTestsContactDBusTubeChannelClass TpTestsContactDBusTubeChannelClass; - -GType tp_tests_contact_dbus_tube_channel_get_type (void); - -#define TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL \ - (tp_tests_contact_dbus_tube_channel_get_type ()) -#define TP_TESTS_CONTACT_DBUS_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL, \ - TpTestsContactDBusTubeChannel)) -#define TP_TESTS_CONTACT_DBUS_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL, \ - TpTestsContactDBusTubeChannelClass)) -#define TP_TESTS_IS_CONTACT_DBUS_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL)) -#define TP_TESTS_IS_CONTACT_DBUS_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL)) -#define TP_TESTS_CONTACT_DBUS_TUBE_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL, \ - TpTestsContactDBusTubeChannelClass)) - -struct _TpTestsContactDBusTubeChannelClass { - TpTestsDBusTubeChannelClass parent_class; -}; - -struct _TpTestsContactDBusTubeChannel { - TpTestsDBusTubeChannel parent; -}; - -/* Room DBus Tube */ - -typedef struct _TpTestsRoomDBusTubeChannel TpTestsRoomDBusTubeChannel; -typedef struct _TpTestsRoomDBusTubeChannelClass TpTestsRoomDBusTubeChannelClass; - -GType tp_tests_room_dbus_tube_channel_get_type (void); - -#define TP_TESTS_TYPE_ROOM_DBUS_TUBE_CHANNEL \ - (tp_tests_room_dbus_tube_channel_get_type ()) -#define TP_TESTS_ROOM_DBUS_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_ROOM_DBUS_TUBE_CHANNEL, \ - TpTestsRoomDBusTubeChannel)) -#define TP_TESTS_ROOM_DBUS_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_ROOM_DBUS_TUBE_CHANNEL, \ - TpTestsRoomDBusTubeChannelClass)) -#define TP_TESTS_IS_ROOM_DBUS_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_ROOM_DBUS_TUBE_CHANNEL)) -#define TP_TESTS_IS_ROOM_DBUS_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_ROOM_DBUS_TUBE_CHANNEL)) -#define TP_TESTS_ROOM_DBUS_TUBE_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_ROOM_DBUS_TUBE_CHANNEL, \ - TpTestsRoomDBusTubeChannelClass)) - -struct _TpTestsRoomDBusTubeChannelClass { - TpTestsDBusTubeChannelClass parent_class; -}; - -struct _TpTestsRoomDBusTubeChannel { - TpTestsDBusTubeChannel parent; -}; - -G_END_DECLS - -#endif /* #ifndef __TP_DBUS_TUBE_CHAN_H__ */ diff --git a/tests/lib/telepathy/contactlist/echo-conn.c b/tests/lib/telepathy/contactlist/echo-conn.c deleted file mode 100644 index 48638792..00000000 --- a/tests/lib/telepathy/contactlist/echo-conn.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * conn.c - an example connection - * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "echo-conn.h" - -#include <dbus/dbus-glib.h> - -#include <telepathy-glib/telepathy-glib.h> - -#include "echo-im-manager.h" -#include "simple-channel-manager.h" - -G_DEFINE_TYPE (TpTestsEchoConnection, - tp_tests_echo_connection, - TP_TESTS_TYPE_CONTACTS_CONNECTION) - -/* type definition stuff */ - -enum -{ - PROP_CHANNEL_MANAGER = 1, - N_PROPS -}; - -struct _TpTestsEchoConnectionPrivate -{ - TpTestsSimpleChannelManager *channel_manager; -}; - - -static void -tp_tests_echo_connection_init (TpTestsEchoConnection *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TP_TESTS_TYPE_ECHO_CONNECTION, - TpTestsEchoConnectionPrivate); -} - -/* Returns the same id given in but in lowercase. If '#' is present, - * the normalized contact will be the lhs of it. For example: - * - * LOL -> lol - * Lol#foo -> lol - */ -static gchar * -tp_tests_echo_normalize_contact (TpHandleRepoIface *repo, - const gchar *id, - gpointer context, - GError **error) -{ - gchar *hash; - - if (id[0] == '\0') - { - g_set_error (error, TP_ERROR, TP_ERROR_INVALID_HANDLE, - "ID must not be empty"); - return NULL; - } - - hash = g_utf8_strchr (id, -1, '#'); - - return g_utf8_strdown (id, hash != NULL ? (hash - id) : -1); -} - -static void -create_handle_repos (TpBaseConnection *conn, - TpHandleRepoIface *repos[TP_NUM_ENTITY_TYPES]) -{ - ((TpBaseConnectionClass *) - tp_tests_echo_connection_parent_class)->create_handle_repos (conn, repos); - - /* Replace the contacts handle repo with our own, for special normalization */ - g_assert (repos[TP_ENTITY_TYPE_CONTACT] != NULL); - g_object_unref (repos[TP_ENTITY_TYPE_CONTACT]); - repos[TP_ENTITY_TYPE_CONTACT] = tp_dynamic_handle_repo_new - (TP_ENTITY_TYPE_CONTACT, tp_tests_echo_normalize_contact, NULL); -} - -static GPtrArray * -create_channel_managers (TpBaseConnection *conn) -{ - TpTestsEchoConnection *self = TP_TESTS_ECHO_CONNECTION (conn); - GPtrArray *ret; - - ret = ((TpBaseConnectionClass *) - tp_tests_echo_connection_parent_class)->create_channel_managers (conn); - - if (self->priv->channel_manager == NULL) - { - self->priv->channel_manager = g_object_new (TP_TESTS_TYPE_ECHO_IM_MANAGER, - "connection", conn, - NULL); - } - - /* tp-glib will free this for us so we don't need to worry about - doing it ourselves. */ - g_ptr_array_add (ret, self->priv->channel_manager); - - return ret; -} - -static void -get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - TpTestsEchoConnection *self = TP_TESTS_ECHO_CONNECTION (object); - - switch (property_id) { - case PROP_CHANNEL_MANAGER: - g_assert (self->priv->channel_manager == NULL); /* construct-only */ - g_value_set_object (value, self->priv->channel_manager); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - } -} - -static void -set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *spec) -{ - TpTestsEchoConnection *self = TP_TESTS_ECHO_CONNECTION (object); - - switch (property_id) { - case PROP_CHANNEL_MANAGER: - self->priv->channel_manager = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - } -} - -static void -tp_tests_echo_connection_class_init (TpTestsEchoConnectionClass *klass) -{ - TpBaseConnectionClass *base_class = - (TpBaseConnectionClass *) klass; - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - object_class->get_property = get_property; - object_class->set_property = set_property; - g_type_class_add_private (klass, sizeof (TpTestsEchoConnectionPrivate)); - - base_class->create_handle_repos = create_handle_repos; - base_class->create_channel_managers = create_channel_managers; - - param_spec = g_param_spec_object ("channel-manager", "Channel manager", - "The channel manager", TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CHANNEL_MANAGER, param_spec); -} diff --git a/tests/lib/telepathy/contactlist/echo-conn.h b/tests/lib/telepathy/contactlist/echo-conn.h deleted file mode 100644 index ffc8f4d9..00000000 --- a/tests/lib/telepathy/contactlist/echo-conn.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * conn.h - header for an example connection - * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_ECHO_CONN_H__ -#define __TP_TESTS_ECHO_CONN_H__ - -#include <glib-object.h> - -#include "contacts-conn.h" - -G_BEGIN_DECLS - -typedef struct _TpTestsEchoConnection TpTestsEchoConnection; -typedef struct _TpTestsEchoConnectionClass TpTestsEchoConnectionClass; -typedef struct _TpTestsEchoConnectionPrivate TpTestsEchoConnectionPrivate; - -struct _TpTestsEchoConnectionClass { - TpTestsContactsConnectionClass parent_class; -}; - -struct _TpTestsEchoConnection { - TpTestsContactsConnection parent; - - TpTestsEchoConnectionPrivate *priv; -}; - -GType tp_tests_echo_connection_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_ECHO_CONNECTION \ - (tp_tests_echo_connection_get_type ()) -#define TP_TESTS_ECHO_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_ECHO_CONNECTION, \ - TpTestsEchoConnection)) -#define TP_TESTS_ECHO_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_ECHO_CONNECTION, \ - TpTestsEchoConnectionClass)) -#define TP_TESTS_IS_ECHO_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_ECHO_CONNECTION)) -#define TP_TESTS_IS_ECHO_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_ECHO_CONNECTION)) -#define TP_TESTS_ECHO_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_ECHO_CONNECTION, \ - TpTestsEchoConnectionClass)) - -G_END_DECLS - -#endif diff --git a/tests/lib/telepathy/contactlist/echo-im-manager.c b/tests/lib/telepathy/contactlist/echo-im-manager.c deleted file mode 100644 index ea091ce3..00000000 --- a/tests/lib/telepathy/contactlist/echo-im-manager.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * im-manager.c - an example channel manager for channels talking to a - * particular contact. Similar code is used for 1-1 IM channels in many - * protocols (IRC private messages ("/query"), XMPP IM etc.) - * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "echo-im-manager.h" - -#include <dbus/dbus-glib.h> - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "echo-chan.h" - -static void channel_manager_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsEchoImManager, - tp_tests_echo_im_manager, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER, - channel_manager_iface_init)) - -/* type definition stuff */ - -enum -{ - PROP_CONNECTION = 1, - N_PROPS -}; - -struct _TpTestsEchoImManagerPrivate -{ - TpBaseConnection *conn; - - /* GUINT_TO_POINTER (handle) => TpTestsEchoChannel */ - GHashTable *channels; - gulong status_changed_id; -}; - -static void -tp_tests_echo_im_manager_init (TpTestsEchoImManager *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TP_TESTS_TYPE_ECHO_IM_MANAGER, - TpTestsEchoImManagerPrivate); - - self->priv->channels = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, g_object_unref); -} - -static void tp_tests_echo_im_manager_close_all (TpTestsEchoImManager *self); - -static void -dispose (GObject *object) -{ - TpTestsEchoImManager *self = TP_TESTS_ECHO_IM_MANAGER (object); - - tp_tests_echo_im_manager_close_all (self); - g_assert (self->priv->channels == NULL); - - ((GObjectClass *) tp_tests_echo_im_manager_parent_class)->dispose (object); -} - -static void -get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TpTestsEchoImManager *self = TP_TESTS_ECHO_IM_MANAGER (object); - - switch (property_id) - { - case PROP_CONNECTION: - g_value_set_object (value, self->priv->conn); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - TpTestsEchoImManager *self = TP_TESTS_ECHO_IM_MANAGER (object); - - switch (property_id) - { - case PROP_CONNECTION: - /* We don't ref the connection, because it owns a reference to the - * channel manager, and it guarantees that the manager's lifetime is - * less than its lifetime */ - self->priv->conn = g_value_get_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -status_changed_cb (TpBaseConnection *conn, - guint status, - guint reason, - TpTestsEchoImManager *self) -{ - if (status == TP_CONNECTION_STATUS_DISCONNECTED) - tp_tests_echo_im_manager_close_all (self); -} - -static void -constructed (GObject *object) -{ - TpTestsEchoImManager *self = TP_TESTS_ECHO_IM_MANAGER (object); - void (*chain_up) (GObject *) = - ((GObjectClass *) tp_tests_echo_im_manager_parent_class)->constructed; - - if (chain_up != NULL) - { - chain_up (object); - } - - self->priv->status_changed_id = g_signal_connect (self->priv->conn, - "status-changed", (GCallback) status_changed_cb, self); -} - -static void -tp_tests_echo_im_manager_class_init (TpTestsEchoImManagerClass *klass) -{ - GParamSpec *param_spec; - GObjectClass *object_class = (GObjectClass *) klass; - - object_class->constructed = constructed; - object_class->dispose = dispose; - object_class->get_property = get_property; - object_class->set_property = set_property; - - param_spec = g_param_spec_object ("connection", "Connection object", - "The connection that owns this channel manager", - TP_TYPE_BASE_CONNECTION, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION, param_spec); - - g_type_class_add_private (klass, sizeof (TpTestsEchoImManagerPrivate)); -} - -static void -tp_tests_echo_im_manager_close_all (TpTestsEchoImManager *self) -{ - if (self->priv->channels != NULL) - { - GHashTable *tmp = self->priv->channels; - - self->priv->channels = NULL; - g_hash_table_unref (tmp); - } - - if (self->priv->status_changed_id != 0) - { - g_signal_handler_disconnect (self->priv->conn, - self->priv->status_changed_id); - self->priv->status_changed_id = 0; - } -} - -static void -tp_tests_echo_im_manager_foreach_channel (TpChannelManager *iface, - TpExportableChannelFunc callback, - gpointer user_data) -{ - TpTestsEchoImManager *self = TP_TESTS_ECHO_IM_MANAGER (iface); - GHashTableIter iter; - gpointer handle, channel; - - g_hash_table_iter_init (&iter, self->priv->channels); - - while (g_hash_table_iter_next (&iter, &handle, &channel)) - { - callback (TP_EXPORTABLE_CHANNEL (channel), user_data); - } -} - -static void -channel_closed_cb (TpTestsEchoChannel *chan, - TpTestsEchoImManager *self) -{ - tp_channel_manager_emit_channel_closed_for_object (self, - TP_EXPORTABLE_CHANNEL (chan)); - - if (self->priv->channels != NULL) - { - TpHandle handle; - gboolean really_destroyed; - - g_object_get (chan, - "handle", &handle, - "channel-destroyed", &really_destroyed, - NULL); - - /* Re-announce the channel if it's not yet ready to go away (pending - * messages) */ - if (really_destroyed) - { - g_hash_table_remove (self->priv->channels, - GUINT_TO_POINTER (handle)); - } - else - { - tp_channel_manager_emit_new_channel (self, - TP_EXPORTABLE_CHANNEL (chan), NULL); - } - } -} - -static void -new_channel (TpTestsEchoImManager *self, - TpHandle handle, - TpHandle initiator, - gpointer request_token) -{ - TpTestsEchoChannel *chan; - gchar *object_path; - GSList *requests = NULL; - - object_path = g_strdup_printf ("%s/EchoChannel%u", - tp_base_connection_get_object_path (self->priv->conn), handle); - - chan = g_object_new (TP_TESTS_TYPE_ECHO_CHANNEL, - "connection", self->priv->conn, - "object-path", object_path, - "handle", handle, - "initiator-handle", initiator, - NULL); - - g_free (object_path); - - g_signal_connect (chan, "closed", (GCallback) channel_closed_cb, self); - - /* self->priv->channels takes ownership of 'chan' */ - g_hash_table_insert (self->priv->channels, GUINT_TO_POINTER (handle), chan); - - if (request_token != NULL) - requests = g_slist_prepend (requests, request_token); - - tp_channel_manager_emit_new_channel (self, TP_EXPORTABLE_CHANNEL (chan), - requests); - g_slist_free (requests); -} - -static const gchar * const fixed_properties[] = { - TP_PROP_CHANNEL_CHANNEL_TYPE, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, - NULL -}; - -static const gchar * const allowed_properties[] = { - TP_PROP_CHANNEL_TARGET_HANDLE, - TP_PROP_CHANNEL_TARGET_ID, - NULL -}; - -static void -tp_tests_echo_im_manager_foreach_channel_class (TpChannelManager *manager, - TpChannelManagerChannelClassFunc func, - gpointer user_data) -{ - GHashTable *table = tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, - G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, TP_ENTITY_TYPE_CONTACT, - NULL); - - - func (manager, table, allowed_properties, user_data); - - g_hash_table_unref (table); -} - -static gboolean -tp_tests_echo_im_manager_request (TpTestsEchoImManager *self, - gpointer request_token, - GHashTable *request_properties, - gboolean require_new) -{ - TpHandle handle; - TpTestsEchoChannel *chan; - GError *error = NULL; - - if (tp_strdiff (tp_asv_get_string (request_properties, - TP_PROP_CHANNEL_CHANNEL_TYPE), - TP_IFACE_CHANNEL_TYPE_TEXT)) - { - return FALSE; - } - - if (tp_asv_get_uint32 (request_properties, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, NULL) != TP_ENTITY_TYPE_CONTACT) - { - return FALSE; - } - - handle = tp_asv_get_uint32 (request_properties, - TP_PROP_CHANNEL_TARGET_HANDLE, NULL); - g_assert (handle != 0); - - if (tp_channel_manager_asv_has_unknown_properties (request_properties, - fixed_properties, allowed_properties, &error)) - { - goto error; - } - - chan = g_hash_table_lookup (self->priv->channels, GUINT_TO_POINTER (handle)); - - if (chan == NULL) - { - new_channel (self, handle, - tp_base_connection_get_self_handle (self->priv->conn), - request_token); - } - else if (require_new) - { - g_set_error (&error, TP_ERROR, TP_ERROR_NOT_AVAILABLE, - "An echo channel to contact #%u already exists", handle); - goto error; - } - else - { - tp_channel_manager_emit_request_already_satisfied (self, - request_token, TP_EXPORTABLE_CHANNEL (chan)); - } - - return TRUE; - -error: - tp_channel_manager_emit_request_failed (self, request_token, - error->domain, error->code, error->message); - g_error_free (error); - return TRUE; -} - -static gboolean -tp_tests_echo_im_manager_create_channel (TpChannelManager *manager, - gpointer request_token, - GHashTable *request_properties) -{ - return tp_tests_echo_im_manager_request (TP_TESTS_ECHO_IM_MANAGER (manager), - request_token, request_properties, TRUE); -} - -static gboolean -tp_tests_echo_im_manager_ensure_channel (TpChannelManager *manager, - gpointer request_token, - GHashTable *request_properties) -{ - return tp_tests_echo_im_manager_request (TP_TESTS_ECHO_IM_MANAGER (manager), - request_token, request_properties, FALSE); -} - -static void -channel_manager_iface_init (gpointer g_iface, - gpointer iface_data G_GNUC_UNUSED) -{ - TpChannelManagerIface *iface = g_iface; - - iface->foreach_channel = tp_tests_echo_im_manager_foreach_channel; - iface->foreach_channel_class = tp_tests_echo_im_manager_foreach_channel_class; - iface->create_channel = tp_tests_echo_im_manager_create_channel; - iface->ensure_channel = tp_tests_echo_im_manager_ensure_channel; - /* In this channel manager, Request has the same semantics as Ensure */ - iface->request_channel = tp_tests_echo_im_manager_ensure_channel; -} diff --git a/tests/lib/telepathy/contactlist/echo-im-manager.h b/tests/lib/telepathy/contactlist/echo-im-manager.h deleted file mode 100644 index a33b83ef..00000000 --- a/tests/lib/telepathy/contactlist/echo-im-manager.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * im-manager.h - header for an example channel manager - * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_ECHO_IM_MANAGER_H__ -#define __TP_TESTS_ECHO_IM_MANAGER_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsEchoImManager TpTestsEchoImManager; -typedef struct _TpTestsEchoImManagerClass TpTestsEchoImManagerClass; -typedef struct _TpTestsEchoImManagerPrivate TpTestsEchoImManagerPrivate; - -struct _TpTestsEchoImManagerClass { - GObjectClass parent_class; -}; - -struct _TpTestsEchoImManager { - GObject parent; - - TpTestsEchoImManagerPrivate *priv; -}; - -GType tp_tests_echo_im_manager_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_ECHO_IM_MANAGER \ - (tp_tests_echo_im_manager_get_type ()) -#define TP_TESTS_ECHO_IM_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_ECHO_IM_MANAGER, \ - TpTestsEchoImManager)) -#define TP_TESTS_ECHO_IM_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_ECHO_IM_MANAGER, \ - TpTestsEchoImManagerClass)) -#define TP_TESTS_IS_ECHO_IM_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_ECHO_IM_MANAGER)) -#define TP_TESTS_IS_ECHO_IM_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_ECHO_IM_MANAGER)) -#define TP_TESTS_ECHO_IM_MANAGER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_ECHO_IM_MANAGER, \ - TpTestsEchoImManagerClass)) - -G_END_DECLS - -#endif diff --git a/tests/lib/telepathy/contactlist/file-transfer-chan.c b/tests/lib/telepathy/contactlist/file-transfer-chan.c deleted file mode 100644 index 813826e8..00000000 --- a/tests/lib/telepathy/contactlist/file-transfer-chan.c +++ /dev/null @@ -1,763 +0,0 @@ -/* - * file-transfer-chan.c - Simple file transfer channel - * - * Copyright (C) 2010-2011 Morten Mjelva <morten.mjelva@gmail.com> - * Copyright (C) 2010-2011 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "file-transfer-chan.h" -#include "util.h" -#include "debug.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include <glib/gstdio.h> - -static void file_transfer_iface_init (gpointer iface, gpointer data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsFileTransferChannel, - tp_tests_file_transfer_channel, - TP_TYPE_BASE_CHANNEL, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_FILE_TRANSFER1, - file_transfer_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA1, - NULL); - ) - -enum /* properties */ -{ - PROP_AVAILABLE_SOCKET_TYPES = 1, - PROP_CONTENT_TYPE, - PROP_CONTENT_HASH, - PROP_CONTENT_HASH_TYPE, - PROP_DATE, - PROP_DESCRIPTION, - PROP_FILENAME, - PROP_INITIAL_OFFSET, - PROP_SIZE, - PROP_STATE, - PROP_TRANSFERRED_BYTES, - PROP_URI, - PROP_SERVICE_NAME, - PROP_METADATA, - N_PROPS, -}; - -struct _TpTestsFileTransferChannelPrivate { - /* Exposed properties */ - gchar *content_type; - guint64 date; - gchar *description; - gchar *filename; - guint64 size; - TpFileTransferState state; - guint64 transferred_bytes; - gchar *uri; - gchar *service_name; - GHashTable *metadata; - - /* Hidden properties */ - TpFileHashType content_hash_type; - gchar *content_hash; - GHashTable *available_socket_types; - gint64 initial_offset; - - /* Accepting side */ - GSocketService *service; - GValue *access_control_param; - - /* Offering side */ - TpSocketAddressType address_type; - GValue *address; - gchar *unix_address; - gchar *unix_tmpdir; - guint connection_id; - TpSocketAccessControl access_control; - - guint timer_id; -}; - -static void -tp_tests_file_transfer_channel_init (TpTestsFileTransferChannel *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), - TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL, TpTestsFileTransferChannelPrivate); -} - -static void -create_available_socket_types (TpTestsFileTransferChannel *self) -{ - TpSocketAccessControl access_control; - GArray *unix_tab; - - g_assert (self->priv->available_socket_types == NULL); - self->priv->available_socket_types = g_hash_table_new_full (NULL, NULL, - NULL, _tp_destroy_socket_control_list); - - /* SocketAddressTypeUnix */ - unix_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl), - 1); - access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST; - g_array_append_val (unix_tab, access_control); - - g_hash_table_insert (self->priv->available_socket_types, - GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_UNIX), unix_tab); -} - -static GObject * -constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *object = - G_OBJECT_CLASS (tp_tests_file_transfer_channel_parent_class)->constructor - (type, n_props, props); - TpTestsFileTransferChannel *self = TP_TESTS_FILE_TRANSFER_CHANNEL (object); - - self->priv->state = TP_FILE_TRANSFER_STATE_PENDING; - - if (self->priv->available_socket_types == NULL) - create_available_socket_types (self); - - tp_base_channel_register (TP_BASE_CHANNEL (self)); - - return object; -} - -static void -dispose (GObject *object) -{ - TpTestsFileTransferChannel *self = TP_TESTS_FILE_TRANSFER_CHANNEL (object); - - if (self->priv->timer_id != 0) - { - g_source_remove (self->priv->timer_id); - self->priv->timer_id = 0; - } - - g_free (self->priv->content_hash); - g_free (self->priv->content_type); - g_free (self->priv->description); - g_free (self->priv->filename); - g_free (self->priv->uri); - g_free (self->priv->service_name); - - tp_clear_pointer (&self->priv->address, tp_g_value_slice_free); - tp_clear_pointer (&self->priv->available_socket_types, g_hash_table_unref); - tp_clear_pointer (&self->priv->access_control_param, tp_g_value_slice_free); - tp_clear_pointer (&self->priv->metadata, g_hash_table_unref); - - if (self->priv->unix_address != NULL) - g_unlink (self->priv->unix_address); - - tp_clear_pointer (&self->priv->unix_address, g_free); - - if (self->priv->unix_tmpdir != NULL) - g_rmdir (self->priv->unix_tmpdir); - - tp_clear_pointer (&self->priv->unix_tmpdir, g_free); - - ((GObjectClass *) tp_tests_file_transfer_channel_parent_class)->dispose ( - object); -} - -static void -get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TpTestsFileTransferChannel *self = (TpTestsFileTransferChannel *) object; - - switch (property_id) - { - case PROP_AVAILABLE_SOCKET_TYPES: - g_value_set_boxed (value, self->priv->available_socket_types); - break; - - case PROP_CONTENT_HASH: - g_value_set_string (value, self->priv->content_hash); - - case PROP_CONTENT_HASH_TYPE: - g_value_set_uint (value, self->priv->content_hash_type); - break; - - case PROP_CONTENT_TYPE: - g_value_set_string (value, self->priv->content_type); - break; - - case PROP_DATE: - g_value_set_uint64 (value, self->priv->date); - break; - - case PROP_DESCRIPTION: - g_value_set_string (value, self->priv->description); - break; - - case PROP_FILENAME: - g_value_set_string (value, self->priv->filename); - break; - - case PROP_INITIAL_OFFSET: - g_value_set_uint64 (value, self->priv->initial_offset); - break; - - case PROP_SIZE: - g_value_set_uint64 (value, self->priv->size); - break; - - case PROP_STATE: - g_value_set_uint (value, self->priv->state); - break; - - case PROP_TRANSFERRED_BYTES: - g_value_set_uint64 (value, self->priv->transferred_bytes); - break; - - case PROP_URI: - g_value_set_string (value, self->priv->uri); - break; - - case PROP_SERVICE_NAME: - g_value_set_string (value, self->priv->service_name); - break; - - case PROP_METADATA: - g_value_set_boxed (value, self->priv->metadata); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - TpTestsFileTransferChannel *self = (TpTestsFileTransferChannel *) object; - - switch (property_id) - { - case PROP_AVAILABLE_SOCKET_TYPES: - self->priv->available_socket_types = g_value_dup_boxed (value); - break; - - case PROP_CONTENT_HASH: - self->priv->content_hash = g_value_dup_string (value); - break; - - case PROP_CONTENT_HASH_TYPE: - break; - - case PROP_CONTENT_TYPE: - self->priv->content_type = g_value_dup_string (value); - break; - - case PROP_DATE: - self->priv->date = g_value_get_uint64 (value); - break; - - case PROP_DESCRIPTION: - self->priv->description = g_value_dup_string (value); - break; - - case PROP_FILENAME: - self->priv->filename = g_value_dup_string (value); - break; - - case PROP_INITIAL_OFFSET: - self->priv->initial_offset = g_value_get_uint64 (value); - break; - - case PROP_SIZE: - self->priv->size = g_value_get_uint64 (value); - break; - - case PROP_STATE: - self->priv->state = g_value_get_uint (value); - break; - - case PROP_TRANSFERRED_BYTES: - self->priv->transferred_bytes = g_value_get_uint64 (value); - break; - - case PROP_URI: - self->priv->uri = g_value_dup_string (value); - break; - - case PROP_SERVICE_NAME: - self->priv->service_name = g_value_dup_string (value); - break; - - case PROP_METADATA: - self->priv->metadata = g_value_dup_boxed (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -channel_close (TpBaseChannel *self) -{ - g_print ("entered channel_close"); - tp_base_channel_destroyed (self); -} - -static void -fill_immutable_properties (TpBaseChannel *self, - GHashTable *properties) -{ - TpBaseChannelClass *klass = TP_BASE_CHANNEL_CLASS ( - tp_tests_file_transfer_channel_parent_class); - - klass->fill_immutable_properties (self, properties); - - tp_dbus_properties_mixin_fill_properties_hash ( - G_OBJECT (self), properties, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "AvailableSocketTypes", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "ContentType", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "Filename", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "Size", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "Description", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "Date", - TP_IFACE_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA1, "ServiceName", - TP_IFACE_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA1, "Metadata", - NULL); - - /* URI is immutable only for outgoing transfers */ - if (tp_base_channel_is_requested (self)) - { - tp_dbus_properties_mixin_fill_properties_hash (G_OBJECT (self), - properties, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, "URI", NULL); - } -} - -static void -change_state (TpTestsFileTransferChannel *self, - TpFileTransferState state, - TpFileTransferStateChangeReason reason) -{ - self->priv->state = state; - - tp_svc_channel_type_file_transfer1_emit_file_transfer_state_changed (self, - state, reason); -} - -/* This function imitates the beginning of a filetransfer. It sets the state - * to open, and connects to the "incoming" signal of the GSocketService. - */ -static gboolean -start_file_transfer (gpointer data) -{ - TpTestsFileTransferChannel *self = (TpTestsFileTransferChannel *) data; - - DEBUG ("Setting TP_FILE_TRANSFER_STATE_OPEN"); - change_state (self, TP_FILE_TRANSFER_STATE_OPEN, - TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED); - - g_object_notify ((GObject *) data, "state"); - DEBUG ("Fired state signal"); - -// g_signal_connect (self->priv->service, "incoming", G_CALLBACK -// (incoming_file_transfer_cb)); - - self->priv->timer_id = 0; - return FALSE; -} - -static gboolean -check_address_type (TpTestsFileTransferChannel *self, - TpSocketAddressType address_type, - TpSocketAccessControl access_control) -{ - GArray *arr; - guint i; - - arr = g_hash_table_lookup (self->priv->available_socket_types, - GUINT_TO_POINTER (address_type)); - if (arr == NULL) - return FALSE; - - for (i = 0; i < arr->len; i++) - { - if (g_array_index (arr, TpSocketAccessControl, i) == access_control) - return TRUE; - } - - return FALSE; -} - -static void -service_incoming_cb (GSocketService *service, - GSocketConnection *connection, - GObject *source_object, - gpointer user_data) -{ - TpTestsFileTransferChannel *self = user_data; - GError *error = NULL; - - DEBUG ("Servicing incoming connection"); - if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS) - { - GCredentials *creds; - guchar byte; - - /* TODO: Async version */ - creds = tp_unix_connection_receive_credentials_with_byte ( - connection, &byte, NULL, &error); - g_assert_no_error (error); - - g_assert_cmpuint (byte, ==, - g_value_get_uchar (self->priv->access_control_param)); - g_object_unref (creds); - } - else if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_PORT) - { - GSocketAddress *addr; - guint16 port; - - addr = g_socket_connection_get_remote_address (connection, &error); - g_assert_no_error (error); - - port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)); - - g_assert_cmpuint (port, ==, - g_value_get_uint (self->priv->access_control_param)); - - g_object_unref (addr); - } -} - -static void -file_transfer_provide_file (TpSvcChannelTypeFileTransfer1 *iface, - TpSocketAddressType address_type, - TpSocketAccessControl access_control, - const GValue *access_control_param, - DBusGMethodInvocation *context) -{ - TpTestsFileTransferChannel *self = (TpTestsFileTransferChannel *) iface; - TpBaseChannel *base_chan = (TpBaseChannel *) iface; - GError *error = NULL; - - if (tp_base_channel_is_requested (base_chan) != TRUE) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "File transfer is not outgoing. Cannot offer file"); - goto fail; - } - - if (self->priv->state != TP_FILE_TRANSFER_STATE_PENDING && - self->priv->state != TP_FILE_TRANSFER_STATE_ACCEPTED) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "File transfer is not pending or accepted. Cannot offer file"); - goto fail; - } - - if (self->priv->address != NULL) - { - g_set_error (&error, TP_ERROR, TP_ERROR_NOT_AVAILABLE, - "ProvideFile has already been called for this channel"); - goto fail; - } - - if (!check_address_type (self, address_type, access_control)) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Address type %i is not supported with access control %i", - address_type, access_control); - goto fail; - } - - self->priv->address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, - &self->priv->unix_tmpdir, &error); - - if (self->priv->address == NULL) - { - g_set_error (&error, TP_ERROR, TP_ERROR_NOT_AVAILABLE, - "Could not set up local socket"); - goto fail; - } - - self->priv->address_type = address_type; - self->priv->access_control = access_control; - - DEBUG ("Waiting 500ms and setting state to OPEN"); - self->priv->timer_id = g_timeout_add (500, start_file_transfer, self); - - // connect to self->priv->service incoming signal - // when the signal returns, add x bytes per n seconds using timeout - // then close the socket - // g_output_stream_write_async - - tp_svc_channel_type_file_transfer1_return_from_provide_file (context, - self->priv->address); - - return; - -fail: - dbus_g_method_return_error (context, error); - g_error_free (error); -} - -static void -file_transfer_accept_file (TpSvcChannelTypeFileTransfer1 *iface, - TpSocketAddressType address_type, - TpSocketAccessControl access_control, - const GValue *access_control_param, - guint64 offset, - DBusGMethodInvocation *context) -{ - TpTestsFileTransferChannel *self = (TpTestsFileTransferChannel *) iface; - TpBaseChannel *base_chan = (TpBaseChannel *) iface; - GError *error = NULL; - GValue *address; - - if (tp_base_channel_is_requested (base_chan) == TRUE) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "File transfer is not incoming. Cannot accept file"); - goto fail; - } - - if (self->priv->state != TP_FILE_TRANSFER_STATE_PENDING) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "File transfer is not in the pending state"); - goto fail; - } - - if (!check_address_type (self, address_type, access_control)) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Address type %i is not supported with access control %i", - address_type, access_control); - goto fail; - } - - address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, - &self->priv->unix_tmpdir, &error); - - tp_g_signal_connect_object (self->priv->service, "incoming", - G_CALLBACK (service_incoming_cb), self, 0); - - self->priv->access_control = access_control; - self->priv->access_control_param = tp_g_value_slice_dup ( - access_control_param); - - DEBUG ("Setting TP_FILE_TRANSFER_STATE_ACCEPTED"); - change_state (self, TP_FILE_TRANSFER_STATE_ACCEPTED, - TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED); - - DEBUG ("Waiting 500ms and setting state to OPEN"); - self->priv->timer_id = g_timeout_add (500, start_file_transfer, self); - - tp_svc_channel_type_file_transfer1_return_from_accept_file (context, - address); - - tp_clear_pointer (&address, tp_g_value_slice_free); - - return; - -fail: - dbus_g_method_return_error (context, error); - g_error_free (error); -} - -static void -tp_tests_file_transfer_channel_class_init ( - TpTestsFileTransferChannelClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - GParamSpec *param_spec; - - static TpDBusPropertiesMixinPropImpl file_transfer_props[] = { - { "AvailableSocketTypes", "available-socket-types", NULL }, - { "ContentType", "content-type", NULL }, - { "Date", "date", NULL }, - { "Description", "description", NULL }, - { "Filename", "filename", NULL }, - { "Size", "size", NULL }, - { "State", "state", NULL }, - { "TransferredBytes", "transferred-bytes", NULL }, - { "URI", "uri", NULL }, - { NULL } - }; - - static TpDBusPropertiesMixinPropImpl metadata_props[] = { - { "ServiceName", "service-name", NULL }, - { "Metadata", "metadata", NULL }, - { NULL } - }; - - object_class->constructor = constructor; - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->dispose = dispose; - - base_class->channel_type = TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1; - base_class->target_entity_type = TP_ENTITY_TYPE_CONTACT; - - base_class->close = channel_close; - base_class->fill_immutable_properties = fill_immutable_properties; - - param_spec = g_param_spec_boxed ("available-socket-types", - "AvailableSocketTypes", - "The AvailableSocketTypes property of this channel", - TP_HASH_TYPE_SUPPORTED_SOCKET_MAP, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_AVAILABLE_SOCKET_TYPES, - param_spec); - - param_spec = g_param_spec_string ("content-type", - "ContentType", - "The ContentType property of this channel", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONTENT_TYPE, - param_spec); - - param_spec = g_param_spec_uint64 ("date", - "Date", - "The Date property of this channel", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DATE, - param_spec); - - param_spec = g_param_spec_string ("description", - "Description", - "The Description property of this channel", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DESCRIPTION, - param_spec); - - param_spec = g_param_spec_string ("filename", - "Filename", - "The Filename property of this channel", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_FILENAME, - param_spec); - - param_spec = g_param_spec_uint64 ("initial-offset", - "InitialOffset", - "The InitialOffset property of this channel", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INITIAL_OFFSET, - param_spec); - - param_spec = g_param_spec_uint64 ("size", - "Size", - "The Size property of this channel", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SIZE, - param_spec); - - param_spec = g_param_spec_uint ("state", - "State", - "The State property of this channel", - 0, TP_NUM_FILE_TRANSFER_STATES, TP_FILE_TRANSFER_STATE_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STATE, - param_spec); - - param_spec = g_param_spec_uint64 ("transferred-bytes", - "TransferredBytes", - "The TransferredBytes property of this channel", - 0, G_MAXUINT64, 0, - G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TRANSFERRED_BYTES, - param_spec); - - param_spec = g_param_spec_string ("uri", - "URI", - "The URI property of this channel", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_URI, - param_spec); - - param_spec = g_param_spec_string ("service-name", - "ServiceName", - "The Metadata.ServiceName property of this channel", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SERVICE_NAME, - param_spec); - - param_spec = g_param_spec_boxed ("metadata", - "Metadata", - "The Metadata.Metadata property of this channel", - TP_HASH_TYPE_METADATA, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_METADATA, - param_spec); - - tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - file_transfer_props); - - tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - metadata_props); - - g_type_class_add_private (object_class, - sizeof (TpTestsFileTransferChannelPrivate)); -} - -static void -file_transfer_iface_init (gpointer iface, gpointer data) -{ - TpSvcChannelTypeFileTransfer1Class *klass = iface; - -#define IMPLEMENT(x) tp_svc_channel_type_file_transfer1_implement_##x (klass, \ - file_transfer_##x) - IMPLEMENT(accept_file); - IMPLEMENT(provide_file); -#undef IMPLEMENT -} - -/* Return the address of the file transfer's socket */ -GSocketAddress * -tp_tests_file_transfer_channel_get_server_address ( - TpTestsFileTransferChannel *self) -{ - GSocketAddress *address; - GError *error = NULL; - - g_assert (self->priv->address != NULL); - - address = tp_g_socket_address_from_variant (self->priv->address_type, - self->priv->address, &error); - - if (error != NULL) - { - g_printf ("%s\n", error->message); - } - - return address; -} diff --git a/tests/lib/telepathy/contactlist/file-transfer-chan.h b/tests/lib/telepathy/contactlist/file-transfer-chan.h deleted file mode 100644 index 19d6c98a..00000000 --- a/tests/lib/telepathy/contactlist/file-transfer-chan.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * stream-tube-chan.h - Simple stream tube channel - * - * Copyright (C) 2010-2011 Morten Mjelva <morten.mjelva@gmail.com> - * Copyright (C) 2010-2011 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_FILE_TRANSFER_CHAN_H__ -#define __TP_FILE_TRANSFER_CHAN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsFileTransferChannel TpTestsFileTransferChannel; -typedef struct _TpTestsFileTransferChannelClass TpTestsFileTransferChannelClass; -typedef struct _TpTestsFileTransferChannelPrivate TpTestsFileTransferChannelPrivate; - -GType tp_tests_file_transfer_channel_get_type (void); - -#define TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL \ - (tp_tests_file_transfer_channel_get_type ()) -#define TP_TESTS_FILE_TRANSFER_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL, \ - TpTestsFileTransferChannel)) -#define TP_TESTS_FILE_TRANSFER_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL, \ - TpTestsFileTransferChannelClass)) -#define TP_TESTS_IS_FILE_TRANSFER_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL)) -#define TP_TESTS_IS_FILE_TRANSFER_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL)) -#define TP_TESTS_FILE_TRANSFER_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_FILE_TRANSFER_CHANNEL, \ - TpTestsFileTransferChannelClass)) - -struct _TpTestsFileTransferChannelClass { - TpBaseChannelClass parent_class; - TpDBusPropertiesMixinClass dbus_properties_class; -}; - -struct _TpTestsFileTransferChannel { - TpBaseChannel parent; - - TpTestsFileTransferChannelPrivate *priv; -}; - -void tp_tests_file_transfer_channel_close (TpTestsFileTransferChannel *self); - -GHashTable * tp_tests_file_transfer_channel_get_props ( - TpTestsFileTransferChannel *self); - -GSocketAddress * tp_tests_file_transfer_channel_get_server_address ( - TpTestsFileTransferChannel *self); - -G_END_DECLS - -#endif diff --git a/tests/lib/telepathy/contactlist/my-conn-proxy.c b/tests/lib/telepathy/contactlist/my-conn-proxy.c deleted file mode 100644 index 0d7723c4..00000000 --- a/tests/lib/telepathy/contactlist/my-conn-proxy.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * my-conn-proxy.c - a simple subclass of TpConnection - * - * Copyright (C) 2010-2011 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "my-conn-proxy.h" - -#include <telepathy-glib/telepathy-glib.h> - -G_DEFINE_TYPE (TpTestsMyConnProxy, tp_tests_my_conn_proxy, - TP_TYPE_CONNECTION) - -static void -tp_tests_my_conn_proxy_init (TpTestsMyConnProxy *self) -{ -} - -enum { - FEAT_CORE, - FEAT_A, - FEAT_B, - FEAT_WRONG_IFACE, - FEAT_BAD_DEP, - FEAT_FAIL, - FEAT_FAIL_DEP, - FEAT_RETRY, - FEAT_RETRY_DEP, - FEAT_BEFORE_CONNECTED, - FEAT_INTERFACE_LATER, - N_FEAT -}; - -static void -prepare_core_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - - /* superclass core features are prepared first */ - g_assert (tp_proxy_is_prepared (proxy, TP_CONNECTION_FEATURE_CORE)); - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_core_async); - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_a_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_a_async); - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_b_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_A)); - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_b_async); - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -cannot_be_prepared_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_assert_not_reached (); -} - -static void -prepare_fail_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); - - result = g_simple_async_result_new_error ((GObject *) proxy, callback, - user_data, TP_ERROR, TP_ERROR_NOT_AVAILABLE, - "No feature for you!"); - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_retry_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TpTestsMyConnProxy *self = (TpTestsMyConnProxy *) proxy; - GSimpleAsyncResult *result; - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_retry_async); - - if (!self->retry_feature_success) - { - /* Fail the first time we try to prepare the feature */ - g_simple_async_result_set_error (result, TP_ERROR, - TP_ERROR_NOT_YET, "Nah"); - } - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_retry_dep_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_retry_dep_async); - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_before_connected_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TpTestsMyConnProxy *self = (TpTestsMyConnProxy *) proxy; - GSimpleAsyncResult *result; - - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_before_connected_async); - - if (tp_connection_get_status (TP_CONNECTION (self), NULL) == - TP_CONNECTION_STATUS_CONNECTED) - self->before_connected_state = BEFORE_CONNECTED_STATE_CONNECTED; - else - self->before_connected_state = BEFORE_CONNECTED_STATE_NOT_CONNECTED; - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_before_connected_before_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TpTestsMyConnProxy *self = (TpTestsMyConnProxy *) proxy; - GSimpleAsyncResult *result; - - g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); - - g_assert_cmpuint (tp_connection_get_status (TP_CONNECTION (proxy), NULL), ==, - TP_CONNECTION_STATUS_CONNECTING); - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_before_connected_before_async); - - self->before_connected_state = BEFORE_CONNECTED_STATE_CONNECTED; - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static void -prepare_interface_later_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - - result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, - prepare_interface_later_async); - - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); -} - -static const TpProxyFeature * -list_features (TpProxyClass *cls G_GNUC_UNUSED) -{ - static TpProxyFeature features[N_FEAT + 1] = { { 0 } }; - static GQuark need_a[2] = {0, 0}; - static GQuark need_channel_core[2] = {0, 0}; - static GQuark need_wrong_iface[2] = {0, 0}; - static GQuark need_fail[2] = {0, 0}; - static GQuark need_retry[2] = {0, 0}; - static GQuark need_iface_later[2] = {0, 0}; - - if (G_LIKELY (features[0].name != 0)) - return features; - - features[FEAT_CORE].name = TP_TESTS_MY_CONN_PROXY_FEATURE_CORE; - features[FEAT_CORE].core = TRUE; - features[FEAT_CORE].prepare_async = prepare_core_async; - - features[FEAT_A].name = TP_TESTS_MY_CONN_PROXY_FEATURE_A; - features[FEAT_A].prepare_async = prepare_a_async; - - features[FEAT_B].name = TP_TESTS_MY_CONN_PROXY_FEATURE_B; - features[FEAT_B].prepare_async = prepare_b_async; - need_a[0] = TP_TESTS_MY_CONN_PROXY_FEATURE_A; - features[FEAT_B].depends_on = need_a; - - features[FEAT_WRONG_IFACE].name = TP_TESTS_MY_CONN_PROXY_FEATURE_WRONG_IFACE; - features[FEAT_WRONG_IFACE].prepare_async = cannot_be_prepared_async; - need_channel_core[0] = TP_CHANNEL_FEATURE_CORE; - features[FEAT_WRONG_IFACE].interfaces_needed = need_channel_core; - - features[FEAT_BAD_DEP].name = TP_TESTS_MY_CONN_PROXY_FEATURE_BAD_DEP; - features[FEAT_BAD_DEP].prepare_async = cannot_be_prepared_async; - need_wrong_iface[0] = TP_TESTS_MY_CONN_PROXY_FEATURE_WRONG_IFACE; - features[FEAT_BAD_DEP].depends_on = need_wrong_iface; - - features[FEAT_FAIL].name = TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL; - features[FEAT_FAIL].prepare_async = prepare_fail_async; - - features[FEAT_FAIL_DEP].name = TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL_DEP; - features[FEAT_FAIL_DEP].prepare_async = cannot_be_prepared_async; - need_fail[0] = TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL; - features[FEAT_FAIL_DEP].depends_on = need_fail; - - features[FEAT_RETRY].name = TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY; - features[FEAT_RETRY].prepare_async = prepare_retry_async; - features[FEAT_RETRY].can_retry = TRUE; - - features[FEAT_RETRY_DEP].name = TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY_DEP; - need_retry[0] = TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY; - features[FEAT_RETRY_DEP].prepare_async = prepare_retry_dep_async; - features[FEAT_RETRY_DEP].depends_on = need_retry; - - features[FEAT_BEFORE_CONNECTED].name = - TP_TESTS_MY_CONN_PROXY_FEATURE_BEFORE_CONNECTED; - features[FEAT_BEFORE_CONNECTED].prepare_async = - prepare_before_connected_async; - features[FEAT_BEFORE_CONNECTED].prepare_before_signalling_connected_async = - prepare_before_connected_before_async; - - features[FEAT_INTERFACE_LATER].name = - TP_TESTS_MY_CONN_PROXY_FEATURE_INTERFACE_LATER; - features[FEAT_INTERFACE_LATER].prepare_async = prepare_interface_later_async; - need_iface_later[0] = g_quark_from_static_string ( - TP_TESTS_MY_CONN_PROXY_IFACE_LATER); - features[FEAT_INTERFACE_LATER].interfaces_needed = need_iface_later; - - return features; -} - -static void -tp_tests_my_conn_proxy_class_init (TpTestsMyConnProxyClass *klass) -{ - TpProxyClass *proxy_class = (TpProxyClass *) klass; - - proxy_class->list_features = list_features; -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_core (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-core"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_a (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-a"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_b (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-b"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_wrong_iface (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-wrong_iface"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_bad_dep (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-bad-dep"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_fail (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-fail"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_fail_dep (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-fail-dep"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_retry (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-retry"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_retry_dep (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-retry-dep"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_before_connected (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-before-connected"); -} - -GQuark -tp_tests_my_conn_proxy_get_feature_quark_interface_later (void) -{ - return g_quark_from_static_string ("tp-my-conn-proxy-feature-interface-later"); -} diff --git a/tests/lib/telepathy/contactlist/my-conn-proxy.h b/tests/lib/telepathy/contactlist/my-conn-proxy.h deleted file mode 100644 index 08be18b9..00000000 --- a/tests/lib/telepathy/contactlist/my-conn-proxy.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * my-conn-proxy.h - header for a simple subclass of TpConnection - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_MY_CONN_PROXY_H__ -#define __TP_TESTS_MY_CONN_PROXY_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - - -G_BEGIN_DECLS - -typedef struct _TpTestsMyConnProxy TpTestsMyConnProxy; -typedef struct _TpTestsMyConnProxyClass TpTestsMyConnProxyClass; -typedef struct _TpTestsMyConnProxyPrivate TpTestsMyConnProxyPrivate; - -struct _TpTestsMyConnProxyClass { - TpConnectionClass parent_class; -}; - -typedef enum -{ - BEFORE_CONNECTED_STATE_UNPREPARED = 0, - BEFORE_CONNECTED_STATE_NOT_CONNECTED, - BEFORE_CONNECTED_STATE_CONNECTED, -} TpTestsMyConnProxyBeforeConnectedState; - - -struct _TpTestsMyConnProxy { - TpConnection parent; - - gboolean retry_feature_success; - TpTestsMyConnProxyBeforeConnectedState before_connected_state; -}; - -GType tp_tests_my_conn_proxy_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_MY_CONN_PROXY \ - (tp_tests_my_conn_proxy_get_type ()) -#define TP_TESTS_MY_CONN_PROXY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_MY_CONN_PROXY, \ - TpTestsMyConnProxy)) -#define TP_TESTS_MY_CONN_PROXY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_MY_CONN_PROXY, \ - TpTestsMyConnProxyClass)) -#define TP_TESTS_SIMPLE_IS_MY_CONN_PROXY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_MY_CONN_PROXY)) -#define TP_TESTS_SIMPLE_IS_MY_CONN_PROXY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_MY_CONN_PROXY)) -#define TP_TESTS_MY_CONN_PROXY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_MY_CONN_PROXY, \ - TpTestsMyConnProxyClass)) - -/* Core feature */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_CORE \ - (tp_tests_my_conn_proxy_get_feature_quark_core ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_core (void) G_GNUC_CONST; - -/* No depends */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_A \ - (tp_tests_my_conn_proxy_get_feature_quark_a ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_a (void) G_GNUC_CONST; - -/* Depends on A */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_B \ - (tp_tests_my_conn_proxy_get_feature_quark_b ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_b (void) G_GNUC_CONST; - -/* Depends on an unimplemented iface */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_WRONG_IFACE \ - (tp_tests_my_conn_proxy_get_feature_quark_wrong_iface ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_wrong_iface (void) G_GNUC_CONST; - -/* Depends on WRONG_IFACE */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_BAD_DEP \ - (tp_tests_my_conn_proxy_get_feature_quark_bad_dep ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_bad_dep (void) G_GNUC_CONST; - -/* Fail during preparation */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL \ - (tp_tests_my_conn_proxy_get_feature_quark_fail ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_fail (void) G_GNUC_CONST; - -/* Depends on FAIL */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL_DEP \ - (tp_tests_my_conn_proxy_get_feature_quark_fail_dep ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_fail_dep (void) G_GNUC_CONST; - -/* Fail at first attempt but succeed after */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY \ - (tp_tests_my_conn_proxy_get_feature_quark_retry ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_retry (void) G_GNUC_CONST; - -/* Depends on FEATURE_RETRY */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY_DEP \ - (tp_tests_my_conn_proxy_get_feature_quark_retry_dep ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_retry_dep (void) G_GNUC_CONST; - -/* Can be prepared before the connection is connected and block announcing the - * connected state */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_BEFORE_CONNECTED \ - (tp_tests_my_conn_proxy_get_feature_quark_before_connected ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_before_connected (void) G_GNUC_CONST; - -#define TP_TESTS_MY_CONN_PROXY_IFACE_LATER "org.freedesktop.Telepathy.Conncetion.Interface.Test.Later" - -/* Need the interface TP_TESTS_MY_CONN_PROXY_IFACE_LATER to be prepared but - * this interface is not in the initial set of interfaces of the connection. - * It is added when the connection is connected. */ -#define TP_TESTS_MY_CONN_PROXY_FEATURE_INTERFACE_LATER \ - (tp_tests_my_conn_proxy_get_feature_quark_interface_later ()) -GQuark tp_tests_my_conn_proxy_get_feature_quark_interface_later (void) G_GNUC_CONST; - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_MY_CONN_PROXY_H__ */ diff --git a/tests/lib/telepathy/contactlist/myassert.h b/tests/lib/telepathy/contactlist/myassert.h deleted file mode 100644 index 1fd6fd3b..00000000 --- a/tests/lib/telepathy/contactlist/myassert.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TP_TESTS_MYASSERT_H -#define TP_TESTS_MYASSERT_H - -#include <glib.h> -#include <telepathy-glib/telepathy-glib.h> - -#define MYASSERT(assertion, extra_format, ...)\ - G_STMT_START {\ - if (!(assertion))\ - {\ - g_error ("\n%s:%d: Assertion failed: %s" extra_format,\ - __FILE__, __LINE__, #assertion, ##__VA_ARGS__);\ - }\ - } G_STMT_END - -#endif diff --git a/tests/lib/telepathy/contactlist/simple-channel-dispatch-operation.c b/tests/lib/telepathy/contactlist/simple-channel-dispatch-operation.c deleted file mode 100644 index 82b38197..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-dispatch-operation.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * simple-channel-dispatch-operation.c - a simple channel dispatch operation - * service. - * - * Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "simple-channel-dispatch-operation.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -static void channel_dispatch_operation_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelDispatchOperation, - tp_tests_simple_channel_dispatch_operation, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_DISPATCH_OPERATION, - channel_dispatch_operation_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init) - ) - -/* TP_IFACE_CHANNEL_DISPATCH_OPERATION is implied */ -static const char *CHANNEL_DISPATCH_OPERATION_INTERFACES[] = { NULL }; - -static const gchar *CHANNEL_DISPATCH_OPERATION_POSSIBLE_HANDLERS[] = { - TP_CLIENT_BUS_NAME_BASE ".Badger", NULL, }; - -enum -{ - PROP_0, - PROP_INTERFACES, - PROP_CONNECTION, - PROP_ACCOUNT, - PROP_CHANNELS, - PROP_POSSIBLE_HANDLERS, -}; - -struct _SimpleChannelDispatchOperationPrivate -{ - gchar *conn_path; - gchar *account_path; - /* Array of TpChannel */ - GPtrArray *channels; -}; - -static void -tp_tests_simple_channel_dispatch_operation_handle_with ( - TpSvcChannelDispatchOperation *iface, - const gchar *handler, - DBusGMethodInvocation *context) -{ - if (!tp_strdiff (handler, "FAIL")) - { - GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "Nope" }; - - dbus_g_method_return_error (context, &error); - return; - } - - dbus_g_method_return (context); -} - -static void -tp_tests_simple_channel_dispatch_operation_claim ( - TpSvcChannelDispatchOperation *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_dispatch_operation_emit_finished (iface); - - dbus_g_method_return (context); -} - -static void -tp_tests_simple_channel_dispatch_operation_handle_with_time ( - TpSvcChannelDispatchOperation *iface, - const gchar *handler, - gint64 user_action_timestamp, - DBusGMethodInvocation *context) -{ - dbus_g_method_return (context); -} - -static void -channel_dispatch_operation_iface_init (gpointer klass, - gpointer unused G_GNUC_UNUSED) -{ -#define IMPLEMENT(x) tp_svc_channel_dispatch_operation_implement_##x (\ - klass, tp_tests_simple_channel_dispatch_operation_##x) - IMPLEMENT(handle_with); - IMPLEMENT(claim); - IMPLEMENT(handle_with_time); -#undef IMPLEMENT -} - - -static void -tp_tests_simple_channel_dispatch_operation_init (TpTestsSimpleChannelDispatchOperation *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION, - TpTestsSimpleChannelDispatchOperationPrivate); - - self->priv->channels = g_ptr_array_new_with_free_func ( - (GDestroyNotify) g_object_unref); -} - -static void -tp_tests_simple_channel_dispatch_operation_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleChannelDispatchOperation *self = - TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION (object); - - switch (property_id) { - case PROP_INTERFACES: - g_value_set_boxed (value, CHANNEL_DISPATCH_OPERATION_INTERFACES); - break; - - case PROP_ACCOUNT: - g_value_set_boxed (value, self->priv->account_path); - break; - - case PROP_CONNECTION: - g_value_set_boxed (value, self->priv->conn_path); - break; - - case PROP_CHANNELS: - { - GPtrArray *arr = g_ptr_array_new (); - guint i; - - for (i = 0; i < self->priv->channels->len; i++) - { - TpChannel *channel = g_ptr_array_index (self->priv->channels, i); - GValue props_value = G_VALUE_INIT; - GVariant *props_variant; - - /* Yay, double conversion! But this is for tests corner case */ - props_variant = tp_channel_dup_immutable_properties (channel); - dbus_g_value_parse_g_variant (props_variant, &props_value); - - g_ptr_array_add (arr, - tp_value_array_build (2, - DBUS_TYPE_G_OBJECT_PATH, tp_proxy_get_object_path (channel), - TP_HASH_TYPE_STRING_VARIANT_MAP, - g_value_get_boxed (&props_value), - G_TYPE_INVALID)); - - g_variant_unref (props_variant); - g_value_unset (&props_value); - } - - g_value_take_boxed (value, arr); - } - break; - - case PROP_POSSIBLE_HANDLERS: - g_value_set_boxed (value, CHANNEL_DISPATCH_OPERATION_POSSIBLE_HANDLERS); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_channel_dispatch_operation_finalize (GObject *object) -{ - TpTestsSimpleChannelDispatchOperation *self = - TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION (object); - void (*finalize) (GObject *) = - G_OBJECT_CLASS (tp_tests_simple_channel_dispatch_operation_parent_class)->finalize; - - g_free (self->priv->conn_path); - g_free (self->priv->account_path); - g_ptr_array_unref (self->priv->channels); - - if (finalize != NULL) - finalize (object); -} - -/** - * This class currently only provides the minimum for - * tp_channel_dispatch_operation_prepare to succeed. This turns out to be only a working - * Properties.GetAll(). - */ -static void -tp_tests_simple_channel_dispatch_operation_class_init (TpTestsSimpleChannelDispatchOperationClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - static TpDBusPropertiesMixinPropImpl a_props[] = { - { "Interfaces", "interfaces", NULL }, - { "Connection", "connection", NULL }, - { "Account", "account", NULL }, - { "Channels", "channels", NULL }, - { "PossibleHandlers", "possible-handlers", NULL }, - { NULL } - }; - - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CHANNEL_DISPATCH_OPERATION, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - a_props - }, - { NULL }, - }; - - g_type_class_add_private (klass, sizeof (TpTestsSimpleChannelDispatchOperationPrivate)); - object_class->get_property = tp_tests_simple_channel_dispatch_operation_get_property; - object_class->finalize = tp_tests_simple_channel_dispatch_operation_finalize; - - param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", - "In this case we only implement ChannelDispatchOperation, so none.", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); - - param_spec = g_param_spec_boxed ("connection", "connection path", - "Connection path", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION, param_spec); - - param_spec = g_param_spec_boxed ("account", "account path", - "Account path", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_boxed ("channels", "channel paths", - "Channel paths", - TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CHANNELS, param_spec); - - param_spec = g_param_spec_boxed ("possible-handlers", "possible handlers", - "possible handles", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_POSSIBLE_HANDLERS, - param_spec); - - klass->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsSimpleChannelDispatchOperationClass, dbus_props_class)); -} - -void -tp_tests_simple_channel_dispatch_operation_set_conn_path ( - TpTestsSimpleChannelDispatchOperation *self, - const gchar *conn_path) -{ - self->priv->conn_path = g_strdup (conn_path); -} - -void -tp_tests_simple_channel_dispatch_operation_add_channel ( - TpTestsSimpleChannelDispatchOperation *self, - TpChannel *chan) -{ - g_ptr_array_add (self->priv->channels, g_object_ref (chan)); -} - -void -tp_tests_simple_channel_dispatch_operation_lost_channel ( - TpTestsSimpleChannelDispatchOperation *self, - TpChannel *chan) -{ - const gchar *path = tp_proxy_get_object_path (chan); - - g_ptr_array_remove (self->priv->channels, chan); - - tp_svc_channel_dispatch_operation_emit_channel_lost (self, path, - TP_ERROR_STR_NOT_AVAILABLE, "Badger"); - - if (self->priv->channels->len == 0) - { - /* We removed the last channel; fire Finished */ - tp_svc_channel_dispatch_operation_emit_finished (self); - } -} - -void -tp_tests_simple_channel_dispatch_operation_set_account_path ( - TpTestsSimpleChannelDispatchOperation *self, - const gchar *account_path) -{ - self->priv->account_path = g_strdup (account_path); -} diff --git a/tests/lib/telepathy/contactlist/simple-channel-dispatch-operation.h b/tests/lib/telepathy/contactlist/simple-channel-dispatch-operation.h deleted file mode 100644 index 3e9ee934..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-dispatch-operation.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * simple-channel-dispatch-operation.h - a simple channel dispatch operation - * service. - * - * Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION_H__ -#define __TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _SimpleChannelDispatchOperation TpTestsSimpleChannelDispatchOperation; -typedef struct _SimpleChannelDispatchOperationClass TpTestsSimpleChannelDispatchOperationClass; -typedef struct _SimpleChannelDispatchOperationPrivate TpTestsSimpleChannelDispatchOperationPrivate; - -struct _SimpleChannelDispatchOperationClass { - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; -}; - -struct _SimpleChannelDispatchOperation { - GObject parent; - - TpTestsSimpleChannelDispatchOperationPrivate *priv; -}; - -GType tp_tests_simple_channel_dispatch_operation_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION \ - (tp_tests_simple_channel_dispatch_operation_get_type ()) -#define TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION, \ - TpTestsSimpleChannelDispatchOperation)) -#define TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION, \ - TpTestsSimpleChannelDispatchOperationClass)) -#define SIMPLE_IS_CHANNEL_DISPATCH_OPERATION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION)) -#define SIMPLE_IS_CHANNEL_DISPATCH_OPERATION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION)) -#define TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION, \ - TpTestsSimpleChannelDispatchOperationClass)) - -void tp_tests_simple_channel_dispatch_operation_set_conn_path ( - TpTestsSimpleChannelDispatchOperation *self, - const gchar *conn_path); - -void tp_tests_simple_channel_dispatch_operation_add_channel ( - TpTestsSimpleChannelDispatchOperation *self, - TpChannel *chan); - -void tp_tests_simple_channel_dispatch_operation_lost_channel ( - TpTestsSimpleChannelDispatchOperation *self, - TpChannel *chan); - -void tp_tests_simple_channel_dispatch_operation_set_account_path ( - TpTestsSimpleChannelDispatchOperation *self, - const gchar *account_path); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION_H__ */ diff --git a/tests/lib/telepathy/contactlist/simple-channel-dispatcher.c b/tests/lib/telepathy/contactlist/simple-channel-dispatcher.c deleted file mode 100644 index 775f915e..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-dispatcher.c +++ /dev/null @@ -1,394 +0,0 @@ -/* - * simple-channel-dispatcher.c - simple channel dispatcher service. - * - * Copyright © 2010 Collabora Ltd. - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "simple-channel-dispatcher.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "simple-channel-request.h" -#include "simple-conn.h" - -static void channel_dispatcher_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelDispatcher, - tp_tests_simple_channel_dispatcher, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_DISPATCHER, - channel_dispatcher_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init) - ) - -/* signals */ -enum { - CHANNEL_REQUEST_CREATED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -/* TP_IFACE_CHANNEL_DISPATCHER is implied */ -static const char *CHANNEL_DISPATCHER_INTERFACES[] = { NULL }; - -enum -{ - PROP_0, - PROP_INTERFACES, - PROP_CONNECTION, -}; - -struct _TpTestsSimpleChannelDispatcherPrivate -{ - /* To keep things simpler, this CD can only create channels using one - * connection */ - TpTestsSimpleConnection *conn; - - /* List of reffed TpTestsSimpleChannelRequest */ - GSList *requests; - - /* Used when ensuring a channel to store its handler. - * If this is set we fake that the channel already exist and re-call - * HandleChannels() on the handler rather than creating a new channel. - * This is pretty stupid but good enough for our tests. */ - gchar *old_handler; -}; - -static gchar * -create_channel_request (TpTestsSimpleChannelDispatcher *self, - const gchar *account, - GHashTable *request, - gint64 user_action_time, - const gchar *preferred_handler, - GHashTable *hints_, - GHashTable **out_immutable_properties) -{ - TpTestsSimpleChannelRequest *chan_request; - GPtrArray *requests; - static guint count = 0; - gchar *path; - TpDBusDaemon *dbus; - GHashTable *hints; - - requests = g_ptr_array_sized_new (1); - g_ptr_array_add (requests, request); - - path = g_strdup_printf ("/Request%u", count++); - - if (hints_ == NULL) - hints = g_hash_table_new (NULL, NULL); - else - hints = g_hash_table_ref (hints_); - - chan_request = tp_tests_simple_channel_request_new (path, - self->priv->conn, account, user_action_time, preferred_handler, requests, - hints); - - g_hash_table_unref (hints); - - self->priv->requests = g_slist_append (self->priv->requests, chan_request); - - g_ptr_array_unref (requests); - - dbus = tp_dbus_daemon_dup (NULL); - g_assert (dbus != NULL); - - tp_dbus_daemon_register_object (dbus, path, chan_request); - - g_object_unref (dbus); - - g_signal_emit (self, signals[CHANNEL_REQUEST_CREATED], 0, chan_request); - - *out_immutable_properties = - tp_tests_simple_channel_request_dup_immutable_props (chan_request); - - return path; -} - -static void -tp_tests_simple_channel_dispatcher_create_channel ( - TpSvcChannelDispatcher *dispatcher, - const gchar *account, - GHashTable *request, - gint64 user_action_time, - const gchar *preferred_handler, - GHashTable *hints, - DBusGMethodInvocation *context) -{ - TpTestsSimpleChannelDispatcher *self = SIMPLE_CHANNEL_DISPATCHER (dispatcher); - gchar *path; - GHashTable *immutable_properties; - - tp_clear_pointer (&self->last_request, g_hash_table_unref); - self->last_request = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, request); - tp_clear_pointer (&self->last_hints, g_hash_table_unref); - self->last_hints = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, request); - self->last_user_action_time = user_action_time; - g_free (self->last_account); - self->last_account = g_strdup (account); - g_free (self->last_preferred_handler); - self->last_preferred_handler = g_strdup (preferred_handler); - - if (tp_asv_get_boolean (request, "CreateChannelFail", NULL)) - { - /* Fail to create the channel */ - GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Computer says no" }; - - dbus_g_method_return_error (context, &error); - return; - } - - path = create_channel_request (self, account, request, user_action_time, - preferred_handler, hints, &immutable_properties); - - if (path == NULL) - return; - - tp_svc_channel_dispatcher_return_from_create_channel (context, - path, immutable_properties); - - g_free (path); - g_hash_table_unref (immutable_properties); -} - -static void -tp_tests_simple_channel_dispatcher_ensure_channel ( - TpSvcChannelDispatcher *dispatcher, - const gchar *account, - GHashTable *request, - gint64 user_action_time, - const gchar *preferred_handler, - GHashTable *hints, - DBusGMethodInvocation *context) -{ - TpTestsSimpleChannelDispatcher *self = SIMPLE_CHANNEL_DISPATCHER (dispatcher); - gchar *path; - GHashTable *immutable_properties; - - tp_clear_pointer (&self->last_request, g_hash_table_unref); - self->last_request = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, request); - tp_clear_pointer (&self->last_hints, g_hash_table_unref); - self->last_hints = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, request); - self->last_user_action_time = user_action_time; - g_free (self->last_account); - self->last_account = g_strdup (account); - g_free (self->last_preferred_handler); - self->last_preferred_handler = g_strdup (preferred_handler); - - if (self->priv->old_handler != NULL) - { - /* Pretend that the channel already exists */ - path = create_channel_request (self, account, request, user_action_time, - self->priv->old_handler, hints, &immutable_properties); - } - else - { - self->priv->old_handler = g_strdup (preferred_handler); - - path = create_channel_request (self, account, request, user_action_time, - preferred_handler, hints, &immutable_properties); - } - - tp_svc_channel_dispatcher_return_from_ensure_channel (context, - path, immutable_properties); - - g_free (path); - g_hash_table_unref (immutable_properties); -} - -static void -free_not_delegated_error (gpointer data) -{ - g_boxed_free (TP_STRUCT_TYPE_NOT_DELEGATED_ERROR, data); -} - - -static void -tp_tests_simple_channel_dispatcher_delegate_channels ( - TpSvcChannelDispatcher *dispatcher, - const GPtrArray *channels, - gint64 user_action_time, - const gchar *preferred_handler, - DBusGMethodInvocation *context) -{ - TpTestsSimpleChannelDispatcher *self = (TpTestsSimpleChannelDispatcher *) - dispatcher; - GPtrArray *delegated; - GHashTable *not_delegated; - guint i; - - delegated = g_ptr_array_new (); - not_delegated = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, free_not_delegated_error); - - for (i = 0; i < channels->len; i++) - { - gpointer chan_path = g_ptr_array_index (channels, i); - GValueArray *v; - - if (!self->refuse_delegate) - { - g_ptr_array_add (delegated, chan_path); - continue; - } - - v = tp_value_array_build (2, - G_TYPE_STRING, TP_ERROR_STR_BUSY, - G_TYPE_STRING, "Nah!", - G_TYPE_INVALID); - - g_hash_table_insert (not_delegated, chan_path, v); - } - - tp_svc_channel_dispatcher_return_from_delegate_channels (context, delegated, - not_delegated); - - g_ptr_array_unref (delegated); - g_hash_table_unref (not_delegated); -} - -static void -tp_tests_simple_channel_dispatcher_present_channel ( - TpSvcChannelDispatcher *dispatcher, - const gchar *channel, - gint64 user_action_time, - DBusGMethodInvocation *context) -{ - tp_svc_channel_dispatcher_return_from_present_channel (context); -} - -static void -channel_dispatcher_iface_init (gpointer klass, - gpointer unused G_GNUC_UNUSED) -{ -#define IMPLEMENT(x) tp_svc_channel_dispatcher_implement_##x (\ - klass, tp_tests_simple_channel_dispatcher_##x) - IMPLEMENT (create_channel); - IMPLEMENT (ensure_channel); - IMPLEMENT (delegate_channels); - IMPLEMENT (present_channel); -#undef IMPLEMENT -} - - -static void -tp_tests_simple_channel_dispatcher_init (TpTestsSimpleChannelDispatcher *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER, - TpTestsSimpleChannelDispatcherPrivate); -} - -static void -tp_tests_simple_channel_dispatcher_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - switch (property_id) { - case PROP_INTERFACES: - g_value_set_boxed (value, CHANNEL_DISPATCHER_INTERFACES); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_channel_dispatcher_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleChannelDispatcher *self = SIMPLE_CHANNEL_DISPATCHER (object); - - switch (property_id) { - case PROP_CONNECTION: - self->priv->conn = g_value_dup_object (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_channel_dispatcher_dispose (GObject *object) -{ - TpTestsSimpleChannelDispatcher *self = SIMPLE_CHANNEL_DISPATCHER (object); - - tp_clear_object (&self->priv->conn); - - g_slist_foreach (self->priv->requests, (GFunc) g_object_unref, NULL); - g_slist_free (self->priv->requests); - - g_free (self->priv->old_handler); - - if (G_OBJECT_CLASS (tp_tests_simple_channel_dispatcher_parent_class)->dispose != NULL) - G_OBJECT_CLASS (tp_tests_simple_channel_dispatcher_parent_class)->dispose (object); -} - -static void -tp_tests_simple_channel_dispatcher_class_init ( - TpTestsSimpleChannelDispatcherClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - static TpDBusPropertiesMixinPropImpl am_props[] = { - { "Interfaces", "interfaces", NULL }, - { NULL } - }; - - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CHANNEL_DISPATCHER, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - am_props - }, - { NULL }, - }; - - g_type_class_add_private (klass, sizeof (TpTestsSimpleChannelDispatcherPrivate)); - object_class->get_property = tp_tests_simple_channel_dispatcher_get_property; - object_class->set_property = tp_tests_simple_channel_dispatcher_set_property; - - object_class->dispose = tp_tests_simple_channel_dispatcher_dispose; - - param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", - "In this case we only implement ChannelDispatcher, so none.", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); - - param_spec = g_param_spec_object ("connection", "TpTestsSimpleConnection", - "connection to use when creating channels", - TP_TESTS_TYPE_SIMPLE_CONNECTION, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION, param_spec); - - /* Fired when we create a new channel request object. This can be used in - * test to track the progression of a request. */ - signals[CHANNEL_REQUEST_CREATED] = g_signal_new ("channel-request-created", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST); - - klass->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsSimpleChannelDispatcherClass, dbus_props_class)); -} diff --git a/tests/lib/telepathy/contactlist/simple-channel-dispatcher.h b/tests/lib/telepathy/contactlist/simple-channel-dispatcher.h deleted file mode 100644 index da214061..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-dispatcher.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * simple-channel-dispatcher.h - header for a simple channel dispatcher service. - * - * Copyright © 2010 Collabora Ltd. - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_SIMPLE_CHANNEL_DISPATCHER_H__ -#define __TP_TESTS_SIMPLE_CHANNEL_DISPATCHER_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - - -G_BEGIN_DECLS - -typedef struct _TpTestsSimpleChannelDispatcher TpTestsSimpleChannelDispatcher; -typedef struct _TpTestsSimpleChannelDispatcherClass TpTestsSimpleChannelDispatcherClass; -typedef struct _TpTestsSimpleChannelDispatcherPrivate TpTestsSimpleChannelDispatcherPrivate; - -struct _TpTestsSimpleChannelDispatcherClass { - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; -}; - -struct _TpTestsSimpleChannelDispatcher { - GObject parent; - - /* so regression tests can verify what was asked for */ - GHashTable *last_request; - gchar *last_account; - gint64 last_user_action_time; - gchar *last_preferred_handler; - GHashTable *last_hints; - - TpTestsSimpleChannelDispatcherPrivate *priv; - - gboolean refuse_delegate; -}; - -GType tp_tests_simple_channel_dispatcher_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER \ - (tp_tests_simple_channel_dispatcher_get_type ()) -#define SIMPLE_CHANNEL_DISPATCHER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER, \ - TpTestsSimpleChannelDispatcher)) -#define SIMPLE_CHANNEL_DISPATCHER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER, \ - TpTestsSimpleChannelDispatcherClass)) -#define SIMPLE_IS_CHANNEL_DISPATCHER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER)) -#define SIMPLE_IS_CHANNEL_DISPATCHER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER)) -#define SIMPLE_CHANNEL_DISPATCHER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCHER, \ - TpTestsSimpleChannelDispatcherClass)) - - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_CHANNEL_DISPATCHER_H__ */ diff --git a/tests/lib/telepathy/contactlist/simple-channel-manager.c b/tests/lib/telepathy/contactlist/simple-channel-manager.c deleted file mode 100644 index ba60a9d9..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-manager.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * simple-channel-manager.c - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "simple-channel-manager.h" -#include "util.h" -#include "echo-chan.h" - -static void channel_manager_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelManager, - tp_tests_simple_channel_manager, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER, channel_manager_iface_init); - ) - -/* signals */ -enum { - REQUEST, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -static void -tp_tests_simple_channel_manager_class_init (TpTestsSimpleChannelManagerClass *klass) -{ - signals[REQUEST] = g_signal_new ("request", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, G_TYPE_HASH_TABLE); -} - -static void -tp_tests_simple_channel_manager_init (TpTestsSimpleChannelManager *self) -{ -} - -static gboolean -tp_tests_simple_channel_manager_request (TpChannelManager *manager, - gpointer request_token, - GHashTable *request_properties) -{ - TpTestsSimpleChannelManager *self = - TP_TESTS_SIMPLE_CHANNEL_MANAGER (manager); - GSList *tokens; - TpExportableChannel *channel; - TpHandle handle = tp_asv_get_uint32 (request_properties, - TP_PROP_CHANNEL_TARGET_HANDLE, NULL); - gchar *path; - - g_signal_emit (manager, signals[REQUEST], 0, request_properties); - - tokens = g_slist_append (NULL, request_token); - - path = g_strdup_printf ("%s/Channel", - tp_base_connection_get_object_path (self->conn)); - - channel = tp_tests_object_new_static_class ( - TP_TESTS_TYPE_ECHO_CHANNEL, - "connection", self->conn, - "object-path", path, - "handle", handle, - NULL); - - tp_channel_manager_emit_new_channel (manager, channel, tokens); - - g_free (path); - g_slist_free (tokens); - g_object_unref (channel); - - return TRUE; -} - -static void -channel_manager_iface_init (gpointer g_iface, - gpointer giface_data G_GNUC_UNUSED) -{ - TpChannelManagerIface *iface = g_iface; - - iface->create_channel = tp_tests_simple_channel_manager_request; - iface->ensure_channel = tp_tests_simple_channel_manager_request; - iface->request_channel = tp_tests_simple_channel_manager_request; -} diff --git a/tests/lib/telepathy/contactlist/simple-channel-manager.h b/tests/lib/telepathy/contactlist/simple-channel-manager.h deleted file mode 100644 index ad711cd5..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-manager.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * simple-channel-manager.h - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_SIMPLE_CHANNEL_MANAGER_H__ -#define __TP_TESTS_SIMPLE_CHANNEL_MANAGER_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -typedef struct _TpTestsSimpleChannelManager TpTestsSimpleChannelManager; -typedef struct _TpTestsSimpleChannelManagerClass TpTestsSimpleChannelManagerClass; - -struct _TpTestsSimpleChannelManager -{ - GObject parent; - - TpBaseConnection *conn; -}; - -struct _TpTestsSimpleChannelManagerClass -{ - GObjectClass parent_class; -}; - -GType tp_tests_simple_channel_manager_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER \ - (tp_tests_simple_channel_manager_get_type ()) -#define TP_TESTS_SIMPLE_CHANNEL_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, \ - TpTestsSimpleChannelManager)) -#define TP_TESTS_SIMPLE_CHANNEL_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, \ - TpTestsSimpleChannelManagerClass)) -#define TP_TESTS_IS_SIMPLE_CHANNEL_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER)) -#define TP_TESTS_IS_SIMPLE_CHANNEL_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER)) -#define TP_TESTS_SIMPLE_CHANNEL_MANAGER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, \ - TpTestsSimpleChannelManagerClass)) - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_CHANNEL_MANAGER_H__ */ diff --git a/tests/lib/telepathy/contactlist/simple-channel-request.c b/tests/lib/telepathy/contactlist/simple-channel-request.c deleted file mode 100644 index 895e3021..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-request.c +++ /dev/null @@ -1,508 +0,0 @@ -/* - * simple-channel-request.c - simple channel request service. - * - * Copyright © 2010 Collabora Ltd. - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "simple-channel-request.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> -#include <telepathy-glib/proxy-subclass.h> - -#include "tests/lib/util.h" - -static void channel_request_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelRequest, - tp_tests_simple_channel_request, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_REQUEST, - channel_request_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init) - ) - - -/* TP_IFACE_CHANNEL_REQUEST is implied */ -static const char *CHANNEL_REQUEST_INTERFACES[] = { NULL }; - -enum -{ - PROP_0, - PROP_PATH, - PROP_ACCOUNT, - PROP_USER_ACTION_TIME, - PROP_PREFERRED_HANDLER, - PROP_REQUESTS, - PROP_CONNECTION, - PROP_INTERFACES, - PROP_HINTS, -}; - -struct _TpTestsSimpleChannelRequestPrivate -{ - /* D-Bus properties */ - gchar *account_path; - gint64 user_action_time; - gchar *preferred_handler; - GPtrArray *requests; - GHashTable *hints; - - /* Our own path */ - gchar *path; - - /* connection used to create channels */ - TpTestsSimpleConnection *conn; -}; - -static void -handle_channels_cb (TpClient *client, - const GError *error, - gpointer user_data, - GObject *weak_object) -{ - TpTestsSimpleChannelRequest *self = SIMPLE_CHANNEL_REQUEST (weak_object); - TpBaseConnection *base_conn = TP_BASE_CONNECTION (self->priv->conn); - const gchar *chan_path = user_data; - GHashTable *props = tp_asv_new (NULL, NULL); - - if (error != NULL) - { - tp_svc_channel_request_emit_failed (self, - tp_error_get_dbus_name (error->code), error->message); - return; - } - - tp_svc_channel_request_emit_succeeded (self, - tp_base_connection_get_object_path (base_conn), props, chan_path, props); - - g_hash_table_unref (props); -} - -static gchar * -add_channel (TpTestsSimpleChannelRequest *self, - GPtrArray *channels) -{ - const gchar *target_id; - gchar *chan_path; - GHashTable *request; - GHashTable *props; - const char *chan_type; - - request = g_ptr_array_index (self->priv->requests, 0); - chan_type = tp_asv_get_string (request, TP_PROP_CHANNEL_CHANNEL_TYPE); - - if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT)) - { - target_id = tp_asv_get_string (request, TP_PROP_CHANNEL_TARGET_ID); - g_assert (target_id != NULL); - - chan_path = tp_tests_simple_connection_ensure_text_chan (self->priv->conn, - target_id, &props); - } - else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_ROOM_LIST1)) - { - chan_path = tp_tests_simple_connection_ensure_room_list_chan ( - self->priv->conn, tp_asv_get_string (request, - TP_PROP_CHANNEL_TYPE_ROOM_LIST1_SERVER), &props); - } - else - { - g_assert_not_reached (); - } - - g_ptr_array_add (channels, tp_value_array_build (2, - DBUS_TYPE_G_OBJECT_PATH, chan_path, - TP_HASH_TYPE_STRING_VARIANT_MAP, props, - G_TYPE_INVALID)); - - g_hash_table_unref (props); - - return chan_path; -} - -static void -free_channel_details (gpointer data, - gpointer user_data) -{ - g_boxed_free (TP_STRUCT_TYPE_CHANNEL_DETAILS, data); -} - -GHashTable * -tp_tests_simple_channel_request_dup_immutable_props ( - TpTestsSimpleChannelRequest *self) -{ - return tp_asv_new ( - TP_PROP_CHANNEL_REQUEST_ACCOUNT, DBUS_TYPE_G_OBJECT_PATH, - self->priv->account_path, - TP_PROP_CHANNEL_REQUEST_USER_ACTION_TIME, G_TYPE_INT64, - self->priv->user_action_time, - TP_PROP_CHANNEL_REQUEST_PREFERRED_HANDLER, G_TYPE_STRING, - self->priv->preferred_handler, - TP_PROP_CHANNEL_REQUEST_REQUESTS, TP_ARRAY_TYPE_CHANNEL_CLASS_LIST, - self->priv->requests, - TP_PROP_CHANNEL_REQUEST_INTERFACES, G_TYPE_STRV, NULL, - TP_PROP_CHANNEL_REQUEST_HINTS, TP_HASH_TYPE_STRING_VARIANT_MAP, - self->priv->hints, - NULL); -} - -static void -tp_tests_simple_channel_request_proceed (TpSvcChannelRequest *request, - DBusGMethodInvocation *context) -{ - TpTestsSimpleChannelRequest *self = SIMPLE_CHANNEL_REQUEST (request); - TpClient *client; - TpDBusDaemon *dbus; - gchar *client_path; - GPtrArray *channels; - GPtrArray *satisfied; - GHashTable *info; - TpBaseConnection *base_conn = (TpBaseConnection *) self->priv->conn; - GHashTable *req; - GHashTable *request_props; - gchar *chan_path; - - req = g_ptr_array_index (self->priv->requests, 0); - g_assert (req != NULL); - if (tp_asv_get_boolean (req, "ProceedFail", NULL)) - { - /* We have been asked to fail */ - GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Computer says no" }; - - dbus_g_method_return_error (context, &error); - return; - } - - tp_svc_channel_request_return_from_proceed (context); - - if (tp_asv_get_boolean (req, "FireFailed", NULL)) - { - /* We have been asked to fire the 'Failed' signal */ - tp_svc_channel_request_emit_failed (self, TP_ERROR_STR_INVALID_ARGUMENT, - "Let's fail!"); - return; - } - - /* We just support handling request having a preferred handler */ - if (self->priv->preferred_handler == NULL || - !tp_strdiff (self->priv->preferred_handler, "")) - { - tp_svc_channel_request_emit_failed (self, TP_ERROR_STR_NOT_AVAILABLE, - "ChannelRequest doesn't have a preferred handler"); - return; - } - - if (!tp_strdiff (self->priv->preferred_handler, "Fake")) - { - /* Pretend that the channel has been handled */ - GHashTable *props; - props = g_hash_table_new (NULL, NULL); - - tp_svc_channel_request_emit_succeeded (self, - tp_base_connection_get_object_path (base_conn), - props, "/chan", props); - - g_hash_table_unref (props); - return; - } - - /* Call HandleChannels() on the preferred handler */ - client_path = g_strdelimit (g_strdup_printf ("/%s", - self->priv->preferred_handler), ".", '/'); - - dbus = tp_dbus_daemon_dup (NULL); - g_assert (dbus != NULL); - - client = tp_tests_object_new_static_class (TP_TYPE_CLIENT, - "dbus-daemon", dbus, - "bus-name", self->priv->preferred_handler, - "object-path", client_path, - NULL); - - tp_proxy_add_interface_by_id (TP_PROXY (client), TP_IFACE_QUARK_CLIENT); - tp_proxy_add_interface_by_id (TP_PROXY (client), - TP_IFACE_QUARK_CLIENT_HANDLER); - - channels = g_ptr_array_sized_new (1); - chan_path = add_channel (self, channels); - - satisfied = g_ptr_array_sized_new (1); - g_ptr_array_add (satisfied, self->priv->path); - - request_props = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify) g_hash_table_unref); - - g_hash_table_insert (request_props, g_strdup (self->priv->path), - tp_tests_simple_channel_request_dup_immutable_props (self)); - - info = tp_asv_new ( - "request-properties", TP_HASH_TYPE_OBJECT_IMMUTABLE_PROPERTIES_MAP, - request_props, - NULL); - - tp_cli_client_handler_call_handle_channels (client, -1, - self->priv->account_path, - tp_base_connection_get_object_path (base_conn), channels, - satisfied, self->priv->user_action_time, info, handle_channels_cb, - g_strdup (chan_path), g_free, G_OBJECT (self)); - - g_free (chan_path); - g_free (client_path); - g_ptr_array_foreach (channels, free_channel_details, NULL); - g_ptr_array_unref (channels); - g_ptr_array_unref (satisfied); - g_hash_table_unref (info); - g_hash_table_unref (request_props); - g_object_unref (dbus); - g_object_unref (client); -} - -static void -tp_tests_simple_channel_request_cancel (TpSvcChannelRequest *request, - DBusGMethodInvocation *context) -{ - tp_svc_channel_request_emit_failed (request, TP_ERROR_STR_CANCELLED, - "ChannelRequest has been cancelled"); - - tp_svc_channel_request_return_from_cancel (context); -} - -static void -channel_request_iface_init (gpointer klass, - gpointer unused G_GNUC_UNUSED) -{ -#define IMPLEMENT(x) tp_svc_channel_request_implement_##x (\ - klass, tp_tests_simple_channel_request_##x) - IMPLEMENT (proceed); - IMPLEMENT (cancel); -#undef IMPLEMENT -} - -static void -tp_tests_simple_channel_request_init (TpTestsSimpleChannelRequest *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST, - TpTestsSimpleChannelRequestPrivate); -} - -static void -tp_tests_simple_channel_request_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleChannelRequest *self = SIMPLE_CHANNEL_REQUEST (object); - - switch (property_id) { - case PROP_PATH: - g_value_set_string (value, self->priv->path); - break; - - case PROP_ACCOUNT: - g_value_set_string (value, self->priv->account_path); - break; - - case PROP_USER_ACTION_TIME: - g_value_set_int64 (value, self->priv->user_action_time); - break; - - case PROP_PREFERRED_HANDLER: - g_value_set_string (value, self->priv->preferred_handler); - break; - - case PROP_REQUESTS: - g_value_set_boxed (value, self->priv->requests); - break; - - case PROP_INTERFACES: - g_value_set_boxed (value, CHANNEL_REQUEST_INTERFACES); - break; - - case PROP_HINTS: - g_value_set_boxed (value, self->priv->hints); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_channel_request_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleChannelRequest *self = SIMPLE_CHANNEL_REQUEST (object); - - switch (property_id) { - case PROP_PATH: - self->priv->path = g_value_dup_string (value); - break; - - case PROP_ACCOUNT: - self->priv->account_path = g_value_dup_string (value); - break; - - case PROP_USER_ACTION_TIME: - self->priv->user_action_time = g_value_get_int64 (value); - break; - - case PROP_PREFERRED_HANDLER: - self->priv->preferred_handler = g_value_dup_string (value); - break; - - case PROP_REQUESTS: - self->priv->requests = g_value_dup_boxed (value); - break; - - case PROP_CONNECTION: - self->priv->conn = g_value_dup_object (value); - break; - - case PROP_HINTS: - self->priv->hints = g_value_dup_boxed (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_channel_request_dispose (GObject *object) -{ - TpTestsSimpleChannelRequest *self = SIMPLE_CHANNEL_REQUEST (object); - - g_free (self->priv->path); - g_free (self->priv->account_path); - g_free (self->priv->preferred_handler); - - if (self->priv->requests != NULL) - { - g_boxed_free (TP_ARRAY_TYPE_CHANNEL_CLASS_LIST, self->priv->requests); - self->priv->requests = NULL; - } - - tp_clear_object (&self->priv->conn); - tp_clear_pointer (&self->priv->hints, g_hash_table_unref); - - if (G_OBJECT_CLASS (tp_tests_simple_channel_request_parent_class)->dispose != NULL) - G_OBJECT_CLASS (tp_tests_simple_channel_request_parent_class)->dispose (object); -} - -static void -tp_tests_simple_channel_request_class_init ( - TpTestsSimpleChannelRequestClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - static TpDBusPropertiesMixinPropImpl am_props[] = { - { "Interfaces", "interfaces", NULL }, - { "Hints", "hints", NULL }, - { NULL } - }; - - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CHANNEL_REQUEST, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - am_props - }, - { NULL }, - }; - - g_type_class_add_private (klass, sizeof (TpTestsSimpleChannelRequestPrivate)); - object_class->get_property = tp_tests_simple_channel_request_get_property; - object_class->set_property = tp_tests_simple_channel_request_set_property; - - object_class->dispose = tp_tests_simple_channel_request_dispose; - - param_spec = g_param_spec_string ("path", "Path", - "Path of this ChannelRequest", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_PATH, param_spec); - - param_spec = g_param_spec_string ("account", "Account", - "Path of the Account", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_int64 ("user-action-time", "UserActionTime", - "UserActionTime", - G_MININT64, G_MAXINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_USER_ACTION_TIME, - param_spec); - - param_spec = g_param_spec_string ("preferred-handler", "PreferredHandler", - "PreferredHandler", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_PREFERRED_HANDLER, - param_spec); - - param_spec = g_param_spec_boxed ("requests", "Requests", - "Requests", - TP_ARRAY_TYPE_CHANNEL_CLASS_LIST, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_REQUESTS, param_spec); - - param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", - "In this case we only implement ChannelRequest, so none.", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); - - param_spec = g_param_spec_object ("connection", "TpBaseConnection", - "connection to use when creating channels", - TP_TYPE_BASE_CONNECTION, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION, param_spec); - - param_spec = g_param_spec_boxed ("hints", "Hints", - "Metadata provided by the channel's requester, if any", - TP_HASH_TYPE_STRING_VARIANT_MAP, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_HINTS, param_spec); - - klass->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsSimpleChannelRequestClass, dbus_props_class)); -} - -TpTestsSimpleChannelRequest * -tp_tests_simple_channel_request_new (const gchar *path, - TpTestsSimpleConnection *conn, - const gchar *account_path, - gint64 user_action_time, - const gchar *preferred_handler, - GPtrArray *requests, - GHashTable *hints) -{ - return tp_tests_object_new_static_class ( - TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST, - "path", path, - "connection", conn, - "account", account_path, - "user-action-time", user_action_time, - "preferred-handler", preferred_handler, - "requests", requests, - "hints", hints, - NULL); -} diff --git a/tests/lib/telepathy/contactlist/simple-channel-request.h b/tests/lib/telepathy/contactlist/simple-channel-request.h deleted file mode 100644 index 60ea3be6..00000000 --- a/tests/lib/telepathy/contactlist/simple-channel-request.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * simple-channel-request.h - header for a simple channel request service. - * - * Copyright © 2010 Collabora Ltd. - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_SIMPLE_CHANNEL_REQUEST_H__ -#define __TP_TESTS_SIMPLE_CHANNEL_REQUEST_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -#include "simple-conn.h" - -G_BEGIN_DECLS - -typedef struct _TpTestsSimpleChannelRequest TpTestsSimpleChannelRequest; -typedef struct _TpTestsSimpleChannelRequestClass TpTestsSimpleChannelRequestClass; -typedef struct _TpTestsSimpleChannelRequestPrivate TpTestsSimpleChannelRequestPrivate; - -struct _TpTestsSimpleChannelRequestClass { - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; -}; - -struct _TpTestsSimpleChannelRequest { - GObject parent; - - TpTestsSimpleChannelRequestPrivate *priv; -}; - -GType tp_tests_simple_channel_request_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST \ - (tp_tests_simple_channel_request_get_type ()) -#define SIMPLE_CHANNEL_REQUEST(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST, \ - TpTestsSimpleChannelRequest)) -#define SIMPLE_CHANNEL_REQUEST_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST, \ - TpTestsSimpleChannelRequestClass)) -#define SIMPLE_IS_CHANNEL_REQUEST(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST)) -#define SIMPLE_IS_CHANNEL_REQUEST_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST)) -#define SIMPLE_CHANNEL_REQUEST_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_REQUEST, \ - TpTestsSimpleChannelRequestClass)) - -TpTestsSimpleChannelRequest * -tp_tests_simple_channel_request_new (const gchar *path, - TpTestsSimpleConnection *conn, - const gchar *account_path, - gint64 user_action_time, - const gchar *preferred_handler, - GPtrArray *requests, - GHashTable *hints); - -GHashTable * tp_tests_simple_channel_request_dup_immutable_props ( - TpTestsSimpleChannelRequest *self); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_CHANNEL_REQUEST_H__ */ diff --git a/tests/lib/telepathy/contactlist/simple-client.c b/tests/lib/telepathy/contactlist/simple-client.c deleted file mode 100644 index c7431644..00000000 --- a/tests/lib/telepathy/contactlist/simple-client.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * simple-client.c - a simple client - * - * Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "simple-client.h" - -#include <string.h> - -#include <dbus/dbus-glib.h> - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "tests/lib/util.h" - -G_DEFINE_TYPE (TpTestsSimpleClient, tp_tests_simple_client, TP_TYPE_BASE_CLIENT) - -static void -simple_observe_channels ( - TpBaseClient *client, - TpAccount *account, - TpConnection *connection, - GList *channels, - TpChannelDispatchOperation *dispatch_operation, - GList *requests, - TpObserveChannelsContext *context) -{ - TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (client); - GHashTable *info; - gboolean fail; - GList *l; - - /* Fail if caller set the fake "FAIL" info */ - g_object_get (context, "observer-info", &info, NULL); - fail = tp_asv_get_boolean (info, "FAIL", NULL); - g_hash_table_unref (info); - - if (self->observe_ctx != NULL) - { - g_object_unref (self->observe_ctx); - self->observe_ctx = NULL; - } - - if (fail) - { - GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "No observation for you!" }; - - tp_observe_channels_context_fail (context, &error); - return; - } - - g_assert (TP_IS_ACCOUNT (account)); - g_assert (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE)); - - g_assert (TP_IS_CONNECTION (connection)); - g_assert (tp_proxy_is_prepared (connection, TP_CONNECTION_FEATURE_CORE)); - - g_assert_cmpuint (g_list_length (channels), >, 0); - for (l = channels; l != NULL; l = g_list_next (l)) - { - TpChannel *channel = l->data; - - g_assert (TP_IS_CHANNEL (channel)); - g_assert (tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CORE) || - tp_proxy_get_invalidated (channel) != NULL); - } - - if (dispatch_operation != NULL) - g_assert (TP_IS_CHANNEL_DISPATCH_OPERATION (dispatch_operation)); - - for (l = requests; l != NULL; l = g_list_next (l)) - { - TpChannelRequest *request = l->data; - - g_assert (TP_IS_CHANNEL_REQUEST (request)); - } - - self->observe_ctx = g_object_ref (context); - tp_observe_channels_context_accept (context); -} - -static void -simple_add_dispatch_operation ( - TpBaseClient *client, - TpAccount *account, - TpConnection *connection, - GList *channels, - TpChannelDispatchOperation *dispatch_operation, - TpAddDispatchOperationContext *context) -{ - TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (client); - GList *l; - - g_assert (TP_IS_ACCOUNT (account)); - g_assert (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE)); - - g_assert (TP_IS_CONNECTION (connection)); - g_assert (tp_proxy_is_prepared (connection, TP_CONNECTION_FEATURE_CORE)); - - g_assert (TP_IS_CHANNEL_DISPATCH_OPERATION (dispatch_operation)); - g_assert (tp_proxy_is_prepared (dispatch_operation, - TP_CHANNEL_DISPATCH_OPERATION_FEATURE_CORE) || - tp_proxy_get_invalidated (dispatch_operation) != NULL); - - if (self->add_dispatch_ctx != NULL) - { - g_object_unref (self->add_dispatch_ctx); - self->add_dispatch_ctx = NULL; - } - - g_assert_cmpuint (g_list_length (channels), >, 0); - for (l = channels; l != NULL; l = g_list_next (l)) - { - TpChannel *channel = l->data; - - g_assert (TP_IS_CHANNEL (channel)); - g_assert (tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CORE) || - tp_proxy_get_invalidated (channel) != NULL); - } - - self->add_dispatch_ctx = g_object_ref (context); - tp_add_dispatch_operation_context_accept (context); -} - -static void -simple_handle_channels (TpBaseClient *client, - TpAccount *account, - TpConnection *connection, - GList *channels, - GList *requests_satisfied, - gint64 user_action_time, - TpHandleChannelsContext *context) -{ - TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (client); - GList *l; - - if (self->handle_channels_ctx != NULL) - { - g_object_unref (self->handle_channels_ctx); - self->handle_channels_ctx = NULL; - } - - g_assert (TP_IS_ACCOUNT (account)); - g_assert (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE)); - - g_assert (TP_IS_CONNECTION (connection)); - g_assert (tp_proxy_is_prepared (connection, TP_CONNECTION_FEATURE_CORE)); - - g_assert_cmpuint (g_list_length (channels), >, 0); - for (l = channels; l != NULL; l = g_list_next (l)) - { - TpChannel *channel = l->data; - - g_assert (TP_IS_CHANNEL (channel)); - g_assert (tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CORE) || - tp_proxy_get_invalidated (channel) != NULL); - } - - for (l = requests_satisfied; l != NULL; l = g_list_next (l)) - { - TpChannelRequest *request = l->data; - - g_assert (TP_IS_CHANNEL_REQUEST (request)); - } - - self->handle_channels_ctx = g_object_ref (context); - tp_handle_channels_context_accept (context); -} - -static void -tp_tests_simple_client_init (TpTestsSimpleClient *self) -{ -} - -static void -tp_tests_simple_client_dispose (GObject *object) -{ - TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (object); - void (*dispose) (GObject *) = - G_OBJECT_CLASS (tp_tests_simple_client_parent_class)->dispose; - - if (self->observe_ctx != NULL) - { - g_object_unref (self->observe_ctx); - self->observe_ctx = NULL; - } - - if (self->add_dispatch_ctx != NULL) - { - g_object_unref (self->add_dispatch_ctx); - self->add_dispatch_ctx = NULL; - } - - if (self->handle_channels_ctx != NULL) - { - g_object_unref (self->handle_channels_ctx); - self->handle_channels_ctx = NULL; - } - - if (dispose != NULL) - dispose (object); -} - -static void -tp_tests_simple_client_class_init (TpTestsSimpleClientClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TpBaseClientClass *base_class = TP_BASE_CLIENT_CLASS (klass); - - object_class->dispose = tp_tests_simple_client_dispose; - - tp_base_client_implement_observe_channels (base_class, - simple_observe_channels); - - tp_base_client_implement_add_dispatch_operation (base_class, - simple_add_dispatch_operation); - - tp_base_client_implement_handle_channels (base_class, - simple_handle_channels); -} - -TpTestsSimpleClient * -tp_tests_simple_client_new (TpClientFactory *factory, - const gchar *name, - gboolean uniquify_name) -{ - return tp_tests_object_new_static_class (TP_TESTS_TYPE_SIMPLE_CLIENT, - "factory", factory, - "name", name, - "uniquify-name", uniquify_name, - NULL); -} - -TpTestsSimpleClient * -tp_tests_simple_client_new_with_am (TpAccountManager *account_mgr, - const gchar *name, - gboolean uniquify_name) -{ - return tp_tests_simple_client_new (tp_proxy_get_factory (account_mgr), - name, uniquify_name); -} diff --git a/tests/lib/telepathy/contactlist/simple-client.h b/tests/lib/telepathy/contactlist/simple-client.h deleted file mode 100644 index b6f7b5f8..00000000 --- a/tests/lib/telepathy/contactlist/simple-client.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * simple-client.h - header for a simple client - * - * Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_TESTS_SIMPLE_CLIENT_H__ -#define __TP_TESTS_SIMPLE_CLIENT_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsSimpleClient TpTestsSimpleClient; -typedef struct _TpTestsSimpleClientClass TpTestsSimpleClientClass; - -struct _TpTestsSimpleClientClass { - TpBaseClientClass parent_class; -}; - -struct _TpTestsSimpleClient { - TpBaseClient parent; - - TpObserveChannelsContext *observe_ctx; - TpAddDispatchOperationContext *add_dispatch_ctx; - TpHandleChannelsContext *handle_channels_ctx; -}; - -GType tp_tests_simple_client_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_CLIENT \ - (tp_tests_simple_client_get_type ()) -#define TP_TESTS_SIMPLE_CLIENT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CLIENT, \ - TpTestsSimpleClient)) -#define TP_TESTS_SIMPLE_CLIENT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CLIENT, \ - TpTestsSimpleClientClass)) -#define SIMPLE_IS_CLIENT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CLIENT)) -#define SIMPLE_IS_CLIENT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CLIENT)) -#define TP_TESTS_SIMPLE_CLIENT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CLIENT, \ - TpTestsSimpleClientClass)) - -TpTestsSimpleClient * tp_tests_simple_client_new (TpClientFactory *factory, - const gchar *name, - gboolean uniquify_name); - -TpTestsSimpleClient * tp_tests_simple_client_new_with_am ( - TpAccountManager *account_mgr, - const gchar *name, - gboolean uniquify_name); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_CONN_H__ */ diff --git a/tests/lib/telepathy/contactlist/stream-tube-chan.c b/tests/lib/telepathy/contactlist/stream-tube-chan.c deleted file mode 100644 index 8a41064d..00000000 --- a/tests/lib/telepathy/contactlist/stream-tube-chan.c +++ /dev/null @@ -1,650 +0,0 @@ -/* - * stream-tube-chan.c - Simple stream tube channel - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "config.h" - -#include "stream-tube-chan.h" -#include "util.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#ifdef HAVE_GIO_UNIX -#include <gio/gunixsocketaddress.h> -#include <gio/gunixconnection.h> -#endif - -#include <glib/gstdio.h> - -enum -{ - PROP_SERVICE = 1, - PROP_SUPPORTED_SOCKET_TYPES, - PROP_PARAMETERS, - PROP_STATE, -}; - -enum -{ - SIG_INCOMING_CONNECTION, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0, }; - - -struct _TpTestsStreamTubeChannelPrivate { - TpTubeChannelState state; - GHashTable *supported_socket_types; - - /* Accepting side */ - GSocketService *service; - GValue *access_control_param; - - /* Offering side */ - TpSocketAddressType address_type; - GValue *address; - gchar *unix_address; - gchar *unix_tmpdir; - guint connection_id; - - TpSocketAccessControl access_control; -}; - -static void -create_supported_socket_types (TpTestsStreamTubeChannel *self) -{ - TpSocketAccessControl access_control; - GArray *unix_tab; - - g_assert (self->priv->supported_socket_types == NULL); - self->priv->supported_socket_types = g_hash_table_new_full (NULL, NULL, - NULL, _tp_destroy_socket_control_list); - - /* Socket_Address_Type_Unix */ - unix_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl), - 1); - access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST; - g_array_append_val (unix_tab, access_control); - - g_hash_table_insert (self->priv->supported_socket_types, - GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_UNIX), unix_tab); -} - -static void -tp_tests_stream_tube_channel_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TpTestsStreamTubeChannel *self = (TpTestsStreamTubeChannel *) object; - - switch (property_id) - { - case PROP_SERVICE: - g_value_set_string (value, "test-service"); - break; - - case PROP_SUPPORTED_SOCKET_TYPES: - g_value_set_boxed (value, - self->priv->supported_socket_types); - break; - - case PROP_PARAMETERS: - g_value_take_boxed (value, tp_asv_new ( - "badger", G_TYPE_UINT, 42, - NULL)); - break; - - case PROP_STATE: - g_value_set_uint (value, self->priv->state); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -tp_tests_stream_tube_channel_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - TpTestsStreamTubeChannel *self = (TpTestsStreamTubeChannel *) object; - - switch (property_id) - { - case PROP_SUPPORTED_SOCKET_TYPES: - self->priv->supported_socket_types = g_value_dup_boxed (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void stream_tube_iface_init (gpointer iface, gpointer data); - -G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TpTestsStreamTubeChannel, - tp_tests_stream_tube_channel, - TP_TYPE_BASE_CHANNEL, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_STREAM_TUBE1, - stream_tube_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_TUBE1, - NULL); - ) - -/* type definition stuff */ - -static GPtrArray * -tp_tests_stream_tube_channel_get_interfaces (TpBaseChannel *self) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CHANNEL_CLASS ( - tp_tests_stream_tube_channel_parent_class)->get_interfaces (self); - - g_ptr_array_add (interfaces, TP_IFACE_CHANNEL_INTERFACE_TUBE1); - return interfaces; -}; - -static void -tp_tests_stream_tube_channel_init (TpTestsStreamTubeChannel *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), - TP_TESTS_TYPE_STREAM_TUBE_CHANNEL, TpTestsStreamTubeChannelPrivate); -} - -static GObject * -constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *object = - G_OBJECT_CLASS (tp_tests_stream_tube_channel_parent_class)->constructor ( - type, n_props, props); - TpTestsStreamTubeChannel *self = TP_TESTS_STREAM_TUBE_CHANNEL (object); - - if (tp_base_channel_is_requested (TP_BASE_CHANNEL (self))) - self->priv->state = TP_TUBE_CHANNEL_STATE_NOT_OFFERED; - else - self->priv->state = TP_TUBE_CHANNEL_STATE_LOCAL_PENDING; - - if (self->priv->supported_socket_types == NULL) - create_supported_socket_types (self); - - tp_base_channel_register (TP_BASE_CHANNEL (self)); - - return object; -} - -static void -dispose (GObject *object) -{ - TpTestsStreamTubeChannel *self = (TpTestsStreamTubeChannel *) object; - - if (self->priv->service != NULL) - { - g_socket_service_stop (self->priv->service); - tp_clear_object (&self->priv->service); - } - - tp_clear_pointer (&self->priv->address, tp_g_value_slice_free); - tp_clear_pointer (&self->priv->supported_socket_types, g_hash_table_unref); - tp_clear_pointer (&self->priv->access_control_param, tp_g_value_slice_free); - - if (self->priv->unix_address != NULL) - g_unlink (self->priv->unix_address); - - tp_clear_pointer (&self->priv->unix_address, g_free); - - if (self->priv->unix_tmpdir != NULL) - g_rmdir (self->priv->unix_tmpdir); - - tp_clear_pointer (&self->priv->unix_tmpdir, g_free); - - ((GObjectClass *) tp_tests_stream_tube_channel_parent_class)->dispose ( - object); -} - -static void -channel_close (TpBaseChannel *channel) -{ - tp_base_channel_destroyed (channel); -} - -static void -fill_immutable_properties (TpBaseChannel *chan, - GHashTable *properties) -{ - TpBaseChannelClass *klass = TP_BASE_CHANNEL_CLASS ( - tp_tests_stream_tube_channel_parent_class); - - klass->fill_immutable_properties (chan, properties); - - tp_dbus_properties_mixin_fill_properties_hash ( - G_OBJECT (chan), properties, - TP_IFACE_CHANNEL_TYPE_STREAM_TUBE1, "Service", - TP_IFACE_CHANNEL_TYPE_STREAM_TUBE1, "SupportedSocketTypes", - NULL); - - if (!tp_base_channel_is_requested (chan)) - { - /* Parameters is immutable only for incoming tubes */ - tp_dbus_properties_mixin_fill_properties_hash ( - G_OBJECT (chan), properties, - TP_IFACE_CHANNEL_INTERFACE_TUBE1, "Parameters", - NULL); - } -} - -static void -tp_tests_stream_tube_channel_class_init (TpTestsStreamTubeChannelClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - GParamSpec *param_spec; - static TpDBusPropertiesMixinPropImpl stream_tube_props[] = { - { "Service", "service", NULL, }, - { "SupportedSocketTypes", "supported-socket-types", NULL }, - { NULL } - }; - static TpDBusPropertiesMixinPropImpl tube_props[] = { - { "Parameters", "parameters", NULL, }, - { "State", "state", NULL, }, - { NULL } - }; - - object_class->constructor = constructor; - object_class->get_property = tp_tests_stream_tube_channel_get_property; - object_class->set_property = tp_tests_stream_tube_channel_set_property; - object_class->dispose = dispose; - - base_class->channel_type = TP_IFACE_CHANNEL_TYPE_STREAM_TUBE1; - base_class->get_interfaces = tp_tests_stream_tube_channel_get_interfaces; - base_class->close = channel_close; - base_class->fill_immutable_properties = fill_immutable_properties; - - /* base_class->target_entity_type is defined in subclasses */ - - param_spec = g_param_spec_string ("service", "service name", - "the service associated with this tube object.", - "", - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SERVICE, param_spec); - - param_spec = g_param_spec_boxed ( - "supported-socket-types", "Supported socket types", - "GHashTable containing supported socket types.", - TP_HASH_TYPE_SUPPORTED_SOCKET_MAP, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SUPPORTED_SOCKET_TYPES, - param_spec); - - param_spec = g_param_spec_boxed ( - "parameters", "Parameters", - "parameters of the tube", - TP_HASH_TYPE_STRING_VARIANT_MAP, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_PARAMETERS, - param_spec); - - param_spec = g_param_spec_uint ( - "state", "TpTubeState", - "state of the tube", - 0, TP_NUM_TUBE_CHANNEL_STATES - 1, 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STATE, - param_spec); - - signals[SIG_INCOMING_CONNECTION] = g_signal_new ("incoming-connection", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, - 1, G_TYPE_IO_STREAM); - - tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CHANNEL_TYPE_STREAM_TUBE1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - stream_tube_props); - - tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CHANNEL_INTERFACE_TUBE1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - tube_props); - - g_type_class_add_private (object_class, - sizeof (TpTestsStreamTubeChannelPrivate)); -} - -static void -change_state (TpTestsStreamTubeChannel *self, - TpTubeChannelState state) -{ - self->priv->state = state; - - tp_svc_channel_interface_tube1_emit_tube_channel_state_changed (self, state); -} - -/* Return the address of the socket which has been shared over the tube */ -GSocketAddress * -tp_tests_stream_tube_channel_get_server_address (TpTestsStreamTubeChannel *self) -{ - return tp_g_socket_address_from_variant (self->priv->address_type, - self->priv->address, NULL); -} - -static gboolean -check_address_type (TpTestsStreamTubeChannel *self, - TpSocketAddressType address_type, - TpSocketAccessControl access_control) -{ - GArray *arr; - guint i; - - arr = g_hash_table_lookup (self->priv->supported_socket_types, - GUINT_TO_POINTER (address_type)); - if (arr == NULL) - return FALSE; - - for (i = 0; i < arr->len; i++) - { - if (g_array_index (arr, TpSocketAccessControl, i) == access_control) - return TRUE; - } - - return FALSE; -} - -static void -stream_tube_offer (TpSvcChannelTypeStreamTube1 *iface, - guint address_type, - const GValue *address, - guint access_control, - GHashTable *parameters, - DBusGMethodInvocation *context) -{ - TpTestsStreamTubeChannel *self = (TpTestsStreamTubeChannel *) iface; - GError *error = NULL; - - if (self->priv->state != TP_TUBE_CHANNEL_STATE_NOT_OFFERED) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Tube is not in the not offered state"); - goto fail; - } - - if (!check_address_type (self, address_type, access_control)) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Address type not supported with this access control"); - goto fail; - } - - self->priv->address_type = address_type; - self->priv->address = tp_g_value_slice_dup (address); - self->priv->access_control = access_control; - - change_state (self, TP_TUBE_CHANNEL_STATE_REMOTE_PENDING); - - tp_svc_channel_type_stream_tube1_return_from_offer (context); - return; - -fail: - dbus_g_method_return_error (context, error); - g_error_free (error); -} - -static void -service_incoming_cb (GSocketService *service, - GSocketConnection *connection, - GObject *source_object, - gpointer user_data) -{ - TpTestsStreamTubeChannel *self = user_data; - GError *error = NULL; - - if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS) - { -#ifdef HAVE_GIO_UNIX - GCredentials *creds; - guchar byte; - - /* FIXME: we should an async version of this API (bgo #629503) */ - creds = tp_unix_connection_receive_credentials_with_byte ( - connection, &byte, NULL, &error); - g_assert_no_error (error); - - g_assert_cmpuint (byte, ==, - g_value_get_uchar (self->priv->access_control_param)); - g_object_unref (creds); -#else - /* Tests shouldn't use this if not supported */ - g_assert_not_reached (); -#endif - } - else if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_PORT) - { - GSocketAddress *addr; - guint16 port; - - addr = g_socket_connection_get_remote_address (connection, &error); - g_assert_no_error (error); - - port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)); - - g_assert_cmpuint (port, ==, - g_value_get_uint (self->priv->access_control_param)); - - g_object_unref (addr); - } - - tp_svc_channel_type_stream_tube1_emit_new_local_connection (self, - self->priv->connection_id); - - self->priv->connection_id++; - - g_signal_emit (self, signals[SIG_INCOMING_CONNECTION], 0, connection); -} - -static void -stream_tube_accept (TpSvcChannelTypeStreamTube1 *iface, - TpSocketAddressType address_type, - TpSocketAccessControl access_control, - const GValue *access_control_param, - DBusGMethodInvocation *context) -{ - TpTestsStreamTubeChannel *self = (TpTestsStreamTubeChannel *) iface; - GError *error = NULL; - GValue *address; - - if (self->priv->state != TP_TUBE_CHANNEL_STATE_LOCAL_PENDING) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Tube is not in the local pending state"); - goto fail; - } - - if (!check_address_type (self, address_type, access_control)) - { - g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Address type not supported with this access control"); - goto fail; - } - - address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, - &self->priv->unix_tmpdir, &error); - tp_g_signal_connect_object (self->priv->service, "incoming", - G_CALLBACK (service_incoming_cb), self, 0); - - self->priv->access_control = access_control; - self->priv->access_control_param = tp_g_value_slice_dup ( - access_control_param); - - change_state (self, TP_TUBE_CHANNEL_STATE_OPEN); - - tp_svc_channel_type_stream_tube1_return_from_accept (context, address); - - tp_g_value_slice_free (address); - return; - -fail: - dbus_g_method_return_error (context, error); - g_error_free (error); -} - -static void -stream_tube_iface_init (gpointer iface, - gpointer data) -{ - TpSvcChannelTypeStreamTube1Class *klass = iface; - -#define IMPLEMENT(x) tp_svc_channel_type_stream_tube1_implement_##x (klass, stream_tube_##x) - IMPLEMENT(offer); - IMPLEMENT(accept); -#undef IMPLEMENT -} - -/* Called to emulate a peer connecting to an offered tube */ -void -tp_tests_stream_tube_channel_peer_connected (TpTestsStreamTubeChannel *self, - GIOStream *stream, - TpHandle handle) -{ - GValue *connection_param; - TpBaseChannel *base = (TpBaseChannel *) self; - TpBaseConnection *conn = tp_base_channel_get_connection (base); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn, - TP_ENTITY_TYPE_CONTACT); - - if (self->priv->state == TP_TUBE_CHANNEL_STATE_REMOTE_PENDING) - change_state (self, TP_TUBE_CHANNEL_STATE_OPEN); - - g_assert (self->priv->state == TP_TUBE_CHANNEL_STATE_OPEN); - - switch (self->priv->access_control) - { - case TP_SOCKET_ACCESS_CONTROL_LOCALHOST: - connection_param = tp_g_value_slice_new_static_string ("dummy"); - break; - - case TP_SOCKET_ACCESS_CONTROL_CREDENTIALS: - { -#ifdef HAVE_GIO_UNIX - GError *error = NULL; - guchar byte = g_random_int_range (0, G_MAXUINT8); - - /* FIXME: we should an async version of this API (bgo #629503) */ - tp_unix_connection_send_credentials_with_byte ( - G_SOCKET_CONNECTION (stream), byte, NULL, &error); - g_assert_no_error (error); - - connection_param = tp_g_value_slice_new_byte (byte); -#else - /* Tests shouldn't use this if not supported */ - g_assert_not_reached (); -#endif - } - break; - - case TP_SOCKET_ACCESS_CONTROL_PORT: - { - GSocketAddress *addr; - GError *error = NULL; - - addr = g_socket_connection_get_local_address ( - G_SOCKET_CONNECTION (stream), &error); - g_assert_no_error (error); - - connection_param = tp_g_value_slice_new_take_boxed ( - TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4, - dbus_g_type_specialized_construct ( - TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4)); - - dbus_g_type_struct_set (connection_param, - 0, "badger", - 1, g_inet_socket_address_get_port ( - G_INET_SOCKET_ADDRESS (addr)), - G_MAXUINT); - - g_object_unref (addr); - } - break; - - default: - g_assert_not_reached (); - } - - tp_svc_channel_type_stream_tube1_emit_new_remote_connection (self, handle, - tp_handle_inspect (contact_repo, handle), connection_param, - self->priv->connection_id); - - self->priv->connection_id++; - - tp_g_value_slice_free (connection_param); -} - -void -tp_tests_stream_tube_channel_last_connection_disconnected ( - TpTestsStreamTubeChannel *self, - const gchar *error) -{ - tp_svc_channel_type_stream_tube1_emit_connection_closed (self, - self->priv->connection_id - 1, error, "kaboum"); -} - -/* Contact Stream Tube */ - -G_DEFINE_TYPE (TpTestsContactStreamTubeChannel, - tp_tests_contact_stream_tube_channel, - TP_TESTS_TYPE_STREAM_TUBE_CHANNEL) - -static void -tp_tests_contact_stream_tube_channel_init ( - TpTestsContactStreamTubeChannel *self) -{ -} - -static void -tp_tests_contact_stream_tube_channel_class_init ( - TpTestsContactStreamTubeChannelClass *klass) -{ - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - - base_class->target_entity_type = TP_ENTITY_TYPE_CONTACT; -} - -/* Room Stream Tube */ - -G_DEFINE_TYPE (TpTestsRoomStreamTubeChannel, - tp_tests_room_stream_tube_channel, - TP_TESTS_TYPE_STREAM_TUBE_CHANNEL) - -static void -tp_tests_room_stream_tube_channel_init ( - TpTestsRoomStreamTubeChannel *self) -{ -} - -static void -tp_tests_room_stream_tube_channel_class_init ( - TpTestsRoomStreamTubeChannelClass *klass) -{ - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - - base_class->target_entity_type = TP_ENTITY_TYPE_ROOM; -} diff --git a/tests/lib/telepathy/contactlist/stream-tube-chan.h b/tests/lib/telepathy/contactlist/stream-tube-chan.h deleted file mode 100644 index 26729127..00000000 --- a/tests/lib/telepathy/contactlist/stream-tube-chan.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * stream-tube-chan.h - Simple stream tube channel - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TP_STREAM_TUBE_CHAN_H__ -#define __TP_STREAM_TUBE_CHAN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -/* Base Class */ -typedef struct _TpTestsStreamTubeChannel TpTestsStreamTubeChannel; -typedef struct _TpTestsStreamTubeChannelClass TpTestsStreamTubeChannelClass; -typedef struct _TpTestsStreamTubeChannelPrivate TpTestsStreamTubeChannelPrivate; - -GType tp_tests_stream_tube_channel_get_type (void); - -#define TP_TESTS_TYPE_STREAM_TUBE_CHANNEL \ - (tp_tests_stream_tube_channel_get_type ()) -#define TP_TESTS_STREAM_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_STREAM_TUBE_CHANNEL, \ - TpTestsStreamTubeChannel)) -#define TP_TESTS_STREAM_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_STREAM_TUBE_CHANNEL, \ - TpTestsStreamTubeChannelClass)) -#define TP_TESTS_IS_STREAM_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_STREAM_TUBE_CHANNEL)) -#define TP_TESTS_IS_STREAM_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_STREAM_TUBE_CHANNEL)) -#define TP_TESTS_STREAM_TUBE_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_STREAM_TUBE_CHANNEL, \ - TpTestsStreamTubeChannelClass)) - -struct _TpTestsStreamTubeChannelClass { - TpBaseChannelClass parent_class; - TpDBusPropertiesMixinClass dbus_properties_class; -}; - -struct _TpTestsStreamTubeChannel { - TpBaseChannel parent; - - TpTestsStreamTubeChannelPrivate *priv; -}; - -GSocketAddress * tp_tests_stream_tube_channel_get_server_address ( - TpTestsStreamTubeChannel *self); - -void tp_tests_stream_tube_channel_peer_connected ( - TpTestsStreamTubeChannel *self, - GIOStream *stream, - TpHandle handle); - -void tp_tests_stream_tube_channel_last_connection_disconnected ( - TpTestsStreamTubeChannel *self, - const gchar *error); - -/* Contact Stream Tube */ - -typedef struct _TpTestsContactStreamTubeChannel TpTestsContactStreamTubeChannel; -typedef struct _TpTestsContactStreamTubeChannelClass TpTestsContactStreamTubeChannelClass; - -GType tp_tests_contact_stream_tube_channel_get_type (void); - -#define TP_TESTS_TYPE_CONTACT_STREAM_TUBE_CHANNEL \ - (tp_tests_contact_stream_tube_channel_get_type ()) -#define TP_TESTS_CONTACT_STREAM_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_CONTACT_STREAM_TUBE_CHANNEL, \ - TpTestsContactStreamTubeChannel)) -#define TP_TESTS_CONTACT_STREAM_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_CONTACT_STREAM_TUBE_CHANNEL, \ - TpTestsContactStreamTubeChannelClass)) -#define TP_TESTS_IS_CONTACT_STREAM_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_CONTACT_STREAM_TUBE_CHANNEL)) -#define TP_TESTS_IS_CONTACT_STREAM_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_CONTACT_STREAM_TUBE_CHANNEL)) -#define TP_TESTS_CONTACT_STREAM_TUBE_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_CONTACT_STREAM_TUBE_CHANNEL, \ - TpTestsContactStreamTubeChannelClass)) - -struct _TpTestsContactStreamTubeChannelClass { - TpTestsStreamTubeChannelClass parent_class; -}; - -struct _TpTestsContactStreamTubeChannel { - TpTestsStreamTubeChannel parent; -}; - -/* Room Stream Tube */ - -typedef struct _TpTestsRoomStreamTubeChannel TpTestsRoomStreamTubeChannel; -typedef struct _TpTestsRoomStreamTubeChannelClass TpTestsRoomStreamTubeChannelClass; - -GType tp_tests_room_stream_tube_channel_get_type (void); - -#define TP_TESTS_TYPE_ROOM_STREAM_TUBE_CHANNEL \ - (tp_tests_room_stream_tube_channel_get_type ()) -#define TP_TESTS_ROOM_STREAM_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_ROOM_STREAM_TUBE_CHANNEL, \ - TpTestsRoomStreamTubeChannel)) -#define TP_TESTS_ROOM_STREAM_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_ROOM_STREAM_TUBE_CHANNEL, \ - TpTestsRoomStreamTubeChannelClass)) -#define TP_TESTS_IS_ROOM_STREAM_TUBE_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_ROOM_STREAM_TUBE_CHANNEL)) -#define TP_TESTS_IS_ROOM_STREAM_TUBE_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_ROOM_STREAM_TUBE_CHANNEL)) -#define TP_TESTS_ROOM_STREAM_TUBE_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_ROOM_STREAM_TUBE_CHANNEL, \ - TpTestsRoomStreamTubeChannelClass)) - -struct _TpTestsRoomStreamTubeChannelClass { - TpTestsStreamTubeChannelClass parent_class; -}; - -struct _TpTestsRoomStreamTubeChannel { - TpTestsStreamTubeChannel parent; -}; - -G_END_DECLS - -#endif /* #ifndef __TP_STREAM_TUBE_CHAN_H__ */ diff --git a/tests/lib/telepathy/contactlist/stub-object.c b/tests/lib/telepathy/contactlist/stub-object.c deleted file mode 100644 index 14828768..00000000 --- a/tests/lib/telepathy/contactlist/stub-object.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "config.h" - -#include "stub-object.h" - -G_DEFINE_TYPE (TpTestsStubObject, tp_tests_stub_object, G_TYPE_OBJECT) - -enum { - PROP_0, - PROP_NAME, - N_PROPS -}; - -static void -stub_object_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *param_spec) -{ - switch (prop_id) - { - case PROP_NAME: - g_value_set_string (value, "Bruce"); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, param_spec); - break; - } -} - -static void -stub_object_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *param_spec) -{ - switch (prop_id) - { - case PROP_NAME: - /* do nothing */ - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, param_spec); - break; - } -} - -static void -tp_tests_stub_object_class_init (TpTestsStubObjectClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - - object_class->get_property = stub_object_get_property; - object_class->set_property = stub_object_set_property; - - g_object_class_install_property (object_class, PROP_NAME, - g_param_spec_string ("name", - "Name", - "The name of the stub object", - "Bruce", - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); -} - -static void -tp_tests_stub_object_init (TpTestsStubObject *self) -{ -} diff --git a/tests/lib/telepathy/contactlist/stub-object.h b/tests/lib/telepathy/contactlist/stub-object.h deleted file mode 100644 index ccdb0940..00000000 --- a/tests/lib/telepathy/contactlist/stub-object.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __TP_TESTS_STUB_OBJECT_H__ -#define __TP_TESTS_STUB_OBJECT_H__ - -#include <glib-object.h> - -typedef struct { GObject p; } TpTestsStubObject; -typedef struct { GObjectClass p; } TpTestsStubObjectClass; - -GType tp_tests_stub_object_get_type (void); - -#endif /* #ifndef __TP_TESTS_STUB_OBJECT_H__ */ diff --git a/tests/lib/telepathy/contactlist/textchan-group.c b/tests/lib/telepathy/contactlist/textchan-group.c deleted file mode 100644 index fedb0028..00000000 --- a/tests/lib/telepathy/contactlist/textchan-group.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * a stub anonymous MUC - * - * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2008 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#include "config.h" - -#include "textchan-group.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -static void password_iface_init (gpointer iface, gpointer data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsTextChannelGroup, - tp_tests_text_channel_group, TP_TYPE_BASE_CHANNEL, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TEXT, - tp_message_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_GROUP1, - tp_group_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_PASSWORD1, - password_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init)) - -static GPtrArray * -text_channel_group_get_interfaces (TpBaseChannel *self) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CHANNEL_CLASS ( - tp_tests_text_channel_group_parent_class)->get_interfaces (self); - - g_ptr_array_add (interfaces, TP_IFACE_CHANNEL_INTERFACE_GROUP1); - g_ptr_array_add (interfaces, TP_IFACE_CHANNEL_INTERFACE_PASSWORD1); - return interfaces; -}; - -/* type definition stuff */ - -struct _TpTestsTextChannelGroupPrivate -{ - gboolean closed; - gboolean disposed; - - gchar *password; -}; - - -static gboolean -add_member (GObject *obj, - TpHandle handle, - const gchar *message, - GError **error) -{ - TpTestsTextChannelGroup *self = TP_TESTS_TEXT_CHANNEL_GROUP (obj); - TpIntset *add = tp_intset_new (); - GHashTable *details = tp_asv_new ( - "actor", G_TYPE_UINT, tp_base_connection_get_self_handle (self->conn), - "change-reason", G_TYPE_UINT, TP_CHANNEL_GROUP_CHANGE_REASON_NONE, - "message", G_TYPE_STRING, message, - NULL); - - tp_intset_add (add, handle); - tp_group_mixin_change_members (obj, add, NULL, NULL, NULL, details); - tp_intset_destroy (add); - - g_hash_table_unref (details); - - return TRUE; -} - -static gboolean -remove_with_reason (GObject *obj, - TpHandle handle, - const gchar *message, - guint reason, - GError **error) -{ - TpTestsTextChannelGroup *self = TP_TESTS_TEXT_CHANNEL_GROUP (obj); - TpGroupMixin *group = TP_GROUP_MIXIN (self); - - tp_clear_pointer (&self->removed_message, g_free); - - self->removed_handle = handle; - self->removed_message = g_strdup (message); - self->removed_reason = reason; - - if (handle == group->self_handle) - { - /* User wants to leave */ - if (!self->priv->closed) - { - self->priv->closed = TRUE; - tp_svc_channel_emit_closed (self); - } - - return TRUE; - } - - return TRUE; -} - -static void -tp_tests_text_channel_group_init (TpTestsTextChannelGroup *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_TEXT_CHANNEL_GROUP, TpTestsTextChannelGroupPrivate); -} - -static void -text_send (GObject *object, - TpMessage *message, - TpMessageSendingFlags flags) -{ - /* silently swallow the message */ - tp_message_mixin_sent (object, message, 0, "", NULL); -} - -static void -constructed (GObject *object) -{ - TpTestsTextChannelGroup *self = TP_TESTS_TEXT_CHANNEL_GROUP (object); - TpHandleRepoIface *contact_repo; - TpChannelGroupFlags flags = 0; - TpBaseChannel *base = TP_BASE_CHANNEL (self); - const TpChannelTextMessageType types[] = { - TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, - TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION, - TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE, - }; - const gchar * supported_content_types[] = { - "text/plain", - NULL - }; - - G_OBJECT_CLASS (tp_tests_text_channel_group_parent_class)->constructed ( - object); - - self->conn = tp_base_channel_get_connection (base); - - contact_repo = tp_base_connection_get_handles (self->conn, - TP_ENTITY_TYPE_CONTACT); - - tp_base_channel_register (base); - - tp_message_mixin_init (object, - G_STRUCT_OFFSET (TpTestsTextChannelGroup, message), - self->conn); - - tp_message_mixin_implement_sending (object, - text_send, G_N_ELEMENTS (types), types, 0, 0, - supported_content_types); - - flags |= TP_CHANNEL_GROUP_FLAG_CAN_ADD; - - tp_group_mixin_init (object, G_STRUCT_OFFSET (TpTestsTextChannelGroup, group), - contact_repo, - tp_base_connection_get_self_handle (self->conn)); - - tp_group_mixin_change_flags (object, flags, 0); -} - -static void -dispose (GObject *object) -{ - TpTestsTextChannelGroup *self = TP_TESTS_TEXT_CHANNEL_GROUP (object); - - if (self->priv->disposed) - return; - - self->priv->disposed = TRUE; - - if (!self->priv->closed) - { - tp_svc_channel_emit_closed (self); - } - - ((GObjectClass *) tp_tests_text_channel_group_parent_class)->dispose (object); -} - -static void -finalize (GObject *object) -{ - TpTestsTextChannelGroup *self = TP_TESTS_TEXT_CHANNEL_GROUP (object); - - tp_message_mixin_finalize (object); - tp_group_mixin_finalize (object); - - tp_clear_pointer (&self->priv->password, g_free); - - ((GObjectClass *) tp_tests_text_channel_group_parent_class)->finalize (object); -} - -static void -channel_close (TpBaseChannel *base) -{ - TpTestsTextChannelGroup *self = TP_TESTS_TEXT_CHANNEL_GROUP (base); - - if (!self->priv->closed) - { - self->priv->closed = TRUE; - tp_svc_channel_emit_closed (self); - } -} - -static void -tp_tests_text_channel_group_class_init (TpTestsTextChannelGroupClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - TpBaseChannelClass *base_class = (TpBaseChannelClass *) klass; - - g_type_class_add_private (klass, sizeof (TpTestsTextChannelGroupPrivate)); - - object_class->constructed = constructed; - object_class->dispose = dispose; - object_class->finalize = finalize; - - base_class->channel_type = TP_IFACE_CHANNEL_TYPE_TEXT; - base_class->target_entity_type = TP_ENTITY_TYPE_NONE; - base_class->get_interfaces = text_channel_group_get_interfaces; - base_class->close = channel_close; - - tp_group_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsTextChannelGroupClass, group_class), add_member, - NULL); - - tp_group_mixin_class_set_remove_with_reason_func (object_class, - remove_with_reason); - - tp_group_mixin_class_allow_self_removal (object_class); - - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsTextChannelGroupClass, dbus_properties_class)); - - tp_group_mixin_init_dbus_properties (object_class); - - tp_message_mixin_init_dbus_properties (object_class); -} - -void -tp_tests_text_channel_group_join (TpTestsTextChannelGroup *self) -{ - TpIntset *add, *empty; - GHashTable *details = tp_asv_new ( - "actor", G_TYPE_UINT, 0, - "change-reason", G_TYPE_UINT, 0, - "message", G_TYPE_STRING, "", - NULL); - - /* Add ourself as a member */ - add = tp_intset_new_containing ( - tp_base_connection_get_self_handle (self->conn)); - empty = tp_intset_new (); - - tp_group_mixin_change_members ((GObject *) self, add, empty, - empty, empty, details); - - tp_intset_destroy (add); - tp_intset_destroy (empty); - g_hash_table_unref (details); -} - -void -tp_tests_text_channel_set_password (TpTestsTextChannelGroup *self, - const gchar *password) -{ - gboolean pass_was_needed, pass_needed; - - pass_was_needed = (self->priv->password != NULL); - - tp_clear_pointer (&self->priv->password, g_free); - - self->priv->password = g_strdup (password); - - pass_needed = (self->priv->password != NULL); - - if (pass_needed == pass_was_needed) - return; - - if (pass_needed) - tp_svc_channel_interface_password1_emit_password_flags_changed (self, - TP_CHANNEL_PASSWORD_FLAG_PROVIDE, 0); - else - tp_svc_channel_interface_password1_emit_password_flags_changed (self, - 0, TP_CHANNEL_PASSWORD_FLAG_PROVIDE); -} - -static void -password_get_password_flags (TpSvcChannelInterfacePassword1 *chan, - DBusGMethodInvocation *context) -{ - TpTestsTextChannelGroup *self = (TpTestsTextChannelGroup *) chan; - TpChannelPasswordFlags flags = 0; - - if (self->priv->password != NULL) - flags |= TP_CHANNEL_PASSWORD_FLAG_PROVIDE; - - tp_svc_channel_interface_password1_return_from_get_password_flags (context, - flags); -} - -static void -password_provide_password (TpSvcChannelInterfacePassword1 *chan, - const gchar *password, - DBusGMethodInvocation *context) -{ - TpTestsTextChannelGroup *self = (TpTestsTextChannelGroup *) chan; - - tp_svc_channel_interface_password1_return_from_provide_password (context, - !tp_strdiff (password, self->priv->password)); -} - -static void -password_iface_init (gpointer iface, gpointer data) -{ - TpSvcChannelInterfacePassword1Class *klass = iface; - -#define IMPLEMENT(x) tp_svc_channel_interface_password1_implement_##x (klass, password_##x) - IMPLEMENT (get_password_flags); - IMPLEMENT (provide_password); -#undef IMPLEMENT -} diff --git a/tests/lib/telepathy/contactlist/textchan-group.h b/tests/lib/telepathy/contactlist/textchan-group.h deleted file mode 100644 index 810e0048..00000000 --- a/tests/lib/telepathy/contactlist/textchan-group.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * a stub anonymous MUC - * - * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2008 Nokia Corporation - * - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. - */ - -#ifndef __TEST_TEXT_CHANNEL_GROUP_H__ -#define __TEST_TEXT_CHANNEL_GROUP_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsTextChannelGroup TpTestsTextChannelGroup; -typedef struct _TpTestsTextChannelGroupClass TpTestsTextChannelGroupClass; -typedef struct _TpTestsTextChannelGroupPrivate TpTestsTextChannelGroupPrivate; - -GType tp_tests_text_channel_group_get_type (void); - -#define TP_TESTS_TYPE_TEXT_CHANNEL_GROUP \ - (tp_tests_text_channel_group_get_type ()) -#define TP_TESTS_TEXT_CHANNEL_GROUP(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_TEXT_CHANNEL_GROUP, \ - TpTestsTextChannelGroup)) -#define TP_TESTS_TEXT_CHANNEL_GROUP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_TEXT_CHANNEL_GROUP, \ - TpTestsTextChannelGroupClass)) -#define TEST_IS_TEXT_CHANNEL_GROUP(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_TEXT_CHANNEL_GROUP)) -#define TEST_IS_TEXT_CHANNEL_GROUP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_TEXT_CHANNEL_GROUP)) -#define TP_TESTS_TEXT_CHANNEL_GROUP_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_TEXT_CHANNEL_GROUP, \ - TpTestsTextChannelGroupClass)) - -struct _TpTestsTextChannelGroupClass { - TpBaseChannelClass parent_class; - - TpGroupMixinClass group_class; - TpDBusPropertiesMixinClass dbus_properties_class; -}; - -struct _TpTestsTextChannelGroup { - TpBaseChannel parent; - - TpBaseConnection *conn; - - TpMessageMixin message; - TpGroupMixin group; - - TpHandle removed_handle; - gchar *removed_message; - TpChannelGroupChangeReason removed_reason; - - TpTestsTextChannelGroupPrivate *priv; -}; - - -void tp_tests_text_channel_group_join (TpTestsTextChannelGroup *self); - -void tp_tests_text_channel_set_password (TpTestsTextChannelGroup *self, - const gchar *password); - -G_END_DECLS - -#endif /* #ifndef __TEST_TEXT_CHANNEL_GROUP_H__ */ diff --git a/tests/lib/telepathy/contactlist/tls-certificate.c b/tests/lib/telepathy/contactlist/tls-certificate.c deleted file mode 100644 index 0da16456..00000000 --- a/tests/lib/telepathy/contactlist/tls-certificate.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * tls-certificate.c - Source for TpTestsTLSCertificate - * Copyright (C) 2010 Collabora Ltd. - * @author Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" -#include "tls-certificate.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#define DEBUG_FLAG TP_TESTS_DEBUG_TLS -#include "debug.h" - -static void -tls_certificate_iface_init (gpointer g_iface, gpointer iface_data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsTLSCertificate, - tp_tests_tls_certificate, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_AUTHENTICATION_TLS_CERTIFICATE, - tls_certificate_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init);) - -struct _TpTestsTLSCertificatePrivate { - gchar *object_path; - - gchar *cert_type; - TpTLSCertificateState cert_state; - - GPtrArray *rejections; - GPtrArray *cert_data; - - TpDBusDaemon *daemon; - - gboolean dispose_has_run; -}; - -enum { - PROP_OBJECT_PATH = 1, - PROP_STATE, - PROP_REJECTIONS, - PROP_CERTIFICATE_TYPE, - PROP_CERTIFICATE_CHAIN_DATA, - - /* not exported */ - PROP_DBUS_DAEMON, - - NUM_PROPERTIES -}; - -static void -tp_tests_tls_certificate_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (object); - - switch (property_id) - { - case PROP_OBJECT_PATH: - g_value_set_string (value, self->priv->object_path); - break; - case PROP_STATE: - g_value_set_uint (value, self->priv->cert_state); - break; - case PROP_REJECTIONS: - g_value_set_boxed (value, self->priv->rejections); - break; - case PROP_CERTIFICATE_TYPE: - g_value_set_string (value, self->priv->cert_type); - break; - case PROP_CERTIFICATE_CHAIN_DATA: - g_value_set_boxed (value, self->priv->cert_data); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -tp_tests_tls_certificate_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (object); - - switch (property_id) - { - case PROP_OBJECT_PATH: - self->priv->object_path = g_value_dup_string (value); - break; - case PROP_CERTIFICATE_TYPE: - self->priv->cert_type = g_value_dup_string (value); - break; - case PROP_CERTIFICATE_CHAIN_DATA: - self->priv->cert_data = g_value_dup_boxed (value); - break; - case PROP_DBUS_DAEMON: - self->priv->daemon = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, value); - break; - } -} - -static void -tp_tests_tls_certificate_finalize (GObject *object) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (object); - - tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST, - &self->priv->rejections); - - g_free (self->priv->object_path); - g_free (self->priv->cert_type); - g_ptr_array_unref (self->priv->cert_data); - - G_OBJECT_CLASS (tp_tests_tls_certificate_parent_class)->finalize (object); -} - -static void -tp_tests_tls_certificate_dispose (GObject *object) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (object); - - if (self->priv->dispose_has_run) - return; - - self->priv->dispose_has_run = TRUE; - - tp_clear_object (&self->priv->daemon); - - G_OBJECT_CLASS (tp_tests_tls_certificate_parent_class)->dispose (object); -} - -static void -tp_tests_tls_certificate_constructed (GObject *object) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (object); - void (*chain_up) (GObject *) = - G_OBJECT_CLASS (tp_tests_tls_certificate_parent_class)->constructed; - - if (chain_up != NULL) - chain_up (object); - - /* register the certificate on the bus */ - tp_dbus_daemon_register_object (self->priv->daemon, - self->priv->object_path, self); -} - -static void -tp_tests_tls_certificate_init (TpTestsTLSCertificate *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_TLS_CERTIFICATE, TpTestsTLSCertificatePrivate); - self->priv->rejections = g_ptr_array_new (); -} - -static void -tp_tests_tls_certificate_class_init (TpTestsTLSCertificateClass *klass) -{ - static TpDBusPropertiesMixinPropImpl object_props[] = { - { "State", "state", NULL }, - { "Rejections", "rejections", NULL }, - { "CertificateType", "certificate-type", NULL }, - { "CertificateChainData", "certificate-chain-data", NULL }, - { NULL } - }; - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_AUTHENTICATION_TLS_CERTIFICATE, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - object_props, - }, - { NULL } - }; - GObjectClass *oclass = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - g_type_class_add_private (klass, sizeof (TpTestsTLSCertificatePrivate)); - - oclass->finalize = tp_tests_tls_certificate_finalize; - oclass->dispose = tp_tests_tls_certificate_dispose; - oclass->set_property = tp_tests_tls_certificate_set_property; - oclass->get_property = tp_tests_tls_certificate_get_property; - oclass->constructed = tp_tests_tls_certificate_constructed; - - pspec = g_param_spec_string ("object-path", - "D-Bus object path", - "The D-Bus object path used for this object on the bus.", - NULL, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_OBJECT_PATH, pspec); - - pspec = g_param_spec_uint ("state", - "State of this certificate", - "The state of this TLS certificate.", - 0, TP_NUM_TLS_CERTIFICATE_STATES - 1, - TP_TLS_CERTIFICATE_STATE_PENDING, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_STATE, pspec); - - pspec = g_param_spec_boxed ("rejections", - "The reject reasons", - "The reasons why this TLS certificate has been rejected", - TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_REJECTIONS, pspec); - - pspec = g_param_spec_string ("certificate-type", - "The certificate type", - "The type of this certificate.", - NULL, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_CERTIFICATE_TYPE, pspec); - - pspec = g_param_spec_boxed ("certificate-chain-data", - "The certificate chain data", - "The raw PEM-encoded trust chain of this certificate.", - TP_ARRAY_TYPE_UCHAR_ARRAY_LIST, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_CERTIFICATE_CHAIN_DATA, pspec); - - pspec = g_param_spec_object ("dbus-daemon", - "The DBus daemon connection", - "The connection to the DBus daemon owning the CM", - TP_TYPE_DBUS_DAEMON, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_DBUS_DAEMON, pspec); - - klass->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (oclass, - G_STRUCT_OFFSET (TpTestsTLSCertificateClass, dbus_props_class)); -} - -static void -tp_tests_tls_certificate_accept (TpSvcAuthenticationTLSCertificate *cert, - DBusGMethodInvocation *context) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (cert); - - DEBUG ("Accept() called on the TLS certificate; current state %u", - self->priv->cert_state); - - if (self->priv->cert_state != TP_TLS_CERTIFICATE_STATE_PENDING) - { - GError error = - { TP_ERROR, - TP_ERROR_INVALID_ARGUMENT, - "Calling Accept() on a certificate with state != PENDING " - "doesn't make sense." - }; - - dbus_g_method_return_error (context, &error); - return; - } - - self->priv->cert_state = TP_TLS_CERTIFICATE_STATE_ACCEPTED; - tp_svc_authentication_tls_certificate_emit_accepted (self); - - tp_svc_authentication_tls_certificate_return_from_accept (context); -} - -static void -tp_tests_tls_certificate_reject (TpSvcAuthenticationTLSCertificate *cert, - const GPtrArray *rejections, - DBusGMethodInvocation *context) -{ - TpTestsTLSCertificate *self = TP_TESTS_TLS_CERTIFICATE (cert); - - DEBUG ("Reject() called on the TLS certificate with rejections %p, " - "length %u; current state %u", rejections, rejections->len, - self->priv->cert_state); - - if (rejections->len < 1) - { - GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Calling Reject() with a zero-length rejection list." }; - - dbus_g_method_return_error (context, &error); - return; - } - - if (self->priv->cert_state != TP_TLS_CERTIFICATE_STATE_PENDING) - { - GError error = - { TP_ERROR, - TP_ERROR_INVALID_ARGUMENT, - "Calling Reject() on a certificate with state != PENDING " - "doesn't make sense." - }; - - dbus_g_method_return_error (context, &error); - return; - } - - tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST, - &self->priv->rejections); - - self->priv->rejections = - g_boxed_copy (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST, - rejections); - self->priv->cert_state = TP_TLS_CERTIFICATE_STATE_REJECTED; - - tp_svc_authentication_tls_certificate_emit_rejected ( - self, self->priv->rejections); - - tp_svc_authentication_tls_certificate_return_from_reject (context); -} - -static void -tls_certificate_iface_init (gpointer g_iface, - gpointer iface_data) -{ - TpSvcAuthenticationTLSCertificateClass *klass = g_iface; - -#define IMPLEMENT(x) \ - tp_svc_authentication_tls_certificate_implement_##x ( \ - klass, tp_tests_tls_certificate_##x) - IMPLEMENT (accept); - IMPLEMENT (reject); -#undef IMPLEMENT -} - -void -tp_tests_tls_certificate_clear_rejection (TpTestsTLSCertificate *self) -{ - g_ptr_array_set_size (self->priv->rejections, 0); -} diff --git a/tests/lib/telepathy/contactlist/tls-certificate.h b/tests/lib/telepathy/contactlist/tls-certificate.h deleted file mode 100644 index 1de31927..00000000 --- a/tests/lib/telepathy/contactlist/tls-certificate.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * tls-certificate.h - Header for TpTestsTLSCertificate - * Copyright (C) 2010 Collabora Ltd. - * @author Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __TP_TESTS_TLS_CERTIFICATE_H__ -#define __TP_TESTS_TLS_CERTIFICATE_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsTLSCertificate TpTestsTLSCertificate; -typedef struct _TpTestsTLSCertificateClass TpTestsTLSCertificateClass; -typedef struct _TpTestsTLSCertificatePrivate TpTestsTLSCertificatePrivate; - -struct _TpTestsTLSCertificateClass { - GObjectClass parent_class; - - TpDBusPropertiesMixinClass dbus_props_class; -}; - -struct _TpTestsTLSCertificate { - GObject parent; - - TpTestsTLSCertificatePrivate *priv; -}; - -GType tp_tests_tls_certificate_get_type (void); - -#define TP_TESTS_TYPE_TLS_CERTIFICATE \ - (tp_tests_tls_certificate_get_type ()) -#define TP_TESTS_TLS_CERTIFICATE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_TLS_CERTIFICATE, \ - TpTestsTLSCertificate)) -#define TP_TESTS_TLS_CERTIFICATE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_TLS_CERTIFICATE, \ - TpTestsTLSCertificateClass)) -#define TP_TESTS_IS_TLS_CERTIFICATE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_TLS_CERTIFICATE)) -#define TP_TESTS_IS_TLS_CERTIFICATE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_TLS_CERTIFICATE)) -#define TP_TESTS_TLS_CERTIFICATE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_TLS_CERTIFICATE, \ - TpTestsTLSCertificateClass)) - -void tp_tests_tls_certificate_clear_rejection (TpTestsTLSCertificate *self); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_TLS_CERTIFICATE_H__*/ |