From 087fcc61824a54e49e68b9090b2983ef7dd18ddb Mon Sep 17 00:00:00 2001 From: Jo Asplin Date: Thu, 3 Nov 2011 10:12:44 +0100 Subject: Moved tests into gui/kernel/ and gui/qopengl/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit moves tests from test/auto/ into more appropriate locations (i.e. matching the locations in the Qt source): - qscreen and qwindow are moved into gui/kernel/ - qopengl is moved into gui/qopengl/ Note: qscreen is disabled for now since it is broken on Linux (see QTBUG-22554). Change-Id: Idcc7a51e78d6d0955bddb9cb4091866659193cc8 Reviewed-by: Samuel Rødal --- tests/auto/gui.pro | 1 - tests/auto/gui/gui.pro | 2 +- tests/auto/gui/kernel/kernel.pro | 5 +- tests/auto/gui/kernel/qscreen/qscreen.pro | 8 + tests/auto/gui/kernel/qscreen/tst_qscreen.cpp | 167 ++++++++++ tests/auto/gui/kernel/qwindow/qwindow.pro | 7 + tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 225 +++++++++++++ tests/auto/gui/qopengl/qopengl.pro | 11 + tests/auto/gui/qopengl/tst_qopengl.cpp | 440 ++++++++++++++++++++++++++ tests/auto/opengl/opengl.pro | 3 +- tests/auto/qopengl/qopengl.pro | 11 - tests/auto/qopengl/tst_qopengl.cpp | 440 -------------------------- tests/auto/qscreen/qscreen.pro | 7 - tests/auto/qscreen/tst_qscreen.cpp | 167 ---------- tests/auto/qwindow/qwindow.pro | 7 - tests/auto/qwindow/tst_qwindow.cpp | 225 ------------- 16 files changed, 863 insertions(+), 863 deletions(-) create mode 100644 tests/auto/gui/kernel/qscreen/qscreen.pro create mode 100644 tests/auto/gui/kernel/qscreen/tst_qscreen.cpp create mode 100644 tests/auto/gui/kernel/qwindow/qwindow.pro create mode 100644 tests/auto/gui/kernel/qwindow/tst_qwindow.cpp create mode 100644 tests/auto/gui/qopengl/qopengl.pro create mode 100644 tests/auto/gui/qopengl/tst_qopengl.cpp delete mode 100644 tests/auto/qopengl/qopengl.pro delete mode 100644 tests/auto/qopengl/tst_qopengl.cpp delete mode 100644 tests/auto/qscreen/qscreen.pro delete mode 100644 tests/auto/qscreen/tst_qscreen.cpp delete mode 100644 tests/auto/qwindow/qwindow.pro delete mode 100644 tests/auto/qwindow/tst_qwindow.cpp (limited to 'tests/auto') diff --git a/tests/auto/gui.pro b/tests/auto/gui.pro index 4f684869f4..2a954e7977 100644 --- a/tests/auto/gui.pro +++ b/tests/auto/gui.pro @@ -6,7 +6,6 @@ TEMPLATE=subdirs SUBDIRS=\ gui \ - qopengl \ qtransformedscreen \ qwindowsurface \ qwsembedwidget \ diff --git a/tests/auto/gui/gui.pro b/tests/auto/gui/gui.pro index d54198467d..48fa2772f9 100644 --- a/tests/auto/gui/gui.pro +++ b/tests/auto/gui/gui.pro @@ -4,6 +4,6 @@ SUBDIRS=\ kernel \ math3d \ painting \ + qopengl \ text \ util \ - diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 16bda68629..e473463828 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -4,13 +4,14 @@ SUBDIRS=\ qdrag \ qevent \ qfileopenevent \ - qinputpanel \ qguimetatype \ qguivariant \ + qinputpanel \ qkeysequence \ qmouseevent \ qmouseevent_modal \ qpalette \ + qscreen \ qshortcut \ qtouchevent \ - + qwindow \ diff --git a/tests/auto/gui/kernel/qscreen/qscreen.pro b/tests/auto/gui/kernel/qscreen/qscreen.pro new file mode 100644 index 0000000000..4ed8eefa1a --- /dev/null +++ b/tests/auto/gui/kernel/qscreen/qscreen.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qscreen + +QT += core-private gui-private testlib + +SOURCES += tst_qscreen.cpp + +CONFIG += insignificant_test # QTBUG-22554 diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp new file mode 100644 index 0000000000..1d00032b56 --- /dev/null +++ b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +class tst_QScreen: public QObject +{ + Q_OBJECT + +private slots: + void angleBetween_data(); + void angleBetween(); + void transformBetween_data(); + void transformBetween(); +}; + +void tst_QScreen::angleBetween_data() +{ + QTest::addColumn("oa"); + QTest::addColumn("ob"); + QTest::addColumn("expected"); + + QTest::newRow("Portrait Portrait") + << uint(Qt::PortraitOrientation) + << uint(Qt::PortraitOrientation) + << 0; + + QTest::newRow("Portrait Landscape") + << uint(Qt::PortraitOrientation) + << uint(Qt::LandscapeOrientation) + << 270; + + QTest::newRow("Portrait InvertedPortrait") + << uint(Qt::PortraitOrientation) + << uint(Qt::InvertedPortraitOrientation) + << 180; + + QTest::newRow("Portrait InvertedLandscape") + << uint(Qt::PortraitOrientation) + << uint(Qt::InvertedLandscapeOrientation) + << 90; + + QTest::newRow("InvertedLandscape InvertedPortrait") + << uint(Qt::InvertedLandscapeOrientation) + << uint(Qt::InvertedPortraitOrientation) + << 90; + + QTest::newRow("InvertedLandscape Landscape") + << uint(Qt::InvertedLandscapeOrientation) + << uint(Qt::LandscapeOrientation) + << 180; +} + +void tst_QScreen::angleBetween() +{ + QFETCH( uint, oa ); + QFETCH( uint, ob ); + QFETCH( int, expected ); + + Qt::ScreenOrientation a = Qt::ScreenOrientation(oa); + Qt::ScreenOrientation b = Qt::ScreenOrientation(ob); + + QCOMPARE(QScreen::angleBetween(a, b), expected); + QCOMPARE(QScreen::angleBetween(b, a), (360 - expected) % 360); +} + +void tst_QScreen::transformBetween_data() +{ + QTest::addColumn("oa"); + QTest::addColumn("ob"); + QTest::addColumn("rect"); + QTest::addColumn("expected"); + + QRect rect(0, 0, 480, 640); + + QTest::newRow("Portrait Portrait") + << uint(Qt::PortraitOrientation) + << uint(Qt::PortraitOrientation) + << rect + << QTransform(); + + QTest::newRow("Portrait Landscape") + << uint(Qt::PortraitOrientation) + << uint(Qt::LandscapeOrientation) + << rect + << QTransform(0, -1, 1, 0, 0, rect.height()); + + QTest::newRow("Portrait InvertedPortrait") + << uint(Qt::PortraitOrientation) + << uint(Qt::InvertedPortraitOrientation) + << rect + << QTransform(-1, 0, 0, -1, rect.width(), rect.height()); + + QTest::newRow("Portrait InvertedLandscape") + << uint(Qt::PortraitOrientation) + << uint(Qt::InvertedLandscapeOrientation) + << rect + << QTransform(0, 1, -1, 0, rect.width(), 0); + + QTest::newRow("InvertedLandscape InvertedPortrait") + << uint(Qt::InvertedLandscapeOrientation) + << uint(Qt::InvertedPortraitOrientation) + << rect + << QTransform(0, 1, -1, 0, rect.width(), 0); + + QTest::newRow("InvertedLandscape Landscape") + << uint(Qt::InvertedLandscapeOrientation) + << uint(Qt::LandscapeOrientation) + << rect + << QTransform(-1, 0, 0, -1, rect.width(), rect.height()); +} + +void tst_QScreen::transformBetween() +{ + QFETCH( uint, oa ); + QFETCH( uint, ob ); + QFETCH( QRect, rect ); + QFETCH( QTransform, expected ); + + Qt::ScreenOrientation a = Qt::ScreenOrientation(oa); + Qt::ScreenOrientation b = Qt::ScreenOrientation(ob); + + QCOMPARE(QScreen::transformBetween(a, b, rect), expected); +} + +#include +QTEST_MAIN(tst_QScreen); diff --git a/tests/auto/gui/kernel/qwindow/qwindow.pro b/tests/auto/gui/kernel/qwindow/qwindow.pro new file mode 100644 index 0000000000..9fb49e8ceb --- /dev/null +++ b/tests/auto/gui/kernel/qwindow/qwindow.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TARGET = tst_qwindow + +QT += core-private gui-private testlib + +SOURCES += tst_qwindow.cpp + diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp new file mode 100644 index 0000000000..4171f0f797 --- /dev/null +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +class tst_QWindow: public QObject +{ + Q_OBJECT + +private slots: + void mapGlobal(); + void positioning(); + void isActive(); +}; + + +void tst_QWindow::mapGlobal() +{ + QWindow a; + QWindow b(&a); + QWindow c(&b); + + a.setGeometry(10, 10, 300, 300); + b.setGeometry(20, 20, 200, 200); + c.setGeometry(40, 40, 100, 100); + + QCOMPARE(a.mapToGlobal(QPoint(100, 100)), QPoint(110, 110)); + QCOMPARE(b.mapToGlobal(QPoint(100, 100)), QPoint(130, 130)); + QCOMPARE(c.mapToGlobal(QPoint(100, 100)), QPoint(170, 170)); + + QCOMPARE(a.mapFromGlobal(QPoint(100, 100)), QPoint(90, 90)); + QCOMPARE(b.mapFromGlobal(QPoint(100, 100)), QPoint(70, 70)); + QCOMPARE(c.mapFromGlobal(QPoint(100, 100)), QPoint(30, 30)); +} + +class Window : public QWindow +{ +public: + Window() + { + reset(); + setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); + } + + void reset() + { + m_received.clear(); + } + + bool event(QEvent *event) + { + m_received[event->type()]++; + + return QWindow::event(event); + } + + int received(QEvent::Type type) + { + return m_received.value(type, 0); + } + +private: + QHash m_received; +}; + +void tst_QWindow::positioning() +{ + QRect geometry(80, 80, 40, 40); + + Window window; + window.setGeometry(geometry); + QCOMPARE(window.geometry(), geometry); + window.show(); + + QTRY_COMPARE(window.received(QEvent::Resize), 1); + QTRY_COMPARE(window.received(QEvent::Map), 1); + + QMargins originalMargins = window.frameMargins(); + + QCOMPARE(window.pos(), window.framePos() + QPoint(originalMargins.left(), originalMargins.top())); + QVERIFY(window.frameGeometry().contains(window.geometry())); + + QPoint originalPos = window.pos(); + QPoint originalFramePos = window.framePos(); + + window.setWindowState(Qt::WindowFullScreen); + QTRY_COMPARE(window.received(QEvent::Resize), 2); + + window.setWindowState(Qt::WindowNoState); + QTRY_COMPARE(window.received(QEvent::Resize), 3); + + QTRY_COMPARE(originalPos, window.pos()); + QTRY_COMPARE(originalFramePos, window.framePos()); + QTRY_COMPARE(originalMargins, window.frameMargins()); + + // if our positioning is actually fully respected by the window manager + // test whether it correctly handles frame positioning as well + if (originalPos == geometry.topLeft() && (originalMargins.top() != 0 || originalMargins.left() != 0)) { + QPoint framePos(40, 40); + + window.reset(); + window.setFramePos(framePos); + + QTRY_VERIFY(window.received(QEvent::Move)); + QTRY_COMPARE(framePos, window.framePos()); + QTRY_COMPARE(originalMargins, window.frameMargins()); + QCOMPARE(window.pos(), window.framePos() + QPoint(originalMargins.left(), originalMargins.top())); + + // and back to regular positioning + + window.reset(); + window.setPos(originalPos); + QTRY_VERIFY(window.received(QEvent::Move)); + QTRY_COMPARE(originalPos, window.pos()); + } +} + +void tst_QWindow::isActive() +{ + Window window; + window.setGeometry(80, 80, 40, 40); + window.show(); + + QTRY_COMPARE(window.received(QEvent::Map), 1); + QTRY_COMPARE(window.received(QEvent::Resize), 1); + QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QVERIFY(window.isActive()); + + Window child; + child.setParent(&window); + child.setGeometry(10, 10, 20, 20); + child.show(); + + QTRY_COMPARE(child.received(QEvent::Map), 1); + + child.requestActivateWindow(); + + QTRY_VERIFY(QGuiApplication::focusWindow() == &child); + QVERIFY(child.isActive()); + + // parent shouldn't receive new map or resize events from child being shown + QTRY_COMPARE(window.received(QEvent::Map), 1); + QTRY_COMPARE(window.received(QEvent::Resize), 1); + QTRY_COMPARE(window.received(QEvent::FocusIn), 1); + QTRY_COMPARE(window.received(QEvent::FocusOut), 1); + QTRY_COMPARE(child.received(QEvent::FocusIn), 1); + + // child has focus + QVERIFY(window.isActive()); + + Window dialog; + dialog.setTransientParent(&window); + dialog.setGeometry(110, 110, 30, 30); + dialog.show(); + + dialog.requestActivateWindow(); + + QTRY_COMPARE(dialog.received(QEvent::Map), 1); + QTRY_COMPARE(dialog.received(QEvent::Resize), 1); + QTRY_VERIFY(QGuiApplication::focusWindow() == &dialog); + QVERIFY(dialog.isActive()); + + // transient child has focus + QVERIFY(window.isActive()); + + // parent is active + QVERIFY(child.isActive()); + + window.requestActivateWindow(); + + QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(dialog.received(QEvent::FocusOut), 1); + QTRY_COMPARE(window.received(QEvent::FocusIn), 2); + + QVERIFY(window.isActive()); + + // transient parent has focus + QVERIFY(dialog.isActive()); + + // parent has focus + QVERIFY(child.isActive()); +} + +#include +QTEST_MAIN(tst_QWindow); diff --git a/tests/auto/gui/qopengl/qopengl.pro b/tests/auto/gui/qopengl/qopengl.pro new file mode 100644 index 0000000000..f281c6c439 --- /dev/null +++ b/tests/auto/gui/qopengl/qopengl.pro @@ -0,0 +1,11 @@ +############################################################ +# Project file for autotest for gui/opengl functionality +############################################################ + +CONFIG += testcase +TARGET = tst_qopengl +QT += gui gui-private core-private testlib + +SOURCES += tst_qopengl.cpp + +CONFIG += insignificant_test diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp new file mode 100644 index 0000000000..ebff56fd5c --- /dev/null +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -0,0 +1,440 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#include + +class tst_QOpenGL : public QObject +{ +Q_OBJECT + +private slots: + void sharedResourceCleanup(); + void fboSimpleRendering(); + void fboRendering(); + void fboHandleNulledAfterContextDestroyed(); + void openGLPaintDevice(); +}; + +struct SharedResourceTracker +{ + SharedResourceTracker() + { + reset(); + } + + void reset() + { + invalidateResourceCalls = 0; + freeResourceCalls = 0; + destructorCalls = 0; + } + + int invalidateResourceCalls; + int freeResourceCalls; + int destructorCalls; +}; + +struct SharedResource : public QOpenGLSharedResource +{ + SharedResource(SharedResourceTracker *t) + : QOpenGLSharedResource(QOpenGLContextGroup::currentContextGroup()) + , resource(1) + , tracker(t) + { + } + + ~SharedResource() + { + tracker->destructorCalls++; + } + + void invalidateResource() + { + resource = 0; + tracker->invalidateResourceCalls++; + } + + void freeResource(QOpenGLContext *context) + { + Q_ASSERT(context == QOpenGLContext::currentContext()); + resource = 0; + tracker->freeResourceCalls++; + } + + int resource; + SharedResourceTracker *tracker; +}; + +void tst_QOpenGL::sharedResourceCleanup() +{ + QWindow window; + window.setGeometry(0, 0, 10, 10); + window.create(); + + QOpenGLContext *ctx = new QOpenGLContext; + ctx->create(); + ctx->makeCurrent(&window); + + SharedResourceTracker tracker; + SharedResource *resource = new SharedResource(&tracker); + resource->free(); + + QCOMPARE(tracker.invalidateResourceCalls, 0); + QCOMPARE(tracker.freeResourceCalls, 1); + QCOMPARE(tracker.destructorCalls, 1); + + tracker.reset(); + + resource = new SharedResource(&tracker); + + QOpenGLContext *ctx2 = new QOpenGLContext; + ctx2->setShareContext(ctx); + ctx2->create(); + delete ctx; + + resource->free(); + + // no current context, freeResource() delayed + QCOMPARE(tracker.invalidateResourceCalls, 0); + QCOMPARE(tracker.freeResourceCalls, 0); + QCOMPARE(tracker.destructorCalls, 0); + + ctx2->makeCurrent(&window); + + // freeResource() should now have been called + QCOMPARE(tracker.invalidateResourceCalls, 0); + QCOMPARE(tracker.freeResourceCalls, 1); + QCOMPARE(tracker.destructorCalls, 1); + + tracker.reset(); + + resource = new SharedResource(&tracker); + + // this should cause invalidateResource() to be called + delete ctx2; + + QCOMPARE(tracker.invalidateResourceCalls, 1); + QCOMPARE(tracker.freeResourceCalls, 0); + QCOMPARE(tracker.destructorCalls, 0); + + // should have no effect other than destroying the resource, + // as it has already been invalidated + resource->free(); + + QCOMPARE(tracker.invalidateResourceCalls, 1); + QCOMPARE(tracker.freeResourceCalls, 0); + QCOMPARE(tracker.destructorCalls, 1); +} + +static bool fuzzyComparePixels(const QRgb testPixel, const QRgb refPixel, const char* file, int line, int x = -1, int y = -1) +{ + static int maxFuzz = 1; + static bool maxFuzzSet = false; + + // On 16 bpp systems, we need to allow for more fuzz: + if (!maxFuzzSet) { + maxFuzzSet = true; + if (QGuiApplication::primaryScreen()->depth() < 24) + maxFuzz = 32; + } + + int redFuzz = qAbs(qRed(testPixel) - qRed(refPixel)); + int greenFuzz = qAbs(qGreen(testPixel) - qGreen(refPixel)); + int blueFuzz = qAbs(qBlue(testPixel) - qBlue(refPixel)); + int alphaFuzz = qAbs(qAlpha(testPixel) - qAlpha(refPixel)); + + if (refPixel != 0 && testPixel == 0) { + QString msg; + if (x >= 0) { + msg = QString("Test pixel [%1, %2] is null (black) when it should be (%3,%4,%5,%6)") + .arg(x).arg(y) + .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); + } else { + msg = QString("Test pixel is null (black) when it should be (%2,%3,%4,%5)") + .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); + } + + QTest::qFail(msg.toLatin1(), file, line); + return false; + } + + if (redFuzz > maxFuzz || greenFuzz > maxFuzz || blueFuzz > maxFuzz || alphaFuzz > maxFuzz) { + QString msg; + + if (x >= 0) + msg = QString("Pixel [%1,%2]: ").arg(x).arg(y); + else + msg = QString("Pixel "); + + msg += QString("Max fuzz (%1) exceeded: (%2,%3,%4,%5) vs (%6,%7,%8,%9)") + .arg(maxFuzz) + .arg(qRed(testPixel)).arg(qGreen(testPixel)).arg(qBlue(testPixel)).arg(qAlpha(testPixel)) + .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); + QTest::qFail(msg.toLatin1(), file, line); + return false; + } + return true; +} + +static void fuzzyCompareImages(const QImage &testImage, const QImage &referenceImage, const char* file, int line) +{ + QCOMPARE(testImage.width(), referenceImage.width()); + QCOMPARE(testImage.height(), referenceImage.height()); + + for (int y = 0; y < testImage.height(); y++) { + for (int x = 0; x < testImage.width(); x++) { + if (!fuzzyComparePixels(testImage.pixel(x, y), referenceImage.pixel(x, y), file, line, x, y)) { + // Might as well save the images for easier debugging: + referenceImage.save("referenceImage.png"); + testImage.save("testImage.png"); + return; + } + } + } +} + +#define QFUZZY_COMPARE_IMAGES(A,B) \ + fuzzyCompareImages(A, B, __FILE__, __LINE__) + +#define QFUZZY_COMPARE_PIXELS(A,B) \ + fuzzyComparePixels(A, B, __FILE__, __LINE__) + +void qt_opengl_draw_test_pattern(QPainter* painter, int width, int height) +{ + QPainterPath intersectingPath; + intersectingPath.moveTo(0, 0); + intersectingPath.lineTo(100, 0); + intersectingPath.lineTo(0, 100); + intersectingPath.lineTo(100, 100); + intersectingPath.closeSubpath(); + + QPainterPath trianglePath; + trianglePath.moveTo(50, 0); + trianglePath.lineTo(100, 100); + trianglePath.lineTo(0, 100); + trianglePath.closeSubpath(); + + painter->setTransform(QTransform()); // reset xform + painter->fillRect(-1, -1, width+2, height+2, Qt::red); // Background + painter->translate(14, 14); + painter->fillPath(intersectingPath, Qt::blue); // Test stencil buffer works + painter->translate(128, 0); + painter->setClipPath(trianglePath); // Test depth buffer works + painter->setTransform(QTransform()); // reset xform ready for fill + painter->fillRect(-1, -1, width+2, height+2, Qt::green); +} + +void qt_opengl_check_test_pattern(const QImage& img) +{ + // As we're doing more than trivial painting, we can't just compare to + // an image rendered with raster. Instead, we sample at well-defined + // test-points: + QFUZZY_COMPARE_PIXELS(img.pixel(39, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(89, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(64, 39), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(64, 89), QColor(Qt::blue).rgb()); + + QFUZZY_COMPARE_PIXELS(img.pixel(167, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(217, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(192, 64), QColor(Qt::green).rgb()); +} + + +void tst_QOpenGL::fboSimpleRendering() +{ + QWindow window; + window.setGeometry(0, 0, 10, 10); + window.create(); + QOpenGLContext ctx; + ctx.create(); + + ctx.makeCurrent(&window); + + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QOpenGLFramebufferObject not supported on this platform"); + + // No multisample with combined depth/stencil attachment: + QOpenGLFramebufferObjectFormat fboFormat; + fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment); + + QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat); + + fbo->bind(); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + glFinish(); + + QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); + QImage reference(fb.size(), QImage::Format_RGB32); + reference.fill(0xffff0000); + + QFUZZY_COMPARE_IMAGES(fb, reference); + + delete fbo; +} + +// NOTE: This tests that CombinedDepthStencil attachment works by assuming the +// GL2 engine is being used and is implemented the same way as it was when +// this autotest was written. If this is not the case, there may be some +// false-positives: I.e. The test passes when either the depth or stencil +// buffer is actually missing. But that's probably ok anyway. +void tst_QOpenGL::fboRendering() +{ + QWindow window; + window.setGeometry(0, 0, 10, 10); + window.create(); + QOpenGLContext ctx; + ctx.create(); + + ctx.makeCurrent(&window); + + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QOpenGLFramebufferObject not supported on this platform"); + + // No multisample with combined depth/stencil attachment: + QOpenGLFramebufferObjectFormat fboFormat; + fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + + // Uncomplicate things by using NPOT: + QOpenGLFramebufferObject fbo(256, 128, fboFormat); + + if (fbo.attachment() != QOpenGLFramebufferObject::CombinedDepthStencil) + QSKIP("FBOs missing combined depth~stencil support"); + + fbo.bind(); + + QPainter fboPainter; + QOpenGLPaintDevice device(fbo.width(), fbo.height()); + bool painterBegun = fboPainter.begin(&device); + QVERIFY(painterBegun); + + qt_opengl_draw_test_pattern(&fboPainter, fbo.width(), fbo.height()); + + fboPainter.end(); + + QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32); + + qt_opengl_check_test_pattern(fb); +} + +void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() +{ + QWindow window; + window.setGeometry(0, 0, 10, 10); + window.create(); + + QOpenGLFramebufferObject *fbo = 0; + + { + QOpenGLContext ctx; + ctx.create(); + + ctx.makeCurrent(&window); + + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QOpenGLFramebufferObject not supported on this platform"); + + fbo = new QOpenGLFramebufferObject(128, 128); + + QVERIFY(fbo->handle() != 0); + } + + QCOMPARE(fbo->handle(), 0U); +} + +void tst_QOpenGL::openGLPaintDevice() +{ + QWindow window; + window.setGeometry(0, 0, 128, 128); + window.create(); + + QOpenGLContext ctx; + ctx.create(); + + ctx.makeCurrent(&window); + + QImage image(128, 128, QImage::Format_RGB32); + QPainter p(&image); + p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); + p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); + p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); + p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); + p.end(); + + QOpenGLFramebufferObject fbo(128, 128); + fbo.bind(); + + QOpenGLPaintDevice device(128, 128); + p.begin(&device); + p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); + p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); + p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); + p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); + p.end(); + + QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); + + p.begin(&device); + p.fillRect(0, 0, image.width(), image.height(), Qt::black); + p.drawImage(0, 0, image); + p.end(); + + QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); + + p.begin(&device); + p.fillRect(0, 0, image.width(), image.height(), Qt::black); + p.fillRect(0, 0, image.width(), image.height(), QBrush(image)); + p.end(); + + QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); +} + +QTEST_MAIN(tst_QOpenGL) +#include "tst_qopengl.moc" diff --git a/tests/auto/opengl/opengl.pro b/tests/auto/opengl/opengl.pro index 6c8e4ca96b..963cda170d 100644 --- a/tests/auto/opengl/opengl.pro +++ b/tests/auto/opengl/opengl.pro @@ -1,7 +1,6 @@ TEMPLATE=subdirs SUBDIRS=\ qgl \ - qglthreads \ qglbuffer \ qglfunctions \ - + qglthreads \ diff --git a/tests/auto/qopengl/qopengl.pro b/tests/auto/qopengl/qopengl.pro deleted file mode 100644 index f281c6c439..0000000000 --- a/tests/auto/qopengl/qopengl.pro +++ /dev/null @@ -1,11 +0,0 @@ -############################################################ -# Project file for autotest for gui/opengl functionality -############################################################ - -CONFIG += testcase -TARGET = tst_qopengl -QT += gui gui-private core-private testlib - -SOURCES += tst_qopengl.cpp - -CONFIG += insignificant_test diff --git a/tests/auto/qopengl/tst_qopengl.cpp b/tests/auto/qopengl/tst_qopengl.cpp deleted file mode 100644 index ebff56fd5c..0000000000 --- a/tests/auto/qopengl/tst_qopengl.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include -#include -#include -#include - -#include - -class tst_QOpenGL : public QObject -{ -Q_OBJECT - -private slots: - void sharedResourceCleanup(); - void fboSimpleRendering(); - void fboRendering(); - void fboHandleNulledAfterContextDestroyed(); - void openGLPaintDevice(); -}; - -struct SharedResourceTracker -{ - SharedResourceTracker() - { - reset(); - } - - void reset() - { - invalidateResourceCalls = 0; - freeResourceCalls = 0; - destructorCalls = 0; - } - - int invalidateResourceCalls; - int freeResourceCalls; - int destructorCalls; -}; - -struct SharedResource : public QOpenGLSharedResource -{ - SharedResource(SharedResourceTracker *t) - : QOpenGLSharedResource(QOpenGLContextGroup::currentContextGroup()) - , resource(1) - , tracker(t) - { - } - - ~SharedResource() - { - tracker->destructorCalls++; - } - - void invalidateResource() - { - resource = 0; - tracker->invalidateResourceCalls++; - } - - void freeResource(QOpenGLContext *context) - { - Q_ASSERT(context == QOpenGLContext::currentContext()); - resource = 0; - tracker->freeResourceCalls++; - } - - int resource; - SharedResourceTracker *tracker; -}; - -void tst_QOpenGL::sharedResourceCleanup() -{ - QWindow window; - window.setGeometry(0, 0, 10, 10); - window.create(); - - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(&window); - - SharedResourceTracker tracker; - SharedResource *resource = new SharedResource(&tracker); - resource->free(); - - QCOMPARE(tracker.invalidateResourceCalls, 0); - QCOMPARE(tracker.freeResourceCalls, 1); - QCOMPARE(tracker.destructorCalls, 1); - - tracker.reset(); - - resource = new SharedResource(&tracker); - - QOpenGLContext *ctx2 = new QOpenGLContext; - ctx2->setShareContext(ctx); - ctx2->create(); - delete ctx; - - resource->free(); - - // no current context, freeResource() delayed - QCOMPARE(tracker.invalidateResourceCalls, 0); - QCOMPARE(tracker.freeResourceCalls, 0); - QCOMPARE(tracker.destructorCalls, 0); - - ctx2->makeCurrent(&window); - - // freeResource() should now have been called - QCOMPARE(tracker.invalidateResourceCalls, 0); - QCOMPARE(tracker.freeResourceCalls, 1); - QCOMPARE(tracker.destructorCalls, 1); - - tracker.reset(); - - resource = new SharedResource(&tracker); - - // this should cause invalidateResource() to be called - delete ctx2; - - QCOMPARE(tracker.invalidateResourceCalls, 1); - QCOMPARE(tracker.freeResourceCalls, 0); - QCOMPARE(tracker.destructorCalls, 0); - - // should have no effect other than destroying the resource, - // as it has already been invalidated - resource->free(); - - QCOMPARE(tracker.invalidateResourceCalls, 1); - QCOMPARE(tracker.freeResourceCalls, 0); - QCOMPARE(tracker.destructorCalls, 1); -} - -static bool fuzzyComparePixels(const QRgb testPixel, const QRgb refPixel, const char* file, int line, int x = -1, int y = -1) -{ - static int maxFuzz = 1; - static bool maxFuzzSet = false; - - // On 16 bpp systems, we need to allow for more fuzz: - if (!maxFuzzSet) { - maxFuzzSet = true; - if (QGuiApplication::primaryScreen()->depth() < 24) - maxFuzz = 32; - } - - int redFuzz = qAbs(qRed(testPixel) - qRed(refPixel)); - int greenFuzz = qAbs(qGreen(testPixel) - qGreen(refPixel)); - int blueFuzz = qAbs(qBlue(testPixel) - qBlue(refPixel)); - int alphaFuzz = qAbs(qAlpha(testPixel) - qAlpha(refPixel)); - - if (refPixel != 0 && testPixel == 0) { - QString msg; - if (x >= 0) { - msg = QString("Test pixel [%1, %2] is null (black) when it should be (%3,%4,%5,%6)") - .arg(x).arg(y) - .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); - } else { - msg = QString("Test pixel is null (black) when it should be (%2,%3,%4,%5)") - .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); - } - - QTest::qFail(msg.toLatin1(), file, line); - return false; - } - - if (redFuzz > maxFuzz || greenFuzz > maxFuzz || blueFuzz > maxFuzz || alphaFuzz > maxFuzz) { - QString msg; - - if (x >= 0) - msg = QString("Pixel [%1,%2]: ").arg(x).arg(y); - else - msg = QString("Pixel "); - - msg += QString("Max fuzz (%1) exceeded: (%2,%3,%4,%5) vs (%6,%7,%8,%9)") - .arg(maxFuzz) - .arg(qRed(testPixel)).arg(qGreen(testPixel)).arg(qBlue(testPixel)).arg(qAlpha(testPixel)) - .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); - QTest::qFail(msg.toLatin1(), file, line); - return false; - } - return true; -} - -static void fuzzyCompareImages(const QImage &testImage, const QImage &referenceImage, const char* file, int line) -{ - QCOMPARE(testImage.width(), referenceImage.width()); - QCOMPARE(testImage.height(), referenceImage.height()); - - for (int y = 0; y < testImage.height(); y++) { - for (int x = 0; x < testImage.width(); x++) { - if (!fuzzyComparePixels(testImage.pixel(x, y), referenceImage.pixel(x, y), file, line, x, y)) { - // Might as well save the images for easier debugging: - referenceImage.save("referenceImage.png"); - testImage.save("testImage.png"); - return; - } - } - } -} - -#define QFUZZY_COMPARE_IMAGES(A,B) \ - fuzzyCompareImages(A, B, __FILE__, __LINE__) - -#define QFUZZY_COMPARE_PIXELS(A,B) \ - fuzzyComparePixels(A, B, __FILE__, __LINE__) - -void qt_opengl_draw_test_pattern(QPainter* painter, int width, int height) -{ - QPainterPath intersectingPath; - intersectingPath.moveTo(0, 0); - intersectingPath.lineTo(100, 0); - intersectingPath.lineTo(0, 100); - intersectingPath.lineTo(100, 100); - intersectingPath.closeSubpath(); - - QPainterPath trianglePath; - trianglePath.moveTo(50, 0); - trianglePath.lineTo(100, 100); - trianglePath.lineTo(0, 100); - trianglePath.closeSubpath(); - - painter->setTransform(QTransform()); // reset xform - painter->fillRect(-1, -1, width+2, height+2, Qt::red); // Background - painter->translate(14, 14); - painter->fillPath(intersectingPath, Qt::blue); // Test stencil buffer works - painter->translate(128, 0); - painter->setClipPath(trianglePath); // Test depth buffer works - painter->setTransform(QTransform()); // reset xform ready for fill - painter->fillRect(-1, -1, width+2, height+2, Qt::green); -} - -void qt_opengl_check_test_pattern(const QImage& img) -{ - // As we're doing more than trivial painting, we can't just compare to - // an image rendered with raster. Instead, we sample at well-defined - // test-points: - QFUZZY_COMPARE_PIXELS(img.pixel(39, 64), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(img.pixel(89, 64), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(img.pixel(64, 39), QColor(Qt::blue).rgb()); - QFUZZY_COMPARE_PIXELS(img.pixel(64, 89), QColor(Qt::blue).rgb()); - - QFUZZY_COMPARE_PIXELS(img.pixel(167, 39), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(img.pixel(217, 39), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(img.pixel(192, 64), QColor(Qt::green).rgb()); -} - - -void tst_QOpenGL::fboSimpleRendering() -{ - QWindow window; - window.setGeometry(0, 0, 10, 10); - window.create(); - QOpenGLContext ctx; - ctx.create(); - - ctx.makeCurrent(&window); - - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - QSKIP("QOpenGLFramebufferObject not supported on this platform"); - - // No multisample with combined depth/stencil attachment: - QOpenGLFramebufferObjectFormat fboFormat; - fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment); - - QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat); - - fbo->bind(); - - glClearColor(1.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - glFinish(); - - QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); - QImage reference(fb.size(), QImage::Format_RGB32); - reference.fill(0xffff0000); - - QFUZZY_COMPARE_IMAGES(fb, reference); - - delete fbo; -} - -// NOTE: This tests that CombinedDepthStencil attachment works by assuming the -// GL2 engine is being used and is implemented the same way as it was when -// this autotest was written. If this is not the case, there may be some -// false-positives: I.e. The test passes when either the depth or stencil -// buffer is actually missing. But that's probably ok anyway. -void tst_QOpenGL::fboRendering() -{ - QWindow window; - window.setGeometry(0, 0, 10, 10); - window.create(); - QOpenGLContext ctx; - ctx.create(); - - ctx.makeCurrent(&window); - - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - QSKIP("QOpenGLFramebufferObject not supported on this platform"); - - // No multisample with combined depth/stencil attachment: - QOpenGLFramebufferObjectFormat fboFormat; - fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - - // Uncomplicate things by using NPOT: - QOpenGLFramebufferObject fbo(256, 128, fboFormat); - - if (fbo.attachment() != QOpenGLFramebufferObject::CombinedDepthStencil) - QSKIP("FBOs missing combined depth~stencil support"); - - fbo.bind(); - - QPainter fboPainter; - QOpenGLPaintDevice device(fbo.width(), fbo.height()); - bool painterBegun = fboPainter.begin(&device); - QVERIFY(painterBegun); - - qt_opengl_draw_test_pattern(&fboPainter, fbo.width(), fbo.height()); - - fboPainter.end(); - - QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32); - - qt_opengl_check_test_pattern(fb); -} - -void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() -{ - QWindow window; - window.setGeometry(0, 0, 10, 10); - window.create(); - - QOpenGLFramebufferObject *fbo = 0; - - { - QOpenGLContext ctx; - ctx.create(); - - ctx.makeCurrent(&window); - - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - QSKIP("QOpenGLFramebufferObject not supported on this platform"); - - fbo = new QOpenGLFramebufferObject(128, 128); - - QVERIFY(fbo->handle() != 0); - } - - QCOMPARE(fbo->handle(), 0U); -} - -void tst_QOpenGL::openGLPaintDevice() -{ - QWindow window; - window.setGeometry(0, 0, 128, 128); - window.create(); - - QOpenGLContext ctx; - ctx.create(); - - ctx.makeCurrent(&window); - - QImage image(128, 128, QImage::Format_RGB32); - QPainter p(&image); - p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); - p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); - p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); - p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); - p.end(); - - QOpenGLFramebufferObject fbo(128, 128); - fbo.bind(); - - QOpenGLPaintDevice device(128, 128); - p.begin(&device); - p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); - p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); - p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); - p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); - p.end(); - - QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); - - p.begin(&device); - p.fillRect(0, 0, image.width(), image.height(), Qt::black); - p.drawImage(0, 0, image); - p.end(); - - QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); - - p.begin(&device); - p.fillRect(0, 0, image.width(), image.height(), Qt::black); - p.fillRect(0, 0, image.width(), image.height(), QBrush(image)); - p.end(); - - QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); -} - -QTEST_MAIN(tst_QOpenGL) -#include "tst_qopengl.moc" diff --git a/tests/auto/qscreen/qscreen.pro b/tests/auto/qscreen/qscreen.pro deleted file mode 100644 index be3a89867d..0000000000 --- a/tests/auto/qscreen/qscreen.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_qscreen - -QT += core-private gui-private testlib - -SOURCES += tst_qscreen.cpp - diff --git a/tests/auto/qscreen/tst_qscreen.cpp b/tests/auto/qscreen/tst_qscreen.cpp deleted file mode 100644 index 1d00032b56..0000000000 --- a/tests/auto/qscreen/tst_qscreen.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include - -class tst_QScreen: public QObject -{ - Q_OBJECT - -private slots: - void angleBetween_data(); - void angleBetween(); - void transformBetween_data(); - void transformBetween(); -}; - -void tst_QScreen::angleBetween_data() -{ - QTest::addColumn("oa"); - QTest::addColumn("ob"); - QTest::addColumn("expected"); - - QTest::newRow("Portrait Portrait") - << uint(Qt::PortraitOrientation) - << uint(Qt::PortraitOrientation) - << 0; - - QTest::newRow("Portrait Landscape") - << uint(Qt::PortraitOrientation) - << uint(Qt::LandscapeOrientation) - << 270; - - QTest::newRow("Portrait InvertedPortrait") - << uint(Qt::PortraitOrientation) - << uint(Qt::InvertedPortraitOrientation) - << 180; - - QTest::newRow("Portrait InvertedLandscape") - << uint(Qt::PortraitOrientation) - << uint(Qt::InvertedLandscapeOrientation) - << 90; - - QTest::newRow("InvertedLandscape InvertedPortrait") - << uint(Qt::InvertedLandscapeOrientation) - << uint(Qt::InvertedPortraitOrientation) - << 90; - - QTest::newRow("InvertedLandscape Landscape") - << uint(Qt::InvertedLandscapeOrientation) - << uint(Qt::LandscapeOrientation) - << 180; -} - -void tst_QScreen::angleBetween() -{ - QFETCH( uint, oa ); - QFETCH( uint, ob ); - QFETCH( int, expected ); - - Qt::ScreenOrientation a = Qt::ScreenOrientation(oa); - Qt::ScreenOrientation b = Qt::ScreenOrientation(ob); - - QCOMPARE(QScreen::angleBetween(a, b), expected); - QCOMPARE(QScreen::angleBetween(b, a), (360 - expected) % 360); -} - -void tst_QScreen::transformBetween_data() -{ - QTest::addColumn("oa"); - QTest::addColumn("ob"); - QTest::addColumn("rect"); - QTest::addColumn("expected"); - - QRect rect(0, 0, 480, 640); - - QTest::newRow("Portrait Portrait") - << uint(Qt::PortraitOrientation) - << uint(Qt::PortraitOrientation) - << rect - << QTransform(); - - QTest::newRow("Portrait Landscape") - << uint(Qt::PortraitOrientation) - << uint(Qt::LandscapeOrientation) - << rect - << QTransform(0, -1, 1, 0, 0, rect.height()); - - QTest::newRow("Portrait InvertedPortrait") - << uint(Qt::PortraitOrientation) - << uint(Qt::InvertedPortraitOrientation) - << rect - << QTransform(-1, 0, 0, -1, rect.width(), rect.height()); - - QTest::newRow("Portrait InvertedLandscape") - << uint(Qt::PortraitOrientation) - << uint(Qt::InvertedLandscapeOrientation) - << rect - << QTransform(0, 1, -1, 0, rect.width(), 0); - - QTest::newRow("InvertedLandscape InvertedPortrait") - << uint(Qt::InvertedLandscapeOrientation) - << uint(Qt::InvertedPortraitOrientation) - << rect - << QTransform(0, 1, -1, 0, rect.width(), 0); - - QTest::newRow("InvertedLandscape Landscape") - << uint(Qt::InvertedLandscapeOrientation) - << uint(Qt::LandscapeOrientation) - << rect - << QTransform(-1, 0, 0, -1, rect.width(), rect.height()); -} - -void tst_QScreen::transformBetween() -{ - QFETCH( uint, oa ); - QFETCH( uint, ob ); - QFETCH( QRect, rect ); - QFETCH( QTransform, expected ); - - Qt::ScreenOrientation a = Qt::ScreenOrientation(oa); - Qt::ScreenOrientation b = Qt::ScreenOrientation(ob); - - QCOMPARE(QScreen::transformBetween(a, b, rect), expected); -} - -#include -QTEST_MAIN(tst_QScreen); diff --git a/tests/auto/qwindow/qwindow.pro b/tests/auto/qwindow/qwindow.pro deleted file mode 100644 index 9fb49e8ceb..0000000000 --- a/tests/auto/qwindow/qwindow.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_qwindow - -QT += core-private gui-private testlib - -SOURCES += tst_qwindow.cpp - diff --git a/tests/auto/qwindow/tst_qwindow.cpp b/tests/auto/qwindow/tst_qwindow.cpp deleted file mode 100644 index 4171f0f797..0000000000 --- a/tests/auto/qwindow/tst_qwindow.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include - -class tst_QWindow: public QObject -{ - Q_OBJECT - -private slots: - void mapGlobal(); - void positioning(); - void isActive(); -}; - - -void tst_QWindow::mapGlobal() -{ - QWindow a; - QWindow b(&a); - QWindow c(&b); - - a.setGeometry(10, 10, 300, 300); - b.setGeometry(20, 20, 200, 200); - c.setGeometry(40, 40, 100, 100); - - QCOMPARE(a.mapToGlobal(QPoint(100, 100)), QPoint(110, 110)); - QCOMPARE(b.mapToGlobal(QPoint(100, 100)), QPoint(130, 130)); - QCOMPARE(c.mapToGlobal(QPoint(100, 100)), QPoint(170, 170)); - - QCOMPARE(a.mapFromGlobal(QPoint(100, 100)), QPoint(90, 90)); - QCOMPARE(b.mapFromGlobal(QPoint(100, 100)), QPoint(70, 70)); - QCOMPARE(c.mapFromGlobal(QPoint(100, 100)), QPoint(30, 30)); -} - -class Window : public QWindow -{ -public: - Window() - { - reset(); - setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); - } - - void reset() - { - m_received.clear(); - } - - bool event(QEvent *event) - { - m_received[event->type()]++; - - return QWindow::event(event); - } - - int received(QEvent::Type type) - { - return m_received.value(type, 0); - } - -private: - QHash m_received; -}; - -void tst_QWindow::positioning() -{ - QRect geometry(80, 80, 40, 40); - - Window window; - window.setGeometry(geometry); - QCOMPARE(window.geometry(), geometry); - window.show(); - - QTRY_COMPARE(window.received(QEvent::Resize), 1); - QTRY_COMPARE(window.received(QEvent::Map), 1); - - QMargins originalMargins = window.frameMargins(); - - QCOMPARE(window.pos(), window.framePos() + QPoint(originalMargins.left(), originalMargins.top())); - QVERIFY(window.frameGeometry().contains(window.geometry())); - - QPoint originalPos = window.pos(); - QPoint originalFramePos = window.framePos(); - - window.setWindowState(Qt::WindowFullScreen); - QTRY_COMPARE(window.received(QEvent::Resize), 2); - - window.setWindowState(Qt::WindowNoState); - QTRY_COMPARE(window.received(QEvent::Resize), 3); - - QTRY_COMPARE(originalPos, window.pos()); - QTRY_COMPARE(originalFramePos, window.framePos()); - QTRY_COMPARE(originalMargins, window.frameMargins()); - - // if our positioning is actually fully respected by the window manager - // test whether it correctly handles frame positioning as well - if (originalPos == geometry.topLeft() && (originalMargins.top() != 0 || originalMargins.left() != 0)) { - QPoint framePos(40, 40); - - window.reset(); - window.setFramePos(framePos); - - QTRY_VERIFY(window.received(QEvent::Move)); - QTRY_COMPARE(framePos, window.framePos()); - QTRY_COMPARE(originalMargins, window.frameMargins()); - QCOMPARE(window.pos(), window.framePos() + QPoint(originalMargins.left(), originalMargins.top())); - - // and back to regular positioning - - window.reset(); - window.setPos(originalPos); - QTRY_VERIFY(window.received(QEvent::Move)); - QTRY_COMPARE(originalPos, window.pos()); - } -} - -void tst_QWindow::isActive() -{ - Window window; - window.setGeometry(80, 80, 40, 40); - window.show(); - - QTRY_COMPARE(window.received(QEvent::Map), 1); - QTRY_COMPARE(window.received(QEvent::Resize), 1); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); - QVERIFY(window.isActive()); - - Window child; - child.setParent(&window); - child.setGeometry(10, 10, 20, 20); - child.show(); - - QTRY_COMPARE(child.received(QEvent::Map), 1); - - child.requestActivateWindow(); - - QTRY_VERIFY(QGuiApplication::focusWindow() == &child); - QVERIFY(child.isActive()); - - // parent shouldn't receive new map or resize events from child being shown - QTRY_COMPARE(window.received(QEvent::Map), 1); - QTRY_COMPARE(window.received(QEvent::Resize), 1); - QTRY_COMPARE(window.received(QEvent::FocusIn), 1); - QTRY_COMPARE(window.received(QEvent::FocusOut), 1); - QTRY_COMPARE(child.received(QEvent::FocusIn), 1); - - // child has focus - QVERIFY(window.isActive()); - - Window dialog; - dialog.setTransientParent(&window); - dialog.setGeometry(110, 110, 30, 30); - dialog.show(); - - dialog.requestActivateWindow(); - - QTRY_COMPARE(dialog.received(QEvent::Map), 1); - QTRY_COMPARE(dialog.received(QEvent::Resize), 1); - QTRY_VERIFY(QGuiApplication::focusWindow() == &dialog); - QVERIFY(dialog.isActive()); - - // transient child has focus - QVERIFY(window.isActive()); - - // parent is active - QVERIFY(child.isActive()); - - window.requestActivateWindow(); - - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); - QTRY_COMPARE(dialog.received(QEvent::FocusOut), 1); - QTRY_COMPARE(window.received(QEvent::FocusIn), 2); - - QVERIFY(window.isActive()); - - // transient parent has focus - QVERIFY(dialog.isActive()); - - // parent has focus - QVERIFY(child.isActive()); -} - -#include -QTEST_MAIN(tst_QWindow); -- cgit v1.2.3