CVS Update: xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests
Aleksander Andrzej Slominski <[email protected]> Mon, 12 Jan 2004 11:20:59 -0500 (EST)
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
aslom 04/01/12 11:20:59
Modified: doc changes.html
src/java/samples XmlPullCount.java
src/java/tests/org/xmlpull/v1/tests PackageTests.java
TestCdsect.java TestMisc.java
TestSerializeWithNs.java
Log:
* added test to check that workaround from issue
"unable to select prefix to use when writing startTag, endTag and attribute" (bug 169) is tested
* updated unit test to check for disallowed "]]>" in character content,
* more tests for CDSECT
Revision Changes Path
1.50 +9 -4 xmlpull-api-v1/doc/changes.html
Index: changes.html
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/doc/changes.html,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -t -w -r1.49 -r1.50
--- changes.html 30 Jul 2003 17:10:18 -0000 1.49
+++ changes.html 12 Jan 2004 16:20:59 -0000 1.50
@@ -9,23 +9,28 @@
<H1>Changes to XmlPull v1 API</H1><P>
-<h3>IN PROGRESS: <a name="XMLPULL_1_2_1"></a>2003-06-... (XMLPULL_1_2_1)</h3>
+<h3>IN PROGRESS: <a name="XMLPULL_1_2_1"></a>2004-02-... (XMLPULL_1_2_1)</h3>
<ul>
<li>this will be next official stable release (based on last of 1.1.x) to
incorporate all changes since 1.0.x in stable version </ul>
<h3>IN PROGRESS INTERIM RELEASE: </h3>
-<h3><a name="XMLPULL_1_1_3_*"></a>2003-08- (XMLPULL_1_1_3_*)</h3>
+<h3><a name="XMLPULL_1_1_3_*"></a>2004-01- (XMLPULL_1_1_3_*)</h3>
<ul>
+<li>added test to check that workaround from issue "unable to select prefix to
+use when writing startTag, endTag, and attribute" " (<a href="http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=169">bug
+169</a>) is tested</li>
+<li>updated unit test to check for disallowed "]]>" in character content, more
+tests for CDSECT</li>
<li>changed DOM2 builder addon to be completely stateless factory
-and made factory contructor empty
+and made factory constructor empty
</li>
<li>improved DOM2 builder addon to allow building DOM tree from only part of
XML pull even stream and still have all namespaces declared
</li>
<li>IN PROGRESS (currently code is commented out):
-added methods to wrapper to encapsulate need ot read some of XSD simple types
+added methods to wrapper to encapsulate need to read some of XSD simple types
(partially based on <a href="http://jibx.sourceforge.net/">JiBX</a>)
</li>
</ul>
1.5 +8 -4 xmlpull-api-v1/src/java/samples/XmlPullCount.java
Index: XmlPullCount.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/samples/XmlPullCount.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -t -w -r1.4 -r1.5
--- XmlPullCount.java 30 Jul 2003 17:07:04 -0000 1.4
+++ XmlPullCount.java 12 Jan 2004 16:20:59 -0000 1.5
@@ -9,6 +9,7 @@
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
+import java.io.FileInputStream;
/**
* Simple example that counts XML elements, characters and attributes.
@@ -39,7 +40,7 @@
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
- factory.setNamespaceAware(true);
+ factory.setNamespaceAware(false);
System.err.println("using factory "+factory.getClass());
XmlPullParser xpp = factory.newPullParser();
@@ -47,7 +48,7 @@
XmlPullCount app = new XmlPullCount();
- app.verbose = false;
+ app.verbose = true;
for(int c = 0; c < 2; ++c) {
System.err.println("run#"+c);
app.resetCounters();
@@ -60,7 +61,8 @@
File f = new File(args[0]);
System.err.println("Parsing file: "+args[0]+" length="+f.length());
- xpp.setInput ( new FileReader ( args [0] ) );
+ //xpp.setInput ( new FileReader ( args [0] ) );
+ xpp.setInput ( new FileInputStream ( args [0] ), "UTF8" );
app.countXml(xpp);
//
}
@@ -104,8 +106,10 @@
if(verbose) {
System.err.println("TEXT '"+printable(xpp.getText())+"'");
}
- } else if(verbose && eventType == XmlPullParser.TEXT) {
+ } else if(eventType == XmlPullParser.END_TAG) {
+ if(verbose) {
System.err.println("END_TAG "+xpp.getName());
+ }
}
eventType = xpp.next();
}
1.18 +6 -6 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/PackageTests.java
Index: PackageTests.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/PackageTests.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -t -w -r1.17 -r1.18
--- PackageTests.java 9 Mar 2003 08:23:57 -0000 1.17
+++ PackageTests.java 12 Jan 2004 16:20:59 -0000 1.18
@@ -163,8 +163,8 @@
driver.setPrinter(resultPrinter);
final String listOfTests = System.getProperty("org.xmlpull.v1.tests");
- final String name = XmlPullParserFactory.PROPERTY_NAME;
- final String oldValue = System.getProperty(name);
+ final String FACTORY_PROPERTY = XmlPullParserFactory.PROPERTY_NAME;
+ final String DEFAULT_FACTORY_PROPERTY = System.getProperty(FACTORY_PROPERTY);
runAll = true;
if(listOfTests != null) {
int pos = 0;
@@ -173,15 +173,15 @@
if (cut == -1) cut = listOfTests.length();
String testFactoryName = listOfTests.substring(pos, cut);
if("DEFAULT".equals(testFactoryName)) {
- if(oldValue != null) {
- System.setProperty(name, oldValue);
+ if(DEFAULT_FACTORY_PROPERTY != null) {
+ System.setProperty(FACTORY_PROPERTY, DEFAULT_FACTORY_PROPERTY);
} else {
// overcoming limitation of System.setProperty not allowing
// null or empty values (who knows how to unset property ?!)
- System.setProperty(name, "DEFAULT");
+ System.setProperty(FACTORY_PROPERTY, "DEFAULT");
}
} else {
- System.setProperty(name, testFactoryName);
+ System.setProperty(FACTORY_PROPERTY, testFactoryName);
}
driver.runPackageTests(testFactoryName);
pos = cut + 1;
1.4 +19 -0 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestCdsect.java
Index: TestCdsect.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestCdsect.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -t -w -r1.3 -r1.4
--- TestCdsect.java 30 Jul 2003 16:51:08 -0000 1.3
+++ TestCdsect.java 12 Jan 2004 16:20:59 -0000 1.4
@@ -95,6 +95,25 @@
checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
}
+ public void testCdsectSoleContent() throws Exception {
+ XmlPullParser xpp = factory.newPullParser();
+ assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
+
+ final String XML =
+ "<t><![CDATA[foo<![CDATA[ \r\n\r]]-->]]></t>";
+
+ xpp.setInput(new StringReader(XML));
+ checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
+ xpp.next();
+ checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, null, 0, "", "t", null, false/*empty*/, 0);
+ xpp.next();
+ //System.err.println(getClass()+" text="+printable(xpp.getText()));
+ checkParserStateNs(xpp, 1, XmlPullParser.TEXT, null, 0, null, null, "foo<![CDATA[ \n\n]]-->", false, -1);
+ xpp.next();
+ checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, null, 0, "", "t", null, false, -1);
+ xpp.next();
+ checkParserStateNs(xpp, 0, XmlPullParser.END_DOCUMENT, null, 0, null, null, null, false, -1);
+ }
}
1.21 +25 -1 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.20
retrieving revision 1.21
diff -u -b -t -w -r1.20 -r1.21
--- TestMisc.java 30 Jul 2003 16:51:08 -0000 1.20
+++ TestMisc.java 12 Jan 2004 16:20:59 -0000 1.21
@@ -34,6 +34,29 @@
protected void tearDown() {
}
+ public void testCharactersLegacy() throws Exception {
+ // [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
+ // SGML "legacy" in XML 1.0 as described in http://www.w3.org/TR/REC-xml#syntax
+ // that XML parsers are required to throw error if they encounter ']]>'
+ final String INPUT_XML = "<t> <test1>d] ]] > ]> fd</test1>\n<test2>]]> </test2>\n </t>";
+ XmlPullParser pp = factory.newPullParser();
+ pp.setInput( new StringReader( INPUT_XML ) );
+ pp.nextTag();
+ pp.require( XmlPullParser.START_TAG, null, "t");
+ pp.nextTag();
+ pp.require( XmlPullParser.START_TAG, null, "test1");
+ assertEquals( "d] ]] > ]> fd", pp.nextText() );
+ pp.require( XmlPullParser.END_TAG, null, "test1");
+
+ pp.nextTag();
+ pp.require( XmlPullParser.START_TAG, null, "test2");
+ try {
+ pp.nextText();
+ fail("if TEXT contains ]]> parser must fail");
+ } catch(XmlPullParserException ex) {}
+ }
+
+
public void testNextTag() throws Exception {
final String INPUT_XML = "<t> <test1>foo</test1>\n<test2> </test2>\n </t>";
XmlPullParser pp = factory.newPullParser();
@@ -57,6 +80,7 @@
pp.require( XmlPullParser.END_DOCUMENT, null, null);
}
+
// public void testReadText() throws Exception {
// final String INPUT_XML = "<test>foo</test>";
1.18 +285 -219 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSerializeWithNs.java
Index: TestSerializeWithNs.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSerializeWithNs.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -t -w -r1.17 -r1.18
--- TestSerializeWithNs.java 19 May 2003 14:43:04 -0000 1.17
+++ TestSerializeWithNs.java 12 Jan 2004 16:20:59 -0000 1.18
@@ -669,7 +669,7 @@
testSetPrefix(null);
}
- //setPrefix check that prefix is not duplicated ...
+ /** setPrefix check that prefix is not duplicated ... */
public void testSetPrefixAdv() throws Exception {
//TODO check redeclaring defult namespace
@@ -702,6 +702,72 @@
checkTestSetPrefixSoap(s, true);
}
+ /** check that ti is possible to select which prefix should be used for namespace
+ * For more details check http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=169
+ */
+ public void testSetPrefixPreferences() throws Exception {
+ testSetPrefixPreferences("", null);
+ testSetPrefixPreferences("saml", "saml");
+
+ // check case when prefix in Infoset is invalid -- prefix preoprty is optional after all
+ // http://www.w3.org/TR/xml-infoset/#infoitem.element
+ testSetPrefixPreferences("sample", "saml");
+
+ testSetPrefixPreferences("", null);
+ testSetPrefixPreferences("saml", "saml");
+
+ }
+
+ private void testSetPrefixPreferences(String preferredPrefix, String expectedPrefix) throws Exception {
+
+ XmlSerializer ser = factory.newSerializer();
+ StringWriter sw = new StringWriter();
+ ser.setOutput(sw);
+ //<Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion"
+ final String NS = "urn:oasis:names:tc:SAML:1.0:assertion";
+ boolean deferred = false;
+ if("".equals(preferredPrefix)) {
+ deferred = true;
+ } else {
+ ser.setPrefix("", NS);
+ }
+ if("saml".equals(preferredPrefix)) {
+ deferred = true;
+ } else {
+ ser.setPrefix("saml", NS);
+
+ }
+ ser.setPrefix("samlp", "urn:oasis:names:tc:SAML:1.0:protocol");
+ if(deferred) {
+ ser.setPrefix(preferredPrefix, NS);
+ }
+ ser.startTag(NS, "Assertion");
+ boolean serAtt = !"".equals(preferredPrefix);
+ if(serAtt) {
+ ser.attribute(NS, "test", "1");
+ }
+ ser.endTag(NS, "Assertion");
+ ser.endDocument();
+
+ sw.close();
+ String serialized = sw.toString();
+ //System.out.println("\n"+getClass()+" sw="+sw);
+ xpp.setInput(new StringReader(serialized));
+
+ checkParserStateNs(xpp, 0, XmlPullParser.START_DOCUMENT, null, 0, null, null, null, false, -1);
+ xpp.next();
+ //String expectedPrefix = (prefix2 != null && prefix2.length() == 0) ? null : prefix2;
+ checkParserStateNs(xpp, 1, XmlPullParser.START_TAG, expectedPrefix, 3,
+ NS, "Assertion", null, xpp.isEmptyElementTag() /*empty*/, serAtt ? 1 : 0);
+ if(serAtt) {
+ assertEquals(expectedPrefix, xpp.getAttributePrefix(0)); //NS, "test
+ }
+ xpp.next();
+ checkParserStateNs(xpp, 1, XmlPullParser.END_TAG, expectedPrefix, 3,
+ NS, "Assertion", null, false, -1);
+
+ }
+
private void checkTestSetPrefixSoap(String soapEnvelope) throws Exception {
checkTestSetPrefixSoap(soapEnvelope, 0, false);
}
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/xmlpull-dev/
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/