1 18 package org.apache.batik.parser; 19 20 import java.io.*; 21 22 import org.apache.batik.test.*; 23 24 30 public class LengthParserTest extends AbstractTest { 31 32 protected String sourceLength; 33 protected String destinationLength; 34 35 protected StringBuffer buffer; 36 protected String resultLength; 37 38 43 public LengthParserTest(String slength, String dlength) { 44 sourceLength = slength; 45 destinationLength = dlength; 46 } 47 48 public TestReport runImpl() throws Exception { 49 LengthParser pp = new LengthParser(); 50 pp.setLengthHandler(new TestHandler()); 51 52 try { 53 pp.parse(new StringReader(sourceLength)); 54 } catch (ParseException e) { 55 DefaultTestReport report = new DefaultTestReport(this); 56 report.setErrorCode("parse.error"); 57 report.addDescriptionEntry("exception.text", e.getMessage()); 58 report.setPassed(false); 59 return report; 60 } 61 62 if (!destinationLength.equals(resultLength)) { 63 DefaultTestReport report = new DefaultTestReport(this); 64 report.setErrorCode("invalid.parsing.events"); 65 report.addDescriptionEntry("expected.text", destinationLength); 66 report.addDescriptionEntry("generated.text", resultLength); 67 report.setPassed(false); 68 return report; 69 } 70 71 return reportSuccess(); 72 } 73 74 class TestHandler extends DefaultLengthHandler { 75 public TestHandler() {} 76 77 public void startLength() throws ParseException { 78 buffer = new StringBuffer (); 79 } 80 81 public void lengthValue(float v) throws ParseException { 82 buffer.append(v); 83 } 84 85 public void em() throws ParseException { 86 buffer.append("em"); 87 } 88 89 public void ex() throws ParseException { 90 buffer.append("ex"); 91 } 92 93 public void in() throws ParseException { 94 buffer.append("in"); 95 } 96 97 public void cm() throws ParseException { 98 buffer.append("cm"); 99 } 100 101 public void mm() throws ParseException { 102 buffer.append("mm"); 103 } 104 105 public void pc() throws ParseException { 106 buffer.append("pc"); 107 } 108 109 public void pt() throws ParseException { 110 buffer.append("pt"); 111 } 112 113 public void px() throws ParseException { 114 buffer.append("px"); 115 } 116 117 public void percentage() throws ParseException { 118 buffer.append("%"); 119 } 120 121 public void endLength() throws ParseException { 122 resultLength = buffer.toString(); 123 } 124 } 125 } 126 | Popular Tags |