diff --git a/test/java/util/Properties/Compatibility.xml b/test/java/util/Properties/Compatibility.xml new file mode 100644 index 0000000000000000000000000000000000000000..b80d2d045f2d23484ea399991cabc3fad6b5462f --- /dev/null +++ b/test/java/util/Properties/Compatibility.xml @@ -0,0 +1,10 @@ + + ]> + + +Property With Other Encoding +value1 +]]> +&intEnt; + diff --git a/test/java/util/Properties/CompatibilityTest.java b/test/java/util/Properties/CompatibilityTest.java new file mode 100644 index 0000000000000000000000000000000000000000..efd16c9bd5906f473d421d083550acc85d11ec0d --- /dev/null +++ b/test/java/util/Properties/CompatibilityTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8005280 8004371 + * @summary Compatibility test + * @run main CompatibilityTest + * @run main/othervm -Dsun.util.spi.XmlPropertiesProvider=jdk.internal.util.xml.BasicXmlPropertiesProvider CompatibilityTest + */ + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * This is a behavior compatibility test. + * Although not defined by the properties.dtd, the constructs + * in Compatibility.xml are supported by the regular JDK XML + * Provider. + * + * @author: Joe Wang + */ +public class CompatibilityTest { + + public static void main(String[] args) { + testInternalDTD(); + } + + /* + * Not in the spec, but the constructs work with the current JDK + */ + static void testInternalDTD() { + String src = System.getProperty("test.src"); + if (src == null) { + src = "."; + } + loadPropertyFile(src + "/Compatibility.xml"); + } + + /* + * 'Store' the populated 'Property' with the specified 'Encoding Type' as an + * XML file. Retrieve the same XML file and 'load' onto a new 'Property' object. + */ + static void loadPropertyFile(String filename) { + try (InputStream in = new FileInputStream(filename)) { + Properties prop = new Properties(); + prop.loadFromXML(in); + verifyProperites(prop); + } catch (IOException ex) { + fail(ex.getMessage()); + } + } + + /* + * This method verifies the first key-value with the original string. + */ + static void verifyProperites(Properties prop) { + try { + for (String key : prop.stringPropertyNames()) { + String val = prop.getProperty(key); + if (key.equals("Key1")) { + if (!val.equals("value1")) { + fail("Key:" + key + "'s value: \nExpected: value1\nFound: " + val); + } + } else if (key.equals("Key2")) { + if (!val.equals("")) { + fail("Key:" + key + "'s value: \nExpected: \nFound: " + val); + } + } else if (key.equals("Key3")) { + if (!val.equals("value3")) { + fail("Key:" + key + "'s value: \nExpected: value3\nFound: " + val); + } + } + } + } catch (Exception e) { + fail(e.getMessage()); + } + + } + + static void fail(String err) { + throw new RuntimeException(err); + } + +} diff --git a/test/java/util/Properties/LoadAndStoreXML.java b/test/java/util/Properties/LoadAndStoreXML.java index 337b3e00a42e1dd18c2b523adf161b8a01307c29..5388485e91be7cf1849d548685368aa984b141d9 100644 --- a/test/java/util/Properties/LoadAndStoreXML.java +++ b/test/java/util/Properties/LoadAndStoreXML.java @@ -75,6 +75,9 @@ public class LoadAndStoreXML { Properties props = new Properties(); props.put("k1", "foo"); props.put("k2", "bar"); + props.put("k3", "\\u0020\\u0391\\u0392\\u0393\\u0394\\u0395\\u0396\\u0397"); + props.put("k4", "\u7532\u9aa8\u6587"); + props.put("k5", "/lib/jaxp.properties"); ByteArrayOutputStream out = new ByteArrayOutputStream(); props.storeToXML(out, null, encoding); diff --git a/test/java/util/Properties/invalidxml/BadDocType.xml.excluded b/test/java/util/Properties/invalidxml/BadDocType.xml similarity index 100% rename from test/java/util/Properties/invalidxml/BadDocType.xml.excluded rename to test/java/util/Properties/invalidxml/BadDocType.xml diff --git a/test/java/util/Properties/invalidxml/DTDRootNotMatch.xml b/test/java/util/Properties/invalidxml/DTDRootNotMatch.xml new file mode 100644 index 0000000000000000000000000000000000000000..757653a4f3a5f3be41934d3a72e3ddcb0d9af5bb --- /dev/null +++ b/test/java/util/Properties/invalidxml/DTDRootNotMatch.xml @@ -0,0 +1,9 @@ + + + + + + +comment +value of the first key + diff --git a/test/java/util/Properties/invalidxml/IllegalComment.xml b/test/java/util/Properties/invalidxml/IllegalComment.xml new file mode 100644 index 0000000000000000000000000000000000000000..06350acce9ce873752c08cd09828ccff08acdb81 --- /dev/null +++ b/test/java/util/Properties/invalidxml/IllegalComment.xml @@ -0,0 +1,10 @@ + + + + + + +comment1 +comment2 +value of the first key + diff --git a/test/java/util/Properties/invalidxml/IllegalEntry.xml b/test/java/util/Properties/invalidxml/IllegalEntry.xml new file mode 100644 index 0000000000000000000000000000000000000000..76171893e8414097f89ed756ad374879b9e47a13 --- /dev/null +++ b/test/java/util/Properties/invalidxml/IllegalEntry.xml @@ -0,0 +1,9 @@ + + + + + + +comment +value of the first key + diff --git a/test/java/util/Properties/invalidxml/IllegalEntry1.xml b/test/java/util/Properties/invalidxml/IllegalEntry1.xml new file mode 100644 index 0000000000000000000000000000000000000000..e51c2979168115104069e2694530c4869d28eafc --- /dev/null +++ b/test/java/util/Properties/invalidxml/IllegalEntry1.xml @@ -0,0 +1,11 @@ + + + + + + +comment1 + +value of the first key +value of the second key + diff --git a/test/java/util/Properties/invalidxml/IllegalKeyAttribute.xml b/test/java/util/Properties/invalidxml/IllegalKeyAttribute.xml new file mode 100644 index 0000000000000000000000000000000000000000..f8c59df5e2421343dab224e44f723d8b7f78dbc1 --- /dev/null +++ b/test/java/util/Properties/invalidxml/IllegalKeyAttribute.xml @@ -0,0 +1,9 @@ + + + + + + +comment1 +value of the first key + diff --git a/test/java/util/Properties/invalidxml/NoDocType.xml.excluded b/test/java/util/Properties/invalidxml/NoDocType.xml similarity index 100% rename from test/java/util/Properties/invalidxml/NoDocType.xml.excluded rename to test/java/util/Properties/invalidxml/NoDocType.xml diff --git a/test/java/util/Properties/invalidxml/NoNamespaceSupport.xml b/test/java/util/Properties/invalidxml/NoNamespaceSupport.xml new file mode 100644 index 0000000000000000000000000000000000000000..176058d846ff0ba58cd7bf8353862416f06e264b --- /dev/null +++ b/test/java/util/Properties/invalidxml/NoNamespaceSupport.xml @@ -0,0 +1,11 @@ + + + + + + +comment1 + +value of the first key +value of the second key +