KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xmlpull > v1 > tests > TestCdsect


1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
2 // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
3

4 package org.xmlpull.v1.tests;
5
6 //import junit.framework.Test;
7
import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9
10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.io.StringReader JavaDoc;
12
13 import org.xmlpull.v1.XmlPullParser;
14 import org.xmlpull.v1.XmlPullParserFactory;
15 import org.xmlpull.v1.XmlPullParserException;
16
17 /**
18  * Simple test for CDATA parsing.
19  *
20  * @author <a HREF="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
21  */

22 public class TestCdsect extends UtilTestCase {
23     private XmlPullParserFactory factory;
24
25     public static void main (String JavaDoc[] args) {
26         junit.textui.TestRunner.run (new TestSuite(TestCdsect.class));
27     }
28
29     public TestCdsect(String JavaDoc name) {
30         super(name);
31     }
32
33     protected void setUp() throws XmlPullParserException {
34         factory = factoryNewInstance();
35         factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
36         assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
37     }
38
39     protected void tearDown() {
40     }
41
42
43     public void testCdsect() throws Exception JavaDoc {
44         XmlPullParser xpp = factory.newPullParser();
45         assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
46
47         final String JavaDoc XML =
48             "<t><![CDATA[ f]]>o<![CDATA[o ]]></t>";
49
50         xpp.setInput(new StringReader JavaDoc(XML));
51         checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
52         xpp.next();
53         checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
54         xpp.next();
55         checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, " foo ", false, -1);
56         xpp.next();
57         checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "t", null, false, -1);
58         xpp.next();
59         checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
60     }
61
62     public void testCdsectWithEol() throws Exception JavaDoc {
63         XmlPullParser xpp = factory.newPullParser();
64         assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
65
66         final String JavaDoc XML =
67             "<t> \n<![CDATA[fo]]>o<![CDATA[ \r\n\r]]>\n</t>";
68
69         xpp.setInput(new StringReader JavaDoc(XML));
70         checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
71         xpp.next();
72         checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
73         xpp.next();
74         checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, " \nfoo \n\n\n", false, -1);
75         xpp.next();
76         checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "t", null, false, -1);
77         xpp.next();
78         checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
79     }
80
81
82
83 }
84
85
Popular Tags