telepathy-qt: TestConnHelper: Rework contacts getter

Alexandr Akulich kaffeine at kemper.freedesktop.org
Mon Nov 11 17:28:14 UTC 2019


Module: telepathy-qt
Branch: master
Commit: 1761b26e79f7e7c8a8ae54c3af1a0d49cf172cbb
URL:    http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=1761b26e79f7e7c8a8ae54c3af1a0d49cf172cbb

Author: Alexander Akulich <akulichalexander at gmail.com>
Date:   Tue Oct 15 02:19:15 2019 +0300

TestConnHelper: Rework contacts getter

---

 tests/lib/glib-helpers/test-conn-helper.cpp | 51 +++++++++++++++++++++--------
 tests/lib/glib-helpers/test-conn-helper.h   |  4 ++-
 2 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/tests/lib/glib-helpers/test-conn-helper.cpp b/tests/lib/glib-helpers/test-conn-helper.cpp
index e12f8052..c9d5cca8 100644
--- a/tests/lib/glib-helpers/test-conn-helper.cpp
+++ b/tests/lib/glib-helpers/test-conn-helper.cpp
@@ -176,18 +176,21 @@ QList<Tp::ContactPtr> TestConnHelper::contacts(const QStringList &ids,
 {
     mLoop->processEvents();
 
-    QList<Tp::ContactPtr> ret;
+    qWarning() << "BEGIN TO HOLD contacts" << ids;
+
     Tp::PendingContacts *pc = mClient->contactManager()->contactsForIdentifiers(ids, features);
-    mContactFeatures = features;
-    QObject::connect(pc,
-            SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(expectContactsForIdentifiersFinished(Tp::PendingOperation*)));
-    if (mLoop->exec() == 0) {
-        ret = mContacts;
+    QSignalSpy spy(pc, &Tp::PendingOperation::finished);
+    if (!spy.wait()) {
+        qWarning() << "Unable to wait!";
+        return { };
     }
-    mContactFeatures.clear();
-    mContacts.clear();
-    return ret;
+    if (pc->isError()) {
+        qWarning() << "Unable to get contacts:" << pc->errorName() << '/' << pc->errorMessage();
+        return { };
+    }
+    checkFinishedContactsForIdentifiers(pc, features);
+
+    return pc->contacts();
 }
 
 QList<Tp::ContactPtr> TestConnHelper::contacts(const Tp::UIntList &handles,
@@ -341,14 +344,17 @@ void TestConnHelper::expectConnInvalidated()
     mLoop->exit(0);
 }
 
-void TestConnHelper::expectContactsForIdentifiersFinished(Tp::PendingOperation *op)
+void TestConnHelper::checkFinishedContactsForIdentifiers(Tp::PendingContacts *pc,
+                                                         const Tp::Features &features)
 {
-    Tp::PendingContacts *pc = qobject_cast<Tp::PendingContacts *>(op);
     QCOMPARE(pc->isForHandles(), false);
     QCOMPARE(pc->isForIdentifiers(), true);
     QCOMPARE(pc->isUpgrade(), false);
+    for (const Tp::Feature &feature : features) {
+        QVERIFY(pc->features().contains(feature));
+    }
 
-    expectPendingContactsFinished(pc);
+    expectPendingContactsFinished(pc, features);
 }
 
 void TestConnHelper::expectContactsForHandlesFinished(Tp::PendingOperation *op)
@@ -386,6 +392,25 @@ void TestConnHelper::expectPendingContactsFinished(Tp::PendingContacts *pc)
     }
 }
 
+void TestConnHelper::expectPendingContactsFinished(Tp::PendingContacts *pc,
+                                                   const Tp::Features &features)
+{
+    QCOMPARE(pc->manager(), mClient->contactManager());
+    if (pc->isError()) {
+        qWarning().nospace() << pc->errorName() << ": " << pc->errorMessage();
+    } else {
+        for (const Tp::Feature &feature : features) {
+            if (!pc->features().contains(feature)) {
+                qWarning() << Q_FUNC_INFO << "The result has no requested feature" << feature;
+            }
+        }
+        const QList<Tp::ContactPtr> contacts = pc->contacts();
+        for (const Tp::ContactPtr &contact : contacts) {
+            QVERIFY(contact->requestedFeatures().contains(features));
+        }
+    }
+}
+
 void TestConnHelper::expectCreateChannelFinished(Tp::PendingOperation *op)
 {
     if (op->isError()) {
diff --git a/tests/lib/glib-helpers/test-conn-helper.h b/tests/lib/glib-helpers/test-conn-helper.h
index 7f1a09f7..a40b3609 100644
--- a/tests/lib/glib-helpers/test-conn-helper.h
+++ b/tests/lib/glib-helpers/test-conn-helper.h
@@ -68,7 +68,8 @@ public:
 
 private Q_SLOTS:
     void expectConnInvalidated();
-    void expectContactsForIdentifiersFinished(Tp::PendingOperation *op);
+    void checkFinishedContactsForIdentifiers(Tp::PendingContacts *pc,
+                                             const Tp::Features &features);
     void expectContactsForHandlesFinished(Tp::PendingOperation *op);
     void expectUpgradeContactsFinished(Tp::PendingOperation *op);
     void expectCreateChannelFinished(Tp::PendingOperation *op);
@@ -85,6 +86,7 @@ private:
             GType gType, const char *firstPropertyName, va_list varArgs);
 
     void expectPendingContactsFinished(Tp::PendingContacts *pc);
+    void expectPendingContactsFinished(Tp::PendingContacts *pc, const Tp::Features &features);
 
     Test *mParent;
     QEventLoop *mLoop;



More information about the telepathy-commits mailing list