001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.batik.parser;
019:
020: import java.io.*;
021:
022: import org.apache.batik.test.*;
023:
024: /**
025: * To test the transform list parser.
026: *
027: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
028: * @version $Id: TransformListParserTest.java 475477 2006-11-15 22:44:28Z cam $
029: */
030: public class TransformListParserTest extends AbstractTest {
031:
032: protected String sourceTransform;
033: protected String destinationTransform;
034:
035: protected StringBuffer buffer;
036: protected String resultTransform;
037:
038: /**
039: * Creates a new TransformListParserTest.
040: * @param stransform The transform to parse.
041: * @param dtransform The transform after serialization.
042: */
043: public TransformListParserTest(String stransform, String dtransform) {
044: sourceTransform = stransform;
045: destinationTransform = dtransform;
046: }
047:
048: public TestReport runImpl() throws Exception {
049: TransformListParser pp = new TransformListParser();
050: pp.setTransformListHandler(new TestHandler());
051:
052: try {
053: pp.parse(new StringReader(sourceTransform));
054: } catch (ParseException e) {
055: DefaultTestReport report = new DefaultTestReport(this );
056: report.setErrorCode("parse.error");
057: report
058: .addDescriptionEntry("exception.text", e
059: .getMessage());
060: report.setPassed(false);
061: return report;
062: }
063:
064: if (!destinationTransform.equals(resultTransform)) {
065: DefaultTestReport report = new DefaultTestReport(this );
066: report.setErrorCode("invalid.parsing.events");
067: report.addDescriptionEntry("expected.text",
068: destinationTransform);
069: report.addDescriptionEntry("generated.text",
070: resultTransform);
071: report.setPassed(false);
072: return report;
073: }
074:
075: return reportSuccess();
076: }
077:
078: class TestHandler extends DefaultTransformListHandler {
079: boolean first;
080:
081: public TestHandler() {
082: }
083:
084: public void startTransformList() throws ParseException {
085: buffer = new StringBuffer();
086: first = true;
087: }
088:
089: public void matrix(float a, float b, float c, float d, float e,
090: float f) throws ParseException {
091: if (!first) {
092: buffer.append(' ');
093: }
094: first = false;
095: buffer.append("matrix(");
096: buffer.append(a);
097: buffer.append(", ");
098: buffer.append(b);
099: buffer.append(", ");
100: buffer.append(c);
101: buffer.append(", ");
102: buffer.append(d);
103: buffer.append(", ");
104: buffer.append(e);
105: buffer.append(", ");
106: buffer.append(f);
107: buffer.append(")");
108: }
109:
110: public void rotate(float theta) throws ParseException {
111: if (!first) {
112: buffer.append(' ');
113: }
114: first = false;
115: }
116:
117: public void rotate(float theta, float cx, float cy)
118: throws ParseException {
119: if (!first) {
120: buffer.append(' ');
121: }
122: first = false;
123: }
124:
125: public void translate(float tx) throws ParseException {
126: if (!first) {
127: buffer.append(' ');
128: }
129: first = false;
130: buffer.append("translate(");
131: buffer.append(tx);
132: buffer.append(")");
133: }
134:
135: public void translate(float tx, float ty) throws ParseException {
136: if (!first) {
137: buffer.append(' ');
138: }
139: first = false;
140: buffer.append("translate(");
141: buffer.append(tx);
142: buffer.append(", ");
143: buffer.append(ty);
144: buffer.append(")");
145: }
146:
147: public void scale(float sx) throws ParseException {
148: if (!first) {
149: buffer.append(' ');
150: }
151: first = false;
152: buffer.append("scale(");
153: buffer.append(sx);
154: buffer.append(")");
155: }
156:
157: public void scale(float sx, float sy) throws ParseException {
158: if (!first) {
159: buffer.append(' ');
160: }
161: first = false;
162: buffer.append("scale(");
163: buffer.append(sx);
164: buffer.append(", ");
165: buffer.append(sy);
166: buffer.append(")");
167: }
168:
169: public void skewX(float skx) throws ParseException {
170: if (!first) {
171: buffer.append(' ');
172: }
173: first = false;
174: buffer.append("skewX(");
175: buffer.append(skx);
176: buffer.append(")");
177: }
178:
179: public void skewY(float sky) throws ParseException {
180: if (!first) {
181: buffer.append(' ');
182: }
183: first = false;
184: buffer.append("skewY(");
185: buffer.append(sky);
186: buffer.append(")");
187: }
188:
189: public void endTransformList() throws ParseException {
190: resultTransform = buffer.toString();
191: }
192: }
193: }
|