summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsvgrenderer
diff options
context:
space:
mode:
authorSuneel BS <suneel.b-s@nokia.com>2009-05-14 08:55:16 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-07-09 11:12:16 (GMT)
commited564a3fef39b649bd38a181126711431f0b40ab (patch)
treec743a856f73ab1fb1a47504c984be5bc47b204cf /tests/auto/qsvgrenderer
parent1c6edd28d528dbb946fcf2a9e0d4349075ca6f9b (diff)
downloadQt-ed564a3fef39b649bd38a181126711431f0b40ab.zip
Qt-ed564a3fef39b649bd38a181126711431f0b40ab.tar.gz
Qt-ed564a3fef39b649bd38a181126711431f0b40ab.tar.bz2
Fixed handling of some SVG attributes when value is invalid.
When the parsing of an SVG attribute fails, it should be given the default value. Fixed handling of invalid viewBox, stop-opacity and stop-offset. Autotest included. Reviewed-by: Kim
Diffstat (limited to 'tests/auto/qsvgrenderer')
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index 68539ef..2bbe897 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -82,6 +82,7 @@ private slots:
void displayMode();
void strokeInherit();
void testFillInheritance();
+ void testStopOffsetOpacity();
#ifndef QT_NO_COMPRESS
void testGzLoading();
@@ -1121,5 +1122,88 @@ void tst_QSvgRenderer::testFillInheritance()
}
}
}
+void tst_QSvgRenderer::testStopOffsetOpacity()
+{
+ static const char *svgs[] = {
+ //reference
+ "<svg viewBox=\"0 0 64 64\">"
+ "<radialGradient id=\"MyGradient1\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"50\" r=\"30\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"0.0\" style=\"stop-color:red\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:green\" stop-opacity=\"1\"/>"
+ "<stop offset=\"1\" style=\"stop-color:yellow\" stop-opacity=\"1\"/>"
+ "</radialGradient>"
+ "<radialGradient id=\"MyGradient2\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"70\" r=\"70\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"0.0\" style=\"stop-color:blue\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:violet\" stop-opacity=\"1\"/>"
+ "<stop offset=\"1\" style=\"stop-color:orange\" stop-opacity=\"1\"/>"
+ "</radialGradient>"
+ "<rect x=\"5\" y=\"5\" width=\"55\" height=\"55\" fill=\"url(#MyGradient1)\" stroke=\"black\" />"
+ "<rect x=\"20\" y=\"20\" width=\"35\" height=\"35\" fill=\"url(#MyGradient2)\"/>"
+ "</svg>",
+ //Stop Offset
+ "<svg viewBox=\"0 0 64 64\">"
+ "<radialGradient id=\"MyGradient1\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"50\" r=\"30\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"abc\" style=\"stop-color:red\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:green\" stop-opacity=\"1\"/>"
+ "<stop offset=\"1\" style=\"stop-color:yellow\" stop-opacity=\"1\"/>"
+ "</radialGradient>"
+ "<radialGradient id=\"MyGradient2\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"70\" r=\"70\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"-3.bc\" style=\"stop-color:blue\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:violet\" stop-opacity=\"1\"/>"
+ "<stop offset=\"1\" style=\"stop-color:orange\" stop-opacity=\"1\"/>"
+ "</radialGradient>"
+ "<rect x=\"5\" y=\"5\" width=\"55\" height=\"55\" fill=\"url(#MyGradient1)\" stroke=\"black\" />"
+ "<rect x=\"20\" y=\"20\" width=\"35\" height=\"35\" fill=\"url(#MyGradient2)\"/>"
+ "</svg>",
+ //Stop Opacity
+ "<svg viewBox=\"0 0 64 64\">"
+ "<radialGradient id=\"MyGradient1\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"50\" r=\"30\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"0.0\" style=\"stop-color:red\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:green\" stop-opacity=\"x.45\"/>"
+ "<stop offset=\"1\" style=\"stop-color:yellow\" stop-opacity=\"-3.abc\"/>"
+ "</radialGradient>"
+ "<radialGradient id=\"MyGradient2\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"70\" r=\"70\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"0.0\" style=\"stop-color:blue\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:violet\" stop-opacity=\"-0.xy\"/>"
+ "<stop offset=\"1\" style=\"stop-color:orange\" stop-opacity=\"z.5\"/>"
+ "</radialGradient>"
+ "<rect x=\"5\" y=\"5\" width=\"55\" height=\"55\" fill=\"url(#MyGradient1)\" stroke=\"black\" />"
+ "<rect x=\"20\" y=\"20\" width=\"35\" height=\"35\" fill=\"url(#MyGradient2)\"/>"
+ "</svg>",
+ //Stop offset and Stop opacity
+ "<svg viewBox=\"0 0 64 64\">"
+ "<radialGradient id=\"MyGradient1\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"50\" r=\"30\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"abc\" style=\"stop-color:red\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:green\" stop-opacity=\"x.45\"/>"
+ "<stop offset=\"1\" style=\"stop-color:yellow\" stop-opacity=\"-3.abc\"/>"
+ "</radialGradient>"
+ "<radialGradient id=\"MyGradient2\" gradientUnits=\"userSpaceOnUse\" cx=\"50\" cy=\"70\" r=\"70\" fx=\"20\" fy=\"20\">"
+ "<stop offset=\"-3.bc\" style=\"stop-color:blue\" stop-opacity=\"0.3\"/>"
+ "<stop offset=\"0.5\" style=\"stop-color:violet\" stop-opacity=\"-0.xy\"/>"
+ "<stop offset=\"1\" style=\"stop-color:orange\" stop-opacity=\"z.5\"/>"
+ "</radialGradient>"
+ "<rect x=\"5\" y=\"5\" width=\"55\" height=\"55\" fill=\"url(#MyGradient1)\" stroke=\"black\" />"
+ "<rect x=\"20\" y=\"20\" width=\"35\" height=\"35\" fill=\"url(#MyGradient2)\"/>"
+ "</svg>"
+ };
+
+ QImage images[4];
+ QPainter p;
+
+ for (int i = 0; i < 4; ++i) {
+ QByteArray data(svgs[i]);
+ QSvgRenderer renderer(data);
+ QVERIFY(renderer.isValid());
+ images[i] = QImage(64, 64, QImage::Format_ARGB32_Premultiplied);
+ images[i].fill(-1);
+ p.begin(&images[i]);
+ renderer.render(&p);
+ p.end();
+ }
+ QCOMPARE(images[0], images[1]);
+ QCOMPARE(images[0], images[2]);
+ QCOMPARE(images[0], images[3]);
+}
+
QTEST_MAIN(tst_QSvgRenderer)
#include "tst_qsvgrenderer.moc"