1
2
3
4
5 package org.w3c.tidy.servlet.util;
6
7 import java.util.HashMap;
8 import java.util.Map;
9
10 import junit.framework.TestCase;
11
12
13 /***
14 *
15 *
16 */
17 public class HTMLEncodeTest extends TestCase
18 {
19
20 public void validate(String expected, String input)
21 {
22 String r = HTMLEncode.encode(input);
23 assertEquals(expected, r);
24 }
25
26 public void testEncode() throws Exception
27 {
28 validate("", null);
29 validate(">", ">");
30 validate("<", "<");
31 validate("<>", "<>");
32 validate("<\n>", "<\n>");
33 validate("<EOL", "<EOL");
34 }
35
36 public void validateHREF(String expected, String[] input)
37 {
38 String r = HTMLEncode.encodeQuery("", input);
39 assertEquals(expected, r);
40 }
41
42 public void testEncodeHREF() throws Exception
43 {
44 validateHREF("", null);
45 validateHREF("?p1", new String[]{"p1"});
46 validateHREF("?p1=p1v", new String[]{"p1", "p1v"});
47 validateHREF("?p1=p1v&p2", new String[]{"p1", "p1v", "p2"});
48 }
49
50 public void validateHREFMap(String expected, Map input)
51 {
52 String r = HTMLEncode.encodeHREFQuery("", input, false);
53
54
55 assertEquals(expected, r);
56 }
57
58 public void testEncodeHREFMap() throws Exception
59 {
60 HashMap params = new HashMap();
61 params.put("np1", "vp1");
62 validateHREFMap("?np1=vp1", params);
63 params.put("np2", "vp2");
64 validateHREFMap("?np1=vp1&np2=vp2", params);
65 }
66 }