summaryrefslogtreecommitdiffstats
path: root/libcore/xml/src
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-03-26 14:03:36 -0700
committerJesse Wilson <jessewilson@google.com>2010-03-26 14:03:36 -0700
commit94640f175b2fcda6a4fd890c6686240f76d01f55 (patch)
treed5abca93538b38a957554f697b38fa26888ce8de /libcore/xml/src
parent63868feb2cc6a1fb1c76d7b54296ef4869f632be (diff)
downloadandroid_dalvik-94640f175b2fcda6a4fd890c6686240f76d01f55.tar.gz
android_dalvik-94640f175b2fcda6a4fd890c6686240f76d01f55.tar.bz2
android_dalvik-94640f175b2fcda6a4fd890c6686240f76d01f55.zip
Fixing tests to handle changes in our behaviour since DOM 3.
Our exception priority has changed for DOM attributes. We previously used to throw DOMExceptions with namespace error codes and now throw DOMExceptions with character error codes when the attribute name is malformed. This caused changes to many tests. Another notable behaviour change is that we now supply the qname (like the RI) where previously we did not. It is optional, but we now include it for RI-consistency. Yet another behaviour change is that we don't look at System properties when choosing a SAX implementation. This simplifies our internals significantly. End users who want an alternative SAX implementation should construct it manually. Also adding @KnownFailure tags for new tests that we have never yet passed. Change-Id: I6f81bedd7c2a0867086dc507b3220c2b07c4d3d3
Diffstat (limited to 'libcore/xml/src')
-rw-r--r--libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java9
-rw-r--r--libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java54
-rw-r--r--libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java1
-rw-r--r--libcore/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java7
-rw-r--r--libcore/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java8
-rw-r--r--libcore/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java7
-rw-r--r--libcore/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java8
-rw-r--r--libcore/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java14
-rw-r--r--libcore/xml/src/test/java/tests/xml/DeclarationTest.java4
-rw-r--r--libcore/xml/src/test/java/tests/xml/DomTest.java11
-rw-r--r--libcore/xml/src/test/java/tests/xml/NodeTest.java11
-rw-r--r--libcore/xml/src/test/java/tests/xml/NormalizeTest.java2
-rw-r--r--libcore/xml/src/test/java/tests/xml/SaxTest.java2
13 files changed, 65 insertions, 73 deletions
diff --git a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
index ea7abedf0..4b4511de6 100644
--- a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
+++ b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
@@ -44,6 +44,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
@TestTargetClass(DocumentBuilder.class)
public class DocumentBuilderTest extends TestCase {
@@ -564,8 +565,8 @@ public class DocumentBuilderTest extends TestCase {
)
public void test_parseLjava_lang_String() throws Exception {
// case 1: Trivial use.
- File f = new File(getClass().getResource("/simple.xml").getFile());
- Document d = db.parse(f.getAbsolutePath());
+ URL resource = getClass().getResource("/simple.xml");
+ Document d = db.parse(resource.toString());
assertNotNull(d);
// TBD getXmlEncoding() is not supported
// assertEquals("ISO-8859-1", d.getXmlEncoding());
@@ -593,8 +594,8 @@ public class DocumentBuilderTest extends TestCase {
// case 4: Try to parse incorrect xml file
try {
- f = new File(getClass().getResource("/wrong.xml").getFile());
- db.parse(f.getAbsolutePath());
+ resource = getClass().getResource("/wrong.xml");
+ db.parse(resource.toString());
fail("Expected SAXException was not thrown");
} catch (SAXException sax) {
// expected
diff --git a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java
index a918ac2bb..6f050e315 100644
--- a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java
+++ b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java
@@ -177,6 +177,7 @@ public class SAXParserFactoryTest extends TestCase {
method = "newInstance",
args = {}
)
+ @KnownFailure("Dalvik doesn't honor system properties when choosing a SAX implementation")
public void test_newInstance() {
try {
SAXParserFactory dtf = SAXParserFactory.newInstance();
@@ -316,57 +317,18 @@ public class SAXParserFactoryTest extends TestCase {
method = "setNamespaceAware",
args = {boolean.class}
)
- @KnownFailure("Error in namespace feature handling (for ExpatParser)")
- public void test_setNamespaceAwareZ() {
+ public void test_setNamespaceAwareZ() throws Exception {
+ MyHandler mh = new MyHandler();
spf.setNamespaceAware(true);
- MyHandler mh = new MyHandler();
InputStream is = getClass().getResourceAsStream("/simple_ns.xml");
- try {
- spf.newSAXParser().parse(is, mh);
- } catch(javax.xml.parsers.ParserConfigurationException pce) {
- fail("ParserConfigurationException was thrown during parsing");
- } catch(org.xml.sax.SAXException se) {
- fail("SAXException was thrown during parsing");
- } catch(IOException ioe) {
- fail("IOException was thrown during parsing");
- } finally {
- try {
- is.close();
- } catch(Exception e) {}
- }
+ spf.newSAXParser().parse(is, mh);
+ is.close();
+
spf.setNamespaceAware(false);
is = getClass().getResourceAsStream("/simple_ns.xml");
- try {
- is = getClass().getResourceAsStream("/simple_ns.xml");
- spf.newSAXParser().parse(is, mh);
- } catch(javax.xml.parsers.ParserConfigurationException pce) {
- fail("ParserConfigurationException was thrown during parsing");
- } catch(org.xml.sax.SAXException se) {
- se.printStackTrace();
- fail("SAXException was thrown during parsing");
- } catch(IOException ioe) {
- fail("IOException was thrown during parsing");
- } finally {
- try {
- is.close();
- } catch(Exception ioee) {}
- }
- is = getClass().getResourceAsStream("/simple_ns.xml");
- try {
- spf.setNamespaceAware(true);
- spf.newSAXParser().parse(is, mh);
- } catch(javax.xml.parsers.ParserConfigurationException pce) {
- fail("ParserConfigurationException was thrown during parsing");
- } catch(org.xml.sax.SAXException se) {
- fail("SAXException was thrown during parsing");
- } catch(IOException ioe) {
- fail("IOException was thrown during parsing");
- } finally {
- try {
- is.close();
- } catch(Exception ioee) {}
- }
+ spf.newSAXParser().parse(is, mh);
+ is.close();
}
/* public void test_setSchemaLjavax_xml_validation_Schema() {
diff --git a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
index e6d64813b..ad0b9c212 100644
--- a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
+++ b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
@@ -669,6 +669,7 @@ public class SAXParserTest extends TestCase {
method = "parse",
args = {java.io.InputStream.class, org.xml.sax.helpers.DefaultHandler.class, java.lang.String.class}
)
+ @KnownFailure("We supply optional qnames, but this test doesn't expect them")
public void test_parseLjava_io_InputStreamLorg_xml_sax_helpers_DefaultHandlerLjava_lang_String() {
for(int i = 0; i < list_wf.length; i++) {
try {
diff --git a/libcore/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java b/libcore/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java
index c7e0d341b..3cd0da62b 100644
--- a/libcore/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java
+++ b/libcore/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java
@@ -218,12 +218,13 @@ public final class CreateAttributeNS extends DOMTestCase {
doc = (Document) load("hc_staff", builder);
- boolean success = false;
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
doc.createAttributeNS(namespaceURI, "");
+ fail();
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("throw_INVALID_CHARACTER_ERR", success);
+ // END android-changed
}
}
diff --git a/libcore/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java b/libcore/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java
index 157b3945e..8e1b175be 100644
--- a/libcore/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java
+++ b/libcore/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java
@@ -305,13 +305,13 @@ public final class CreateDocument extends DOMTestCase {
domImpl = builder.getDOMImplementation();
- boolean success = false;
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
domImpl.createDocument(namespaceURI, "", docType);
+ fail();
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("throw_NAMESPACE_ERR", success);
-
+ // END android-changed
}
}
diff --git a/libcore/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java b/libcore/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java
index 8d8bb4dc2..6258936df 100644
--- a/libcore/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java
+++ b/libcore/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java
@@ -239,13 +239,14 @@ public final class CreateElementNS extends DOMTestCase {
doc = (Document) load("hc_staff", builder);
{
- boolean success = false;
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
doc.createElementNS(namespaceURI, "");
+ fail();
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("throw_NAMESPACE_ERR", success);
+ // END android-changed
}
}
}
diff --git a/libcore/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java b/libcore/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java
index e46f3b3c9..87c8661cf 100644
--- a/libcore/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java
+++ b/libcore/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java
@@ -216,13 +216,15 @@ public final class DocumentCreateAttributeNS extends DOMTestCase {
qualifiedName = (String) qualifiedNames.get(indexN1004E);
{
- boolean success = false;
+
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
doc.createAttributeNS(namespaceURI, qualifiedName);
+ fail();
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("documentcreateattributeNS04", success);
+ // END android-changed
}
}
}
diff --git a/libcore/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java b/libcore/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java
index 58c146f1f..b1f24e9be 100644
--- a/libcore/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java
+++ b/libcore/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java
@@ -126,14 +126,15 @@ public final class SetAttributeNS extends DOMTestCase {
testAddr = elementList.item(0);
{
- boolean success = false;
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "newValue");
+ fail();
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("throw_NAMESPACE_ERR", success);
+ // END android-changed
}
}
@@ -340,14 +341,15 @@ public final class SetAttributeNS extends DOMTestCase {
testAddr = elementList.item(0);
{
- boolean success = false;
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI, "",
"newValue");
+ fail();
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("throw_NAMESPACE_ERR", success);
+ // END android-changed
}
}
}
diff --git a/libcore/xml/src/test/java/tests/xml/DeclarationTest.java b/libcore/xml/src/test/java/tests/xml/DeclarationTest.java
index 8fea844d1..9fc42fe3c 100644
--- a/libcore/xml/src/test/java/tests/xml/DeclarationTest.java
+++ b/libcore/xml/src/test/java/tests/xml/DeclarationTest.java
@@ -16,6 +16,7 @@
package tests.xml;
+import dalvik.annotation.KnownFailure;
import junit.framework.TestCase;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
@@ -78,18 +79,21 @@ public class DeclarationTest extends TestCase {
assertEquals("ISO-8859-1", documentB.getInputEncoding());
}
+ @KnownFailure("Dalvik doesn't parse the XML declaration")
public void testGetXmlEncoding() throws Exception {
String message = "This implementation doesn't parse the encoding from the XML declaration";
assertEquals(message, "ISO-8859-1", documentA.getXmlEncoding());
assertEquals(message, "US-ASCII", documentB.getXmlEncoding());
}
+ @KnownFailure("Dalvik doesn't parse the XML declaration")
public void testGetXmlVersion() throws Exception {
String message = "This implementation doesn't parse the version from the XML declaration";
assertEquals(message, "1.0", documentA.getXmlVersion());
assertEquals(message, "1.1", documentB.getXmlVersion());
}
+ @KnownFailure("Dalvik doesn't parse the XML declaration")
public void testGetXmlStandalone() throws Exception {
String message = "This implementation doesn't parse standalone from the XML declaration";
assertEquals(message, false, documentA.getXmlStandalone());
diff --git a/libcore/xml/src/test/java/tests/xml/DomTest.java b/libcore/xml/src/test/java/tests/xml/DomTest.java
index 5f088c191..1f723f75d 100644
--- a/libcore/xml/src/test/java/tests/xml/DomTest.java
+++ b/libcore/xml/src/test/java/tests/xml/DomTest.java
@@ -16,6 +16,7 @@
package tests.xml;
+import dalvik.annotation.KnownFailure;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.w3c.dom.Attr;
@@ -185,6 +186,7 @@ public class DomTest extends TestCase {
* Android's parsed DOM doesn't include entity declarations. These nodes will
* only be tested for implementations that support them.
*/
+ @KnownFailure("Dalvik doesn't parse entity declarations")
public void testEntityDeclarations() {
assertNotNull("This implementation does not parse entity declarations", sp);
}
@@ -193,6 +195,7 @@ public class DomTest extends TestCase {
* Android's parsed DOM doesn't include notations. These nodes will only be
* tested for implementations that support them.
*/
+ @KnownFailure("Dalvik doesn't parse notations")
public void testNotations() {
assertNotNull("This implementation does not parse notations", png);
}
@@ -552,10 +555,12 @@ public class DomTest extends TestCase {
assertNoFeature("XMLVersion", "2.0");
}
- public void testLsFeature() {
+ @KnownFailure("Dalvik doesn't support load/save")
+ public void testLoadSaveFeature() {
assertFeature("LS", "3.0");
}
+ @KnownFailure("Dalvik doesn't support the element traversal feature")
public void testElementTraversalFeature() {
assertFeature("ElementTraversal", "1.0");
}
@@ -652,6 +657,7 @@ public class DomTest extends TestCase {
assertFalse(text.isElementContentWhitespace());
}
+ @KnownFailure("Dalvik doesn't recognize element content whitespace")
public void testIsElementContentWhitespaceWithDeclaration() throws Exception {
String xml = "<!DOCTYPE menu [\n"
+ " <!ELEMENT menu (item)*>\n"
@@ -685,6 +691,7 @@ public class DomTest extends TestCase {
assertEquals("60%", vitamincText.getWholeText());
}
+ @KnownFailure("Dalvik doesn't resolve entity references")
public void testGetWholeTextWithEntityReference() {
EntityReference spReference = document.createEntityReference("sp");
description.insertBefore(spReference, descriptionText2);
@@ -1180,6 +1187,7 @@ public class DomTest extends TestCase {
assertNull(document.getElementById("g"));
}
+ @KnownFailure("Dalvik treats id attributes as identifiers")
public void testAttributeNamedIdIsNotAnIdByDefault() {
String message = "This implementation incorrectly interprets the "
+ "\"id\" attribute as an identifier by default.";
@@ -1323,6 +1331,7 @@ public class DomTest extends TestCase {
1, document.getChildNodes().getLength());
}
+ @KnownFailure("Dalvik document nodes accept arbitrary child nodes")
public void testDocumentAddChild()
throws IOException, SAXException {
try {
diff --git a/libcore/xml/src/test/java/tests/xml/NodeTest.java b/libcore/xml/src/test/java/tests/xml/NodeTest.java
index dc3a33302..d1d99c1ed 100644
--- a/libcore/xml/src/test/java/tests/xml/NodeTest.java
+++ b/libcore/xml/src/test/java/tests/xml/NodeTest.java
@@ -51,14 +51,13 @@ public class NodeTest extends TestCase {
File file = Support_Resources.resourceToTempFile("/simple.xml");
Document document = builder.parse(file);
- String baseUri = "file:" + file.getPath();
- assertEquals(baseUri, document.getBaseURI());
+ assertFileUriEquals(file, document.getBaseURI());
Element documentElement = document.getDocumentElement();
for (Node node : flattenSubtree(documentElement)) {
if (node.getNodeType() == Node.ELEMENT_NODE
|| node.getNodeType() == Node.DOCUMENT_NODE) {
- assertEquals("Unexpected base URI for " + node, baseUri, node.getBaseURI());
+ assertFileUriEquals(file, node.getBaseURI());
} else {
assertNull("Unexpected base URI for " + node, node.getBaseURI());
}
@@ -69,6 +68,12 @@ public class NodeTest extends TestCase {
// TODO: test URI santization
}
+ private void assertFileUriEquals(File expectedFile, String actual) {
+ assertTrue("Expected URI for: " + expectedFile + " but was " + actual + ". ",
+ actual.equals("file:" + expectedFile)
+ || actual.equals("file://" + expectedFile));
+ }
+
private List<Node> flattenSubtree(Node subtree) {
List<Node> result = new ArrayList<Node>();
traverse(subtree, result);
diff --git a/libcore/xml/src/test/java/tests/xml/NormalizeTest.java b/libcore/xml/src/test/java/tests/xml/NormalizeTest.java
index f35ca105d..5d2bb0be9 100644
--- a/libcore/xml/src/test/java/tests/xml/NormalizeTest.java
+++ b/libcore/xml/src/test/java/tests/xml/NormalizeTest.java
@@ -16,6 +16,7 @@
package tests.xml;
+import dalvik.annotation.KnownFailure;
import junit.framework.TestCase;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
@@ -204,6 +205,7 @@ public class NormalizeTest extends TestCase {
* This fails under the RI because setParameter() succeeds even though
* canSetParameter() returns false.
*/
+ @KnownFailure("Dalvik doesn't honor the schema-type parameter")
public void testSchemaTypeDtd() {
assertUnsupported("schema-type", "http://www.w3.org/TR/REC-xml"); // supported in RI v6
}
diff --git a/libcore/xml/src/test/java/tests/xml/SaxTest.java b/libcore/xml/src/test/java/tests/xml/SaxTest.java
index 2c75a7312..dc59b2ddb 100644
--- a/libcore/xml/src/test/java/tests/xml/SaxTest.java
+++ b/libcore/xml/src/test/java/tests/xml/SaxTest.java
@@ -16,6 +16,7 @@
package tests.xml;
+import dalvik.annotation.KnownFailure;
import junit.framework.TestCase;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@@ -94,6 +95,7 @@ public class SaxTest extends TestCase {
* Android's Expat-based SAX parser fails this test because Expat doesn't
* supply us with our much desired {@code xmlns="http://..."} attributes.
*/
+ @KnownFailure("No xmlns attributes from Expat")
public void testYesPrefixesYesNamespaces() throws Exception {
parse(true, true, "<foo bar=\"baz\"/>", new DefaultHandler() {
@Override public void startElement(String uri, String localName,