blob: a2f3382b2ee508279596147d2fca8441a77c127c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
#include <QtTest/QSignalSpy>
#include <QtCore/qfileinfo.h>
#include <QtCore/qdir.h>
#include <QtQml/qqmlcontext.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
#include <QtQuick/qquickitem.h>
#include <QtQuickShapes/private/qquickshape_p.h>
#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtQuickTestUtils/private/viewtestutils_p.h>
#include <QtQuickTestUtils/private/visualtestutils_p.h>
class tst_QQuickVectorImage : public QQmlDataTest
{
Q_OBJECT
public:
tst_QQuickVectorImage();
private slots:
void parseFiles_data();
void parseFiles();
void parseBrokenFile();
void asyncShapes_data();
void asyncShapes();
};
tst_QQuickVectorImage::tst_QQuickVectorImage()
: QQmlDataTest(QT_QMLTEST_DATADIR)
{
}
void tst_QQuickVectorImage::parseFiles_data()
{
QTest::addColumn<QString>("fileName");
QDir dir(QStringLiteral(":/svgs"));
const QFileInfoList infos = dir.entryInfoList({ QStringLiteral("*.svg") });
QVERIFY(!infos.isEmpty());
for (const QFileInfo &info : infos) {
QString fileName = info.fileName();
QByteArray rowName = fileName.toUtf8();
QTest::newRow(rowName) << fileName;
}
}
void tst_QQuickVectorImage::parseFiles()
{
QFETCH(QString, fileName);
QQmlEngine engine;
engine.rootContext()->setContextProperty(QStringLiteral("fileName"), QStringLiteral("qrc:/svgs/%1").arg(fileName));
QQmlComponent c(&engine, testFileUrl("vectorimage.qml"));
QQuickItem *item = qobject_cast<QQuickItem *>(c.create());
auto cleanup = qScopeGuard([&item] {
delete item;
item = nullptr;
});
QVERIFY(item != nullptr);
QVERIFY(!item->childItems().isEmpty());
QVERIFY(!item->childItems().first()->size().isNull());
}
void tst_QQuickVectorImage::parseBrokenFile()
{
QQmlEngine engine;
engine.rootContext()->setContextProperty(QStringLiteral("fileName"), testFileUrl("svg/broken.svg"));
QQmlComponent c(&engine, testFileUrl("vectorimage.qml"));
QQuickItem *item = qobject_cast<QQuickItem *>(c.create());
auto cleanup = qScopeGuard([&item] {
delete item;
item = nullptr;
});
QVERIFY(item != nullptr);
QVERIFY(!item->childItems().isEmpty());
QVERIFY(item->childItems().first()->size().isNull());
}
void tst_QQuickVectorImage::asyncShapes_data()
{
QTest::addColumn<QString>("testFile");
QTest::addColumn<bool>("isAsync");
QTest::newRow("sync") << "vectorimage.qml" << false;
QTest::newRow("async") << "vectorimage-async.qml" << true;
}
void tst_QQuickVectorImage::asyncShapes()
{
QFETCH(QString, testFile);
QFETCH(bool, isAsync);
QQmlEngine engine;
engine.rootContext()->setContextProperty(QStringLiteral("fileName"), QStringLiteral("qrc:/svgs/gradientxform.svg"));
QQmlComponent c(&engine, testFileUrl(testFile));
QQuickItem *item = qobject_cast<QQuickItem *>(c.create());
auto cleanup = qScopeGuard([&item] {
delete item;
item = nullptr;
});
QVERIFY(item != nullptr);
QVERIFY(!item->childItems().isEmpty());
QVERIFY(!item->childItems().first()->size().isNull());
const QList<const QQuickShape *> shapes = item->findChildren<const QQuickShape *>();
QVERIFY(!shapes.isEmpty());
for (const QQuickShape *shape : shapes)
QCOMPARE(shape->asynchronous(), isAsync);
}
QTEST_MAIN(tst_QQuickVectorImage)
#include "tst_qquickvectorimage.moc"
|