[Telepathy-commits] [telepathy-qt4/master] Channel: Added tests for contact removal.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Wed Feb 11 05:31:44 PST 2009


---
 tests/dbus/chan-group.cpp    |  108 +++++++++++++++++++++++++--------------
 tests/lib/csh/conn.c         |   20 +++++++
 tests/lib/csh/conn.h         |    1 +
 tests/lib/csh/room-manager.c |   14 +++++
 tests/lib/csh/room-manager.h |    1 +
 tests/lib/csh/room.c         |  116 +++++++++++++++++++++++++++++-------------
 tests/lib/csh/room.h         |    1 +
 7 files changed, 187 insertions(+), 74 deletions(-)

diff --git a/tests/dbus/chan-group.cpp b/tests/dbus/chan-group.cpp
index d0a9461..236f63d 100644
--- a/tests/dbus/chan-group.cpp
+++ b/tests/dbus/chan-group.cpp
@@ -230,41 +230,39 @@ void TestChanGroup::onGroupMembersChanged(
     QVERIFY(mChan->groupContacts().size() > 1);
 
     QString roomName = QString("#room%1").arg(mRoomNumber);
-    if (mChan->groupRemotePendingContacts().isEmpty()) {
-        QVERIFY(mChan->groupLocalPendingContacts().isEmpty());
-
-        QStringList ids;
-        foreach (const QSharedPointer<Contact> &contact, mChan->groupContacts()) {
-            ids << contact->id();
-        }
-
-        if (mChan->groupContacts().count() == 5) {
-            QCOMPARE(ids, QStringList() <<
-                            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() <<
-                            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) {
+    if (groupMembersRemoved.isEmpty()) {
+        if (mChan->groupRemotePendingContacts().isEmpty()) {
+            QVERIFY(mChan->groupLocalPendingContacts().isEmpty());
+
+            QStringList ids;
+            foreach (const QSharedPointer<Contact> &contact, mChan->groupContacts()) {
+                ids << contact->id();
+            }
+
+            QStringList expectedIds;
+            expectedIds << QString("me@") + roomName <<
+                QString("alice@") + roomName <<
+                QString("bob@") + roomName <<
+                QString("chris@") + roomName <<
+                QString("anonymous coward@") + roomName;
+
+            if (mChan->groupContacts().count() == 5) {
+                ret = 0;
+            } else if (mChan->groupContacts().count() == 6) {
+                QCOMPARE(details.message(), QString("Invitation accepted"));
+                expectedIds << QString("john@") + roomName;
+                ret = 3;
+            }
+            ids.sort();
+            expectedIds.sort();
+            QCOMPARE(ids, expectedIds);
+        } else {
             QCOMPARE(details.actorContact(), mChan->groupSelfContact());
-            QCOMPARE(details.message(), QString("I want to add john"));
-            QCOMPARE(mChan->groupRemotePendingContacts().first()->id(),
-                     QString("john@" + roomName));
+            QCOMPARE(details.message(), QString("I want to add them"));
             ret = 1;
         }
+    } else {
+        ret = 2;
     }
 
     qDebug() << "onGroupMembersChanged exiting with ret" << ret;
@@ -415,7 +413,7 @@ void TestChanGroup::doTestCreateChannel()
                         SLOT(onChannelGroupFlagsChanged(uint, uint, uint))));
         QCOMPARE(mLoop->exec(), 0);
         QCOMPARE(mChan->groupCanAddContacts(), true);
-        QCOMPARE(mChan->groupCanRemoveContacts(), false);
+        QCOMPARE(mChan->groupCanRemoveContacts(), true);
 
         debugContacts();
 
@@ -434,7 +432,10 @@ void TestChanGroup::doTestCreateChannel()
                                 const Channel::GroupMemberChangeDetails &))));
         QCOMPARE(mLoop->exec(), 0);
 
-        QStringList ids = QStringList() << QString("john@#room%1").arg(mRoomNumber);
+        QStringList ids = QStringList() <<
+            QString("john@#room%1").arg(mRoomNumber) <<
+            QString("mary@#room%1").arg(mRoomNumber) <<
+            QString("another anonymous coward@#room%1").arg(mRoomNumber);
         QVERIFY(connect(mConn->requestHandles(Telepathy::HandleTypeContact, ids),
                         SIGNAL(finished(Telepathy::Client::PendingOperation*)),
                         SLOT(expectPendingContactHandlesFinished(Telepathy::Client::PendingOperation*))));
@@ -446,19 +447,50 @@ void TestChanGroup::doTestCreateChannel()
                         SLOT(expectPendingContactsFinished(Telepathy::Client::PendingOperation*))));
         QCOMPARE(mLoop->exec(), 0);
 
-        QCOMPARE(mContacts.size(), 1);
+        QCOMPARE(mContacts.size(), 3);
         QCOMPARE(mContacts.first()->id(), QString("john@#room%1").arg(mRoomNumber));
 
-        mChan->groupAddContacts(mContacts, "I want to add john");
+        mChan->groupAddContacts(mContacts, "I want to add them");
 
         // members changed should be emitted twice now, one for adding john to
         // remote pending and one for adding it to current members
 
-        // expect john to be added to remote pending
+        // expect contacts to be added to remote pending
         QCOMPARE(mLoop->exec(), 1);
-        // expect john to accept invite
+        QCOMPARE(mLoop->exec(), 1);
+        QCOMPARE(mLoop->exec(), 1);
+
+        QList<QSharedPointer<Contact> > toRemove;
+        toRemove.append(mContacts[1]);
+        toRemove.append(mContacts[2]);
+        mChan->groupRemoveContacts(toRemove, "I want to remove some of them");
+
+        // expect mary and another anonymous coward to reject invite
         QCOMPARE(mLoop->exec(), 2);
 
+        example_csh_connection_accept_invitations(mConnService);
+
+        // expect john to accept invite
+        QCOMPARE(mLoop->exec(), 3);
+
+        QString roomName = QString("#room%1").arg(mRoomNumber);
+        QStringList expectedIds;
+        expectedIds << QString("me@") + roomName <<
+                QString("alice@") + roomName <<
+                QString("bob@") + roomName <<
+                QString("chris@") + roomName <<
+                QString("anonymous coward@") + roomName <<
+                QString("john@") + roomName;
+
+        ids.clear();
+        foreach (const QSharedPointer<Contact> &contact, mChan->groupContacts()) {
+            ids << contact->id();
+        }
+
+        ids.sort();
+        expectedIds.sort();
+        QCOMPARE(ids, expectedIds);
+
         delete mChan;
         mChan = 0;
     }
diff --git a/tests/lib/csh/conn.c b/tests/lib/csh/conn.c
index 10ed9b9..ff77f32 100644
--- a/tests/lib/csh/conn.c
+++ b/tests/lib/csh/conn.c
@@ -297,3 +297,23 @@ example_csh_connection_set_enable_change_members_detailed (ExampleCSHConnection
         }
     }
 }
+
+void
+example_csh_connection_accept_invitations (ExampleCSHConnection *self)
+{
+  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_accept_invitations (
+            (ExampleCSHRoomManager *) channel_manager);
+        }
+    }
+}
diff --git a/tests/lib/csh/conn.h b/tests/lib/csh/conn.h
index 3fa823b..7b8527a 100644
--- a/tests/lib/csh/conn.h
+++ b/tests/lib/csh/conn.h
@@ -36,6 +36,7 @@ GType example_csh_connection_get_type (void);
 
 void example_csh_connection_set_enable_change_members_detailed (ExampleCSHConnection *self,
                                                                 gboolean enable);
+void example_csh_connection_accept_invitations (ExampleCSHConnection *self);
 
 /* TYPE MACROS */
 #define EXAMPLE_TYPE_CSH_CONNECTION \
diff --git a/tests/lib/csh/room-manager.c b/tests/lib/csh/room-manager.c
index 390bdf6..0adfa81 100644
--- a/tests/lib/csh/room-manager.c
+++ b/tests/lib/csh/room-manager.c
@@ -399,3 +399,17 @@ example_csh_room_manager_set_enable_change_members_detailed (ExampleCSHRoomManag
                                                            enable);
     }
 }
+
+void
+example_csh_room_manager_accept_invitations (ExampleCSHRoomManager *self)
+{
+  GHashTableIter iter;
+  gpointer handle, channel;
+
+  g_return_if_fail (EXAMPLE_IS_CSH_ROOM_MANAGER (self));
+
+  g_hash_table_iter_init (&iter, self->priv->channels);
+
+  while (g_hash_table_iter_next (&iter, &handle, &channel))
+    example_csh_room_accept_invitations (EXAMPLE_CSH_ROOM_CHANNEL (channel));
+}
diff --git a/tests/lib/csh/room-manager.h b/tests/lib/csh/room-manager.h
index e040387..e6123a8 100644
--- a/tests/lib/csh/room-manager.h
+++ b/tests/lib/csh/room-manager.h
@@ -35,6 +35,7 @@ GType example_csh_room_manager_get_type (void);
 
 void example_csh_room_manager_set_enable_change_members_detailed (ExampleCSHRoomManager *manager,
                                                                   gboolean enable);
+void example_csh_room_manager_accept_invitations (ExampleCSHRoomManager *manager);
 
 /* TYPE MACROS */
 #define EXAMPLE_TYPE_CSH_ROOM_MANAGER \
diff --git a/tests/lib/csh/room.c b/tests/lib/csh/room.c
index c9caeef..167df34 100644
--- a/tests/lib/csh/room.c
+++ b/tests/lib/csh/room.c
@@ -59,7 +59,6 @@ struct _ExampleCSHRoomChannelPrivate
   TpHandle handle;
   TpHandle initiator;
   TpIntSet *remote;
-  guint accept_invitations_timeout;
 
   /* These are really booleans, but gboolean is signed. Thanks, GLib */
   unsigned members_changed_detailed:1;
@@ -230,37 +229,14 @@ 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 | TP_CHANNEL_GROUP_FLAG_MESSAGE_ACCEPT |
+      TP_CHANNEL_GROUP_FLAG_CAN_REMOVE | TP_CHANNEL_GROUP_FLAG_MESSAGE_REMOVE | TP_CHANNEL_GROUP_FLAG_MESSAGE_REJECT |
+      TP_CHANNEL_GROUP_FLAG_CAN_RESCIND | TP_CHANNEL_GROUP_FLAG_MESSAGE_RESCIND |
       (self->priv->members_changed_detailed ? TP_CHANNEL_GROUP_FLAG_MEMBERS_CHANGED_DETAILED : 0),
       0);
 }
 
 static void
-accept_invitations (ExampleCSHRoomChannel *self)
-{
-  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);
-}
-
-static void
 join_room (ExampleCSHRoomChannel *self)
 {
   TpGroupMixin *mixin = TP_GROUP_MIXIN (self);
@@ -491,9 +467,6 @@ dispose (GObject *object)
 
   self->priv->disposed = TRUE;
 
-  if (self->priv->accept_invitations_timeout)
-    g_source_remove (self->priv->accept_invitations_timeout);
-
   tp_intset_destroy (self->priv->remote);
 
   if (!self->priv->closed)
@@ -538,8 +511,6 @@ add_member (GObject *object,
   GHashTable *details;
   GValue *v;
 
-  /* we know that anon_local is channel-specific, but not whose it is,
-   * hence 0 */
   tp_group_mixin_add_handle_owner (object, handle, 0);
 
   /* everyone in! */
@@ -566,9 +537,52 @@ add_member (GObject *object,
       self->priv->remote, mixin->self_handle,
       TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
 
-  // accept invitation after 500ms
-  self->priv->accept_invitations_timeout =
-      g_timeout_add (500, (GSourceFunc) accept_invitations, self);
+  return TRUE;
+}
+
+static gboolean
+remove_member (GObject *object,
+               TpHandle handle,
+               const gchar *message,
+               GError **error)
+{
+  /* 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;
+  TpIntSet *removed;
+
+  removed = tp_intset_new ();
+  tp_intset_add (removed, 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, removed, NULL,
+      NULL, details);
+  tp_group_mixin_change_members (object, message, NULL, removed, NULL,
+      NULL, mixin->self_handle,
+      TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+
+  tp_intset_destroy (removed);
+
+  // we were waiting for accept invitation
+  if (tp_intset_is_member (self->priv->remote, handle))
+    tp_intset_remove (self->priv->remote, handle);
 
   return TRUE;
 }
@@ -667,7 +681,7 @@ example_csh_room_channel_class_init (ExampleCSHRoomChannelClass *klass)
   tp_group_mixin_class_init (object_class,
       G_STRUCT_OFFSET (ExampleCSHRoomChannelClass, group_class),
       add_member,
-      NULL);
+      remove_member);
   tp_group_mixin_init_dbus_properties (object_class);
 }
 
@@ -789,3 +803,33 @@ example_csh_room_set_enable_change_members_detailed (ExampleCSHRoomChannel *self
 
   self->priv->members_changed_detailed = enable;
 }
+
+void
+example_csh_room_accept_invitations (ExampleCSHRoomChannel *self)
+{
+  GHashTable *details = g_hash_table_new_full (g_str_hash, g_str_equal,
+     NULL, (GDestroyNotify) tp_g_value_slice_free);
+  GValue *v;
+
+  g_return_if_fail (EXAMPLE_IS_CSH_ROOM_CHANNEL (self));
+
+  if (tp_intset_size (self->priv->remote) == 0)
+    return;
+
+  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);
+}
diff --git a/tests/lib/csh/room.h b/tests/lib/csh/room.h
index c72ced3..b3b92a7 100644
--- a/tests/lib/csh/room.h
+++ b/tests/lib/csh/room.h
@@ -28,6 +28,7 @@ GType example_csh_room_channel_get_type (void);
 
 void example_csh_room_set_enable_change_members_detailed (ExampleCSHRoomChannel *channel,
                                                           gboolean enable);
+void example_csh_room_accept_invitations (ExampleCSHRoomChannel *channel);
 
 #define EXAMPLE_TYPE_CSH_ROOM_CHANNEL \
   (example_csh_room_channel_get_type ())
-- 
1.5.6.5




More information about the telepathy-commits mailing list