1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <test/bootstrapfixture.hxx>
13 #include <test/primitive2dxmldump.hxx>
14 #include <test/xmltesttools.hxx>
16 #include <comphelper/processfactory.hxx>
17 #include <comphelper/seqstream.hxx>
19 #include <com/sun/star/graphic/SvgTools.hpp>
20 #include <com/sun/star/graphic/Primitive2DTools.hpp>
21 #include <com/sun/star/graphic/XPrimitive2D.hpp>
23 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
25 #include <boost/scoped_array.hpp>
30 using namespace css::uno
;
31 using namespace css::io
;
32 using namespace css::graphic
;
33 using drawinglayer::primitive2d::arePrimitive2DSequencesEqual
;
35 class Test
: public test::BootstrapFixture
, public XmlTestTools
37 void checkRectPrimitive(Primitive2DSequence
& rPrimitive
);
41 Primitive2DSequence
parseSvg(const char* aSource
);
44 virtual void setUp() SAL_OVERRIDE
;
45 virtual void tearDown() SAL_OVERRIDE
;
47 CPPUNIT_TEST_SUITE(Test
);
48 CPPUNIT_TEST(testStyles
);
49 CPPUNIT_TEST_SUITE_END();
52 Primitive2DSequence
Test::parseSvg(const char* aSource
)
54 const Reference
<XSvgParser
> xSvgParser
= SvgTools::create(m_xContext
);
56 OUString aUrl
= getURLFromSrc(aSource
);
57 OUString aPath
= getPathFromSrc(aSource
);
59 SvFileStream
aFileStream(aUrl
, StreamMode::READ
);
60 sal_Size nSize
= aFileStream
.remainingSize();
61 boost::scoped_array
<sal_Int8
> pBuffer(new sal_Int8
[nSize
+ 1]);
62 aFileStream
.Read(pBuffer
.get(), nSize
);
65 Sequence
<sal_Int8
> aData(pBuffer
.get(), nSize
+ 1);
66 Reference
<XInputStream
> aInputStream(new comphelper::SequenceInputStream(aData
));
68 return xSvgParser
->getDecomposition(aInputStream
, aPath
);
73 BootstrapFixture::setUp();
78 BootstrapFixture::tearDown();
81 void Test::checkRectPrimitive(Primitive2DSequence
& rPrimitive
)
83 Primitive2dXmlDump dumper
;
84 xmlDocPtr pDocument
= dumper
.dumpAndParse(rPrimitive
);
86 CPPUNIT_ASSERT (pDocument
);
88 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00"); // rect background color
89 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "color", "#ff0000"); // rect stroke color
90 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "width", "3"); // rect stroke width
94 // Attributes for an object (like rect as in this case) can be defined
95 // in different ways (directly with xml attributes, or with CSS styles),
96 // however the end result should be the same.
97 void Test::testStyles()
99 Primitive2DSequence aSequenceRect
= parseSvg("/svgio/qa/cppunit/data/Rect.svg");
100 CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRect
.getLength());
101 checkRectPrimitive(aSequenceRect
);
103 Primitive2DSequence aSequenceRectWithStyle
= parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
104 CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStyle
.getLength());
105 checkRectPrimitive(aSequenceRectWithStyle
);
107 Primitive2DSequence aSequenceRectWithParentStyle
= parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
108 CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithParentStyle
.getLength());
109 checkRectPrimitive(aSequenceRectWithParentStyle
);
111 Primitive2DSequence aSequenceRectWithStylesByGroup
= parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
112 CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStylesByGroup
.getLength());
113 checkRectPrimitive(aSequenceRectWithStylesByGroup
);
115 CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect
, aSequenceRectWithStyle
));
116 CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect
, aSequenceRectWithParentStyle
));
117 CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect
, aSequenceRectWithStylesByGroup
));
122 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
126 CPPUNIT_PLUGIN_IMPLEMENT();
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */