diff options
author | Martin Wolf <ext-martin.2.wolf@nokia.com> | 2010-02-08 14:39:14 +0200 |
---|---|---|
committer | Martin Wolf <ext-martin.2.wolf@nokia.com> | 2010-02-08 14:39:14 +0200 |
commit | fd22517204cd038ff47b33ccb05cc17384eb8230 (patch) | |
tree | 5ef3026f5c73ea51fd42b3db30e53b48a1727c0f /tests/test-dbus-pong | |
parent | 6751c585385f017d08540bbe121606d642afb220 (diff) |
Small refactoring, added unit tests
Diffstat (limited to 'tests/test-dbus-pong')
-rw-r--r-- | tests/test-dbus-pong/test-dbus-pong.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/tests/test-dbus-pong/test-dbus-pong.cpp b/tests/test-dbus-pong/test-dbus-pong.cpp index 701abb1..c936cc4 100644 --- a/tests/test-dbus-pong/test-dbus-pong.cpp +++ b/tests/test-dbus-pong/test-dbus-pong.cpp @@ -31,17 +31,50 @@ unsigned int Pong::timeout() int main(int argc, char **argv) { + bool useSessionBus = false; + QCoreApplication app(argc, argv); + if( app.arguments().count() > 1 ) + { + if( app.arguments().at(1) == "--session" ) + { + useSessionBus = true; + } + } + + QDBusConnection* myBus; + if( useSessionBus ) + { + myBus = new QDBusConnection(QDBusConnection::systemBus().sessionBus()); + qDebug("Using session bus ..."); + } + else + { + myBus = new QDBusConnection(QDBusConnection::systemBus().systemBus()); + qDebug("Using system bus ..."); + } // Check system bus connection - if( !QDBusConnection::systemBus().isConnected() ) + if( !myBus->isConnected() ) { - qDebug("Cannot connect to the D-Bus system bus."); + // Cleanup!! + delete myBus; + myBus = NULL; + + if( useSessionBus ) + { + qDebug("Cannot connect to the D-Bus session bus."); + } + else + { + qDebug("Cannot connect to the D-Bus system bus."); + } + return 1; } // Create listener service - if( !QDBusConnection::systemBus().registerService("com.nokia.dbusqeventloop.test") ) + if( !myBus->registerService("com.nokia.dbusqeventloop.test") ) { qDebug("%s", qPrintable(QDBusConnection::systemBus().lastError().message())); exit(2); @@ -49,10 +82,14 @@ int main(int argc, char **argv) Pong pong; // Register all slots as dbus methods - QDBusConnection::systemBus().registerObject("/", &pong, QDBusConnection::ExportAllSlots); + myBus->registerObject("/", &pong, QDBusConnection::ExportAllSlots); // Let's go! app.exec(); + // Cleanup!! + delete myBus; + myBus = NULL; + return 0; } |