~ubuntu-branches/ubuntu/utopic/ant/utopic

« back to all changes in this revision

Viewing changes to src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2014-05-09 11:46:04 UTC
  • mfrom: (25.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140509114604-3h26sbqgjef3jln4
Tags: 1.9.4-1
* New upstream release
  - Refreshed the patches
  - Removed the patch for #735786 (Fixed upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
package org.apache.tools.ant.util;
20
20
 
 
21
import org.junit.Test;
 
22
import org.w3c.dom.Document;
 
23
import org.w3c.dom.Element;
 
24
 
21
25
import java.io.IOException;
22
26
import java.io.StringWriter;
23
27
 
24
 
import junit.framework.TestCase;
25
 
 
26
 
import org.w3c.dom.Document;
27
 
import org.w3c.dom.Element;
 
28
import static org.junit.Assert.assertEquals;
 
29
import static org.junit.Assert.assertTrue;
28
30
 
29
31
/**
30
32
 * Tests for org.apache.tools.ant.util.DOMElementWriter.
31
33
 *
32
34
 */
33
 
public class DOMElementWriterTest extends TestCase {
 
35
public class DOMElementWriterTest {
34
36
 
35
37
    private DOMElementWriter w = new DOMElementWriter();
36
38
 
37
 
    public DOMElementWriterTest(String name) {
38
 
        super(name);
39
 
    }
40
 
 
 
39
    @Test
41
40
    public void testIsReference() {
42
41
        assertTrue("", w.isReference(""));
43
42
        assertTrue(" ", w.isReference(" "));
52
51
        assertTrue("&", w.isReference("&"));
53
52
    }
54
53
 
 
54
    @Test
55
55
    public void testEncode() {
56
56
        assertEquals("", w.encode(""));
57
57
        assertEquals(" ", w.encode(" "));
71
71
        assertEquals("\r\n\t", w.encode("\r\n\t"));
72
72
    }
73
73
 
 
74
    @Test
74
75
    public void testEncodeAttributeValue() {
75
76
        assertEquals("", w.encodeAttributeValue(""));
76
77
        assertEquals(" ", w.encodeAttributeValue(" "));
90
91
        assertEquals("
	", w.encodeAttributeValue("\r\n\t"));
91
92
    }
92
93
 
 
94
    @Test
93
95
    public void testAttributeWithWhitespace() throws IOException {
94
96
        Document d = DOMUtils.newDocument();
95
97
        Element root = d.createElement("root");
101
103
                     sw.toString());
102
104
    }
103
105
 
 
106
    @Test
104
107
    public void testEncodeData() {
105
108
        assertEquals("\"20;&", w.encodedata("\"20;&"));
106
109
        assertEquals("", w.encodedata("\u0017"));
107
110
    }
108
111
 
 
112
    @Test
109
113
    public void testIsLegalCharacter() {
110
114
        assertTrue("0x00", !w.isLegalCharacter('\u0000'));
111
115
        assertTrue("0x09", w.isLegalCharacter('\t'));
121
125
        assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE'));
122
126
    }
123
127
 
 
128
    @Test
124
129
    public void testCDATAEndEncoding() {
125
130
        assertEquals("]>", w.encodedata("]>"));
126
131
        assertEquals("]]", w.encodedata("]]"));
132
137
                     w.encodedata("A]]>B]]>C"));
133
138
    }
134
139
 
 
140
    @Test
135
141
    public void testNoAdditionalWhiteSpaceForText() throws IOException {
136
142
        Document d = DOMUtils.newDocument();
137
143
        Element root = d.createElement("root");
147
153
                     sw.toString());
148
154
    }
149
155
 
 
156
    @Test
150
157
    public void testNoAdditionalWhiteSpaceForCDATA() throws IOException {
151
158
        Document d = DOMUtils.newDocument();
152
159
        Element root = d.createElement("root");
162
169
                     sw.toString());
163
170
    }
164
171
 
 
172
    @Test
165
173
    public void testNoAdditionalWhiteSpaceForEmptyElement() throws IOException {
166
174
        Document d = DOMUtils.newDocument();
167
175
        Element root = d.createElement("root");
178
186
                     sw.toString());
179
187
    }
180
188
 
 
189
    @Test
181
190
    public void testNoNSPrefixByDefault() throws IOException {
182
191
        Document d = DOMUtils.newDocument();
183
192
        Element root = d.createElementNS("urn:foo", "root");
190
199
                     + StringUtils.LINE_SEP, sw.toString());
191
200
    }
192
201
 
 
202
    @Test
193
203
    public void testNSOnElement() throws IOException {
194
204
        Document d = DOMUtils.newDocument();
195
205
        Element root = d.createElementNS("urn:foo", "root");
205
215
                     + StringUtils.LINE_SEP, sw.toString());
206
216
    }
207
217
 
 
218
    @Test
208
219
    public void testNSPrefixOnAttribute() throws IOException {
209
220
        Document d = DOMUtils.newDocument();
210
221
        Element root = d.createElementNS("urn:foo", "root");
221
232
                     + StringUtils.LINE_SEP, sw.toString());
222
233
    }
223
234
 
 
235
    @Test
224
236
    public void testNSPrefixOnAttributeEvenWithoutElement() throws IOException {
225
237
        Document d = DOMUtils.newDocument();
226
238
        Element root = d.createElementNS("urn:foo", "root");
237
249
                     + StringUtils.LINE_SEP, sw.toString());
238
250
    }
239
251
 
 
252
    @Test
240
253
    public void testNSGetsReused() throws IOException {
241
254
        Document d = DOMUtils.newDocument();
242
255
        Element root = d.createElementNS("urn:foo", "root");
256
269
                     + StringUtils.LINE_SEP, sw.toString());
257
270
    }
258
271
 
 
272
    @Test
259
273
    public void testNSGoesOutOfScope() throws IOException {
260
274
        Document d = DOMUtils.newDocument();
261
275
        Element root = d.createElementNS("urn:foo", "root");