[Telepathy-commits] [telepathy-glib/master] test-group-mixin: Add stub
Will Thompson
will.thompson at collabora.co.uk
Mon Jan 12 04:18:08 PST 2009
---
.gitignore | 1 +
tests/dbus/Makefile.am | 3 +
tests/dbus/group-mixin.c | 111 +++++++++++++
tests/lib/Makefile.am | 2 +
tests/lib/textchan-group.c | 376 ++++++++++++++++++++++++++++++++++++++++++++
tests/lib/textchan-group.h | 59 +++++++
6 files changed, 552 insertions(+), 0 deletions(-)
create mode 100644 tests/dbus/group-mixin.c
create mode 100644 tests/lib/textchan-group.c
create mode 100644 tests/lib/textchan-group.h
diff --git a/.gitignore b/.gitignore
index 6da86cf..80e6604 100644
--- a/.gitignore
+++ b/.gitignore
@@ -78,6 +78,7 @@ tests/dbus/test-dbus
tests/dbus/test-disconnection
tests/dbus/test-example-no-protocols
tests/dbus/test-finalized-in-invalidated-handler
+tests/dbus/test-group-mixin
tests/dbus/test-handle-set
tests/dbus/test-invalidated-while-invoking-signals
tests/dbus/test-message-mixin
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 6c013c6..294074c 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -13,6 +13,7 @@ noinst_PROGRAMS = \
test-disconnection \
test-example-no-protocols \
test-finalized-in-invalidated-handler \
+ test-group-mixin \
test-handle-set \
test-invalidated-while-invoking-signals \
test-message-mixin \
@@ -49,6 +50,8 @@ test_contacts_mixin_SOURCES = contacts-mixin.c
test_finalized_in_invalidated_handler_SOURCES = \
finalized-in-invalidated-handler.c
+test_group_mixin_SOURCES = group-mixin.c
+
test_handle_set_SOURCES = handle-set.c
test_invalidated_while_invoking_signals_SOURCES = \
diff --git a/tests/dbus/group-mixin.c b/tests/dbus/group-mixin.c
new file mode 100644
index 0000000..fa22cbb
--- /dev/null
+++ b/tests/dbus/group-mixin.c
@@ -0,0 +1,111 @@
+/* Test TpGroupMixin
+ *
+ * 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.
+ */
+
+#include <telepathy-glib/channel.h>
+#include <telepathy-glib/connection.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/debug.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/proxy-subclass.h>
+
+#include "tests/lib/myassert.h"
+#include "tests/lib/simple-conn.h"
+#include "tests/lib/textchan-group.h"
+#include "tests/lib/util.h"
+
+#define IDENTIFIER "them at example.org"
+
+static int fail = 0;
+static GMainLoop *mainloop;
+
+static void
+myassert_failed (void)
+{
+ fail = 1;
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ SimpleConnection *service_conn;
+ TpBaseConnection *service_conn_as_base;
+ TpHandleRepoIface *contact_repo;
+ TestTextChannelGroup *service_chan;
+ TpDBusDaemon *dbus;
+ TpConnection *conn;
+ TpChannel *chan = NULL;
+ GError *error = NULL;
+ gchar *name;
+ gchar *conn_path;
+ gchar *chan_path;
+
+ g_type_init ();
+ tp_debug_set_flags ("all");
+
+ service_conn = SIMPLE_CONNECTION (g_object_new (SIMPLE_TYPE_CONNECTION,
+ "account", "me at example.com",
+ "protocol", "simple",
+ NULL));
+ service_conn_as_base = TP_BASE_CONNECTION (service_conn);
+ MYASSERT (service_conn != NULL, "");
+ MYASSERT (service_conn_as_base != NULL, "");
+
+ MYASSERT (tp_base_connection_register (service_conn_as_base, "simple",
+ &name, &conn_path, &error), "");
+ MYASSERT_NO_ERROR (error);
+
+ dbus = tp_dbus_daemon_new (tp_get_bus ());
+ conn = tp_connection_new (dbus, name, conn_path, &error);
+ MYASSERT (conn != NULL, "");
+ MYASSERT_NO_ERROR (error);
+
+ MYASSERT (tp_connection_run_until_ready (conn, TRUE, &error, NULL),
+ "");
+ MYASSERT_NO_ERROR (error);
+
+ contact_repo = tp_base_connection_get_handles (service_conn_as_base,
+ TP_HANDLE_TYPE_CONTACT);
+ MYASSERT (contact_repo != NULL, "");
+
+ chan_path = g_strdup_printf ("%s/Channel", conn_path);
+
+ service_chan = TEST_TEXT_CHANNEL_GROUP (g_object_new (
+ TEST_TYPE_TEXT_CHANNEL_GROUP,
+ "connection", service_conn,
+ "object-path", chan_path,
+ NULL));
+
+ mainloop = g_main_loop_new (NULL, FALSE);
+
+ MYASSERT (tp_cli_connection_run_connect (conn, -1, &error, NULL), "");
+ MYASSERT_NO_ERROR (error);
+
+ MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
+ MYASSERT_NO_ERROR (error);
+
+ /* clean up */
+
+ g_assert (chan == NULL);
+ g_main_loop_unref (mainloop);
+ mainloop = NULL;
+
+ g_object_unref (conn);
+ g_object_unref (service_chan);
+
+ service_conn_as_base = NULL;
+ g_object_unref (service_conn);
+ g_object_unref (dbus);
+ g_free (name);
+ g_free (conn_path);
+ g_free (chan_path);
+
+ return fail;
+}
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index d2509ca..857a17e 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -17,6 +17,8 @@ libtp_glib_tests_la_SOURCES = \
stub-object.h \
textchan-null.c \
textchan-null.h \
+ textchan-group.c \
+ textchan-group.h \
util.c \
util.h
diff --git a/tests/lib/textchan-group.c b/tests/lib/textchan-group.c
new file mode 100644
index 0000000..da229dd
--- /dev/null
+++ b/tests/lib/textchan-group.c
@@ -0,0 +1,376 @@
+/*
+ * 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 "textchan-group.h"
+
+#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/channel-iface.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/svc-channel.h>
+#include <telepathy-glib/svc-generic.h>
+
+static void text_iface_init (gpointer iface, gpointer data);
+static void channel_iface_init (gpointer iface, gpointer data);
+
+G_DEFINE_TYPE_WITH_CODE (TestTextChannelGroup,
+ test_text_channel_group,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL, channel_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TEXT, text_iface_init);
+ /*
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_GROUP,
+ group_iface_init);
+ */
+ G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
+ tp_dbus_properties_mixin_iface_init))
+
+static const char *test_text_channel_group_interfaces[] = {
+ TP_IFACE_CHANNEL_INTERFACE_GROUP,
+ NULL
+};
+
+/* type definition stuff */
+
+enum
+{
+ PROP_OBJECT_PATH = 1,
+ PROP_CHANNEL_TYPE,
+ PROP_HANDLE_TYPE,
+ PROP_HANDLE,
+ PROP_TARGET_ID,
+ PROP_CONNECTION,
+ PROP_INTERFACES,
+ PROP_REQUESTED,
+ PROP_INITIATOR_HANDLE,
+ PROP_INITIATOR_ID,
+ N_PROPS
+};
+
+struct _TestTextChannelGroupPrivate
+{
+ TpBaseConnection *conn;
+ gchar *object_path;
+
+ gboolean closed;
+ gboolean disposed;
+};
+
+static void
+test_text_channel_group_init (TestTextChannelGroup *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TEST_TYPE_TEXT_CHANNEL_GROUP,
+ TestTextChannelGroupPrivate);
+}
+
+static GObject *
+constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
+{
+ GObject *object =
+ G_OBJECT_CLASS (test_text_channel_group_parent_class)->constructor (type,
+ n_props, props);
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (object);
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles
+ (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+ DBusGConnection *bus;
+
+ bus = tp_get_bus ();
+ dbus_g_connection_register_g_object (bus, self->priv->object_path, object);
+
+ tp_text_mixin_init (object, G_STRUCT_OFFSET (TestTextChannelGroup, text),
+ contact_repo);
+
+ tp_text_mixin_set_message_types (object,
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE,
+ G_MAXUINT);
+
+ return object;
+}
+
+static void
+get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (object);
+
+ switch (property_id)
+ {
+ case PROP_OBJECT_PATH:
+ g_value_set_string (value, self->priv->object_path);
+ break;
+ case PROP_CHANNEL_TYPE:
+ g_value_set_static_string (value, TP_IFACE_CHANNEL_TYPE_TEXT);
+ break;
+ case PROP_HANDLE_TYPE:
+ g_value_set_uint (value, TP_HANDLE_TYPE_NONE);
+ break;
+ case PROP_HANDLE:
+ g_value_set_uint (value, 0);
+ break;
+ case PROP_TARGET_ID:
+ g_value_set_static_string (value, "");
+ break;
+ case PROP_REQUESTED:
+ g_value_set_boolean (value, TRUE);
+ break;
+ case PROP_INITIATOR_HANDLE:
+ g_value_set_uint (value, self->priv->conn->self_handle);
+ break;
+ case PROP_INITIATOR_ID:
+ {
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+ self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+
+ g_value_set_string (value,
+ tp_handle_inspect (contact_repo, self->priv->conn->self_handle));
+ }
+ break;
+ case PROP_INTERFACES:
+ g_value_set_boxed (value, test_text_channel_group_interfaces);
+ break;
+ case PROP_CONNECTION:
+ g_value_set_object (value, self->priv->conn);
+ 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)
+{
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (object);
+
+ switch (property_id)
+ {
+ case PROP_OBJECT_PATH:
+ g_free (self->priv->object_path);
+ self->priv->object_path = g_value_dup_string (value);
+ break;
+ case PROP_HANDLE:
+ case PROP_HANDLE_TYPE:
+ case PROP_CHANNEL_TYPE:
+ /* these properties are writable in the interface, but not actually
+ * meaningfully changable on this channel, so we do nothing */
+ break;
+ case PROP_CONNECTION:
+ self->priv->conn = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+dispose (GObject *object)
+{
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (object);
+
+ if (self->priv->disposed)
+ return;
+
+ self->priv->disposed = TRUE;
+
+ if (!self->priv->closed)
+ {
+ tp_svc_channel_emit_closed (self);
+ }
+
+ ((GObjectClass *) test_text_channel_group_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (object);
+
+ g_free (self->priv->object_path);
+
+ tp_text_mixin_finalize (object);
+
+ ((GObjectClass *) test_text_channel_group_parent_class)->finalize (object);
+}
+
+static void
+test_text_channel_group_class_init (TestTextChannelGroupClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+ GParamSpec *param_spec;
+
+ static TpDBusPropertiesMixinPropImpl channel_props[] = {
+ { "TargetHandleType", "handle-type", NULL },
+ { "TargetHandle", "handle", NULL },
+ { "ChannelType", "channel-type", NULL },
+ { "Interfaces", "interfaces", NULL },
+ { "TargetID", "target-id", NULL },
+ { "Requested", "requested", NULL },
+ { "InitiatorHandle", "initiator-handle", NULL },
+ { "InitiatorID", "initiator-id", NULL },
+ { NULL }
+ };
+ static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
+ { TP_IFACE_CHANNEL,
+ tp_dbus_properties_mixin_getter_gobject_properties,
+ NULL,
+ channel_props,
+ },
+ { NULL }
+ };
+
+ g_type_class_add_private (klass, sizeof (TestTextChannelGroupPrivate));
+
+ object_class->constructor = constructor;
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+
+ g_object_class_override_property (object_class, PROP_OBJECT_PATH,
+ "object-path");
+ g_object_class_override_property (object_class, PROP_CHANNEL_TYPE,
+ "channel-type");
+ g_object_class_override_property (object_class, PROP_HANDLE_TYPE,
+ "handle-type");
+ g_object_class_override_property (object_class, PROP_HANDLE, "handle");
+
+ param_spec = g_param_spec_object ("connection", "TpBaseConnection object",
+ "Connection object that owns this channel",
+ TP_TYPE_BASE_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
+
+ param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
+ "Additional Channel.Interface.* interfaces",
+ 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_string ("target-id", "Peer's ID",
+ "Always the empty string on this channel",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_TARGET_ID, param_spec);
+
+ param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
+ "The contact who initiated the channel",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
+ param_spec);
+
+ param_spec = g_param_spec_string ("initiator-id", "Initiator's ID",
+ "The string obtained by inspecting the initiator-handle",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INITIATOR_ID,
+ param_spec);
+
+ param_spec = g_param_spec_boolean ("requested", "Requested?",
+ "True if this channel was requested by the local user",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_REQUESTED, param_spec);
+
+ tp_text_mixin_class_init (object_class,
+ G_STRUCT_OFFSET (TestTextChannelGroupClass, text_class));
+
+ klass->dbus_properties_class.interfaces = prop_interfaces;
+ tp_dbus_properties_mixin_class_init (object_class,
+ G_STRUCT_OFFSET (TestTextChannelGroupClass, dbus_properties_class));
+}
+
+static void
+channel_close (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (iface);
+
+ if (!self->priv->closed)
+ {
+ self->priv->closed = TRUE;
+ tp_svc_channel_emit_closed (self);
+ }
+
+ tp_svc_channel_return_from_close (context);
+}
+
+static void
+channel_get_channel_type (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ tp_svc_channel_return_from_get_channel_type (context,
+ TP_IFACE_CHANNEL_TYPE_TEXT);
+}
+
+static void
+channel_get_handle (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ tp_svc_channel_return_from_get_handle (context, TP_HANDLE_TYPE_NONE, 0);
+}
+
+static void
+channel_get_interfaces (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ tp_svc_channel_return_from_get_interfaces (context,
+ test_text_channel_group_interfaces);
+}
+
+static void
+channel_iface_init (gpointer iface,
+ gpointer data)
+{
+ TpSvcChannelClass *klass = iface;
+
+#define IMPLEMENT(x) tp_svc_channel_implement_##x (klass, channel_##x)
+ IMPLEMENT (close);
+ IMPLEMENT (get_channel_type);
+ IMPLEMENT (get_handle);
+ IMPLEMENT (get_interfaces);
+#undef IMPLEMENT
+}
+
+static void
+text_send (TpSvcChannelTypeText *iface,
+ guint type,
+ const gchar *text,
+ DBusGMethodInvocation *context)
+{
+ /* silently swallow the message */
+ tp_svc_channel_type_text_return_from_send (context);
+}
+
+static void
+text_iface_init (gpointer iface,
+ gpointer data)
+{
+ TpSvcChannelTypeTextClass *klass = iface;
+
+ tp_text_mixin_iface_init (iface, data);
+#define IMPLEMENT(x) tp_svc_channel_type_text_implement_##x (klass, text_##x)
+ IMPLEMENT (send);
+#undef IMPLEMENT
+}
diff --git a/tests/lib/textchan-group.h b/tests/lib/textchan-group.h
new file mode 100644
index 0000000..8226c80
--- /dev/null
+++ b/tests/lib/textchan-group.h
@@ -0,0 +1,59 @@
+/*
+ * 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/base-connection.h>
+#include <telepathy-glib/text-mixin.h>
+
+G_BEGIN_DECLS
+
+typedef struct _TestTextChannelGroup TestTextChannelGroup;
+typedef struct _TestTextChannelGroupClass TestTextChannelGroupClass;
+typedef struct _TestTextChannelGroupPrivate TestTextChannelGroupPrivate;
+
+GType test_text_channel_group_get_type (void);
+
+#define TEST_TYPE_TEXT_CHANNEL_GROUP \
+ (test_text_channel_group_get_type ())
+#define TEST_TEXT_CHANNEL_GROUP(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_TEXT_CHANNEL_GROUP, \
+ TestTextChannelGroup))
+#define TEST_TEXT_CHANNEL_GROUP_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_TEXT_CHANNEL_GROUP, \
+ TestTextChannelGroupClass))
+#define TEST_IS_TEXT_CHANNEL_GROUP(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_TEXT_CHANNEL_GROUP))
+#define TEST_IS_TEXT_CHANNEL_GROUP_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_TEXT_CHANNEL_GROUP))
+#define TEST_TEXT_CHANNEL_GROUP_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_TEXT_CHANNEL_GROUP, \
+ TestTextChannelGroupClass))
+
+struct _TestTextChannelGroupClass {
+ GObjectClass parent_class;
+
+ TpTextMixinClass text_class;
+ TpDBusPropertiesMixinClass dbus_properties_class;
+};
+
+struct _TestTextChannelGroup {
+ GObject parent;
+ TpTextMixin text;
+
+ TestTextChannelGroupPrivate *priv;
+};
+
+G_END_DECLS
+
+#endif /* #ifndef __TEST_TEXT_CHANNEL_GROUP_H__ */
--
1.5.6.5
More information about the Telepathy-commits
mailing list