tests/auto/dbus: Avoid unconditional qWait()s
Use QTRY_COMPARE instead of a wait followed by QCOMPARE. Unless the condition doesn't change and the wait provides the opportunity for things to go wrong. Task-number: QTBUG-63992 Change-Id: I13474a45f1f4df9d77a418729a5748235ae0dd1a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
parent
375dd7ad34
commit
350a64196f
@ -768,9 +768,8 @@ void tst_QDBusAbstractAdaptor::scriptableSignalOrNot()
|
|||||||
con.connect(con.baseService(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
con.connect(con.baseService(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
||||||
obj.emitSignal("scriptableSignalVoid", QVariant());
|
obj.emitSignal("scriptableSignalVoid", QVariant());
|
||||||
obj.emitSignal("nonScriptableSignalVoid", QVariant());
|
obj.emitSignal("nonScriptableSignalVoid", QVariant());
|
||||||
QTest::qWait(200);
|
|
||||||
|
|
||||||
QCOMPARE(spy.count, 1); // only /p1 must have emitted
|
QTRY_COMPARE(spy.count, 1); // only /p1 must have emitted
|
||||||
QCOMPARE(spy.interface, QString("local.MyObject"));
|
QCOMPARE(spy.interface, QString("local.MyObject"));
|
||||||
QCOMPARE(spy.name, QString("scriptableSignalVoid"));
|
QCOMPARE(spy.name, QString("scriptableSignalVoid"));
|
||||||
QCOMPARE(spy.path, QString("/p1"));
|
QCOMPARE(spy.path, QString("/p1"));
|
||||||
@ -788,9 +787,8 @@ void tst_QDBusAbstractAdaptor::scriptableSignalOrNot()
|
|||||||
con.connect(con.baseService(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
con.connect(con.baseService(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
||||||
con.connect(con.baseService(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
con.connect(con.baseService(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
||||||
obj.emitSignal("nonScriptableSignalVoid", QVariant());
|
obj.emitSignal("nonScriptableSignalVoid", QVariant());
|
||||||
QTest::qWait(200);
|
|
||||||
|
|
||||||
QCOMPARE(spy.count, 1); // only /p2 must have emitted now
|
QTRY_COMPARE(spy.count, 1); // only /p2 must have emitted now
|
||||||
QCOMPARE(spy.interface, QString("local.MyObject"));
|
QCOMPARE(spy.interface, QString("local.MyObject"));
|
||||||
QCOMPARE(spy.name, QString("nonScriptableSignalVoid"));
|
QCOMPARE(spy.name, QString("nonScriptableSignalVoid"));
|
||||||
QCOMPARE(spy.path, QString("/p2"));
|
QCOMPARE(spy.path, QString("/p2"));
|
||||||
@ -1306,9 +1304,8 @@ void tst_QDBusAbstractAdaptor::scriptableSignalOrNotPeer()
|
|||||||
con.connect(QString(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
con.connect(QString(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
||||||
emitSignalPeer("local.MyObject", "scriptableSignalVoid", QVariant());
|
emitSignalPeer("local.MyObject", "scriptableSignalVoid", QVariant());
|
||||||
emitSignalPeer("local.MyObject", "nonScriptableSignalVoid", QVariant());
|
emitSignalPeer("local.MyObject", "nonScriptableSignalVoid", QVariant());
|
||||||
QTest::qWait(200);
|
|
||||||
|
|
||||||
QCOMPARE(spy.count, 1); // only /p1 must have emitted
|
QTRY_COMPARE(spy.count, 1); // only /p1 must have emitted
|
||||||
QCOMPARE(spy.interface, QString("local.MyObject"));
|
QCOMPARE(spy.interface, QString("local.MyObject"));
|
||||||
QCOMPARE(spy.name, QString("scriptableSignalVoid"));
|
QCOMPARE(spy.name, QString("scriptableSignalVoid"));
|
||||||
QCOMPARE(spy.path, QString("/p1"));
|
QCOMPARE(spy.path, QString("/p1"));
|
||||||
@ -1327,9 +1324,8 @@ void tst_QDBusAbstractAdaptor::scriptableSignalOrNotPeer()
|
|||||||
con.connect(QString(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
con.connect(QString(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
||||||
con.connect(QString(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
con.connect(QString(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
|
||||||
emitSignalPeer("local.MyObject", "nonScriptableSignalVoid", QVariant());
|
emitSignalPeer("local.MyObject", "nonScriptableSignalVoid", QVariant());
|
||||||
QTest::qWait(200);
|
|
||||||
|
|
||||||
QCOMPARE(spy.count, 1); // only /p2 must have emitted now
|
QTRY_COMPARE(spy.count, 1); // only /p2 must have emitted now
|
||||||
QCOMPARE(spy.interface, QString("local.MyObject"));
|
QCOMPARE(spy.interface, QString("local.MyObject"));
|
||||||
QCOMPARE(spy.name, QString("nonScriptableSignalVoid"));
|
QCOMPARE(spy.name, QString("nonScriptableSignalVoid"));
|
||||||
QCOMPARE(spy.path, QString("/p2"));
|
QCOMPARE(spy.path, QString("/p2"));
|
||||||
|
@ -136,9 +136,7 @@ void tst_QDBusConnection::sendSignalToName()
|
|||||||
|
|
||||||
QVERIFY(con.send(msg));
|
QVERIFY(con.send(msg));
|
||||||
|
|
||||||
QTest::qWait(1000);
|
QTRY_COMPARE(spy.args.count(), 1);
|
||||||
|
|
||||||
QCOMPARE(spy.args.count(), 1);
|
|
||||||
QCOMPARE(spy.args.at(0).toString(), QString("ping"));
|
QCOMPARE(spy.args.at(0).toString(), QString("ping"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,8 +213,7 @@ void tst_QDBusConnection::sendAsync()
|
|||||||
"/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames");
|
"/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames");
|
||||||
QVERIFY(con.callWithCallback(msg, &spy, SLOT(asyncReply(QDBusMessage))));
|
QVERIFY(con.callWithCallback(msg, &spy, SLOT(asyncReply(QDBusMessage))));
|
||||||
|
|
||||||
QTest::qWait(1000);
|
QTRY_COMPARE(spy.args.count(), 1);
|
||||||
|
|
||||||
QCOMPARE(spy.args.value(0).typeName(), "QStringList");
|
QCOMPARE(spy.args.value(0).typeName(), "QStringList");
|
||||||
QVERIFY(spy.args.at(0).toStringList().contains(con.baseService()));
|
QVERIFY(spy.args.at(0).toStringList().contains(con.baseService()));
|
||||||
}
|
}
|
||||||
@ -239,9 +236,7 @@ void tst_QDBusConnection::connect()
|
|||||||
|
|
||||||
QVERIFY(con.send(msg));
|
QVERIFY(con.send(msg));
|
||||||
|
|
||||||
QTest::qWait(1000);
|
QTRY_COMPARE(spy.args.count(), 1);
|
||||||
|
|
||||||
QCOMPARE(spy.args.count(), 1);
|
|
||||||
QCOMPARE(spy.args.at(0).toString(), QString("ping"));
|
QCOMPARE(spy.args.at(0).toString(), QString("ping"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,9 +1067,8 @@ void tst_QDBusConnection::connectSignal()
|
|||||||
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), &recv, SLOT(oneSlot(QString))));
|
signal.member(), &recv, SLOT(oneSlot(QString))));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
||||||
QCOMPARE(recv.signalsReceived, 1);
|
|
||||||
|
|
||||||
// disconnect and try with a signature
|
// disconnect and try with a signature
|
||||||
recv.argumentReceived.clear();
|
recv.argumentReceived.clear();
|
||||||
@ -1084,9 +1078,8 @@ void tst_QDBusConnection::connectSignal()
|
|||||||
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), "s", &recv, SLOT(oneSlot(QString))));
|
signal.member(), "s", &recv, SLOT(oneSlot(QString))));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
||||||
QCOMPARE(recv.signalsReceived, 1);
|
|
||||||
|
|
||||||
// confirm that we are, indeed, a unique connection
|
// confirm that we are, indeed, a unique connection
|
||||||
recv.argumentReceived.clear();
|
recv.argumentReceived.clear();
|
||||||
@ -1094,9 +1087,8 @@ void tst_QDBusConnection::connectSignal()
|
|||||||
QVERIFY(!con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(!con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), "s", &recv, SLOT(oneSlot(QString))));
|
signal.member(), "s", &recv, SLOT(oneSlot(QString))));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
||||||
QCOMPARE(recv.signalsReceived, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QDBusConnection::slotsWithLessParameters()
|
void tst_QDBusConnection::slotsWithLessParameters()
|
||||||
@ -1114,9 +1106,8 @@ void tst_QDBusConnection::slotsWithLessParameters()
|
|||||||
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), &recv, SLOT(oneSlot())));
|
signal.member(), &recv, SLOT(oneSlot())));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE(recv.argumentReceived, QString());
|
QCOMPARE(recv.argumentReceived, QString());
|
||||||
QCOMPARE(recv.signalsReceived, 1);
|
|
||||||
|
|
||||||
// disconnect and try with a signature
|
// disconnect and try with a signature
|
||||||
recv.signalsReceived = 0;
|
recv.signalsReceived = 0;
|
||||||
@ -1125,18 +1116,16 @@ void tst_QDBusConnection::slotsWithLessParameters()
|
|||||||
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), "s", &recv, SLOT(oneSlot())));
|
signal.member(), "s", &recv, SLOT(oneSlot())));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE(recv.argumentReceived, QString());
|
QCOMPARE(recv.argumentReceived, QString());
|
||||||
QCOMPARE(recv.signalsReceived, 1);
|
|
||||||
|
|
||||||
// confirm that we are, indeed, a unique connection
|
// confirm that we are, indeed, a unique connection
|
||||||
recv.signalsReceived = 0;
|
recv.signalsReceived = 0;
|
||||||
QVERIFY(!con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(!con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), "s", &recv, SLOT(oneSlot())));
|
signal.member(), "s", &recv, SLOT(oneSlot())));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE(recv.argumentReceived, QString());
|
QCOMPARE(recv.argumentReceived, QString());
|
||||||
QCOMPARE(recv.signalsReceived, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalReceiver::secondCallWithCallback()
|
void SignalReceiver::secondCallWithCallback()
|
||||||
|
@ -414,8 +414,7 @@ void tst_QDBusThreading::registerObjectInOtherThread()
|
|||||||
QCOMPARE(functionSpy, Object_method);
|
QCOMPARE(functionSpy, Object_method);
|
||||||
QCOMPARE(threadSpy, th);
|
QCOMPARE(threadSpy, th);
|
||||||
|
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(signalSpy, 1);
|
||||||
QCOMPARE(signalSpy, 1);
|
|
||||||
|
|
||||||
sem2.acquire(); // the object is gone
|
sem2.acquire(); // the object is gone
|
||||||
functionSpy = NoMethod;
|
functionSpy = NoMethod;
|
||||||
@ -462,8 +461,7 @@ void tst_QDBusThreading::registerAdaptorInOtherThread()
|
|||||||
QCOMPARE(functionSpy, Adaptor_method);
|
QCOMPARE(functionSpy, Adaptor_method);
|
||||||
QCOMPARE(threadSpy, th);
|
QCOMPARE(threadSpy, th);
|
||||||
|
|
||||||
QTest::qWait(100);
|
QTRY_COMPARE(signalSpy, 1);
|
||||||
QCOMPARE(signalSpy, 1);
|
|
||||||
|
|
||||||
functionSpy = NoMethod;
|
functionSpy = NoMethod;
|
||||||
threadSpy = 0;
|
threadSpy = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user