Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include <sal/config.h>
11 :
12 : #include <test/bootstrapfixture.hxx>
13 : #include <test/primitive2dxmldump.hxx>
14 : #include <test/xmltesttools.hxx>
15 :
16 : #include <comphelper/processfactory.hxx>
17 : #include <comphelper/seqstream.hxx>
18 :
19 : #include <com/sun/star/graphic/SvgTools.hpp>
20 : #include <com/sun/star/graphic/Primitive2DTools.hpp>
21 : #include <com/sun/star/graphic/XPrimitive2D.hpp>
22 :
23 : #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
24 :
25 : #include <boost/scoped_array.hpp>
26 :
27 : namespace
28 : {
29 :
30 : using namespace css::uno;
31 : using namespace css::io;
32 : using namespace css::graphic;
33 : using drawinglayer::primitive2d::arePrimitive2DSequencesEqual;
34 :
35 6 : class Test : public test::BootstrapFixture, public XmlTestTools
36 : {
37 : void checkRectPrimitive(Primitive2DSequence& rPrimitive);
38 :
39 : void testStyles();
40 :
41 : Primitive2DSequence parseSvg(const char* aSource);
42 :
43 : public:
44 : virtual void setUp() SAL_OVERRIDE;
45 : virtual void tearDown() SAL_OVERRIDE;
46 :
47 4 : CPPUNIT_TEST_SUITE(Test);
48 2 : CPPUNIT_TEST(testStyles);
49 4 : CPPUNIT_TEST_SUITE_END();
50 : };
51 :
52 8 : Primitive2DSequence Test::parseSvg(const char* aSource)
53 : {
54 8 : const Reference<XSvgParser> xSvgParser = SvgTools::create(m_xContext);
55 :
56 16 : OUString aUrl = getURLFromSrc(aSource);
57 16 : OUString aPath = getPathFromSrc(aSource);
58 :
59 16 : SvFileStream aFileStream(aUrl, STREAM_READ);
60 8 : sal_Size nSize = aFileStream.remainingSize();
61 16 : boost::scoped_array<sal_Int8> pBuffer(new sal_Int8[nSize + 1]);
62 8 : aFileStream.Read(pBuffer.get(), nSize);
63 8 : pBuffer[nSize] = 0;
64 :
65 16 : Sequence<sal_Int8> aData(pBuffer.get(), nSize + 1);
66 16 : Reference<XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
67 :
68 16 : return xSvgParser->getDecomposition(aInputStream, aPath);
69 : }
70 :
71 2 : void Test::setUp()
72 : {
73 2 : BootstrapFixture::setUp();
74 2 : }
75 :
76 2 : void Test::tearDown()
77 : {
78 2 : BootstrapFixture::tearDown();
79 2 : }
80 :
81 8 : void Test::checkRectPrimitive(Primitive2DSequence& rPrimitive)
82 : {
83 8 : Primitive2dXmlDump dumper;
84 8 : xmlDocPtr pDocument = dumper.dumpAndParse(rPrimitive);
85 :
86 8 : CPPUNIT_ASSERT (pDocument);
87 :
88 8 : assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00"); // rect background color
89 8 : assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#ff0000"); // rect stroke color
90 8 : assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "3"); // rect stroke width
91 :
92 8 : }
93 :
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 2 : void Test::testStyles()
98 : {
99 2 : Primitive2DSequence aSequenceRect = parseSvg("/svgio/qa/cppunit/data/Rect.svg");
100 2 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRect.getLength());
101 2 : checkRectPrimitive(aSequenceRect);
102 :
103 4 : Primitive2DSequence aSequenceRectWithStyle = parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
104 2 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStyle.getLength());
105 2 : checkRectPrimitive(aSequenceRectWithStyle);
106 :
107 4 : Primitive2DSequence aSequenceRectWithParentStyle = parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
108 2 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithParentStyle.getLength());
109 2 : checkRectPrimitive(aSequenceRectWithParentStyle);
110 :
111 4 : Primitive2DSequence aSequenceRectWithStylesByGroup = parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
112 2 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStylesByGroup.getLength());
113 2 : checkRectPrimitive(aSequenceRectWithStylesByGroup);
114 :
115 2 : CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStyle));
116 2 : CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithParentStyle));
117 4 : CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStylesByGroup));
118 :
119 2 : }
120 :
121 :
122 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
123 :
124 : }
125 :
126 8 : CPPUNIT_PLUGIN_IMPLEMENT();
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|