[Telepathy-commits] [telepathy-qt4/master] Add a simple CM test using a telepathy-glib CM in-process with the test

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 9 08:14:35 PST 2009


---
 tests/dbus/Makefile.am   |   15 +++++
 tests/dbus/cm-basics.cpp |  150 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/cm-basics.cpp

diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index fb46913..f620718 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -34,6 +34,21 @@ BUILT_SOURCES += \
 test_account_basics_SOURCES = account-basics.cpp
 endif
 
+if ENABLE_TP_GLIB_TESTS
+# Tests which can only be run if we have telepathy-glib, and Qt was compiled
+# to use the GLib main loop
+TESTS += \
+    test-cm-basics
+
+BUILT_SOURCES += \
+    _gen/cm-basics.cpp.moc.hpp
+
+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
+endif
+
 LDADD = \
     $(QTCORE_LIBS) \
     $(QTDBUS_LIBS) \
diff --git a/tests/dbus/cm-basics.cpp b/tests/dbus/cm-basics.cpp
new file mode 100644
index 0000000..02970c3
--- /dev/null
+++ b/tests/dbus/cm-basics.cpp
@@ -0,0 +1,150 @@
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+
+#include <QtDBus/QtDBus>
+
+#include <QtTest/QtTest>
+
+#include <TelepathyQt4/Client/ConnectionManager>
+#include <TelepathyQt4/Client/PendingStringList>
+#include <TelepathyQt4/Debug>
+
+#include <telepathy-glib/debug.h>
+
+#include <tests/lib/simple-manager.h>
+
+using namespace Telepathy::Client;
+
+class TestCmBasics : public QObject
+{
+    Q_OBJECT
+
+public:
+    QEventLoop *mLoop;
+    Telepathy::Client::ConnectionManager* mCM;
+    TpBaseConnectionManager *mCmService;
+
+protected Q_SLOTS:
+    void expectSuccessfulCall(Telepathy::Client::PendingOperation*);
+
+private Q_SLOTS:
+    void initTestCase();
+    void init();
+
+    void testBasics();
+
+    void cleanup();
+    void cleanupTestCase();
+};
+
+
+void TestCmBasics::initTestCase()
+{
+    Telepathy::registerTypes();
+    Telepathy::enableDebug(true);
+    Telepathy::enableWarnings(true);
+
+    QVERIFY(QDBusConnection::sessionBus().isConnected());
+
+    g_type_init();
+    g_set_prgname("cm-basics");
+    tp_debug_set_flags("all");
+
+    mCmService = TP_BASE_CONNECTION_MANAGER(g_object_new(
+        SIMPLE_TYPE_CONNECTION_MANAGER,
+        NULL));
+    QVERIFY(mCmService != NULL);
+    QVERIFY(tp_base_connection_manager_register (mCmService));
+}
+
+
+void TestCmBasics::init()
+{
+    mLoop = new QEventLoop(this);
+}
+
+
+void TestCmBasics::expectSuccessfulCall(PendingOperation* op)
+{
+    qDebug() << "pending operation finished";
+    if (op->isError()) {
+        qWarning().nospace() << op->errorName()
+            << ": " << op->errorMessage();
+        mLoop->exit(1);
+        return;
+    }
+
+    mLoop->exit(0);
+}
+
+
+void TestCmBasics::testBasics()
+{
+    mCM = new ConnectionManager("simple");
+    QCOMPARE(mCM->isReady(), false);
+
+    connect(mCM->becomeReady(),
+            SIGNAL(finished(Telepathy::Client::PendingOperation *)),
+            this,
+            SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation *)));
+    qDebug() << "enter main loop";
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mCM->isReady(), true);
+
+    // calling becomeReady() twice is a no-op
+    connect(mCM->becomeReady(),
+            SIGNAL(finished(Telepathy::Client::PendingOperation *)),
+            this,
+            SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation *)));
+    QCOMPARE(mLoop->exec(), 0);
+    QCOMPARE(mCM->isReady(), true);
+
+    QCOMPARE(mCM->interfaces(), QStringList());
+    QCOMPARE(mCM->supportedProtocols(), QStringList() << "simple");
+
+    Q_FOREACH (ProtocolInfo *info, mCM->protocols()) {
+        QVERIFY(info != 0);
+        QVERIFY(info->cmName() == "simple");
+        QVERIFY(info->name() == "simple");
+
+        QCOMPARE(info->hasParameter("account"), true);
+        QCOMPARE(info->hasParameter("not-there"), false);
+
+        Q_FOREACH (ProtocolParameter *param, info->parameters()) {
+            QCOMPARE(param->name(), QString::fromAscii("account"));
+            QCOMPARE(param->dbusSignature().signature(),
+                         QLatin1String("s"));
+            QCOMPARE(param->isRequired(), true);
+            QCOMPARE(param->isSecret(), false);
+        }
+        QCOMPARE(info->canRegister(), false);
+    }
+
+    QCOMPARE(mCM->supportedProtocols(), QStringList() << "simple");
+}
+
+
+void TestCmBasics::cleanup()
+{
+    if (mCM != NULL) {
+        delete mCM;
+        mCM = NULL;
+    }
+    if (mLoop != NULL) {
+        delete mLoop;
+        mLoop = NULL;
+    }
+}
+
+
+void TestCmBasics::cleanupTestCase()
+{
+    if (mCmService != NULL) {
+        g_object_unref(mCmService);
+        mCmService = NULL;
+    }
+}
+
+
+QTEST_MAIN(TestCmBasics)
+#include "_gen/cm-basics.cpp.moc.hpp"
-- 
1.5.6.5



More information about the Telepathy-commits mailing list