Merge "Fixing tests to handle changes in our behaviour since DOM 3." into froyo
diff --git a/dom/src/test/java/org/w3c/domts/level2/core/documentcreateattributeNS04.java b/dom/src/test/java/org/w3c/domts/level2/core/documentcreateattributeNS04.java
index bc7b323..bae9800 100644
--- a/dom/src/test/java/org/w3c/domts/level2/core/documentcreateattributeNS04.java
+++ b/dom/src/test/java/org/w3c/domts/level2/core/documentcreateattributeNS04.java
@@ -92,13 +92,14 @@
qualifiedName = (String) qualifiedNames.get(indexN1004E);
{
- boolean success = false;
+ // BEGIN android-changed
+ // Our exception priorities differ from the spec
try {
attribute = doc.createAttributeNS(namespaceURI, qualifiedName);
- } catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
+ fail("documentcreateattributeNS04");
+ } catch (DOMException expected) {
}
- assertTrue("documentcreateattributeNS04", success);
+ // END android-changed
}
}
}
diff --git a/dom/src/test/java/org/w3c/domts/level2/core/setAttributeNS02.java b/dom/src/test/java/org/w3c/domts/level2/core/setAttributeNS02.java
index 7300f80..9a83561 100644
--- a/dom/src/test/java/org/w3c/domts/level2/core/setAttributeNS02.java
+++ b/dom/src/test/java/org/w3c/domts/level2/core/setAttributeNS02.java
@@ -75,13 +75,14 @@
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("throw_NAMESPACE_ERR");
} catch (DOMException ex) {
- success = (ex.code == DOMException.NAMESPACE_ERR);
}
- assertTrue("throw_NAMESPACE_ERR", success);
+ // END android-changed
}
}
/**
diff --git a/support/src/test/java/tests/util/TestEnvironment.java b/support/src/test/java/tests/util/TestEnvironment.java
index 088e624..fd02123 100644
--- a/support/src/test/java/tests/util/TestEnvironment.java
+++ b/support/src/test/java/tests/util/TestEnvironment.java
@@ -145,7 +145,12 @@
}
private static void copyProperty(Properties p, String key) {
- p.put(key, System.getProperty(key));
+ String value = System.getProperty(key);
+ if (value != null) {
+ p.put(key, value);
+ } else {
+ p.remove(key);
+ }
}
private static void makeDirectory(File path) {
diff --git a/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java b/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
index ea7abed..4b4511d 100644
--- a/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
+++ b/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
@@ -44,6 +44,7 @@
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 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 @@
// 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/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java b/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java
index a918ac2..6f050e3 100644
--- a/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java
+++ b/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserFactoryTest.java
@@ -177,6 +177,7 @@
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 @@
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/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java b/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
index e6d6481..ad0b9c2 100644
--- a/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
+++ b/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
@@ -669,6 +669,7 @@
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/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java b/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java
index c7e0d34..3cd0da6 100644
--- a/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java
+++ b/xml/src/test/java/tests/org/w3c/dom/CreateAttributeNS.java
@@ -218,12 +218,13 @@
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/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java b/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java
index 157b394..8e1b175 100644
--- a/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java
+++ b/xml/src/test/java/tests/org/w3c/dom/CreateDocument.java
@@ -305,13 +305,13 @@
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/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java b/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java
index 8d8bb4d..6258936 100644
--- a/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java
+++ b/xml/src/test/java/tests/org/w3c/dom/CreateElementNS.java
@@ -239,13 +239,14 @@
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/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java b/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java
index e46f3b3..87c8661 100644
--- a/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java
+++ b/xml/src/test/java/tests/org/w3c/dom/DocumentCreateAttributeNS.java
@@ -216,13 +216,15 @@
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/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java b/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java
index 58c146f..b1f24e9 100644
--- a/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java
+++ b/xml/src/test/java/tests/org/w3c/dom/SetAttributeNS.java
@@ -126,14 +126,15 @@
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 @@
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/xml/src/test/java/tests/xml/DeclarationTest.java b/xml/src/test/java/tests/xml/DeclarationTest.java
index 8fea844..9fc42fe 100644
--- a/xml/src/test/java/tests/xml/DeclarationTest.java
+++ b/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 @@
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/xml/src/test/java/tests/xml/DomTest.java b/xml/src/test/java/tests/xml/DomTest.java
index 5f088c1..1f723f7 100644
--- a/xml/src/test/java/tests/xml/DomTest.java
+++ b/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 @@
* 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 @@
* 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 @@
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 @@
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 @@
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 @@
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 @@
1, document.getChildNodes().getLength());
}
+ @KnownFailure("Dalvik document nodes accept arbitrary child nodes")
public void testDocumentAddChild()
throws IOException, SAXException {
try {
diff --git a/xml/src/test/java/tests/xml/NodeTest.java b/xml/src/test/java/tests/xml/NodeTest.java
index dc3a333..d1d99c1 100644
--- a/xml/src/test/java/tests/xml/NodeTest.java
+++ b/xml/src/test/java/tests/xml/NodeTest.java
@@ -51,14 +51,13 @@
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 @@
// 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/xml/src/test/java/tests/xml/NormalizeTest.java b/xml/src/test/java/tests/xml/NormalizeTest.java
index f35ca10..5d2bb0be 100644
--- a/xml/src/test/java/tests/xml/NormalizeTest.java
+++ b/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 @@
* 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/xml/src/test/java/tests/xml/SaxTest.java b/xml/src/test/java/tests/xml/SaxTest.java
index 2c75a73..dc59b2d 100644
--- a/xml/src/test/java/tests/xml/SaxTest.java
+++ b/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 @@
* 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,