001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.swing;
020:
021: import java.awt.EventQueue;
022: import java.io.PrintWriter;
023: import java.io.StringWriter;
024:
025: import org.w3c.dom.svg.SVGDocument;
026:
027: import org.apache.batik.test.DefaultTestReport;
028: import org.apache.batik.test.TestReport;
029:
030: /**
031: * Test setDocument on JSVGComponent with non-Batik SVGOMDocument.
032: *
033: * This test constructs a generic Document with SVG content then it
034: * ensures that when this is passed to JSVGComponet.setDocument it is
035: * properly imported to an SVGOMDocument and rendered from there.
036: *
037: * @author <a href="mailto:deweese@apache.org">l449433</a>
038: * @version $Id: NullSetSVGDocumentTest.java 503369 2007-02-04 07:25:21Z cam $
039: */
040: public class NullSetSVGDocumentTest extends JSVGMemoryLeakTest {
041: public NullSetSVGDocumentTest() {
042: }
043:
044: public static final String TEST_NON_NULL_URI = "file:samples/anne.svg";
045:
046: /**
047: * Entry describing the error
048: */
049: public static final String ENTRY_KEY_ERROR_DESCRIPTION = "JSVGCanvasHandler.entry.key.error.description";
050:
051: /**
052: * Entry describing the error
053: */
054: public static final String ERROR_IMAGE_NOT_CLEARED = "NullSetSVGDocumentTest.message.error.image.not.cleared";
055:
056: public static final String ERROR_ON_SET = "NullSetSVGDocumentTest.message.error.on.set";
057:
058: public String getName() {
059: return getId();
060: }
061:
062: public JSVGCanvasHandler createHandler() {
063: return new JSVGCanvasHandler(this , this ) {
064: public JSVGCanvas createCanvas() {
065: return new JSVGCanvas() {
066: protected void installSVGDocument(SVGDocument doc) {
067: super .installSVGDocument(doc);
068: if (doc != null)
069: return;
070: handler.scriptDone();
071: }
072: };
073: }
074: };
075: }
076:
077: public Runnable getRunnable(final JSVGCanvas canvas) {
078: return new Runnable() {
079: public void run() {
080: canvas.setSVGDocument(null);
081: }
082: };
083: }
084:
085: /* JSVGCanvasHandler.Delegate Interface */
086: public boolean canvasInit(JSVGCanvas canvas) {
087: setTheCanvas(canvas);
088: theFrame = handler.getFrame();
089:
090: canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
091: canvas.setURI(TEST_NON_NULL_URI);
092:
093: registerObjectDesc(canvas, "JSVGCanvas");
094: registerObjectDesc(handler.getFrame(), "JFrame");
095: return true; // We did trigger a load event.
096: }
097:
098: public void canvasRendered(JSVGCanvas canvas) {
099: super .canvasRendered(canvas);
100: try {
101: EventQueue.invokeAndWait(getRunnable(canvas));
102: } catch (Throwable t) {
103: t.printStackTrace();
104: StringWriter trace = new StringWriter();
105: t.printStackTrace(new PrintWriter(trace));
106: DefaultTestReport report = new DefaultTestReport(this );
107: report.setErrorCode(ERROR_ON_SET);
108: report
109: .setDescription(new TestReport.Entry[] { new TestReport.Entry(
110: fmt(ENTRY_KEY_ERROR_DESCRIPTION, null),
111: fmt(ERROR_ON_SET, new Object[] { trace
112: .toString() })) });
113: report.setPassed(false);
114: failReport = report;
115: }
116: }
117:
118: public boolean canvasUpdated(JSVGCanvas canvas) {
119: return true;
120: }
121:
122: public void canvasDone(JSVGCanvas canvas) {
123: synchronized (this ) {
124: // Check that the original SVG
125: // Document and GVT tree are cleared.
126: checkObjects(new String[] { "SVGDoc", "GVT",
127: "updateManager" });
128:
129: if (canvas.getOffScreen() == null)
130: return;
131: System.err.println(">>>>>>> Canvas not cleared");
132: DefaultTestReport report = new DefaultTestReport(this );
133: report.setErrorCode(ERROR_IMAGE_NOT_CLEARED);
134: // It would be great to provide the image here
135: // but it's a lot of work and this isn't _really_
136: // what we are testing. More testing that
137: // everything works (no exceptions thrown).
138: report
139: .setDescription(new TestReport.Entry[] { new TestReport.Entry(
140: fmt(ENTRY_KEY_ERROR_DESCRIPTION, null),
141: fmt(ERROR_IMAGE_NOT_CLEARED, null)) });
142: report.setPassed(false);
143: failReport = report;
144: return;
145: }
146: }
147: }
|