1 18 package org.apache.batik.svggen; 19 20 import java.awt.Dimension ; 21 import java.awt.Font ; 22 import java.io.StringWriter ; 23 24 import org.w3c.dom.DOMImplementation ; 25 import org.w3c.dom.Document ; 26 27 import org.apache.batik.dom.GenericDOMImplementation; 28 import org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults; 29 import org.apache.batik.test.AbstractTest; 30 import org.apache.batik.test.TestReport; 31 import org.apache.batik.util.SVGConstants; 32 33 40 public class GetRootTest extends AbstractTest implements SVGConstants { 41 public static final Dimension CANVAS_SIZE 42 = new Dimension (300, 400); 43 44 public static final String ERROR_DIFFERENT_SVG_OUTPUT 45 = "GetRootTest.error.different.svg.output"; 46 47 public static final String ENTRY_KEY_NO_ARG_OUTPUT 48 = "GetRootTest.entry.key.no.arg.output"; 49 50 public static final String ENTRY_KEY_SVG_ARG_OUTPUT 51 = "GetRootTest.entry.key.svg.arg.output"; 52 53 public TestReport runImpl() throws Exception { 54 56 DOMImplementation impl = GenericDOMImplementation.getDOMImplementation(); 57 String namespaceURI = SVGConstants.SVG_NAMESPACE_URI; 58 Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null); 59 SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory); 60 GraphicContextDefaults defaults 61 = new GraphicContextDefaults(); 62 defaults.font = new Font ("Arial", Font.PLAIN, 12); 63 ctx.setGraphicContextDefaults(defaults); 64 SVGGraphics2D g2d = new SVGGraphics2D(ctx, false); 65 66 g2d.setSVGCanvasSize(CANVAS_SIZE); 67 68 Painter painter = new BasicShapes(); 69 painter.paint(g2d); 70 71 StringWriter swA = new StringWriter (); 72 g2d.stream(g2d.getRoot(), swA); 73 74 domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null); 76 ctx = SVGGeneratorContext.createDefault(domFactory); 77 ctx.setGraphicContextDefaults(defaults); 78 g2d = new SVGGraphics2D(ctx, false); 79 80 g2d.setSVGCanvasSize(CANVAS_SIZE); 81 82 painter.paint(g2d); 83 84 StringWriter swB = new StringWriter (); 85 g2d.stream(g2d.getRoot(domFactory.getDocumentElement()), 86 swB); 87 88 if (swA.toString().equals(swB.toString())) { 90 return reportSuccess(); 91 } else { 92 TestReport report = reportError(ERROR_DIFFERENT_SVG_OUTPUT); 93 report.addDescriptionEntry(ENTRY_KEY_NO_ARG_OUTPUT, 94 swA.toString()); 95 report.addDescriptionEntry(ENTRY_KEY_SVG_ARG_OUTPUT, 96 swB.toString()); 97 return report; 98 } 99 } 100 } 101 | Popular Tags |