1
package junit.test.svg;
3
import junit.framework.TestCase;
4
import latexDraw.parsers.svg.SVGAttr;
5
import latexDraw.parsers.svg.SVGDocument;
6
import latexDraw.parsers.svg.SVGNodeList;
7
import latexDraw.parsers.svg.elements.SVGElement;
9
import org.junit.Before;
10
import org.junit.Test;
11
import org.w3c.dom.DOMException;
13
public abstract class AbstractTestSVGElement extends TestCase
15
protected SVGElement node;
16
protected SVGDocument doc = new SVGDocument();
19
public abstract String getNameNode();
26
doc = new SVGDocument();
27
node = (SVGElement)doc.createElement(getNameNode());
32
public void testGetNodeName()
34
assertEquals(getNameNode(), node.getNodeName());
39
public void testSetNodeName()
41
node.setNodeName("test");
42
assertEquals("test", node.getNodeName());
43
node.setNodeName(getNameNode());
44
assertEquals(getNameNode(), node.getNodeName());
49
public void testSetParent()
51
SVGElement elt = (SVGElement)doc.createElement("elt");
54
assertNull(node.getParent());
56
assertEquals(elt, node.getParent());
57
SVGNodeList list = elt.getChildren(getNameNode());
58
assertEquals(1, list.getLength());
60
list = elt.getChildren(getNameNode());
61
assertEquals(0, list.getLength());
66
public void testGetAttribute()
68
assertNull(node.getAttribute(null));
69
assertNull(node.getAttribute(""));
70
node.setAttribute("testAttr", "valAttr");
71
assertEquals(node.getAttribute("testAttr"), "valAttr");
76
public void testGetAttributeNode()
78
assertNull(node.getAttributeNode(null));
79
assertNull(node.getAttributeNode(""));
80
node.setAttribute("testAttr2", "valAttr2");
81
assertEquals(node.getAttributeNode("testAttr2").getNodeValue(), "valAttr2");
86
public void testGetTagName()
88
assertEquals(node.getNodeName(), node.getTagName());
94
public void testAppendChild()
98
node.appendChild(null);
101
catch(DOMException e) { /* ok */ }
105
node.appendChild(new SVGAttr("", "", node));
108
catch(DOMException e) { /* ok */ }
111
SVGElement elt = (SVGElement)doc.createElement("eltAppendChild");
112
assertEquals(node.appendChild(elt), elt);
113
assertEquals(node.getChildren("eltAppendChild").getLength(), 1);