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/08 00:05:37
Modified: src/java/tests/org/xmlpull/v1/tests TestSimpleToken.java
TestToken.java UtilTestCase.java
Log:
changed test code to allow IGNORABLE WHITESPACE to happen
for outside root element (they are no longer required if ROUNDTRIP is false)
Revision Changes Path
1.18 +66 -58 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.17
retrieving revision 1.18
diff -u -b -t -w -r1.17 -r1.18
--- TestSimpleToken.java 2002/08/01 18:18:56 1.17
+++ TestSimpleToken.java 2002/08/08 05:05:37 1.18
@@ -113,14 +113,22 @@
public void testNormalization() throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
+ testNormalization(xpp);
+ try{ xpp.setFeature(FEATURE_XML_ROUNDTRIP, false); } catch(Exception ex) {}
+ testNormalization(xpp);
+ try{ xpp.setFeature(FEATURE_XML_ROUNDTRIP, true); } catch(Exception ex) {}
+ testNormalization(xpp);
+ }
+
+ public void testNormalization(XmlPullParser xpp) throws Exception {
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;
+ boolean roundtrip = xpp.getFeature(FEATURE_XML_ROUNDTRIP) == false;
String text = nextTokenGathered(xpp, XmlPullParser.TEXT, true);
- if(normalized) {
+ if(roundtrip) {
assertEquals(printable("\n \n \n\n"), printable(text));
assertEquals("\n \n \n\n", text);
} else {
1.11 +225 -211 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.10
retrieving revision 1.11
diff -u -b -t -w -r1.10 -r1.11
--- TestToken.java 2002/08/01 18:18:57 1.10
+++ TestToken.java 2002/08/08 05:05:37 1.11
@@ -89,19 +89,22 @@
}
-
public void testTokenTypes() throws Exception {
- testTokenTypes(false);
+ testTokenTypes(false, false);
+ testTokenTypes(false, true);
}
public void testTokenTypesInPrologAndEpilog() throws Exception {
- testTokenTypes(true);
+ testTokenTypes(true, false);
+ testTokenTypes(true, false);
}
// one step further - it has content ...
- public void testTokenTypes(boolean checkPrologAndEpilog) throws Exception {
+ public void testTokenTypes(boolean checkPrologAndEpilog,
+ boolean useRoundtrip) throws Exception {
XmlPullParser xpp = factory.newPullParser();
assertEquals(true, xpp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
+ System.out.println("using "+xpp);
if(checkPrologAndEpilog) {
xpp.setInput(new StringReader(MISC_XML));
@@ -111,12 +114,12 @@
// attempt to set roundtrip
try {
- xpp.setFeature(FEATURE_XML_ROUNDTRIP, true);
+ xpp.setFeature(FEATURE_XML_ROUNDTRIP, useRoundtrip);
} catch(Exception ex) { // make sure we ignore if failed ...
}
// did we succeeded?
boolean roundtripSupported = xpp.getFeature(FEATURE_XML_ROUNDTRIP);
- boolean unnormalizedSupported = xpp.getFeature(FEATURE_UNNORMALIZED_XML);
+ //boolean unnormalizedSupported = xpp.getFeature(FEATURE_UNNORMALIZED_XML);
checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
try {
@@ -126,17 +129,22 @@
}
if(checkPrologAndEpilog) {
- if(unnormalizedSupported) {
+ xpp.nextToken();
+ if(xpp.getEventType() == xpp.IGNORABLE_WHITESPACE) {
// 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);
+ String text = gatherTokenText(xpp, xpp.IGNORABLE_WHITESPACE, true);
+ if(roundtripSupported) {
assertEquals(printable("\n \r\n \n\r"), printable(text));
assertEquals("\n \r\n \n\r", text);
+ } else {
+ assertEquals(printable("\n \n \n\n"), printable(text));
+ assertEquals("\n \n \n\n", text);
+ }
}
- xpp.nextToken();
checkParserStateNs(xpp, 0, xpp.COMMENT, null, 0, null, null, "c", false, -1);
try {
xpp.isWhitespace();
@@ -144,14 +152,17 @@
} catch(XmlPullParserException ex) {
}
- if(unnormalizedSupported) {
+ xpp.nextToken();
+ if(xpp.getEventType() == xpp.IGNORABLE_WHITESPACE) {
// 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);
+ if(roundtripSupported) {
assertEquals(printable(" \r\n"), printable(text));
} else {
- xpp.nextToken();
+ assertEquals(printable(" \n"), printable(text));
+ }
}
@@ -280,19 +291,22 @@
} catch(XmlPullParserException ex) {
}
+ xpp.nextToken();
if(checkPrologAndEpilog) {
- if(unnormalizedSupported) {
+ //if(unnormalizedSupported) {
+ if(xpp.getEventType() == xpp.IGNORABLE_WHITESPACE) {
+
// 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);
+ if(roundtripSupported) {
assertEquals(printable("\r\n "), printable(text));
} else {
- xpp.nextToken();
+ assertEquals(printable("\n "), printable(text));
}
- } else {
- xpp.nextToken();
+ }
}
checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
try {
1.15 +75 -61 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.14
retrieving revision 1.15
diff -u -b -t -w -r1.14 -r1.15
--- UtilTestCase.java 2002/08/01 18:18:57 1.14
+++ UtilTestCase.java 2002/08/08 05:05:37 1.15
@@ -19,8 +19,6 @@
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"+
@@ -44,23 +42,39 @@
System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
null //Thread.currentThread().getContextClassLoader().getClass(), //NOT ON JDK 1.1
);
+ //System.out.println("factory="+factory);
return factory;
}
/**
- * Gathers getText() for successive tokens of the same type.
+ *
+ * Mpve to next token and gather 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
{
+
+ xpp.nextToken();
+ return gatherTokenText(xpp, type, expectedWhitespaces);
+
+ }
+
+ /**
+ * Gathers getText() for successive tokens of the same type.
+ * Parser will be positioned on next token of different type.
+ */
+ public String gatherTokenText(XmlPullParser xpp, int type, boolean expectedWhitespaces)
+ throws XmlPullParserException, IOException
+ {
StringBuffer buf = new StringBuffer();
- while(xpp.nextToken() == type) {
+ assertEquals(xpp.TYPES[ type ], xpp.TYPES[ xpp.getEventType() ]);
+ do {
buf.append(xpp.getText());
if(expectedWhitespaces) {
assertTrue(xpp.isWhitespace());
- }
}
+ } while(xpp.nextToken() == type);
return buf.toString();
}