summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-01-20 15:25:17 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-01-20 22:57:45 +0100
commit177c370a7262a56f408d7343822ca119c9650cd9 (patch)
tree35fb3b1650f9613fe2a2c18d9eb658c8c7c3df13 /tests/auto
parentd86a02b468666116ca758a5e1f112a1616a5ff07 (diff)
Improve QAbstractButton::animateClick test
The test is timing sensitive; if it takes more than 100ms to process events, then the timer that clicks the button might have fired. So only verify that the button is still down if 100ms have not yet passed, and verify that at least 100ms have passed when the click is complete. Also use QSignalSpy to test the signal emissions. Pick-to: 6.2 6.3 Change-Id: I95f99e204a17c6709f8e2913eefe4b487e949123 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp b/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
index 878647f4a4..c13e6a5420 100644
--- a/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
+++ b/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
@@ -514,11 +514,34 @@ void tst_QAbstractButton::setShortcut()
void tst_QAbstractButton::animateClick()
{
- testWidget->animateClick();
- QVERIFY( testWidget->isDown() );
- qApp->processEvents();
- QVERIFY( testWidget->isDown() );
- QTRY_VERIFY( !testWidget->isDown() );
+ MyButton button;
+ QSignalSpy pressedSpy(&button, &QAbstractButton::pressed);
+ QSignalSpy releasedSpy(&button, &QAbstractButton::released);
+ QSignalSpy clickedSpy(&button, &QAbstractButton::clicked);
+
+ QElapsedTimer elapsed;
+ elapsed.start();
+ button.animateClick();
+
+ QVERIFY(button.isDown());
+ QCOMPARE(pressedSpy.count(), 1);
+ QCOMPARE(releasedSpy.count(), 0);
+ QCOMPARE(clickedSpy.count(), 0);
+ qApp->processEvents(QEventLoop::AllEvents, 10);
+ // QAbstractButton starts a 100ms timer which performs the click. If it
+ // took more than 100ms to get here, then the button might no longer be down.
+ if (elapsed.elapsed() < 100) {
+ QVERIFY(button.isDown());
+ QCOMPARE(pressedSpy.count(), 1);
+ QCOMPARE(releasedSpy.count(), 0);
+ QCOMPARE(clickedSpy.count(), 0);
+ }
+ QTRY_VERIFY(!button.isDown());
+ // but once the button has been clicked, it must have taken at least 100ms
+ QVERIFY(elapsed.elapsed() >= 100);
+ QCOMPARE(pressedSpy.count(), 1);
+ QCOMPARE(releasedSpy.count(), 1);
+ QCOMPARE(clickedSpy.count(), 1);
}
#if QT_CONFIG(shortcut)