summaryrefslogtreecommitdiff
path: root/tests/auto/qsvgrenderer
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-06-17 13:28:57 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-06-17 13:29:56 +0200
commitf33a29a8dbe03cbe9e59f9e5124f15e90b6336fc (patch)
tree09ba56a3338604358e53c7a33c35d29dc32860a6 /tests/auto/qsvgrenderer
parent3864601f76e0b212ec69ad64409d939fd021fbd2 (diff)
parent5c298ef5bea0930b68263ba84194250dbb9d26a9 (diff)
downloadqtsvg-f33a29a8dbe03cbe9e59f9e5124f15e90b6336fc.tar.gz
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: Icb0da709c1cb8d2bdc2f33edfe656b7821cb148a
Diffstat (limited to 'tests/auto/qsvgrenderer')
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp110
1 files changed, 94 insertions, 16 deletions
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index 553838e..cf19213 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -67,6 +67,8 @@ private slots:
void boundsOnElement() const;
void gradientStops() const;
void gradientRefs();
+ void recursiveRefs_data();
+ void recursiveRefs();
void fillRule();
void opacity();
void paths();
@@ -77,6 +79,7 @@ private slots:
void testUseElement();
void smallFont();
void styleSheet();
+ void duplicateStyleId();
#ifndef QT_NO_COMPRESS
void testGzLoading();
@@ -139,22 +142,28 @@ void tst_QSvgRenderer::invalidUrl_data()
{
QTest::addColumn<QByteArray>("svg");
- QTest::newRow("00") << QByteArray("<svg><circle fill=\"url\" /></svg>");
- QTest::newRow("01") << QByteArray("<svg><circle fill=\"url0\" /></svg>");
- QTest::newRow("02") << QByteArray("<svg><circle fill=\"url(0\" /></svg>");
- QTest::newRow("03") << QByteArray("<svg><circle fill=\"url (0\" /></svg>");
- QTest::newRow("04") << QByteArray("<svg><circle fill=\"url ( 0\" /></svg>");
- QTest::newRow("05") << QByteArray("<svg><circle fill=\"url#\" /></svg>");
- QTest::newRow("06") << QByteArray("<svg><circle fill=\"url#(\" /></svg>");
- QTest::newRow("07") << QByteArray("<svg><circle fill=\"url(#\" /></svg>");
- QTest::newRow("08") << QByteArray("<svg><circle fill=\"url(# \" /></svg>");
- QTest::newRow("09") << QByteArray("<svg><circle fill=\"url(# 0\" /></svg>");
+ QTest::newRow("01") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url0\" /></svg>");
+ QTest::newRow("02") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(0\" /></svg>");
+ QTest::newRow("03") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url (0\" /></svg>");
+ QTest::newRow("04") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url ( 0\" /></svg>");
+ QTest::newRow("05") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url#\" /></svg>");
+ QTest::newRow("06") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url#(\" /></svg>");
+ QTest::newRow("07") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(#\" /></svg>");
+ QTest::newRow("08") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(# \" /></svg>");
+ QTest::newRow("09") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(# 0\" /></svg>");
+ QTest::newRow("10") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"urlblabla\" /></svg>");
+ QTest::newRow("11") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"url(blabla\" /></svg>");
+ QTest::newRow("12") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"url(blabla)\" /></svg>");
+ QTest::newRow("13") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"url(#blabla\" /></svg>");
}
void tst_QSvgRenderer::invalidUrl()
{
QFETCH(QByteArray, svg);
+#if QT_CONFIG(regularexpression)
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Could not resolve property"));
+#endif
QSvgRenderer renderer(svg);
QVERIFY(renderer.isValid());
}
@@ -259,6 +268,16 @@ void tst_QSvgRenderer::testMapViewBoxToTarget()
QCOMPARE(picture.boundingRect(), QRect(125, 125, 250, 250));
}
+ { // Viewport and viewBox specified -> scale 500x500 square to 1000x750 while preserving aspect ratio gives 750x750
+ // however the box is centered at 375, 250
+ data = "<svg width=\"1000\" height=\"750\" viewBox=\"-250 -250 500 500\"><g><rect x=\"0\" y=\"0\" width=\"500\" height=\"500\" /></g></svg>";
+ QPicture picture;
+ QPainter painter(&picture);
+ QSvgRenderer rend(data);
+ rend.render(&painter);
+ painter.end();
+ QCOMPARE(picture.boundingRect(), QRect(375, 250, 750, 750));
+ }
}
void tst_QSvgRenderer::testRenderElement()
@@ -476,15 +495,15 @@ void tst_QSvgRenderer::matrixForElement() const
QPainter painter(&image);
QSvgRenderer renderer(data);
- compareTransforms(QTransform(painter.worldMatrix()), QTransform(renderer.matrixForElement(QLatin1String("ichi"))));
+ compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("ichi"))));
painter.translate(-3, 1);
- compareTransforms(QTransform(painter.worldMatrix()), QTransform(renderer.matrixForElement(QLatin1String("ni"))));
+ compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("ni"))));
painter.rotate(45);
- compareTransforms(QTransform(painter.worldMatrix()), QTransform(renderer.matrixForElement(QLatin1String("san"))));
+ compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("san"))));
painter.scale(4, 2);
- compareTransforms(QTransform(painter.worldMatrix()), QTransform(renderer.matrixForElement(QLatin1String("yon"))));
- painter.setWorldMatrix(QMatrix(1, 2, 3, 4, 5, 6), true);
- compareTransforms(QTransform(painter.worldMatrix()), QTransform(renderer.matrixForElement(QLatin1String("firkant"))));
+ compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("yon"))));
+ painter.setWorldTransform(QTransform(1, 2, 3, 4, 5, 6), true);
+ compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("firkant"))));
}
void tst_QSvgRenderer::boundsOnElement() const
@@ -667,6 +686,43 @@ void tst_QSvgRenderer::gradientRefs()
}
}
+void tst_QSvgRenderer::recursiveRefs_data()
+{
+ QTest::addColumn<QByteArray>("svg");
+
+ QTest::newRow("single") << QByteArray("<svg>"
+ "<linearGradient id='0' xlink:href='#0'/>"
+ "<rect x='0' y='0' width='20' height='20' fill='url(#0)'/>"
+ "</svg>");
+
+ QTest::newRow("double") << QByteArray("<svg>"
+ "<linearGradient id='0' xlink:href='#1'/>"
+ "<linearGradient id='1' xlink:href='#0'/>"
+ "<rect x='0' y='0' width='20' height='20' fill='url(#0)'/>"
+ "</svg>");
+
+ QTest::newRow("triple") << QByteArray("<svg>"
+ "<linearGradient id='0' xlink:href='#1'/>"
+ "<linearGradient id='1' xlink:href='#2'/>"
+ "<linearGradient id='2' xlink:href='#0'/>"
+ "<rect x='0' y='0' width='20' height='20' fill='url(#0)'/>"
+ "</svg>");
+}
+
+void tst_QSvgRenderer::recursiveRefs()
+{
+ QFETCH(QByteArray, svg);
+
+ QImage image(20, 20, QImage::Format_ARGB32_Premultiplied);
+ image.fill(Qt::green);
+ QImage refImage = image.copy();
+
+ QSvgRenderer renderer(svg);
+ QPainter painter(&image);
+ renderer.render(&painter);
+ QCOMPARE(image, refImage);
+}
+
#ifndef QT_NO_COMPRESS
void tst_QSvgRenderer::testGzLoading()
@@ -1377,6 +1433,16 @@ void tst_QSvgRenderer::testUseElement()
" <circle fill=\"#a6ce39\" cx=\"0\" cy=\"0\" r=\"33\" />"
" </g>"
" </defs>"
+ "</svg>",
+ // 17 - Indirect self referral
+ "<svg>"
+ " <defs>"
+ " <g id=\"g0\">"
+ " <g id=\"g1\"><use href=\"#g2\"/></g>"
+ " <g id=\"g2\"><use href=\"#g1\"/></g>"
+ " </g>"
+ " </defs>"
+ " <use xlink:href=\"#g0\" fill=\"black\"/>"
"</svg>"
};
@@ -1459,5 +1525,17 @@ void tst_QSvgRenderer::styleSheet()
QCOMPARE(images[0], images[1]);
}
+void tst_QSvgRenderer::duplicateStyleId()
+{
+ QByteArray svg = QByteArrayLiteral("<svg><linearGradient id=\"a\"/>"
+ "<rect style=\"fill:url(#a)\"/>"
+ "<linearGradient id=\"a\"/></svg>");
+ QTest::ignoreMessage(QtWarningMsg, "Duplicate unique style id: \"a\"");
+ QImage image(200, 200, QImage::Format_RGB32);
+ QPainter painter(&image);
+ QSvgRenderer renderer(svg);
+ renderer.render(&painter);
+}
+
QTEST_MAIN(tst_QSvgRenderer)
#include "tst_qsvgrenderer.moc"