diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2020-12-10 18:46:31 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-26 21:47:50 +0100 |
commit | 709a0942aa5adeea8057a92a301dee85fc575528 (patch) | |
tree | 8b76cb93284c6f4bb479f001244ec27c37217e81 /tests | |
parent | 519420641fabeeb7a372ed6157a7bc01f43b1b3b (diff) |
QTimer: port to new property system
Task-number: QTBUG-85520
Change-Id: I1f92b86619f2ca186c505251b21463f396af0ac6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 586ffc85ed..cd0a0d03d9 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -89,6 +89,9 @@ private slots: void dontBlockEvents(); void postedEventsShouldNotStarveTimers(); void callOnTimeout(); + + void bindToTimer(); + void bindTimer(); }; void tst_QTimer::zeroTimer() @@ -1083,6 +1086,91 @@ void tst_QTimer::callOnTimeout() QVERIFY(!connection); } +void tst_QTimer::bindToTimer() +{ + QTimer timer; + + // singleShot property + QProperty<bool> singleShot; + singleShot.setBinding(timer.bindableSingleShot().makeBinding()); + QCOMPARE(timer.isSingleShot(), singleShot); + + timer.setSingleShot(true); + QVERIFY(singleShot); + timer.setSingleShot(false); + QVERIFY(!singleShot); + + // interval property + QProperty<int> interval; + interval.setBinding([&](){ return timer.interval(); }); + QCOMPARE(timer.interval(), interval); + + timer.setInterval(10); + QCOMPARE(interval, 10); + timer.setInterval(100); + QCOMPARE(interval, 100); + + // timerType property + QProperty<Qt::TimerType> timerType; + timerType.setBinding(timer.bindableTimerType().makeBinding()); + QCOMPARE(timer.timerType(), timerType); + + timer.setTimerType(Qt::PreciseTimer); + QCOMPARE(timerType, Qt::PreciseTimer); + + timer.setTimerType(Qt::VeryCoarseTimer); + QCOMPARE(timerType, Qt::VeryCoarseTimer); + + // active property + QProperty<bool> active; + active.setBinding([&](){ return timer.isActive(); }); + QCOMPARE(active, timer.isActive()); + + timer.start(1000); + QVERIFY(active); + + timer.stop(); + QVERIFY(!active); +} + +void tst_QTimer::bindTimer() +{ + QTimer timer; + + // singleShot property + QVERIFY(!timer.isSingleShot()); + + QProperty<bool> singleShot; + timer.bindableSingleShot().setBinding(Qt::makePropertyBinding(singleShot)); + + singleShot = true; + QVERIFY(timer.isSingleShot()); + singleShot = false; + QVERIFY(!timer.isSingleShot()); + + // interval property + QCOMPARE(timer.interval(), 0); + + QProperty<int> interval; + timer.bindableInterval().setBinding(Qt::makePropertyBinding(interval)); + + interval = 10; + QCOMPARE(timer.interval(), 10); + interval = 100; + QCOMPARE(timer.interval(), 100); + + // timerType property + QCOMPARE(timer.timerType(), Qt::CoarseTimer); + + QProperty<Qt::TimerType> timerType; + timer.bindableTimerType().setBinding(Qt::makePropertyBinding(timerType)); + + timerType = Qt::PreciseTimer; + QCOMPARE(timer.timerType(), Qt::PreciseTimer); + timerType = Qt::VeryCoarseTimer; + QCOMPARE(timer.timerType(), Qt::VeryCoarseTimer); +} + class OrderHelper : public QObject { Q_OBJECT |