~ubuntu-branches/debian/sid/latexdraw/sid

« back to all changes in this revision

Viewing changes to junit/test/parser/svg/parsers/TestSVGLengthParser.java

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2009-07-15 23:35:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090715233552-2bblktyf2lmrkyo3
Tags: 2.0.3+1-1
* New upstream release.
* Add additional Recommended packages for new export features.
* Fix typo in long description, with thanks to Kai Weber (Closes: #529195).
* Bump standards to 3.8.2 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package junit.test.parser.svg.parsers;
 
2
 
 
3
import java.text.ParseException;
 
4
 
 
5
import junit.framework.TestCase;
 
6
import latexDraw.parsers.svg.SVGLength;
 
7
import latexDraw.parsers.svg.parsers.SVGLengthParser;
 
8
import latexDraw.parsers.svg.parsers.UnitProcessor;
 
9
 
 
10
import org.junit.Test;
 
11
 
 
12
/** 
 
13
 * Tests the class SVGLengthParser.<br>
 
14
 *<br>
 
15
 * This file is part of LaTeXDraw<br>
 
16
 * Copyright (c) 2005-2008 Arnaud BLOUIN<br>
 
17
 *<br>
 
18
 *  LaTeXDraw is free software; you can redistribute it and/or modify
 
19
 *  it under the terms of the GNU General Public License as published by
 
20
 *  the Free Software Foundation; either version 2 of the License, or
 
21
 *  any later version.<br>
 
22
 *<br>
 
23
 *  LaTeXDraw is distributed without any warranty; without even the 
 
24
 *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
25
 *  PURPOSE.  See the GNU General Public License for more details.<br>
 
26
 *<br>
 
27
 * 10/24/07<br>
 
28
 * @author Arnaud BLOUIN<br>
 
29
 * @version 0.1<br>
 
30
 * @since 0.1<br>
 
31
 */
 
32
@SuppressWarnings("nls")
 
33
public class TestSVGLengthParser extends TestCase
 
34
{
 
35
        @Test
 
36
        public void testParseLength()
 
37
        {
 
38
                SVGLengthParser p;
 
39
                SVGLength l;
 
40
                
 
41
                try
 
42
                {
 
43
                        new SVGLengthParser(null);
 
44
                        fail();
 
45
                }
 
46
                catch(IllegalArgumentException e){ /* */ }
 
47
                
 
48
                try
 
49
                {
 
50
                        p = new SVGLengthParser("");
 
51
                        l = p.parseLength();
 
52
                        fail();
 
53
                }
 
54
                catch(ParseException e){ /* */ }
 
55
                
 
56
                try
 
57
                {
 
58
                        p = new SVGLengthParser("1m");
 
59
                        l = p.parseLength();
 
60
                        fail();
 
61
                }
 
62
                catch(ParseException e){ /* */ }
 
63
                
 
64
                try
 
65
                {
 
66
                        p = new SVGLengthParser("m");
 
67
                        l = p.parseLength();
 
68
                        fail();
 
69
                }
 
70
                catch(ParseException e){ /* */ }
 
71
                
 
72
                try
 
73
                {
 
74
                        p = new SVGLengthParser("1p");
 
75
                        l = p.parseLength();
 
76
                        fail();
 
77
                }
 
78
                catch(ParseException e){ /* */ }
 
79
                
 
80
                try
 
81
                {
 
82
                        p = new SVGLengthParser("1e1i");
 
83
                        l = p.parseLength();
 
84
                        fail();
 
85
                }
 
86
                catch(ParseException e){ /* */ }
 
87
                
 
88
                try
 
89
                {
 
90
                        p = new SVGLengthParser("1ci");
 
91
                        l = p.parseLength();
 
92
                        fail();
 
93
                }
 
94
                catch(ParseException e){ /* */ }
 
95
                
 
96
                try
 
97
                {
 
98
                        p = new SVGLengthParser("1 c ");
 
99
                        l = p.parseLength();
 
100
                        fail();
 
101
                }
 
102
                catch(ParseException e){ /* */ }
 
103
                
 
104
                try
 
105
                {
 
106
                        p = new SVGLengthParser("1mm");
 
107
                        l = p.parseLength();
 
108
                        
 
109
                        assertEquals(l.getValueAsString(), "1");
 
110
                        assertEquals(l.getLengthType(), SVGLength.LengthType.MM);
 
111
                        assertEquals(UnitProcessor.toUserUnit(1, SVGLength.LengthType.MM), l.getValue());
 
112
                }
 
113
                catch(ParseException e){ fail(); }
 
114
                
 
115
                try
 
116
                {
 
117
                        p = new SVGLengthParser("0.65 cm");
 
118
                        l = p.parseLength();
 
119
                        
 
120
                        assertEquals(l.getValueAsString(), "0.65");
 
121
                        assertEquals(l.getLengthType(), SVGLength.LengthType.CM);
 
122
                        assertEquals(UnitProcessor.toUserUnit(0.65, SVGLength.LengthType.CM), l.getValue());
 
123
                }
 
124
                catch(ParseException e){ fail(); }
 
125
                
 
126
                try
 
127
                {
 
128
                        p = new SVGLengthParser("\t -10.65  \t \n pc");
 
129
                        l = p.parseLength();
 
130
                        
 
131
                        assertEquals(l.getValueAsString(), "-10.65");
 
132
                        assertEquals(l.getLengthType(), SVGLength.LengthType.PC);
 
133
                        assertEquals(UnitProcessor.toUserUnit(-10.65, SVGLength.LengthType.PC), l.getValue());
 
134
                }
 
135
                catch(ParseException e){ fail(); }
 
136
                
 
137
                try
 
138
                {
 
139
                        p = new SVGLengthParser("\t -10.65e2  \t \n px \t   ");
 
140
                        l = p.parseLength();
 
141
                        
 
142
                        assertEquals(l.getValueAsString(), "-10.65e2");
 
143
                        assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
 
144
                        assertEquals(UnitProcessor.toUserUnit(-10.65e2, SVGLength.LengthType.PX), l.getValue());
 
145
                }
 
146
                catch(ParseException e){ fail(); }
 
147
                
 
148
                try
 
149
                {
 
150
                        p = new SVGLengthParser("\t -10.65e0pt \t   ");
 
151
                        l = p.parseLength();
 
152
                        
 
153
                        assertEquals(l.getValueAsString(), "-10.65e0");
 
154
                        assertEquals(l.getLengthType(), SVGLength.LengthType.PT);
 
155
                        assertEquals(UnitProcessor.toUserUnit(-10.65e0, SVGLength.LengthType.PT), l.getValue());
 
156
                }
 
157
                catch(ParseException e){ fail(); }
 
158
                
 
159
                try
 
160
                {
 
161
                        p = new SVGLengthParser("\t -1.in \t   ");
 
162
                        l = p.parseLength();
 
163
                        
 
164
                        assertEquals(l.getValueAsString(), "-1.");
 
165
                        assertEquals(l.getLengthType(), SVGLength.LengthType.IN);
 
166
                        assertEquals(UnitProcessor.toUserUnit(-1., SVGLength.LengthType.IN), l.getValue());
 
167
                }
 
168
                catch(ParseException e){ fail(); }
 
169
                
 
170
                try
 
171
                {
 
172
                        p = new SVGLengthParser("-1.");
 
173
                        l = p.parseLength();
 
174
                        
 
175
                        assertEquals(l.getValueAsString(), "-1.");
 
176
                        assertEquals(l.getLengthType(), SVGLength.LengthType.NUMBER);
 
177
                        assertEquals(UnitProcessor.toUserUnit(-1., SVGLength.LengthType.NUMBER), l.getValue());
 
178
                }
 
179
                catch(ParseException e){ fail(); }
 
180
        }
 
181
        
 
182
        
 
183
        
 
184
        @Test
 
185
        public void testParseNumberOrPercent()
 
186
        {
 
187
                SVGLengthParser p;
 
188
                SVGLength l;
 
189
                
 
190
                try
 
191
                {
 
192
                        p = new SVGLengthParser("1mm");
 
193
                        l = p.parseNumberOrPercent();
 
194
                        
 
195
                        assertEquals(l.getValueAsString(), "1");
 
196
                        assertEquals(l.getLengthType(), SVGLength.LengthType.NUMBER);
 
197
                        assertEquals(UnitProcessor.toUserUnit(1, SVGLength.LengthType.NUMBER), l.getValue());
 
198
                }
 
199
                catch(ParseException e){ fail(); }
 
200
                
 
201
                try
 
202
                {
 
203
                        p = new SVGLengthParser("0.876");
 
204
                        l = p.parseNumberOrPercent();
 
205
                        
 
206
                        assertEquals(l.getValueAsString(), "0.876");
 
207
                        assertEquals(l.getLengthType(), SVGLength.LengthType.NUMBER);
 
208
                        assertEquals(UnitProcessor.toUserUnit(0.876, SVGLength.LengthType.NUMBER), l.getValue());
 
209
                }
 
210
                catch(ParseException e){ fail(); }
 
211
        }
 
212
        
 
213
        
 
214
        
 
215
        @Test
 
216
        public void testParseCoordinate()
 
217
        {
 
218
                SVGLengthParser p;
 
219
                SVGLength l;
 
220
                
 
221
                try
 
222
                {
 
223
                        p = new SVGLengthParser("");
 
224
                        l = p.parseCoordinate();
 
225
                        fail();
 
226
                }
 
227
                catch(ParseException e){ /* */ }
 
228
                
 
229
                try
 
230
                {
 
231
                        p = new SVGLengthParser("1m");
 
232
                        l = p.parseCoordinate();
 
233
                        fail();
 
234
                }
 
235
                catch(ParseException e){ /* */ }
 
236
                
 
237
                try
 
238
                {
 
239
                        p = new SVGLengthParser("m");
 
240
                        l = p.parseCoordinate();
 
241
                        fail();
 
242
                }
 
243
                catch(ParseException e){ /* */ }
 
244
                
 
245
                try
 
246
                {
 
247
                        p = new SVGLengthParser("1p");
 
248
                        l = p.parseCoordinate();
 
249
                        fail();
 
250
                }
 
251
                catch(ParseException e){ /* */ }
 
252
                
 
253
                try
 
254
                {
 
255
                        p = new SVGLengthParser("1e1i");
 
256
                        l = p.parseCoordinate();
 
257
                        fail();
 
258
                }
 
259
                catch(ParseException e){ /* */ }
 
260
                
 
261
                try
 
262
                {
 
263
                        p = new SVGLengthParser("1ci");
 
264
                        l = p.parseCoordinate();
 
265
                        fail();
 
266
                }
 
267
                catch(ParseException e){ /* */ }
 
268
                
 
269
                try
 
270
                {
 
271
                        p = new SVGLengthParser("1 c ");
 
272
                        l = p.parseCoordinate();
 
273
                        fail();
 
274
                }
 
275
                catch(ParseException e){ /* */ }
 
276
                
 
277
                try
 
278
                {
 
279
                        p = new SVGLengthParser("1mm");
 
280
                        l = p.parseCoordinate();
 
281
                        
 
282
                        assertEquals(l.getValueAsString(), "1");
 
283
                        assertEquals(l.getLengthType(), SVGLength.LengthType.MM);
 
284
                        assertEquals(UnitProcessor.toUserUnit(1, SVGLength.LengthType.MM), l.getValue());
 
285
                }
 
286
                catch(ParseException e){ fail(); }
 
287
                
 
288
                try
 
289
                {
 
290
                        p = new SVGLengthParser("0.65 cm");
 
291
                        l = p.parseCoordinate();
 
292
                        
 
293
                        assertEquals(l.getValueAsString(), "0.65");
 
294
                        assertEquals(l.getLengthType(), SVGLength.LengthType.CM);
 
295
                        assertEquals(UnitProcessor.toUserUnit(0.65, SVGLength.LengthType.CM), l.getValue());
 
296
                }
 
297
                catch(ParseException e){ fail(); }
 
298
                
 
299
                try
 
300
                {
 
301
                        p = new SVGLengthParser("\t -10.65  \t \n pc");
 
302
                        l = p.parseCoordinate();
 
303
                        
 
304
                        assertEquals(l.getValueAsString(), "-10.65");
 
305
                        assertEquals(l.getLengthType(), SVGLength.LengthType.PC);
 
306
                        assertEquals(UnitProcessor.toUserUnit(-10.65, SVGLength.LengthType.PC), l.getValue());
 
307
                }
 
308
                catch(ParseException e){ fail(); }
 
309
                
 
310
                try
 
311
                {
 
312
                        p = new SVGLengthParser("\t -10.65e2  \t \n px \t   ");
 
313
                        l = p.parseCoordinate();
 
314
                        
 
315
                        assertEquals(l.getValueAsString(), "-10.65e2");
 
316
                        assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
 
317
                        assertEquals(UnitProcessor.toUserUnit(-10.65e2, SVGLength.LengthType.PX), l.getValue());
 
318
                }
 
319
                catch(ParseException e){ fail(); }
 
320
                
 
321
                try
 
322
                {
 
323
                        p = new SVGLengthParser("\t -10.65e0pt \t   ");
 
324
                        l = p.parseCoordinate();
 
325
                        
 
326
                        assertEquals(l.getValueAsString(), "-10.65e0");
 
327
                        assertEquals(l.getLengthType(), SVGLength.LengthType.PT);
 
328
                        assertEquals(UnitProcessor.toUserUnit(-10.65e0, SVGLength.LengthType.PT), l.getValue());
 
329
                }
 
330
                catch(ParseException e){ fail(); }
 
331
                
 
332
                try
 
333
                {
 
334
                        p = new SVGLengthParser("\t -1.in \t   ");
 
335
                        l = p.parseCoordinate();
 
336
                        
 
337
                        assertEquals(l.getValueAsString(), "-1.");
 
338
                        assertEquals(l.getLengthType(), SVGLength.LengthType.IN);
 
339
                        assertEquals(UnitProcessor.toUserUnit(-1., SVGLength.LengthType.IN), l.getValue());
 
340
                }
 
341
                catch(ParseException e){ fail(); }
 
342
                
 
343
                try
 
344
                {
 
345
                        p = new SVGLengthParser("-1.");
 
346
                        l = p.parseCoordinate();
 
347
                        
 
348
                        assertEquals(l.getValueAsString(), "-1.");
 
349
                        assertEquals(l.getLengthType(), SVGLength.LengthType.NUMBER);
 
350
                        assertEquals(UnitProcessor.toUserUnit(-1., SVGLength.LengthType.NUMBER), l.getValue());
 
351
                }
 
352
                catch(ParseException e){ fail(); }
 
353
        }
 
354
}