diff -r 56cd8111b7f7 -r 41300fa6a67c tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp --- a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp Tue Jan 26 12:42:25 2010 +0200 +++ b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp Tue Feb 02 00:43:10 2010 +0200 @@ -103,6 +103,8 @@ void getComplexSignal_data(); void getComplexSignal(); + void followSignal(); + void createErrors_data(); void createErrors(); @@ -130,6 +132,9 @@ void tst_QDBusAbstractInterface::initTestCase() { + // enable debugging temporarily: + //putenv("QDBUS_DEBUG=1"); + // register the object QDBusConnection con = QDBusConnection::sessionBus(); QVERIFY(con.isConnected()); @@ -432,6 +437,61 @@ QCOMPARE(s[0][0].value(), 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 r = + con.interface()->registerService(serviceToFollow, QDBusConnectionInterface::DontQueueService, + QDBusConnectionInterface::DontAllowReplacement); + QVERIFY(r.isValid() && r.value() == QDBusConnectionInterface::ServiceRegistered); + QVERIFY(con.interface()->isServiceRegistered(serviceToFollow)); + QCoreApplication::instance()->processEvents(); + + // emit the signal again: + emit targetObj.voidSignal(); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // now the signal must have been received: + QCOMPARE(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("service");