KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > DOMElementWriterTest


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.util;
19
20 import junit.framework.Test;
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24 /**
25  * Tests for org.apache.tools.ant.util.DOMElementWriter.
26  *
27  */

28 public class DOMElementWriterTest extends TestCase {
29
30     private DOMElementWriter w = new DOMElementWriter();
31
32     public DOMElementWriterTest(String JavaDoc name) {
33         super(name);
34     }
35
36     public void testIsReference() {
37         assertTrue("", w.isReference(""));
38         assertTrue(" ", w.isReference(" "));
39         assertTrue(" ", w.isReference(" "));
40         assertTrue("&#A0;", !w.isReference("&#A0;"));
41         assertTrue("20;", !w.isReference("20;"));
42         assertTrue("&#20", !w.isReference("&#20"));
43         assertTrue(""", w.isReference("""));
44         assertTrue("'", w.isReference("'"));
45         assertTrue(">", w.isReference(">"));
46         assertTrue("<", w.isReference("<"));
47         assertTrue("&", w.isReference("&"));
48     }
49
50     public void testEncode() {
51         assertEquals("", w.encode(""));
52         assertEquals(" ", w.encode(" "));
53         assertEquals(" ", w.encode(" "));
54         assertEquals("&#A0;", w.encode("&#A0;"));
55         assertEquals("20;", w.encode("20;"));
56         assertEquals("&#20", w.encode("&#20"));
57         assertEquals(""", w.encode("""));
58         assertEquals("'", w.encode("'"));
59         assertEquals(">", w.encode(">"));
60         assertEquals("<", w.encode("<"));
61         assertEquals("&", w.encode("&"));
62         assertEquals(""", w.encode("\""));
63         assertEquals("&lt;", w.encode("<"));
64         assertEquals("&amp;", w.encode("&"));
65         assertEquals("", w.encode("\u0017"));
66         assertEquals("&#20;\"20;&", w.encodedata("&#20;\"20;&"));
67         assertEquals("", w.encodedata("\u0017"));
68     }
69
70     public void testIsLegalCharacter() {
71         assertTrue("0x00", !w.isLegalCharacter('\u0000'));
72         assertTrue("0x09", w.isLegalCharacter('\t'));
73         assertTrue("0x0A", w.isLegalCharacter('\n'));
74         assertTrue("0x0C", w.isLegalCharacter('\r'));
75         assertTrue("0x1F", !w.isLegalCharacter('\u001F'));
76         assertTrue("0x20", w.isLegalCharacter('\u0020'));
77         assertTrue("0xD7FF", w.isLegalCharacter('\uD7FF'));
78         assertTrue("0xD800", !w.isLegalCharacter('\uD800'));
79         assertTrue("0xDFFF", !w.isLegalCharacter('\uDFFF'));
80         assertTrue("0xE000", w.isLegalCharacter('\uE000'));
81         assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD'));
82         assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE'));
83     }
84
85     public void testCDATAEndEncoding() {
86         assertEquals("]>", w.encodedata("]>"));
87         assertEquals("]]", w.encodedata("]]"));
88         assertEquals("&#x5d;&#x5d;&gt;", w.encodedata("]]>"));
89         assertEquals("&#x5d;&#x5d;&gt;A", w.encodedata("]]>A"));
90         assertEquals("A&#x5d;&#x5d;&gt;", w.encodedata("A]]>"));
91         assertEquals("A&#x5d;&#x5d;&gt;A", w.encodedata("A]]>A"));
92         assertEquals("A&#x5d;&#x5d;&gt;B&#x5d;&#x5d;&gt;C",
93                      w.encodedata("A]]>B]]>C"));
94     }
95 }
96
Popular Tags