Brush up tst_QWindow

- Use nullptr
- Fix C-style casts
- Remove unnecessary casts to int from registered enums
- Fix most signedness-related warnings
- Use range-based for
- Use correct static invocation
- Set a title on shown windows to make it possible to identify
  slow tests
- Fix the class declarations, use override, member initializations
- Streamline code in some cases

Change-Id: I4c9b99126cff02136def0e03accdf1129fe6d72b
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
Friedemann Kleint 2019-05-10 09:10:27 +02:00
parent ef3b585ddf
commit 909f793de1

View File

@ -45,10 +45,6 @@
# include <QtCore/qt_windows.h> # include <QtCore/qt_windows.h>
#endif #endif
// For QSignalSpy slot connections.
Q_DECLARE_METATYPE(Qt::ScreenOrientation)
Q_DECLARE_METATYPE(QWindow::Visibility)
static bool isPlatformWinRT() static bool isPlatformWinRT()
{ {
static const bool isWinRT = !QGuiApplication::platformName().compare(QLatin1String("winrt"), Qt::CaseInsensitive); static const bool isWinRT = !QGuiApplication::platformName().compare(QLatin1String("winrt"), Qt::CaseInsensitive);
@ -185,7 +181,7 @@ void tst_QWindow::setParent()
QVERIFY2(c.children().contains(&d), "Parent should have child in list of children"); QVERIFY2(c.children().contains(&d), "Parent should have child in list of children");
a.create(); a.create();
b.setParent(0); b.setParent(nullptr);
QVERIFY2(!b.handle(), "Making window top level shouild not automatically create it"); QVERIFY2(!b.handle(), "Making window top level shouild not automatically create it");
QWindow e; QWindow e;
@ -228,7 +224,7 @@ void tst_QWindow::setVisible()
f.setVisible(true); f.setVisible(true);
QVERIFY(!f.handle()); QVERIFY(!f.handle());
QVERIFY(!e.handle()); QVERIFY(!e.handle());
f.setParent(0); f.setParent(nullptr);
QVERIFY2(f.handle(), "Making a visible but not created child window top level should create it"); QVERIFY2(f.handle(), "Making a visible but not created child window top level should create it");
QVERIFY(QTest::qWaitForWindowExposed(&f)); QVERIFY(QTest::qWaitForWindowExposed(&f));
@ -304,7 +300,7 @@ public:
m_framePositionsOnMove.clear(); m_framePositionsOnMove.clear();
} }
bool event(QEvent *event) bool event(QEvent *event) override
{ {
m_received[event->type()]++; m_received[event->type()]++;
m_order << event->type(); m_order << event->type();
@ -323,6 +319,7 @@ public:
case QEvent::WindowStateChange: case QEvent::WindowStateChange:
lastReceivedWindowState = windowState(); lastReceivedWindowState = windowState();
break;
default: default:
break; break;
@ -363,7 +360,7 @@ private:
class ColoredWindow : public QRasterWindow { class ColoredWindow : public QRasterWindow {
public: public:
explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {} explicit ColoredWindow(const QColor &color, QWindow *parent = nullptr) : QRasterWindow(parent), m_color(color) {}
void paintEvent(QPaintEvent *) override void paintEvent(QPaintEvent *) override
{ {
QPainter p(this); QPainter p(this);
@ -381,6 +378,7 @@ void tst_QWindow::eventOrderOnShow()
QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(geometry); window.setGeometry(geometry);
window.show(); window.show();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
@ -440,12 +438,12 @@ void tst_QWindow::exposeEventOnShrink_QTBUG54040()
void tst_QWindow::positioning_data() void tst_QWindow::positioning_data()
{ {
QTest::addColumn<int>("windowflags"); QTest::addColumn<Qt::WindowFlags>("windowflags");
QTest::newRow("default") << int(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint); QTest::newRow("default") << (Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint);
#ifdef Q_OS_OSX #ifdef Q_OS_MACOS
QTest::newRow("fake") << int(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); QTest::newRow("fake") << (Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
#endif #endif
} }
@ -500,8 +498,8 @@ void tst_QWindow::positioning()
// events, so set the width to suitably large value to avoid those. // events, so set the width to suitably large value to avoid those.
const QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); const QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
QFETCH(int, windowflags); QFETCH(Qt::WindowFlags, windowflags);
Window window((Qt::WindowFlags)windowflags); Window window(windowflags);
window.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20), m_testWindowSize));
window.setFramePosition(m_availableTopLeft + QPoint(40, 40)); // Move window around before show, size must not change. window.setFramePosition(m_availableTopLeft + QPoint(40, 40)); // Move window around before show, size must not change.
QCOMPARE(window.geometry().size(), m_testWindowSize); QCOMPARE(window.geometry().size(), m_testWindowSize);
@ -628,15 +626,13 @@ void tst_QWindow::childWindowPositioning()
QFETCH(bool, showInsteadOfCreate); QFETCH(bool, showInsteadOfCreate);
QWindow* windows[] = { &topLevelWindowFirst, &childWindowAfter, &childWindowFirst, &topLevelWindowAfter, 0 }; QWindow *windows[] = {&topLevelWindowFirst, &childWindowAfter, &childWindowFirst, &topLevelWindowAfter};
for (int i = 0; windows[i]; ++i) { for (QWindow *window : windows) {
QWindow *window = windows[i]; if (showInsteadOfCreate)
if (showInsteadOfCreate) {
window->showNormal(); window->showNormal();
} else { else
window->create(); window->create();
} }
}
if (showInsteadOfCreate) { if (showInsteadOfCreate) {
QVERIFY(QTest::qWaitForWindowExposed(&topLevelWindowFirst)); QVERIFY(QTest::qWaitForWindowExposed(&topLevelWindowFirst));
@ -712,7 +708,7 @@ void tst_QWindow::stateChange()
// explicitly use non-fullscreen show. show() can be fullscreen on some platforms // explicitly use non-fullscreen show. show() can be fullscreen on some platforms
window.showNormal(); window.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
foreach (Qt::WindowState state, stateSequence) { for (Qt::WindowState state : qAsConst(stateSequence)) {
window.setWindowState(state); window.setWindowState(state);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
} }
@ -726,15 +722,9 @@ class PlatformWindowFilter : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PlatformWindowFilter(QObject *parent = 0) explicit PlatformWindowFilter(Window *window) : m_window(window) {}
: QObject(parent)
, m_window(nullptr)
, m_alwaysExisted(true)
{}
void setWindow(Window *window) { m_window = window; } bool eventFilter(QObject *o, QEvent *e) override
bool eventFilter(QObject *o, QEvent *e)
{ {
// Check that the platform surface events are delivered synchronously. // Check that the platform surface events are delivered synchronously.
// If they are, the native platform surface should always exist when we // If they are, the native platform surface should always exist when we
@ -749,7 +739,7 @@ public:
private: private:
Window *m_window; Window *m_window;
bool m_alwaysExisted; bool m_alwaysExisted = true;
}; };
void tst_QWindow::platformSurface() void tst_QWindow::platformSurface()
@ -757,8 +747,7 @@ void tst_QWindow::platformSurface()
QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
PlatformWindowFilter filter; PlatformWindowFilter filter(&window);
filter.setWindow(&window);
window.installEventFilter(&filter); window.installEventFilter(&filter);
window.setGeometry(geometry); window.setGeometry(geometry);
@ -784,6 +773,7 @@ void tst_QWindow::isExposed()
QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(geometry); window.setGeometry(geometry);
QCOMPARE(window.geometry(), geometry); QCOMPARE(window.geometry(), geometry);
window.show(); window.show();
@ -818,6 +808,7 @@ void tst_QWindow::isActive()
QSKIP("QWindow::requestActivate() is not supported."); QSKIP("QWindow::requestActivate() is not supported.");
Window window; Window window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
// Some platforms enforce minimum widths for windows, which can cause extra resize // Some platforms enforce minimum widths for windows, which can cause extra resize
// events, so set the width to suitably large value to avoid those. // events, so set the width to suitably large value to avoid those.
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
@ -916,13 +907,16 @@ void tst_QWindow::isActive()
class InputTestWindow : public ColoredWindow class InputTestWindow : public ColoredWindow
{ {
public: public:
void keyPressEvent(QKeyEvent *event) { void keyPressEvent(QKeyEvent *event) override
{
keyPressCode = event->key(); keyPressCode = event->key();
} }
void keyReleaseEvent(QKeyEvent *event) { void keyReleaseEvent(QKeyEvent *event) override
{
keyReleaseCode = event->key(); keyReleaseCode = event->key();
} }
void mousePressEvent(QMouseEvent *event) { void mousePressEvent(QMouseEvent *event) override
{
if (ignoreMouse) { if (ignoreMouse) {
event->ignore(); event->ignore();
} else { } else {
@ -935,7 +929,8 @@ public:
QCoreApplication::processEvents(); QCoreApplication::processEvents();
} }
} }
void mouseReleaseEvent(QMouseEvent *event) { void mouseReleaseEvent(QMouseEvent *event) override
{
if (ignoreMouse) { if (ignoreMouse) {
event->ignore(); event->ignore();
} else { } else {
@ -944,7 +939,8 @@ public:
mouseReleaseButton = event->button(); mouseReleaseButton = event->button();
} }
} }
void mouseMoveEvent(QMouseEvent *event) { void mouseMoveEvent(QMouseEvent *event) override
{
buttonStateInGeneratedMove = event->buttons(); buttonStateInGeneratedMove = event->buttons();
if (ignoreMouse) { if (ignoreMouse) {
event->ignore(); event->ignore();
@ -954,7 +950,8 @@ public:
mouseMoveScreenPos = event->screenPos(); mouseMoveScreenPos = event->screenPos();
} }
} }
void mouseDoubleClickEvent(QMouseEvent *event) { void mouseDoubleClickEvent(QMouseEvent *event) override
{
if (ignoreMouse) { if (ignoreMouse) {
event->ignore(); event->ignore();
} else { } else {
@ -962,7 +959,8 @@ public:
mouseSequenceSignature += 'd'; mouseSequenceSignature += 'd';
} }
} }
void touchEvent(QTouchEvent *event) { void touchEvent(QTouchEvent *event) override
{
if (ignoreTouch) { if (ignoreTouch) {
event->ignore(); event->ignore();
return; return;
@ -987,7 +985,8 @@ public:
} }
} }
} }
bool event(QEvent *e) { bool event(QEvent *e) override
{
switch (e->type()) { switch (e->type()) {
case QEvent::Enter: case QEvent::Enter:
++enterEventCount; ++enterEventCount;
@ -998,37 +997,31 @@ public:
default: default:
break; break;
} }
return QWindow::event(e); return ColoredWindow::event(e);
} }
void resetCounters() { void resetCounters()
{
mousePressedCount = mouseReleasedCount = mouseMovedCount = mouseDoubleClickedCount = 0; mousePressedCount = mouseReleasedCount = mouseMovedCount = mouseDoubleClickedCount = 0;
mouseSequenceSignature = QString(); mouseSequenceSignature.clear();
touchPressedCount = touchReleasedCount = touchMovedCount = 0; touchPressedCount = touchReleasedCount = touchMovedCount = 0;
enterEventCount = leaveEventCount = 0; enterEventCount = leaveEventCount = 0;
} }
explicit InputTestWindow(const QColor &color = Qt::white, QWindow *parent = nullptr) explicit InputTestWindow(const QColor &color = Qt::white, QWindow *parent = nullptr)
: ColoredWindow(color, parent) : ColoredWindow(color, parent) {}
{
keyPressCode = keyReleaseCode = 0;
mousePressButton = mouseReleaseButton = mouseMoveButton = 0;
ignoreMouse = ignoreTouch = false;
spinLoopWhenPressed = false;
resetCounters();
}
int keyPressCode, keyReleaseCode; int keyPressCode = 0, keyReleaseCode = 0;
int mousePressButton, mouseReleaseButton, mouseMoveButton; int mousePressButton = 0, mouseReleaseButton = 0, mouseMoveButton = 0;
int mousePressedCount, mouseReleasedCount, mouseMovedCount, mouseDoubleClickedCount; int mousePressedCount = 0, mouseReleasedCount = 0, mouseMovedCount = 0, mouseDoubleClickedCount = 0;
QString mouseSequenceSignature; QString mouseSequenceSignature;
QPointF mousePressScreenPos, mouseMoveScreenPos, mousePressLocalPos; QPointF mousePressScreenPos, mouseMoveScreenPos, mousePressLocalPos;
int touchPressedCount, touchReleasedCount, touchMovedCount; int touchPressedCount = 0, touchReleasedCount = 0, touchMovedCount = 0;
QEvent::Type touchEventType; QEvent::Type touchEventType = QEvent::None;
int enterEventCount, leaveEventCount; int enterEventCount = 0, leaveEventCount = 0;
bool ignoreMouse, ignoreTouch; bool ignoreMouse = false, ignoreTouch = false;
bool spinLoopWhenPressed; bool spinLoopWhenPressed = false;
Qt::MouseButtons buttonStateInGeneratedMove; Qt::MouseButtons buttonStateInGeneratedMove;
}; };
@ -1073,15 +1066,15 @@ void tst_QWindow::testInputEvents()
window.mousePressButton = window.mouseReleaseButton = 0; window.mousePressButton = window.mouseReleaseButton = 0;
const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window
const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen()); const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen());
QWindowSystemInterface::handleMouseEvent(0, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton); QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton);
QWindowSystemInterface::handleMouseEvent(0, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton); QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QCOMPARE(window.mousePressButton, 0); QCOMPARE(window.mousePressButton, 0);
QCOMPARE(window.mouseReleaseButton, 0); QCOMPARE(window.mouseReleaseButton, 0);
const QPointF windowGlobal = window.mapToGlobal(local.toPoint()); const QPointF windowGlobal = window.mapToGlobal(local.toPoint());
const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen()); const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen());
QWindowSystemInterface::handleMouseEvent(0, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton); QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton);
QWindowSystemInterface::handleMouseEvent(0, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton); QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QCOMPARE(window.mousePressButton, int(Qt::LeftButton)); QCOMPARE(window.mousePressButton, int(Qt::LeftButton));
QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
@ -1092,6 +1085,7 @@ void tst_QWindow::testInputEvents()
void tst_QWindow::touchToMouseTranslation() void tst_QWindow::touchToMouseTranslation()
{ {
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
@ -1145,7 +1139,7 @@ void tst_QWindow::touchToMouseTranslation()
QTRY_COMPARE(window.mousePressButton, 0); QTRY_COMPARE(window.mousePressButton, 0);
QTRY_COMPARE(window.mouseReleaseButton, 0); QTRY_COMPARE(window.mouseReleaseButton, 0);
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false); QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false);
window.ignoreTouch = true; window.ignoreTouch = true;
points[0].state = Qt::TouchPointPressed; points[0].state = Qt::TouchPointPressed;
@ -1156,7 +1150,7 @@ void tst_QWindow::touchToMouseTranslation()
QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points); QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true);
// mouse event synthesizing disabled // mouse event synthesizing disabled
QTRY_COMPARE(window.mousePressButton, 0); QTRY_COMPARE(window.mousePressButton, 0);
@ -1166,6 +1160,7 @@ void tst_QWindow::touchToMouseTranslation()
void tst_QWindow::touchToMouseTranslationForDevices() void tst_QWindow::touchToMouseTranslationForDevices()
{ {
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
@ -1194,9 +1189,10 @@ void tst_QWindow::touchToMouseTranslationForDevices()
void tst_QWindow::mouseToTouchTranslation() void tst_QWindow::mouseToTouchTranslation()
{ {
qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.ignoreMouse = true; window.ignoreMouse = true;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
@ -1206,12 +1202,12 @@ void tst_QWindow::mouseToTouchTranslation()
QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
QTRY_COMPARE(window.touchPressedCount, 1); QTRY_COMPARE(window.touchPressedCount, 1);
QTRY_COMPARE(window.touchReleasedCount, 1); QTRY_COMPARE(window.touchReleasedCount, 1);
qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);
window.ignoreMouse = false; window.ignoreMouse = false;
@ -1219,7 +1215,7 @@ void tst_QWindow::mouseToTouchTranslation()
QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
// no new touch events should be generated since the input window handles the mouse events // no new touch events should be generated since the input window handles the mouse events
QTRY_COMPARE(window.touchPressedCount, 1); QTRY_COMPARE(window.touchPressedCount, 1);
@ -1241,10 +1237,12 @@ void tst_QWindow::mouseToTouchTranslation()
void tst_QWindow::mouseToTouchLoop() void tst_QWindow::mouseToTouchLoop()
{ {
// make sure there's no infinite loop when synthesizing both ways // make sure there's no infinite loop when synthesizing both ways
qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true);
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.ignoreMouse = true; window.ignoreMouse = true;
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
@ -1255,13 +1253,14 @@ void tst_QWindow::mouseToTouchLoop()
QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true);
} }
void tst_QWindow::touchCancel() void tst_QWindow::touchCancel()
{ {
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -1321,6 +1320,7 @@ void tst_QWindow::touchCancel()
void tst_QWindow::touchCancelWithTouchToMouse() void tst_QWindow::touchCancelWithTouchToMouse()
{ {
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
@ -1343,7 +1343,7 @@ void tst_QWindow::touchCancelWithTouchToMouse()
// Cancel the touch. Should result in a mouse release for windows that have // Cancel the touch. Should result in a mouse release for windows that have
// have an active touch-to-mouse sequence. // have an active touch-to-mouse sequence.
QWindowSystemInterface::handleTouchCancelEvent(0, touchDevice); QWindowSystemInterface::handleTouchCancelEvent(nullptr, touchDevice);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
@ -1358,7 +1358,7 @@ void tst_QWindow::touchCancelWithTouchToMouse()
QTRY_COMPARE(window.mousePressButton, 0); QTRY_COMPARE(window.mousePressButton, 0);
// Cancel the touch. It should not result in a mouse release with this window. // Cancel the touch. It should not result in a mouse release with this window.
QWindowSystemInterface::handleTouchCancelEvent(0, touchDevice); QWindowSystemInterface::handleTouchCancelEvent(nullptr, touchDevice);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QTRY_COMPARE(window.mouseReleaseButton, 0); QTRY_COMPARE(window.mouseReleaseButton, 0);
} }
@ -1369,6 +1369,7 @@ void tst_QWindow::touchInterruptedByPopup()
QSKIP("Wayland: This test crashes with xdg-shell unstable v6"); QSKIP("Wayland: This test crashes with xdg-shell unstable v6");
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -1489,6 +1490,7 @@ void tst_QWindow::sizes()
void tst_QWindow::close() void tst_QWindow::close()
{ {
QWindow a; QWindow a;
a.setTitle(QLatin1String(QTest::currentTestFunction()));
QWindow b; QWindow b;
QWindow c(&a); QWindow c(&a);
@ -1508,6 +1510,7 @@ void tst_QWindow::activateAndClose()
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
QWindow window; QWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()) + QString::number(i));
#if defined(Q_OS_QNX) #if defined(Q_OS_QNX)
window.setSurfaceType(QSurface::OpenGLSurface); window.setSurfaceType(QSurface::OpenGLSurface);
#endif #endif
@ -1525,15 +1528,16 @@ void tst_QWindow::activateAndClose()
#endif #endif
window.requestActivate(); window.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&window)); QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(qGuiApp->focusWindow(), &window); QCOMPARE(QGuiApplication::focusWindow(), &window);
} }
} }
void tst_QWindow::mouseEventSequence() void tst_QWindow::mouseEventSequence()
{ {
int doubleClickInterval = qGuiApp->styleHints()->mouseDoubleClickInterval(); const auto doubleClickInterval = ulong(QGuiApplication::styleHints()->mouseDoubleClickInterval());
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -1655,6 +1659,7 @@ void tst_QWindow::windowModality()
void tst_QWindow::inputReentrancy() void tst_QWindow::inputReentrancy()
{ {
InputTestWindow window; InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.spinLoopWhenPressed = true; window.spinLoopWhenPressed = true;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
@ -1700,17 +1705,20 @@ void tst_QWindow::inputReentrancy()
class TabletTestWindow : public QWindow class TabletTestWindow : public QWindow
{ {
public: public:
TabletTestWindow() : eventType(QEvent::None) { } void tabletEvent(QTabletEvent *ev) override
void tabletEvent(QTabletEvent *ev) { {
eventType = ev->type(); eventType = ev->type();
eventGlobal = ev->globalPosF(); eventGlobal = ev->globalPosF();
eventLocal = ev->posF(); eventLocal = ev->posF();
eventDevice = ev->device(); eventDevice = ev->device();
} }
QEvent::Type eventType;
QEvent::Type eventType = QEvent::None;
QPointF eventGlobal, eventLocal; QPointF eventGlobal, eventLocal;
int eventDevice; int eventDevice = -1;
bool eventFilter(QObject *obj, QEvent *ev) {
bool eventFilter(QObject *obj, QEvent *ev) override
{
if (ev->type() == QEvent::TabletEnterProximity if (ev->type() == QEvent::TabletEnterProximity
|| ev->type() == QEvent::TabletLeaveProximity) { || ev->type() == QEvent::TabletLeaveProximity) {
eventType = ev->type(); eventType = ev->type();
@ -1758,6 +1766,7 @@ void tst_QWindow::tabletEvents()
void tst_QWindow::windowModality_QTBUG27039() void tst_QWindow::windowModality_QTBUG27039()
{ {
QWindow parent; QWindow parent;
parent.setTitle(QLatin1String(QTest::currentTestFunction()));
parent.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize)); parent.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize));
parent.show(); parent.show();
@ -1868,6 +1877,7 @@ void tst_QWindow::initialSize()
QSize defaultSize(0,0); QSize defaultSize(0,0);
{ {
Window w; Window w;
w.setTitle(QLatin1String(QTest::currentTestFunction()));
w.showNormal(); w.showNormal();
QTRY_VERIFY(w.width() > 0); QTRY_VERIFY(w.width() > 0);
QTRY_VERIFY(w.height() > 0); QTRY_VERIFY(w.height() > 0);
@ -1875,6 +1885,7 @@ void tst_QWindow::initialSize()
} }
{ {
Window w; Window w;
w.setTitle(QLatin1String(QTest::currentTestFunction()));
w.setWidth(m_testWindowSize.width()); w.setWidth(m_testWindowSize.width());
w.showNormal(); w.showNormal();
if (isPlatformWinRT()) if (isPlatformWinRT())
@ -1884,6 +1895,7 @@ void tst_QWindow::initialSize()
} }
{ {
Window w; Window w;
w.setTitle(QLatin1String(QTest::currentTestFunction()));
const QSize testSize(m_testWindowSize.width(), 42); const QSize testSize(m_testWindowSize.width(), 42);
w.resize(testSize); w.resize(testSize);
w.showNormal(); w.showNormal();
@ -1910,6 +1922,7 @@ void tst_QWindow::modalDialog()
QSKIP("Test fails due to QTBUG-61965, and is slow due to QTBUG-61964"); QSKIP("Test fails due to QTBUG-61965, and is slow due to QTBUG-61964");
QWindow normalWindow; QWindow normalWindow;
normalWindow.setTitle(QLatin1String(QTest::currentTestFunction()));
normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize); normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
@ -1945,6 +1958,7 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal()
QSKIP("QWindow::requestActivate() is not supported."); QSKIP("QWindow::requestActivate() is not supported.");
QWindow normalWindow; QWindow normalWindow;
normalWindow.setTitle(QLatin1String(QTest::currentTestFunction()));
normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize); normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
@ -1992,6 +2006,7 @@ void tst_QWindow::modalWithChildWindow()
QSKIP("QWindow::requestActivate() is not supported."); QSKIP("QWindow::requestActivate() is not supported.");
QWindow normalWindow; QWindow normalWindow;
normalWindow.setTitle(QLatin1String(QTest::currentTestFunction()));
normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize); normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
@ -2028,6 +2043,7 @@ void tst_QWindow::modalWindowModallity()
QSKIP("QWindow::requestActivate() is not supported."); QSKIP("QWindow::requestActivate() is not supported.");
QWindow normal_window; QWindow normal_window;
normal_window.setTitle(QLatin1String(QTest::currentTestFunction()));
normal_window.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normal_window.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normal_window.resize(m_testWindowSize); normal_window.resize(m_testWindowSize);
normal_window.show(); normal_window.show();
@ -2058,6 +2074,7 @@ void tst_QWindow::modalWindowModallity()
void tst_QWindow::modalWindowPosition() void tst_QWindow::modalWindowPosition()
{ {
QWindow window; QWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); window.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize));
// Allow for any potential resizing due to constraints // Allow for any potential resizing due to constraints
QRect origGeo = window.geometry(); QRect origGeo = window.geometry();
@ -2341,6 +2358,7 @@ void tst_QWindow::requestUpdate()
QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(geometry); window.setGeometry(geometry);
window.show(); window.show();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
@ -2370,10 +2388,10 @@ void tst_QWindow::flags()
class EventWindow : public QWindow class EventWindow : public QWindow
{ {
public: public:
EventWindow() : QWindow(), gotBlocked(false) {} bool gotBlocked = false;
bool gotBlocked;
protected: protected:
bool event(QEvent *e) bool event(QEvent *e) override
{ {
if (e->type() == QEvent::WindowBlocked) if (e->type() == QEvent::WindowBlocked)
gotBlocked = true; gotBlocked = true;
@ -2384,6 +2402,7 @@ protected:
void tst_QWindow::testBlockingWindowShownAfterModalDialog() void tst_QWindow::testBlockingWindowShownAfterModalDialog()
{ {
EventWindow normalWindow; EventWindow normalWindow;
normalWindow.setTitle(QLatin1String(QTest::currentTestFunction()));
normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize); normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
@ -2411,6 +2430,7 @@ void tst_QWindow::testBlockingWindowShownAfterModalDialog()
void tst_QWindow::generatedMouseMove() void tst_QWindow::generatedMouseMove()
{ {
InputTestWindow w; InputTestWindow w;
w.setTitle(QLatin1String(QTest::currentTestFunction()));
w.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); w.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize));
w.setFlags(w.flags() | Qt::FramelessWindowHint); // ### FIXME: QTBUG-63542 w.setFlags(w.flags() | Qt::FramelessWindowHint); // ### FIXME: QTBUG-63542
w.show(); w.show();
@ -2422,34 +2442,34 @@ void tst_QWindow::generatedMouseMove()
QTest::mouseMove(&w, point); QTest::mouseMove(&w, point);
QVERIFY(w.mouseMovedCount == 1); QVERIFY(w.mouseMovedCount == 1);
// A press event that does not change position should not generate mouse move // A press event that does not change position should not generate mouse move
QTest::mousePress(&w, Qt::LeftButton, 0, point); QTest::mousePress(&w, Qt::LeftButton, Qt::KeyboardModifiers(), point);
QTest::mousePress(&w, Qt::RightButton, 0, point); QTest::mousePress(&w, Qt::RightButton, Qt::KeyboardModifiers(), point);
QVERIFY(w.mouseMovedCount == 1); QVERIFY(w.mouseMovedCount == 1);
// Verify that a move event is generated for a mouse release event that changes position // Verify that a move event is generated for a mouse release event that changes position
point += step; point += step;
QTest::mouseRelease(&w, Qt::LeftButton, 0, point); QTest::mouseRelease(&w, Qt::LeftButton,Qt::KeyboardModifiers(), point);
QVERIFY(w.mouseMovedCount == 2); QVERIFY(w.mouseMovedCount == 2);
QVERIFY(w.buttonStateInGeneratedMove == (Qt::LeftButton | Qt::RightButton)); QVERIFY(w.buttonStateInGeneratedMove == (Qt::LeftButton | Qt::RightButton));
point += step; point += step;
QTest::mouseRelease(&w, Qt::RightButton, 0, point); QTest::mouseRelease(&w, Qt::RightButton, Qt::KeyboardModifiers(), point);
QVERIFY(w.mouseMovedCount == 3); QVERIFY(w.mouseMovedCount == 3);
QVERIFY(w.buttonStateInGeneratedMove == Qt::RightButton); QVERIFY(w.buttonStateInGeneratedMove == Qt::RightButton);
// Verify that a move event is generated for a mouse press event that changes position // Verify that a move event is generated for a mouse press event that changes position
point += step; point += step;
QTest::mousePress(&w, Qt::LeftButton, 0, point); QTest::mousePress(&w, Qt::LeftButton, Qt::KeyboardModifiers(), point);
QVERIFY(w.mouseMovedCount == 4); QVERIFY(w.mouseMovedCount == 4);
QVERIFY(w.buttonStateInGeneratedMove == Qt::NoButton); QVERIFY(w.buttonStateInGeneratedMove == Qt::NoButton);
point += step; point += step;
QTest::mousePress(&w, Qt::RightButton, 0, point); QTest::mousePress(&w, Qt::RightButton, Qt::KeyboardModifiers(), point);
QVERIFY(w.mouseMovedCount == 5); QVERIFY(w.mouseMovedCount == 5);
QVERIFY(w.buttonStateInGeneratedMove == Qt::LeftButton); QVERIFY(w.buttonStateInGeneratedMove == Qt::LeftButton);
// A release event that does not change position should not generate mouse move // A release event that does not change position should not generate mouse move
QTest::mouseRelease(&w, Qt::RightButton, 0, point); QTest::mouseRelease(&w, Qt::RightButton, Qt::KeyboardModifiers(), point);
QTest::mouseRelease(&w, Qt::LeftButton, 0, point); QTest::mouseRelease(&w, Qt::LeftButton, Qt::KeyboardModifiers(), point);
QVERIFY(w.mouseMovedCount == 5); QVERIFY(w.mouseMovedCount == 5);
} }
@ -2458,6 +2478,7 @@ void tst_QWindow::keepPendingUpdateRequests()
QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(geometry); window.setGeometry(geometry);
window.show(); window.show();
QCoreApplication::processEvents(); QCoreApplication::processEvents();