summaryrefslogtreecommitdiff
path: root/tests/test-dbus-pong
diff options
context:
space:
mode:
authorMartin Wolf <ext-martin.2.wolf@nokia.com>2010-02-04 18:32:35 +0200
committerMartin Wolf <ext-martin.2.wolf@nokia.com>2010-02-04 18:32:35 +0200
commit6751c585385f017d08540bbe121606d642afb220 (patch)
treeaa25c7bf41e4d26dcff1ce5d56832912b4cf473d /tests/test-dbus-pong
parent96c2304b134ae2aa1ec56825af40eae4a4fe21cf (diff)
Automated tests for libdbus-qeventloop
Diffstat (limited to 'tests/test-dbus-pong')
-rw-r--r--tests/test-dbus-pong/pong.h2
-rw-r--r--tests/test-dbus-pong/test-dbus-pong.cpp33
2 files changed, 27 insertions, 8 deletions
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;
}