summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2022-12-30 10:15:51 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-01-06 07:51:25 +0000
commitb2113f30e03126596df94bd7825bf5a4cb73dcd9 (patch)
treec319cc1f610a1bb1bf8bc5a83764b07005f593eb /tests
parentf54f2d589750999dfb37e59a20c826b81bdbdd54 (diff)
Stabilize tst_QSpinBox::sizeHint()
The test function used to flake on Linux occasionally. 8e6ede7cd131682161180bfab0cc46686674709b provided a fix. While it seemed to work, further analysis has shown that the root cause is event sequence in case of multiple paint events. This patch re-engineers the test function: 1. Allocate test widget on the stack instead of the heap. 2. Send layout requests posted by QHBoxLayout constructor and QLayout::addWidget() before showing the widget. 3. Remove calls to QCoreApplication::processEvents(). They are unnessecary, because - the size hint request counter is supposed to increase (by any number) - QTRY_VERIFY processes events anyway until the counter increases or it times out. Change-Id: I54998483725cbdd4899ba6f5469d7dae0980ab1d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 71e67dec957d41d55ae03f32613a80394c928352) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp
index 583cce9f7a..9883de6190 100644
--- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp
+++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp
@@ -1149,34 +1149,32 @@ public:
void tst_QSpinBox::sizeHint()
{
- QWidget *widget = new QWidget;
- QHBoxLayout *layout = new QHBoxLayout(widget);
- widget->setLayout(layout);
+ QWidget widget;
+ QHBoxLayout *layout = new QHBoxLayout(&widget);
+
sizeHint_SpinBox *spinBox = new sizeHint_SpinBox;
layout->addWidget(spinBox);
- widget->show();
- QVERIFY(QTest::qWaitForWindowExposed(widget));
+ // Make sure all layout requests posted by the QHBoxLayout constructor and addWidget
+ // are processed before the widget is shown
+ QCoreApplication::sendPostedEvents(&widget, QEvent::LayoutRequest);
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
// Prefix
spinBox->sizeHintRequests = 0;
spinBox->setPrefix(QLatin1String("abcdefghij"));
- qApp->processEvents();
QTRY_VERIFY(spinBox->sizeHintRequests > 0);
// Suffix
spinBox->sizeHintRequests = 0;
spinBox->setSuffix(QLatin1String("abcdefghij"));
- qApp->processEvents();
QTRY_VERIFY(spinBox->sizeHintRequests > 0);
// Range
spinBox->sizeHintRequests = 0;
spinBox->setRange(0, 1234567890);
spinBox->setValue(spinBox->maximum());
- qApp->processEvents();
QTRY_VERIFY(spinBox->sizeHintRequests > 0);
-
- delete widget;
}
void tst_QSpinBox::taskQTBUG_5008_textFromValueAndValidate()