1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/types.h>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "../gfxtypes.hxx"
#include "../parserfragments.hxx"
using namespace svgi;
class TestParser : public CppUnit::TestFixture
{
public:
void setUp()
{}
void tearDown()
{}
void testParseColor()
{
ARGBColor aTmp;
const char* sIn="#102030 ";
ARGBColor aOut(16, 32, 48);
CPPUNIT_ASSERT_MESSAGE( "Consuming color #112233",
parseColor( sIn, aTmp ) );
OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
CPPUNIT_ASSERT_MESSAGE( "Parsing color #112233",
aOut==aTmp );
sIn=" #321";
aOut=ARGBColor(51, 34, 17);
CPPUNIT_ASSERT_MESSAGE( "Consuming color #321",
parseColor( sIn, aTmp ) );
OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
CPPUNIT_ASSERT_MESSAGE( "Parsing color #321",
aOut==aTmp );
sIn="rgb(100,200,\t 50)";
aOut=ARGBColor(100, 200, 50);
CPPUNIT_ASSERT_MESSAGE( "Consuming color rgb(100,200,50)",
parseColor( sIn, aTmp ) );
OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
CPPUNIT_ASSERT_MESSAGE( "Parsing color rgb(100,200,50)",
aOut==aTmp );
sIn="rgb(0.1, \t0.2,0.9)";
aOut=ARGBColor(0.1, 0.2, 0.9);
CPPUNIT_ASSERT_MESSAGE( "Consuming color rgb(0.1,0.2,0.9)",
parseColor( sIn, aTmp ) );
OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
CPPUNIT_ASSERT_MESSAGE( "Parsing color rgb(0.1,0.2,0.9)",
aOut==aTmp );
sIn=" burlywood ";
aOut=ARGBColor(222,184,135);
CPPUNIT_ASSERT_MESSAGE( "Consuming color burlywood",
parseColor( sIn, aTmp ) );
OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
CPPUNIT_ASSERT_MESSAGE( "Parsing color burlywood",
aOut==aTmp );
}
void testParseOpacity()
{
ARGBColor aTmp;
const char* sIn=" 0.123 ";
ARGBColor aOut(0.123, 0.0, 0.0, 0.0);
CPPUNIT_ASSERT_MESSAGE( "Consuming opacity 0.123",
parseOpacity( sIn, aTmp ) );
OSL_TRACE("color is: a:%f r:%f g:%f b:%f", aTmp.a, aTmp.r, aTmp.g, aTmp.b);
CPPUNIT_ASSERT_MESSAGE( "Parsing opacity 0.123",
aOut==aTmp );
}
void testParseTransform()
{
basegfx::B2DHomMatrix aOut;
const char* sIn=" none ";
basegfx::B2DHomMatrix aTmp;
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation none",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation none",
aOut==aTmp );
sIn=" scale( 10 ) ";
aOut.identity();
aOut.scale(10.0,10.0);
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation scale(10)",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation scale(10)",
aOut==aTmp );
sIn=" scale( 10 20.12 ) ";
aOut.identity();
aOut.scale(10.0,20.12);
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation scale(10 20.12)",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation scale(10 20.12)",
aOut==aTmp );
sIn="matrix( 1,2 3,4,5 6 )";
aOut.identity();
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);
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation matrix(1,2,3,4,5,6)",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation matrix(1,2,3,4,5,6)",
aOut==aTmp );
sIn="matrix( 1 0 0 1 -10 -10 ) translate(10) scale(10), rotate(90)";
aOut.identity();
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);
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation matrix(1,2,3,4,5,6)",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation matrix(1,2,3,4,5,6)",
aOut==aTmp );
sIn="skewX(45)";
aOut.identity();
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);
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation skewX(45)",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation skewX(45)",
aOut==aTmp );
sIn="skewY(45)";
aOut.identity();
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);
CPPUNIT_ASSERT_MESSAGE( "Consuming transformation skewY(45)",
parseTransform( sIn, aTmp ) );
OSL_TRACE("transformation is: m00:%f m01:%f m02:%f m10:%f m11:%f m12:%f",
aTmp.get(0,0), aTmp.get(0,1), aTmp.get(0,2), aTmp.get(1,0), aTmp.get(1,1), aTmp.get(1,2) );
CPPUNIT_ASSERT_MESSAGE( "Parsing transformation skewY(45)",
aOut==aTmp );
}
void testParseViewBox()
{
basegfx::B2DRange aTmp;
const char* sIn=" 10 20, 30.5,5 ";
basegfx::B2DRange aOut(10,20,40.5,25);
CPPUNIT_ASSERT_MESSAGE( "Consuming 10,20,30.5,5",
parseViewBox( sIn, aTmp ) );
OSL_TRACE("viewbox is: x1:%f y1:%f x2:%f y2:%f", aTmp.getMinX(), aTmp.getMinY(), aTmp.getMaxX(), aTmp.getMaxY());
CPPUNIT_ASSERT_MESSAGE( "Parsing 10,20,30.5,5",
aOut==aTmp );
}
void testParseDashArray()
{
std::vector<double> aTmp;
const char* sIn=" 10,20, -10.00 ";
std::vector<double> aOut; aOut.push_back(10.0); aOut.push_back(20.0); aOut.push_back(-10.0);
CPPUNIT_ASSERT_MESSAGE( "Consuming 10,20,-10.00",
parseDashArray( sIn, aTmp ) );
OSL_TRACE("dash array is: len %d, %f %f %f", aTmp.size(), aTmp[0], aTmp[1], aTmp[2] );
CPPUNIT_ASSERT_MESSAGE( "Parsing 10,20,-10.00",
aOut==aTmp );
}
CPPUNIT_TEST_SUITE(TestParser);
CPPUNIT_TEST(testParseColor);
CPPUNIT_TEST(testParseOpacity);
CPPUNIT_TEST(testParseTransform);
CPPUNIT_TEST(testParseViewBox);
CPPUNIT_TEST(testParseDashArray);
// TODO: CPPUNIT_TEST(testParseXlinkHref);
CPPUNIT_TEST_SUITE_END();
};
// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestParser, "test svg parser fragments");
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|