Make setReadOnly track ReadOnlyChange events only

The test was previously tracking all Change events,
which made it fragile.

Change-Id: I17872341237009a9a0a2ad2fd5482f917991d7b2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Morten Johan Sørvig 2020-01-06 13:23:42 +01:00
parent 89c4bb5f24
commit 5507d0f1b0

View File

@ -500,26 +500,27 @@ void tst_QSpinBox::valueChangedHelper(int value)
actualValues << value;
}
class MySpinBox: public QSpinBox
class ReadOnlyChangeTracker: public QSpinBox
{
public:
MySpinBox(QWidget *parent = 0) : QSpinBox(parent) {}
ReadOnlyChangeTracker(QWidget *parent = 0) : QSpinBox(parent) {}
void changeEvent(QEvent *ev) {
eventsReceived.append(ev->type());
if (ev->type() == QEvent::ReadOnlyChange)
++readOnlyChangeEventCount;
}
QList<QEvent::Type> eventsReceived;
int readOnlyChangeEventCount = 0;
};
void tst_QSpinBox::setReadOnly()
{
MySpinBox spin(0);
ReadOnlyChangeTracker spin(0);
spin.show();
QTest::keyClick(&spin, Qt::Key_Up);
QCOMPARE(spin.value(), 1);
spin.setReadOnly(true);
#ifndef Q_OS_WINRT // QTBUG-68297
QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange);
QCOMPARE(spin.readOnlyChangeEventCount, 1);
#endif
QTest::keyClick(&spin, Qt::Key_Up);
QCOMPARE(spin.value(), 1);
@ -527,7 +528,7 @@ void tst_QSpinBox::setReadOnly()
QCOMPARE(spin.value(), 2);
spin.setReadOnly(false);
#ifndef Q_OS_WINRT // QTBUG-68297
QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange << QEvent::ReadOnlyChange);
QCOMPARE(spin.readOnlyChangeEventCount, 2);
#endif
QTest::keyClick(&spin, Qt::Key_Up);
QCOMPARE(spin.value(), 3);