summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2023-08-25 18:05:36 +0200
committerIvan Solovev <ivan.solovev@qt.io>2023-09-03 18:20:51 +0200
commit7d70edd31cb4c55471ad96e3a1d7114e2c081cf6 (patch)
treefd3a126a2866e7bb1a023c6595c8dcc785ab32b6
parentcdb50edc9862679e8795a8404ce49fb26534f4bc (diff)
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 Pick-to: 6.6 6.5 Change-Id: If94f57938da449a68e3527aead5ebd55ba410adb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
-rw-r--r--src/corelib/kernel/qtimer.cpp5
-rw-r--r--tests/auto/corelib/kernel/qtimer/CMakeLists.txt2
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp38
-rw-r--r--tests/auto/gui/kernel/qguitimer/CMakeLists.txt2
4 files changed, 45 insertions, 2 deletions
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index 6c13215ac5..c591b0ecec 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -630,8 +630,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);
diff --git a/tests/auto/corelib/kernel/qtimer/CMakeLists.txt b/tests/auto/corelib/kernel/qtimer/CMakeLists.txt
index e7ac67d12e..4959caa2ad 100644
--- a/tests/auto/corelib/kernel/qtimer/CMakeLists.txt
+++ b/tests/auto/corelib/kernel/qtimer/CMakeLists.txt
@@ -16,6 +16,7 @@ qt_internal_add_test(tst_qtimer
tst_qtimer.cpp
LIBRARIES
Qt::CorePrivate
+ Qt::TestPrivate
)
if(QT_FEATURE_glib AND UNIX)
@@ -26,5 +27,6 @@ if(QT_FEATURE_glib AND UNIX)
DISABLE_GLIB
LIBRARIES
Qt::CorePrivate
+ Qt::TestPrivate
)
endif()
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index dcce526a35..4ece1dc2b4 100644
--- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
+++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
@@ -12,6 +12,7 @@
#include <QtCore/private/qglobal_p.h>
#include <QTest>
#include <QSignalSpy>
+#include <QtTest/private/qpropertytesthelper_p.h>
#include <qtimer.h>
#include <qthread.h>
@@ -89,6 +90,7 @@ private slots:
void bindToTimer();
void bindTimer();
+ void automatedBindingTests();
};
void tst_QTimer::zeroTimer()
@@ -1326,6 +1328,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
diff --git a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt
index c3bd8a0a59..1f27b5b919 100644
--- a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt
@@ -17,6 +17,7 @@ qt_internal_add_test(tst_qguitimer
LIBRARIES
Qt::CorePrivate
Qt::Gui
+ Qt::TestPrivate
)
if(QT_FEATURE_glib AND UNIX)
@@ -29,5 +30,6 @@ if(QT_FEATURE_glib AND UNIX)
LIBRARIES
Qt::CorePrivate
Qt::Gui
+ Qt::TestPrivate
)
endif()