~ubuntu-branches/debian/squeeze/latexdraw/squeeze

« back to all changes in this revision

Viewing changes to junit/test/svg/AbstractTestSVGElement.java

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2009-05-03 23:49:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090503234935-cls7n48x018g0vk2
Tags: upstream-2.0.2+1
ImportĀ upstreamĀ versionĀ 2.0.2+1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package junit.test.svg;
 
2
 
 
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;
 
8
 
 
9
import org.junit.Before;
 
10
import org.junit.Test;
 
11
import org.w3c.dom.DOMException;
 
12
 
 
13
public abstract class AbstractTestSVGElement extends TestCase
 
14
{
 
15
        protected SVGElement node;
 
16
        protected SVGDocument doc = new SVGDocument();
 
17
        
 
18
        
 
19
        public abstract String getNameNode();
 
20
        
 
21
        
 
22
        @Override
 
23
        @Before
 
24
        public void setUp()
 
25
        {
 
26
                doc = new SVGDocument();
 
27
        node = (SVGElement)doc.createElement(getNameNode());
 
28
        }
 
29
        
 
30
        
 
31
        @Test
 
32
        public void testGetNodeName()
 
33
        {
 
34
                assertEquals(getNameNode(), node.getNodeName());
 
35
        }
 
36
        
 
37
        
 
38
        @Test
 
39
        public void testSetNodeName()
 
40
        {
 
41
                node.setNodeName("test");
 
42
                assertEquals("test", node.getNodeName());
 
43
                node.setNodeName(getNameNode());
 
44
                assertEquals(getNameNode(), node.getNodeName());
 
45
        }
 
46
        
 
47
        
 
48
        @Test
 
49
        public void testSetParent()
 
50
        {
 
51
                SVGElement elt = (SVGElement)doc.createElement("elt");
 
52
                
 
53
                node.setParent(null);
 
54
                assertNull(node.getParent());
 
55
                node.setParent(elt);
 
56
                assertEquals(elt, node.getParent());
 
57
                SVGNodeList list = elt.getChildren(getNameNode());
 
58
                assertEquals(1, list.getLength());
 
59
                node.setParent(null);
 
60
                list = elt.getChildren(getNameNode());
 
61
                assertEquals(0, list.getLength());
 
62
        }
 
63
        
 
64
        
 
65
        @Test
 
66
        public void testGetAttribute()
 
67
        {
 
68
                assertNull(node.getAttribute(null));
 
69
                assertNull(node.getAttribute(""));
 
70
                node.setAttribute("testAttr", "valAttr");
 
71
                assertEquals(node.getAttribute("testAttr"), "valAttr");
 
72
        }
 
73
        
 
74
        
 
75
        @Test
 
76
        public void testGetAttributeNode()
 
77
        {
 
78
                assertNull(node.getAttributeNode(null));
 
79
                assertNull(node.getAttributeNode(""));
 
80
                node.setAttribute("testAttr2", "valAttr2");
 
81
                assertEquals(node.getAttributeNode("testAttr2").getNodeValue(), "valAttr2");
 
82
        }
 
83
        
 
84
        
 
85
        @Test
 
86
        public void testGetTagName()
 
87
        {
 
88
                assertEquals(node.getNodeName(), node.getTagName());
 
89
        }
 
90
        
 
91
        
 
92
        
 
93
        @Test
 
94
        public void testAppendChild()
 
95
        {
 
96
                try
 
97
                {
 
98
                        node.appendChild(null);
 
99
                        fail();
 
100
                }
 
101
                catch(DOMException e) { /* ok */ }
 
102
                
 
103
                try
 
104
                {
 
105
                        node.appendChild(new SVGAttr("", "", node));
 
106
                        fail();
 
107
                }
 
108
                catch(DOMException e) { /* ok */ }
 
109
                
 
110
                
 
111
                SVGElement elt = (SVGElement)doc.createElement("eltAppendChild");
 
112
                assertEquals(node.appendChild(elt), elt);
 
113
                assertEquals(node.getChildren("eltAppendChild").getLength(), 1);
 
114
        }
 
115
}