aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2017-03-28 13:19:29 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2017-03-30 09:29:19 +0000
commit4cddb73882ed950f652fd1e079bc4cf8ccde93d5 (patch)
tree9861942e82d92641806b2fa296ed151dbe8a3691 /tests
parent83fc08cc6faa5f52a010d7bd821c9606f13d5ae9 (diff)
Add a PathItem autotest for the declarative API
Change-Id: I276c185c93122e5eb05ef6678ab62fa6928f2523 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/examples/tst_examples.cpp1
-rw-r--r--tests/auto/quick/qquickpathitem/data/pathitem1.qml4
-rw-r--r--tests/auto/quick/qquickpathitem/data/pathitem2.qml6
-rw-r--r--tests/auto/quick/qquickpathitem/data/pathitem3.pngbin0 -> 5214 bytes
-rw-r--r--tests/auto/quick/qquickpathitem/data/pathitem3.qml34
-rw-r--r--tests/auto/quick/qquickpathitem/data/pathitem4.pngbin0 -> 5713 bytes
-rw-r--r--tests/auto/quick/qquickpathitem/data/pathitem4.qml61
-rw-r--r--tests/auto/quick/qquickpathitem/qquickpathitem.pro13
-rw-r--r--tests/auto/quick/qquickpathitem/tst_qquickpathitem.cpp244
-rw-r--r--tests/auto/quick/quick.pro1
10 files changed, 364 insertions, 0 deletions
diff --git a/tests/auto/quick/examples/tst_examples.cpp b/tests/auto/quick/examples/tst_examples.cpp
index 0feebb8c1e..b25da6418b 100644
--- a/tests/auto/quick/examples/tst_examples.cpp
+++ b/tests/auto/quick/examples/tst_examples.cpp
@@ -88,6 +88,7 @@ tst_examples::tst_examples()
excludedDirs << "snippets/qml/qtbinding";
excludedDirs << "snippets/qml/imports";
excludedFiles << "examples/quick/pathitem/content/pathitem.qml"; // relies on resources
+ excludedFiles << "examples/quick/pathitem/content/pathiteminteract.qml"; // relies on resources
#ifdef QT_NO_XMLPATTERNS
excludedDirs << "demos/twitter";
diff --git a/tests/auto/quick/qquickpathitem/data/pathitem1.qml b/tests/auto/quick/qquickpathitem/data/pathitem1.qml
new file mode 100644
index 0000000000..885ec7d323
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/data/pathitem1.qml
@@ -0,0 +1,4 @@
+import QtQuick 2.9
+
+PathItem {
+}
diff --git a/tests/auto/quick/qquickpathitem/data/pathitem2.qml b/tests/auto/quick/qquickpathitem/data/pathitem2.qml
new file mode 100644
index 0000000000..9f4a3b5957
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/data/pathitem2.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.9
+
+PathItem {
+ VisualPath { }
+ VisualPath { }
+}
diff --git a/tests/auto/quick/qquickpathitem/data/pathitem3.png b/tests/auto/quick/qquickpathitem/data/pathitem3.png
new file mode 100644
index 0000000000..a8b4483c96
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/data/pathitem3.png
Binary files differ
diff --git a/tests/auto/quick/qquickpathitem/data/pathitem3.qml b/tests/auto/quick/qquickpathitem/data/pathitem3.qml
new file mode 100644
index 0000000000..69a56dd488
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/data/pathitem3.qml
@@ -0,0 +1,34 @@
+import QtQuick 2.9
+
+Item {
+ width: 200
+ height: 150
+
+ PathItem {
+ enableVendorExtensions: false
+ objectName: "pathItem"
+ anchors.fill: parent
+
+ VisualPath {
+ strokeWidth: 4
+ strokeColor: "red"
+ fillGradient: PathLinearGradient {
+ x1: 20; y1: 20
+ x2: 180; y2: 130
+ PathGradientStop { position: 0; color: "blue" }
+ PathGradientStop { position: 0.2; color: "green" }
+ PathGradientStop { position: 0.4; color: "red" }
+ PathGradientStop { position: 0.6; color: "yellow" }
+ PathGradientStop { position: 1; color: "cyan" }
+ }
+ strokeStyle: VisualPath.DashLine
+ dashPattern: [ 1, 4 ]
+ Path {
+ startX: 20; startY: 20
+ PathLine { x: 180; y: 130 }
+ PathLine { x: 20; y: 130 }
+ PathLine { x: 20; y: 20 }
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickpathitem/data/pathitem4.png b/tests/auto/quick/qquickpathitem/data/pathitem4.png
new file mode 100644
index 0000000000..3a988ba249
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/data/pathitem4.png
Binary files differ
diff --git a/tests/auto/quick/qquickpathitem/data/pathitem4.qml b/tests/auto/quick/qquickpathitem/data/pathitem4.qml
new file mode 100644
index 0000000000..74f0ca7408
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/data/pathitem4.qml
@@ -0,0 +1,61 @@
+import QtQuick 2.9
+
+Item {
+ width: 200
+ height: 150
+
+ PathItem {
+ enableVendorExtensions: false
+ objectName: "pathItem"
+ anchors.fill: parent
+
+ VisualPath {
+ strokeColor: "red"
+ fillColor: "green"
+ Path {
+ startX: 40; startY: 30
+ PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 }
+ PathLine { x: 150; y: 80 }
+ PathQuad { x: 160; y: 30; controlX: 200; controlY: 80 }
+ }
+ }
+
+ VisualPath {
+ strokeWidth: 10
+ fillColor: "transparent"
+ strokeColor: "blue"
+ Path {
+ startX: 40; startY: 30
+ PathCubic { x: 50; y: 80; control1X: 0; control1Y: 80; control2X: 100; control2Y: 100 }
+ }
+ }
+
+ VisualPath {
+ fillGradient: PathLinearGradient {
+ y2: 150
+ PathGradientStop { position: 0; color: "yellow" }
+ PathGradientStop { position: 1; color: "green" }
+ }
+
+ Path {
+ startX: 10; startY: 100
+ PathArc {
+ relativeX: 50; y: 100
+ radiusX: 25; radiusY: 25
+ }
+ PathArc {
+ relativeX: 50; y: 100
+ radiusX: 25; radiusY: 35
+ }
+ PathArc {
+ relativeX: 50; y: 100
+ radiusX: 25; radiusY: 60
+ }
+ PathArc {
+ relativeX: 50; y: 100
+ radiusX: 50; radiusY: 120
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickpathitem/qquickpathitem.pro b/tests/auto/quick/qquickpathitem/qquickpathitem.pro
new file mode 100644
index 0000000000..909fbd8027
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/qquickpathitem.pro
@@ -0,0 +1,13 @@
+CONFIG += testcase
+TARGET = tst_qquickpathitem
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qquickpathitem.cpp
+
+include (../../shared/util.pri)
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+QT += core-private gui-private qml-private quick-private testlib
+qtHaveModule(widgets): QT += widgets
diff --git a/tests/auto/quick/qquickpathitem/tst_qquickpathitem.cpp b/tests/auto/quick/qquickpathitem/tst_qquickpathitem.cpp
new file mode 100644
index 0000000000..d18df11c96
--- /dev/null
+++ b/tests/auto/quick/qquickpathitem/tst_qquickpathitem.cpp
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtQuick/qquickview.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlexpression.h>
+#include <QtQml/qqmlincubator.h>
+#include <QtQuick/private/qquickpathitem_p.h>
+
+#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
+#include "../shared/visualtestutil.h"
+
+using namespace QQuickViewTestUtil;
+using namespace QQuickVisualTestUtil;
+
+class tst_QQuickPathItem : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_QQuickPathItem();
+
+private slots:
+ void initValues();
+ void vpInitValues();
+ void basicPathItem();
+ void changeSignals();
+ void render();
+ void renderWithMultipleVp();
+};
+
+tst_QQuickPathItem::tst_QQuickPathItem()
+{
+ // Force the software backend to get reliable rendering results regardless of the hw and drivers.
+ QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
+}
+
+void tst_QQuickPathItem::initValues()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("pathitem1.qml"));
+ QQuickPathItem *obj = qobject_cast<QQuickPathItem *>(c.create());
+
+ QVERIFY(obj != nullptr);
+ QVERIFY(obj->rendererType() == QQuickPathItem::UnknownRenderer);
+ QVERIFY(!obj->asynchronous());
+ QVERIFY(obj->enableVendorExtensions());
+ QVERIFY(obj->status() == QQuickPathItem::Null);
+ auto vps = obj->elements();
+ QVERIFY(vps.count(&vps) == 0);
+
+ delete obj;
+}
+
+void tst_QQuickPathItem::vpInitValues()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("pathitem2.qml"));
+ QQuickPathItem *obj = qobject_cast<QQuickPathItem *>(c.create());
+
+ QVERIFY(obj != nullptr);
+ QVERIFY(obj->rendererType() == QQuickPathItem::UnknownRenderer);
+ QVERIFY(!obj->asynchronous());
+ QVERIFY(obj->enableVendorExtensions());
+ QVERIFY(obj->status() == QQuickPathItem::Null);
+ auto vps = obj->elements();
+ QVERIFY(vps.count(&vps) == 2);
+
+ QQuickVisualPath *vp = vps.at(&vps, 0);
+ QVERIFY(vp != nullptr);
+ QVERIFY(!vp->path());
+ QCOMPARE(vp->strokeColor(), QColor(Qt::white));
+ QCOMPARE(vp->strokeWidth(), 1.0f);
+ QCOMPARE(vp->fillColor(), QColor(Qt::white));
+ QCOMPARE(vp->fillRule(), QQuickVisualPath::OddEvenFill);
+ QCOMPARE(vp->joinStyle(), QQuickVisualPath::BevelJoin);
+ QCOMPARE(vp->miterLimit(), 2);
+ QCOMPARE(vp->capStyle(), QQuickVisualPath::SquareCap);
+ QCOMPARE(vp->strokeStyle(), QQuickVisualPath::SolidLine);
+ QCOMPARE(vp->dashOffset(), 0.0f);
+ QCOMPARE(vp->dashPattern(), QVector<qreal>() << 4 << 2);
+ QVERIFY(!vp->fillGradient());
+
+ delete obj;
+}
+
+void tst_QQuickPathItem::basicPathItem()
+{
+ QScopedPointer<QQuickView> window(createView());
+
+ window->setSource(testFileUrl("pathitem3.qml"));
+ qApp->processEvents();
+
+ QQuickPathItem *obj = findItem<QQuickPathItem>(window->rootObject(), "pathItem");
+ QVERIFY(obj != nullptr);
+ QQmlListReference list(obj, "elements");
+ QCOMPARE(list.count(), 1);
+ QQuickVisualPath *vp = qobject_cast<QQuickVisualPath *>(list.at(0));
+ QVERIFY(vp != nullptr);
+ QCOMPARE(vp->strokeWidth(), 4.0f);
+ QVERIFY(vp->fillGradient() != nullptr);
+ QVERIFY(vp->path() != nullptr);
+ QCOMPARE(vp->strokeStyle(), QQuickVisualPath::DashLine);
+
+ vp->setStrokeWidth(5.0f);
+ QCOMPARE(vp->strokeWidth(), 5.0f);
+
+ QQuickPathLinearGradient *lgrad = qobject_cast<QQuickPathLinearGradient *>(vp->fillGradient());
+ QVERIFY(lgrad != nullptr);
+ QCOMPARE(lgrad->spread(), QQuickPathGradient::PadSpread);
+ QCOMPARE(lgrad->x1(), 20.0f);
+ QQmlListReference stopList(lgrad, "stops");
+ QCOMPARE(stopList.count(), 5);
+ QVERIFY(stopList.at(2) != nullptr);
+
+ QQuickPath *path = vp->path();
+ QCOMPARE(path->startX(), 20.0f);
+ QQmlListReference pathList(path, "pathElements");
+ QCOMPARE(pathList.count(), 3);
+}
+
+void tst_QQuickPathItem::changeSignals()
+{
+ QScopedPointer<QQuickView> window(createView());
+
+ window->setSource(testFileUrl("pathitem3.qml"));
+ qApp->processEvents();
+
+ QQuickPathItem *obj = findItem<QQuickPathItem>(window->rootObject(), "pathItem");
+ QVERIFY(obj != nullptr);
+
+ QSignalSpy asyncPropSpy(obj, SIGNAL(asynchronousChanged()));
+ obj->setAsynchronous(true);
+ obj->setAsynchronous(false);
+ QCOMPARE(asyncPropSpy.count(), 2);
+
+ QQmlListReference list(obj, "elements");
+ QQuickVisualPath *vp = qobject_cast<QQuickVisualPath *>(list.at(0));
+ QVERIFY(vp != nullptr);
+
+ // Verify that VisualPath property changes emit changed().
+ QSignalSpy vpChangeSpy(vp, SIGNAL(changed()));
+ QSignalSpy strokeColorPropSpy(vp, SIGNAL(strokeColorChanged()));
+ vp->setStrokeColor(Qt::blue);
+ vp->setStrokeWidth(1.0f);
+ QQuickPathGradient *g = vp->fillGradient();
+ vp->setFillGradient(nullptr);
+ vp->setFillColor(Qt::yellow);
+ vp->setFillRule(QQuickVisualPath::WindingFill);
+ vp->setJoinStyle(QQuickVisualPath::MiterJoin);
+ vp->setMiterLimit(5);
+ vp->setCapStyle(QQuickVisualPath::RoundCap);
+ vp->setDashOffset(10);
+ vp->setDashPattern(QVector<qreal>() << 1 << 2 << 3 << 4);
+ QCOMPARE(strokeColorPropSpy.count(), 1);
+ QCOMPARE(vpChangeSpy.count(), 10);
+
+ // Verify that property changes from Path and its elements bubble up and result in changed().
+ QQuickPath *path = vp->path();
+ path->setStartX(30);
+ QCOMPARE(vpChangeSpy.count(), 11);
+ QQmlListReference pathList(path, "pathElements");
+ qobject_cast<QQuickPathLine *>(pathList.at(1))->setY(200);
+ QCOMPARE(vpChangeSpy.count(), 12);
+
+ // Verify that property changes from the gradient bubble up and result in changed().
+ vp->setFillGradient(g);
+ QCOMPARE(vpChangeSpy.count(), 13);
+ QQuickPathLinearGradient *lgrad = qobject_cast<QQuickPathLinearGradient *>(g);
+ lgrad->setX2(200);
+ QCOMPARE(vpChangeSpy.count(), 14);
+ QQmlListReference stopList(lgrad, "stops");
+ QCOMPARE(stopList.count(), 5);
+ qobject_cast<QQuickPathGradientStop *>(stopList.at(1))->setPosition(0.3);
+ QCOMPARE(vpChangeSpy.count(), 15);
+ qobject_cast<QQuickPathGradientStop *>(stopList.at(1))->setColor(Qt::black);
+ QCOMPARE(vpChangeSpy.count(), 16);
+}
+
+void tst_QQuickPathItem::render()
+{
+ QScopedPointer<QQuickView> window(createView());
+
+ window->setSource(testFileUrl("pathitem3.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QImage img = window->grabWindow();
+ QVERIFY(!img.isNull());
+
+ QImage refImg(testFileUrl("pathitem3.png").toLocalFile());
+ QVERIFY(!refImg.isNull());
+
+ QVERIFY(QQuickVisualTestUtil::compareImages(img.convertToFormat(refImg.format()), refImg));
+}
+
+void tst_QQuickPathItem::renderWithMultipleVp()
+{
+ QScopedPointer<QQuickView> window(createView());
+
+ window->setSource(testFileUrl("pathitem4.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QImage img = window->grabWindow();
+ QVERIFY(!img.isNull());
+
+ QImage refImg(testFileUrl("pathitem4.png").toLocalFile());
+ QVERIFY(!refImg.isNull());
+
+ QVERIFY(QQuickVisualTestUtil::compareImages(img.convertToFormat(refImg.format()), refImg));
+}
+
+QTEST_MAIN(tst_QQuickPathItem)
+
+#include "tst_qquickpathitem.moc"
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index 6e9998c061..9b1657e2a2 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -69,6 +69,7 @@ QUICKTESTS = \
qquickmousearea \
qquickmultipointtoucharea \
qquickpainteditem \
+ qquickpathitem \
qquickpathview \
qquickpincharea \
qquickpositioners \