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/08/01 13:18:57
Modified: doc features.html
src/java/tests/org/xmlpull/v1/tests TestSimpleToken.java
TestToken.java UtilTestCase.java
Log:
updated tests (may not work until normalized/rountrip feature are resolved)
Revision Changes Path
1.12 +3 -2 xmlpull-api-v1/doc/features.html
Index: features.html
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/doc/features.html,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -t -w -r1.11 -r1.12
--- features.html 2002/08/01 15:38:09 1.11
+++ features.html 2002/08/01 18:18:56 1.12
@@ -150,8 +150,9 @@
http://xmlpull.org/v1/doc/features.html#xml-roundtrip</a> </p>
<p>If set to true then XMLPULL parser <b>MUST</b> make available original XML
value for START_TAG and END_TAG events with getText() and getTextCharacters()
-functions and implicitly <a href="#unnormalized-xml">UNNORMALIZED XML</a>
-feature is set to true.<br>
+functions, also parse MUST return exact content of DOCTYPE for DOCDECL token and
+exact PI content for PROCESSING_INSTRUCTION token and implicitly <a href="#unnormalized-xml">UNNORMALIZED XML</a>
+feature is set to true and <b>MUST</b> be reported as true.<br>
</p>
<h3>
1.17 +24 -2 xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleToken.java
Index: TestSimpleToken.java
===================================================================
RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleToken.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -t -w -r1.16 -r1.17
--- TestSimpleToken.java 2002/08/01 04:45:36 1.16
+++ TestSimpleToken.java 2002/08/01 18:18:56 1.17
@@ -21,9 +21,8 @@
*/
public class TestSimpleToken extends UtilTestCase {
private XmlPullParserFactory factory;
- private static final String FEATURE_XML_ROUNDTRIP=
- "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
+
public static void main (String[] args) {
junit.textui.TestRunner.run (new TestSuite(TestSimpleToken.class));
}
@@ -110,5 +109,28 @@
}
}
+
+ public void testNormalization() throws Exception {
+ XmlPullParser xpp = factory.newPullParser();
+ assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
+ xpp.setInput(new StringReader("<foo>\n \r\n \n\r</foo>"));
+ checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
+ xpp.nextToken();
+ checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "foo", null, false/*empty*/, 0);
+
+ boolean normalized = xpp.getFeature(FEATURE_UNNORMALIZED_XML) == false;
+ String text = nextTokenGathered(xpp, XmlPullParser.TEXT, true);
+ if(normalized) {
+ assertEquals(printable("\n \n \n\n"), printable(text));
+ assertEquals("\n \n \n\n", text);
+ } else {
+ assertEquals(printable("\n \r\n \n\r"), printable(text));
+ assertEquals("\n \r\n \n\r", text);
+ }
+
+ checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "foo", null, false, -1);
+ xpp.nextToken();
+ checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
+ }
}
1.10 +34 -23 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.9
retrieving revision 1.10
diff -u -b -t -w -r1.9 -r1.10
--- TestToken.java 2002/08/01 04:45:36 1.9
+++ TestToken.java 2002/08/01 18:18:57 1.10
@@ -16,14 +16,12 @@
import org.xmlpull.v1.XmlPullParserException;
/**
- * Simple test ot verify pull parser factory
+ * Conformance test to verify nextToken() behavior.
*
* @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
*/
public class TestToken extends UtilTestCase {
private XmlPullParserFactory factory;
- private static final String FEATURE_XML_ROUNDTRIP=
- "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
public TestToken(String name) {
super(name);
@@ -118,6 +116,7 @@
}
// did we succeeded?
boolean roundtripSupported = xpp.getFeature(FEATURE_XML_ROUNDTRIP);
+ boolean unnormalizedSupported = xpp.getFeature(FEATURE_UNNORMALIZED_XML);
checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
try {
@@ -127,11 +126,14 @@
}
if(checkPrologAndEpilog) {
- if(roundtripSupported) {
- xpp.nextToken();
- checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null,
- "\n \r\n \n\r", false, -1);
- assertTrue(xpp.isWhitespace());
+ if(unnormalizedSupported) {
+ // xpp.nextToken();
+ // checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null,
+ // "\n \r\n \n\r", false, -1);
+ // assertTrue(xpp.isWhitespace());
+ String text = nextTokenGathered(xpp, xpp.IGNORABLE_WHITESPACE, true);
+ assertEquals(printable("\n \r\n \n\r"), printable(text));
+ assertEquals("\n \r\n \n\r", text);
}
xpp.nextToken();
@@ -142,16 +144,20 @@
} catch(XmlPullParserException ex) {
}
- if(roundtripSupported) {
+ if(unnormalizedSupported) {
+ // xpp.nextToken();
+ // checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null, " \r\n", false, -1);
+ // assertTrue(xpp.isWhitespace());
+ String text = nextTokenGathered(xpp, xpp.IGNORABLE_WHITESPACE, true);
+ assertEquals(printable(" \r\n"), printable(text));
+ } else {
xpp.nextToken();
- checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null, " \r\n", false, -1);
- assertTrue(xpp.isWhitespace());
}
- }
-
+ } else {
xpp.nextToken();
+ }
checkParserStateNs(xpp, 0, xpp.DOCDECL, null, 0, null, null,
(roundtripSupported ? " titlepage "+
//"SYSTEM \"http://www.foo.bar/dtds/typo.dtd\""+
@@ -177,11 +183,12 @@
} catch(XmlPullParserException ex) {
}
- xpp.nextToken();
- checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "bar", false, -1);
- assertEquals(false, xpp.isWhitespace());
+ {
+ String text = nextTokenGathered(xpp, xpp.TEXT, false);
+ assertEquals(printable("bar"), printable(text));
+ }
- xpp.nextToken();
+ //xpp.nextToken();
checkParserStateNs(xpp, 1, xpp.COMMENT, null, 0, null, null, "comment", false, -1);
try {
xpp.isWhitespace();
@@ -274,15 +281,19 @@
}
if(checkPrologAndEpilog) {
- if(roundtripSupported) {
+ if(unnormalizedSupported) {
+ // xpp.nextToken();
+ // checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null,
+ // " \r\n", false, -1);
+ // assertTrue(xpp.isWhitespace());
+ String text = nextTokenGathered(xpp, xpp.IGNORABLE_WHITESPACE, true);
+ assertEquals(printable("\r\n "), printable(text));
+ } else {
xpp.nextToken();
- checkParserStateNs(xpp, 0, xpp.IGNORABLE_WHITESPACE, null, 0, null, null,
- " \r\n", false, -1);
- assertTrue(xpp.isWhitespace());
}
- }
-
+ } else {
xpp.nextToken();
+ }
checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
try {
xpp.isWhitespace();
1.14 +72 -50 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.13
retrieving revision 1.14
diff -u -b -t -w -r1.13 -r1.14
--- UtilTestCase.java 2002/07/31 21:32:05 1.13
+++ UtilTestCase.java 2002/08/01 18:18:57 1.14
@@ -17,6 +17,10 @@
* @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
*/
public class UtilTestCase extends TestCase {
+ protected static final String FEATURE_XML_ROUNDTRIP=
+ "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
+ protected static final String FEATURE_UNNORMALIZED_XML =
+ "http://xmlpull.org/v1/doc/features.html#unnormalized-xml";
protected String TEST_XML =
"<root>\n"+
@@ -43,6 +47,24 @@
return factory;
}
+ /**
+ * Gathers getText() for successive tokens of the same type.
+ * Parser will be positioned on next token of different type.
+ */
+ public String nextTokenGathered(XmlPullParser xpp, int type, boolean expectedWhitespaces)
+ throws XmlPullParserException, IOException
+ {
+ StringBuffer buf = new StringBuffer();
+ while(xpp.nextToken() == type) {
+ buf.append(xpp.getText());
+ if(expectedWhitespaces) {
+ assertTrue(xpp.isWhitespace());
+ }
+ }
+ return buf.toString();
+
+ }
+
public void checkParserState(
XmlPullParser xpp,
int depth,
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/