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:
parent
89c4bb5f24
commit
5507d0f1b0
@ -500,26 +500,27 @@ void tst_QSpinBox::valueChangedHelper(int value)
|
|||||||
actualValues << value;
|
actualValues << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MySpinBox: public QSpinBox
|
class ReadOnlyChangeTracker: public QSpinBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MySpinBox(QWidget *parent = 0) : QSpinBox(parent) {}
|
ReadOnlyChangeTracker(QWidget *parent = 0) : QSpinBox(parent) {}
|
||||||
|
|
||||||
void changeEvent(QEvent *ev) {
|
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()
|
void tst_QSpinBox::setReadOnly()
|
||||||
{
|
{
|
||||||
MySpinBox spin(0);
|
ReadOnlyChangeTracker spin(0);
|
||||||
spin.show();
|
spin.show();
|
||||||
QTest::keyClick(&spin, Qt::Key_Up);
|
QTest::keyClick(&spin, Qt::Key_Up);
|
||||||
QCOMPARE(spin.value(), 1);
|
QCOMPARE(spin.value(), 1);
|
||||||
spin.setReadOnly(true);
|
spin.setReadOnly(true);
|
||||||
#ifndef Q_OS_WINRT // QTBUG-68297
|
#ifndef Q_OS_WINRT // QTBUG-68297
|
||||||
QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange);
|
QCOMPARE(spin.readOnlyChangeEventCount, 1);
|
||||||
#endif
|
#endif
|
||||||
QTest::keyClick(&spin, Qt::Key_Up);
|
QTest::keyClick(&spin, Qt::Key_Up);
|
||||||
QCOMPARE(spin.value(), 1);
|
QCOMPARE(spin.value(), 1);
|
||||||
@ -527,7 +528,7 @@ void tst_QSpinBox::setReadOnly()
|
|||||||
QCOMPARE(spin.value(), 2);
|
QCOMPARE(spin.value(), 2);
|
||||||
spin.setReadOnly(false);
|
spin.setReadOnly(false);
|
||||||
#ifndef Q_OS_WINRT // QTBUG-68297
|
#ifndef Q_OS_WINRT // QTBUG-68297
|
||||||
QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange << QEvent::ReadOnlyChange);
|
QCOMPARE(spin.readOnlyChangeEventCount, 2);
|
||||||
#endif
|
#endif
|
||||||
QTest::keyClick(&spin, Qt::Key_Up);
|
QTest::keyClick(&spin, Qt::Key_Up);
|
||||||
QCOMPARE(spin.value(), 3);
|
QCOMPARE(spin.value(), 3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user