KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > parser > TransformListParserTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.batik.parser;
18
19 import java.io.*;
20
21 import org.apache.batik.test.*;
22
23 /**
24  * To test the transform list parser.
25  *
26  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
27  * @version $Id: TransformListParserTest.java,v 1.3 2005/04/01 02:28:16 deweese Exp $
28  */

29 public class TransformListParserTest extends AbstractTest {
30
31     protected String JavaDoc sourceTransform;
32     protected String JavaDoc destinationTransform;
33
34     protected StringBuffer JavaDoc buffer;
35     protected String JavaDoc resultTransform;
36
37     /**
38      * Creates a new TransformListParserTest.
39      * @param stransform The transform to parse.
40      * @param dtransform The transform after serialization.
41      */

42     public TransformListParserTest(String JavaDoc stransform, String JavaDoc dtransform) {
43         sourceTransform = stransform;
44         destinationTransform = dtransform;
45     }
46
47     public TestReport runImpl() throws Exception JavaDoc {
48         TransformListParser pp = new TransformListParser();
49         pp.setTransformListHandler(new TestHandler());
50
51         try {
52             pp.parse(new StringReader(sourceTransform));
53         } catch (ParseException e) {
54             DefaultTestReport report = new DefaultTestReport(this);
55             report.setErrorCode("parse.error");
56             report.addDescriptionEntry("exception.text", e.getMessage());
57             report.setPassed(false);
58             return report;
59         }
60
61         if (!destinationTransform.equals(resultTransform)) {
62             DefaultTestReport report = new DefaultTestReport(this);
63             report.setErrorCode("invalid.parsing.events");
64             report.addDescriptionEntry("expected.text", destinationTransform);
65             report.addDescriptionEntry("generated.text", resultTransform);
66             report.setPassed(false);
67             return report;
68         }
69
70         return reportSuccess();
71     }
72
73     class TestHandler extends DefaultTransformListHandler {
74         boolean first;
75         public TestHandler() {}
76         public void startTransformList() throws ParseException {
77             buffer = new StringBuffer JavaDoc();
78             first = true;
79         }
80         public void matrix(float a, float b, float c, float d, float e, float f)
81             throws ParseException {
82             if (!first) {
83                 buffer.append(' ');
84             }
85             first = false;
86             buffer.append("matrix(");
87             buffer.append(a);
88             buffer.append(", ");
89             buffer.append(b);
90             buffer.append(", ");
91             buffer.append(c);
92             buffer.append(", ");
93             buffer.append(d);
94             buffer.append(", ");
95             buffer.append(e);
96             buffer.append(", ");
97             buffer.append(f);
98             buffer.append(")");
99         }
100         public void rotate(float theta) throws ParseException {
101             if (!first) {
102                 buffer.append(' ');
103             }
104             first = false;
105         }
106         public void rotate(float theta, float cx, float cy) throws ParseException {
107             if (!first) {
108                 buffer.append(' ');
109             }
110             first = false;
111         }
112         public void translate(float tx) throws ParseException {
113             if (!first) {
114                 buffer.append(' ');
115             }
116             first = false;
117             buffer.append("translate(");
118             buffer.append(tx);
119             buffer.append(")");
120         }
121         public void translate(float tx, float ty) throws ParseException {
122             if (!first) {
123                 buffer.append(' ');
124             }
125             first = false;
126             buffer.append("translate(");
127             buffer.append(tx);
128             buffer.append(", ");
129             buffer.append(ty);
130             buffer.append(")");
131         }
132         public void scale(float sx) throws ParseException {
133             if (!first) {
134                 buffer.append(' ');
135             }
136             first = false;
137             buffer.append("scale(");
138             buffer.append(sx);
139             buffer.append(")");
140         }
141         public void scale(float sx, float sy) throws ParseException {
142             if (!first) {
143                 buffer.append(' ');
144             }
145             first = false;
146             buffer.append("scale(");
147             buffer.append(sx);
148             buffer.append(", ");
149             buffer.append(sy);
150             buffer.append(")");
151         }
152         public void skewX(float skx) throws ParseException {
153             if (!first) {
154                 buffer.append(' ');
155             }
156             first = false;
157             buffer.append("skewX(");
158             buffer.append(skx);
159             buffer.append(")");
160         }
161         public void skewY(float sky) throws ParseException {
162             if (!first) {
163                 buffer.append(' ');
164             }
165             first = false;
166             buffer.append("skewY(");
167             buffer.append(sky);
168             buffer.append(")");
169         }
170         public void endTransformList() throws ParseException {
171             resultTransform = buffer.toString();
172         }
173     }
174 }
175
Popular Tags