[Telepathy-commits] [telepathy-qt4/master] Channel: Improved test coverage to test for both MembersChanged and MembersChangedDetailed.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Feb 10 19:15:41 PST 2009


---
 tests/dbus/chan-group.cpp    |   54 +++++++++++++------
 tests/lib/csh/conn.c         |   21 +++++++
 tests/lib/csh/conn.h         |    3 +
 tests/lib/csh/room-manager.c |   25 +++++++++
 tests/lib/csh/room-manager.h |    3 +
 tests/lib/csh/room.c         |  123 +++++++++++++++++++++++++++++++++++++++--
 tests/lib/csh/room.h         |    3 +
 7 files changed, 209 insertions(+), 23 deletions(-)

diff --git a/tests/dbus/chan-group.cpp b/tests/dbus/chan-group.cpp
index cf5bcda..d0a9461 100644
--- a/tests/dbus/chan-group.cpp
+++ b/tests/dbus/chan-group.cpp
@@ -51,18 +51,21 @@ private Q_SLOTS:
 
     void testRequestHandle();
     void testCreateChannel();
+    void testCreateChannelDetailed();
 
     void cleanup();
     void cleanupTestCase();
 
 private:
     void debugContacts();
+    void doTestCreateChannel();
 
     QString mConnName, mConnPath;
     ExampleCSHConnection *mConnService;
     Connection *mConn;
     Channel *mChan;
     QString mChanObjectPath;
+    uint mRoomNumber;
     ReferencedHandles mRoomHandles;
     ReferencedHandles mContactHandles;
     QList<QSharedPointer<Contact> > mContacts;
@@ -226,6 +229,7 @@ void TestChanGroup::onGroupMembersChanged(
 
     QVERIFY(mChan->groupContacts().size() > 1);
 
+    QString roomName = QString("#room%1").arg(mRoomNumber);
     if (mChan->groupRemotePendingContacts().isEmpty()) {
         QVERIFY(mChan->groupLocalPendingContacts().isEmpty());
 
@@ -236,27 +240,29 @@ void TestChanGroup::onGroupMembersChanged(
 
         if (mChan->groupContacts().count() == 5) {
             QCOMPARE(ids, QStringList() <<
-                            "me@#room" <<
-                            "alice@#room" <<
-                            "bob@#room" <<
-                            "chris@#room" <<
-                            "anonymous coward@#room");
+                            QString("me@") + roomName <<
+                            QString("alice@") + roomName <<
+                            QString("bob@") + roomName <<
+                            QString("chris@") + roomName <<
+                            QString("anonymous coward@") + roomName);
             ret = 0;
         } else if (mChan->groupContacts().count() == 6) {
+            QCOMPARE(details.message(), QString("Invitation accepted"));
             QCOMPARE(ids, QStringList() <<
-                            "me@#room" <<
-                            "alice@#room" <<
-                            "bob@#room" <<
-                            "chris@#room" <<
-                            "anonymous coward@#room" <<
-                            "john@#room");
+                            QString("me@") + roomName <<
+                            QString("alice@") + roomName <<
+                            QString("bob@") + roomName <<
+                            QString("chris@") + roomName <<
+                            QString("anonymous coward@") + roomName <<
+                            QString("john@") + roomName);
             ret = 2;
         }
     } else {
         if (mChan->groupRemotePendingContacts().count() == 1) {
+            QCOMPARE(details.actorContact(), mChan->groupSelfContact());
             QCOMPARE(details.message(), QString("I want to add john"));
             QCOMPARE(mChan->groupRemotePendingContacts().first()->id(),
-                     QString("john@#room"));
+                     QString("john@" + roomName));
             ret = 1;
         }
     }
@@ -348,7 +354,7 @@ void TestChanGroup::init()
 void TestChanGroup::testRequestHandle()
 {
     // Test identifiers
-    QStringList ids = QStringList() << "#room";
+    QStringList ids = QStringList() << "#room0" << "#room1";
 
     // Request handles for the identifiers and wait for the request to process
     PendingHandles *pending = mConn->requestHandles(Telepathy::HandleTypeRoom, ids);
@@ -364,13 +370,27 @@ void TestChanGroup::testRequestHandle()
 
 void TestChanGroup::testCreateChannel()
 {
+    mRoomNumber = 0;
+    doTestCreateChannel();
+}
+
+void TestChanGroup::testCreateChannelDetailed()
+{
+    example_csh_connection_set_enable_change_members_detailed(mConnService, true);
+    mRoomNumber = 1;
+    doTestCreateChannel();
+}
+
+void TestChanGroup::doTestCreateChannel()
+{
     QVariantMap request;
     request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
                    TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT);
     request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
                    Telepathy::HandleTypeRoom);
     request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
-                   mRoomHandles[0]);
+                   mRoomHandles[mRoomNumber]);
+
     QVERIFY(connect(mConn->createChannel(request),
                     SIGNAL(finished(Telepathy::Client::PendingOperation*)),
                     SLOT(expectCreateChannelFinished(Telepathy::Client::PendingOperation*))));
@@ -385,7 +405,7 @@ void TestChanGroup::testCreateChannel()
 
         QCOMPARE(mChan->isRequested(), true);
         QCOMPARE(mChan->initiatorContact().isNull(), true);
-        QCOMPARE(mChan->groupSelfContact()->id(), QString("me@#room"));
+        QCOMPARE(mChan->groupSelfContact()->id(), QString("me@#room%1").arg(mRoomNumber));
 
         QCOMPARE(mChan->groupCanAddContacts(), false);
         QCOMPARE(mChan->groupCanRemoveContacts(), false);
@@ -414,7 +434,7 @@ void TestChanGroup::testCreateChannel()
                                 const Channel::GroupMemberChangeDetails &))));
         QCOMPARE(mLoop->exec(), 0);
 
-        QStringList ids = QStringList() << "john@#room";
+        QStringList ids = QStringList() << QString("john@#room%1").arg(mRoomNumber);
         QVERIFY(connect(mConn->requestHandles(Telepathy::HandleTypeContact, ids),
                         SIGNAL(finished(Telepathy::Client::PendingOperation*)),
                         SLOT(expectPendingContactHandlesFinished(Telepathy::Client::PendingOperation*))));
@@ -427,7 +447,7 @@ void TestChanGroup::testCreateChannel()
         QCOMPARE(mLoop->exec(), 0);
 
         QCOMPARE(mContacts.size(), 1);
-        QCOMPARE(mContacts.first()->id(), QString("john@#room"));
+        QCOMPARE(mContacts.first()->id(), QString("john@#room%1").arg(mRoomNumber));
 
         mChan->groupAddContacts(mContacts, "I want to add john");
 
diff --git a/tests/lib/csh/conn.c b/tests/lib/csh/conn.c
index fa6fcba..10ed9b9 100644
--- a/tests/lib/csh/conn.c
+++ b/tests/lib/csh/conn.c
@@ -276,3 +276,24 @@ example_csh_connection_class_init (ExampleCSHConnectionClass *klass)
       G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
   g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec);
 }
+
+void
+example_csh_connection_set_enable_change_members_detailed (ExampleCSHConnection *self,
+                                                           gboolean enable)
+{
+  TpChannelManagerIter iter;
+  TpChannelManager *channel_manager;
+
+  g_return_if_fail (EXAMPLE_IS_CSH_CONNECTION (self));
+
+  tp_base_connection_channel_manager_iter_init (&iter, (TpBaseConnection *) self);
+
+  while (tp_base_connection_channel_manager_iter_next (&iter, &channel_manager))
+    {
+      if (EXAMPLE_IS_CSH_ROOM_MANAGER (channel_manager))
+        {
+          example_csh_room_manager_set_enable_change_members_detailed (
+            (ExampleCSHRoomManager *) channel_manager, enable);
+        }
+    }
+}
diff --git a/tests/lib/csh/conn.h b/tests/lib/csh/conn.h
index a19feb5..3fa823b 100644
--- a/tests/lib/csh/conn.h
+++ b/tests/lib/csh/conn.h
@@ -34,6 +34,9 @@ struct _ExampleCSHConnection {
 
 GType example_csh_connection_get_type (void);
 
+void example_csh_connection_set_enable_change_members_detailed (ExampleCSHConnection *self,
+                                                                gboolean enable);
+
 /* TYPE MACROS */
 #define EXAMPLE_TYPE_CSH_CONNECTION \
   (example_csh_connection_get_type ())
diff --git a/tests/lib/csh/room-manager.c b/tests/lib/csh/room-manager.c
index 7666927..390bdf6 100644
--- a/tests/lib/csh/room-manager.c
+++ b/tests/lib/csh/room-manager.c
@@ -43,6 +43,8 @@ struct _ExampleCSHRoomManagerPrivate
   /* GUINT_TO_POINTER (room handle) => ExampleCSHRoomChannel */
   GHashTable *channels;
   gulong status_changed_id;
+
+  unsigned enable_change_members_detailed:1;
 };
 
 static void
@@ -131,6 +133,7 @@ constructed (GObject *object)
 
   self->priv->status_changed_id = g_signal_connect (self->priv->conn,
       "status-changed", (GCallback) status_changed_cb, self);
+  self->priv->enable_change_members_detailed = FALSE;
 }
 
 static void
@@ -228,6 +231,8 @@ new_channel (ExampleCSHRoomManager *self,
       "handle", handle,
       /* FIXME: initiator */
       NULL);
+  example_csh_room_set_enable_change_members_detailed(
+    chan, self->priv->enable_change_members_detailed);
 
   g_free (object_path);
 
@@ -374,3 +379,23 @@ channel_manager_iface_init (gpointer g_iface,
   /* In this channel manager, Request has the same semantics as Ensure */
   iface->request_channel = example_csh_room_manager_ensure_channel;
 }
+
+void
+example_csh_room_manager_set_enable_change_members_detailed (ExampleCSHRoomManager *self,
+                                                             gboolean enable)
+{
+  GHashTableIter iter;
+  gpointer handle, channel;
+
+  g_return_if_fail (EXAMPLE_IS_CSH_ROOM_MANAGER (self));
+
+  self->priv->enable_change_members_detailed = enable;
+
+  g_hash_table_iter_init (&iter, self->priv->channels);
+
+  while (g_hash_table_iter_next (&iter, &handle, &channel))
+    {
+      example_csh_room_set_enable_change_members_detailed (EXAMPLE_CSH_ROOM_CHANNEL (channel),
+                                                           enable);
+    }
+}
diff --git a/tests/lib/csh/room-manager.h b/tests/lib/csh/room-manager.h
index 6e9eb27..e040387 100644
--- a/tests/lib/csh/room-manager.h
+++ b/tests/lib/csh/room-manager.h
@@ -33,6 +33,9 @@ struct _ExampleCSHRoomManager {
 
 GType example_csh_room_manager_get_type (void);
 
+void example_csh_room_manager_set_enable_change_members_detailed (ExampleCSHRoomManager *manager,
+                                                                  gboolean enable);
+
 /* TYPE MACROS */
 #define EXAMPLE_TYPE_CSH_ROOM_MANAGER \
   (example_csh_room_manager_get_type ())
diff --git a/tests/lib/csh/room.c b/tests/lib/csh/room.c
index 0327499..c9caeef 100644
--- a/tests/lib/csh/room.c
+++ b/tests/lib/csh/room.c
@@ -62,6 +62,7 @@ struct _ExampleCSHRoomChannelPrivate
   guint accept_invitations_timeout;
 
   /* These are really booleans, but gboolean is signed. Thanks, GLib */
+  unsigned members_changed_detailed:1;
   unsigned closed:1;
   unsigned disposed:1;
 };
@@ -120,6 +121,8 @@ complete_join (ExampleCSHRoomChannel *self)
   TpHandle alice_global, bob_global, chris_global;
   TpGroupMixin *mixin = TP_GROUP_MIXIN (self);
   TpIntSet *added;
+  GHashTable *details;
+  GValue *v;
 
   /* For this example, we assume that all chatrooms initially contain
    * Alice, Bob and Chris (and that their global IDs are also known),
@@ -166,12 +169,22 @@ complete_join (ExampleCSHRoomChannel *self)
           self->priv->conn->self_handle);
       tp_group_mixin_change_self_handle ((GObject *) self, new_self);
 
+      details = g_hash_table_new_full (g_str_hash, g_str_equal,
+         NULL, (GDestroyNotify) tp_g_value_slice_free);
+
+      v = tp_g_value_slice_new (G_TYPE_UINT);
+      g_value_set_uint (v, TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED);
+      g_hash_table_insert (details, "change-reason", v);
+
+      tp_group_mixin_change_members_detailed ((GObject *) self, NULL, removed,
+         NULL, rp, details);
       tp_group_mixin_change_members ((GObject *) self, "", NULL, removed, NULL,
           rp, 0, TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED);
 
       tp_handle_unref (contact_repo, new_self);
       tp_intset_destroy (removed);
       tp_intset_destroy (rp);
+      g_hash_table_unref (details);
     }
 
   tp_group_mixin_add_handle_owner ((GObject *) self, alice_local,
@@ -192,8 +205,19 @@ complete_join (ExampleCSHRoomChannel *self)
   tp_intset_add (added, anon_local);
   tp_intset_add (added, mixin->self_handle);
 
+  details = g_hash_table_new_full (g_str_hash, g_str_equal,
+     NULL, (GDestroyNotify) tp_g_value_slice_free);
+
+  v = tp_g_value_slice_new (G_TYPE_UINT);
+  g_value_set_uint (v, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+  g_hash_table_insert (details, "change-reason", v);
+
+  tp_group_mixin_change_members_detailed ((GObject *) self, added, NULL,
+     NULL, NULL, details);
   tp_group_mixin_change_members ((GObject *) self, "", added, NULL, NULL,
-      NULL, 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+     NULL, 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+
+  g_hash_table_unref (details);
 
   tp_handle_unref (contact_repo, alice_local);
   tp_handle_unref (contact_repo, bob_local);
@@ -206,15 +230,33 @@ complete_join (ExampleCSHRoomChannel *self)
 
   /* now that the dust has settled, we can also invite people */
   tp_group_mixin_change_flags ((GObject *) self,
-      TP_CHANNEL_GROUP_FLAG_CAN_ADD | TP_CHANNEL_GROUP_FLAG_MESSAGE_ADD,
+      TP_CHANNEL_GROUP_FLAG_CAN_ADD | TP_CHANNEL_GROUP_FLAG_MESSAGE_ADD |
+      (self->priv->members_changed_detailed ? TP_CHANNEL_GROUP_FLAG_MEMBERS_CHANGED_DETAILED : 0),
       0);
 }
 
 static void
 accept_invitations (ExampleCSHRoomChannel *self)
 {
-  tp_group_mixin_change_members ((GObject *) self, "", self->priv->remote, NULL, NULL,
-      self->priv->remote, 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+  GHashTable *details = g_hash_table_new_full (g_str_hash, g_str_equal,
+     NULL, (GDestroyNotify) tp_g_value_slice_free);
+  GValue *v;
+
+  v = tp_g_value_slice_new (G_TYPE_UINT);
+  g_value_set_uint (v, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+  g_hash_table_insert (details, "change-reason", v);
+
+  v = tp_g_value_slice_new (G_TYPE_STRING);
+  g_value_set_static_string (v, "Invitation accepted");
+  g_hash_table_insert (details, "message", v);
+
+  tp_group_mixin_change_members_detailed ((GObject *) self, self->priv->remote, NULL,
+     NULL, NULL, details);
+  tp_group_mixin_change_members ((GObject *) self, "Invitation accepted",
+     self->priv->remote, NULL, NULL,
+     NULL, 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+
+  g_hash_table_unref (details);
   tp_intset_clear(self->priv->remote);
 }
 
@@ -224,6 +266,8 @@ join_room (ExampleCSHRoomChannel *self)
   TpGroupMixin *mixin = TP_GROUP_MIXIN (self);
   GObject *object = (GObject *) self;
   TpIntSet *add_remote_pending;
+  GHashTable *details;
+  GValue *v;
 
   g_assert (!tp_handle_set_is_member (mixin->members, mixin->self_handle));
   g_assert (!tp_handle_set_is_member (mixin->remote_pending,
@@ -236,10 +280,25 @@ join_room (ExampleCSHRoomChannel *self)
 
   tp_group_mixin_add_handle_owner (object, mixin->self_handle,
       self->priv->conn->self_handle);
+
+  details = g_hash_table_new_full (g_str_hash, g_str_equal,
+     NULL, (GDestroyNotify) tp_g_value_slice_free);
+
+  v = tp_g_value_slice_new (G_TYPE_UINT);
+  g_value_set_uint (v, mixin->self_handle);
+  g_hash_table_insert (details, "actor", v);
+
+  v = tp_g_value_slice_new (G_TYPE_UINT);
+  g_value_set_uint (v, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+  g_hash_table_insert (details, "change-reason", v);
+
+  tp_group_mixin_change_members_detailed ((GObject *) self, NULL, NULL,
+     NULL, add_remote_pending, details);
   tp_group_mixin_change_members (object, "", NULL, NULL, NULL,
-      add_remote_pending, self->priv->conn->self_handle,
+      add_remote_pending, mixin->self_handle,
       TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
 
+  g_hash_table_unref (details);
   tp_intset_destroy (add_remote_pending);
 
   /* Actually join the room. In a real implementation this would be a network
@@ -297,6 +356,7 @@ constructor (GType type,
       0);
 
   self->priv->remote = tp_intset_new ();
+  self->priv->members_changed_detailed = FALSE;
 
   /* Immediately attempt to join the group */
   join_room (self);
@@ -474,6 +534,9 @@ add_member (GObject *object,
   /* In a real implementation, if handle was mixin->self_handle we'd accept
    * an invitation here; otherwise we'd invite the given contact. */
   ExampleCSHRoomChannel *self = EXAMPLE_CSH_ROOM_CHANNEL (object);
+  TpGroupMixin *mixin = TP_GROUP_MIXIN (self);
+  GHashTable *details;
+  GValue *v;
 
   /* we know that anon_local is channel-specific, but not whose it is,
    * hence 0 */
@@ -482,8 +545,26 @@ add_member (GObject *object,
   /* everyone in! */
   tp_intset_add (self->priv->remote, handle);
 
+  details = g_hash_table_new_full (g_str_hash, g_str_equal,
+     NULL, (GDestroyNotify) tp_g_value_slice_free);
+
+  v = tp_g_value_slice_new (G_TYPE_UINT);
+  g_value_set_uint (v, mixin->self_handle);
+  g_hash_table_insert (details, "actor", v);
+
+  v = tp_g_value_slice_new (G_TYPE_UINT);
+  g_value_set_uint (v, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+  g_hash_table_insert (details, "change-reason", v);
+
+  v = tp_g_value_slice_new (G_TYPE_STRING);
+  g_value_set_static_string (v, message);
+  g_hash_table_insert (details, "message", v);
+
+  tp_group_mixin_change_members_detailed (object, NULL, NULL, NULL,
+      self->priv->remote, details);
   tp_group_mixin_change_members (object, message, NULL, NULL, NULL,
-      self->priv->remote, 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+      self->priv->remote, mixin->self_handle,
+      TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
 
   // accept invitation after 500ms
   self->priv->accept_invitations_timeout =
@@ -678,3 +759,33 @@ text_iface_init (gpointer iface,
   IMPLEMENT (send);
 #undef IMPLEMENT
 }
+
+void
+example_csh_room_set_enable_change_members_detailed (ExampleCSHRoomChannel *self,
+                                                     gboolean enable)
+{
+  g_return_if_fail (EXAMPLE_IS_CSH_ROOM_CHANNEL (self));
+
+  if ((enable && self->priv->members_changed_detailed) ||
+      !(enable && !self->priv->members_changed_detailed))
+    {
+      // nothing to change
+      return;
+    }
+
+
+  if (enable)
+    {
+      tp_group_mixin_change_flags ((GObject *) self,
+        TP_CHANNEL_GROUP_FLAG_MEMBERS_CHANGED_DETAILED,
+        0);
+    }
+  else
+    {
+      tp_group_mixin_change_flags ((GObject *) self,
+        0,
+        TP_CHANNEL_GROUP_FLAG_MEMBERS_CHANGED_DETAILED);
+    }
+
+  self->priv->members_changed_detailed = enable;
+}
diff --git a/tests/lib/csh/room.h b/tests/lib/csh/room.h
index 1945543..c72ced3 100644
--- a/tests/lib/csh/room.h
+++ b/tests/lib/csh/room.h
@@ -26,6 +26,9 @@ typedef struct _ExampleCSHRoomChannelPrivate ExampleCSHRoomChannelPrivate;
 
 GType example_csh_room_channel_get_type (void);
 
+void example_csh_room_set_enable_change_members_detailed (ExampleCSHRoomChannel *channel,
+                                                          gboolean enable);
+
 #define EXAMPLE_TYPE_CSH_ROOM_CHANNEL \
   (example_csh_room_channel_get_type ())
 #define EXAMPLE_CSH_ROOM_CHANNEL(obj) \
-- 
1.5.6.5




More information about the telepathy-commits mailing list