From c180071b66d4e5c22248c488df57c6acd6aa36ed Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 23 Oct 2009 19:23:51 +0200 Subject: Autotest: fix improper use of the serviceOwnerChanged signal This test was doubly wrong: it first registered a service name, then it connected to signal to watch it. You can't receive a signal if you connect to it after it's emitted... Second, it waited for any serviceOwnerChanged() signal to exit the event loop, not necessarily the one we wanted to receive. This used to work because we'd always connect to the D-Bus signal, but now we don't anymore. --- tests/auto/qdbusinterface/tst_qdbusinterface.cpp | 34 ++++++++---------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp index e31a3a0..62d6342 100644 --- a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp +++ b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp @@ -171,6 +171,13 @@ class tst_QDBusInterface: public QObject { Q_OBJECT MyObject obj; +public slots: + void testServiceOwnerChanged(const QString &service) + { + if (service == "com.example.Test") + QTestEventLoop::instance().exitLoop(); + } + private slots: void initTestCase(); @@ -235,32 +242,13 @@ void tst_QDBusInterface::invalidAfterServiceOwnerChanged() QDBusInterface invalidInterface("com.example.Test", "/"); QVERIFY(!invalidInterface.isValid()); + QTestEventLoop::instance().connect(connIface, SIGNAL(serviceOwnerChanged(QString, QString, QString)), + SLOT(exitLoop())); QVERIFY(connIface->registerService("com.example.Test") == QDBusConnectionInterface::ServiceRegistered); - QSignalSpy serviceOwnerChangedSpy(connIface, SIGNAL(serviceOwnerChanged(QString, QString, QString))); - - QEventLoop loop; - QObject::connect(connIface, SIGNAL(serviceOwnerChanged(QString, QString, QString)), - &loop, SLOT(quit())); - loop.exec(); - - // at least once, but other services might have changed while running the test, too. - QVERIFY(serviceOwnerChangedSpy.count() >= 1); - bool foundOurService = false; - for (int i = 0; i < serviceOwnerChangedSpy.count(); ++i) { - QList args = serviceOwnerChangedSpy.at(i); - QString name = args[0].toString(); - QString oldOwner = args[1].toString(); - QString newOwner = args[2].toString(); - if (name == QLatin1String("com.example.Test")) { - if (newOwner == conn.baseService()) { - foundOurService = true; - break; - } - } - } - QVERIFY(foundOurService); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(!invalidInterface.isValid()); } -- cgit v0.12