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 TestSimpleProcessDocdecl extends UtilTestCase { 23 private XmlPullParserFactory factory; 24 25 public static void main (String [] args) { 26 junit.textui.TestRunner.run (new TestSuite(TestSimpleProcessDocdecl.class)); 27 } 28 29 30 public TestSimpleProcessDocdecl(String name) { 31 super(name); 32 } 33 34 protected void setUp() throws XmlPullParserException { 35 factory = factoryNewInstance(); 36 assertEquals(false, factory.isNamespaceAware()); 37 assertEquals(false, factory.isValidating()); 38 } 40 41 public void testProcessDocdecl() throws Exception { 42 XmlPullParser xpp = factory.newPullParser(); 43 try { 44 xpp.setFeature(xpp.FEATURE_PROCESS_DOCDECL, true); 45 } catch(XmlPullParserException ex) { 46 return; 47 } 48 PackageTests.addNote("* feature "+xpp.FEATURE_PROCESS_DOCDECL+" is supported\n"); 49 assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL)); 51 assertEquals(false, xpp.getFeature(XmlPullParser.FEATURE_VALIDATION)); 53 54 final String XML_MIN_PROLOG = 57 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone='yes' ?>\n"+ 58 "<!DOCTYPE greeting [\n"+ 59 "<!ENTITY name \"world\">\n"+ 60 "]>\n"; 61 62 final String XML_MIN_VALID = XML_MIN_PROLOG+ 63 "<greeting>Hello, &name;!</greeting>\n"; 64 65 xpp.setInput(new StringReader ( XML_MIN_VALID )); 66 checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1); 67 assertNull(xpp.getProperty(PROPERTY_XMLDECL_VERSION)); 68 assertNull(xpp.getProperty(PROPERTY_XMLDECL_STANDALONE)); 69 assertNull(xpp.getProperty(PROPERTY_XMLDECL_CONTENT)); 70 71 xpp.next(); 72 checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "greeting", null, false, 0); 73 74 assertEquals("1.0", xpp.getProperty(PROPERTY_XMLDECL_VERSION)); 76 assertEquals(Boolean.TRUE, xpp.getProperty(PROPERTY_XMLDECL_STANDALONE)); 77 78 xpp.next(); 79 checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "Hello, world!", false, -1); 80 xpp.next(); 81 checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "greeting", null, false, -1); 82 xpp.next(); 83 checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1); 84 85 86 87 final String XML_MIN_INVALID = XML_MIN_PROLOG+ 89 "<greet>Hello, &world;!</greet>\n"; 90 xpp.setInput(new StringReader ( XML_MIN_INVALID )); 91 checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1); 92 xpp.next(); 93 checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "greet", null, false, 0); 94 try { 95 xpp.next(); 96 fail("exception was expected of next() for undeclared entity"); 97 } catch(XmlPullParserException ex) {} 98 99 } 100 101 } 102 103 | Popular Tags |