summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorofftkp <parisoplop@gmail.com>2022-06-20 15:23:14 +0300
committerTomaž Vajngerl <quikee@gmail.com>2022-06-22 14:14:50 +0200
commiteedc5b1c576fcaaea85a5278762efc8ba8c5a084 (patch)
treea7981e6df316acc64666cd2314d3a4987874e967 /svgio
parent99f8e8aa0ccb741c2b5ede6cab75798c1793d899 (diff)
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 <quikee@gmail.com>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx22
-rw-r--r--svgio/qa/cppunit/data/CssClassRedefinition.svg13
2 files changed, 35 insertions, 0 deletions
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>