01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.util;
17:
18: import junit.framework.TestCase;
19:
20: import java.io.IOException;
21: import java.io.StringWriter;
22: import java.util.Random;
23: import java.util.BitSet;
24:
25: /** Test (some of the) character escaping functions of the XML class
26: * $Id$
27: */
28:
29: public class TestXMLEscaping extends TestCase {
30: private void doSimpleTest(String input, String expectedOutput)
31: throws IOException {
32: final StringWriter sw = new StringWriter();
33: XML.escapeCharData(input, sw);
34: final String result = sw.toString();
35: assertEquals("Escaped output matches '" + expectedOutput + "'",
36: result, expectedOutput);
37: }
38:
39: public void testNoEscape() throws IOException {
40: doSimpleTest("Bonnie", "Bonnie");
41: }
42:
43: public void testAmpAscii() throws IOException {
44: doSimpleTest("Bonnie & Clyde", "Bonnie & Clyde");
45: }
46:
47: public void testAmpAndTagAscii() throws IOException {
48: doSimpleTest("Bonnie & Cl<em>y</em>de",
49: "Bonnie & Cl<em>y</em>de");
50: }
51:
52: public void testAmpWithAccents() throws IOException {
53: // 00e9 is unicode eacute
54: doSimpleTest("Les \u00e9v\u00e9nements chez Bonnie & Clyde",
55: "Les \u00e9v\u00e9nements chez Bonnie & Clyde");
56: }
57:
58: public void testAmpDotWithAccents() throws IOException {
59: // 00e9 is unicode eacute
60: doSimpleTest("Les \u00e9v\u00e9nements chez Bonnie & Clyde.",
61: "Les \u00e9v\u00e9nements chez Bonnie & Clyde.");
62: }
63:
64: public void testAmpAndTagWithAccents() throws IOException {
65: // 00e9 is unicode eacute
66: doSimpleTest("Les \u00e9v\u00e9nements <chez/> Bonnie & Clyde",
67: "Les \u00e9v\u00e9nements <chez/> Bonnie & Clyde");
68: }
69:
70: public void testGt() throws IOException {
71: doSimpleTest("a ]]> b", "a ]]> b");
72: }
73: }
|