1 2 4 package org.xmlpull.v1.tests; 5 6 import junit.framework.TestSuite; 9 10 import java.io.StringReader ; 11 12 import org.xmlpull.v1.XmlPullParser; 13 import org.xmlpull.v1.XmlPullParserFactory; 14 import org.xmlpull.v1.XmlPullParserException; 15 16 21 public class TestBootstrapXmlTests extends UtilTestCase { 22 private XmlPullParserFactory factory; 23 24 25 public static void main (String [] args) { 26 junit.textui.TestRunner.run (new TestSuite(TestBootstrapXmlTests.class)); 27 } 28 29 30 public TestBootstrapXmlTests(String name) { 31 super(name); 32 } 33 34 protected void setUp() throws XmlPullParserException { 35 factory = factoryNewInstance(); 36 factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); 37 assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES)); 38 } 39 40 protected void tearDown() { 41 } 42 43 final String TEST_NS = "http://xmlpull.org/v1/tests/2002-08.xsd"; 44 45 final String MINI_TEST_XML = 46 "<tests xmlns=\""+TEST_NS+"\">\n"+ 47 " <test-parser name=\"initial test\">\r"+ 48 " <create-parser/> <input-inline>"+ 49 "<foo/> "+ 50 "</input-inline>\n"+ 51 " <next/><expect type=\"START_TAG\" namespace=\"\" name=\"foo\" empty=\"false\"/>\n"+ 52 " <next/><expect type=\"END_TAG\"/>"+ 53 " <next/><expect type=\"END_DOCUMENT\"/>"+ 54 " </test-parser>"+ 55 "</tests>\n \n" 56 ; 57 58 public void testMini() throws Exception { 59 XmlPullParser pp = factory.newPullParser(); 60 pp.setInput( new StringReader ( MINI_TEST_XML ) ); 61 pp.next(); 62 pp.require( pp.START_TAG, TEST_NS, "tests"); 63 pp.next(); 64 pp.require( pp.TEXT, null, null); 65 String text = pp.getText(); 66 assertEquals("\n ", text); 67 pp.next(); 68 pp.require( pp.START_TAG, TEST_NS, "test-parser"); 69 71 pp.nextTag(); 72 pp.require( pp.START_TAG, TEST_NS, "create-parser"); 73 pp.nextTag(); 74 pp.require( pp.END_TAG, TEST_NS, "create-parser"); 75 76 77 pp.nextTag(); 78 pp.require( pp.START_TAG, TEST_NS, "input-inline"); 79 text = ""; 80 if(pp.next() == pp.TEXT) { 81 text = pp.getText(); 82 pp.next(); 83 } 84 assertEquals("<foo/> ", text); 85 pp.require( pp.END_TAG, TEST_NS, "input-inline"); 86 87 pp.nextTag(); 88 pp.require( pp.START_TAG, TEST_NS, "next"); 89 pp.nextTag(); 90 pp.require( pp.END_TAG, TEST_NS, "next"); 91 92 pp.nextTag(); 93 pp.require( pp.START_TAG, TEST_NS, "expect"); 94 pp.nextTag(); 95 pp.require( pp.END_TAG, TEST_NS, "expect"); 96 97 pp.nextTag(); 98 pp.require( pp.START_TAG, TEST_NS, "next"); 99 pp.nextTag(); 100 pp.require( pp.END_TAG, TEST_NS, "next"); 101 102 pp.nextTag(); 103 pp.require( pp.START_TAG, TEST_NS, "expect"); 104 pp.nextTag(); 105 pp.require( pp.END_TAG, TEST_NS, "expect"); 106 107 pp.nextTag(); 108 pp.require( pp.START_TAG, TEST_NS, "next"); 109 pp.nextTag(); 110 pp.require( pp.END_TAG, TEST_NS, "next"); 111 112 pp.nextTag(); 113 pp.require( pp.START_TAG, TEST_NS, "expect"); 114 pp.nextTag(); 115 pp.require( pp.END_TAG, TEST_NS, "expect"); 116 117 pp.nextTag(); 118 pp.require( pp.END_TAG, TEST_NS, "test-parser"); 119 120 pp.nextTag(); 121 pp.require( pp.END_TAG, TEST_NS, "tests"); 122 123 pp.next(); 124 pp.require( pp.END_DOCUMENT, null, null); 125 126 } 127 128 129 final String TYPICAL_TEST_XML = 130 "<tests xmlns=\""+TEST_NS+"\">\n"+ 131 " <test-parser name=\"initial test\">\r"+ 132 " <create-parser/> <input-inline>"+ 133 "<foo att="t" att2='a' ><![CDATA[ bar&baz ]]>&</foo>"+ 134 "</input-inline>\r\n"+ 136 " <set-feature>http://xmlpull.org/v1/doc/features.html#process-namespaces</set-feature>\r\n"+ 137 " <expect type=\"START_DOCUMENT\"/>\n"+ 138 " <next/><expect type=\"START_TAG\" namespace=\"\" name=\"foo\" empty=\"false\"/>\n"+ 139 " <next-text text=\"bar\"/>"+ 140 " <next/><expect type=\"END_DOCUMENT\"/>"+ 141 " </test-parser>"+ 142 "</tests>\n \n" 143 ; 144 public void testTypical() throws Exception { 145 XmlPullParser pp = factory.newPullParser(); 146 pp.setInput( new StringReader ( TYPICAL_TEST_XML ) ); 147 pp.next(); 148 pp.require( pp.START_TAG, TEST_NS, "tests"); 149 pp.next(); 150 pp.require( pp.TEXT, null, null); 151 String text = pp.getText(); 152 assertEquals("\n ", text); 153 pp.next(); 154 pp.require( pp.START_TAG, TEST_NS, "test-parser"); 155 157 pp.nextTag(); 158 pp.require( pp.START_TAG, TEST_NS, "create-parser"); 159 pp.nextTag(); 160 pp.require( pp.END_TAG, TEST_NS, "create-parser"); 161 162 163 pp.nextTag(); 164 pp.require( pp.START_TAG, TEST_NS, "input-inline"); 165 text = ""; 166 if(pp.next() == pp.TEXT) { 167 text = pp.getText(); 168 pp.next(); 169 } 170 assertEquals("<foo att=\"t\" att2='a' > bar&baz &</foo>", text); 171 pp.require( pp.END_TAG, TEST_NS, "input-inline"); 172 173 pp.nextTag(); 174 pp.require( pp.START_TAG, TEST_NS, "set-feature"); 175 text = pp.nextText(); 176 assertEquals("http://xmlpull.org/v1/doc/features.html#process-namespaces", text); 177 pp.require( pp.END_TAG, TEST_NS, "set-feature"); 178 179 pp.nextTag(); 180 pp.require( pp.START_TAG, TEST_NS, "expect"); 181 pp.nextTag(); 182 pp.require( pp.END_TAG, TEST_NS, "expect"); 183 184 pp.nextTag(); 185 pp.require( pp.START_TAG, TEST_NS, "next"); 186 pp.nextTag(); 187 pp.require( pp.END_TAG, TEST_NS, "next"); 188 189 pp.nextTag(); 190 pp.require( pp.START_TAG, TEST_NS, "expect"); 191 pp.nextTag(); 192 pp.require( pp.END_TAG, TEST_NS, "expect"); 193 194 pp.nextTag(); 195 pp.require( pp.START_TAG, TEST_NS, "next-text"); 196 pp.nextTag(); 197 pp.require( pp.END_TAG, TEST_NS, "next-text"); 198 199 pp.nextTag(); 200 pp.require( pp.START_TAG, TEST_NS, "next"); 201 pp.nextTag(); 202 pp.require( pp.END_TAG, TEST_NS, "next"); 203 204 pp.nextTag(); 205 pp.require( pp.START_TAG, TEST_NS, "expect"); 206 pp.nextTag(); 207 pp.require( pp.END_TAG, TEST_NS, "expect"); 208 209 pp.nextTag(); 210 pp.require( pp.END_TAG, TEST_NS, "test-parser"); 211 212 pp.nextTag(); 213 pp.require( pp.END_TAG, TEST_NS, "tests"); 214 215 pp.next(); 216 pp.require( pp.END_DOCUMENT, null, null); 217 218 } 219 220 221 } 222 223 | Popular Tags |