[Telepathy-commits] [telepathy-qt4/master] Add some more test infrastructure (no real tests yet)

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Nov 26 08:10:37 PST 2008


---
 .gitignore                     |    2 +
 configure.ac                   |    6 +++++
 tests/Makefile.am              |    6 ++++-
 tests/README                   |   13 ++++++++++
 tests/dbus/Makefile.am         |   25 ++++++++++++++++++++
 tests/dbus/do-nothing.cpp      |   19 +++++++++++++++
 tests/pinocchio/Makefile.am    |   30 +++++++++++++++++++++++++
 tests/pinocchio/do-nothing.cpp |   48 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 148 insertions(+), 1 deletions(-)
 create mode 100644 tests/README
 create mode 100644 tests/dbus/Makefile.am
 create mode 100644 tests/dbus/do-nothing.cpp
 create mode 100644 tests/pinocchio/Makefile.am
 create mode 100644 tests/pinocchio/do-nothing.cpp

diff --git a/.gitignore b/.gitignore
index 0f35149..29eb3a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,8 @@
 /telepathy-qt4.pro*
 /telepathy-qt4-*.tar.gz
 /telepathy-qt4-*/
+/tests/dbus/test-*
+/tests/pinocchio/test-*
 Makefile
 Makefile.in
 _gen
diff --git a/configure.ac b/configure.ac
index 442ea25..bfa0d66 100644
--- a/configure.ac
+++ b/configure.ac
@@ -137,6 +137,10 @@ TP_QT4_LIBS='${top_builddir}/TelepathyQt4/libtelepathy-qt4.la'
 AC_SUBST(TP_QT4_CXXFLAGS)
 AC_SUBST(TP_QT4_LIBS)
 
+AC_PATH_PROGS([PINOCCHIO], [telepathy-pinocchio], [none],
+  [$PATH:/usr/local/libexec:/usr/libexec:/usr/lib/telepathy])
+AM_CONDITIONAL([HAVE_PINOCCHIO], [! test none = "$PINOCCHIO"])
+
 dnl Check for code generation tools
 PYTHON=
 AC_CHECK_PROGS([PYTHON], [python2.5 python])
@@ -167,5 +171,7 @@ AC_OUTPUT([
     m4/Makefile
     spec/Makefile
     tests/Makefile
+    tests/dbus/Makefile
+    tests/pinocchio/Makefile
     tools/Makefile
 ])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 30fd8e1..13d26c9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1 +1,5 @@
-# Nothing here yet
+SUBDIRS = \
+    dbus \
+    pinocchio
+
+EXTRA_DIST = README
diff --git a/tests/README b/tests/README
new file mode 100644
index 0000000..dd32492
--- /dev/null
+++ b/tests/README
@@ -0,0 +1,13 @@
+Tests should be divided up by the environment they require in order to operate
+correctly.
+
+Where to put new tests:
+
+/tests/ if they're simple regression tests in pure C++ that don't access D-Bus
+(these are likely to be rare)
+
+/tests/dbus/ if they touch the session bus (a temporary session bus will be
+used)
+
+/tests/pinocchio/ if they touch the session bus, and require
+telepathy-pinocchio to be available
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
new file mode 100644
index 0000000..c2f2ce4
--- /dev/null
+++ b/tests/dbus/Makefile.am
@@ -0,0 +1,25 @@
+# Tests each run under their own temporary dbus-daemon.
+
+TESTS = \
+    test-do-nothing
+
+noinst_PROGRAMS = $(TESTS)
+
+test_do_nothing_SOURCES = do-nothing.cpp
+test_do_nothing_LDADD = $(TP_QT4_LIBS)
+
+AM_CXXFLAGS = \
+    $(ERROR_CXXFLAGS) \
+    $(QTCORE_CFLAGS) \
+    $(QTDBUS_CFLAGS) \
+    $(TP_QT4_CXXFLAGS)
+
+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
+
+TESTS_ENVIRONMENT = \
+    $(TESTS_ENV) \
+    sh $(top_srcdir)/tools/with-session-bus.sh --session --
diff --git a/tests/dbus/do-nothing.cpp b/tests/dbus/do-nothing.cpp
new file mode 100644
index 0000000..8b93194
--- /dev/null
+++ b/tests/dbus/do-nothing.cpp
@@ -0,0 +1,19 @@
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+
+#include <QtDBus/QtDBus>
+
+extern "C" int main(int argc, char **argv)
+{
+    QCoreApplication app(argc, argv);
+
+    if (!QDBusConnection::sessionBus().isConnected()) {
+        qFatal("Session bus not available");
+        return 1;
+    }
+
+    QTimer::singleShot(0, &app, SLOT(quit()));
+
+    return app.exec();
+}
diff --git a/tests/pinocchio/Makefile.am b/tests/pinocchio/Makefile.am
new file mode 100644
index 0000000..1b85c46
--- /dev/null
+++ b/tests/pinocchio/Makefile.am
@@ -0,0 +1,30 @@
+# Tests that need telepathy-pinocchio, run under their own dbus-daemon
+
+if HAVE_PINOCCHIO
+
+TESTS = \
+    test-do-nothing
+
+noinst_PROGRAMS = $(TESTS)
+
+test_do_nothing_SOURCES = do-nothing.cpp
+test_do_nothing_LDADD = $(TP_QT4_LIBS)
+
+AM_CXXFLAGS = \
+    $(ERROR_CXXFLAGS) \
+    $(QTCORE_CFLAGS) \
+    $(QTDBUS_CFLAGS) \
+    $(TP_QT4_CXXFLAGS)
+
+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@
+
+TESTS_ENVIRONMENT = \
+    $(TESTS_ENV) \
+    sh $(top_srcdir)/tools/with-session-bus.sh --session --
+
+endif
diff --git a/tests/pinocchio/do-nothing.cpp b/tests/pinocchio/do-nothing.cpp
new file mode 100644
index 0000000..60c0554
--- /dev/null
+++ b/tests/pinocchio/do-nothing.cpp
@@ -0,0 +1,48 @@
+#include <cstdlib>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDebug>
+#include <QtCore/QProcess>
+#include <QtCore/QTimer>
+
+#include <QtDBus/QtDBus>
+
+extern "C" int main(int argc, char **argv)
+{
+    QCoreApplication app(argc, argv);
+    char *command = ::getenv("PINOCCHIO");
+
+    if (!command) {
+        qFatal("Put $PINOCCHIO in your environment");
+        return 1;
+    }
+
+    if (!QDBusConnection::sessionBus().isConnected()) {
+        qFatal("Session bus not available");
+        return 1;
+    }
+
+    QProcess pinocchio;
+
+    pinocchio.setProcessChannelMode(QProcess::ForwardedChannels);
+    pinocchio.start(command, QStringList());
+
+    if (!pinocchio.waitForStarted(5000)) {
+        qFatal("Timed out waiting for pinocchio to start");
+        return 1;
+    }
+
+    pinocchio.closeWriteChannel();
+
+    /* insert test logic here... */
+    QTimer::singleShot(0, &app, SLOT(quit()));
+    int ret = app.exec();
+
+    pinocchio.terminate();
+
+    if (!pinocchio.waitForFinished(1000)) {
+        pinocchio.kill();
+    }
+
+    return ret;
+}
-- 
1.5.6.5




More information about the Telepathy-commits mailing list