QTimer: extend property tests and fix binding loop
The bindable property tests were not using the QTestPrivate helpers, so add a new test which uses them. The new tests revealed a binding loop for the interval property. Fix it in a usual way by explicitly removing the binding and using {set}ValueBypassingBindings() in the setter. Task-number: QTBUG-116346 Change-Id: If94f57938da449a68e3527aead5ebd55ba410adb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> (cherry picked from commit 7d70edd31cb4c55471ad96e3a1d7114e2c081cf6)
This commit is contained in:
parent
4f55529d4a
commit
4c9e36ffcd
@ -622,8 +622,9 @@ QBindable<bool> QTimer::bindableSingleShot()
|
||||
void QTimer::setInterval(int msec)
|
||||
{
|
||||
Q_D(QTimer);
|
||||
const bool intervalChanged = msec != d->inter;
|
||||
d->inter.setValue(msec);
|
||||
d->inter.removeBindingUnlessInWrapper();
|
||||
const bool intervalChanged = msec != d->inter.valueBypassingBindings();
|
||||
d->inter.setValueBypassingBindings(msec);
|
||||
if (d->id != QTimerPrivate::INV_TIMER) { // create new timer
|
||||
QObject::killTimer(d->id); // restart timer
|
||||
d->id = QObject::startTimer(std::chrono::milliseconds{msec}, d->type);
|
||||
|
@ -14,6 +14,7 @@ qt_internal_add_test(tst_qtimer
|
||||
tst_qtimer.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
||||
## Scopes:
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||
|
||||
#include <qtimer.h>
|
||||
#include <qthread.h>
|
||||
@ -75,6 +76,7 @@ private slots:
|
||||
|
||||
void bindToTimer();
|
||||
void bindTimer();
|
||||
void automatedBindingTests();
|
||||
};
|
||||
|
||||
void tst_QTimer::zeroTimer()
|
||||
@ -1312,6 +1314,42 @@ void tst_QTimer::bindTimer()
|
||||
QCOMPARE(timer.timerType(), Qt::VeryCoarseTimer);
|
||||
}
|
||||
|
||||
void tst_QTimer::automatedBindingTests()
|
||||
{
|
||||
QTimer timer;
|
||||
|
||||
QVERIFY(!timer.isSingleShot());
|
||||
QTestPrivate::testReadWritePropertyBasics(timer, true, false, "singleShot");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::singleShot");
|
||||
return;
|
||||
}
|
||||
|
||||
QCOMPARE_NE(timer.interval(), 10);
|
||||
QTestPrivate::testReadWritePropertyBasics(timer, 10, 20, "interval");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::interval");
|
||||
return;
|
||||
}
|
||||
|
||||
QCOMPARE_NE(timer.timerType(), Qt::PreciseTimer);
|
||||
QTestPrivate::testReadWritePropertyBasics(timer, Qt::PreciseTimer, Qt::CoarseTimer,
|
||||
"timerType");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::timerType");
|
||||
return;
|
||||
}
|
||||
|
||||
timer.start(1000);
|
||||
QVERIFY(timer.isActive());
|
||||
QTestPrivate::testReadOnlyPropertyBasics(timer, true, false, "active",
|
||||
[&timer]() { timer.stop(); });
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::active");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
class OrderHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -11,4 +11,5 @@ qt_internal_add_test(tst_qguitimer
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user