CVS Update: xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests
Aleksander Andrzej Slominski <[email protected]> Sun, 9 Mar 2003 03:23:58 -0500 (EST)
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
aslom 03/03/09 03:23:58
Modified: src/java/tests/org/xmlpull/v1/tests PackageTests.java
TestMisc.java TestSerializeWithNs.java
TestSetInput.java TestToken.java
Log:
updated tests to look for edge cases with PI/comments and next() (thanks to Henry Minsky)
marked all supported optional features and properties as such in unit tests summary
Revision Changes Path
1.17 +30 -17 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.16
retrieving revision 1.17
diff -u -b -t -w -r1.16 -r1.17
--- PackageTests.java 25 Feb 2003 20:08:12 -0000 1.16
+++ PackageTests.java 9 Mar 2003 08:23:57 -0000 1.17
@@ -6,6 +6,7 @@
import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
+import junit.textui.ResultPrinter;
import junit.textui.TestRunner;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
@@ -19,19 +20,16 @@
*
* @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
*/
-public class PackageTests extends TestRunner
-{
+public class PackageTests extends TestRunner {
private static boolean runAll;
public static boolean runnigAllTests() { return runAll; }
- public PackageTests()
- {
+ public PackageTests() {
super();
}
- public static Test suite()
- {
+ public static Test suite() {
TestSuite suite = new TestSuite("XmlPull V1 API TESTS");
suite.addTestSuite(TestFactory.class);
@@ -62,14 +60,23 @@
return suite;
}
- public synchronized void startTest(Test test) {
- writer().print(".");
- //if (fColumn++ >= 40) {
- // writer().println();
- // fColumn= 0;
+ public synchronized void tick() {
+ //if(resultPrinter != null) {
+ // resultPrinter.startTest(null);
+ //} else {
+ System.err.print(".");
//}
}
+ // public synchronized void startTest(Test test) {
+ // writer()
+ // System.err.print(".");
+ // //if (fColumn++ >= 40) {
+ // // writer().println();
+ // // fColumn= 0;
+ // //}
+ // }
+
private static StringBuffer notes = new StringBuffer();
public static void addNote(String note) {
if(PackageTests.runnigAllTests() == false) {
@@ -81,7 +88,8 @@
public void runPackageTests(String testFactoryName) {
- writer().println("Executing XMLPULL tests"
+ //writer()
+ System.err.println("Executing XmlPull API tests"
+(testFactoryName != null ? " for '"+testFactoryName+"'" : ""));
notes.setLength(0);
XmlPullParserFactory f = null;
@@ -137,18 +145,23 @@
}
if(notes.length() > 0) {
- writer().println("Test results "
+ //writer().
+ System.err.println("Test results "
+(testFactoryName != null ? "for '"+testFactoryName+"'" : "")
+"\n"+notes+"\n");
}
}
public void printFinalReport() {
- writer().println("\nAll tests were passed.");
+ //writer()
+ System.err.println("\nAll tests were passed.");
}
public static void main (String[] args) {
final PackageTests driver = new PackageTests();
+ final ResultPrinter resultPrinter = new ResultPrinter(System.err);
+ driver.setPrinter(resultPrinter);
+
final String listOfTests = System.getProperty("org.xmlpull.v1.tests");
final String name = XmlPullParserFactory.PROPERTY_NAME;
final String oldValue = System.getProperty(name);
1.16 +61 -38 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.15
retrieving revision 1.16
diff -u -b -t -w -r1.15 -r1.16
--- TestMisc.java 12 Oct 2002 22:17:59 -0000 1.15
+++ TestMisc.java 9 Mar 2003 08:23:57 -0000 1.16
@@ -185,39 +185,6 @@
}
- public void testPI() throws Exception {
- XmlPullParser pp = factory.newPullParser();
- //System.out.println(getClass()+"-pp="+pp);
-
- pp.setInput( new StringReader( "<foo><?XmLsdsd test?></foo>" ) );
- pp.require( pp.START_DOCUMENT, null, null);
- pp.next();
- pp.require( pp.START_TAG, null, "foo");
- 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();
@@ -248,18 +215,18 @@
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");
+ PackageTests.addNote("* optional 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");
+ PackageTests.addNote("* optional 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");
+ PackageTests.addNote("* optional property "+PROPERTY_XMLDECL_CONTENT+" is supported\n");
}
@@ -313,8 +280,64 @@
pp.next();
fail("expected eception for invalid comment ending with --->");
} catch(XmlPullParserException ex){}
+ testContentMerging(pp, "<foo><!-- this is a comment --></foo>", null);
+ testContentMerging(pp, "<foo>\n<!-- this is a comment -->\n</foo>", "\n\n");
+ testContentMerging(pp, "<foo><!-- this is a comment -->\n</foo>", "\n");
+ }
+
+ public void testContentMerging(final XmlPullParser pp, final String xml, final String expected)
+ throws Exception {
+ pp.setInput( new StringReader( xml ) );
+ pp.next();
+ pp.require( pp.START_TAG, null, "foo");
+ if(expected != null) {
+ pp.next();
+ pp.require( pp.TEXT, null, null);
+ assertEquals(printable(expected), printable(pp.getText()));
+ assertEquals(expected, pp.getText());
+ }
+ pp.next();
+ pp.require( pp.END_TAG, null, "foo");
+ }
+
+
+ public void testPI() throws Exception {
+ XmlPullParser pp = factory.newPullParser();
+ //System.out.println(getClass()+"-pp="+pp);
+
+ pp.setInput( new StringReader( "<foo><?XmLsdsd test?></foo>" ) );
+ pp.require( pp.START_DOCUMENT, null, null);
+ pp.next();
+ pp.require( pp.START_TAG, null, "foo");
+ 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");
+
+ testContentMerging(pp, "<foo><? this is PI ?></foo>", null);
+ testContentMerging(pp, "<foo>\n<? this is PI ?>\n</foo>", "\n\n");
+ testContentMerging(pp, "<foo><? this is PI ?>\n</foo>", "\n");
+
}
+
public void testReportNamespaceAttributes() throws Exception {
XmlPullParser pp = factory.newPullParser();
assertEquals(true, pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
@@ -322,10 +345,10 @@
try {
pp.setFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES, true);
}catch(XmlPullParserException ex) {
- // skip rest of test if parser does nto support reporting
+ // skip rest of test if parser does not support reporting
return;
}
- PackageTests.addNote("* feature "+pp.FEATURE_REPORT_NAMESPACE_ATTRIBUTES+" is supported\n");
+ PackageTests.addNote("* optional feature "+pp.FEATURE_REPORT_NAMESPACE_ATTRIBUTES+" is supported\n");
// see XML Namespaces spec for namespace URIs for 'xml' and 'xmlns'
// xml is bound to http://www.w3.org/XML/1998/namespace
// "(...) The prefix xmlns is used only for namespace bindings
1.15 +5 -6 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.14
retrieving revision 1.15
diff -u -b -t -w -r1.14 -r1.15
--- TestSerializeWithNs.java 26 Feb 2003 04:13:06 -0000 1.14
+++ TestSerializeWithNs.java 9 Mar 2003 08:23:57 -0000 1.15
@@ -141,7 +141,7 @@
public void testNamespaceGeneration() throws Exception {
XmlSerializer ser = factory.newSerializer();
- System.out.println(getClass()+" ser="+ser);
+ //System.out.println(getClass()+" ser="+ser);
StringWriter sw = new StringWriter();
ser.setOutput(sw);
@@ -176,7 +176,7 @@
//xpp.setInput(new StringReader("<foo></foo>"));
String serialized = sw.toString();
- System.out.println(getClass()+" serialized="+serialized);
+ //System.out.println(getClass()+" serialized="+serialized);
//xpp.setInput(new StringReader(serialized));
}
@@ -369,8 +369,7 @@
// ignore test if optional property not supported
return;
}
- PackageTests.addNote(
- "* feature "+FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE+" is supported\n");
+ PackageTests.addNote("* optional feature "+FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE+" is supported\n");
boolean useApost = ser.getFeature(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE);
assertEquals(true, useApost);
@@ -462,7 +461,7 @@
// ignore test if optional property not supported
return;
}
- PackageTests.addNote("* property "+PROPERTY_SERIALIZER_INDENTATION+" is supported\n");
+ PackageTests.addNote("* optional property "+PROPERTY_SERIALIZER_INDENTATION+" is supported\n");
StringWriter sw = new StringWriter();
ser.setOutput(sw);
@@ -549,7 +548,7 @@
// ignore test if optional property not supported
return;
}
- PackageTests.addNote("* property "+PROPERTY_SERIALIZER_LINE_SEPARATOR+" is supported\n");
+ PackageTests.addNote("* optional property "+PROPERTY_SERIALIZER_LINE_SEPARATOR+" is supported\n");
}
/** generate SOAP 1.2 envelope
1.6 +24 -24 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSetInput.java
Index: TestSetInput.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSetInput.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -t -w -r1.5 -r1.6
--- TestSetInput.java 19 Sep 2002 23:33:13 -0000 1.5
+++ TestSetInput.java 9 Mar 2003 08:23:57 -0000 1.6
@@ -113,7 +113,7 @@
"http://xmlpull.org/v1/doc/features.html#detect-encoding";
if(xpp.getFeature(FEATURE_DETECT_ENCODING)) {
- PackageTests.addNote("* feature "+FEATURE_DETECT_ENCODING+" is supported\n");
+ PackageTests.addNote("* optional feature "+FEATURE_DETECT_ENCODING+" is supported\n");
isw = new InputStreamWrapper(
new ByteArrayInputStream( binput ));
1.16 +1 -1 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestToken.java
Index: TestToken.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestToken.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -t -w -r1.15 -r1.16
--- TestToken.java 19 Sep 2002 23:33:13 -0000 1.15
+++ TestToken.java 9 Mar 2003 08:23:57 -0000 1.16
@@ -367,7 +367,7 @@
if(!roundtripSupported) {
return;
}
- PackageTests.addNote("* feature "+FEATURE_XML_ROUNDTRIP+" is supported\n");
+ PackageTests.addNote("* optional feature "+FEATURE_XML_ROUNDTRIP+" is supported\n");
StringWriter sw = new StringWriter();
String s;
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/xaxhjB/hdqFAA/xGHJAA/2U_rlB/TM
---------------------------------------------------------------------~->
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/