Stop copying events in tests
It's unnecessary, and copying QEvents is a bad practice since it's a polymorphic class. Change-Id: Ieb6de106084f838c5e6c8a0643c54fd3c7f4a7a8 Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
03e03d7ceb
commit
e796857abb
|
|
@ -208,21 +208,21 @@ namespace QTest
|
|||
|
||||
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
|
||||
|
||||
QMouseEvent me(QEvent::User, QPointF(), Qt::LeftButton, QTestPrivate::qtestMouseButtons, stateKey, QPointingDevice::primaryPointingDevice());
|
||||
QEvent::Type meType;
|
||||
Qt::MouseButton meButton;
|
||||
switch (action)
|
||||
{
|
||||
case MousePress:
|
||||
me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey, QPointingDevice::primaryPointingDevice());
|
||||
me.setTimestamp(++lastMouseTimestamp);
|
||||
meType = QEvent::MouseButtonPress;
|
||||
meButton = button;
|
||||
break;
|
||||
case MouseRelease:
|
||||
me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, Qt::MouseButton(), stateKey, QPointingDevice::primaryPointingDevice());
|
||||
me.setTimestamp(++lastMouseTimestamp);
|
||||
lastMouseTimestamp += mouseDoubleClickInterval; // avoid double clicks being generated
|
||||
meType = QEvent::MouseButtonRelease;
|
||||
meButton = Qt::MouseButton();
|
||||
break;
|
||||
case MouseDClick:
|
||||
me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey, QPointingDevice::primaryPointingDevice());
|
||||
me.setTimestamp(++lastMouseTimestamp);
|
||||
meType = QEvent::MouseButtonDblClick;
|
||||
meButton = button;
|
||||
break;
|
||||
case MouseMove:
|
||||
QCursor::setPos(widget->mapToGlobal(pos));
|
||||
|
|
@ -235,6 +235,11 @@ namespace QTest
|
|||
default:
|
||||
QTEST_ASSERT(false);
|
||||
}
|
||||
QMouseEvent me(meType, pos, widget->mapToGlobal(pos), button, meButton, stateKey, QPointingDevice::primaryPointingDevice());
|
||||
me.setTimestamp(++lastMouseTimestamp);
|
||||
if (action == MouseRelease) // avoid double clicks being generated
|
||||
lastMouseTimestamp += mouseDoubleClickInterval;
|
||||
|
||||
QSpontaneKeyEvent::setSpontaneous(&me);
|
||||
if (!qApp->notify(widget, &me)) {
|
||||
static const char *const mouseActionNames[] =
|
||||
|
|
|
|||
|
|
@ -169,27 +169,17 @@ void tst_QMouseEvent::mouseEventBasic()
|
|||
QCOMPARE(me.scenePosition(), scene);
|
||||
QCOMPARE(me.globalPosition(), screen);
|
||||
// Press right button while left is already pressed
|
||||
me = QMouseEvent(QEvent::MouseButtonPress, local, scene, screen, Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier);
|
||||
QVERIFY(me.isBeginEvent());
|
||||
QVERIFY(!me.isEndEvent());
|
||||
QMouseEvent me2(QEvent::MouseButtonPress, local, scene, screen, Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier);
|
||||
QVERIFY(me2.isBeginEvent());
|
||||
QVERIFY(!me2.isEndEvent());
|
||||
// Release right button while left is still pressed
|
||||
me = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::RightButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QVERIFY(!me.isBeginEvent());
|
||||
QVERIFY(me.isEndEvent());
|
||||
QMouseEvent me3 = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::RightButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QVERIFY(!me3.isBeginEvent());
|
||||
QVERIFY(me3.isEndEvent());
|
||||
// Release left button in the usual way
|
||||
me = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
|
||||
QVERIFY(!me.isBeginEvent());
|
||||
QVERIFY(me.isEndEvent());
|
||||
// Try out the copy constructor
|
||||
QMouseEvent copy(me);
|
||||
QVERIFY(copy.isInputEvent());
|
||||
QVERIFY(copy.isPointerEvent());
|
||||
QVERIFY(copy.isSinglePointEvent());
|
||||
QVERIFY(!copy.isBeginEvent());
|
||||
QVERIFY(copy.isEndEvent());
|
||||
QCOMPARE(copy.position(), local);
|
||||
QCOMPARE(copy.scenePosition(), scene);
|
||||
QCOMPARE(copy.globalPosition(), screen);
|
||||
QMouseEvent me4 = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
|
||||
QVERIFY(!me4.isBeginEvent());
|
||||
QVERIFY(me4.isEndEvent());
|
||||
}
|
||||
|
||||
void tst_QMouseEvent::checkMousePressEvent_data()
|
||||
|
|
|
|||
|
|
@ -345,27 +345,27 @@ void tst_QTouchEvent::state()
|
|||
QVERIFY(touchEvent.isPointerEvent());
|
||||
QVERIFY(!touchEvent.isSinglePointEvent());
|
||||
|
||||
touchEvent = QTouchEvent(QEvent::TouchBegin, touchScreenDevice,
|
||||
Qt::NoModifier, QList<QEventPoint>() <<
|
||||
QEventPoint(0, QEventPoint::State::Updated, {}, {}) <<
|
||||
QEventPoint(1, QEventPoint::State::Pressed, {}, {}));
|
||||
QCOMPARE(touchEvent.touchPointStates(), QEventPoint::State::Updated | QEventPoint::State::Pressed);
|
||||
QCOMPARE(touchEvent.pointCount(), 2);
|
||||
QVERIFY(touchEvent.isBeginEvent());
|
||||
QVERIFY(!touchEvent.isUpdateEvent());
|
||||
QVERIFY(!touchEvent.isEndEvent());
|
||||
QTouchEvent touchEvent2 = QTouchEvent(QEvent::TouchBegin, touchScreenDevice,
|
||||
Qt::NoModifier, QList<QEventPoint>() <<
|
||||
QEventPoint(0, QEventPoint::State::Updated, {}, {}) <<
|
||||
QEventPoint(1, QEventPoint::State::Pressed, {}, {}));
|
||||
QCOMPARE(touchEvent2.touchPointStates(), QEventPoint::State::Updated | QEventPoint::State::Pressed);
|
||||
QCOMPARE(touchEvent2.pointCount(), 2);
|
||||
QVERIFY(touchEvent2.isBeginEvent());
|
||||
QVERIFY(!touchEvent2.isUpdateEvent());
|
||||
QVERIFY(!touchEvent2.isEndEvent());
|
||||
|
||||
touchEvent = QTouchEvent(QEvent::TouchBegin, touchScreenDevice,
|
||||
Qt::NoModifier, QList<QEventPoint>() <<
|
||||
QEventPoint(0, QEventPoint::State::Updated, {}, {}) <<
|
||||
QEventPoint(1, QEventPoint::State::Released, {}, {}));
|
||||
QCOMPARE(touchEvent.touchPointStates(), QEventPoint::State::Updated | QEventPoint::State::Released);
|
||||
QCOMPARE(touchEvent.pointCount(), 2);
|
||||
QVERIFY(!touchEvent.isBeginEvent());
|
||||
QVERIFY(!touchEvent.isUpdateEvent());
|
||||
QVERIFY(touchEvent.isEndEvent());
|
||||
QTouchEvent touchEvent3 = QTouchEvent(QEvent::TouchBegin, touchScreenDevice,
|
||||
Qt::NoModifier, QList<QEventPoint>() <<
|
||||
QEventPoint(0, QEventPoint::State::Updated, {}, {}) <<
|
||||
QEventPoint(1, QEventPoint::State::Released, {}, {}));
|
||||
QCOMPARE(touchEvent3.touchPointStates(), QEventPoint::State::Updated | QEventPoint::State::Released);
|
||||
QCOMPARE(touchEvent3.pointCount(), 2);
|
||||
QVERIFY(!touchEvent3.isBeginEvent());
|
||||
QVERIFY(!touchEvent3.isUpdateEvent());
|
||||
QVERIFY(touchEvent3.isEndEvent());
|
||||
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // test Qt 5 compatibility wrappers
|
||||
QCOMPARE(touchEvent.touchPoints(), touchEvent.points());
|
||||
QCOMPARE(touchEvent3.touchPoints(), touchEvent3.points());
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1699,9 +1699,13 @@ void tst_QTableWidget::search()
|
|||
return item;
|
||||
};
|
||||
|
||||
auto checkSeries = [](TestTableWidget &tw, const QList<QPair<QKeyEvent, int>> &series) {
|
||||
struct KeyPress {
|
||||
Qt::Key key;
|
||||
QString text;
|
||||
};
|
||||
auto checkSeries = [](TestTableWidget &tw, const QList<QPair<KeyPress, int>> &series) {
|
||||
for (const auto &p : series) {
|
||||
QKeyEvent e = p.first;
|
||||
QKeyEvent e(QEvent::KeyPress, p.first.key, Qt::NoModifier, p.first.text);
|
||||
tw.keyPressEvent(&e);
|
||||
QVERIFY(tw.selectionModel()->isSelected(tw.model()->index(p.second, 0)));
|
||||
}
|
||||
|
|
@ -1714,12 +1718,12 @@ void tst_QTableWidget::search()
|
|||
tw.setItem(4, 0, createItem(" "));
|
||||
tw.show();
|
||||
|
||||
QKeyEvent evSpace(QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, " ");
|
||||
QKeyEvent ev1(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier, "1");
|
||||
QKeyEvent ev2(QEvent::KeyPress, Qt::Key_2, Qt::NoModifier, "2");
|
||||
QKeyEvent ev3(QEvent::KeyPress, Qt::Key_3, Qt::NoModifier, "3");
|
||||
QKeyEvent ev4(QEvent::KeyPress, Qt::Key_4, Qt::NoModifier, "4");
|
||||
QKeyEvent ev5(QEvent::KeyPress, Qt::Key_5, Qt::NoModifier, "5");
|
||||
KeyPress evSpace{Qt::Key_Space, " "};
|
||||
KeyPress ev1{Qt::Key_1, "1"};
|
||||
KeyPress ev2{Qt::Key_2, "2"};
|
||||
KeyPress ev3{Qt::Key_3, "3"};
|
||||
KeyPress ev4{Qt::Key_4, "4"};
|
||||
KeyPress ev5{Qt::Key_5, "5"};
|
||||
|
||||
checkSeries(tw, {{evSpace, 4}, {ev1, 4}});
|
||||
QTest::qWait(QApplication::keyboardInputInterval() * 2);
|
||||
|
|
|
|||
|
|
@ -4069,8 +4069,8 @@ void tst_QWidget::testDeletionInEventHandlers()
|
|||
w->setMouseTracking(true);
|
||||
w->show();
|
||||
w->deleteThis = true;
|
||||
me = QMouseEvent(QEvent::MouseMove, QPoint(0, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(w, &me);
|
||||
QMouseEvent me2 = QMouseEvent(QEvent::MouseMove, QPoint(0, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(w, &me2);
|
||||
QVERIFY(w.isNull());
|
||||
delete w;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1678,11 +1678,11 @@ void tst_QAbstractSlider::wheelEvent()
|
|||
|
||||
slider->setSliderPosition(initialSliderPosition);
|
||||
k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier;
|
||||
event = QWheelEvent(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), angleDelta,
|
||||
Qt::NoButton, k, Qt::NoScrollPhase, false);
|
||||
QWheelEvent event2 = QWheelEvent(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), angleDelta,
|
||||
Qt::NoButton, k, Qt::NoScrollPhase, false);
|
||||
QSignalSpy spy1(slider, SIGNAL(actionTriggered(int)));
|
||||
QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
|
||||
QVERIFY(applicationInstance->sendEvent(slider,&event));
|
||||
QVERIFY(applicationInstance->sendEvent(slider,&event2));
|
||||
#ifdef Q_OS_MAC
|
||||
QEXPECT_FAIL("Normal data page", "QTBUG-23679", Continue);
|
||||
QEXPECT_FAIL("Different orientation", "QTBUG-23679", Continue);
|
||||
|
|
|
|||
Loading…
Reference in New Issue