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/types.h>
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
15 #include "../gfxtypes.hxx"
16 #include "../parserfragments.hxx"
20 class TestParser
: public CppUnit::TestFixture
33 const char* sIn
="#102030 ";
34 ARGBColor
aOut(16, 32, 48);
35 CPPUNIT_ASSERT_MESSAGE( "Consuming color #112233",
36 parseColor( sIn
, aTmp
) );
37 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp
.a
, aTmp
.r
, aTmp
.g
, aTmp
.b
);
38 CPPUNIT_ASSERT_MESSAGE( "Parsing color #112233",
42 aOut
=ARGBColor(51, 34, 17);
43 CPPUNIT_ASSERT_MESSAGE( "Consuming color #321",
44 parseColor( sIn
, aTmp
) );
45 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp
.a
, aTmp
.r
, aTmp
.g
, aTmp
.b
);
46 CPPUNIT_ASSERT_MESSAGE( "Parsing color #321",
49 sIn
="rgb(100,200,\t 50)";
50 aOut
=ARGBColor(100, 200, 50);
51 CPPUNIT_ASSERT_MESSAGE( "Consuming color rgb(100,200,50)",
52 parseColor( sIn
, aTmp
) );
53 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp
.a
, aTmp
.r
, aTmp
.g
, aTmp
.b
);
54 CPPUNIT_ASSERT_MESSAGE( "Parsing color rgb(100,200,50)",
57 sIn
="rgb(0.1, \t0.2,0.9)";
58 aOut
=ARGBColor(0.1, 0.2, 0.9);
59 CPPUNIT_ASSERT_MESSAGE( "Consuming color rgb(0.1,0.2,0.9)",
60 parseColor( sIn
, aTmp
) );
61 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp
.a
, aTmp
.r
, aTmp
.g
, aTmp
.b
);
62 CPPUNIT_ASSERT_MESSAGE( "Parsing color rgb(0.1,0.2,0.9)",
66 aOut
=ARGBColor(222,184,135);
67 CPPUNIT_ASSERT_MESSAGE( "Consuming color burlywood",
68 parseColor( sIn
, aTmp
) );
69 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp
.a
, aTmp
.r
, aTmp
.g
, aTmp
.b
);
70 CPPUNIT_ASSERT_MESSAGE( "Parsing color burlywood",
74 void testParseOpacity()
78 const char* sIn
=" 0.123 ";
79 ARGBColor
aOut(0.123, 0.0, 0.0, 0.0);
80 CPPUNIT_ASSERT_MESSAGE( "Consuming opacity 0.123",
81 parseOpacity( sIn
, aTmp
) );
82 OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp
.a
, aTmp
.r
, aTmp
.g
, aTmp
.b
);
83 CPPUNIT_ASSERT_MESSAGE( "Parsing opacity 0.123",
87 void testParseTransform()
89 basegfx::B2DHomMatrix aOut
;
91 const char* sIn
=" none ";
92 basegfx::B2DHomMatrix aTmp
;
93 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation none",
94 parseTransform( sIn
, aTmp
) );
95 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
96 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
97 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation none",
102 aOut
.scale(10.0,10.0);
103 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation scale(10)",
104 parseTransform( sIn
, aTmp
) );
105 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
106 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
107 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation scale(10)",
110 sIn
=" scale( 10 20.12 ) ";
112 aOut
.scale(10.0,20.12);
113 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation scale(10 20.12)",
114 parseTransform( sIn
, aTmp
) );
115 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
116 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
117 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation scale(10 20.12)",
120 sIn
="matrix( 1,2 3,4,5 6 )";
122 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);
123 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation matrix(1,2,3,4,5,6)",
124 parseTransform( sIn
, aTmp
) );
125 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
126 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
127 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation matrix(1,2,3,4,5,6)",
130 sIn
="matrix( 1 0 0 1 -10 -10 ) translate(10) scale(10), rotate(90)";
132 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);
133 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation matrix(1,2,3,4,5,6)",
134 parseTransform( sIn
, aTmp
) );
135 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
136 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
137 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation matrix(1,2,3,4,5,6)",
142 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);
143 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation skewX(45)",
144 parseTransform( sIn
, aTmp
) );
145 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
146 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
147 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation skewX(45)",
152 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);
153 CPPUNIT_ASSERT_MESSAGE( "Consuming transformation skewY(45)",
154 parseTransform( sIn
, aTmp
) );
155 OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
156 aTmp
.get(0,0), aTmp
.get(0,1), aTmp
.get(0,2), aTmp
.get(1,0), aTmp
.get(1,1), aTmp
.get(1,2) );
157 CPPUNIT_ASSERT_MESSAGE( "Parsing transformation skewY(45)",
161 void testParseViewBox()
163 basegfx::B2DRange aTmp
;
165 const char* sIn
=" 10 20, 30.5,5 ";
166 basegfx::B2DRange
aOut(10,20,40.5,25);
167 CPPUNIT_ASSERT_MESSAGE( "Consuming 10,20,30.5,5",
168 parseViewBox( sIn
, aTmp
) );
169 OSL_TRACE("viewbox is: x1:%f y1:%f x2:%f y2:%f", aTmp
.getMinX(), aTmp
.getMinY(), aTmp
.getMaxX(), aTmp
.getMaxY());
170 CPPUNIT_ASSERT_MESSAGE( "Parsing 10,20,30.5,5",
174 void testParseDashArray()
176 std::vector
<double> aTmp
;
178 const char* sIn
=" 10,20, -10.00 ";
179 std::vector
<double> aOut
; aOut
.push_back(10.0); aOut
.push_back(20.0); aOut
.push_back(-10.0);
180 CPPUNIT_ASSERT_MESSAGE( "Consuming 10,20,-10.00",
181 parseDashArray( sIn
, aTmp
) );
182 OSL_TRACE("dash array is: len %d, %f %f %f", aTmp
.size(), aTmp
[0], aTmp
[1], aTmp
[2] );
183 CPPUNIT_ASSERT_MESSAGE( "Parsing 10,20,-10.00",
187 CPPUNIT_TEST_SUITE(TestParser
);
188 CPPUNIT_TEST(testParseColor
);
189 CPPUNIT_TEST(testParseOpacity
);
190 CPPUNIT_TEST(testParseTransform
);
191 CPPUNIT_TEST(testParseViewBox
);
192 CPPUNIT_TEST(testParseDashArray
);
193 // TODO: CPPUNIT_TEST(testParseXlinkHref);
194 CPPUNIT_TEST_SUITE_END();
197 // -----------------------------------------------------------------------------
199 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestParser
, "test svg parser fragments");
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */