1 18 package org.apache.batik.swing; 19 20 import java.awt.EventQueue ; 21 import java.io.PrintWriter ; 22 import java.io.StringWriter ; 23 24 import org.w3c.dom.svg.SVGDocument; 25 26 import org.apache.batik.test.DefaultTestReport; 27 import org.apache.batik.test.TestReport; 28 29 39 public class NullSetSVGDocumentTest extends JSVGMemoryLeakTest { 40 public NullSetSVGDocumentTest() { 41 } 42 43 public static final String TEST_NON_NULL_URI 44 = "file:samples/anne.svg"; 45 46 49 public static final String ENTRY_KEY_ERROR_DESCRIPTION 50 = "JSVGCanvasHandler.entry.key.error.description"; 51 52 55 public static final String ERROR_IMAGE_NOT_CLEARED 56 = "NullSetSVGDocumentTest.message.error.image.not.cleared"; 57 58 public static final String ERROR_ON_SET 59 = "NullSetSVGDocumentTest.message.error.on.set"; 60 61 public String getName() { return getId(); } 62 63 public JSVGCanvasHandler createHandler() { 64 return new JSVGCanvasHandler(this, this) { 65 public JSVGCanvas createCanvas() { 66 return new JSVGCanvas() { 67 protected void installSVGDocument(SVGDocument doc){ 68 super.installSVGDocument(doc); 69 if (doc != null) return; 70 handler.scriptDone(); 71 } 72 }; 73 } 74 }; 75 } 76 77 public Runnable getRunnable(final JSVGCanvas canvas) { 78 return new Runnable () { 79 public void run() { 80 canvas.setSVGDocument(null); 81 }}; 82 } 83 84 85 public boolean canvasInit(JSVGCanvas canvas) { 86 theCanvas = canvas; 87 theFrame = handler.getFrame(); 88 89 canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); 90 canvas.setURI(TEST_NON_NULL_URI); 91 92 registerObjectDesc(canvas, "JSVGCanvas"); 93 registerObjectDesc(handler.getFrame(), "JFrame"); 94 return true; } 96 97 public void canvasRendered(JSVGCanvas canvas) { 98 super.canvasRendered(canvas); 99 try { 100 EventQueue.invokeAndWait(getRunnable(canvas)); 101 } catch (Throwable t) { 102 t.printStackTrace(); 103 StringWriter trace = new StringWriter (); 104 t.printStackTrace(new PrintWriter (trace)); 105 DefaultTestReport report = new DefaultTestReport(this); 106 report.setErrorCode(ERROR_ON_SET); 107 report.setDescription(new TestReport.Entry[] { 108 new TestReport.Entry 109 (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), 110 fmt(ERROR_ON_SET, new Object []{ trace.toString()})) 111 }); 112 report.setPassed(false); 113 failReport = report; 114 } 115 } 116 117 public boolean canvasUpdated(JSVGCanvas canvas) { 118 return true; 119 } 120 121 122 public void canvasDone(JSVGCanvas canvas) { 123 synchronized (this) { 124 checkObjects(new String [] { "SVGDoc", "GVT", "updateManager" }); 127 128 if (canvas.getOffScreen() == null) 129 return; 130 System.err.println(">>>>>>> Canvas not cleared"); 131 DefaultTestReport report = new DefaultTestReport(this); 132 report.setErrorCode(ERROR_IMAGE_NOT_CLEARED); 133 report.setDescription(new TestReport.Entry[] { 138 new TestReport.Entry 139 (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), 140 fmt(ERROR_IMAGE_NOT_CLEARED, null))}); 141 report.setPassed(false); 142 failReport = report; 143 return; 144 } 145 } 146 } 147 | Popular Tags |