summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qsvgplugin/imageInclude.svg18
-rw-r--r--tests/auto/qsvgplugin/imageIncludeA.svg5
-rw-r--r--tests/auto/qsvgplugin/resources.qrc2
-rw-r--r--tests/auto/qsvgplugin/tst_qsvgplugin.cpp41
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp45
5 files changed, 106 insertions, 5 deletions
diff --git a/tests/auto/qsvgplugin/imageInclude.svg b/tests/auto/qsvgplugin/imageInclude.svg
new file mode 100644
index 0000000..c78d3fa
--- /dev/null
+++ b/tests/auto/qsvgplugin/imageInclude.svg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg version="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100">
+ <circle cx="50" cy="50" r="25" fill="#00ff00" />
+
+ <image x="0" y="0" width="100" height="100" xlink:href="imageIncludeA.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="./imageIncludeA.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href=":/imageIncludeA.svg" />
+
+ <image x="0" y="0" width="100" height="100" xlink:href="notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="./notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="../notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="/notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href=":/notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="qrc:///notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="file:///notExisting.svg" />
+ <image x="0" y="0" width="100" height="100" xlink:href="http://qt.io/notExisting.svg" />
+</svg>
diff --git a/tests/auto/qsvgplugin/imageIncludeA.svg b/tests/auto/qsvgplugin/imageIncludeA.svg
new file mode 100644
index 0000000..5811505
--- /dev/null
+++ b/tests/auto/qsvgplugin/imageIncludeA.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg version="1.0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
+ <circle cx="50" cy="50" r="25" fill="#00ff00" />
+</svg>
diff --git a/tests/auto/qsvgplugin/resources.qrc b/tests/auto/qsvgplugin/resources.qrc
index fcb311a..fd83b80 100644
--- a/tests/auto/qsvgplugin/resources.qrc
+++ b/tests/auto/qsvgplugin/resources.qrc
@@ -1,5 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
+ <file>imageInclude.svg</file>
+ <file>imageIncludeA.svg</file>
<file>square.svg</file>
<file>square_size.svg</file>
<file>square_size_viewbox.svg</file>
diff --git a/tests/auto/qsvgplugin/tst_qsvgplugin.cpp b/tests/auto/qsvgplugin/tst_qsvgplugin.cpp
index 4ec1737..da49b75 100644
--- a/tests/auto/qsvgplugin/tst_qsvgplugin.cpp
+++ b/tests/auto/qsvgplugin/tst_qsvgplugin.cpp
@@ -39,6 +39,16 @@
#endif
+QStringList logMessages;
+
+static void messageHandler(QtMsgType pType, const QMessageLogContext& pContext, const QString& pMsg)
+{
+ Q_UNUSED(pType);
+ Q_UNUSED(pContext);
+ logMessages.append(pMsg);
+}
+
+
class tst_QSvgPlugin : public QObject
{
Q_OBJECT
@@ -50,6 +60,7 @@ public:
private slots:
void checkSize_data();
void checkSize();
+ void checkImageInclude();
};
@@ -103,6 +114,36 @@ void tst_QSvgPlugin::checkSize()
QCOMPARE(imageWidth, image.width());
}
+void tst_QSvgPlugin::checkImageInclude()
+{
+ const QString filename(SRCDIR "imageInclude.svg");
+
+ QFile file(filename);
+ file.open(QIODevice::ReadOnly);
+
+ QSvgIOHandler plugin;
+ plugin.setDevice(&file);
+
+ QImage image;
+ qInstallMessageHandler(messageHandler);
+ plugin.read(&image);
+ qInstallMessageHandler(nullptr);
+
+ file.close();
+
+ QCOMPARE(logMessages.size(), 8);
+ QCOMPARE(logMessages.at(0), QString("Could not create image from \"%1notExisting.svg\"").arg(SRCDIR));
+ QCOMPARE(logMessages.at(1), QString("Could not create image from \"%1./notExisting.svg\"").arg(SRCDIR));
+ QCOMPARE(logMessages.at(2), QString("Could not create image from \"%1../notExisting.svg\"").arg(SRCDIR));
+ QCOMPARE(logMessages.at(3), QString("Could not create image from \"%1notExisting.svg\"").arg(QDir::rootPath()));
+ QCOMPARE(logMessages.at(4), QLatin1String("Could not create image from \":/notExisting.svg\""));
+ QCOMPARE(logMessages.at(5), QLatin1String("Could not create image from \"qrc:///notExisting.svg\""));
+ QCOMPARE(logMessages.at(6), QLatin1String("Could not create image from \"file:///notExisting.svg\""));
+ QCOMPARE(logMessages.at(7), QLatin1String("Could not create image from \"http://qt.io/notExisting.svg\""));
+
+ logMessages.clear();
+}
+
QTEST_MAIN(tst_QSvgPlugin)
#include "tst_qsvgplugin.moc"
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index a8fc9de..5e13bee 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -1261,32 +1261,36 @@ void tst_QSvgRenderer::testStopOffsetOpacity()
void tst_QSvgRenderer::testUseElement()
{
static const char *svgs[] = {
- //Use referring to non group node (1)
+ // 0 - Use referring to non group node (1)
"<svg viewBox = \"0 0 200 200\">"
" <polygon points=\"20,20 50,120 100,10 40,80 50,80\"/>"
" <polygon points=\"20,80 50,180 100,70 40,140 50,140\" fill= \"red\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\" stroke-width = \"3\"/>"
"</svg>",
+ // 1
"<svg viewBox = \"0 0 200 200\">"
" <polygon id = \"usedPolyline\" points=\"20,20 50,120 100,10 40,80 50,80\"/>"
" <use y = \"60\" xlink:href = \"#usedPolyline\" fill= \"red\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\" stroke-width = \"3\"/>"
"</svg>",
+ // 2
"<svg viewBox = \"0 0 200 200\">"
" <polygon id = \"usedPolyline\" points=\"20,20 50,120 100,10 40,80 50,80\"/>"
" <g fill = \" red\" fill-opacity =\"0.2\">"
"<use y = \"60\" xlink:href = \"#usedPolyline\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\" stroke-width = \"3\"/>"
"</g>"
"</svg>",
+ // 3
"<svg viewBox = \"0 0 200 200\">"
" <polygon id = \"usedPolyline\" points=\"20,20 50,120 100,10 40,80 50,80\"/>"
" <g stroke-width = \"3\" stroke = \"yellow\">"
" <use y = \"60\" xlink:href = \"#usedPolyline\" fill = \" red\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\"/>"
" </g>"
"</svg>",
- //Use referring to non group node (2)
+ // 4 - Use referring to non group node (2)
"<svg viewBox = \"0 0 200 200\">"
" <polygon points=\"20,20 50,120 100,10 40,80 50,80\" fill = \"green\" fill-rule = \"nonzero\" stroke = \"purple\" stroke-width = \"4\" stroke-dasharray = \"1,1,3,1\" stroke-offset = \"3\" stroke-miterlimit = \"6\" stroke-linecap = \"butt\" stroke-linejoin = \"round\"/>"
" <polygon points=\"20,80 50,180 100,70 40,140 50,140\" fill= \"red\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\" stroke-width = \"3\" stroke-dasharray = \"1,1,1,1\" stroke-offset = \"5\" stroke-miterlimit = \"3\" stroke-linecap = \"butt\" stroke-linejoin = \"square\"/>"
"</svg>",
+ // 5
"<svg viewBox = \"0 0 200 200\">"
" <g fill = \"green\" fill-rule = \"nonzero\" stroke = \"purple\" stroke-width = \"4\" stroke-dasharray = \"1,1,3,1\" stroke-offset = \"3\" stroke-miterlimit = \"6\" stroke-linecap = \"butt\" stroke-linejoin = \"round\">"
" <polygon id = \"usedPolyline\" points=\"20,20 50,120 100,10 40,80 50,80\" />"
@@ -1295,6 +1299,7 @@ void tst_QSvgRenderer::testUseElement()
" <use y = \"60\" xlink:href = \"#usedPolyline\" fill-opacity = \"0.7\" fill= \"red\" stroke = \"blue\" fill-rule = \"evenodd\"/>"
" </g>"
"</svg>",
+ // 6
"<svg viewBox = \"0 0 200 200\">"
" <g fill = \"green\" fill-rule = \"nonzero\" stroke = \"purple\" stroke-width = \"4\" stroke-dasharray = \"1,1,3,1\" stroke-offset = \"3\" stroke-miterlimit = \"6\" stroke-linecap = \"butt\" stroke-linejoin = \"round\">"
" <polygon id = \"usedPolyline\" points=\"20,20 50,120 100,10 40,80 50,80\" />"
@@ -1303,7 +1308,7 @@ void tst_QSvgRenderer::testUseElement()
" <use y = \"60\" xlink:href = \"#usedPolyline\" fill= \"red\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\" />"
" </g>"
"</svg>",
- //Use referring to group node
+ // 7 - Use referring to group node
"<svg viewBox = \"0 0 200 200\">"
" <g>"
" <circle cx=\"0\" cy=\"0\" r=\"100\" fill = \"red\" fill-opacity = \"0.6\"/>"
@@ -1311,6 +1316,7 @@ void tst_QSvgRenderer::testUseElement()
" <circle fill=\"#a6ce39\" cx=\"0\" cy=\"0\" r=\"33\" fill-opacity = \"0.5\"/>"
" </g>"
"</svg>",
+ // 8
"<svg viewBox = \"0 0 200 200\">"
" <defs>"
" <g id=\"usedG\">"
@@ -1321,6 +1327,7 @@ void tst_QSvgRenderer::testUseElement()
" </defs>"
" <use xlink:href =\"#usedG\" fill = \"red\" fill-opacity =\"0.5\"/>"
"</svg>",
+ // 9
"<svg viewBox = \"0 0 200 200\">"
" <defs>"
" <g fill = \"blue\" fill-opacity = \"0.3\">"
@@ -1335,16 +1342,40 @@ void tst_QSvgRenderer::testUseElement()
" <use xlink:href =\"#usedG\" />"
" </g>"
"</svg>",
- // Self referral, should be ignored
+ // 10 - Self referral, should be ignored
"<svg><g id=\"0\"><use xlink:href=\"#0\" /></g></svg>",
+ // 11
"<svg width=\"200\" height=\"200\">"
" <rect width=\"100\" height=\"50\"/>"
"</svg>",
+ // 12
"<svg width=\"200\" height=\"200\">"
" <g id=\"0\"><use xlink:href=\"#0\" /><rect width=\"100\" height=\"50\"/></g>"
"</svg>",
+ // 13
"<svg width=\"200\" height=\"200\">"
" <g id=\"0\"><g><use xlink:href=\"#0\" /><rect width=\"100\" height=\"50\"/></g></g>"
+ "</svg>",
+ // 14 (undefined)
+ "<svg width=\"200\" height=\"200\">"
+ " <rect width=\"100\" height=\"50\"/>"
+ " <use x=\"100\" y=\"100\" opacity=\"0.5\" xlink:href=\"#nosuch\" />"
+ "</svg>",
+ // 15 - Forward references
+ "<svg viewBox = \"0 0 200 200\">"
+ " <use y = \"60\" xlink:href = \"#usedPolyline\" fill= \"red\" stroke = \"blue\" fill-opacity = \"0.7\" fill-rule = \"evenodd\" stroke-width = \"3\"/>"
+ " <polygon id = \"usedPolyline\" points=\"20,20 50,120 100,10 40,80 50,80\"/>"
+ "</svg>",
+ // 16
+ "<svg viewBox = \"0 0 200 200\">"
+ " <use xlink:href =\"#usedG\" fill = \"red\" fill-opacity =\"0.5\"/>"
+ " <defs>"
+ " <g id=\"usedG\">"
+ " <circle cx=\"0\" cy=\"0\" r=\"100\" fill-opacity = \"0.6\"/>"
+ " <rect x = \"10\" y = \"10\" width = \"30\" height = \"30\"/>"
+ " <circle fill=\"#a6ce39\" cx=\"0\" cy=\"0\" r=\"33\" />"
+ " </g>"
+ " </defs>"
"</svg>"
};
@@ -1373,8 +1404,12 @@ void tst_QSvgRenderer::testUseElement()
}
} else if (i > 7 && i < 10) {
QCOMPARE(images[8], images[i]);
- } else if (i > 11) {
+ } else if (i > 11 && i < 15) {
QCOMPARE(images[11], images[i]);
+ } else if (i == 15) {
+ QCOMPARE(images[0], images[i]);
+ } else if (i == 16) {
+ QCOMPARE(images[8], images[i]);
}
}
}