diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-10-23 17:25:56 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-10-28 09:06:34 (GMT) |
commit | feca69fb15a4176689e4f58252361750f3444275 (patch) | |
tree | 67ec8964b90e330bba3229c627b1165be72f069a /tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp | |
parent | c180071b66d4e5c22248c488df57c6acd6aa36ed (diff) | |
download | Qt-feca69fb15a4176689e4f58252361750f3444275.zip Qt-feca69fb15a4176689e4f58252361750f3444275.tar.gz Qt-feca69fb15a4176689e4f58252361750f3444275.tar.bz2 |
Autotest: add a test that tries to follow a service changing owners.
I'm not sure if this used to work before...
Diffstat (limited to 'tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp')
-rw-r--r-- | tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index baf769f..d84350b 100644 --- a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -103,6 +103,8 @@ private slots: void getComplexSignal_data(); void getComplexSignal(); + void followSignal(); + void createErrors_data(); void createErrors(); @@ -432,6 +434,60 @@ void tst_QDBusAbstractInterface::getComplexSignal() QCOMPARE(s[0][0].value<RegisteredType>(), expectedValue); } +void tst_QDBusAbstractInterface::followSignal() +{ + const QString serviceToFollow = "com.trolltech.tst_qdbusabstractinterface.FollowMe"; + Pinger p = getPinger(serviceToFollow); + QVERIFY2(p, "Not connected to D-Bus"); + + QDBusConnection con = p->connection(); + QVERIFY(!con.interface()->isServiceRegistered(serviceToFollow)); + Pinger control = getPinger(""); + + // we need to connect the signal somewhere in order for D-Bus to enable the rules + QTestEventLoop::instance().connect(p.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); + QTestEventLoop::instance().connect(control.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); + QSignalSpy s(p.data(), SIGNAL(voidSignal())); + + emit targetObj.voidSignal(); + QTestEventLoop::instance().enterLoop(200); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // signal must not have been received because the service isn't registered + QVERIFY(s.isEmpty()); + + // now register the service + QDBusReply<QDBusConnectionInterface::RegisterServiceReply> r = + con.interface()->registerService(serviceToFollow, QDBusConnectionInterface::DontQueueService, + QDBusConnectionInterface::DontAllowReplacement); + QVERIFY(r.isValid() && r.value() == QDBusConnectionInterface::ServiceRegistered); + QVERIFY(con.interface()->isServiceRegistered(serviceToFollow)); + + // emit the signal again: + emit targetObj.voidSignal(); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // now the signal must have been received: + QVERIFY(s.size() == 1); + QVERIFY(s.at(0).size() == 0); + s.clear(); + + // disconnect the signal + disconnect(p.data(), SIGNAL(voidSignal()), &QTestEventLoop::instance(), 0); + + // emit the signal again: + emit targetObj.voidSignal(); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // and now it mustn't have been received + QVERIFY(s.isEmpty()); + + // cleanup: + con.interface()->unregisterService(serviceToFollow); +} + void tst_QDBusAbstractInterface::createErrors_data() { QTest::addColumn<QString>("service"); |