AI 144831: am: CL 144827 am: CL 144822 Bringing XML down to one broken test.
Original author: jorgp
Merged from: //branches/cupcake/...
Original author: android-build
Automated import of CL 144831
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 181e8f5..793139d 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
@@ -19,8 +19,10 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -31,6 +33,8 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
@@ -41,7 +45,6 @@
import tests.api.org.xml.sax.support.MethodLogger;
import tests.api.org.xml.sax.support.MockHandler;
import tests.api.org.xml.sax.support.MockResolver;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
@@ -274,9 +277,19 @@
method = "parse",
args = {java.io.File.class}
)
- @BrokenTest("Need to use XML file from correct location")
- public void test_parseLjava_io_File() {
- File f = new File("/tmp/xml_source/simple.xml");
+ @KnownFailure("d.getChildNodes returns an unexpected/strange #Text node")
+ public void test_parseLjava_io_File() throws IOException {
+ File f = File.createTempFile("simple", ".xml");
+ f.deleteOnExit();
+ InputStream xml = getClass().getResourceAsStream("/simple.xml");
+ FileOutputStream out = new FileOutputStream(f);
+ while (xml.available() > 0) {
+ out.write(xml.read());
+ }
+ out.flush();
+ out.close();
+ xml.close();
+
// case 1: Trivial use.
try {
Document d = db.parse(f);
@@ -317,8 +330,17 @@
}
// case 4: Try to parse incorrect xml file
+ f = File.createTempFile("wrong", ".xml");
+ f.deleteOnExit();
+ xml = getClass().getResourceAsStream("/wrong.xml");
+ out = new FileOutputStream(f);
+ while (xml.available() > 0) {
+ out.write(xml.read());
+ }
+ out.flush();
+ out.close();
+ xml.close();
try {
- f = new File("/tmp/xml_source/wrong.xml");
db.parse(f);
fail("Expected SAXException was not thrown");
} catch (IOException ioe) {
diff --git a/libcore/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java b/libcore/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java
index ebf2a04..5ac87d5 100644
--- a/libcore/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java
+++ b/libcore/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java
@@ -34,14 +34,14 @@
args = { },
notes = "Checks everything except META-INF case"
)
- public void testMakeParser() {
+ public void testMakeParser() throws NullPointerException,
+ ClassCastException, ClassNotFoundException, InstantiationException,
+ IllegalAccessException {
// Property not set at all
try {
ParserFactory.makeParser();
} catch (NullPointerException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Unknown class
@@ -51,8 +51,6 @@
ParserFactory.makeParser();
} catch (ClassNotFoundException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Non-accessible class
@@ -63,8 +61,6 @@
ParserFactory.makeParser();
} catch (IllegalAccessException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Non-instantiable class
@@ -75,8 +71,6 @@
ParserFactory.makeParser();
} catch (InstantiationException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Non-Parser class
@@ -87,19 +81,13 @@
ParserFactory.makeParser();
} catch (ClassCastException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Good one, finally
System.setProperty("org.xml.sax.parser",
"tests.api.org.xml.sax.support.DoNothingParser");
- try {
- ParserFactory.makeParser();
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
- }
+ ParserFactory.makeParser();
}
@@ -108,14 +96,14 @@
method = "makeParser",
args = { String.class }
)
- public void testMakeParserString() {
+ public void testMakeParserString() throws ClassCastException,
+ ClassNotFoundException, IllegalAccessException,
+ InstantiationException {
// No class
try {
ParserFactory.makeParser(null);
} catch (NullPointerException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Unknown class
@@ -123,8 +111,6 @@
ParserFactory.makeParser("foo.bar.SAXParser");
} catch (ClassNotFoundException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Non-accessible class
@@ -133,8 +119,6 @@
"tests.api.org.xml.sax.support.NoAccessParser");
} catch (IllegalAccessException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Non-instantiable class
@@ -143,8 +127,6 @@
"tests.api.org.xml.sax.support.NoInstanceParser");
} catch (InstantiationException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Non-Parser class
@@ -153,17 +135,11 @@
"tests.api.org.xml.sax.support.NoSubclassParser");
} catch (ClassCastException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
}
// Good one, finally
- try {
- ParserFactory.makeParser(
- "tests.api.org.xml.sax.support.DoNothingParser");
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
- }
+ ParserFactory.makeParser(
+ "tests.api.org.xml.sax.support.DoNothingParser");
}