CVS Update: xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests
Aleksander Andrzej Slominski <[email protected]>
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
aslom 02/09/08 20:36:42
Modified: doc changes.html properties.html
src/java/tests/org/xmlpull/v1/tests TestMisc.java
TestSimpleProcessDocdecl.java
TestSimpleValidation.java UtilTestCase.java
XmlTestCase.java
Log:
added test for reporting XMLDecl properties
changed XmlTestCase strategy to load XML test files to
try first file, then resource property in build dir and finally resource in top level dir (jar or classpath)
Revision Changes Path
1.37 +3 -2 xmlpull-api-v1/doc/changes.html
Index: changes.html
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/doc/changes.html,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -t -w -r1.36 -r1.37
--- changes.html 2002/09/08 19:56:42 1.36
+++ changes.html 2002/09/09 01:36:41 1.37
@@ -26,7 +26,8 @@
and
<a href="http://xmlpull.org/v1/doc/features.html#xmldecl-content">XMLDECL CONTENT</a>.
-<li>TODO: changed tests to reflect changed handling of XMLDecl
+<li>changed tests to reflect changed handling of XMLDecl
+and added tests to check for optional XMLDecl properties
<li>more tests to check for CDATA end-of-line normalization
1.5 +1 -1 xmlpull-api-v1/doc/properties.html
Index: properties.html
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/doc/properties.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -t -w -r1.4 -r1.5
1.12 +68 -5 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestMisc.java
Index: TestMisc.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestMisc.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -t -w -r1.11 -r1.12
--- TestMisc.java 2002/08/23 19:11:51 1.11
+++ TestMisc.java 2002/09/09 01:36:41 1.12
@@ -196,6 +196,31 @@
pp.next();
pp.require( pp.END_TAG, null, "foo");
+ pp.setInput( new StringReader( "<foo><?XmL test?></foo>" ) );
+ pp.require( pp.START_DOCUMENT, null, null);
+ pp.next();
+ pp.require( pp.START_TAG, null, "foo");
+ try {
+ pp.next();
+ fail("expected exception for invalid PI starting with xml");
+ } catch(XmlPullParserException ex){}
+
+ pp.setInput( new StringReader( "<foo><?pi test?></foo>" ) );
+ pp.require( pp.START_DOCUMENT, null, null);
+ pp.next();
+ pp.require( pp.START_TAG, null, "foo");
+ pp.nextToken();
+ pp.require( pp.PROCESSING_INSTRUCTION, null, null);
+ assertEquals("PI", "pi test", pp.getText());
+ pp.next();
+ pp.require( pp.END_TAG, null, "foo");
+
+
+ }
+
+ public void testXmlDecl() throws Exception {
+ XmlPullParser pp = factory.newPullParser();
+
pp.setInput( new StringReader( "<?xml version='1.0'?><foo/>" ) );
pp.require( pp.START_DOCUMENT, null, null);
pp.next();
@@ -214,26 +239,64 @@
pp.setInput( new StringReader(
"<?xml version=\"1.0\" \t encoding='UTF-8' \nstandalone='yes' ?><foo/>" ));
pp.require( pp.START_DOCUMENT, null, null);
+ assertNull(pp.getProperty(PROPERTY_XMLDECL_VERSION));
+ assertNull(pp.getProperty(PROPERTY_XMLDECL_STANDALONE));
+ assertNull(pp.getProperty(PROPERTY_XMLDECL_CONTENT));
+
pp.next();
pp.require( pp.START_TAG, null, "foo");
+ String xmlDeclVersion = (String) pp.getProperty(PROPERTY_XMLDECL_VERSION);
+ if(xmlDeclVersion != null) {
+ assertEquals("XMLDecl version","1.0", xmlDeclVersion);
+ PackageTests.addNote("* property "+PROPERTY_XMLDECL_VERSION+" is supported\n");
+ }
+ Boolean xmlDeclStandalone = (Boolean) pp.getProperty(PROPERTY_XMLDECL_STANDALONE);
+ if(xmlDeclStandalone != null) {
+ assertTrue("XMLDecl standalone",xmlDeclStandalone.booleanValue());
+ PackageTests.addNote("* property "+PROPERTY_XMLDECL_STANDALONE+" is supported\n");
+ }
+ String xmlDeclContent = (String) pp.getProperty(PROPERTY_XMLDECL_CONTENT);
+ if(xmlDeclContent != null) {
+ String expected = " version=\"1.0\" \t encoding='UTF-8' \nstandalone='yes' ";
+ assertEquals("XMLDecl content", printable(expected), printable(xmlDeclContent));
+ PackageTests.addNote("* property "+PROPERTY_XMLDECL_CONTENT+" is supported\n");
+ }
+
// XML decl without required verion
pp.setInput( new StringReader( "<?xml test?><foo/>" ) );
pp.require( pp.START_DOCUMENT, null, null);
+
+ // check that proerties are reset
+ assertNull(pp.getProperty(PROPERTY_XMLDECL_VERSION));
+ assertNull(pp.getProperty(PROPERTY_XMLDECL_STANDALONE));
+ assertNull(pp.getProperty(PROPERTY_XMLDECL_CONTENT));
+
try {
pp.next();
- fail("expected exception for invalid XML declaration wiuthout verion");
+ fail("expected exception for invalid XML declaration without version");
} catch(XmlPullParserException ex){}
- pp.setInput( new StringReader( "<foo><?XmL test?></foo>" ) );
+ pp.setInput( new StringReader(
+ "<?xml version=\"1.0\" standalone='yes' encoding=\"UTF-8\" ?>\n<foo/>" ));
pp.require( pp.START_DOCUMENT, null, null);
- pp.next();
- pp.require( pp.START_TAG, null, "foo");
try {
pp.next();
- fail("expected exception for invalid PI starting with xml");
+ fail("expected exception for invalid XML declaration with standalone at wrong position");
} catch(XmlPullParserException ex){}
+
+
+ pp.setInput( new StringReader(
+ "<?xml version=\"1.0\" \t encoding='UTF-8' \nstandalone='yes' ?><foo/>" ));
+ pp.require( pp.START_DOCUMENT, null, null);
+ // make sure that XMLDecl is not reported
+ pp.nextToken();
+ pp.require( pp.START_TAG, null, "foo");
+ pp.next();
+ pp.require( pp.END_TAG, null, "foo");
+ pp.next();
+ pp.require( pp.END_DOCUMENT, null, null);
}
1.2 +10 -1 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleProcessDocdecl.java
Index: TestSimpleProcessDocdecl.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleProcessDocdecl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -t -w -r1.1 -r1.2
--- TestSimpleProcessDocdecl.java 2002/08/23 19:11:51 1.1
+++ TestSimpleProcessDocdecl.java 2002/09/09 01:36:41 1.2
@@ -54,7 +54,7 @@
//http://www.w3.org/TR/REC-xml#NT-extSubsetDecl
// minimum validation
final String XML_MIN_PROLOG =
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"+
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone='yes' ?>\n"+
"<!DOCTYPE greeting [\n"+
"<!ENTITY name \"world\">\n"+
"]>\n";
@@ -64,8 +64,17 @@
xpp.setInput(new StringReader( XML_MIN_VALID ));
checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
+ assertNull(xpp.getProperty(PROPERTY_XMLDECL_VERSION));
+ assertNull(xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
+ assertNull(xpp.getProperty(PROPERTY_XMLDECL_CONTENT));
+
xpp.next();
checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "greeting", null, false/*empty*/, 0);
+
+ //XMLDecl support is required when PROCESS DOCDECL enabled
+ assertEquals("1.0", xpp.getProperty(PROPERTY_XMLDECL_VERSION));
+ assertEquals(Boolean.TRUE, xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
+
xpp.next();
checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "Hello, world!", false, -1);
xpp.next();
1.2 +9 -0 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleValidation.java
Index: TestSimpleValidation.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleValidation.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -t -w -r1.1 -r1.2
--- TestSimpleValidation.java 2002/08/23 19:11:51 1.1
+++ TestSimpleValidation.java 2002/09/09 01:36:41 1.2
@@ -63,8 +63,17 @@
xpp.setInput(new StringReader( XML_MIN_VALID ));
checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
+ assertNull(xpp.getProperty(PROPERTY_XMLDECL_VERSION));
+ assertNull(xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
+ assertNull(xpp.getProperty(PROPERTY_XMLDECL_CONTENT));
+
xpp.next();
checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "greeting", null, false/*empty*/, 0);
+
+ //XMLDecl support is required when PROCESS DOCDECL enabled
+ assertEquals("1.0", xpp.getProperty(PROPERTY_XMLDECL_VERSION));
+ assertEquals(null, xpp.getProperty(PROPERTY_XMLDECL_STANDALONE));
+
xpp.next();
checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "Hello, world!", false, -1);
xpp.next();
1.18 +6 -0 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/UtilTestCase.java
Index: UtilTestCase.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/UtilTestCase.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -t -w -r1.17 -r1.18
--- UtilTestCase.java 2002/09/07 20:39:44 1.17
+++ UtilTestCase.java 2002/09/09 01:36:41 1.18
@@ -19,6 +19,12 @@
public class UtilTestCase extends TestCase {
protected static final String FEATURE_XML_ROUNDTRIP=
"http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
+ protected final static String PROPERTY_XMLDECL_VERSION =
+ "http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
+ protected final static String PROPERTY_XMLDECL_STANDALONE =
+ "http://xmlpull.org/v1/doc/features.html#xmldecl-standalone";
+ protected final static String PROPERTY_XMLDECL_CONTENT =
+ "http://xmlpull.org/v1/doc/features.html#xmldecl-content";
protected final static String TEST_XML =
1.6 +9 -9 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/XmlTestCase.java
Index: XmlTestCase.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/XmlTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -t -w -r1.5 -r1.6
--- XmlTestCase.java 2002/09/08 21:03:17 1.5
+++ XmlTestCase.java 2002/09/09 01:36:41 1.6
@@ -85,13 +85,13 @@
InputStream is = null;
if(is == null) {
try {
- is = getClass().getResourceAsStream (RESOURCE_PREFIX+name);
+ is = new FileInputStream(name);
} catch(Exception ex) {
}
}
-/* if(is == null) { // this seems to causes loading of simple.xml in the kxml samples dir
+ if(is == null) {
try {
- is = getClass().getResourceAsStream (name);
+ is = getClass().getResourceAsStream (RESOURCE_PREFIX+name);
} catch(Exception ex) {
}
}
@@ -100,13 +100,13 @@
is = getClass().getResourceAsStream ("/"+name);
} catch(Exception ex) {
}
- } */
- if(is == null) {
+ }
+ /*if(is == null) { // this seems to causes loading of simple.xml in the kxml samples dir
try {
- is = new FileInputStream(name);
+ is = getClass().getResourceAsStream (name);
} catch(Exception ex) {
- }
}
+ }*/
if (is == null) {