[Telepathy-commits] [telepathy-qt4/master] Connection: Added tests for presence.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Mon Jan 26 13:26:01 PST 2009


---
 TelepathyQt4/Client/connection.cpp |    4 +-
 tests/dbus/Makefile.am             |    5 +
 tests/dbus/conn-basics.cpp         |  191 ++++++++++++++++++++++++++++++++++++
 3 files changed, 198 insertions(+), 2 deletions(-)
 create mode 100644 tests/dbus/conn-basics.cpp

diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 8c6a135..663a340 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -955,7 +955,7 @@ void Connection::gotSelfPresence(QDBusPendingCallWatcher *watcher)
 
     if (!reply.isError()) {
         mPriv->changeSelfPresence(reply.value()[mPriv->selfHandle]);
-        debug() << "Got self presence";
+        debug() << "Got self presence:" << mPriv->selfPresence.type;
     }
     else {
         warning().nospace() << "Getting self presence status failed with" <<
@@ -973,7 +973,7 @@ void Connection::gotSelfHandle(QDBusPendingCallWatcher *watcher)
 
     if (!reply.isError()) {
         mPriv->selfHandle = reply.value();
-        debug() << "Got self handle";
+        debug() << "Got self handle" << mPriv->selfHandle;
     }
     else {
         warning().nospace() << "Getting self handle failed with" <<
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 4706779..15348de 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -39,11 +39,13 @@ if ENABLE_TP_GLIB_TESTS
 # to use the GLib main loop
 TESTS += \
     test-cm-basics \
+    test-conn-basics \
     test-handles \
     test-stateful-proxy
 
 BUILT_SOURCES += \
     _gen/cm-basics.cpp.moc.hpp \
+    _gen/conn-basics.cpp.moc.hpp \
     _gen/handles.cpp.moc.hpp \
     _gen/stateful-proxy.cpp.moc.hpp
 
@@ -52,6 +54,9 @@ MOC_INCLUDES += $(TP_GLIB_CFLAGS)
 test_cm_basics_SOURCES = cm-basics.cpp
 test_cm_basics_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
 
+test_conn_basics_SOURCES = conn-basics.cpp
+test_conn_basics_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
+
 test_handles_SOURCES = handles.cpp
 test_handles_LDADD = $(LDADD) $(top_builddir)/tests/lib/libtp-glib-tests.la
 
diff --git a/tests/dbus/conn-basics.cpp b/tests/dbus/conn-basics.cpp
new file mode 100644
index 0000000..aed6383
--- /dev/null
+++ b/tests/dbus/conn-basics.cpp
@@ -0,0 +1,191 @@
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+
+#include <QtDBus/QtDBus>
+
+#include <QtTest/QtTest>
+
+#include <TelepathyQt4/Client/Connection>
+#include <TelepathyQt4/Client/PendingChannel>
+#include <TelepathyQt4/Debug>
+
+#include <telepathy-glib/debug.h>
+
+#include <tests/lib/contacts-conn.h>
+#include <tests/lib/test.h>
+
+using namespace Telepathy::Client;
+
+class TestConnBasics : public Test
+{
+    Q_OBJECT
+
+public:
+    Connection *mConn;
+    ContactsConnection *mConnService;
+    QString mConnName, mConnPath;
+
+protected Q_SLOTS:
+    void expectConnReady(uint, uint);
+    void expectConnInvalidated();
+    void expectPresenceAvailable(const Telepathy::SimplePresence &);
+
+private Q_SLOTS:
+    void initTestCaseImpl();
+    void initImpl();
+
+    void testSimplePresence();
+
+    void cleanupImpl();
+    void cleanupTestCaseImpl();
+};
+
+void TestConnBasics::expectConnReady(uint newStatus, uint newStatusReason)
+{
+    qDebug() << "==>>> connection changed to status" << newStatus;
+    switch (newStatus) {
+    case Connection::StatusDisconnected:
+        qWarning() << "Disconnected";
+        mLoop->exit(1);
+        break;
+    case Connection::StatusConnecting:
+        /* do nothing */
+        break;
+    case Connection::StatusConnected:
+        qDebug() << "Ready";
+        mLoop->exit(0);
+        break;
+    default:
+        qWarning().nospace() << "What sort of status is "
+            << newStatus << "?!";
+        mLoop->exit(2);
+        break;
+    }
+}
+
+void TestConnBasics::expectConnInvalidated()
+{
+    mLoop->exit(0);
+}
+
+void TestConnBasics::expectPresenceAvailable(const Telepathy::SimplePresence &presence)
+{
+    if (presence.type == Telepathy::ConnectionPresenceTypeAvailable) {
+        mLoop->exit(0);
+        return;
+    }
+    mLoop->exit(1);
+}
+
+void TestConnBasics::initTestCaseImpl()
+{
+    Test::initTestCaseImpl();
+
+    g_type_init();
+    g_set_prgname("conn-basics");
+    tp_debug_set_flags("all");
+
+    gchar *name;
+    gchar *connPath;
+    GError *error = 0;
+
+    mConnService = CONTACTS_CONNECTION(g_object_new(
+            CONTACTS_TYPE_CONNECTION,
+            "account", "me at example.com",
+            "protocol", "contacts",
+            0));
+    QVERIFY(mConnService != 0);
+    QVERIFY(tp_base_connection_register(TP_BASE_CONNECTION(mConnService), "contacts", &name,
+                &connPath, &error));
+    QVERIFY(error == 0);
+
+    QVERIFY(name != 0);
+    QVERIFY(connPath != 0);
+
+    mConnName = name;
+    mConnPath = connPath;
+
+    g_free(name);
+    g_free(connPath);
+}
+
+void TestConnBasics::initImpl()
+{
+    mConn = new Connection(mConnName, mConnPath);
+
+    QVERIFY(connect(mConn->becomeReady(),
+                    SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+                    SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mConn->isReady(), true);
+
+    mConn->requestConnect();
+
+    QVERIFY(connect(mConn,
+                    SIGNAL(statusChanged(uint, uint)),
+                    SLOT(expectConnReady(uint, uint))));
+    QCOMPARE(mLoop->exec(), 0);
+    QVERIFY(disconnect(mConn,
+                       SIGNAL(statusChanged(uint, uint)),
+                       this,
+                       SLOT(expectConnReady(uint, uint))));
+    QCOMPARE(mConn->status(), (uint) Connection::StatusConnected);
+}
+
+void TestConnBasics::testSimplePresence()
+{
+    QCOMPARE(mConn->isReady(Connection::FeatureSelfPresence), false);
+    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSelfPresence),
+                    SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+                    SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mConn->isReady(Connection::FeatureSelfPresence), true);
+
+    QVERIFY(connect(mConn,
+                    SIGNAL(selfPresenceChanged(const Telepathy::SimplePresence &)),
+                    SLOT(expectPresenceAvailable(const Telepathy::SimplePresence &))));
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mConn->selfPresence().type, (uint) Telepathy::ConnectionPresenceTypeAvailable);
+    QCOMPARE(mConn->selfPresence().status, QString("available"));
+
+    qDebug() << "mConn->status:" << mConn->status();
+    qDebug() << "mConn->selfPresence "
+                "type:" << mConn->selfPresence().type <<
+                "status:" << mConn->selfPresence().status <<
+                "status message:" << mConn->selfPresence().statusMessage;
+}
+
+void TestConnBasics::cleanupImpl()
+{
+    if (mConn != 0) {
+        // Disconnect and wait for the readiness change
+        QVERIFY(connect(mConn->requestDisconnect(),
+                        SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+                        SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
+        QCOMPARE(mLoop->exec(), 0);
+
+        if (mConn->isValid()) {
+            QVERIFY(connect(mConn,
+                            SIGNAL(invalidated(Telepathy::Client::DBusProxy *proxy,
+                                               QString errorName, QString errorMessage)),
+                            SLOT(expectConnInvalidated())));
+            QCOMPARE(mLoop->exec(), 0);
+        }
+
+        delete mConn;
+        mConn = 0;
+    }
+}
+
+void TestConnBasics::cleanupTestCaseImpl()
+{
+    if (mConnService != 0) {
+        g_object_unref(mConnService);
+        mConnService = 0;
+    }
+
+    Test::cleanupTestCaseImpl();
+}
+
+QTEST_MAIN(TestConnBasics)
+#include "_gen/conn-basics.cpp.moc.hpp"
-- 
1.5.6.5




More information about the Telepathy-commits mailing list