diff options
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r-- | tests/auto/gui/kernel/kernel.pro | 1 | ||||
-rw-r--r-- | tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qcursor/qcursor.pro | 6 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qcursor/tst_qcursor.cpp | 123 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 32 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguitimer/qguitimer.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp | 12 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp | 32 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpalette/tst_qpalette.cpp | 31 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp | 6 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp | 14 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qwindow/BLACKLIST | 8 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 118 |
13 files changed, 329 insertions, 58 deletions
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 559395a9ae..46786262c0 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -2,6 +2,7 @@ TEMPLATE=subdirs SUBDIRS=\ qbackingstore \ qclipboard \ + qcursor \ qdrag \ qevent \ qfileopenevent \ diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp index 37d97cd3db..4fca9a07fc 100644 --- a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp +++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp @@ -64,7 +64,7 @@ public: m_received.clear(); } - bool event(QEvent *event) + bool event(QEvent *event) override { m_received[event->type()]++; return QWindow::event(event); diff --git a/tests/auto/gui/kernel/qcursor/qcursor.pro b/tests/auto/gui/kernel/qcursor/qcursor.pro new file mode 100644 index 0000000000..16e7d7c41c --- /dev/null +++ b/tests/auto/gui/kernel/qcursor/qcursor.pro @@ -0,0 +1,6 @@ +QT += testlib +TARGET = tst_qcursor +CONFIG += testcase +CONFIG -= app_bundle + +SOURCES += tst_qcursor.cpp diff --git a/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp b/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp new file mode 100644 index 0000000000..d505f5a655 --- /dev/null +++ b/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QTest> +#include <qcursor.h> +#include <qpixmap.h> +#include <qbitmap.h> + +class tst_QCursor : public QObject +{ + Q_OBJECT + +private slots: + void equality(); +}; + +#define VERIFY_EQUAL(lhs, rhs) \ + QVERIFY(lhs == rhs); \ + QVERIFY(rhs == lhs); \ + QVERIFY(!(rhs != lhs)); \ + QVERIFY(!(lhs != rhs)) + +#define VERIFY_DIFFERENT(lhs, rhs) \ + QVERIFY(lhs != rhs); \ + QVERIFY(rhs != lhs); \ + QVERIFY(!(rhs == lhs)); \ + QVERIFY(!(lhs == rhs)) + +void tst_QCursor::equality() +{ + VERIFY_EQUAL(QCursor(), QCursor()); + VERIFY_EQUAL(QCursor(Qt::CrossCursor), QCursor(Qt::CrossCursor)); + VERIFY_DIFFERENT(QCursor(Qt::CrossCursor), QCursor()); + + // Shape + QCursor shapeCursor(Qt::WaitCursor); + VERIFY_EQUAL(shapeCursor, shapeCursor); + QCursor shapeCursorCopy(shapeCursor); + VERIFY_EQUAL(shapeCursor, shapeCursorCopy); + shapeCursorCopy.setShape(Qt::DragMoveCursor); + VERIFY_DIFFERENT(shapeCursor, shapeCursorCopy); + shapeCursorCopy.setShape(shapeCursor.shape()); + VERIFY_EQUAL(shapeCursor, shapeCursorCopy); + + // Pixmap + QPixmap pixmap(16, 16); + QCursor pixmapCursor(pixmap); + VERIFY_EQUAL(pixmapCursor, pixmapCursor); + VERIFY_EQUAL(pixmapCursor, QCursor(pixmapCursor)); + VERIFY_EQUAL(pixmapCursor, QCursor(pixmap)); + VERIFY_DIFFERENT(pixmapCursor, QCursor()); + VERIFY_DIFFERENT(pixmapCursor, QCursor(pixmap, 5, 5)); + VERIFY_DIFFERENT(pixmapCursor, QCursor(QPixmap(16, 16))); + VERIFY_DIFFERENT(pixmapCursor, shapeCursor); + + // Bitmap & mask + QBitmap bitmap(16, 16); + QBitmap mask(16, 16); + QCursor bitmapCursor(bitmap, mask); + VERIFY_EQUAL(bitmapCursor, bitmapCursor); + VERIFY_EQUAL(bitmapCursor, QCursor(bitmapCursor)); + VERIFY_EQUAL(bitmapCursor, QCursor(bitmap, mask)); + VERIFY_DIFFERENT(bitmapCursor, QCursor()); + VERIFY_DIFFERENT(bitmapCursor, QCursor(bitmap, mask, 5, 5)); + VERIFY_DIFFERENT(bitmapCursor, QCursor(bitmap, QBitmap(16, 16))); + VERIFY_DIFFERENT(bitmapCursor, QCursor(QBitmap(16, 16), mask)); + VERIFY_DIFFERENT(bitmapCursor, shapeCursor); + VERIFY_DIFFERENT(bitmapCursor, pixmapCursor); + + // Empty pixmap + QPixmap emptyPixmap; + QCursor emptyPixmapCursor(emptyPixmap); + QCOMPARE(emptyPixmapCursor.shape(), Qt::ArrowCursor); + VERIFY_EQUAL(emptyPixmapCursor, QCursor()); + VERIFY_EQUAL(emptyPixmapCursor, QCursor(emptyPixmap, 5, 5)); + VERIFY_DIFFERENT(emptyPixmapCursor, shapeCursor); + VERIFY_DIFFERENT(emptyPixmapCursor, pixmapCursor); + VERIFY_DIFFERENT(emptyPixmapCursor, bitmapCursor); + + // Empty bitmap & mask + QBitmap emptyBitmap; + QCursor emptyBitmapCursor(emptyBitmap, emptyBitmap); + QCOMPARE(emptyBitmapCursor.shape(), Qt::ArrowCursor); + VERIFY_EQUAL(emptyBitmapCursor, QCursor()); + VERIFY_EQUAL(emptyBitmapCursor, QCursor(emptyBitmap, emptyBitmap, 5, 5)); + VERIFY_EQUAL(emptyBitmapCursor, QCursor(emptyBitmap, mask)); + VERIFY_EQUAL(emptyBitmapCursor, QCursor(bitmap, emptyBitmap)); + VERIFY_EQUAL(emptyBitmapCursor, emptyPixmapCursor); + VERIFY_DIFFERENT(emptyBitmapCursor, shapeCursor); + VERIFY_DIFFERENT(emptyBitmapCursor, pixmapCursor); + VERIFY_DIFFERENT(emptyBitmapCursor, bitmapCursor); +} + +#undef VERIFY_EQUAL +#undef VERIFY_DIFFERENT + +QTEST_MAIN(tst_QCursor) +#include "tst_qcursor.moc" diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index a935258fb8..4f27aeb899 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -68,6 +68,7 @@ private slots: void changeFocusWindow(); void keyboardModifiers(); void palette(); + void font(); void modalWindow(); void quitOnLastWindowClosed(); void quitOnLastWindowClosedMulti(); @@ -227,7 +228,7 @@ void tst_QGuiApplication::focusObject() QOpenGLContext context; context.create(); context.makeCurrent(&window1); - QTest::qWaitForWindowExposed(&window1); // Buffer swap only succeeds with exposed window + QVERIFY(QTest::qWaitForWindowExposed(&window1)); // Buffer swap only succeeds with exposed window context.swapBuffers(&window1); #endif @@ -392,7 +393,7 @@ void tst_QGuiApplication::changeFocusWindow() QOpenGLContext context; context.create(); context.makeCurrent(&window1); - QTest::qWaitForWindowExposed(&window1); // Buffer swap only succeeds with exposed window + QVERIFY(QTest::qWaitForWindowExposed(&window1)); // Buffer swap only succeeds with exposed window context.swapBuffers(&window1); #endif FocusChangeWindow window2; @@ -406,7 +407,7 @@ void tst_QGuiApplication::changeFocusWindow() #if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store // and then post the window in order for screen to show the window context.makeCurrent(&window2); - QTest::qWaitForWindowExposed(&window2); // Buffer swap only succeeds with exposed window + QVERIFY(QTest::qWaitForWindowExposed(&window2)); // Buffer swap only succeeds with exposed window context.swapBuffers(&window2); #endif QVERIFY(QTest::qWaitForWindowExposed(&window1)); @@ -524,6 +525,31 @@ void tst_QGuiApplication::palette() QCOMPARE(signalSpy.count(), 2); } +void tst_QGuiApplication::font() +{ + int argc = 1; + char *argv[] = { const_cast<char*>("tst_qguiapplication") }; + QGuiApplication app(argc, argv); + QSignalSpy signalSpy(&app, SIGNAL(fontChanged(QFont))); + + QFont oldFont = QGuiApplication::font(); + QFont newFont = QFont("BogusFont", 33); + + QGuiApplication::setFont(newFont); + QCOMPARE(QGuiApplication::font(), newFont); + QCOMPARE(signalSpy.count(), 1); + QCOMPARE(signalSpy.at(0).at(0), QVariant(newFont)); + + QGuiApplication::setFont(oldFont); + QCOMPARE(QGuiApplication::font(), oldFont); + QCOMPARE(signalSpy.count(), 2); + QCOMPARE(signalSpy.at(1).at(0), QVariant(oldFont)); + + QGuiApplication::setFont(oldFont); + QCOMPARE(QGuiApplication::font(), oldFont); + QCOMPARE(signalSpy.count(), 2); +} + class BlockableWindow : public QWindow { Q_OBJECT diff --git a/tests/auto/gui/kernel/qguitimer/qguitimer.pro b/tests/auto/gui/kernel/qguitimer/qguitimer.pro index 8a71e48007..9c58f0e22c 100644 --- a/tests/auto/gui/kernel/qguitimer/qguitimer.pro +++ b/tests/auto/gui/kernel/qguitimer/qguitimer.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qguitimer -QT = core gui testlib +QT = core core-private gui testlib SOURCES += ../../../corelib/kernel/qtimer/tst_qtimer.cpp diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp index 6394a956bd..f8b6bf064a 100644 --- a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp @@ -36,14 +36,18 @@ #include <QLibraryInfo> #ifdef Q_OS_MAC -#ifdef Q_OS_OSX -#include <Carbon/Carbon.h> -#endif struct MacSpecialKey { int key; ushort macSymbol; }; +// Unicode code points for the glyphs associated with these keys +// Defined by Carbon headers but not anywhere in Cocoa +static const int kShiftUnicode = 0x21E7; +static const int kControlUnicode = 0x2303; +static const int kOptionUnicode = 0x2325; +static const int kCommandUnicode = 0x2318; + static const int NumEntries = 21; static const MacSpecialKey entries[NumEntries] = { { Qt::Key_Escape, 0x238B }, @@ -61,12 +65,10 @@ static const MacSpecialKey entries[NumEntries] = { { Qt::Key_Down, 0x2193 }, { Qt::Key_PageUp, 0x21DE }, { Qt::Key_PageDown, 0x21DF }, -#ifdef Q_OS_OSX { Qt::Key_Shift, kShiftUnicode }, { Qt::Key_Control, kCommandUnicode }, { Qt::Key_Meta, kControlUnicode }, { Qt::Key_Alt, kOptionUnicode }, -#endif { Qt::Key_CapsLock, 0x21EA }, }; diff --git a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp index 58dee6f6ca..8ffd1bb9b4 100644 --- a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp +++ b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp @@ -62,7 +62,7 @@ void tst_QOpenGLWindow::create() w.resize(640, 480); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w)); QVERIFY(w.isValid()); } @@ -74,17 +74,17 @@ public: initCount = resizeCount = paintCount = 0; } - void initializeGL() Q_DECL_OVERRIDE { + void initializeGL() override { ++initCount; } - void resizeGL(int w, int h) Q_DECL_OVERRIDE { + void resizeGL(int w, int h) override { ++resizeCount; QCOMPARE(w, size().width()); QCOMPARE(h, size().height()); } - void paintGL() Q_DECL_OVERRIDE { + void paintGL() override { ++paintCount; QOpenGLContext *ctx = QOpenGLContext::currentContext(); @@ -111,7 +111,7 @@ void tst_QOpenGLWindow::basic() w.reset(); w.resize(640, 480); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w)); // Check that the virtuals are invoked. QCOMPARE(w.initCount, 1); @@ -144,7 +144,7 @@ void tst_QOpenGLWindow::basic() class PainterWindow : public QOpenGLWindow { public: - void paintGL() Q_DECL_OVERRIDE { + void paintGL() override { QOpenGLContext *ctx = QOpenGLContext::currentContext(); QVERIFY(ctx); QCOMPARE(ctx, context()); @@ -170,7 +170,7 @@ void tst_QOpenGLWindow::painter() PainterWindow w; w.resize(400, 400); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w)); QCOMPARE(w.img.size(), w.size() * w.devicePixelRatio()); QVERIFY(w.img.pixel(QPoint(5, 5) * w.devicePixelRatio()) == qRgb(0, 0, 255)); @@ -183,7 +183,7 @@ public: PartialPainterWindow(QOpenGLWindow::UpdateBehavior u) : QOpenGLWindow(u), x(0) { } - void paintGL() Q_DECL_OVERRIDE { + void paintGL() override { ++paintCount; QPainter p(this); @@ -212,7 +212,7 @@ void tst_QOpenGLWindow::partial() PartialPainterWindow w(u); w.resize(800, 400); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w)); // Add a couple of small blue rects. for (int i = 0; i < 10; ++i) { @@ -244,7 +244,7 @@ public: Error } m_state; - void paintUnderGL() Q_DECL_OVERRIDE { + void paintUnderGL() override { if (m_state == None || m_state == PaintOver) m_state = PaintUnder; else @@ -252,10 +252,10 @@ public: GLuint fbo = 0xFFFF; QOpenGLContext::currentContext()->functions()->glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *) &fbo); - QCOMPARE(fbo, GLuint(0)); + QCOMPARE(fbo, QOpenGLContext::currentContext()->defaultFramebufferObject()); } - void paintGL() Q_DECL_OVERRIDE { + void paintGL() override { if (m_state == PaintUnder) m_state = Paint; else @@ -264,11 +264,11 @@ public: // Using PartialUpdateBlend so paintGL() targets a user fbo, not the default. GLuint fbo = 0xFFFF; QOpenGLContext::currentContext()->functions()->glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *) &fbo); - QVERIFY(fbo != 0); + QVERIFY(fbo != QOpenGLContext::currentContext()->defaultFramebufferObject()); QCOMPARE(fbo, defaultFramebufferObject()); } - void paintOverGL() Q_DECL_OVERRIDE { + void paintOverGL() override { if (m_state == Paint) m_state = PaintOver; else @@ -276,7 +276,7 @@ public: GLuint fbo = 0xFFFF; QOpenGLContext::currentContext()->functions()->glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *) &fbo); - QCOMPARE(fbo, GLuint(0)); + QCOMPARE(fbo, QOpenGLContext::currentContext()->defaultFramebufferObject()); } }; @@ -285,7 +285,7 @@ void tst_QOpenGLWindow::underOver() PaintUnderOverWindow w; w.resize(400, 400); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w)); // under -> paint -> over -> under -> paint -> ... is the only acceptable sequence QCOMPARE(w.m_state, PaintUnderOverWindow::PaintOver); diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index f43e8d8ee6..ca6f677ba6 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -39,6 +39,7 @@ private Q_SLOTS: void roleValues(); void copySemantics(); void moveSemantics(); + void setBrush(); }; void tst_QPalette::roleValues_data() @@ -128,5 +129,35 @@ void tst_QPalette::moveSemantics() #endif } +void tst_QPalette::setBrush() +{ + QPalette p(Qt::red); + const QPalette q = p; + QVERIFY(q.isCopyOf(p)); + + // Setting a different brush will detach + p.setBrush(QPalette::Disabled, QPalette::Button, Qt::green); + QVERIFY(!q.isCopyOf(p)); + QVERIFY(q != p); + + // Check we only changed what we said we would + for (int i = 0; i < QPalette::NColorGroups; i++) + for (int j = 0; j < QPalette::NColorRoles; j++) { + const auto g = QPalette::ColorGroup(i); + const auto r = QPalette::ColorRole(j); + const auto b = p.brush(g, r); + if (g == QPalette::Disabled && r == QPalette::Button) + QCOMPARE(b, QBrush(Qt::green)); + else + QCOMPARE(b, q.brush(g, r)); + } + + const QPalette pp = p; + QVERIFY(pp.isCopyOf(p)); + // Setting the same brush won't detach + p.setBrush(QPalette::Disabled, QPalette::Button, Qt::green); + QVERIFY(pp.isCopyOf(p)); +} + QTEST_MAIN(tst_QPalette) #include "tst_qpalette.moc" diff --git a/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp b/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp index 41fcdf9f30..ffc440ac2d 100644 --- a/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp +++ b/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp @@ -46,7 +46,7 @@ void tst_QRasterWindow::create() w.resize(640, 480); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w)); } class PainterWindow : public QRasterWindow @@ -54,7 +54,7 @@ class PainterWindow : public QRasterWindow public: void reset() { paintCount = 0; } - void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE { + void paintEvent(QPaintEvent*) override { ++paintCount; QPainter p(this); p.fillRect(QRect(0, 0, 100, 100), Qt::blue); @@ -70,7 +70,7 @@ void tst_QRasterWindow::basic() w.reset(); w.resize(400, 400); w.show(); - QTest::qWaitForWindowExposed(&w); + QVERIFY(QTest::qWaitForWindowExposed(&w));; QVERIFY(w.paintCount >= 1); diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index ec143896ab..706c66ef14 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -48,7 +48,7 @@ public: ulong timestamp; QTouchDevice *deviceFromEvent; - explicit tst_QTouchEventWidget(QWidget *parent = Q_NULLPTR) : QWidget(parent) + explicit tst_QTouchEventWidget(QWidget *parent = nullptr) : QWidget(parent) { reset(); } @@ -63,7 +63,7 @@ public: deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false; } - bool event(QEvent *event) Q_DECL_OVERRIDE + bool event(QEvent *event) override { switch (event->type()) { case QEvent::TouchBegin: @@ -117,7 +117,7 @@ public: bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd; tst_QTouchEventGraphicsItem **weakpointer; - explicit tst_QTouchEventGraphicsItem(QGraphicsItem *parent = Q_NULLPTR) + explicit tst_QTouchEventGraphicsItem(QGraphicsItem *parent = nullptr) : QGraphicsItem(parent), weakpointer(0) { reset(); @@ -140,13 +140,13 @@ public: deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false; } - QRectF boundingRect() const Q_DECL_OVERRIDE { return QRectF(0, 0, 10, 10); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE + QRectF boundingRect() const override { return QRectF(0, 0, 10, 10); } + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->fillRect(QRectF(QPointF(0, 0), boundingRect().size()), Qt::yellow); } - bool sceneEvent(QEvent *event) Q_DECL_OVERRIDE + bool sceneEvent(QEvent *event) override { switch (event->type()) { case QEvent::TouchBegin: @@ -1628,7 +1628,7 @@ class WindowTouchEventFilter : public QObject { Q_OBJECT public: - bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; + bool eventFilter(QObject *obj, QEvent *event) override; struct TouchInfo { QList<QTouchEvent::TouchPoint> points; QEvent::Type lastSeenType; diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST index cb18651091..05cf1b5a30 100644 --- a/tests/auto/gui/kernel/qwindow/BLACKLIST +++ b/tests/auto/gui/kernel/qwindow/BLACKLIST @@ -4,20 +4,20 @@ osx-10.12 ci [positioning:fake] osx-10.12 ci [modalWindowPosition] -ubuntu-14.04 ubuntu-16.04 [modalWithChildWindow] -ubuntu-14.04 ubuntu-16.04 [setVisible] -ubuntu-14.04 [modalWindowEnterEventOnHide_QTBUG35109] -ubuntu-14.04 ubuntu-16.04 osx ci [modalDialogClosingOneOfTwoModal] osx [modalWindowModallity] osx +[visibility] +osx-10.11 ci +osx-10.12 ci + [testInputEvents] rhel-7.4 diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 5145c22356..18723458f6 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -106,6 +106,7 @@ private slots: void flags(); void cleanup(); void testBlockingWindowShownAfterModalDialog(); + void generatedMouseMove(); private: QPoint m_availableTopLeft; @@ -269,12 +270,21 @@ class Window : public QWindow { public: Window(const Qt::WindowFlags flags = Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint) + : QWindow(), lastReceivedWindowState(windowState()) { reset(); setFlags(flags); #if defined(Q_OS_QNX) setSurfaceType(QSurface::OpenGLSurface); #endif + +#if !defined(Q_OS_MACOS) + // FIXME: All platforms should send window-state change events, regardless + // of the sync/async nature of the the underlying platform, but they don't. + connect(this, &QWindow::windowStateChanged, [=]() { + lastReceivedWindowState = windowState(); + }); +#endif } void reset() @@ -299,6 +309,10 @@ public: case QEvent::Move: m_framePositionsOnMove << framePosition(); break; + + case QEvent::WindowStateChange: + lastReceivedWindowState = windowState(); + default: break; } @@ -327,6 +341,8 @@ public: } QVector<QPoint> m_framePositionsOnMove; + Qt::WindowStates lastReceivedWindowState; + private: QHash<QEvent::Type, int> m_received; QVector<QEvent::Type> m_order; @@ -337,7 +353,7 @@ private: class ColoredWindow : public QRasterWindow { public: explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {} - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE + void paintEvent(QPaintEvent *) override { QPainter p(this); p.fillRect(QRect(QPoint(0, 0), size()), m_color); @@ -475,7 +491,7 @@ void tst_QWindow::positioning() window.showNormal(); QCoreApplication::processEvents(); - QTest::qWaitForWindowExposed(&window); + QVERIFY(QTest::qWaitForWindowExposed(&window)); QMargins originalMargins = window.frameMargins(); @@ -487,17 +503,15 @@ void tst_QWindow::positioning() window.reset(); window.setWindowState(Qt::WindowFullScreen); - QCoreApplication::processEvents(); + QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowFullScreen); QTRY_VERIFY(window.received(QEvent::Resize) > 0); - QTest::qWait(2000); window.reset(); window.setWindowState(Qt::WindowNoState); - QCoreApplication::processEvents(); + QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowNoState); QTRY_VERIFY(window.received(QEvent::Resize) > 0); - QTest::qWait(2000); QTRY_COMPARE(originalPos, window.position()); QTRY_COMPARE(originalFramePos, window.framePosition()); @@ -689,7 +703,7 @@ class PlatformWindowFilter : public QObject public: PlatformWindowFilter(QObject *parent = 0) : QObject(parent) - , m_window(Q_NULLPTR) + , m_window(nullptr) , m_alwaysExisted(true) {} @@ -701,7 +715,7 @@ public: // If they are, the native platform surface should always exist when we // receive a QPlatformSurfaceEvent if (e->type() == QEvent::PlatformSurface && o == m_window) { - m_alwaysExisted &= (m_window->handle() != Q_NULLPTR); + m_alwaysExisted &= (m_window->handle() != nullptr); } return false; } @@ -728,7 +742,7 @@ void tst_QWindow::platformSurface() QTRY_COMPARE(window.received(QEvent::PlatformSurface), 1); QTRY_COMPARE(window.surfaceEventType(), QPlatformSurfaceEvent::SurfaceCreated); - QTRY_VERIFY(window.handle() != Q_NULLPTR); + QTRY_VERIFY(window.handle() != nullptr); window.destroy(); QTRY_COMPARE(window.received(QEvent::PlatformSurface), 2); @@ -905,6 +919,7 @@ public: } } void mouseMoveEvent(QMouseEvent *event) { + buttonStateInGeneratedMove = event->buttons(); if (ignoreMouse) { event->ignore(); } else { @@ -986,6 +1001,7 @@ public: bool ignoreMouse, ignoreTouch; bool spinLoopWhenPressed; + Qt::MouseButtons buttonStateInGeneratedMove; }; void tst_QWindow::testInputEvents() @@ -1470,7 +1486,7 @@ void tst_QWindow::activateAndClose() window.showNormal(); #if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store // and then post the window in order for screen to show the window - QTest::qWaitForWindowExposed(&window); + QVERIFY(QTest::qWaitForWindowExposed(&window)); QOpenGLContext context; context.create(); context.makeCurrent(&window); @@ -1753,7 +1769,7 @@ void tst_QWindow::visibility() { qRegisterMetaType<Qt::WindowModality>("QWindow::Visibility"); - QWindow window; + Window window; QSignalSpy spy(&window, SIGNAL(visibilityChanged(QWindow::Visibility))); window.setVisibility(QWindow::AutomaticVisibility); @@ -1774,11 +1790,13 @@ void tst_QWindow::visibility() QCOMPARE(window.windowState(), Qt::WindowFullScreen); QCOMPARE(window.visibility(), QWindow::FullScreen); QCOMPARE(spy.count(), 1); + QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowFullScreen); spy.clear(); window.setWindowState(Qt::WindowNoState); QCOMPARE(window.visibility(), QWindow::Windowed); QCOMPARE(spy.count(), 1); + QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowNoState); spy.clear(); window.setVisible(false); @@ -1791,16 +1809,27 @@ void tst_QWindow::mask() { QRegion mask = QRect(10, 10, 800 - 20, 600 - 20); - QWindow window; - window.resize(800, 600); - window.setMask(mask); + { + QWindow window; + window.resize(800, 600); + QCOMPARE(window.mask(), QRegion()); - QCOMPARE(window.mask(), QRegion()); + window.create(); + window.setMask(mask); + QCOMPARE(window.mask(), mask); + } - window.create(); - window.setMask(mask); + { + QWindow window; + window.resize(800, 600); + QCOMPARE(window.mask(), QRegion()); + + window.setMask(mask); + QCOMPARE(window.mask(), mask); + window.create(); + QCOMPARE(window.mask(), mask); + } - QCOMPARE(window.mask(), mask); } void tst_QWindow::initialSize() @@ -1845,6 +1874,9 @@ void tst_QWindow::modalDialog() if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); + if (QGuiApplication::platformName() == QLatin1String("cocoa")) + QSKIP("Test fails due to QTBUG-61965, and is slow due to QTBUG-61964"); + QWindow normalWindow; normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.resize(m_testWindowSize); @@ -2284,6 +2316,56 @@ void tst_QWindow::testBlockingWindowShownAfterModalDialog() QVERIFY(normalWindowAfter.gotBlocked); } +void tst_QWindow::generatedMouseMove() +{ + InputTestWindow w; + w.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); + w.show(); + QVERIFY(QTest::qWaitForWindowActive(&w)); + QPoint point(10, 10); + QPoint step(2, 2); + + QVERIFY(w.mouseMovedCount == 0); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::NoButton, QEvent::MouseMove); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 1); + // Press that does not change position should not generate mouse move + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton | Qt::RightButton, Qt::RightButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 1); + + // Test moves generated for mouse release + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::RightButton, Qt::LeftButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 2); + QVERIFY(w.buttonStateInGeneratedMove == (Qt::LeftButton | Qt::RightButton)); + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::RightButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 3); + QVERIFY(w.buttonStateInGeneratedMove == Qt::RightButton); + + // Test moves generated for mouse press + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 4); + QVERIFY(w.buttonStateInGeneratedMove == Qt::NoButton); + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton | Qt::RightButton, Qt::RightButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 5); + QVERIFY(w.buttonStateInGeneratedMove == Qt::LeftButton); + + // Release that does not change position should not generate mouse move + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::RightButton, QEvent::MouseButtonRelease); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::LeftButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 5); +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow) |