1
package junit.test.svg;
3
import javax.xml.parsers.DocumentBuilder;
4
import javax.xml.parsers.DocumentBuilderFactory;
6
import latexDraw.parsers.svg.MalformedSVGDocument;
7
import latexDraw.parsers.svg.SVGAttributes;
8
import latexDraw.parsers.svg.SVGDocument;
9
import latexDraw.parsers.svg.SVGElements;
10
import latexDraw.parsers.svg.elements.SVGSVGElement;
12
import org.junit.Test;
13
import org.w3c.dom.Document;
14
import org.w3c.dom.Element;
17
* This class contains tests for the SVGSVGElement class.<br>
19
* This file is part of LaTeXDraw<br>
20
* Copyright (c) 2005-2008 Arnaud BLOUIN<br>
22
* LaTeXDraw is free software; you can redistribute it and/or modify
23
* it under the terms of the GNU General Public License as published by
24
* the Free Software Foundation; either version 2 of the License, or
25
* any later version.<br>
27
* LaTeXDraw is distributed without any warranty; without even the
28
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
29
* PURPOSE. See the GNU General Public License for more details.<br>
32
* @author Arnaud BLOUIN<br>
35
@SuppressWarnings("nls")
36
public class TestSVGSVGElement extends AbstractTestSVGElement
39
public void testContructor()
43
new SVGSVGElement(null);
46
catch(Exception e){/**/}
48
try { new SVGSVGElement(node, null); }
49
catch(MalformedSVGDocument e){ fail(); }
55
public void testGetDefs()
59
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
60
DocumentBuilder builder = factory.newDocumentBuilder();
61
Document document = builder.newDocument();
63
SVGSVGElement e = new SVGSVGElement(node, null);
65
assertNull(e.getMeta());
67
n = document.createElement(SVGElements.SVG_SVG);
68
n.setAttribute("xmlns", SVGDocument.SVG_NAMESPACE);
69
elt = document.createElement(SVGElements.SVG_DEFS);
71
e = new SVGSVGElement(n, null);
72
assertNotNull(e.getDefs());
74
catch(Exception e) { fail(); }
80
public void testGetMeta()
84
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
85
DocumentBuilder builder = factory.newDocumentBuilder();
86
Document document = builder.newDocument();
88
SVGSVGElement e = new SVGSVGElement(node, null);
90
assertNull(e.getMeta());
92
n = document.createElement(SVGElements.SVG_SVG);
93
n.setAttribute("xmlns", SVGDocument.SVG_NAMESPACE);
94
elt = document.createElement(SVGElements.SVG_METADATA);
96
e = new SVGSVGElement(n, null);
97
assertNotNull(e.getMeta());
99
catch(Exception e) { fail(); }
106
public void testGetHeight()
110
node.setAttribute(SVGAttributes.SVG_HEIGHT, "200");
111
SVGSVGElement e = new SVGSVGElement(node, null);
112
assertEquals(e.getHeight(), 200.);
114
catch(MalformedSVGDocument e) { fail(); }
120
public void testEnableRendering()
124
SVGSVGElement e = new SVGSVGElement(node, null);
125
assertTrue(e.enableRendering());
127
node.setAttribute(SVGAttributes.SVG_WIDTH, "0");
128
e = new SVGSVGElement(node, null);
129
assertFalse(e.enableRendering());
131
node.setAttribute(SVGAttributes.SVG_WIDTH, "10");
132
node.setAttribute(SVGAttributes.SVG_HEIGHT, "0");
133
e = new SVGSVGElement(node, null);
134
assertFalse(e.enableRendering());
136
node.setAttribute(SVGAttributes.SVG_WIDTH, "10");
137
node.setAttribute(SVGAttributes.SVG_HEIGHT, "10");
138
e = new SVGSVGElement(node, null);
139
assertTrue(e.enableRendering());
141
catch(MalformedSVGDocument e) { fail(); }
146
public void testGetY()
150
SVGSVGElement e = new SVGSVGElement(node, null);
151
assertEquals(e.getY(), 0.);
153
node.setAttribute(SVGAttributes.SVG_Y, "-10");
154
e = new SVGSVGElement(node, null);
155
assertEquals(e.getY(), -10.);
157
catch(MalformedSVGDocument e) { fail(); }
163
public void testGetX()
167
SVGSVGElement e = new SVGSVGElement(node, null);
168
assertEquals(e.getX(), 0.);
170
node.setAttribute(SVGAttributes.SVG_X, "10");
171
e = new SVGSVGElement(node, null);
172
assertEquals(e.getX(), 10.);
174
catch(MalformedSVGDocument e) { fail(); }
180
public void testGetWidth()
184
node.setAttribute(SVGAttributes.SVG_WIDTH, "100");
185
SVGSVGElement e = new SVGSVGElement(node, null);
186
assertEquals(e.getWidth(), 100.);
188
catch(MalformedSVGDocument e) { fail(); }
193
public void testVersion()
197
node.setAttribute(SVGAttributes.SVG_VERSION, "1.1");
198
SVGSVGElement e = new SVGSVGElement(node, null);
199
assertEquals(e.getVersion(), "1.1");
201
catch(MalformedSVGDocument e) { fail(); }
206
public String getNameNode()
208
return SVGElements.SVG_SVG;