aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSorin Basca <sorinbasca@google.com>2024-03-26 11:54:43 +0000
committerSorin Basca <sorinbasca@google.com>2024-03-26 15:47:12 +0000
commit4a48a2f62ed3e2ad96d1fcfebf412d25b1b9c49a (patch)
treedd638e0ddd34d16cce34603d395ff0acc8a06ea0
parent8277520728691269c0ea4786c0f41ae98870c711 (diff)
downloadlibcore-4a48a2f62ed3e2ad96d1fcfebf412d25b1b9c49a.tar.gz
Add test for XmlPullParserFactory.setValidating
Test: atest CtsLibcoreTestCases:libcore.xml.XmlPullParserFactoryTest Fixes: 330772906 Change-Id: Id95ed0891f250e9941f02f032e97306122a0b629
-rw-r--r--luni/src/test/java/libcore/xml/XmlPullParserFactoryTest.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/luni/src/test/java/libcore/xml/XmlPullParserFactoryTest.java b/luni/src/test/java/libcore/xml/XmlPullParserFactoryTest.java
index 0431a161b15..4af835b66e5 100644
--- a/luni/src/test/java/libcore/xml/XmlPullParserFactoryTest.java
+++ b/luni/src/test/java/libcore/xml/XmlPullParserFactoryTest.java
@@ -16,6 +16,11 @@
package libcore.xml;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.android.org.kxml2.io.KXmlParser;
import com.android.org.kxml2.io.KXmlSerializer;
import java.io.IOException;
@@ -23,14 +28,18 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
-public class XmlPullParserFactoryTest extends TestCase {
+@RunWith(JUnit4.class)
+public class XmlPullParserFactoryTest {
+ @Test
public void testDefaultNewInstance() throws Exception {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(null, null);
XmlPullParser parser = factory.newPullParser();
@@ -46,6 +55,7 @@ public class XmlPullParserFactoryTest extends TestCase {
* Tests that trying to instantiate a parser with an empty list of
* parsers and serializers fails.
*/
+ @Test
public void testOverriding_emptyClassList() {
TestXmlPullParserFactory tf = new TestXmlPullParserFactory(null, null);
@@ -62,6 +72,7 @@ public class XmlPullParserFactoryTest extends TestCase {
}
}
+ @Test
public void testOverriding_customClassList() throws Exception {
TestXmlPullParserFactory tf = new TestXmlPullParserFactory(
new String[] { "libcore.xml.XmlPullParserFactoryTest$XmlPullParserStub" },
@@ -85,6 +96,7 @@ public class XmlPullParserFactoryTest extends TestCase {
}
// https://b/12956724
+ @Test
public void testSetFeature_setsFeatureOnlyIfTrue() throws Exception {
TestXmlPullParserFactory tf = new TestXmlPullParserFactory(
new String[] { "libcore.xml.XmlPullParserFactoryTest$XmlParserThatHatesAllFeatures" }, null);
@@ -93,6 +105,18 @@ public class XmlPullParserFactoryTest extends TestCase {
tf.newPullParser();
}
+ @Test
+ public void testSetValidating() throws Exception {
+ XmlPullParserFactory xppf = XmlPullParserFactory.newInstance();
+ xppf.setValidating(true);
+ assertTrue(xppf.isValidating());
+ xppf.setValidating(false);
+ assertFalse(xppf.isValidating());
+ xppf.setValidating(true);
+ assertTrue(xppf.isValidating());
+ }
+
+
/**
* A class that makes use of inherited XmlPullParserFactory fields to check they are