KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > swing > NullSetSVGDocumentTest


1 /*
2
3    Copyright 2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.swing;
19
20 import java.awt.EventQueue JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22 import java.io.StringWriter JavaDoc;
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 /**
30  * Test setDocument on JSVGComponent with non-Batik SVGOMDocument.
31  *
32  * This test constructs a generic Document with SVG content then it
33  * ensures that when this is passed to JSVGComponet.setDocument it is
34  * properly imported to an SVGOMDocument and rendered from there.
35  *
36  * @author <a HREF="mailto:deweese@apache.org">l449433</a>
37  * @version $Id: NullSetSVGDocumentTest.java,v 1.8 2005/03/27 08:58:37 cam Exp $
38  */

39 public class NullSetSVGDocumentTest extends JSVGMemoryLeakTest {
40     public NullSetSVGDocumentTest() {
41     }
42
43     public static final String JavaDoc TEST_NON_NULL_URI
44         = "file:samples/anne.svg";
45
46     /**
47      * Entry describing the error
48      */

49     public static final String JavaDoc ENTRY_KEY_ERROR_DESCRIPTION
50         = "JSVGCanvasHandler.entry.key.error.description";
51
52     /**
53      * Entry describing the error
54      */

55     public static final String JavaDoc ERROR_IMAGE_NOT_CLEARED
56         = "NullSetSVGDocumentTest.message.error.image.not.cleared";
57
58     public static final String JavaDoc ERROR_ON_SET
59         = "NullSetSVGDocumentTest.message.error.on.set";
60
61     public String JavaDoc 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 JavaDoc getRunnable(final JSVGCanvas canvas) {
78         return new Runnable JavaDoc () {
79                 public void run() {
80                     canvas.setSVGDocument(null);
81                 }};
82             }
83
84     /* JSVGCanvasHandler.Delegate Interface */
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; // We did trigger a load event.
95
}
96
97     public void canvasRendered(JSVGCanvas canvas) {
98         super.canvasRendered(canvas);
99         try {
100             EventQueue.invokeAndWait(getRunnable(canvas));
101         } catch (Throwable JavaDoc t) {
102             t.printStackTrace();
103             StringWriter JavaDoc trace = new StringWriter JavaDoc();
104             t.printStackTrace(new PrintWriter JavaDoc(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 JavaDoc[]{ 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             // Check that the original SVG
125
// Document and GVT tree are cleared.
126
checkObjects(new String JavaDoc[] { "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             // It would be great to provide the image here
134
// but it's a lot of work and this isn't _really_
135
// what we are testing. More testing that
136
// everything works (no exceptions thrown).
137
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