~ubuntu-branches/debian/jessie/latexdraw/jessie

« back to all changes in this revision

Viewing changes to junit/test/svg/TestSVGSVGElement.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 javax.xml.parsers.DocumentBuilder;
 
4
import javax.xml.parsers.DocumentBuilderFactory;
 
5
 
 
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;
 
11
 
 
12
import org.junit.Test;
 
13
import org.w3c.dom.Document;
 
14
import org.w3c.dom.Element;
 
15
 
 
16
/** 
 
17
 * This class contains tests for the SVGSVGElement class.<br>
 
18
 *<br>
 
19
 * This file is part of LaTeXDraw<br>
 
20
 * Copyright (c) 2005-2008 Arnaud BLOUIN<br>
 
21
 *<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>
 
26
 *<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>
 
30
 *<br>
 
31
 * 10/12/07<br>
 
32
 * @author Arnaud BLOUIN<br>
 
33
 * @version 2.0.0<br>
 
34
 */
 
35
@SuppressWarnings("nls")
 
36
public class TestSVGSVGElement extends AbstractTestSVGElement
 
37
{
 
38
        @Test
 
39
        public void testContructor()
 
40
        {
 
41
                try
 
42
                { 
 
43
                        new SVGSVGElement(null);
 
44
                        fail();
 
45
                }
 
46
                catch(Exception e){/**/}
 
47
                
 
48
                try { new SVGSVGElement(node, null); }
 
49
                catch(MalformedSVGDocument e){ fail(); }
 
50
        }
 
51
        
 
52
        
 
53
        
 
54
        @Test
 
55
        public void testGetDefs()
 
56
        {
 
57
                try
 
58
                {
 
59
                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 
60
                DocumentBuilder builder = factory.newDocumentBuilder();
 
61
                Document document = builder.newDocument();
 
62
                        Element elt, n;
 
63
                SVGSVGElement e = new SVGSVGElement(node, null);
 
64
                        
 
65
                        assertNull(e.getMeta());
 
66
 
 
67
                        n = document.createElement(SVGElements.SVG_SVG);
 
68
                        n.setAttribute("xmlns", SVGDocument.SVG_NAMESPACE);
 
69
                        elt = document.createElement(SVGElements.SVG_DEFS);
 
70
                        n.appendChild(elt);
 
71
                        e = new SVGSVGElement(n, null);
 
72
                        assertNotNull(e.getDefs());
 
73
                }
 
74
                catch(Exception e) { fail(); }
 
75
        }
 
76
        
 
77
        
 
78
        
 
79
        @Test
 
80
        public void testGetMeta()
 
81
        {
 
82
                try
 
83
                {
 
84
                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 
85
                DocumentBuilder builder = factory.newDocumentBuilder();
 
86
                Document document = builder.newDocument();
 
87
                        Element elt, n;
 
88
                SVGSVGElement e = new SVGSVGElement(node, null);
 
89
                        
 
90
                        assertNull(e.getMeta());
 
91
 
 
92
                        n = document.createElement(SVGElements.SVG_SVG);
 
93
                        n.setAttribute("xmlns", SVGDocument.SVG_NAMESPACE);
 
94
                        elt = document.createElement(SVGElements.SVG_METADATA);
 
95
                        n.appendChild(elt);
 
96
                        e = new SVGSVGElement(n, null);
 
97
                        assertNotNull(e.getMeta());
 
98
                }
 
99
                catch(Exception e) { fail(); }
 
100
        }
 
101
        
 
102
        
 
103
        
 
104
        
 
105
        @Test
 
106
        public void testGetHeight()
 
107
        {
 
108
                try
 
109
                {
 
110
                        node.setAttribute(SVGAttributes.SVG_HEIGHT, "200");
 
111
                        SVGSVGElement e = new SVGSVGElement(node, null);
 
112
                        assertEquals(e.getHeight(), 200.);
 
113
                }
 
114
                catch(MalformedSVGDocument e) { fail(); }
 
115
        }
 
116
        
 
117
        
 
118
        
 
119
        @Test
 
120
        public void testEnableRendering()
 
121
        {
 
122
                try
 
123
                {
 
124
                        SVGSVGElement e = new SVGSVGElement(node, null);
 
125
                        assertTrue(e.enableRendering());
 
126
                        
 
127
                        node.setAttribute(SVGAttributes.SVG_WIDTH, "0");
 
128
                        e = new SVGSVGElement(node, null);
 
129
                        assertFalse(e.enableRendering());
 
130
                        
 
131
                        node.setAttribute(SVGAttributes.SVG_WIDTH, "10");
 
132
                        node.setAttribute(SVGAttributes.SVG_HEIGHT, "0");
 
133
                        e = new SVGSVGElement(node, null);
 
134
                        assertFalse(e.enableRendering());
 
135
                        
 
136
                        node.setAttribute(SVGAttributes.SVG_WIDTH, "10");
 
137
                        node.setAttribute(SVGAttributes.SVG_HEIGHT, "10");
 
138
                        e = new SVGSVGElement(node, null);
 
139
                        assertTrue(e.enableRendering());
 
140
                }
 
141
                catch(MalformedSVGDocument e) { fail(); }
 
142
        }
 
143
        
 
144
        
 
145
        @Test
 
146
        public void testGetY()
 
147
        {
 
148
                try
 
149
                {
 
150
                        SVGSVGElement e = new SVGSVGElement(node, null);
 
151
                        assertEquals(e.getY(), 0.);
 
152
                        
 
153
                        node.setAttribute(SVGAttributes.SVG_Y, "-10");
 
154
                        e = new SVGSVGElement(node, null);
 
155
                        assertEquals(e.getY(), -10.);
 
156
                }
 
157
                catch(MalformedSVGDocument e) { fail(); }
 
158
        }
 
159
        
 
160
        
 
161
        
 
162
        @Test
 
163
        public void testGetX()
 
164
        {
 
165
                try
 
166
                {
 
167
                        SVGSVGElement e = new SVGSVGElement(node, null);
 
168
                        assertEquals(e.getX(), 0.);
 
169
                        
 
170
                        node.setAttribute(SVGAttributes.SVG_X, "10");
 
171
                        e = new SVGSVGElement(node, null);
 
172
                        assertEquals(e.getX(), 10.);
 
173
                }
 
174
                catch(MalformedSVGDocument e) { fail(); }
 
175
        }
 
176
        
 
177
        
 
178
        
 
179
        @Test
 
180
        public void testGetWidth()
 
181
        {
 
182
                try
 
183
                {
 
184
                        node.setAttribute(SVGAttributes.SVG_WIDTH, "100");
 
185
                        SVGSVGElement e = new SVGSVGElement(node, null);
 
186
                        assertEquals(e.getWidth(), 100.);
 
187
                }
 
188
                catch(MalformedSVGDocument e) { fail(); }
 
189
        }
 
190
        
 
191
        
 
192
        @Test
 
193
        public void testVersion()
 
194
        {
 
195
                try
 
196
                {
 
197
                        node.setAttribute(SVGAttributes.SVG_VERSION, "1.1");
 
198
                        SVGSVGElement e = new SVGSVGElement(node, null);
 
199
                        assertEquals(e.getVersion(), "1.1");
 
200
                }
 
201
                catch(MalformedSVGDocument e) { fail(); }
 
202
        }
 
203
        
 
204
        
 
205
        @Override
 
206
        public String getNameNode()
 
207
        {
 
208
                return SVGElements.SVG_SVG;
 
209
        }
 
210
}