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 3 : 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 2 : CPPUNIT_TEST_SUITE(Test);
48 1 : CPPUNIT_TEST(testStyles);
49 5 : CPPUNIT_TEST_SUITE_END();
50 : };
51 :
52 4 : Primitive2DSequence Test::parseSvg(const char* aSource)
53 : {
54 4 : const Reference<XSvgParser> xSvgParser = SvgTools::create(m_xContext);
55 :
56 8 : OUString aUrl = getURLFromSrc(aSource);
57 8 : OUString aPath = getPathFromSrc(aSource);
58 :
59 8 : SvFileStream aFileStream(aUrl, StreamMode::READ);
60 4 : sal_Size nSize = aFileStream.remainingSize();
61 8 : boost::scoped_array<sal_Int8> pBuffer(new sal_Int8[nSize + 1]);
62 4 : aFileStream.Read(pBuffer.get(), nSize);
63 4 : pBuffer[nSize] = 0;
64 :
65 8 : Sequence<sal_Int8> aData(pBuffer.get(), nSize + 1);
66 8 : Reference<XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
67 :
68 8 : return xSvgParser->getDecomposition(aInputStream, aPath);
69 : }
70 :
71 1 : void Test::setUp()
72 : {
73 1 : BootstrapFixture::setUp();
74 1 : }
75 :
76 1 : void Test::tearDown()
77 : {
78 1 : BootstrapFixture::tearDown();
79 1 : }
80 :
81 4 : void Test::checkRectPrimitive(Primitive2DSequence& rPrimitive)
82 : {
83 4 : Primitive2dXmlDump dumper;
84 4 : xmlDocPtr pDocument = dumper.dumpAndParse(rPrimitive);
85 :
86 4 : CPPUNIT_ASSERT (pDocument);
87 :
88 4 : assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00"); // rect background color
89 4 : assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#ff0000"); // rect stroke color
90 4 : assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "3"); // rect stroke width
91 :
92 4 : }
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 1 : void Test::testStyles()
98 : {
99 1 : Primitive2DSequence aSequenceRect = parseSvg("/svgio/qa/cppunit/data/Rect.svg");
100 1 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRect.getLength());
101 1 : checkRectPrimitive(aSequenceRect);
102 :
103 2 : Primitive2DSequence aSequenceRectWithStyle = parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
104 1 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStyle.getLength());
105 1 : checkRectPrimitive(aSequenceRectWithStyle);
106 :
107 2 : Primitive2DSequence aSequenceRectWithParentStyle = parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
108 1 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithParentStyle.getLength());
109 1 : checkRectPrimitive(aSequenceRectWithParentStyle);
110 :
111 2 : Primitive2DSequence aSequenceRectWithStylesByGroup = parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
112 1 : CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStylesByGroup.getLength());
113 1 : checkRectPrimitive(aSequenceRectWithStylesByGroup);
114 :
115 1 : CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStyle));
116 1 : CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithParentStyle));
117 2 : CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStylesByGroup));
118 :
119 1 : }
120 :
121 :
122 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
123 :
124 : }
125 :
126 4 : CPPUNIT_PLUGIN_IMPLEMENT();
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|