[Telepathy-commits] [telepathy-qt4/master] tests/pinocchio/do-nothing.cpp: rework to use QtTest

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Nov 27 04:39:26 PST 2008


---
 tests/pinocchio/Makefile.am    |   17 ++++++-
 tests/pinocchio/do-nothing.cpp |  102 +++++++++++++++++++++++++++++-----------
 2 files changed, 89 insertions(+), 30 deletions(-)

diff --git a/tests/pinocchio/Makefile.am b/tests/pinocchio/Makefile.am
index a35754b..286d5df 100644
--- a/tests/pinocchio/Makefile.am
+++ b/tests/pinocchio/Makefile.am
@@ -5,24 +5,35 @@ if HAVE_PINOCCHIO
 TESTS = \
     test-do-nothing
 
+BUILT_SOURCES = \
+    _gen/do-nothing.moc.hpp
+
+_gen/%.moc.hpp: %.cpp
+	$(mkdir_p) _gen
+	$(MOC) $(LIB_CFLAGS) -i $< -o $@
+
 noinst_PROGRAMS = $(TESTS)
 
 test_do_nothing_SOURCES = do-nothing.cpp
 test_do_nothing_LDADD = $(TP_QT4_LIBS) $(QTTEST_LIBS)
 
-AM_CXXFLAGS = \
-    $(ERROR_CXXFLAGS) \
+LIB_CFLAGS = \
     $(QTCORE_CFLAGS) \
     $(QTDBUS_CFLAGS) \
     $(QTTEST_CFLAGS) \
     $(TP_QT4_CFLAGS)
 
+AM_CXXFLAGS = \
+    $(ERROR_CXXFLAGS) \
+    $(LIB_CFLAGS)
+
 TESTS_ENV = \
     abs_top_builddir=@abs_top_builddir@ \
     abs_top_srcdir=@abs_top_srcdir@ \
     XDG_DATA_HOME=@abs_top_builddir@/tests \
     XDG_DATA_DIRS=@abs_top_srcdir@/tests \
-    PINOCCHIO=@PINOCCHIO@
+    PINOCCHIO=@PINOCCHIO@ \
+    PINOCCHIO_CTL=@PINOCCHIO_CTL@
 
 TESTS_ENVIRONMENT = \
     $(TESTS_ENV) \
diff --git a/tests/pinocchio/do-nothing.cpp b/tests/pinocchio/do-nothing.cpp
index 60c0554..5a7ba56 100644
--- a/tests/pinocchio/do-nothing.cpp
+++ b/tests/pinocchio/do-nothing.cpp
@@ -7,42 +7,90 @@
 
 #include <QtDBus/QtDBus>
 
-extern "C" int main(int argc, char **argv)
+#include <QtTest/QtTest>
+
+class TestDoNothing : public QObject
 {
-    QCoreApplication app(argc, argv);
-    char *command = ::getenv("PINOCCHIO");
+    Q_OBJECT
 
-    if (!command) {
-        qFatal("Put $PINOCCHIO in your environment");
-        return 1;
-    }
+public:
+    TestDoNothing(QObject *parent = 0)
+        : QObject(parent), mLoop(new QEventLoop(this))
+    { }
 
-    if (!QDBusConnection::sessionBus().isConnected()) {
-        qFatal("Session bus not available");
-        return 1;
-    }
+private:
+    QString mPinocchioPath;
+    QString mPinocchioCtlPath;
+    QProcess mPinocchio;
+    QEventLoop *mLoop;
 
-    QProcess pinocchio;
+private slots:
+    void initTestCase();
+    void init();
 
-    pinocchio.setProcessChannelMode(QProcess::ForwardedChannels);
-    pinocchio.start(command, QStringList());
+    void doNothing();
+    void doNothing2();
 
-    if (!pinocchio.waitForStarted(5000)) {
-        qFatal("Timed out waiting for pinocchio to start");
-        return 1;
-    }
+    void cleanup();
+    void cleanupTestCase();
+};
 
-    pinocchio.closeWriteChannel();
 
-    /* insert test logic here... */
-    QTimer::singleShot(0, &app, SLOT(quit()));
-    int ret = app.exec();
+void TestDoNothing::initTestCase()
+{
+    mPinocchioPath = QString::fromLocal8Bit(::getenv("PINOCCHIO"));
+    mPinocchioCtlPath = QString::fromLocal8Bit(::getenv("PINOCCHIO_CTL"));
 
-    pinocchio.terminate();
+    QVERIFY2(!mPinocchioPath.isEmpty(), "Put $PINOCCHIO in your environment");
+    QVERIFY2(!mPinocchioCtlPath.isEmpty(),
+        "Put $PINOCCHIO_CTL in your environment");
+    QVERIFY(QDBusConnection::sessionBus().isConnected());
 
-    if (!pinocchio.waitForFinished(1000)) {
-        pinocchio.kill();
-    }
+    mPinocchio.setProcessChannelMode(QProcess::ForwardedChannels);
+    mPinocchio.start(mPinocchioPath, QStringList());
+
+    QVERIFY(mPinocchio.waitForStarted(5000));
+    mPinocchio.closeWriteChannel();
+
+    qDebug() << "Started Pinocchio";
+}
+
+
+void TestDoNothing::init()
+{
+}
+
+
+void TestDoNothing::doNothing()
+{
+    QTimer::singleShot(0, mLoop, SLOT(quit()));
+    QCOMPARE(mLoop->exec(), 0);
+}
+
+
+void TestDoNothing::doNothing2()
+{
+    QTimer::singleShot(0, mLoop, SLOT(quit()));
+    QCOMPARE(mLoop->exec(), 0);
+}
+
+
+void TestDoNothing::cleanup()
+{
+}
+
+
+void TestDoNothing::cleanupTestCase()
+{
+    qDebug() << "Terminating Pinocchio";
 
-    return ret;
+    mPinocchio.terminate();
+
+    if (!mPinocchio.waitForFinished(1000)) {
+        mPinocchio.kill();
+    }
 }
+
+
+QTEST_MAIN(TestDoNothing)
+#include "_gen/do-nothing.moc.hpp"
-- 
1.5.6.5




More information about the Telepathy-commits mailing list