diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-10-23 17:23:51 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-10-28 09:06:26 (GMT) |
commit | c180071b66d4e5c22248c488df57c6acd6aa36ed (patch) | |
tree | 7583b2dba5f26a5cd0343257c7a6cca2cf99676b | |
parent | 735525dc51952c90846c8129b755422b288b204b (diff) | |
download | Qt-c180071b66d4e5c22248c488df57c6acd6aa36ed.zip Qt-c180071b66d4e5c22248c488df57c6acd6aa36ed.tar.gz Qt-c180071b66d4e5c22248c488df57c6acd6aa36ed.tar.bz2 |
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.
-rw-r--r-- | tests/auto/qdbusinterface/tst_qdbusinterface.cpp | 34 |
1 files 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<QVariant> 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()); } |