Prospective fix for flaky test tst_QDoubleSpinBox::setReadOnly()

The test has been observed to fail with:

 FAIL!  : tst_QDoubleSpinBox::setReadOnly() 'QTest::qWaitForWindowActive(&spin)' returned FALSE. ()
 /Users/qt/work/qt/qtbase/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp(863) : failure location

Remove the widget member and use a widget instantiated on the stack instead.
Add a check for top level widget leaks in cleanup() and fix leaking task224497_fltMax()
by instantiating the widget  on the stack.

Pick-to: 6.1
Change-Id: Idbbb5d859c0df2d9b9f49fb9f69ef6bb7d1ee150
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Friedemann Kleint 2021-03-02 20:11:59 +01:00
parent b1ad7f938e
commit 4b15a8ea8f
1 changed files with 23 additions and 35 deletions

View File

@ -134,8 +134,8 @@ public:
virtual ~tst_QDoubleSpinBox();
public slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
private slots:
void germanTest();
@ -213,7 +213,6 @@ public slots:
private:
QStringList actualTexts;
QList<double> actualValues;
QWidget *testFocusWidget;
};
typedef QList<double> DoubleList;
@ -257,20 +256,8 @@ tst_QDoubleSpinBox::~tst_QDoubleSpinBox()
void tst_QDoubleSpinBox::initTestCase()
{
testFocusWidget = new QWidget(0);
testFocusWidget->resize(200, 100);
testFocusWidget->show();
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
QSKIP("Wayland: This fails. Figure out why.");
QVERIFY(QTest::qWaitForWindowActive(testFocusWidget));
}
void tst_QDoubleSpinBox::cleanupTestCase()
{
delete testFocusWidget;
testFocusWidget = 0;
}
void tst_QDoubleSpinBox::init()
@ -278,6 +265,11 @@ void tst_QDoubleSpinBox::init()
QLocale::setDefault(QLocale(QLocale::C));
}
void tst_QDoubleSpinBox::cleanup()
{
QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty());
}
void tst_QDoubleSpinBox::setValue_data()
{
QTest::addColumn<double>("val");
@ -878,15 +870,16 @@ void tst_QDoubleSpinBox::setReadOnly()
void tst_QDoubleSpinBox::editingFinished()
{
QVBoxLayout *layout = new QVBoxLayout(testFocusWidget);
QDoubleSpinBox *box = new QDoubleSpinBox(testFocusWidget);
QWidget testFocusWidget(nullptr);
QVBoxLayout *layout = new QVBoxLayout(&testFocusWidget);
QDoubleSpinBox *box = new QDoubleSpinBox(&testFocusWidget);
layout->addWidget(box);
QDoubleSpinBox *box2 = new QDoubleSpinBox(testFocusWidget);
QDoubleSpinBox *box2 = new QDoubleSpinBox(&testFocusWidget);
layout->addWidget(box2);
testFocusWidget->show();
testFocusWidget->activateWindow();
QVERIFY(QTest::qWaitForWindowActive(testFocusWidget));
testFocusWidget.show();
testFocusWidget.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&testFocusWidget));
box->setFocus();
QTRY_VERIFY(box->hasFocus());
@ -925,14 +918,9 @@ void tst_QDoubleSpinBox::editingFinished()
QTest::keyClick(box2, Qt::Key_Return);
QCOMPARE(editingFinishedSpy1.count(), 4);
QCOMPARE(editingFinishedSpy2.count(), 3);
testFocusWidget->hide();
testFocusWidget.hide();
QCOMPARE(editingFinishedSpy1.count(), 4);
QCOMPARE(editingFinishedSpy2.count(), 4);
// On some platforms this is our root window
// we need to show it again otherwise subsequent
// tests will fail
testFocusWidget->show();
}
void tst_QDoubleSpinBox::removeAll()
@ -1111,15 +1099,15 @@ public:
void tst_QDoubleSpinBox::task224497_fltMax()
{
task224497_fltMax_DoubleSpinBox *dspin = new task224497_fltMax_DoubleSpinBox;
dspin->setMinimum(3);
dspin->setMaximum(FLT_MAX);
dspin->show();
QVERIFY(QTest::qWaitForWindowActive(dspin));
dspin->lineEdit()->selectAll();
QTest::keyClick(dspin->lineEdit(), Qt::Key_Delete);
QTest::keyClick(dspin->lineEdit(), Qt::Key_1);
QCOMPARE(dspin->cleanText(), QLatin1String("1"));
task224497_fltMax_DoubleSpinBox dspin;
dspin.setMinimum(3);
dspin.setMaximum(FLT_MAX);
dspin.show();
QVERIFY(QTest::qWaitForWindowActive(&dspin));
dspin.lineEdit()->selectAll();
QTest::keyClick(dspin.lineEdit(), Qt::Key_Delete);
QTest::keyClick(dspin.lineEdit(), Qt::Key_1);
QCOMPARE(dspin.cleanText(), QLatin1String("1"));
}
void tst_QDoubleSpinBox::task221221()