1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.tika.sax;
18
19 import org.xml.sax.ContentHandler;
20 import org.xml.sax.SAXException;
21
22 import junit.framework.TestCase;
23
24
25
26
27 public class SafeContentHandlerTest extends TestCase {
28
29 private ContentHandler output;
30
31 private ContentHandler safe;
32
33 protected void setUp() {
34 output = new WriteOutContentHandler();
35 safe = new SafeContentHandler(output);
36 }
37
38 public void testEmptyInput() throws SAXException {
39 safe.characters(new char[0], 0, 0);
40 safe.ignorableWhitespace(new char[0], 0, 0);
41 assertEquals("", output.toString());
42 }
43
44 public void testNormalCharacters() throws SAXException {
45 safe.characters("abc".toCharArray(), 0, 3);
46 assertEquals("abc", output.toString());
47 }
48
49 public void testNormalWhitespace() throws SAXException {
50 safe.ignorableWhitespace("abc".toCharArray(), 0, 3);
51 assertEquals("abc", output.toString());
52 }
53
54 public void testInvalidCharacters() throws SAXException {
55 safe.characters("ab\u0007".toCharArray(), 0, 3);
56 safe.characters("a\u000Bc".toCharArray(), 0, 3);
57 safe.characters("\u0019bc".toCharArray(), 0, 3);
58 assertEquals("ab a c bc", output.toString());
59 }
60
61 public void testInvalidWhitespace() throws SAXException {
62 safe.ignorableWhitespace("ab\u0000".toCharArray(), 0, 3);
63 safe.ignorableWhitespace("a\u0001c".toCharArray(), 0, 3);
64 safe.ignorableWhitespace("\u0002bc".toCharArray(), 0, 3);
65 assertEquals("ab a c bc", output.toString());
66 }
67
68 }