[Telepathy-commits] [telepathy-qt4/master] Factor out parts of PinocchioTest into a generic Test helper

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 23 04:34:13 PST 2009


---
 tests/dbus/Makefile.am      |    1 +
 tests/lib/Makefile.am       |   29 ++++++++++++++++--
 tests/lib/test.cpp          |   68 +++++++++++++++++++++++++++++++++++++++++++
 tests/lib/test.h            |   29 ++++++++++++++++++
 tests/pinocchio/Makefile.am |    1 +
 tests/pinocchio/lib.cpp     |   51 +++++---------------------------
 tests/pinocchio/lib.h       |   15 +++------
 7 files changed, 137 insertions(+), 57 deletions(-)
 create mode 100644 tests/lib/test.cpp
 create mode 100644 tests/lib/test.h

diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 18600b6..4706779 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -63,6 +63,7 @@ LDADD = \
     $(QTCORE_LIBS) \
     $(QTDBUS_LIBS) \
     $(QTTEST_LIBS) \
+    ${top_builddir}/tests/lib/libtp-qt4-tests.la \
     ${top_builddir}/TelepathyQt4/libtelepathy-qt4.la
 
 AM_CXXFLAGS = \
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 1cb5b42..ab3b1c3 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -1,14 +1,31 @@
-AM_CFLAGS = \
-    $(ERROR_CFLAGS) \
-    $(TP_GLIB_CFLAGS)
+AM_CFLAGS = $(ERROR_CFLAGS)
 
-noinst_LTLIBRARIES =
+MOC_INCLUDES = \
+    $(QTCORE_CFLAGS) \
+    $(QTDBUS_CFLAGS) \
+    $(QTTEST_CFLAGS) \
+    $(TP_QT4_CFLAGS)
+
+AM_CXXFLAGS = $(ERROR_CXXFLAGS) $(MOC_INCLUDES)
+
+noinst_LTLIBRARIES = libtp-qt4-tests.la
 
 EXTRA_DIST = \
     account-manager.py
 
+BUILT_SOURCES = \
+    _gen/test.h.moc.hpp
+
+libtp_qt4_tests_la_SOURCES = \
+    test.cpp \
+    test.h
+libtp_qt4_tests_la_LIBADD = $(top_builddir)/TelepathyQt4/libtelepathy-qt4.la
+
 if ENABLE_TP_GLIB_TESTS
 
+AM_CFLAGS += $(TP_GLIB_CFLAGS)
+AM_CXXFLAGS += $(TP_GLIB_CFLAGS)
+
 noinst_LTLIBRARIES += libtp-glib-tests.la
 
 libtp_glib_tests_la_SOURCES = \
@@ -20,3 +37,7 @@ libtp_glib_tests_la_LIBADD = \
     $(TP_GLIB_LIBS)
 
 endif
+
+_gen/%.moc.hpp: %
+	$(mkdir_p) _gen
+	$(MOC) $(MOC_INCLUDES) -i $< -o $@
diff --git a/tests/lib/test.cpp b/tests/lib/test.cpp
new file mode 100644
index 0000000..c00ad18
--- /dev/null
+++ b/tests/lib/test.cpp
@@ -0,0 +1,68 @@
+#include "tests/lib/test.h"
+
+#include <cstdlib>
+
+#include <QtCore/QTimer>
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Debug>
+#include <TelepathyQt4/Client/DBus>
+
+using Telepathy::Client::PendingOperation;
+
+Test::Test(QObject *parent)
+    : QObject(parent), mLoop(new QEventLoop(this))
+{
+}
+
+Test::~Test()
+{
+    delete mLoop;
+}
+
+void Test::initTestCaseImpl()
+{
+    Telepathy::registerTypes();
+    Telepathy::enableDebug(true);
+    Telepathy::enableWarnings(true);
+
+    QVERIFY(QDBusConnection::sessionBus().isConnected());
+}
+
+void Test::initImpl()
+{
+}
+
+void Test::cleanupImpl()
+{
+}
+
+void Test::cleanupTestCaseImpl()
+{
+}
+
+void Test::expectSuccessfulCall(PendingOperation *op)
+{
+    if (op->isError()) {
+        qWarning().nospace() << op->errorName()
+            << ": " << op->errorMessage();
+        mLoop->exit(1);
+        return;
+    }
+
+    mLoop->exit(0);
+}
+
+void Test::expectSuccessfulCall(QDBusPendingCallWatcher *watcher)
+{
+    if (watcher->isError()) {
+        qWarning().nospace() << watcher->error().name()
+            << ": " << watcher->error().message();
+        mLoop->exit(1);
+        return;
+    }
+
+    mLoop->exit(0);
+}
+
+#include "_gen/test.h.moc.hpp"
diff --git a/tests/lib/test.h b/tests/lib/test.h
new file mode 100644
index 0000000..06edefc
--- /dev/null
+++ b/tests/lib/test.h
@@ -0,0 +1,29 @@
+#include <QtDBus>
+
+#include <QtTest>
+
+#include <TelepathyQt4/Client/PendingOperation>
+#include <TelepathyQt4/Constants>
+
+class Test : public QObject
+{
+    Q_OBJECT
+
+public:
+
+    Test(QObject *parent = 0);
+
+    virtual ~Test();
+
+    QEventLoop *mLoop;
+
+protected Q_SLOTS:
+    void expectSuccessfulCall(QDBusPendingCallWatcher*);
+    void expectSuccessfulCall(Telepathy::Client::PendingOperation*);
+
+    virtual void initTestCaseImpl();
+    virtual void initImpl();
+
+    virtual void cleanupImpl();
+    virtual void cleanupTestCaseImpl();
+};
diff --git a/tests/pinocchio/Makefile.am b/tests/pinocchio/Makefile.am
index 0ed8831..e326646 100644
--- a/tests/pinocchio/Makefile.am
+++ b/tests/pinocchio/Makefile.am
@@ -49,6 +49,7 @@ LDADD = \
     $(QTCORE_LIBS) \
     $(QTDBUS_LIBS) \
     $(QTTEST_LIBS) \
+    ${top_builddir}/tests/lib/libtp-qt4-tests.la \
     ${top_builddir}/TelepathyQt4/libtelepathy-qt4.la
 
 AM_CXXFLAGS = \
diff --git a/tests/pinocchio/lib.cpp b/tests/pinocchio/lib.cpp
index ecdd8b8..883e404 100644
--- a/tests/pinocchio/lib.cpp
+++ b/tests/pinocchio/lib.cpp
@@ -11,16 +11,18 @@
 using Telepathy::Client::DBus::DBusDaemonInterface;
 using Telepathy::Client::PendingOperation;
 
+PinocchioTest::PinocchioTest(QObject *parent)
+    : Test(parent)
+{
+}
+
 PinocchioTest::~PinocchioTest()
 {
-    delete mLoop;
 }
 
 void PinocchioTest::initTestCaseImpl()
 {
-    Telepathy::registerTypes();
-    Telepathy::enableDebug(true);
-    Telepathy::enableWarnings(true);
+    Test::initTestCaseImpl();
 
     mPinocchioPath = QString::fromLocal8Bit(::getenv("PINOCCHIO"));
     mPinocchioCtlPath = QString::fromLocal8Bit(::getenv("PINOCCHIO_CTL"));
@@ -38,8 +40,6 @@ void PinocchioTest::initTestCaseImpl()
     dir.cd(pinocchioSavePath);
     dir.remove(QLatin1String("empty/contacts.xml"));
 
-    QVERIFY(QDBusConnection::sessionBus().isConnected());
-
     mPinocchio.setProcessChannelMode(QProcess::ForwardedChannels);
     mPinocchio.start(mPinocchioPath, QStringList());
 
@@ -49,43 +49,6 @@ void PinocchioTest::initTestCaseImpl()
     qDebug() << "Started Pinocchio";
 }
 
-
-void PinocchioTest::initImpl()
-{
-}
-
-
-void PinocchioTest::cleanupImpl()
-{
-}
-
-
-void PinocchioTest::expectSuccessfulCall(PendingOperation* op)
-{
-    if (op->isError()) {
-        qWarning().nospace() << op->errorName()
-            << ": " << op->errorMessage();
-        mLoop->exit(1);
-        return;
-    }
-
-    mLoop->exit(0);
-}
-
-
-void PinocchioTest::expectSuccessfulCall(QDBusPendingCallWatcher* watcher)
-{
-    if (watcher->isError()) {
-        qWarning().nospace() << watcher->error().name()
-            << ": " << watcher->error().message();
-        mLoop->exit(1);
-        return;
-    }
-
-    mLoop->exit(0);
-}
-
-
 void PinocchioTest::gotNameOwner(QDBusPendingCallWatcher* watcher)
 {
     QDBusPendingReply<QString> reply = *watcher;
@@ -153,6 +116,8 @@ void PinocchioTest::cleanupTestCaseImpl()
     if (!mPinocchio.waitForFinished(1000)) {
         mPinocchio.kill();
     }
+
+    Test::cleanupTestCaseImpl();
 }
 
 #include "_gen/lib.h.moc.hpp"
diff --git a/tests/pinocchio/lib.h b/tests/pinocchio/lib.h
index d38f3bd..fbbf6d0 100644
--- a/tests/pinocchio/lib.h
+++ b/tests/pinocchio/lib.h
@@ -7,15 +7,15 @@
 #include <TelepathyQt4/Client/PendingOperation>
 #include <TelepathyQt4/Constants>
 
-class PinocchioTest : public QObject
+#include "tests/lib/test.h"
+
+class PinocchioTest : public Test
 {
     Q_OBJECT
 
 public:
 
-    PinocchioTest(QObject *parent = 0)
-        : QObject(parent), mLoop(new QEventLoop(this))
-    { }
+    PinocchioTest(QObject *parent = 0);
 
     virtual ~PinocchioTest();
 
@@ -39,16 +39,11 @@ protected:
     QProcess mPinocchio;
     QEventLoop *mLoop;
 
-protected Q_SLOTS:
-    void expectSuccessfulCall(QDBusPendingCallWatcher*);
-    void expectSuccessfulCall(Telepathy::Client::PendingOperation*);
-
     virtual void initTestCaseImpl();
-    virtual void initImpl();
 
-    virtual void cleanupImpl();
     virtual void cleanupTestCaseImpl();
 
+protected Q_SLOTS:
     void gotNameOwner(QDBusPendingCallWatcher* watcher);
     void onNameOwnerChanged(const QString&, const QString&, const QString&);
 };
-- 
1.5.6.5




More information about the Telepathy-commits mailing list