From 6751c585385f017d08540bbe121606d642afb220 Mon Sep 17 00:00:00 2001 From: Martin Wolf Date: Thu, 4 Feb 2010 18:32:35 +0200 Subject: Automated tests for libdbus-qeventloop --- tests/test-dbus-pong/pong.h | 2 ++ tests/test-dbus-pong/test-dbus-pong.cpp | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'tests/test-dbus-pong') diff --git a/tests/test-dbus-pong/pong.h b/tests/test-dbus-pong/pong.h index 8656186..21f0082 100644 --- a/tests/test-dbus-pong/pong.h +++ b/tests/test-dbus-pong/pong.h @@ -8,6 +8,8 @@ class Pong: public QObject Q_OBJECT public slots: Q_SCRIPTABLE QString ping(const QString &arg); + Q_SCRIPTABLE unsigned int quit(); + Q_SCRIPTABLE unsigned int timeout(); }; #endif // _PONG_H_ diff --git a/tests/test-dbus-pong/test-dbus-pong.cpp b/tests/test-dbus-pong/test-dbus-pong.cpp index f781004..701abb1 100644 --- a/tests/test-dbus-pong/test-dbus-pong.cpp +++ b/tests/test-dbus-pong/test-dbus-pong.cpp @@ -7,35 +7,52 @@ #include "pong.h" -#define SERVICE_NAME "com.nokia.dbusqeventloop.test" - QString Pong::ping(const QString &arg) { + // Just return back + return QString("%1").arg(arg); +} + +unsigned int Pong::quit() +{ + // Quit application QMetaObject::invokeMethod(QCoreApplication::instance(), "quit"); - return QString("ping(\"%1\") got called").arg(arg); + // Magic number + return 12345; +} + +unsigned int Pong::timeout() +{ + // Timeout in testing application should be set to less than 2 seconds! + sleep(2); + // Just to suppress warning + return 54321; } int main(int argc, char **argv) { QCoreApplication app(argc, argv); + // Check system bus connection if( !QDBusConnection::systemBus().isConnected() ) { - fprintf(stderr, "Cannot connect to the D-Bus system bus.\n" - "To start it, run:\n" - "\teval `dbus-launch --auto-syntax`\n"); + qDebug("Cannot connect to the D-Bus system bus."); return 1; } - if( !QDBusConnection::systemBus().registerService(SERVICE_NAME) ) + // Create listener service + if( !QDBusConnection::systemBus().registerService("com.nokia.dbusqeventloop.test") ) { - fprintf(stderr, "%s\n", qPrintable(QDBusConnection::systemBus().lastError().message())); + qDebug("%s", qPrintable(QDBusConnection::systemBus().lastError().message())); exit(2); } Pong pong; + // Register all slots as dbus methods QDBusConnection::systemBus().registerObject("/", &pong, QDBusConnection::ExportAllSlots); + // Let's go! app.exec(); + return 0; } -- cgit v1.2.3