[Telepathy-commits] [telepathy-glib/master] test-group-mixin: Test invitations
Will Thompson
will.thompson at collabora.co.uk
Mon Jan 12 04:18:07 PST 2009
---
tests/dbus/group-mixin.c | 145 +++++++++++++++++++++++++++++++++++++++++++-
tests/lib/textchan-group.c | 45 +++++++++++---
tests/lib/textchan-group.h | 6 ++
3 files changed, 185 insertions(+), 11 deletions(-)
diff --git a/tests/dbus/group-mixin.c b/tests/dbus/group-mixin.c
index fa22cbb..0f1acaa 100644
--- a/tests/dbus/group-mixin.c
+++ b/tests/dbus/group-mixin.c
@@ -13,6 +13,7 @@
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/debug.h>
#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/proxy-subclass.h>
#include "tests/lib/myassert.h"
@@ -24,6 +25,7 @@
static int fail = 0;
static GMainLoop *mainloop;
+static guint expecting_members_changed = 0;
static void
myassert_failed (void)
@@ -31,6 +33,138 @@ myassert_failed (void)
fail = 1;
}
+static gboolean
+outstanding_signals (void)
+{
+ return expecting_members_changed > 0;
+}
+
+static void
+wait_for_outstanding_signals (void)
+{
+ if (outstanding_signals ())
+ g_main_loop_run (mainloop);
+}
+
+static void
+on_members_changed (TpChannel *proxy,
+ const gchar *arg_Message,
+ const GArray *arg_Added,
+ const GArray *arg_Removed,
+ const GArray *arg_Local_Pending,
+ const GArray *arg_Remote_Pending,
+ guint arg_Actor,
+ guint arg_Reason,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ MYASSERT (expecting_members_changed > 0, "got unexpected MembersChanged");
+
+ expecting_members_changed--;
+
+ if (!outstanding_signals ())
+ g_main_loop_quit (mainloop);
+}
+
+static void
+check_initial_properties (TpChannel *chan)
+{
+ GHashTable *props = NULL;
+ GArray *members;
+ TpHandle h;
+ gboolean valid;
+ GError *error = NULL;
+ TpChannelGroupFlags flags;
+
+ MYASSERT (tp_cli_dbus_properties_run_get_all (chan, -1,
+ TP_IFACE_CHANNEL_INTERFACE_GROUP, &props, &error, NULL), "");
+ MYASSERT_NO_ERROR (error);
+
+ members = tp_asv_get_boxed (props, "Members", DBUS_TYPE_G_UINT_ARRAY);
+ MYASSERT (members != NULL, ": Members should be defined"); \
+ MYASSERT (members->len == 0, ": Members should be empty initally");
+
+ members = tp_asv_get_boxed (props, "RemotePendingMembers",
+ DBUS_TYPE_G_UINT_ARRAY);
+ MYASSERT (members != NULL, ": RemotePendingMembers should be defined"); \
+ MYASSERT (members->len == 0, ": RemotePendingMembers should be empty initally");
+
+ members = tp_asv_get_boxed (props, "LocalPendingMembers",
+ TP_ARRAY_TYPE_LOCAL_PENDING_INFO_LIST);
+ MYASSERT (members != NULL, ": LocalPendingMembers should be defined"); \
+ MYASSERT (members->len == 0, ": LocalPendingMembers should be empty initally");
+
+ h = tp_asv_get_uint32 (props, "SelfHandle", &valid);
+ MYASSERT (valid, ": SelfHandle property should be defined");
+
+ flags = tp_asv_get_uint32 (props, "GroupFlags", &valid);
+ MYASSERT (flags, ": GroupFlags property should be defined");
+ MYASSERT_SAME_UINT (flags, TP_CHANNEL_GROUP_FLAG_PROPERTIES);
+
+ g_hash_table_unref (props);
+}
+
+static void
+check_incoming_invitation (TestTextChannelGroup *service_chan,
+ TpChannel *chan)
+{
+ GError *error = NULL;
+
+ /* We get an invitation to the channel */
+ {
+ TpIntSet *add_local_pending = tp_intset_new ();
+ tp_intset_add (add_local_pending, service_chan->conn->self_handle);
+
+ expecting_members_changed = 1;
+ tp_group_mixin_change_members ((GObject *) service_chan, "HELLO THAR", NULL,
+ NULL, add_local_pending, NULL, 0,
+ TP_CHANNEL_GROUP_CHANGE_REASON_INVITED);
+ wait_for_outstanding_signals ();
+ MYASSERT (expecting_members_changed == 0,
+ ": MembersChanged should have fired once");
+
+ tp_intset_destroy (add_local_pending);
+ }
+
+ /* We accept the invitation; even though the channel lacks CanAdd we should
+ * be able to move someone from local pending to members by calling Add().
+ */
+ {
+ GArray *contacts = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
+ g_array_append_val (contacts, service_chan->conn->self_handle);
+
+ expecting_members_changed = 1;
+ MYASSERT (tp_cli_channel_interface_group_run_add_members (chan, -1,
+ contacts, "", &error, NULL), "");
+ MYASSERT_NO_ERROR (error);
+ wait_for_outstanding_signals ();
+ MYASSERT (expecting_members_changed == 0,
+ ": MembersChanged should have fired once");
+
+ g_array_free (contacts, TRUE);
+ }
+}
+
+static void
+test_group_mixin (TestTextChannelGroup *service_chan,
+ TpChannel *chan)
+{
+ GError *error = NULL;
+
+ MYASSERT (tp_channel_run_until_ready (chan, &error, NULL), "");
+ MYASSERT_NO_ERROR (error);
+
+ MYASSERT (tp_proxy_has_interface (chan, TP_IFACE_CHANNEL_INTERFACE_GROUP),
+ "");
+
+ tp_cli_channel_interface_group_connect_to_members_changed (chan,
+ on_members_changed, NULL, NULL, NULL, NULL);
+
+ check_initial_properties (chan);
+
+ check_incoming_invitation (service_chan, chan);
+}
+
int
main (int argc,
char **argv)
@@ -88,12 +222,21 @@ main (int argc,
MYASSERT (tp_cli_connection_run_connect (conn, -1, &error, NULL), "");
MYASSERT_NO_ERROR (error);
+ chan = tp_channel_new (conn, chan_path, NULL, TP_UNKNOWN_HANDLE_TYPE, 0,
+ &error);
+ MYASSERT_NO_ERROR (error);
+
+ MYASSERT (tp_channel_run_until_ready (chan, &error, NULL), "");
+ MYASSERT_NO_ERROR (error);
+
+ test_group_mixin (service_chan, chan);
+
MYASSERT (tp_cli_connection_run_disconnect (conn, -1, &error, NULL), "");
MYASSERT_NO_ERROR (error);
/* clean up */
- g_assert (chan == NULL);
+ g_object_unref (chan);
g_main_loop_unref (mainloop);
mainloop = NULL;
diff --git a/tests/lib/textchan-group.c b/tests/lib/textchan-group.c
index da229dd..4cf952f 100644
--- a/tests/lib/textchan-group.c
+++ b/tests/lib/textchan-group.c
@@ -27,10 +27,8 @@ G_DEFINE_TYPE_WITH_CODE (TestTextChannelGroup,
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);
- */
+ tp_group_mixin_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
tp_dbus_properties_mixin_iface_init))
@@ -59,13 +57,30 @@ enum
struct _TestTextChannelGroupPrivate
{
- TpBaseConnection *conn;
gchar *object_path;
gboolean closed;
gboolean disposed;
};
+
+static gboolean
+add_member (GObject *obj,
+ TpHandle handle,
+ const gchar *message,
+ GError **error)
+{
+ TestTextChannelGroup *self = TEST_TEXT_CHANNEL_GROUP (obj);
+ TpIntSet *add = tp_intset_new ();
+
+ tp_intset_add (add, handle);
+ tp_group_mixin_change_members (obj, message, add, NULL, NULL, NULL,
+ self->conn->self_handle, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+ tp_intset_destroy (add);
+
+ return TRUE;
+}
+
static void
test_text_channel_group_init (TestTextChannelGroup *self)
{
@@ -83,7 +98,7 @@ constructor (GType 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);
+ (self->conn, TP_HANDLE_TYPE_CONTACT);
DBusGConnection *bus;
bus = tp_get_bus ();
@@ -98,6 +113,10 @@ constructor (GType type,
TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE,
G_MAXUINT);
+ tp_group_mixin_init (object, G_STRUCT_OFFSET (TestTextChannelGroup, group),
+ contact_repo, self->conn->self_handle);
+ tp_group_mixin_change_flags (object, TP_CHANNEL_GROUP_FLAG_PROPERTIES, 0);
+
return object;
}
@@ -130,22 +149,22 @@ get_property (GObject *object,
g_value_set_boolean (value, TRUE);
break;
case PROP_INITIATOR_HANDLE:
- g_value_set_uint (value, self->priv->conn->self_handle);
+ g_value_set_uint (value, self->conn->self_handle);
break;
case PROP_INITIATOR_ID:
{
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
- self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+ self->conn, TP_HANDLE_TYPE_CONTACT);
g_value_set_string (value,
- tp_handle_inspect (contact_repo, self->priv->conn->self_handle));
+ tp_handle_inspect (contact_repo, self->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);
+ g_value_set_object (value, self->conn);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -174,7 +193,7 @@ set_property (GObject *object,
* meaningfully changable on this channel, so we do nothing */
break;
case PROP_CONNECTION:
- self->priv->conn = g_value_get_object (value);
+ self->conn = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -208,6 +227,7 @@ finalize (GObject *object)
g_free (self->priv->object_path);
tp_text_mixin_finalize (object);
+ tp_group_mixin_finalize (object);
((GObjectClass *) test_text_channel_group_parent_class)->finalize (object);
}
@@ -295,10 +315,15 @@ test_text_channel_group_class_init (TestTextChannelGroupClass *klass)
tp_text_mixin_class_init (object_class,
G_STRUCT_OFFSET (TestTextChannelGroupClass, text_class));
+ tp_group_mixin_class_init (object_class,
+ G_STRUCT_OFFSET (TestTextChannelGroupClass, group_class), add_member,
+ NULL);
klass->dbus_properties_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (TestTextChannelGroupClass, dbus_properties_class));
+
+ tp_group_mixin_init_dbus_properties (object_class);
}
static void
diff --git a/tests/lib/textchan-group.h b/tests/lib/textchan-group.h
index 8226c80..29decd9 100644
--- a/tests/lib/textchan-group.h
+++ b/tests/lib/textchan-group.h
@@ -14,6 +14,7 @@
#include <glib-object.h>
#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/group-mixin.h>
#include <telepathy-glib/text-mixin.h>
G_BEGIN_DECLS
@@ -44,12 +45,17 @@ struct _TestTextChannelGroupClass {
GObjectClass parent_class;
TpTextMixinClass text_class;
+ TpGroupMixinClass group_class;
TpDBusPropertiesMixinClass dbus_properties_class;
};
struct _TestTextChannelGroup {
GObject parent;
+
+ TpBaseConnection *conn;
+
TpTextMixin text;
+ TpGroupMixin group;
TestTextChannelGroupPrivate *priv;
};
--
1.5.6.5
More information about the Telepathy-commits
mailing list