Update ooo320-m1
[ooovba.git] / filter / source / svg / test / parsertest.cxx
blobc8db1012aa5c67eaa481419aa75d20bf37d5bc58
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * Author:
6 * Fridrich Strba <fridrich.strba@bluewin.ch>
7 * Thorsten Behrens <tbehrens@novell.com>
9 * Copyright (C) 2008, Novell Inc.
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
14 ************************************************************************/
16 // MARKER(update_precomp.py): autogen include statement, do not remove
17 #include "precompiled_filter.hxx"
19 #include <cppunit/simpleheader.hxx>
21 #include "../gfxtypes.hxx"
22 #include "../parserfragments.hxx"
24 using namespace svgi;
26 class TestParser : public CppUnit::TestFixture
28 public:
29 void setUp()
32 void tearDown()
35 void testParseColor()
37 ARGBColor aTmp;
39 const char* sIn="#102030 ";
40 ARGBColor aOut(16, 32, 48);
41 CPPUNIT_ASSERT_MESSAGE( "Consuming color #112233",
42 parseColor( sIn, aTmp ) );
43 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
44 CPPUNIT_ASSERT_MESSAGE( "Parsing color #112233",
45 aOut==aTmp );
47 sIn=" #321";
48 aOut=ARGBColor(51, 34, 17);
49 CPPUNIT_ASSERT_MESSAGE( "Consuming color #321",
50 parseColor( sIn, aTmp ) );
51 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
52 CPPUNIT_ASSERT_MESSAGE( "Parsing color #321",
53 aOut==aTmp );
55 sIn="rgb(100,200,\t 50)";
56 aOut=ARGBColor(100, 200, 50);
57 CPPUNIT_ASSERT_MESSAGE( "Consuming color rgb(100,200,50)",
58 parseColor( sIn, aTmp ) );
59 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
60 CPPUNIT_ASSERT_MESSAGE( "Parsing color rgb(100,200,50)",
61 aOut==aTmp );
63 sIn="rgb(0.1, \t0.2,0.9)";
64 aOut=ARGBColor(0.1, 0.2, 0.9);
65 CPPUNIT_ASSERT_MESSAGE( "Consuming color rgb(0.1,0.2,0.9)",
66 parseColor( sIn, aTmp ) );
67 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
68 CPPUNIT_ASSERT_MESSAGE( "Parsing color rgb(0.1,0.2,0.9)",
69 aOut==aTmp );
71 sIn=" burlywood ";
72 aOut=ARGBColor(222,184,135);
73 CPPUNIT_ASSERT_MESSAGE( "Consuming color burlywood",
74 parseColor( sIn, aTmp ) );
75 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
76 CPPUNIT_ASSERT_MESSAGE( "Parsing color burlywood",
77 aOut==aTmp );
80 void testParseOpacity()
82 ARGBColor aTmp;
84 const char* sIn=" 0.123 ";
85 ARGBColor aOut(0.123, 0.0, 0.0, 0.0);
86 CPPUNIT_ASSERT_MESSAGE( "Consuming opacity 0.123",
87 parseOpacity( sIn, aTmp ) );
88 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
89 CPPUNIT_ASSERT_MESSAGE( "Parsing opacity 0.123",
90 aOut==aTmp );
93 void testParseTransform()
95 basegfx::B2DHomMatrix aOut;
97 const char* sIn=" none ";
98 basegfx::B2DHomMatrix aTmp;
99 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation none",
100 parseTransform( sIn, aTmp ) );
101 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
102 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
103 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation none",
104 aOut==aTmp );
106 sIn=" scale( 10 ) ";
107 aOut.identity();
108 aOut.scale(10.0,10.0);
109 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation scale(10)",
110 parseTransform( sIn, aTmp ) );
111 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
112 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
113 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation scale(10)",
114 aOut==aTmp );
116 sIn=" scale( 10 20.12 ) ";
117 aOut.identity();
118 aOut.scale(10.0,20.12);
119 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation scale(10 20.12)",
120 parseTransform( sIn, aTmp ) );
121 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
122 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
123 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation scale(10 20.12)",
124 aOut==aTmp );
126 sIn="matrix( 1,2 3,4,5 6 )";
127 aOut.identity();
128 aOut.set(0,0,1.0); aOut.set(1,0,2.0); aOut.set(0,1,3.0); aOut.set(1,1,4.0); aOut.set(0,2,5.0); aOut.set(1,2,6.0);
129 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation matrix(1,2,3,4,5,6)",
130 parseTransform( sIn, aTmp ) );
131 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
132 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
133 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation matrix(1,2,3,4,5,6)",
134 aOut==aTmp );
136 sIn="matrix( 1 0 0 1 -10 -10 ) translate(10) scale(10), rotate(90)";
137 aOut.identity();
138 aOut.set(0,0,0.0); aOut.set(1,0,10.0); aOut.set(0,1,-10.0); aOut.set(1,1,0.0); aOut.set(0,2,0.0); aOut.set(1,2,0.0);
139 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation matrix(1,2,3,4,5,6)",
140 parseTransform( sIn, aTmp ) );
141 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
142 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
143 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation matrix(1,2,3,4,5,6)",
144 aOut==aTmp );
146 sIn="skewX(45)";
147 aOut.identity();
148 aOut.set(0,0,1.0); aOut.set(1,0,1.0); aOut.set(0,1,0.0); aOut.set(1,1,1.0); aOut.set(0,2,0.0); aOut.set(1,2,0.0);
149 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation skewX(45)",
150 parseTransform( sIn, aTmp ) );
151 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
152 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
153 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation skewX(45)",
154 aOut==aTmp );
156 sIn="skewY(45)";
157 aOut.identity();
158 aOut.set(0,0,1.0); aOut.set(1,0,0.0); aOut.set(0,1,1.0); aOut.set(1,1,1.0); aOut.set(0,2,0.0); aOut.set(1,2,0.0);
159 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation skewY(45)",
160 parseTransform( sIn, aTmp ) );
161 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
162 aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
163 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation skewY(45)",
164 aOut==aTmp );
167 void testParseViewBox()
169 basegfx::B2DRange aTmp;
171 const char* sIn=" 10 20, 30.5,5 ";
172 basegfx::B2DRange aOut(10,20,40.5,25);
173 CPPUNIT_ASSERT_MESSAGE( "Consuming 10,20,30.5,5",
174 parseViewBox( sIn, aTmp ) );
175 OSL_TRACE("viewbox is: x1:%f y1:%f x2:%f y2:%f", aTmp.getMinX(), aTmp.getMinY(), aTmp.getMaxX(), aTmp.getMaxY());
176 CPPUNIT_ASSERT_MESSAGE( "Parsing 10,20,30.5,5",
177 aOut==aTmp );
180 void testParseDashArray()
182 std::vector<double> aTmp;
184 const char* sIn=" 10,20, -10.00 ";
185 std::vector<double> aOut; aOut.push_back(10.0); aOut.push_back(20.0); aOut.push_back(-10.0);
186 CPPUNIT_ASSERT_MESSAGE( "Consuming 10,20,-10.00",
187 parseDashArray( sIn, aTmp ) );
188 OSL_TRACE("dash array is: len %d, %f %f %f", aTmp.size(), aTmp[0], aTmp[1], aTmp[2] );
189 CPPUNIT_ASSERT_MESSAGE( "Parsing 10,20,-10.00",
190 aOut==aTmp );
193 CPPUNIT_TEST_SUITE(TestParser);
194 CPPUNIT_TEST(testParseColor);
195 CPPUNIT_TEST(testParseOpacity);
196 CPPUNIT_TEST(testParseTransform);
197 CPPUNIT_TEST(testParseViewBox);
198 CPPUNIT_TEST(testParseDashArray);
199 // TODO: CPPUNIT_TEST(testParseXlinkHref);
200 CPPUNIT_TEST_SUITE_END();
203 // -----------------------------------------------------------------------------
205 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestParser, "test svg parser fragments");
207 // this macro creates an empty function, which will called by the RegisterAllFunctions()
208 // to let the user the possibility to also register some functions by hand.
209 NOADDITIONAL;