aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-11-11 13:51:35 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-11-16 10:58:52 +0100
commit55318c95d6bf72132ded283971450b4f56674997 (patch)
treeca751a92797b75b483a420a10370f206eecf97b2 /src
parent10c2a8315977e8eb5fc36cf793cfc74d8913dbb0 (diff)
Don't copy or assign QEvent instances in tests
Copying/assigning polymorphic types is a code smell, use separate instances instead in the tests. Those should perhaps be rewritten to use a data driven testing approach, there's a lot of code repetition. In the test API implementation, first evaluate the parameters for the event, then construct the event once with the correct values. Change-Id: I2572772698cb0204f5ff950741b9fe3805fae15d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/testlib/quicktestevent.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/imports/testlib/quicktestevent.cpp b/src/imports/testlib/quicktestevent.cpp
index b2693de234..a1a707d2d6 100644
--- a/src/imports/testlib/quicktestevent.cpp
+++ b/src/imports/testlib/quicktestevent.cpp
@@ -189,30 +189,39 @@ namespace QtQuickTest
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
- QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
+ QEvent::Type meType;
+ Qt::MouseButton meButton;
+ Qt::MouseButtons meButtons;
switch (action)
{
case MousePress:
- me = QMouseEvent(QEvent::MouseButtonPress, pos, window->mapToGlobal(pos), button, button, stateKey);
- me.setTimestamp(++lastMouseTimestamp);
+ meType = QEvent::MouseButtonPress;
+ meButton = button;
+ meButtons = button;
break;
case MouseRelease:
- me = QMouseEvent(QEvent::MouseButtonRelease, pos, window->mapToGlobal(pos), button, {}, stateKey);
- me.setTimestamp(++lastMouseTimestamp);
- lastMouseTimestamp += 500; // avoid double clicks being generated
+ meType = QEvent::MouseButtonRelease;
+ meButton = button;
+ meButtons = Qt::MouseButton();
break;
case MouseDoubleClick:
- me = QMouseEvent(QEvent::MouseButtonDblClick, pos, window->mapToGlobal(pos), button, button, stateKey);
- me.setTimestamp(++lastMouseTimestamp);
+ meType = QEvent::MouseButtonDblClick;
+ meButton = button;
+ meButtons = button;
break;
case MouseMove:
- // with move event the button is NoButton, but 'buttons' holds the currently pressed buttons
- me = QMouseEvent(QEvent::MouseMove, pos, window->mapToGlobal(pos), Qt::NoButton, button, stateKey);
- me.setTimestamp(++lastMouseTimestamp);
+ meType = QEvent::MouseMove;
+ meButton = Qt::NoButton;
+ meButtons = button;
break;
default:
QTEST_ASSERT(false);
}
+ QMouseEvent me(meType, pos, window->mapToGlobal(pos), meButton, meButtons, stateKey);
+ me.setTimestamp(++lastMouseTimestamp);
+ if (action == MouseRelease) // avoid double clicks being generated
+ lastMouseTimestamp += 500;
+
QSpontaneKeyEvent::setSpontaneous(&me);
if (!qApp->notify(window, &me)) {
static const char *mouseActionNames[] =