svgio/qa/cppunit/SvgImportTest.cxx | 22 ++++++++++++++++++++++ svgio/qa/cppunit/data/CssClassRedefinition.svg | 13 +++++++++++++ 2 files changed, 35 insertions(+)
New commits: commit d931e8876cbaf8e409ebbba97d991d0099124de4 Author: offtkp <parisop...@gmail.com> AuthorDate: Mon Jun 20 15:23:14 2022 +0300 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Thu Jun 23 23:08:24 2022 +0200 tdf#149449 Add unit test for CSS class redefinition inside SVGs Tests what happens when a CSS class is redefined with new attributes and with already defined attributes Change-Id: I5996fa4dce6c98c1792001a11387bf570d159a8f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136151 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit eedc5b1c576fcaaea85a5278762efc8ba8c5a084) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136315 Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 4f9ee58f68db..650dbdde67f6 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -70,6 +70,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testTdf94765(); void testBehaviourWhenWidthAndHeightIsOrIsNotSet(); void testTdf97663(); + void testCssClassRedefinition(); Primitive2DSequence parseSvg(std::u16string_view aSource); @@ -106,6 +107,7 @@ public: CPPUNIT_TEST(testTdf94765); CPPUNIT_TEST(testBehaviourWhenWidthAndHeightIsOrIsNotSet); CPPUNIT_TEST(testTdf97663); + CPPUNIT_TEST(testCssClassRedefinition); CPPUNIT_TEST_SUITE_END(); }; @@ -833,6 +835,26 @@ void Test::testTdf97663() assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "y", "236"); } +void Test::testCssClassRedefinition() +{ + // Tests for svg css class redefinition behavior + // Example: + // .c1 {fill:#00ff00} + // .c1 {font-family:Sans} + // .c1 {fill:#ff0000} + // Expected result is .c1 {font-family:Sans; fill:#ff0000} because + // the second redefinition appends attributes to the class and the + // third redefinition replaces the already existing + // attribute in the original definition + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/CssClassRedefinition.svg"); + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + CPPUNIT_ASSERT (pDocument); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "text", "test"); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#ff0000"); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Sans"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/svgio/qa/cppunit/data/CssClassRedefinition.svg b/svgio/qa/cppunit/data/CssClassRedefinition.svg new file mode 100644 index 000000000000..87eb2023384b --- /dev/null +++ b/svgio/qa/cppunit/data/CssClassRedefinition.svg @@ -0,0 +1,13 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="50 px" height="100 px"> + <style type="text/css"> + .c1 {fill:#00ff00} + <!-- this redefinition should be appended --> + .c1 {font-family:Sans} + <!-- this redefinition should change the color to red, replacing the first definition --> + .c1 {fill:#ff0000} + <!-- finally c1 should be equal to fill:#ff0000 and font-family:Sans --> + </style> + <text x="20" y="20" > + <tspan class="c1">test</tspan> + </text> +</svg>