diff options
Diffstat (limited to 'tests/auto/quick')
36 files changed, 1035 insertions, 142 deletions
diff --git a/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp b/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp index afc66948b0..f3825b350f 100644 --- a/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp +++ b/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp @@ -69,6 +69,9 @@ private slots: void triangles(); void triangleStrip(); void triangleFan(); + +private: + bool isRunningOnRhi() const; }; class DrawingModeItem : public QQuickItem @@ -260,6 +263,9 @@ void tst_drawingmodes::lineLoop() || (QGuiApplication::platformName() == QLatin1String("minimal"))) QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); + if (isRunningOnRhi()) + QSKIP("Line loops are not supported by some modern graphics APIs - skipping test"); + QImage fb = runTest("DrawingModes.qml"); QCOMPARE(fb.width(), 200); @@ -350,6 +356,9 @@ void tst_drawingmodes::triangleFan() || (QGuiApplication::platformName() == QLatin1String("minimal"))) QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); + if (isRunningOnRhi()) + QSKIP("Triangle fans are not supported by some modern graphics APIs - skipping test"); + QImage fb = runTest("DrawingModes.qml"); QCOMPARE(fb.width(), 200); @@ -368,6 +377,22 @@ void tst_drawingmodes::triangleFan() QVERIFY(!hasPixelAround(fb, 37, 100)); } +bool tst_drawingmodes::isRunningOnRhi() const +{ + static bool retval = false; + static bool decided = false; + if (!decided) { + decided = true; + QQuickView dummy; + dummy.show(); + QTest::qWaitForWindowExposed(&dummy); + QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); + retval = QSGRendererInterface::isApiRhiBased(api); + dummy.hide(); + } + return retval; +} + QTEST_MAIN(tst_drawingmodes) diff --git a/tests/auto/quick/nodes/tst_nodestest.cpp b/tests/auto/quick/nodes/tst_nodestest.cpp index 79a9e5f757..bd5e6c6383 100644 --- a/tests/auto/quick/nodes/tst_nodestest.cpp +++ b/tests/auto/quick/nodes/tst_nodestest.cpp @@ -39,7 +39,7 @@ #include <QtQuick/qsgsimplerectnode.h> #include <QtQuick/qsgsimpletexturenode.h> -#include <QtQuick/private/qsgtexture_p.h> +#include <QtQuick/private/qsgplaintexture_p.h> #include <QtGui/private/qguiapplication_p.h> #include <QtGui/qpa/qplatformintegration.h> @@ -99,7 +99,10 @@ void NodesTest::initTestCase() auto rc = renderLoop->createRenderContext(renderLoop->sceneGraphContext()); renderContext = static_cast<QSGDefaultRenderContext *>(rc); QVERIFY(renderContext); - renderContext->initialize(context); + QSGDefaultRenderContext::InitParams rcParams; + rcParams.openGLContext = context; + rcParams.initialSurfacePixelSize = QSize(512, 512); // dummy, make up something + renderContext->initialize(&rcParams); QVERIFY(renderContext->isValid()); } diff --git a/tests/auto/quick/nokeywords/tst_nokeywords.cpp b/tests/auto/quick/nokeywords/tst_nokeywords.cpp index e6655589a3..c0b66f1c3f 100644 --- a/tests/auto/quick/nokeywords/tst_nokeywords.cpp +++ b/tests/auto/quick/nokeywords/tst_nokeywords.cpp @@ -49,7 +49,7 @@ #include <QtQuick/private/qsgcontext_p.h> #include <QtQuick/private/qsgcontextplugin_p.h> #if QT_CONFIG(opengl) -#include <QtQuick/private/qsgdefaultdistancefieldglyphcache_p.h> +#include <QtQuick/private/qsgopengldistancefieldglyphcache_p.h> #include <QtQuick/private/qsgdefaultglyphnode_p.h> #include <QtQuick/private/qsgdefaultinternalimagenode_p.h> #include <QtQuick/private/qsgdefaultinternalrectanglenode_p.h> @@ -65,9 +65,16 @@ #include <QtQuick/private/qsgrendernode_p.h> #include <QtQuick/private/qsgtexturematerial_p.h> #include <QtQuick/private/qsgtexture_p.h> +#include <QtQuick/private/qsgplaintexture_p.h> #include <QtQuick/private/qsgthreadedrenderloop_p.h> #include <QtQuick/private/qsgwindowsrenderloop_p.h> +#include <QtQuick/private/qsgrhiatlastexture_p.h> +#include <QtQuick/private/qsgrhidistancefieldglyphcache_p.h> +#include <QtQuick/private/qsgrhilayer_p.h> +#include <QtQuick/private/qsgrhishadereffectnode_p.h> +#include <QtQuick/private/qsgrhitextureglyphcache_p.h> + #undef signals #undef slots #undef emit diff --git a/tests/auto/quick/qquickanimations/data/animationJobSelfDestructionBug.qml b/tests/auto/quick/qquickanimations/data/animationJobSelfDestructionBug.qml new file mode 100644 index 0000000000..259871785b --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/animationJobSelfDestructionBug.qml @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.11 +import QtQuick.Window 2.11 + +Window { + id: root + property alias timer : timer + property variant ops: [{'op': 'add', 'count': 3}, {'op': 'add', 'count': 6}, {'op': 'rem', 'count': 4}, {'op': 'rem', 'count': 1}, {'op': 'rem', 'count': 3}] + property int opIndex : 0 + width: 400 + height: 600 + + ListModel { + id: theModel + } + + Timer { + id: timer + interval: 100 + running: false + repeat: true + onTriggered: { + if (opIndex >= ops.length) { + timer.stop() + return + } + let op = ops[opIndex] + for (var i = 0; i < op.count; ++i) { + if (op.op === "add") + theModel.append({"name": "opIndex " + opIndex}) + else + theModel.remove(0, 1); + } + opIndex = opIndex + 1 + } + } + + ListView { + anchors.top: parent.top + anchors.right: parent.right + height: 600 + anchors.left: parent.horizontalCenter + spacing: 4 + model: theModel + header: Text { + text: "YAnimator" + } + add: Transition { + NumberAnimation { property: "scale"; from: 0; to: 1; duration: 200 } + NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 200 } + } + displaced: Transition { + YAnimator { duration: 500 } + NumberAnimation { property: "opacity"; to: 1.0; duration: 500 } + NumberAnimation { property: "scale"; to: 1.0; duration: 500 } + } + remove: Transition { + NumberAnimation { property: "opacity"; to: 0; duration: 200 } + NumberAnimation { property: "scale"; to: 0; duration: 200 } + } + delegate: Rectangle { + width: 200 + height: 20 + color:"red" + Text { + anchors.centerIn: parent + text: name + } + } + } +} diff --git a/tests/auto/quick/qquickanimations/data/fastFlickingBug.qml b/tests/auto/quick/qquickanimations/data/fastFlickingBug.qml new file mode 100644 index 0000000000..b2649a801b --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/fastFlickingBug.qml @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.11 +import QtQuick.Window 2.11 + +Window { + id: root + property alias timer : timer + property alias listView : listView + property alias theModel: theModel + property variant ops: [{'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}, + {'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}, + {'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}, + {'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}, + {'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}, + {'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}, + {'op': 'add', 'count': 30}, {'op': 'add', 'count': 60}, {'op': 'rem', 'count': 40}, {'op': 'rem', 'count': 10}, {'op': 'rem', 'count': 39}] + property int opIndex : 0 + width: 400 + height: 600 + + ListModel { + id: theModel + } + + Timer { + id: timer + interval: 100 + running: false + repeat: true + onTriggered: { + if (opIndex >= ops.length) { + timer.stop() + return + } + let op = ops[opIndex] + for (var i = 0; i < op.count; ++i) { + if (op.op === "add") + theModel.append({"name": "opIndex " + opIndex}) + else + theModel.remove(0, 1); + } + opIndex = opIndex + 1 + } + } + + ListView { + id: listView + anchors.fill: parent + spacing: 4 + model: theModel + header: Text { + text: "YAnimator" + } + add: Transition { + NumberAnimation { property: "scale"; from: 0; to: 1; duration: 200 } + NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 200 } + } + displaced: Transition { + YAnimator { duration: 500 } + NumberAnimation { property: "opacity"; to: 1.0; duration: 1000 } + NumberAnimation { property: "scale"; to: 1.0; duration: 1000 } + } + remove: Transition { + NumberAnimation { property: "opacity"; to: 0; duration: 200 } + NumberAnimation { property: "scale"; to: 0; duration: 200 } + } + delegate: Rectangle { + width: 200 + height: 20 + color:"red" + Text { + anchors.centerIn: parent + text: name + } + } + } +} diff --git a/tests/auto/quick/qquickanimations/qquickanimations.pro b/tests/auto/quick/qquickanimations/qquickanimations.pro index cd0a0fbb15..94f694181d 100644 --- a/tests/auto/quick/qquickanimations/qquickanimations.pro +++ b/tests/auto/quick/qquickanimations/qquickanimations.pro @@ -12,6 +12,7 @@ QT += core-private gui-private qml-private quick-private testlib qmlmodels-priv DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 OTHER_FILES += \ + data/animationJobSelfDestructionBug.qml\ data/attached.qml \ data/badproperty1.qml \ data/badproperty2.qml \ @@ -26,6 +27,7 @@ OTHER_FILES += \ data/dotproperty.qml \ data/Double.qml \ data/doubleRegistrationBug.qml \ + data/fastFlickingBug.qml \ data/looping.qml \ data/mixedtype1.qml \ data/mixedtype2.qml \ diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index b75dc8bc6b..48f779a490 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -40,6 +40,7 @@ #include <QtQuick/private/qquickanimatorjob_p.h> #include <QtQuick/private/qquickpathinterpolator_p.h> #include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquicklistview_p.h> #include <QEasingCurve> #include <limits.h> @@ -109,6 +110,8 @@ private slots: void unsetAnimatorProxyJobWindow(); void finished(); void replacingTransitions(); + void animationJobSelfDestruction(); + void fastFlickingBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -1723,6 +1726,54 @@ void tst_qquickanimations::replacingTransitions() QCOMPARE(model->count(), 3); } +void tst_qquickanimations::animationJobSelfDestruction() +{ + // Don't crash + QQmlEngine engine; + engine.clearComponentCache(); + QQmlComponent c(&engine, testFileUrl("animationJobSelfDestructionBug.qml")); + QScopedPointer<QQuickWindow> win(qobject_cast<QQuickWindow*>(c.create())); + if (!c.errors().isEmpty()) + qDebug() << c.errorString(); + QVERIFY(win); + win->setTitle(QTest::currentTestFunction()); + win->show(); + QVERIFY(QTest::qWaitForWindowExposed(win.data())); + QQmlTimer *timer = win->property("timer").value<QQmlTimer*>(); + QVERIFY(timer); + QCOMPARE(timer->isRunning(), false); + timer->start(); + QTest::qWait(1000); +} + +void tst_qquickanimations::fastFlickingBug() +{ + // Don't crash + QQmlEngine engine; + engine.clearComponentCache(); + QQmlComponent c(&engine, testFileUrl("fastFlickingBug.qml")); + QScopedPointer<QQuickWindow> win(qobject_cast<QQuickWindow*>(c.create())); + if (!c.errors().isEmpty()) + qDebug() << c.errorString(); + QVERIFY(win); + win->setTitle(QTest::currentTestFunction()); + win->show(); + QVERIFY(QTest::qWaitForWindowExposed(win.data())); + auto timer = win->property("timer").value<QQmlTimer*>(); + QVERIFY(timer); + QCOMPARE(timer->isRunning(), false); + auto listView = win->property("listView").value<QQuickFlickable*>(); + QVERIFY(listView); + timer->start(); + // flick listView up and down quickly in the middle of a slow transition + for (int sign = 1; timer->isRunning(); sign *= -1) { + listView->flick(0, sign * 4000); + qApp->processEvents(); + QTest::qWait(53); + qApp->processEvents(); + } +} + QTEST_MAIN(tst_qquickanimations) #include "tst_qquickanimations.moc" diff --git a/tests/auto/quick/qquickbehaviors/data/delete.qml b/tests/auto/quick/qquickbehaviors/data/delete.qml new file mode 100644 index 0000000000..1bf0267b84 --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/delete.qml @@ -0,0 +1,37 @@ +import QtQuick 2.12 + +Item { + visible: true + width: 640 + height: 480 + + Component.onCompleted: { + myLoader.active = false + } + + Loader { + id: myLoader + + active: true + sourceComponent: Item { + width: 100 + height: 100 + id: myPopup + + NumberAnimation { + id: anim + } + + Rectangle { + color: "black" + Component.onCompleted: { + opacity = 20 + } + + Behavior on opacity { + animation: anim + } + } + } + } +} diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index 6367f327da..64e32dcdfd 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -74,6 +74,7 @@ private slots: void aliasedProperty(); void innerBehaviorOverwritten(); void oneWay(); + void safeToDelete(); }; void tst_qquickbehaviors::simpleBehavior() @@ -647,6 +648,16 @@ void tst_qquickbehaviors::oneWay() QCOMPARE(myAnimation->isRunning(), false); } +// QTBUG-76749 +void tst_qquickbehaviors::safeToDelete() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("delete.qml")); + QVERIFY(c.create()); +} + + + QTEST_MAIN(tst_qquickbehaviors) #include "tst_qquickbehaviors.moc" diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index d1f46a3912..c722f2fc2c 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -45,6 +45,7 @@ #include <QQuickWindow> #include <QQuickView> #include <QQuickImageProvider> +#include <QQmlAbstractUrlInterceptor> #include "../../shared/util.h" #include "../../shared/testhttpserver.h" @@ -95,6 +96,7 @@ private slots: void highDpiFillModesAndSizes_data(); void highDpiFillModesAndSizes(); void hugeImages(); + void urlInterceptor(); private: QQmlEngine engine; @@ -1100,6 +1102,36 @@ void tst_qquickimage::hugeImages() QCOMPARE(contents.pixel(199, 99), qRgba(0, 0, 255, 255)); } + +class MyInterceptor : public QQmlAbstractUrlInterceptor +{ +public: + MyInterceptor(QUrl url) : QQmlAbstractUrlInterceptor(), m_url(url) {} + QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) + { + if (url.scheme() == "interceptthis") + return m_url; + return url; + } + + QUrl m_url; +}; + +void tst_qquickimage::urlInterceptor() +{ + QQmlEngine engine; + MyInterceptor interceptor {testFileUrl("colors.png")}; + engine.setUrlInterceptor(&interceptor); + + QQmlComponent c(&engine); + + c.setData("import QtQuick 2.12; Image { objectName: \"item\"; source: width == 0 ? \"interceptthis:doesNotExist\" : \"interceptthis:doesNotExist\"}", QUrl{}); + QScopedPointer<QQuickImage> object { qobject_cast<QQuickImage*>(c.create())}; + QVERIFY(object); + QTRY_COMPARE(object->status(), QQuickImage::Ready); + QTRY_COMPARE(object->progress(), 1.0); +} + QTEST_MAIN(tst_qquickimage) #include "tst_qquickimage.moc" diff --git a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp index 4b75a7e008..c79e665d94 100644 --- a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp +++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp @@ -33,6 +33,7 @@ #include <QImageReader> #include <QWaitCondition> #include <QThreadPool> +#include <private/qqmlengine_p.h> Q_DECLARE_METATYPE(QQuickImageProvider*); @@ -67,6 +68,8 @@ private slots: void asyncTextureTest(); void instantAsyncTextureTest(); + void asyncImageThreadSafety(); + private: QString newImageFileName() const; void fillRequestTestsData(const QString &id); @@ -448,21 +451,56 @@ void tst_qquickimageprovider::threadTest() foreach (QQuickImage *img, images) { QCOMPARE(img->status(), QQuickImage::Loading); } - provider->ok = true; - provider->cond.wakeAll(); + { + QMutexLocker lock(&provider->mutex); + provider->ok = true; + provider->cond.wakeAll(); + } QTest::qWait(250); foreach (QQuickImage *img, images) { QTRY_COMPARE(img->status(), QQuickImage::Ready); } } -class TestImageResponse : public QQuickImageResponse, public QRunnable +class TestImageResponseRunner : public QObject, public QRunnable { + + Q_OBJECT + +public: + Q_SIGNAL void finished(QQuickTextureFactory *texture); + TestImageResponseRunner(QMutex *lock, QWaitCondition *condition, bool *ok, const QString &id, const QSize &requestedSize) + : m_lock(lock), m_condition(condition), m_ok(ok), m_id(id), m_requestedSize(requestedSize) {} + void run() + { + m_lock->lock(); + if (!(*m_ok)) { + m_condition->wait(m_lock); + } + m_lock->unlock(); + QImage image(50, 50, QImage::Format_RGB32); + image.fill(QColor(m_id).rgb()); + if (m_requestedSize.isValid()) + image = image.scaled(m_requestedSize); + emit finished(QQuickTextureFactory::textureFactoryForImage(image)); + } + +private: + QMutex *m_lock; + QWaitCondition *m_condition; + bool *m_ok; + QString m_id; + QSize m_requestedSize; +}; + +class TestImageResponse : public QQuickImageResponse { public: - TestImageResponse(QMutex *lock, QWaitCondition *condition, bool *ok, const QString &id, const QSize &requestedSize) + TestImageResponse(QMutex *lock, QWaitCondition *condition, bool *ok, const QString &id, const QSize &requestedSize, QThreadPool *pool) : m_lock(lock), m_condition(condition), m_ok(ok), m_id(id), m_requestedSize(requestedSize), m_texture(nullptr) { - setAutoDelete(false); + auto runnable = new TestImageResponseRunner(m_lock, m_condition, m_ok, m_id, m_requestedSize); + QObject::connect(runnable, &TestImageResponseRunner::finished, this, &TestImageResponse::handleResponse); + pool->start(runnable); } QQuickTextureFactory *textureFactory() const @@ -470,18 +508,8 @@ class TestImageResponse : public QQuickImageResponse, public QRunnable return m_texture; } - void run() - { - m_lock->lock(); - if (!(*m_ok)) { - m_condition->wait(m_lock); - } - m_lock->unlock(); - QImage image(50, 50, QImage::Format_RGB32); - image.fill(QColor(m_id).rgb()); - if (m_requestedSize.isValid()) - image = image.scaled(m_requestedSize); - m_texture = QQuickTextureFactory::textureFactoryForImage(image); + void handleResponse(QQuickTextureFactory *factory) { + this->m_texture = factory; emit finished(); } @@ -505,8 +533,7 @@ class TestAsyncProvider : public QQuickAsyncImageProvider QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) { - TestImageResponse *response = new TestImageResponse(&lock, &condition, &ok, id, requestedSize); - pool.start(response); + TestImageResponse *response = new TestImageResponse(&lock, &condition, &ok, id, requestedSize, &pool); return response; } @@ -544,8 +571,11 @@ void tst_qquickimageprovider::asyncTextureTest() foreach (QQuickImage *img, images) { QTRY_COMPARE(img->status(), QQuickImage::Loading); } - provider->ok = true; - provider->condition.wakeAll(); + { + QMutexLocker lock(&provider->lock); + provider->ok = true; + provider->condition.wakeAll(); + } foreach (QQuickImage *img, images) { QTRY_COMPARE(img->status(), QQuickImage::Ready); } @@ -616,6 +646,115 @@ void tst_qquickimageprovider::instantAsyncTextureTest() } +class WaitingAsyncImageResponse : public QQuickImageResponse, public QRunnable +{ +public: + WaitingAsyncImageResponse(QMutex *providerRemovedMutex, QWaitCondition *providerRemovedCond, bool *providerRemoved, QMutex *imageRequestedMutex, QWaitCondition *imageRequestedCond, bool *imageRequested) + : m_providerRemovedMutex(providerRemovedMutex), m_providerRemovedCond(providerRemovedCond), m_providerRemoved(providerRemoved), + m_imageRequestedMutex(imageRequestedMutex), m_imageRequestedCondition(imageRequestedCond), m_imageRequested(imageRequested) + { + setAutoDelete(false); + } + + void run() override + { + m_imageRequestedMutex->lock(); + *m_imageRequested = true; + m_imageRequestedCondition->wakeAll(); + m_imageRequestedMutex->unlock(); + m_providerRemovedMutex->lock(); + while (!*m_providerRemoved) + m_providerRemovedCond->wait(m_providerRemovedMutex); + m_providerRemovedMutex->unlock(); + emit finished(); + } + + QQuickTextureFactory *textureFactory() const + { + QImage image(50, 50, QImage::Format_RGB32); + auto texture = QQuickTextureFactory::textureFactoryForImage(image); + return texture; + } + + QMutex *m_providerRemovedMutex; + QWaitCondition *m_providerRemovedCond; + bool *m_providerRemoved; + QMutex *m_imageRequestedMutex; + QWaitCondition *m_imageRequestedCondition; + bool *m_imageRequested; + +}; + +class WaitingAsyncProvider : public QQuickAsyncImageProvider +{ +public: + WaitingAsyncProvider(QMutex *providerRemovedMutex, QWaitCondition *providerRemovedCond, bool *providerRemoved, QMutex *imageRequestedMutex, QWaitCondition *imageRequestedCond, bool *imageRequested) + : m_providerRemovedMutex(providerRemovedMutex), m_providerRemovedCond(providerRemovedCond), m_providerRemoved(providerRemoved), + m_imageRequestedMutex(imageRequestedMutex), m_imageRequestedCondition(imageRequestedCond), m_imageRequested(imageRequested) + { + } + + ~WaitingAsyncProvider() {} + + QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) + { + auto response = new WaitingAsyncImageResponse(m_providerRemovedMutex, m_providerRemovedCond, m_providerRemoved, m_imageRequestedMutex, m_imageRequestedCondition, m_imageRequested); + pool.start(response); + return response; + } + + QMutex *m_providerRemovedMutex; + QWaitCondition *m_providerRemovedCond; + bool *m_providerRemoved; + QMutex *m_imageRequestedMutex; + QWaitCondition *m_imageRequestedCondition; + bool *m_imageRequested; + QThreadPool pool; +}; + + +// QTBUG-76527 +void tst_qquickimageprovider::asyncImageThreadSafety() +{ + QQmlEngine engine; + QMutex providerRemovedMutex; + bool providerRemoved = false; + QWaitCondition providerRemovedCond; + QMutex imageRequestedMutex; + bool imageRequested = false; + QWaitCondition imageRequestedCond; + auto imageProvider = new WaitingAsyncProvider(&providerRemovedMutex, &providerRemovedCond, &providerRemoved, &imageRequestedMutex, &imageRequestedCond, &imageRequested); + engine.addImageProvider("test_waiting", imageProvider); + QVERIFY(engine.imageProvider("test_waiting") != nullptr); + auto privateEngine = QQmlEnginePrivate::get(&engine); + + QString componentStr = "import QtQuick 2.0\nItem { \n" + "Image { source: \"image://test_waiting/blue\"; }\n" + " }"; + QQmlComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QWeakPointer<QQmlImageProviderBase> observer = privateEngine->imageProvider("test_waiting").toWeakRef(); + QVERIFY(!observer.isNull()); // engine still own the object + imageRequestedMutex.lock(); + while (!imageRequested) + imageRequestedCond.wait(&imageRequestedMutex); + imageRequestedMutex.unlock(); + engine.removeImageProvider("test_waiting"); + + QVERIFY(engine.imageProvider("test_waiting") == nullptr); + QVERIFY(!observer.isNull()); // lifetime has been extended + + providerRemovedMutex.lock(); + providerRemoved = true; + providerRemovedCond.wakeAll(); + providerRemovedMutex.unlock(); + + QTRY_VERIFY(observer.isNull()); // once the reply has finished, the imageprovider gets deleted +} + + QTEST_MAIN(tst_qquickimageprovider) #include "tst_qquickimageprovider.moc" diff --git a/tests/auto/quick/qquickitem2/data/keynavigationtest_implicitDestroy.qml b/tests/auto/quick/qquickitem2/data/keynavigationtest_implicitDestroy.qml new file mode 100644 index 0000000000..54d20273da --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/keynavigationtest_implicitDestroy.qml @@ -0,0 +1,13 @@ +import QtQuick 2.12 + +Item { + id: root + + function createImplicitKeyNavigation() { + var item = Qt.createQmlObject("import QtQuick 2.0; Item { }", root); + item.KeyNavigation.up = root + item.destroy(); + + forceActiveFocus(); + } +} diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 7107f4d995..399535cfa6 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -86,6 +86,7 @@ private slots: void keyNavigation_RightToLeft(); void keyNavigation_skipNotVisible(); void keyNavigation_implicitSetting(); + void keyNavigation_implicitDestroy(); void keyNavigation_focusReason(); void keyNavigation_loop(); void layoutMirroring(); @@ -2164,6 +2165,29 @@ void tst_QQuickItem::keyNavigation_implicitSetting() delete window; } +// QTBUG-75399 +void tst_QQuickItem::keyNavigation_implicitDestroy() +{ + QQuickView view; + view.setSource(testFileUrl("keynavigationtest_implicitDestroy.qml")); + view.show(); + + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickItem *root = view.rootObject(); + QVERIFY(QMetaObject::invokeMethod(root, "createImplicitKeyNavigation")); + + // process events is necessary to trigger upcoming memory access violation + QTest::qWait(0); + + QVERIFY(root->hasActiveFocus()); + + QKeyEvent keyPress = QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(&view, &keyPress); // <-- access violation happens here + // this should fail the test, even if the access violation does not occur + QVERIFY(!keyPress.isAccepted()); +} + void tst_QQuickItem::keyNavigation_focusReason() { QQuickView *window = new QQuickView(nullptr); diff --git a/tests/auto/quick/qquicklistview/BLACKLIST b/tests/auto/quick/qquicklistview/BLACKLIST index 6dd7302661..1f3736328a 100644 --- a/tests/auto/quick/qquicklistview/BLACKLIST +++ b/tests/auto/quick/qquicklistview/BLACKLIST @@ -1,15 +1,14 @@ [enforceRange_withoutHighlight] -osx opensuse-42.3 opensuse-leap #QTBUG-53863 [populateTransitions] opensuse-42.1 -#QTBUG-65964 - [contentHeightWithDelayRemove] osx-10.12 - #QTBUG-75960 +#QTBUG-76652 [currentIndex] osx-10.12 +opensuse-leap +ubuntu-18.04 diff --git a/tests/auto/quick/qquicklistview/data/footer2.qml b/tests/auto/quick/qquicklistview/data/footer2.qml new file mode 100644 index 0000000000..bba74d89f7 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/footer2.qml @@ -0,0 +1,33 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + Timer { + running: true + repeat: false + interval: 100 + onTriggered: { + list.model -= 3; + } + } + + ListView { + id: list + objectName: "list" + anchors.fill: parent + model: 3 + delegate: Rectangle { + color: "red" + width: 240 + height: 10 + } + footer: Rectangle { + color: "blue" + width: 240 + height: 10 + } + } +} + diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 7d5ad1b604..f14a6e75f6 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -153,6 +153,7 @@ private slots: void headerChangesViewport(); void footer(); void footer_data(); + void footer2(); void extents(); void extents_data(); void resetModel_headerFooter(); @@ -4139,6 +4140,21 @@ void tst_QQuickListView::footer_data() << QPointF(0, -(30 * 20) - 10); } +void tst_QQuickListView::footer2() // QTBUG-31677 +{ + QQuickView *window = getView(); + window->setSource(testFileUrl("footer2.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); + QTRY_VERIFY(listview != nullptr); + + QQuickItem *footer = listview->footerItem(); + QVERIFY(footer != nullptr); + QTRY_COMPARE(footer->y(), 0.0); +} + class LVAccessor : public QQuickListView { public: diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 52d1458a53..4215017db3 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -393,10 +393,20 @@ void tst_QQuickMouseArea::dragging() QTRY_COMPARE(blackRect->x(), 61.0); QCOMPARE(blackRect->y(), 61.0); + qreal relativeX = mouseRegion->mouseX(); + qreal relativeY = mouseRegion->mouseY(); + for (int i = 0; i < 20; i++) { + p += QPoint(1, 1); + QTest::mouseMove(&window, p); + } + QTRY_VERIFY(drag->active()); + QTRY_COMPARE(mouseRegion->mouseX(), relativeX); + QCOMPARE(mouseRegion->mouseY(), relativeY); + QTest::mouseRelease(&window, button, Qt::NoModifier, p); QTRY_VERIFY(!drag->active()); - QTRY_COMPARE(blackRect->x(), 61.0); - QCOMPARE(blackRect->y(), 61.0); + QTRY_COMPARE(blackRect->x(), 81.0); + QCOMPARE(blackRect->y(), 81.0); } void tst_QQuickMouseArea::dragSmoothed() diff --git a/tests/auto/quick/qquickpath/qquickpath.pro b/tests/auto/quick/qquickpath/qquickpath.pro index 492f82f53d..ef110a8331 100644 --- a/tests/auto/quick/qquickpath/qquickpath.pro +++ b/tests/auto/quick/qquickpath/qquickpath.pro @@ -7,5 +7,6 @@ SOURCES += tst_qquickpath.cpp include (../../shared/util.pri) TESTDATA = data/* +DISTFILES = data/* QT += core-private gui-private qml-private quick-private testlib diff --git a/tests/auto/quick/qquickpath/tst_qquickpath.cpp b/tests/auto/quick/qquickpath/tst_qquickpath.cpp index 12a8c673b0..c89ce730a8 100644 --- a/tests/auto/quick/qquickpath/tst_qquickpath.cpp +++ b/tests/auto/quick/qquickpath/tst_qquickpath.cpp @@ -42,18 +42,44 @@ public: private slots: void arc(); void angleArc(); - void catmullromCurve(); - void closedCatmullromCurve(); + void catmullRomCurve(); + void closedCatmullRomCurve(); void svg(); void line(); + +private: + void arc(QSizeF scale); + void angleArc(QSizeF scale); + void catmullRomCurve(QSizeF scale, const QVector<QPointF> &points); + void closedCatmullRomCurve(QSizeF scale, const QVector<QPointF> &points); + void svg(QSizeF scale); + void line(QSizeF scale); }; -void tst_QuickPath::arc() +static void compare(const QPointF &point, const QSizeF &scale, int line, double x, double y) +{ + QVERIFY2(qFuzzyCompare(float(point.x()), float(x * scale.width())), + (QStringLiteral("Actual: ") + QString::number(point.x(),'g',14) + + QStringLiteral(" Expected: ") + QString::number(x * scale.width(),'g',14) + + QStringLiteral(" At: ") + QString::number(line)).toLatin1().data()); + QVERIFY2(qFuzzyCompare(float(point.y()), float(y * scale.height())), + (QStringLiteral("Actual: ") + QString::number(point.y(),'g',14) + + QStringLiteral(" Expected: ") + QString::number(y * scale.height(),'g',14) + + QStringLiteral(" At: ") + QString::number(line)).toLatin1().data()); +} +static void compare(const QPointF &point, int line, const QPointF &pt) +{ + return compare(point, QSizeF(1,1), line, pt.x(), pt.y()); +} + +void tst_QuickPath::arc(QSizeF scale) { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("arc.qml")); QQuickPath *obj = qobject_cast<QQuickPath*>(c.create()); QVERIFY(obj != nullptr); + if (scale != QSizeF(1,1)) + obj->setProperty("scale", scale); QCOMPARE(obj->startX(), 0.); QCOMPARE(obj->startY(), 0.); @@ -73,22 +99,30 @@ void tst_QuickPath::arc() QPainterPath path = obj->path(); QVERIFY(path != QPainterPath()); - QPointF pos = obj->pointAt(0); + QPointF pos = obj->pointAtPercent(0); QCOMPARE(pos, QPointF(0,0)); - pos = obj->pointAt(.25); - QCOMPARE(pos.toPoint(), QPoint(39,8)); //fuzzy compare - pos = obj->pointAt(.75); - QCOMPARE(pos.toPoint(), QPoint(92,61)); //fuzzy compare - pos = obj->pointAt(1); - QCOMPARE(pos, QPointF(100,100)); + pos = obj->pointAtPercent(.25); + compare(pos, scale, __LINE__, 38.9244897744, 7.85853964341); + pos = obj->pointAtPercent(.75); + compare(pos, scale, __LINE__, 92.141460356592, 61.07551022559); + pos = obj->pointAtPercent(1); + QCOMPARE(pos, QPointF(100 * scale.width(), 100 * scale.height())); } -void tst_QuickPath::angleArc() +void tst_QuickPath::arc() +{ + arc(QSizeF(1,1)); + arc(QSizeF(2.2,3.4)); +} + +void tst_QuickPath::angleArc(QSizeF scale) { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("anglearc.qml")); QQuickPath *obj = qobject_cast<QQuickPath*>(c.create()); QVERIFY(obj != nullptr); + if (scale != QSizeF(1,1)) + obj->setProperty("scale", scale); QQmlListReference list(obj, "pathElements"); QCOMPARE(list.count(), 1); @@ -106,28 +140,35 @@ void tst_QuickPath::angleArc() QPainterPath path = obj->path(); QVERIFY(path != QPainterPath()); - // using QPoint to do fuzzy compare - QPointF pos = obj->pointAt(0); - QCOMPARE(pos.toPoint(), QPoint(135,135)); - pos = obj->pointAt(.25); - QCOMPARE(pos.toPoint(), QPoint(119,146)); - pos = obj->pointAt(.75); - QCOMPARE(pos.toPoint(), QPoint(81,146)); - pos = obj->pointAt(1); - QCOMPARE(pos.toPoint(), QPoint(65,135)); + QPointF pos = obj->pointAtPercent(0); + compare(pos, scale, __LINE__, 135.35533905867, 135.35533905867); + pos = obj->pointAtPercent(.25); + compare(pos, scale, __LINE__, 119.46222180396, 146.07068621369); + pos = obj->pointAtPercent(.75); + compare(pos, scale, __LINE__, 80.537778196007, 146.07068621366); + pos = obj->pointAtPercent(1); + compare(pos, scale, __LINE__, 64.644660941173, 135.35533905867); // if moveToStart is false, we should have a line starting from startX/Y arc->setMoveToStart(false); - pos = obj->pointAt(0); + pos = obj->pointAtPercent(0); QCOMPARE(pos, QPointF(0,0)); } -void tst_QuickPath::catmullromCurve() +void tst_QuickPath::angleArc() +{ + angleArc(QSizeF(1,1)); + angleArc(QSizeF(2.7,0.92)); +} + +void tst_QuickPath::catmullRomCurve(QSizeF scale, const QVector<QPointF> &points) { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("curve.qml")); QQuickPath *obj = qobject_cast<QQuickPath*>(c.create()); QVERIFY(obj != nullptr); + if (scale != QSizeF(1,1)) + obj->setProperty("scale", scale); QCOMPARE(obj->startX(), 0.); QCOMPARE(obj->startY(), 0.); @@ -148,22 +189,36 @@ void tst_QuickPath::catmullromCurve() QPainterPath path = obj->path(); QVERIFY(path != QPainterPath()); - QPointF pos = obj->pointAt(0); - QCOMPARE(pos, QPointF(0,0)); - pos = obj->pointAt(.25); - QCOMPARE(pos.toPoint(), QPoint(63,26)); //fuzzy compare - pos = obj->pointAt(.75); - QCOMPARE(pos.toPoint(), QPoint(51,105)); //fuzzy compare - pos = obj->pointAt(1); - QCOMPARE(pos.toPoint(), QPoint(100,150)); + QPointF pos = path.pointAtPercent(0); + QCOMPARE(pos, points.at(0)); + pos = path.pointAtPercent(.25); + compare(pos, __LINE__, points.at(1)); + pos = path.pointAtPercent(.75); + compare(pos, __LINE__, points.at(2)); + pos = path.pointAtPercent(1); + compare(pos, __LINE__, points.at(3)); +} + +void tst_QuickPath::catmullRomCurve() +{ + catmullRomCurve(QSizeF(1,1), { QPointF(0,0), + QPointF(62.917022919131, 26.175485291549), + QPointF(51.194527196674 , 105.27985623074), + QPointF(100, 150) }); + catmullRomCurve(QSizeF(2,5.3), { QPointF(0,0), + QPointF(150.80562419914, 170.34065984615), + QPointF(109.08400252853 , 588.35165918579), + QPointF(200, 795) }); } -void tst_QuickPath::closedCatmullromCurve() +void tst_QuickPath::closedCatmullRomCurve(QSizeF scale, const QVector<QPointF> &points) { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("closedcurve.qml")); QQuickPath *obj = qobject_cast<QQuickPath*>(c.create()); QVERIFY(obj != nullptr); + if (scale != QSizeF(1,1)) + obj->setProperty("scale", scale); QCOMPARE(obj->startX(), 50.); QCOMPARE(obj->startY(), 50.); @@ -181,22 +236,36 @@ void tst_QuickPath::closedCatmullromCurve() QPainterPath path = obj->path(); QVERIFY(path != QPainterPath()); - QPointF pos = obj->pointAt(0); - QCOMPARE(pos, QPointF(50,50)); - pos = obj->pointAt(.1); - QCOMPARE(pos.toPoint(), QPoint(67,56)); //fuzzy compare - pos = obj->pointAt(.75); - QCOMPARE(pos.toPoint(), QPoint(44,116)); //fuzzy compare - pos = obj->pointAt(1); - QCOMPARE(pos, QPointF(50,50)); + QPointF pos = path.pointAtPercent(0); + QCOMPARE(pos, points.at(0)); + pos = path.pointAtPercent(.1); + compare(pos, __LINE__, points.at(1)); + pos = path.pointAtPercent(.75); + compare(pos, __LINE__, points.at(2)); + pos = path.pointAtPercent(1); + compare(pos, __LINE__, points.at(3)); } -void tst_QuickPath::svg() +void tst_QuickPath::closedCatmullRomCurve() +{ + closedCatmullRomCurve(QSizeF(1,1), { QPointF(50,50), + QPointF(66.776225481812, 55.617435304145), + QPointF(44.10269379731 , 116.33512508175), + QPointF(50, 50) }); + closedCatmullRomCurve(QSizeF(2,3), { QPointF(100,150), + QPointF(136.49725836178, 170.25466686363), + QPointF(87.713232151943 , 328.29232737977), + QPointF(100, 150) }); +} + +void tst_QuickPath::svg(QSizeF scale) { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("svg.qml")); QQuickPath *obj = qobject_cast<QQuickPath*>(c.create()); QVERIFY(obj != nullptr); + if (scale != QSizeF(1,1)) + obj->setProperty("scale", scale); QCOMPARE(obj->startX(), 0.); QCOMPARE(obj->startY(), 0.); @@ -211,17 +280,23 @@ void tst_QuickPath::svg() QPainterPath path = obj->path(); QVERIFY(path != QPainterPath()); - QPointF pos = obj->pointAt(0); - QCOMPARE(pos, QPointF(200,300)); - pos = obj->pointAt(.25); - QCOMPARE(pos.toPoint(), QPoint(400,175)); //fuzzy compare - pos = obj->pointAt(.75); - QCOMPARE(pos.toPoint(), QPoint(800,425)); //fuzzy compare - pos = obj->pointAt(1); - QCOMPARE(pos, QPointF(1000,300)); + QPointF pos = obj->pointAtPercent(0); + QCOMPARE(pos, QPointF(200 * scale.width(),300 * scale.height())); + pos = obj->pointAtPercent(.25); + QCOMPARE(pos.toPoint(), QPoint(400 * scale.width(),175 * scale.height())); //fuzzy compare + pos = obj->pointAtPercent(.75); + QCOMPARE(pos.toPoint(), QPoint(800 * scale.width(),425 * scale.height())); //fuzzy compare + pos = obj->pointAtPercent(1); + QCOMPARE(pos, QPointF(1000 * scale.width(),300 * scale.height())); } -void tst_QuickPath::line() +void tst_QuickPath::svg() +{ + svg(QSizeF(1,1)); + svg(QSizeF(5,3)); +} + +void tst_QuickPath::line(QSizeF scale) { QQmlEngine engine; QQmlComponent c1(&engine); @@ -234,6 +309,8 @@ void tst_QuickPath::line() QScopedPointer<QObject> o1(c1.create()); QQuickPath *path1 = qobject_cast<QQuickPath *>(o1.data()); QVERIFY(path1); + if (scale != QSizeF(1,1)) + path1->setProperty("scale", scale); QQmlComponent c2(&engine); c2.setData( @@ -246,18 +323,25 @@ void tst_QuickPath::line() QScopedPointer<QObject> o2(c2.create()); QQuickPath *path2 = qobject_cast<QQuickPath *>(o2.data()); QVERIFY(path2); + if (scale != QSizeF(1,1)) + path2->setProperty("scale", scale); for (int i = 0; i < 167; ++i) { qreal t = i / 167.0; - QPointF p1 = path1->pointAt(t); + QPointF p1 = path1->pointAtPercent(t); QCOMPARE(p1.x(), p1.y()); - QPointF p2 = path2->pointAt(t); + QPointF p2 = path2->pointAtPercent(t); QCOMPARE(p1.toPoint(), p2.toPoint()); } } +void tst_QuickPath::line() +{ + line(QSizeF(1,1)); + line(QSizeF(7.23,7.23)); +} QTEST_MAIN(tst_QuickPath) diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index a1b2b64ae2..8b963117ed 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -241,7 +241,7 @@ void tst_QQuickPathView::items() QVERIFY(path); QVERIFY(pathview->highlightItem()); - QPointF start = path->pointAt(0.0); + QPointF start = path->pointAtPercent(0.0); QPointF offset; offset.setX(pathview->highlightItem()->width()/2); offset.setY(pathview->highlightItem()->height()/2); @@ -919,7 +919,7 @@ void tst_QQuickPathView::pathMoved() QVERIFY(firstItem); QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path()); QVERIFY(path); - QPointF start = path->pointAt(0.0); + QPointF start = path->pointAtPercent(0.0); QPointF offset;//Center of item is at point, but pos is from corner offset.setX(firstItem->width()/2); offset.setY(firstItem->height()/2); @@ -928,7 +928,7 @@ void tst_QQuickPathView::pathMoved() for (int i=0; i<model.count(); i++) { QQuickRectangle *curItem = findItem<QQuickRectangle>(pathview, "wrapper", i); - QPointF itemPos(path->pointAt(0.25 + i*0.25)); + QPointF itemPos(path->pointAtPercent(0.25 + i*0.25)); QCOMPARE(curItem->position() + offset, QPointF(itemPos.x(), itemPos.y())); } @@ -1007,7 +1007,7 @@ void tst_QQuickPathView::setCurrentIndex() QVERIFY(firstItem); QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path()); QVERIFY(path); - QPointF start = path->pointAt(0.0); + QPointF start = path->pointAtPercent(0.0); QPointF offset;//Center of item is at point, but pos is from corner offset.setX(firstItem->width()/2); offset.setY(firstItem->height()/2); @@ -1491,11 +1491,11 @@ void tst_QQuickPathView::undefinedPath() // QPainterPath warnings are only received if QT_NO_DEBUG is not defined if (QLibraryInfo::isDebugBuild()) { - QString warning1("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call"); - QTest::ignoreMessage(QtWarningMsg,qPrintable(warning1)); + QRegularExpression warning1("^QPainterPath::moveTo:.*ignoring call$"); + QTest::ignoreMessage(QtWarningMsg, warning1); - QString warning2("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call"); - QTest::ignoreMessage(QtWarningMsg,qPrintable(warning2)); + QRegularExpression warning2("^QPainterPath::lineTo:.*ignoring call$"); + QTest::ignoreMessage(QtWarningMsg, warning2); } QQmlComponent c(&engine, testFileUrl("undefinedpath.qml")); @@ -1648,7 +1648,7 @@ void tst_QQuickPathView::changePreferredHighlight() QVERIFY(firstItem); QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path()); QVERIFY(path); - QPointF start = path->pointAt(0.5); + QPointF start = path->pointAtPercent(0.5); QPointF offset;//Center of item is at point, but pos is from corner offset.setX(firstItem->width()/2); offset.setY(firstItem->height()/2); @@ -1656,7 +1656,7 @@ void tst_QQuickPathView::changePreferredHighlight() pathview->setPreferredHighlightBegin(0.8); pathview->setPreferredHighlightEnd(0.8); - start = path->pointAt(0.8); + start = path->pointAtPercent(0.8); QTRY_COMPARE(firstItem->position() + offset, start); QCOMPARE(pathview->currentIndex(), 0); @@ -1709,7 +1709,7 @@ void tst_QQuickPathView::currentOffsetOnInsertion() QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path()); QVERIFY(path); - QPointF start = path->pointAt(0.5); + QPointF start = path->pointAtPercent(0.5); QPointF offset;//Center of item is at point, but pos is from corner offset.setX(item->width()/2); offset.setY(item->height()/2); @@ -1798,7 +1798,7 @@ void tst_QQuickPathView::asynchronous() QVERIFY(firstItem); QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path()); QVERIFY(path); - QPointF start = path->pointAt(0.0); + QPointF start = path->pointAtPercent(0.0); QPointF offset;//Center of item is at point, but pos is from corner offset.setX(firstItem->width()/2); offset.setY(firstItem->height()/2); @@ -1807,7 +1807,7 @@ void tst_QQuickPathView::asynchronous() for (int i=0; i<5; i++) { QQuickItem *curItem = findItem<QQuickItem>(pathview, "wrapper", i); - QPointF itemPos(path->pointAt(0.2 + i*0.2)); + QPointF itemPos(path->pointAtPercent(0.2 + i*0.2)); QCOMPARE(curItem->position() + offset, itemPos); } diff --git a/tests/auto/quick/qquickrectangle/data/gradient-preset.qml b/tests/auto/quick/qquickrectangle/data/gradient-preset.qml index b740bdd610..c046dc4c05 100644 --- a/tests/auto/quick/qquickrectangle/data/gradient-preset.qml +++ b/tests/auto/quick/qquickrectangle/data/gradient-preset.qml @@ -10,7 +10,23 @@ Item { gradient: "NightFade" } Rectangle { - objectName: "invalid" + objectName: "invalid1" gradient: -1 } + Rectangle { + objectName: "invalid2" + gradient: 123456789 + } + Rectangle { + objectName: "invalid3" + gradient: "NOT_EXISTING" + } + Rectangle { + objectName: "invalid4" + gradient: "NumPresets" + } + Rectangle { + objectName: "invalid5" + gradient: Gradient.NumPresets + } } diff --git a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp index 710caaa734..e4d790f466 100644 --- a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp +++ b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp @@ -189,9 +189,11 @@ void tst_qquickrectangle::gradient_preset() QVERIFY(stringRect->gradient().isString()); QCOMPARE(stringRect->gradient().toString(), QLatin1String("NightFade")); - QQuickRectangle *invalidRect = view.rootObject()->findChild<QQuickRectangle *>("invalid"); - QVERIFY(invalidRect); - QVERIFY(invalidRect->gradient().isUndefined()); + for (int i = 1; i <= 5; ++i) { + QQuickRectangle *invalidRect = view.rootObject()->findChild<QQuickRectangle *>(qPrintable(QString("invalid%1").arg(i))); + QVERIFY(invalidRect); + QVERIFY(invalidRect->gradient().isUndefined()); + } } void tst_qquickrectangle::antialiasing() diff --git a/tests/auto/quick/qquickshape/BLACKLIST b/tests/auto/quick/qquickshape/BLACKLIST deleted file mode 100644 index d0ebc2f505..0000000000 --- a/tests/auto/quick/qquickshape/BLACKLIST +++ /dev/null @@ -1,8 +0,0 @@ -[render] -osx ci -[renderWithMultipleSp] -osx ci -[radialGrad] -osx ci -[conicalGrad] -osx ci diff --git a/tests/auto/quick/qquickshape/data/pathitem7.qml b/tests/auto/quick/qquickshape/data/pathitem7.qml new file mode 100644 index 0000000000..b3ef47a4dd --- /dev/null +++ b/tests/auto/quick/qquickshape/data/pathitem7.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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$ +** +****************************************************************************/ + +import QtQuick 2.14 +import tst_qquickpathitem 1.0 + +Item { + id: item + width: 200 + height: 150 + + Shape { + vendorExtensionsEnabled: false + objectName: "shape" + id: shape + anchors.fill: parent + + ShapePath { + strokeWidth: 4 + strokeColor: "red" + scale: Qt.size(shape.width - 1, shape.height - 1) + fillGradient: LinearGradient { + x1: 20; y1: 20 + x2: 180; y2: 130 + GradientStop { position: 0; color: "blue" } + GradientStop { position: 0.2; color: "green" } + GradientStop { position: 0.4; color: "red" } + GradientStop { position: 0.6; color: "yellow" } + GradientStop { position: 1; color: "cyan" } + } + strokeStyle: ShapePath.DashLine + dashPattern: [ 1, 4 ] + startX: 20; startY: 20 // unnecessary, PathPolyline moves to the first vertex. + PathPolyline { + path: [ Qt.point(20.0 / (item.width - 1.0), 20.0 / (item.height - 1.0)), + Qt.point(180.0 / (item.width - 1.0), 130.0 / (item.height - 1.0)), + Qt.point(20.0 / (item.width - 1.0), 130.0 / (item.height - 1.0)), + Qt.point(20.0 / (item.width - 1.0), 20.0 / (item.height - 1.0)) ] + } + } + } +} diff --git a/tests/auto/quick/qquickshape/qquickshape.pro b/tests/auto/quick/qquickshape/qquickshape.pro index a0e5c002e0..3cf79426c5 100644 --- a/tests/auto/quick/qquickshape/qquickshape.pro +++ b/tests/auto/quick/qquickshape/qquickshape.pro @@ -8,6 +8,7 @@ include (../../shared/util.pri) include (../shared/util.pri) TESTDATA = data/* +DISTFILES = data/* QT += core-private gui-private qml-private quick-private testlib quickshapes-private qtHaveModule(widgets): QT += widgets diff --git a/tests/auto/quick/qquickshape/tst_qquickshape.cpp b/tests/auto/quick/qquickshape/tst_qquickshape.cpp index 61fb260612..174ada65a5 100644 --- a/tests/auto/quick/qquickshape/tst_qquickshape.cpp +++ b/tests/auto/quick/qquickshape/tst_qquickshape.cpp @@ -1,6 +1,6 @@ -/**************************************************************************** +/**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -34,6 +34,7 @@ #include <QtQml/qqmlexpression.h> #include <QtQml/qqmlincubator.h> #include <QtQuickShapes/private/qquickshape_p.h> +#include <QStandardPaths> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -57,6 +58,7 @@ private slots: void renderWithMultipleSp(); void radialGrad(); void conicalGrad(); + void renderPolyline(); }; tst_QQuickShape::tst_QQuickShape() @@ -66,11 +68,12 @@ tst_QQuickShape::tst_QQuickShape() const char *uri = "tst_qquickpathitem"; qmlRegisterType<QQuickShape>(uri, 1, 0, "Shape"); - qmlRegisterType<QQuickShapePath>(uri, 1, 0, "ShapePath"); + qmlRegisterType<QQuickShapePath, 14>(uri, 1, 0, "ShapePath"); qmlRegisterUncreatableType<QQuickShapeGradient>(uri, 1, 0, "ShapeGradient", QQuickShapeGradient::tr("ShapeGradient is an abstract base class")); qmlRegisterType<QQuickShapeLinearGradient>(uri, 1, 0, "LinearGradient"); qmlRegisterType<QQuickShapeRadialGradient>(uri, 1, 0, "RadialGradient"); qmlRegisterType<QQuickShapeConicalGradient>(uri, 1, 0, "ConicalGradient"); + qmlRegisterType<QQuickPathPolyline>(uri, 1, 0, "PathPolyline"); } void tst_QQuickShape::initValues() @@ -311,6 +314,35 @@ void tst_QQuickShape::conicalGrad() qPrintable(errorMessage)); } +void tst_QQuickShape::renderPolyline() +{ + QScopedPointer<QQuickView> window(createView()); + + window->setSource(testFileUrl("pathitem7.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + if ((QGuiApplication::platformName() == QLatin1String("offscreen")) + || (QGuiApplication::platformName() == QLatin1String("minimal"))) + QEXPECT_FAIL("", "Failure due to grabWindow not functional on offscreen/minimimal platforms", Abort); + + QImage img = window->grabWindow(); + QVERIFY(!img.isNull()); + + QImage refImg(testFileUrl("pathitem3.png").toLocalFile()); // It's a recreation of pathitem3 using PathPolyline + QVERIFY(!refImg.isNull()); + + QString errorMessage; + const QImage actualImg = img.convertToFormat(refImg.format()); + const bool res = QQuickVisualTestUtil::compareImages(actualImg, refImg, &errorMessage); + if (!res) { // For visual inspection purposes. + QTest::qWait(5000); + const QString &tempLocation = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + actualImg.save(tempLocation + QLatin1String("/pathitem7.png")); + } + QVERIFY2(res, qPrintable(errorMessage)); +} + QTEST_MAIN(tst_QQuickShape) #include "tst_qquickshape.moc" diff --git a/tests/auto/quick/qquickstates/data/trivialWhen.qml b/tests/auto/quick/qquickstates/data/trivialWhen.qml new file mode 100644 index 0000000000..9f7f3161e9 --- /dev/null +++ b/tests/auto/quick/qquickstates/data/trivialWhen.qml @@ -0,0 +1,5 @@ +import QtQuick 2.12 + +State { + when: true +} diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 50554f6333..1eb797f54f 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -138,6 +138,7 @@ private slots: void QTBUG_38492(); void revertListMemoryLeak(); void duplicateStateName(); + void trivialWhen(); }; void tst_qquickstates::initTestCase() @@ -1665,6 +1666,15 @@ void tst_qquickstates::duplicateStateName() QVERIFY(!item.isNull()); } +// QTBUG-76838 +void tst_qquickstates::trivialWhen() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, testFileUrl("trivialWhen.qml")); + QVERIFY(c.create()); +} + QTEST_MAIN(tst_qquickstates) diff --git a/tests/auto/quick/qquicktext/BLACKLIST b/tests/auto/quick/qquicktext/BLACKLIST index 531d981159..6c3c3af154 100644 --- a/tests/auto/quick/qquicktext/BLACKLIST +++ b/tests/auto/quick/qquicktext/BLACKLIST @@ -1,6 +1,6 @@ [dependentImplicitSizes] -* -[lineLaidOutRelayout] -msvc-2015 +b2qt +qemu +osx-10.12 [fontSizeMode] opensuse-42.1 diff --git a/tests/auto/quick/qquickwindow/BLACKLIST b/tests/auto/quick/qquickwindow/BLACKLIST index 1282a9d5ec..b4b7d2d761 100644 --- a/tests/auto/quick/qquickwindow/BLACKLIST +++ b/tests/auto/quick/qquickwindow/BLACKLIST @@ -1,6 +1,3 @@ [openglContextCreatedSignal] opensuse-42.3 opensuse-leap -# QTBUG-62177 -[attachedProperty] -osx diff --git a/tests/auto/quick/rendernode/tst_rendernode.cpp b/tests/auto/quick/rendernode/tst_rendernode.cpp index 0e06ee6f50..b6028079f3 100644 --- a/tests/auto/quick/rendernode/tst_rendernode.cpp +++ b/tests/auto/quick/rendernode/tst_rendernode.cpp @@ -61,6 +61,9 @@ private slots: void renderOrder(); void messUpState(); void matrix(); + +private: + bool isRunningOnRhi() const; }; class ClearNode : public QSGRenderNode @@ -192,7 +195,7 @@ static bool fuzzyCompareColor(QRgb x, QRgb y, QByteArray *errorMessage) enum { fuzz = 4 }; if (qAbs(qRed(x) - qRed(y)) >= fuzz || qAbs(qGreen(x) - qGreen(y)) >= fuzz || qAbs(qBlue(x) - qBlue(y)) >= fuzz) { QString s; - QDebug(&s).nospace() << hex << "Color mismatch 0x" << x << " 0x" << y << dec << " (fuzz=" << fuzz << ")."; + QDebug(&s).nospace() << Qt::hex << "Color mismatch 0x" << x << " 0x" << y << Qt::dec << " (fuzz=" << fuzz << ")."; *errorMessage = s.toLocal8Bit(); return false; } @@ -218,6 +221,9 @@ void tst_rendernode::renderOrder() || (QGuiApplication::platformName() == QLatin1String("minimal"))) QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); + if (isRunningOnRhi()) + QSKIP("Render nodes not yet supported with QRhi"); + QImage fb = runTest("RenderOrder.qml"); const qreal scaleFactor = QGuiApplication::primaryScreen()->devicePixelRatio(); @@ -247,6 +253,9 @@ void tst_rendernode::messUpState() || (QGuiApplication::platformName() == QLatin1String("minimal"))) QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); + if (isRunningOnRhi()) + QSKIP("Render nodes not yet supported with QRhi"); + QImage fb = runTest("MessUpState.qml"); int x1 = 0; int x2 = fb.width() / 2; @@ -304,6 +313,9 @@ void tst_rendernode::matrix() || (QGuiApplication::platformName() == QLatin1String("minimal"))) QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); + if (isRunningOnRhi()) + QSKIP("Render nodes not yet supported with QRhi"); + qmlRegisterType<StateRecordingRenderNodeItem>("RenderNode", 1, 0, "StateRecorder"); StateRecordingRenderNode::matrices.clear(); runTest("matrix.qml"); @@ -351,6 +363,21 @@ void tst_rendernode::matrix() } } +bool tst_rendernode::isRunningOnRhi() const +{ + static bool retval = false; + static bool decided = false; + if (!decided) { + decided = true; + QQuickView dummy; + dummy.show(); + QTest::qWaitForWindowExposed(&dummy); + QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); + retval = QSGRendererInterface::isApiRhiBased(api); + dummy.hide(); + } + return retval; +} QTEST_MAIN(tst_rendernode) diff --git a/tests/auto/quick/scenegraph/data/render_bug37422.frag b/tests/auto/quick/scenegraph/data/render_bug37422.frag new file mode 100644 index 0000000000..da157232ac --- /dev/null +++ b/tests/auto/quick/scenegraph/data/render_bug37422.frag @@ -0,0 +1,9 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; + +void main() +{ + fragColor = vec4(1, 0, 0, 1); +} diff --git a/tests/auto/quick/scenegraph/data/render_bug37422.frag.qsb b/tests/auto/quick/scenegraph/data/render_bug37422.frag.qsb Binary files differnew file mode 100644 index 0000000000..1233ccfbca --- /dev/null +++ b/tests/auto/quick/scenegraph/data/render_bug37422.frag.qsb diff --git a/tests/auto/quick/scenegraph/data/render_bug37422.qml b/tests/auto/quick/scenegraph/data/render_bug37422.qml index c1b47eddb8..09661d8ccb 100644 --- a/tests/auto/quick/scenegraph/data/render_bug37422.qml +++ b/tests/auto/quick/scenegraph/data/render_bug37422.qml @@ -26,7 +26,7 @@ ** ****************************************************************************/ -import QtQuick 2.2 +import QtQuick 2.12 /* The test verifies that batching does not interfere with overlapping @@ -71,7 +71,9 @@ RenderTestBase width: 100 height: 9 y: 10 - fragmentShader: "varying highp vec2 qt_TexCoord0; void main() { gl_FragColor = vec4(1, 0, 0, 1); }" + fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.GLSL + ? "varying highp vec2 qt_TexCoord0; void main() { gl_FragColor = vec4(1, 0, 0, 1); }" + : "file:data/render_bug37422.frag.qsb" Rectangle { width: 5 diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 063358c795..c15f1e941e 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -70,16 +70,17 @@ public: QColor color() const { return m_color; } - QSGNode *updatePaintNode(QSGNode *old, UpdatePaintNodeData *) + QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) { - if (old) - delete old; - - QSGNode *node = new QSGNode(); - - for (int y=0; y<height(); ++y) { - for (int x=0; x<width(); ++x) { - QSGSimpleRectNode *rn = new QSGSimpleRectNode(); + delete node; + node = new QSGNode; + + const int w = width(); + const int h = height(); + QQuickWindow *win = window(); + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + QSGRectangleNode *rn = win->createRectangleNode(); rn->setRect(x, y, 1, 1); rn->setColor(m_color); node->appendChildNode(rn); @@ -90,7 +91,7 @@ public: } Q_SIGNALS: - void colorChanged(const QColor &c ); + void colorChanged(const QColor &c); private: QColor m_color; @@ -117,7 +118,8 @@ private slots: private: bool m_brokenMipmapSupport; QQuickView *createView(const QString &file, QWindow *parent = nullptr, int x = -1, int y = -1, int w = -1, int h = -1); - bool isRunningOnOpenGL(); + bool isRunningOnOpenGLDirectly(); + bool isRunningOnRhi(); }; template <typename T> class ScopedList : public QList<T> { @@ -402,7 +404,7 @@ void tst_SceneGraph::render_data() << "render_bug37422.qml" << "render_OpacityThroughBatchRoot.qml"; if (!m_brokenMipmapSupport) - files << "render_Mipmap.qml"; + files << "render_Mipmap.qml"; QRegExp sampleCount("#samples: *(\\d+)"); // X:int Y:int R:float G:float B:float Error:float @@ -444,8 +446,8 @@ void tst_SceneGraph::render_data() void tst_SceneGraph::render() { - if (!isRunningOnOpenGL()) - QSKIP("Skipping complex rendering tests due to not running with OpenGL"); + if (!isRunningOnOpenGLDirectly() && !isRunningOnRhi()) + QSKIP("Skipping complex rendering tests due to not running with OpenGL or QRhi"); QFETCH(QString, file); QFETCH(QList<Sample>, baseStage); @@ -495,7 +497,7 @@ void tst_SceneGraph::render() // current on the other window. void tst_SceneGraph::hideWithOtherContext() { - if (!isRunningOnOpenGL()) + if (!isRunningOnOpenGLDirectly()) QSKIP("Skipping OpenGL context test due to not running with OpenGL"); QWindow window; @@ -559,15 +561,37 @@ void tst_SceneGraph::createTextureFromImage() QCOMPARE(texture->hasAlphaChannel(), expectedAlpha); } -bool tst_SceneGraph::isRunningOnOpenGL() +bool tst_SceneGraph::isRunningOnOpenGLDirectly() { - bool retval = false; - QQuickView dummy; - dummy.show(); - QTest::qWaitForWindowExposed(&dummy); - if (dummy.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL) - retval = true; - dummy.hide(); + static bool retval = false; + static bool decided = false; + if (!decided) { + decided = true; + QQuickView dummy; + dummy.show(); + QTest::qWaitForWindowExposed(&dummy); + retval = dummy.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL; + dummy.hide(); + } + return retval; +} + +bool tst_SceneGraph::isRunningOnRhi() +{ + static bool retval = false; + static bool decided = false; + if (!decided) { + decided = true; + QQuickView dummy; + dummy.show(); + if (!QTest::qWaitForWindowExposed(&dummy)) { + [](){ QFAIL("Could not show a QQuickView"); }(); + return false; + } + QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); + retval = QSGRendererInterface::isApiRhiBased(api); + dummy.hide(); + } return retval; } diff --git a/tests/auto/quick/shared/visualtestutil.cpp b/tests/auto/quick/shared/visualtestutil.cpp index de2cf2bd5b..06f7386902 100644 --- a/tests/auto/quick/shared/visualtestutil.cpp +++ b/tests/auto/quick/shared/visualtestutil.cpp @@ -95,7 +95,7 @@ bool QQuickVisualTestUtil::compareImages(const QImage &ia, const QImage &ib, QSt || qAbs(qRed(a) - qRed(b)) > tolerance || qAbs(qRed(a) - qRed(b)) > tolerance) { QDebug(errorMessage) << "Mismatch at:" << x << y << ':' - << hex << showbase << a << b; + << Qt::hex << Qt::showbase << a << b; return false; } } |