1 2 4 package org.xmlpull.v1.tests; 5 6 import junit.framework.TestCase; 8 import junit.framework.TestSuite; 9 10 import java.io.ByteArrayInputStream ; 11 import java.io.StringReader ; 12 13 import org.xmlpull.v1.XmlPullParser; 14 import org.xmlpull.v1.XmlPullParserFactory; 15 import org.xmlpull.v1.XmlPullParserException; 16 17 22 public class TestCdsect extends UtilTestCase { 23 private XmlPullParserFactory factory; 24 25 public static void main (String [] args) { 26 junit.textui.TestRunner.run (new TestSuite(TestCdsect.class)); 27 } 28 29 public TestCdsect(String 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 { 44 XmlPullParser xpp = factory.newPullParser(); 45 assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES)); 46 47 final String XML = 48 "<t><![CDATA[ f]]>o<![CDATA[o ]]></t>"; 49 50 xpp.setInput(new StringReader (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, 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 { 63 XmlPullParser xpp = factory.newPullParser(); 64 assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES)); 65 66 final String XML = 67 "<t> \n<![CDATA[fo]]>o<![CDATA[ \r\n\r]]>\n</t>"; 68 69 xpp.setInput(new StringReader (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, 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 |