[Telepathy-commits] [telepathy-qt4/master] Check for QtTest and port tests/dbus/do-nothing.cpp to QtTest

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


---
 configure.ac                |    6 ++++
 tests/dbus/Makefile.am      |   17 +++++++++--
 tests/dbus/do-nothing.cpp   |   66 +++++++++++++++++++++++++++++++++++++-----
 tests/pinocchio/Makefile.am |    3 +-
 4 files changed, 80 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9d53a2e..818a30e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,6 +130,12 @@ PKG_CHECK_MODULES(QTDBUS, [QtDBus >= 4.5])
 AC_SUBST(QTDBUS_CFLAGS)
 AC_SUBST(QTDBUS_LIBS)
 
+dnl Check for QtTest
+PKG_CHECK_MODULES(QTTEST, [QtTest >= 4.5])
+
+AC_SUBST(QTTEST_CFLAGS)
+AC_SUBST(QTTEST_LIBS)
+
 dnl We want the examples to be able to use TP_QT4_CFLAGS, TP_QT4_LIBS
 dnl as though they were independent programs that got them from pkgconfig
 TP_QT4_CFLAGS='-I${top_builddir} -I${top_srcdir}'
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index eafd2a4..191c737 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -3,17 +3,28 @@
 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)
+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@ \
diff --git a/tests/dbus/do-nothing.cpp b/tests/dbus/do-nothing.cpp
index 8b93194..db1e40c 100644
--- a/tests/dbus/do-nothing.cpp
+++ b/tests/dbus/do-nothing.cpp
@@ -4,16 +4,66 @@
 
 #include <QtDBus/QtDBus>
 
-extern "C" int main(int argc, char **argv)
+#include <QtTest/QtTest>
+
+class TestDoNothing : public QObject
+{
+    Q_OBJECT
+
+public:
+    TestDoNothing(QObject *parent = 0)
+        : QObject(parent), mLoop(new QEventLoop(this))
+    { }
+
+private:
+    QEventLoop *mLoop;
+
+private slots:
+    void initTestCase();
+    void init();
+
+    void doNothing();
+    void doNothing2();
+
+    void cleanup();
+    void cleanupTestCase();
+};
+
+
+void TestDoNothing::initTestCase()
+{
+  QVERIFY(QDBusConnection::sessionBus().isConnected());
+}
+
+
+void TestDoNothing::init()
+{
+}
+
+
+void TestDoNothing::doNothing()
+{
+  QTimer::singleShot(0, mLoop, SLOT(quit()));
+  QCOMPARE(mLoop->exec(), 0);
+}
+
+
+void TestDoNothing::doNothing2()
 {
-    QCoreApplication app(argc, argv);
+  QTimer::singleShot(0, mLoop, SLOT(quit()));
+  QCOMPARE(mLoop->exec(), 0);
+}
+
 
-    if (!QDBusConnection::sessionBus().isConnected()) {
-        qFatal("Session bus not available");
-        return 1;
-    }
+void TestDoNothing::cleanup()
+{
+}
 
-    QTimer::singleShot(0, &app, SLOT(quit()));
 
-    return app.exec();
+void TestDoNothing::cleanupTestCase()
+{
 }
+
+
+QTEST_MAIN(TestDoNothing)
+#include "_gen/do-nothing.moc.hpp"
diff --git a/tests/pinocchio/Makefile.am b/tests/pinocchio/Makefile.am
index aec4bea..a35754b 100644
--- a/tests/pinocchio/Makefile.am
+++ b/tests/pinocchio/Makefile.am
@@ -8,12 +8,13 @@ TESTS = \
 noinst_PROGRAMS = $(TESTS)
 
 test_do_nothing_SOURCES = do-nothing.cpp
-test_do_nothing_LDADD = $(TP_QT4_LIBS)
+test_do_nothing_LDADD = $(TP_QT4_LIBS) $(QTTEST_LIBS)
 
 AM_CXXFLAGS = \
     $(ERROR_CXXFLAGS) \
     $(QTCORE_CFLAGS) \
     $(QTDBUS_CFLAGS) \
+    $(QTTEST_CFLAGS) \
     $(TP_QT4_CFLAGS)
 
 TESTS_ENV = \
-- 
1.5.6.5




More information about the Telepathy-commits mailing list