aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Iashchenko <nikitai@google.com>2021-09-30 19:35:28 +0100
committerVictor Chang <vichang@google.com>2021-11-09 15:19:28 +0000
commit5b74997b7a43aba08cf57a6df91fc57245d341bf (patch)
tree43206fe033f8c7c932e6333d856e1fdaf6e8e12b
parent5b7f7c74aa6c94c3282de65821a41cbcd26dc22d (diff)
downloadlibcore-5b74997b7a43aba08cf57a6df91fc57245d341bf.tar.gz
Add API coverage for javax.xml.{datatype,namespace,parsers}
API list: * javax.xml.datatype.DatatypeConfigurationException.DatatypeConfigurationException() * javax.xml.datatype.DatatypeConfigurationException.DatatypeConfigurationException(java.lang.String, java.lang.Throwable) * javax.xml.datatype.DatatypeConfigurationException.DatatypeConfigurationException(java.lang.Throwable) * javax.xml.datatype.DatatypeConstants.Field.getId() * javax.xml.datatype.XMLGregorianCalendar.getMillisecond() * javax.xml.datatype.XMLGregorianCalendar.setTime(int, int, int) * javax.xml.datatype.XMLGregorianCalendar.setTime(int, int, int, int) * javax.xml.datatype.XMLGregorianCalendar.setTime(int, int, int, java.math.BigDecimal) * javax.xml.namespace.QName.QName(java.lang.String) * javax.xml.namespace.QName.getNamespaceURI() * javax.xml.namespace.QName.getPrefix() * javax.xml.parsers.DocumentBuilder.getSchema() * javax.xml.parsers.DocumentBuilderFactory.getSchema() * javax.xml.parsers.DocumentBuilderFactory.newInstance(java.lang.String, java.lang.ClassLoader) * javax.xml.parsers.DocumentBuilderFactory.setSchema(javax.xml.validation.Schema) Bug: 200273920 Test: atest CtsLibcoreTestCases:libcore.javax.xml.datatype.{\ DatatypeConfigurationExceptionTest,DatatypeConstantsTest,\ XMLGregorianCalendarTest} atest CtsLibcoreTestCases:libcore.javax.xml.namespace.QNameTest atest CtsLibcoreTestCases:libcore.javax.xml.parsers.{\ DocumentBuilderFactoryTest,DocumentBuilderTest} Merged-In: I77d19b46debd6aa74cf24d82d7ef9ab3a27890e5 Change-Id: I77d19b46debd6aa74cf24d82d7ef9ab3a27890e5
-rw-r--r--luni/src/test/java/libcore/javax/xml/datatype/DatatypeConfigurationExceptionTest.java51
-rw-r--r--luni/src/test/java/libcore/javax/xml/datatype/DatatypeConstantsTest.java31
-rw-r--r--luni/src/test/java/libcore/javax/xml/datatype/XMLGregorianCalendarTest.java251
-rw-r--r--luni/src/test/java/libcore/javax/xml/namespace/QNameTest.java51
-rw-r--r--luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderFactoryTest.java57
-rw-r--r--luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderTest.java43
6 files changed, 483 insertions, 1 deletions
diff --git a/luni/src/test/java/libcore/javax/xml/datatype/DatatypeConfigurationExceptionTest.java b/luni/src/test/java/libcore/javax/xml/datatype/DatatypeConfigurationExceptionTest.java
new file mode 100644
index 00000000000..3b6708d6b36
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/xml/datatype/DatatypeConfigurationExceptionTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.javax.xml.datatype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class DatatypeConfigurationExceptionTest {
+
+ @Test
+ public void constructor() {
+ DatatypeConfigurationException e = new DatatypeConfigurationException();
+ assertNull(e.getMessage());
+ assertNull(e.getCause());
+ }
+
+ @Test
+ public void constructorWithStringAndThrowable() {
+ Throwable t = new Throwable();
+ DatatypeConfigurationException e = new DatatypeConfigurationException("message", t);
+ assertEquals("message", e.getMessage());
+ assertEquals(t, e.getCause());
+ }
+
+ @Test
+ public void constructorWithThrowable() {
+ Throwable t = new Throwable();
+ DatatypeConfigurationException e = new DatatypeConfigurationException(t);
+ assertEquals("java.lang.Throwable", e.getMessage());
+ assertEquals(t, e.getCause());
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/xml/datatype/DatatypeConstantsTest.java b/luni/src/test/java/libcore/javax/xml/datatype/DatatypeConstantsTest.java
new file mode 100644
index 00000000000..f1797d1fabd
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/xml/datatype/DatatypeConstantsTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.javax.xml.datatype;
+
+import javax.xml.datatype.DatatypeConstants;
+import junit.framework.TestCase;
+
+public class DatatypeConstantsTest extends TestCase {
+
+ public void testField_getId() {
+ assertEquals(0, DatatypeConstants.YEARS.getId());
+ assertEquals(1, DatatypeConstants.MONTHS.getId());
+ assertEquals(2, DatatypeConstants.DAYS.getId());
+ assertEquals(3, DatatypeConstants.HOURS.getId());
+ assertEquals(4, DatatypeConstants.MINUTES.getId());
+ assertEquals(5, DatatypeConstants.SECONDS.getId());
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/xml/datatype/XMLGregorianCalendarTest.java b/luni/src/test/java/libcore/javax/xml/datatype/XMLGregorianCalendarTest.java
new file mode 100644
index 00000000000..012facc595c
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/xml/datatype/XMLGregorianCalendarTest.java
@@ -0,0 +1,251 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.javax.xml.datatype;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+import junit.framework.TestCase;
+
+public class XMLGregorianCalendarTest extends TestCase {
+
+ private XMLGregorianCalendar calendar;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ calendar = new XMLGregorianCalendarImpl();
+ }
+
+ public void testGetMillisecond() {
+ assertEquals(DatatypeConstants.FIELD_UNDEFINED, calendar.getMillisecond());
+ }
+
+ public void testSetTime_iii() {
+ calendar.setTime(1, 2, 3);
+ assertEquals(1, calendar.getHour());
+ assertEquals(2, calendar.getMinute());
+ assertEquals(3, calendar.getSecond());
+ }
+
+ public void testSetTime_iiii() {
+ calendar.setTime(1, 2, 3, 4);
+ assertEquals(1, calendar.getHour());
+ assertEquals(2, calendar.getMinute());
+ assertEquals(3, calendar.getSecond());
+ assertEquals(DatatypeConstants.FIELD_UNDEFINED, calendar.getMillisecond());
+ }
+
+ public void testSetTime_iiiBigDecimal() {
+ calendar.setTime(1, 2, 3, BigDecimal.valueOf(0.1));
+ assertEquals(1, calendar.getHour());
+ assertEquals(2, calendar.getMinute());
+ assertEquals(3, calendar.getSecond());
+ assertEquals(100, calendar.getMillisecond());
+ assertEquals(BigDecimal.valueOf(0.1), calendar.getFractionalSecond());
+ }
+
+ /**
+ * Stub implementation intended for test coverage.
+ */
+ private static final class XMLGregorianCalendarImpl extends XMLGregorianCalendar {
+
+ private int year;
+ private int month;
+ private int day;
+ private int hour;
+ private int minute;
+ private int second;
+ private int millisecond;
+ private BigDecimal fractional;
+ private int timezoneOffset;
+
+ @Override
+ public void clear() {
+ year = month = day = hour = minute = second = millisecond = timezoneOffset = 0;
+ fractional = BigDecimal.valueOf(0);
+ }
+
+ @Override
+ public void reset() {
+ year = month = day = hour = minute = second = millisecond = timezoneOffset = 0;
+ fractional = BigDecimal.valueOf(0);
+ }
+
+ @Override
+ public void setYear(BigInteger year) {
+ this.year = year.intValue();
+ }
+
+ @Override
+ public void setYear(int year) {
+ this.year = year;
+ }
+
+ @Override
+ public void setMonth(int month) {
+ this.month = month;
+ }
+
+ @Override
+ public void setDay(int day) {
+ this.day = day;
+ }
+
+ @Override
+ public void setTimezone(int offset) {
+ this.timezoneOffset = offset;
+ }
+
+ @Override
+ public void setHour(int hour) {
+ this.hour = hour;
+ }
+
+ @Override
+ public void setMinute(int minute) {
+ this.minute = minute;
+ }
+
+ @Override
+ public void setSecond(int second) {
+ this.second = second;
+ }
+
+ @Override
+ public void setMillisecond(int millisecond) {
+ this.millisecond = millisecond;
+ }
+
+ @Override
+ public void setFractionalSecond(BigDecimal fractional) {
+ this.fractional = fractional;
+ }
+
+ @Override
+ public BigInteger getEon() {
+ return null;
+ }
+
+ @Override
+ public int getYear() {
+ return year;
+ }
+
+ @Override
+ public BigInteger getEonAndYear() {
+ return null;
+ }
+
+ @Override
+ public int getMonth() {
+ return month;
+ }
+
+ @Override
+ public int getDay() {
+ return day;
+ }
+
+ @Override
+ public int getTimezone() {
+ return timezoneOffset;
+ }
+
+ @Override
+ public int getHour() {
+ return hour;
+ }
+
+ @Override
+ public int getMinute() {
+ return minute;
+ }
+
+ @Override
+ public int getSecond() {
+ return second;
+ }
+
+ @Override
+ public BigDecimal getFractionalSecond() {
+ return fractional;
+ }
+
+ @Override
+ public int compare(XMLGregorianCalendar rhs) {
+ if (year != rhs.getYear()) return year - rhs.getYear();
+ if (month != rhs.getMonth()) return month - rhs.getMonth();
+ if (day != rhs.getDay()) return day - rhs.getDay();
+ if (hour != rhs.getHour()) return hour - rhs.getHour();
+ if (minute != rhs.getMinute()) return minute - rhs.getMinute();
+ if (second != rhs.getSecond()) return second - rhs.getSecond();
+ if (millisecond != rhs.getMillisecond()) return millisecond - getMillisecond();
+ return fractional.subtract(rhs.getFractionalSecond()).intValue();
+ }
+
+ @Override
+ public XMLGregorianCalendar normalize() {
+ return null;
+ }
+
+ @Override
+ public String toXMLFormat() {
+ return null;
+ }
+
+ @Override
+ public QName getXMLSchemaType() {
+ return null;
+ }
+
+ @Override
+ public boolean isValid() {
+ return false;
+ }
+
+ @Override
+ public void add(Duration duration) {}
+
+ @Override
+ public GregorianCalendar toGregorianCalendar() {
+ return null;
+ }
+
+ @Override
+ public GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale,
+ XMLGregorianCalendar defaults) {
+ return null;
+ }
+
+ @Override
+ public TimeZone getTimeZone(int defaultZoneoffset) {
+ return null;
+ }
+
+ @Override
+ public Object clone() {
+ return null;
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/xml/namespace/QNameTest.java b/luni/src/test/java/libcore/javax/xml/namespace/QNameTest.java
new file mode 100644
index 00000000000..8214c1132ba
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/xml/namespace/QNameTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.javax.xml.namespace;
+
+import javax.xml.namespace.QName;
+import junit.framework.TestCase;
+
+public class QNameTest extends TestCase {
+
+ public void testConstructor() {
+ QName qName = new QName("hello");
+ assertEquals("", qName.getNamespaceURI());
+ assertEquals("", qName.getPrefix());
+ assertEquals("hello", qName.getLocalPart());
+ }
+
+ public void testGetNamespaceURI() {
+ QName qName = new QName("namespace", "local part", "prefix");
+ assertEquals("namespace", qName.getNamespaceURI());
+ assertEquals("local part", qName.getLocalPart());
+ assertEquals("prefix", qName.getPrefix());
+
+ qName = new QName(null, "local part", "prefix");
+ assertEquals("", qName.getNamespaceURI());
+ assertEquals("local part", qName.getLocalPart());
+ assertEquals("prefix", qName.getPrefix());
+ }
+
+ public void testGetPrefix() {
+ QName qName = new QName("namespace", "local part", "prefix");
+ assertEquals("prefix", qName.getPrefix());
+
+ try {
+ new QName("namespace", "local part", null);
+ fail("Unexpectedly didn't throw IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {}
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderFactoryTest.java b/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderFactoryTest.java
new file mode 100644
index 00000000000..ae9a04503f1
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderFactoryTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.javax.xml.parsers;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.validation.Schema;
+import javax.xml.validation.Validator;
+import javax.xml.validation.ValidatorHandler;
+import junit.framework.TestCase;
+
+public class DocumentBuilderFactoryTest extends TestCase {
+
+ public void testGetSchema() {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ try {
+ factory.getSchema();
+ fail("Unexpectedly didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {}
+ }
+
+ public void testSetSchema() {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ try {
+ factory.setSchema(new Schema() {
+ @Override
+ public Validator newValidator() { return null; }
+
+ @Override
+ public ValidatorHandler newValidatorHandler() { return null; }
+ });
+ fail("Unexpectedly didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {}
+ }
+
+ public void testNewInstance_StringClassLoader() {
+ try {
+ DocumentBuilderFactory.newInstance(null, null);
+ } catch (FactoryConfigurationError expected) {}
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderTest.java b/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderTest.java
index 646776a935d..e643bfd25ab 100644
--- a/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderTest.java
+++ b/luni/src/test/java/libcore/javax/xml/parsers/DocumentBuilderTest.java
@@ -16,7 +16,17 @@
package libcore.javax.xml.parsers;
-import static tests.support.Support_Xml.*;
+import static tests.support.Support_Xml.attrOf;
+import static tests.support.Support_Xml.domOf;
+import static tests.support.Support_Xml.firstChildTextOf;
+import static tests.support.Support_Xml.firstElementOf;
+
+import javax.xml.parsers.DocumentBuilder;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
public class DocumentBuilderTest extends junit.framework.TestCase {
// http://code.google.com/p/android/issues/detail?id=2607
@@ -61,4 +71,35 @@ public class DocumentBuilderTest extends junit.framework.TestCase {
// Expected.
}
}
+
+ public void testGetSchema() {
+ DocumentBuilder db = new DocumentBuilder() {
+ @Override
+ public Document parse(InputSource is) { return null; }
+
+ @Override
+ public boolean isNamespaceAware() { return false; }
+
+ @Override
+ public boolean isValidating() { return false; }
+
+ @Override
+ public void setEntityResolver(EntityResolver er) {}
+
+ @Override
+ public void setErrorHandler(ErrorHandler eh) {}
+
+ @Override
+ public Document newDocument() { return null; }
+
+ @Override
+ public DOMImplementation getDOMImplementation() { return null; }
+ };
+
+ try {
+ db.getSchema();
+ fail("Unexpectedly didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {}
+ }
+
}