1 /*
2 * $Source$
3 * $Revision$
4 *
5 * Copyright (C) 2008 Tim Pizey
6 *
7 * Part of Melati (http://melati.org), a framework for the rapid
8 * development of clean, maintainable web applications.
9 *
10 * Melati is free software; Permission is granted to copy, distribute
11 * and/or modify this software under the terms either:
12 *
13 * a) the GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at your option)
15 * any later version,
16 *
17 * or
18 *
19 * b) any version of the Melati Software License, as published
20 * at http://melati.org
21 *
22 * You should have received a copy of the GNU General Public License and
23 * the Melati Software License along with this program;
24 * if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26 * GNU General Public License and visit http://melati.org to obtain the
27 * Melati Software License.
28 *
29 * Feel free to contact the Developers of Melati (http://melati.org),
30 * if you would like to work out a different arrangement than the options
31 * outlined here. It is our intention to allow Melati to be used by as
32 * wide an audience as possible.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * Contact details for copyright holder:
40 *
41 * Tim Pizey <timp At paneris.org>
42 * http://paneris.org/~timp
43 */
44
45 package org.melati.util.test;
46
47 import java.nio.charset.Charset;
48 import java.nio.charset.CharsetEncoder;
49
50 import org.melati.util.HTMLUtils;
51
52 import junit.framework.TestCase;
53
54 /**
55 * @author timp
56 * @since 25 Oct 2008
57 *
58 */
59 public class HTMLUtilsTest extends TestCase {
60
61 /**
62 * Constructor.
63 * @param name
64 */
65 public HTMLUtilsTest(String name) {
66 super(name);
67 }
68
69 /**
70 * {@inheritDoc}
71 * @see junit.framework.TestCase#setUp()
72 */
73 protected void setUp() throws Exception {
74 super.setUp();
75 }
76
77 /**
78 * {@inheritDoc}
79 * @see junit.framework.TestCase#tearDown()
80 */
81 protected void tearDown() throws Exception {
82 super.tearDown();
83 }
84
85 /**
86 * Test method for {@link org.melati.util.HTMLUtils#add(javax.swing.text.html.parser.ContentModel, javax.swing.text.html.parser.Element, javax.swing.text.html.parser.Element)}.
87 */
88 public void testAdd() {
89 }
90
91 /**
92 * Test method for {@link org.melati.util.HTMLUtils#addToContentModels(javax.swing.text.html.parser.DTD, javax.swing.text.html.parser.Element, javax.swing.text.html.parser.Element)}.
93 */
94 public void testAddToContentModels() {
95 }
96
97 /**
98 * Test method for {@link org.melati.util.HTMLUtils#dtdForHTMLParser()}.
99 */
100 public void testDtdForHTMLParser() {
101 }
102
103 /**
104 * Test method for {@link org.melati.util.HTMLUtils#entityFor(char, boolean, java.nio.charset.CharsetEncoder, boolean)}.
105 */
106 public void testEntityFor() {
107 cTest(null);
108 CharsetEncoder ce = Charset.forName("ISO-8859-1").newEncoder();
109 cTest(ce);
110 ce = Charset.forName("UTF-8").newEncoder();
111 cTest(ce);
112
113 }
114 private void cTest(CharsetEncoder ce) {
115 assertNull(HTMLUtils.entityFor('a',true, ce, false));
116 assertEquals("Á",HTMLUtils.entityFor("\u00C1".charAt(0),false, null, false));
117 char it = 193;
118 assertEquals("Á",HTMLUtils.entityFor(it,false, ce, false));
119 assertEquals("Á",HTMLUtils.entityFor("\u00C1".charAt(0),false, ce, true));
120 System.err.println("\u00C1".charAt(0));
121 System.err.println(new Integer("\u00C1".charAt(0)));
122 System.err.println(new Integer("?".charAt(0)));
123 System.err.println("Acirc=" +new Integer("Â".charAt(0)));
124 System.err.println(HTMLUtils.entityFor("Â".charAt(0),false, ce, true));
125 System.err.println(HTMLUtils.entityFor(it,false, ce, true));
126 System.err.println("");
127
128 }
129 /**
130 * Test method for {@link org.melati.util.HTMLUtils#entitied(java.lang.String, boolean, java.lang.String, boolean)}.
131 */
132 public void testEntitiedStringBooleanStringBoolean() {
133 dTest("ISO-8859-1");
134 dTest("UTF-8");
135 }
136 void dTest(String csName){
137 System.err.println(HTMLUtils.entitied("Â",false, csName, true));
138
139 }
140 /**
141 * Test method for {@link org.melati.util.HTMLUtils#entitied(java.lang.String)}.
142 */
143 public void testEntitiedString() {
144 }
145
146 /**
147 * Test method for {@link org.melati.util.HTMLUtils#jsEscapeFor(char)}.
148 */
149 public void testJsEscapeFor() {
150 }
151
152 /**
153 * Test method for {@link org.melati.util.HTMLUtils#jsEscaped(java.lang.String)}.
154 */
155 public void testJsEscaped() {
156 }
157
158 /**
159 * Test method for {@link org.melati.util.HTMLUtils#write(java.io.Writer, javax.swing.text.html.HTML.Tag, javax.swing.text.AttributeSet)}.
160 */
161 public void testWrite() {
162 }
163
164 /**
165 * Test method for {@link org.melati.util.HTMLUtils#stringOf(javax.swing.text.html.HTML.Tag, javax.swing.text.AttributeSet)}.
166 */
167 public void testStringOf() {
168 }
169
170 }