[Telepathy-commits] [telepathy-qt4/master] Add test for upgradeContacts

Olli Salli olli.salli at collabora.co.uk
Mon Feb 2 02:47:57 PST 2009


---
 tests/dbus/contacts.cpp |   72 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index b362eee..21ae9e0 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -43,6 +43,7 @@ private Q_SLOTS:
 
     void testForHandles();
     void testForIdentifiers();
+    void testUpgrade();
 
     void cleanup();
     void cleanupTestCase();
@@ -349,6 +350,77 @@ void TestContacts::testForIdentifiers()
     }
 }
 
+void TestContacts::testUpgrade()
+{
+    QStringList ids = QStringList() << "alice" << "bob" << "chris";
+    Telepathy::UIntList handles;
+    TpHandleRepoIface *serviceRepo =
+        tp_base_connection_get_handles(TP_BASE_CONNECTION(mConnService), TP_HANDLE_TYPE_CONTACT);
+
+    for (int i = 0; i < 3; i++) {
+        handles.push_back(tp_handle_ensure(serviceRepo, ids[i].toLatin1().constData(), NULL, NULL));
+        QVERIFY(handles[i] != 0);
+    }
+
+    PendingContacts *pending = mConn->contactManager()->contactsForHandles(handles);
+
+    // Wait for the contacts to be built
+    QVERIFY(connect(pending,
+                SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+                SLOT(expectPendingContactsFinished(Telepathy::Client::PendingOperation*))));
+    QCOMPARE(mLoop->exec(), 0);
+
+    // There should be 3 resulting contacts - save them for future reference
+    QCOMPARE(mContacts.size(), 3);
+    QList<QSharedPointer<Contact> > saveContacts = mContacts;
+
+    // Upgrade them
+    // TODO: when features are added, actually add more features when upgrading :P
+    QSet<Contact::Feature> features = QSet<Contact::Feature>();
+    pending = mConn->contactManager()->upgradeContacts(saveContacts, features);
+
+    // Test the closure accessors
+    QCOMPARE(pending->manager(), mConn->contactManager());
+    QCOMPARE(pending->features(), features);
+
+    QVERIFY(!pending->isForHandles());
+    QVERIFY(!pending->isForIdentifiers());
+    QVERIFY(pending->isUpgrade());
+
+    QCOMPARE(pending->contactsToUpgrade(), saveContacts);
+
+    // Wait for the contacts to be built
+    QVERIFY(connect(pending,
+                SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+                SLOT(expectPendingContactsFinished(Telepathy::Client::PendingOperation*))));
+    QCOMPARE(mLoop->exec(), 0);
+
+    // Check that we got the correct contacts back
+    QCOMPARE(mContacts, saveContacts);
+
+    // Check the contact contents
+    for (int i = 0; i < 3; i++) {
+        QCOMPARE(mContacts[i]->handle()[0], handles[i]);
+        QCOMPARE(mContacts[i]->id(), ids[i]);
+        QCOMPARE(mContacts[i]->requestedFeatures(), features);
+        QVERIFY((mContacts[i]->actualFeatures() - mContacts[i]->requestedFeatures()).isEmpty());
+    }
+
+    // Make the contacts go out of scope, starting releasing their handles, and finish that
+    saveContacts.clear();
+    mContacts.clear();
+    mLoop->processEvents();
+    processDBusQueue(mConn);
+
+    // Unref the handles we created service-side
+    tp_handle_unref(serviceRepo, handles[0]);
+    QVERIFY(!tp_handle_is_valid(serviceRepo, handles[0], NULL));
+    tp_handle_unref(serviceRepo, handles[1]);
+    QVERIFY(!tp_handle_is_valid(serviceRepo, handles[1], NULL));
+    tp_handle_unref(serviceRepo, handles[2]);
+    QVERIFY(!tp_handle_is_valid(serviceRepo, handles[2], NULL));
+}
+
 void TestContacts::cleanup()
 {
     cleanupImpl();
-- 
1.5.6.5




More information about the Telepathy-commits mailing list