1 16 17 package org.apache.batik.parser; 18 19 import java.io.*; 20 21 import org.apache.batik.test.*; 22 23 29 public class TransformListParserTest extends AbstractTest { 30 31 protected String sourceTransform; 32 protected String destinationTransform; 33 34 protected StringBuffer buffer; 35 protected String resultTransform; 36 37 42 public TransformListParserTest(String stransform, String dtransform) { 43 sourceTransform = stransform; 44 destinationTransform = dtransform; 45 } 46 47 public TestReport runImpl() throws Exception { 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 (); 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 |