diff options
Diffstat (limited to 'tests/auto/gui/kernel/qwindow/tst_qwindow.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 113 |
1 files changed, 104 insertions, 9 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 61ba99c7de..89490525c9 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -63,6 +63,7 @@ private slots: void positioning_data(); void positioning(); void positioningDuringMinimized(); + void platformSurface(); void isExposed(); void isActive(); void testInputEvents(); @@ -90,6 +91,7 @@ private slots: void modalWindowModallity(); void modalWindowPosition(); void windowsTransientChildren(); + void requestUpdate(); void initTestCase(); void cleanup(); @@ -161,10 +163,21 @@ public: { m_received[event->type()]++; m_order << event->type(); - if (event->type() == QEvent::Expose) + switch (event->type()) { + case QEvent::Expose: m_exposeRegion = static_cast<QExposeEvent *>(event)->region(); - else if (event->type() == QEvent::Move) + break; + + case QEvent::PlatformSurface: + m_surfaceventType = static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType(); + break; + + case QEvent::Move: m_framePositionsOnMove << framePosition(); + break; + default: + break; + } return QWindow::event(event); } @@ -184,11 +197,17 @@ public: return m_exposeRegion; } + QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const + { + return m_surfaceventType; + } + QVector<QPoint> m_framePositionsOnMove; private: QHash<QEvent::Type, int> m_received; QVector<QEvent::Type> m_order; QRegion m_exposeRegion; + QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType; }; void tst_QWindow::eventOrderOnShow() @@ -355,6 +374,63 @@ void tst_QWindow::positioningDuringMinimized() QTRY_COMPARE(window.geometry(), newGeometry); } +class PlatformWindowFilter : public QObject +{ + Q_OBJECT +public: + PlatformWindowFilter(QObject *parent = 0) + : QObject(parent) + , m_window(Q_NULLPTR) + , m_alwaysExisted(true) + {} + + void setWindow(Window *window) { m_window = window; } + + bool eventFilter(QObject *o, QEvent *e) + { + // Check that the platform surface events are delivered synchronously. + // 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); + } + return false; + } + + bool surfaceExisted() const { return m_alwaysExisted; } + +private: + Window *m_window; + bool m_alwaysExisted; +}; + +void tst_QWindow::platformSurface() +{ + QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); + + Window window; + PlatformWindowFilter filter; + filter.setWindow(&window); + window.installEventFilter(&filter); + + window.setGeometry(geometry); + QCOMPARE(window.geometry(), geometry); + window.create(); + + QTRY_VERIFY(window.received(QEvent::PlatformSurface) == 1); + QTRY_VERIFY(window.surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated); + QTRY_VERIFY(window.handle() != Q_NULLPTR); + + window.destroy(); + QTRY_VERIFY(window.received(QEvent::PlatformSurface) == 2); + QTRY_VERIFY(window.surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed); + QTRY_VERIFY(window.handle() == Q_NULLPTR); + + // Check for synchronous delivery of platform surface events and that the platform + // surface always existed upon event delivery + QTRY_VERIFY(filter.surfaceExisted()); +} + void tst_QWindow::isExposed() { QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); @@ -1591,6 +1667,25 @@ void tst_QWindow::windowsTransientChildren() QVERIFY(isNativeWindowVisible(&child)); // Real children should be visible. } +void tst_QWindow::requestUpdate() +{ + QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); + + Window window; + window.setGeometry(geometry); + window.show(); + QCoreApplication::processEvents(); + QTRY_VERIFY(window.isExposed()); + + QVERIFY(window.received(QEvent::UpdateRequest) == 0); + + window.requestUpdate(); + QTRY_VERIFY(window.received(QEvent::UpdateRequest) == 1); + + window.requestUpdate(); + QTRY_VERIFY(window.received(QEvent::UpdateRequest) == 2); +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow) |