1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.feedparser.test; |
18 | |
|
19 | |
import java.io.FileInputStream; |
20 | |
|
21 | |
import javax.xml.parsers.DocumentBuilder; |
22 | |
import javax.xml.parsers.DocumentBuilderFactory; |
23 | |
|
24 | |
import junit.framework.TestCase; |
25 | |
|
26 | |
import org.apache.commons.feedparser.FeedParser; |
27 | |
import org.apache.commons.feedparser.FeedParserFactory; |
28 | |
import org.apache.commons.feedparser.FeedParserListener; |
29 | |
import org.apache.commons.feedparser.impl.DebugFeedParserListener; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class TestFeedParserUTF8 extends TestCase { |
37 | |
|
38 | |
public TestFeedParserUTF8( String name ) throws Exception { |
39 | 0 | super( name ); |
40 | 0 | } |
41 | |
|
42 | |
public void testAssertXerces() throws Exception { |
43 | |
|
44 | |
String v; |
45 | |
|
46 | 0 | DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
47 | |
|
48 | 0 | v = db.getClass().getName(); |
49 | |
|
50 | 0 | if ( ! v.equals( "org.apache.xerces.jaxp.DocumentBuilderImpl" ) ) |
51 | 0 | throw new Exception( "Incorrect version of Xerces: " + v ); |
52 | |
|
53 | 0 | v = org.apache.xerces.impl.Version.fVersion; |
54 | |
|
55 | 0 | if ( v.indexOf( "2.6" ) == -1 ) |
56 | 0 | throw new Exception( "Incorrect version of Xerces: " + v); |
57 | |
|
58 | 0 | } |
59 | |
|
60 | |
public void test( String path ) throws Exception { |
61 | |
|
62 | 0 | FeedParser parser = FeedParserFactory.newFeedParser(); |
63 | |
|
64 | 0 | FeedParserListener listener = new DebugFeedParserListener(); |
65 | |
|
66 | 0 | parser.parse( listener, |
67 | |
new FileInputStream( "src/java/org/apache/commons/feedparser/test/" + path), |
68 | |
path ); |
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
public void test1() throws Exception { |
73 | |
|
74 | 0 | test( "TestFeedParserUTF8.rss" ); |
75 | |
|
76 | 0 | } |
77 | |
|
78 | |
public void test2() throws Exception { |
79 | |
|
80 | 0 | test( "broken-UTF8-feed.rss" ); |
81 | 0 | } |
82 | |
|
83 | |
public void test3() throws Exception { |
84 | |
|
85 | 0 | test( "broken-Invalid-byte-2-of-3-byte-UTF-8-sequence.xml" ); |
86 | 0 | } |
87 | |
|
88 | |
public void test4() throws Exception { |
89 | |
|
90 | 0 | test( "broken-salon.rdf" ); |
91 | 0 | } |
92 | |
|
93 | |
public static void main( String[] args ) throws Exception { |
94 | |
|
95 | 0 | TestFeedParserUTF8 test = new TestFeedParserUTF8( null ); |
96 | |
|
97 | |
|
98 | |
|
99 | 0 | test.test2(); |
100 | |
|
101 | 0 | } |
102 | |
|
103 | |
} |
104 | |
|