undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
69
test/jdk/java/beans/XMLDecoder/spec/AbstractTest.java
Normal file
69
test/jdk/java/beans/XMLDecoder/spec/AbstractTest.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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.
|
||||
*/
|
||||
|
||||
import java.beans.ExceptionListener;
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
abstract class AbstractTest implements ExceptionListener {
|
||||
public void exceptionThrown(Exception exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the XML decoder for XML archive
|
||||
* that defined in the public field of the subclass.
|
||||
*
|
||||
* @param decoder the initialized XML decoder
|
||||
* @throws Error if validation failed
|
||||
*/
|
||||
protected abstract void validate(XMLDecoder decoder);
|
||||
|
||||
/**
|
||||
* This is entry point to start testing.
|
||||
*/
|
||||
final void test() {
|
||||
byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
|
||||
ByteArrayInputStream input = new ByteArrayInputStream(array);
|
||||
XMLDecoder decoder = new XMLDecoder(input);
|
||||
decoder.setExceptionListener(this);
|
||||
validate(decoder);
|
||||
try {
|
||||
throw new Error("unexpected object" + decoder.readObject());
|
||||
} catch (ArrayIndexOutOfBoundsException exception) {
|
||||
// expected exception
|
||||
}
|
||||
decoder.close();
|
||||
}
|
||||
|
||||
private String getFieldValue(String field) {
|
||||
try {
|
||||
return getClass().getField(field).get(this).toString();
|
||||
} catch (NoSuchFieldException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
} catch (IllegalAccessException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
test/jdk/java/beans/XMLDecoder/spec/TestArray.java
Normal file
87
test/jdk/java/beans/XMLDecoder/spec/TestArray.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <array> element
|
||||
* @run main/othervm TestArray
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public final class TestArray extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <array class=\"java.lang.Number\">\n"
|
||||
+ " <byte>-111</byte>\n"
|
||||
+ " <long>1111</long>\n"
|
||||
+ " </array>\n"
|
||||
+ " <array length=\"3\">\n"
|
||||
+ " <void index=\"1\">\n"
|
||||
+ " <string>Hello, world!</string>\n"
|
||||
+ " </void>\n"
|
||||
+ " </array>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestArray().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
Number[] numbers = getArray(Number.class, 2, decoder.readObject());
|
||||
if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected byte value");
|
||||
}
|
||||
if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected long value");
|
||||
}
|
||||
|
||||
Object[] objects = getArray(Object.class, 3, decoder.readObject());
|
||||
if (objects[0] != null) {
|
||||
throw new Error("unexpected first value");
|
||||
}
|
||||
if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected string value");
|
||||
}
|
||||
if (objects[2] != null) {
|
||||
throw new Error("unexpected last value");
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T[] getArray(Class<T> component, int length, Object object) {
|
||||
Class type = object.getClass();
|
||||
if (!type.isArray()) {
|
||||
throw new Error("array expected");
|
||||
}
|
||||
if (!type.getComponentType().equals(component)) {
|
||||
throw new Error("unexpected component type");
|
||||
}
|
||||
if (length != Array.getLength(object)) {
|
||||
throw new Error("unexpected array length");
|
||||
}
|
||||
return (T[]) object;
|
||||
}
|
||||
}
|
||||
53
test/jdk/java/beans/XMLDecoder/spec/TestBoolean.java
Normal file
53
test/jdk/java/beans/XMLDecoder/spec/TestBoolean.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <boolean> element
|
||||
* @run main/othervm TestBoolean
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestBoolean extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <boolean>true</boolean>\n"
|
||||
+ " <boolean>false</boolean>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestBoolean().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!Boolean.TRUE.equals(decoder.readObject())) {
|
||||
throw new Error("true expected");
|
||||
}
|
||||
if (!Boolean.FALSE.equals(decoder.readObject())) {
|
||||
throw new Error("false expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
57
test/jdk/java/beans/XMLDecoder/spec/TestByte.java
Normal file
57
test/jdk/java/beans/XMLDecoder/spec/TestByte.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <byte> element
|
||||
* @run main/othervm TestByte
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestByte extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <byte>0</byte>\n"
|
||||
+ " <byte>127</byte>\n"
|
||||
+ " <byte>-128</byte>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestByte().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate((byte) 0, decoder.readObject());
|
||||
validate(Byte.MAX_VALUE, decoder.readObject());
|
||||
validate(Byte.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(byte value, Object object) {
|
||||
if (!object.equals(Byte.valueOf(value))) {
|
||||
throw new Error("byte " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
53
test/jdk/java/beans/XMLDecoder/spec/TestChar.java
Normal file
53
test/jdk/java/beans/XMLDecoder/spec/TestChar.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <char> element
|
||||
* @run main/othervm TestChar
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestChar extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <char>X</char>\n"
|
||||
+ " <char code=\"#20\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestChar().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!decoder.readObject().equals(Character.valueOf('X'))) {
|
||||
throw new Error("unexpected character");
|
||||
}
|
||||
if (!decoder.readObject().equals(Character.valueOf((char) 0x20))) {
|
||||
throw new Error("unexpected character code");
|
||||
}
|
||||
}
|
||||
}
|
||||
62
test/jdk/java/beans/XMLDecoder/spec/TestClass.java
Normal file
62
test/jdk/java/beans/XMLDecoder/spec/TestClass.java
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <class> element
|
||||
* @run main/othervm TestClass
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestClass extends AbstractTest {
|
||||
public static final String PREFIX = "javax.swing.colorchooser.";
|
||||
public static final String INTERFACE = "ColorSelectionModel";
|
||||
public static final String PUBLIC_CLASS = "DefaultColorSelectionModel";
|
||||
public static final String PRIVATE_CLASS = "DiagramComponent";
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <class>" + PREFIX + INTERFACE + "</class>\n"
|
||||
+ " <class>" + PREFIX + PUBLIC_CLASS + "</class>\n"
|
||||
+ " <class>" + PREFIX + PRIVATE_CLASS + "</class>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestClass().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(PREFIX + INTERFACE, decoder.readObject());
|
||||
validate(PREFIX + PUBLIC_CLASS, decoder.readObject());
|
||||
validate(PREFIX + PRIVATE_CLASS, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(String name, Object object) {
|
||||
Class type = (Class) object;
|
||||
if (!type.getName().equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/jdk/java/beans/XMLDecoder/spec/TestDouble.java
Normal file
59
test/jdk/java/beans/XMLDecoder/spec/TestDouble.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <double> element
|
||||
* @run main/othervm TestDouble
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestDouble extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <double>0</double>\n"
|
||||
+ " <double>1000</double>\n"
|
||||
+ " <double>-1.1e15</double>\n"
|
||||
+ " <double>10.11e-123</double>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestDouble().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0.0, decoder.readObject());
|
||||
validate(1000.0, decoder.readObject());
|
||||
validate(-1.1e15, decoder.readObject());
|
||||
validate(10.11e-123, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(double value, Object object) {
|
||||
if (!object.equals(Double.valueOf(value))) {
|
||||
throw new Error("double " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/beans/XMLDecoder/spec/TestFalse.java
Normal file
49
test/jdk/java/beans/XMLDecoder/spec/TestFalse.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <false> element
|
||||
* @run main/othervm TestFalse
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestFalse extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <false/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestFalse().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!Boolean.FALSE.equals(decoder.readObject())) {
|
||||
throw new Error("false expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
75
test/jdk/java/beans/XMLDecoder/spec/TestField.java
Normal file
75
test/jdk/java/beans/XMLDecoder/spec/TestField.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <field> element
|
||||
* @run main/othervm TestField
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestField extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <field name=\"FIELD\" class=\"TestField\"/>\n"
|
||||
+ " <field name=\"FIELD\" class=\"TestField\">\n"
|
||||
+ " <string>static postfix</string>\n"
|
||||
+ " </field>\n"
|
||||
+ " <field name=\"FIELD\" class=\"TestField\"/>\n"
|
||||
+ " <property name=\"owner\">\n"
|
||||
+ " <field id=\"prefix\" name=\"field\"/>\n"
|
||||
+ " <field name=\"field\">\n"
|
||||
+ " <string>postfix</string>\n"
|
||||
+ " </field>\n"
|
||||
+ " <field id=\"postfix\" name=\"field\"/>\n"
|
||||
+ " </property>\n"
|
||||
+ " <var idref=\"prefix\"/>\n"
|
||||
+ " <var idref=\"postfix\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestField().test();
|
||||
}
|
||||
|
||||
public static String FIELD;
|
||||
public String field;
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
FIELD = "static prefix";
|
||||
field = "prefix";
|
||||
decoder.setOwner(this);
|
||||
validate(decoder, "static prefix");
|
||||
validate(decoder, "static postfix");
|
||||
validate(decoder, "prefix");
|
||||
validate(decoder, "postfix");
|
||||
}
|
||||
|
||||
private static void validate(XMLDecoder decoder, String name) {
|
||||
if (!decoder.readObject().equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/jdk/java/beans/XMLDecoder/spec/TestFloat.java
Normal file
59
test/jdk/java/beans/XMLDecoder/spec/TestFloat.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <float> element
|
||||
* @run main/othervm TestFloat
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestFloat extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <float>0</float>\n"
|
||||
+ " <float>100</float>\n"
|
||||
+ " <float>-1e15</float>\n"
|
||||
+ " <float>100e-20</float>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestFloat().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0.0f, decoder.readObject());
|
||||
validate(100.0f, decoder.readObject());
|
||||
validate(-1e15f, decoder.readObject());
|
||||
validate(100e-20f, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(float value, Object object) {
|
||||
if (!object.equals(Float.valueOf(value))) {
|
||||
throw new Error("float " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
65
test/jdk/java/beans/XMLDecoder/spec/TestInt.java
Normal file
65
test/jdk/java/beans/XMLDecoder/spec/TestInt.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <int> element
|
||||
* @run main/othervm TestInt
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestInt extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <int>0</int>\n"
|
||||
+ " <int>127</int>\n"
|
||||
+ " <int>-128</int>\n"
|
||||
+ " <int>32767</int>\n"
|
||||
+ " <int>-32768</int>\n"
|
||||
+ " <int>2147483647</int>\n"
|
||||
+ " <int>-2147483648</int>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestInt().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0, decoder.readObject());
|
||||
validate((int) Byte.MAX_VALUE, decoder.readObject());
|
||||
validate((int) Byte.MIN_VALUE, decoder.readObject());
|
||||
validate((int) Short.MAX_VALUE, decoder.readObject());
|
||||
validate((int) Short.MIN_VALUE, decoder.readObject());
|
||||
validate(Integer.MAX_VALUE, decoder.readObject());
|
||||
validate(Integer.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(int value, Object object) {
|
||||
if (!object.equals(Integer.valueOf(value))) {
|
||||
throw new Error("int " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
64
test/jdk/java/beans/XMLDecoder/spec/TestJava.java
Normal file
64
test/jdk/java/beans/XMLDecoder/spec/TestJava.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <java> element
|
||||
* @run main/othervm TestJava
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestJava extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <void id=\"owner\" method=\"getOwner\">\n"
|
||||
+ " <void method=\"init\">\n"
|
||||
+ " <string>Hello, world!</string>\n"
|
||||
+ " </void>\n"
|
||||
+ " </void>\n"
|
||||
+ " <object idref=\"owner\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestJava().test();
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
public void init(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
decoder.setOwner(this);
|
||||
if (this != decoder.readObject()) {
|
||||
throw new Error("owner should be the same");
|
||||
}
|
||||
if (this.message == null) {
|
||||
throw new Error("owner's method is not called");
|
||||
}
|
||||
}
|
||||
}
|
||||
69
test/jdk/java/beans/XMLDecoder/spec/TestLong.java
Normal file
69
test/jdk/java/beans/XMLDecoder/spec/TestLong.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <long> element
|
||||
* @run main/othervm TestLong
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestLong extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <long>0</long>\n"
|
||||
+ " <long>127</long>\n"
|
||||
+ " <long>-128</long>\n"
|
||||
+ " <long>32767</long>\n"
|
||||
+ " <long>-32768</long>\n"
|
||||
+ " <long>2147483647</long>\n"
|
||||
+ " <long>-2147483648</long>\n"
|
||||
+ " <long>9223372036854775807</long>\n"
|
||||
+ " <long>-9223372036854775808</long>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestLong().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0L, decoder.readObject());
|
||||
validate((long) Byte.MAX_VALUE, decoder.readObject());
|
||||
validate((long) Byte.MIN_VALUE, decoder.readObject());
|
||||
validate((long) Short.MAX_VALUE, decoder.readObject());
|
||||
validate((long) Short.MIN_VALUE, decoder.readObject());
|
||||
validate((long) Integer.MAX_VALUE, decoder.readObject());
|
||||
validate((long) Integer.MIN_VALUE, decoder.readObject());
|
||||
validate(Long.MAX_VALUE, decoder.readObject());
|
||||
validate(Long.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(long value, Object object) {
|
||||
if (!object.equals(Long.valueOf(value))) {
|
||||
throw new Error("long " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
179
test/jdk/java/beans/XMLDecoder/spec/TestMethod.java
Normal file
179
test/jdk/java/beans/XMLDecoder/spec/TestMethod.java
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <method> element
|
||||
* @run main/othervm TestMethod
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestMethod extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <new class=\"TestMethod$A\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$B\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$C\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$D\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$E\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestMethod().test();
|
||||
}
|
||||
|
||||
private NoSuchMethodException exception;
|
||||
|
||||
@Override
|
||||
public void exceptionThrown(Exception exception) {
|
||||
if (this.exception != null) {
|
||||
// only one exception allowed
|
||||
super.exceptionThrown(exception);
|
||||
} else if (exception instanceof NoSuchMethodException) {
|
||||
// expected exception: ambiguous methods are found
|
||||
this.exception = (NoSuchMethodException) exception;
|
||||
} else {
|
||||
super.exceptionThrown(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
this.exception = null;
|
||||
validate(decoder, A.class);
|
||||
validate(decoder, B.class);
|
||||
validate(decoder, C.class);
|
||||
validate(decoder, D.class);
|
||||
validate(decoder, E.class);
|
||||
if (this.exception == null) {
|
||||
throw new Error("NoSuchMethodException expected");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validate(XMLDecoder decoder, Class type) {
|
||||
if (!type.equals(decoder.readObject().getClass())) {
|
||||
throw new Error("unexpected class");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All ambiguous method declarations should fail.
|
||||
*/
|
||||
public static class A {
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("A.m(X,X) should not be called");
|
||||
}
|
||||
|
||||
public void m(X x1, Y y2) {
|
||||
throw new Error("A.m(X,Y) should not be called");
|
||||
}
|
||||
|
||||
public void m(Y y1, X x2) {
|
||||
throw new Error("A.m(Y,X) should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The most specific method in this case would be the second declaration.
|
||||
*/
|
||||
public static class B {
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("B.m(X,X) should not be called");
|
||||
}
|
||||
|
||||
public void m(X x1, Y y2) {
|
||||
// expected: B.m(X,Y) should be called
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The most specific method in this case would be the first declaration.
|
||||
*/
|
||||
public static class C {
|
||||
public void m(Y y1, Y y2) {
|
||||
// expected: C.m(Y,Y) should be called
|
||||
}
|
||||
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("C.m(X,X) should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as the previous case but flip methods.
|
||||
*/
|
||||
public static class D {
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("D.m(X,X) should not be called");
|
||||
}
|
||||
|
||||
public void m(Y y1, Y y2) {
|
||||
// expected: D.m(Y,Y) should be called
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should be called with (Z,Z).
|
||||
*/
|
||||
public static class E {
|
||||
public void m(X x1, X x2) {
|
||||
// expected: E.m(X,X) should be called
|
||||
}
|
||||
}
|
||||
|
||||
public static class X {
|
||||
}
|
||||
|
||||
public static class Y extends X {
|
||||
}
|
||||
|
||||
public static class Z extends Y {
|
||||
}
|
||||
}
|
||||
91
test/jdk/java/beans/XMLDecoder/spec/TestNew.java
Normal file
91
test/jdk/java/beans/XMLDecoder/spec/TestNew.java
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <new> element
|
||||
* @run main/othervm TestNew
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TestNew extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <new class=\"TestNew\"/>\n"
|
||||
+ " <new class=\"TestNew\">\n"
|
||||
+ " <null/>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestNew\">\n"
|
||||
+ " <string>single</string>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestNew\">\n"
|
||||
+ " <string>first</string>\n"
|
||||
+ " <string>second</string>\n"
|
||||
+ " <string>third</string>\n"
|
||||
+ " </new>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestNew().test();
|
||||
}
|
||||
|
||||
private List<String> list;
|
||||
|
||||
public TestNew(String...messages) {
|
||||
if (messages != null) {
|
||||
this.list = new ArrayList<String>();
|
||||
for (String message : messages) {
|
||||
this.list.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof TestNew) {
|
||||
TestNew test = (TestNew) object;
|
||||
return (test.list == null)
|
||||
? this.list == null
|
||||
: test.list.equals(this.list);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(decoder.readObject());
|
||||
validate(decoder.readObject(), null);
|
||||
validate(decoder.readObject(), "single");
|
||||
validate(decoder.readObject(), "first", "second", "third");
|
||||
}
|
||||
|
||||
private static void validate(Object object, String...messages) {
|
||||
if (!object.equals(new TestNew(messages))) {
|
||||
throw new Error("expected object");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/beans/XMLDecoder/spec/TestNull.java
Normal file
49
test/jdk/java/beans/XMLDecoder/spec/TestNull.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <null> element
|
||||
* @run main/othervm TestNull
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestNull extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <null/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestNull().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (null != decoder.readObject()) {
|
||||
throw new Error("null value expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
85
test/jdk/java/beans/XMLDecoder/spec/TestObject.java
Normal file
85
test/jdk/java/beans/XMLDecoder/spec/TestObject.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <object> element
|
||||
* @run main/othervm TestObject
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public final class TestObject extends AbstractTest {
|
||||
public static final String XML // TODO
|
||||
= "<java>\n"
|
||||
+ " <object class=\"javax.swing.JPanel\">\n"
|
||||
+ " <void method=\"add\">\n"
|
||||
+ " <object id=\"button\" class=\"javax.swing.JButton\">\n"
|
||||
+ " <string>button</string>\n"
|
||||
+ " <void property=\"verticalAlignment\">\n"
|
||||
+ " <object field=\"CENTER\" class=\"javax.swing.SwingConstants\"/>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ " </void>\n"
|
||||
+ " <void method=\"add\">\n"
|
||||
+ " <object class=\"javax.swing.JLabel\">\n"
|
||||
+ " <string>label</string>\n"
|
||||
+ " <void property=\"labelFor\">\n"
|
||||
+ " <object idref=\"button\"/>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestObject().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
JPanel panel = (JPanel) decoder.readObject();
|
||||
if (2 != panel.getComponents().length) {
|
||||
throw new Error("unexpected component count");
|
||||
}
|
||||
JButton button = (JButton) panel.getComponents()[0];
|
||||
if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected button text");
|
||||
}
|
||||
if (SwingConstants.CENTER != button.getVerticalAlignment()) {
|
||||
throw new Error("unexpected vertical alignment");
|
||||
}
|
||||
JLabel label = (JLabel) panel.getComponents()[1];
|
||||
if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected label text");
|
||||
}
|
||||
if (button != label.getLabelFor()) {
|
||||
throw new Error("unexpected component");
|
||||
}
|
||||
}
|
||||
}
|
||||
89
test/jdk/java/beans/XMLDecoder/spec/TestProperty.java
Normal file
89
test/jdk/java/beans/XMLDecoder/spec/TestProperty.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <property> element
|
||||
* @run main/othervm TestProperty
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestProperty extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <property name=\"owner\">\n"
|
||||
+ " <property name=\"message\">\n"
|
||||
+ " <string>message</string>\n"
|
||||
+ " </property>\n"
|
||||
+ " <property id=\"message\" name=\"message\"/>\n"
|
||||
+ " <property name=\"indexed\" index=\"1\">\n"
|
||||
+ " <string>indexed</string>\n"
|
||||
+ " </property>\n"
|
||||
+ " <property id=\"indexed\" name=\"indexed\" index=\"1\"/>\n"
|
||||
+ " </property>\n"
|
||||
+ " <var idref=\"message\"/>\n"
|
||||
+ " <var idref=\"indexed\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestProperty().test();
|
||||
}
|
||||
|
||||
private int index;
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getIndexed(int index) {
|
||||
if (this.index != index) {
|
||||
throw new Error("unexpected index");
|
||||
}
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setIndexed(int index, String message) {
|
||||
this.index = index;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
decoder.setOwner(this);
|
||||
validate(decoder, "message");
|
||||
validate(decoder, "indexed");
|
||||
}
|
||||
|
||||
private static void validate(XMLDecoder decoder, String name) {
|
||||
if (!decoder.readObject().equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
61
test/jdk/java/beans/XMLDecoder/spec/TestShort.java
Normal file
61
test/jdk/java/beans/XMLDecoder/spec/TestShort.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <short> element
|
||||
* @run main/othervm TestShort
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestShort extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <short>0</short>\n"
|
||||
+ " <short>127</short>\n"
|
||||
+ " <short>-128</short>\n"
|
||||
+ " <short>32767</short>\n"
|
||||
+ " <short>-32768</short>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestShort().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate((short) 0, decoder.readObject());
|
||||
validate((short) Byte.MAX_VALUE, decoder.readObject());
|
||||
validate((short) Byte.MIN_VALUE, decoder.readObject());
|
||||
validate(Short.MAX_VALUE, decoder.readObject());
|
||||
validate(Short.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(short value, Object object) {
|
||||
if (!object.equals(Short.valueOf(value))) {
|
||||
throw new Error("short " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
61
test/jdk/java/beans/XMLDecoder/spec/TestString.java
Normal file
61
test/jdk/java/beans/XMLDecoder/spec/TestString.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <string> element
|
||||
* @run main/othervm TestString
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestString extends AbstractTest {
|
||||
public static final String PREFIX = " prefix ";
|
||||
public static final String POSTFIX = " postfix ";
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <string>" + PREFIX + "</string>\n"
|
||||
+ " <string>" + POSTFIX + "</string>\n"
|
||||
+ " <string>" + PREFIX + POSTFIX + "</string>\n"
|
||||
+ " <string>" + PREFIX + "<char code=\"0\"/>" + POSTFIX + "</string>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestString().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(PREFIX, decoder.readObject());
|
||||
validate(POSTFIX, decoder.readObject());
|
||||
validate(PREFIX + POSTFIX, decoder.readObject());
|
||||
validate(PREFIX + '\u0000' + POSTFIX, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(String name, Object object) {
|
||||
if (!object.equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/beans/XMLDecoder/spec/TestTrue.java
Normal file
49
test/jdk/java/beans/XMLDecoder/spec/TestTrue.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <true> element
|
||||
* @run main/othervm TestTrue
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestTrue extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <true/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestTrue().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!Boolean.TRUE.equals(decoder.readObject())) {
|
||||
throw new Error("true expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
55
test/jdk/java/beans/XMLDecoder/spec/TestVar.java
Normal file
55
test/jdk/java/beans/XMLDecoder/spec/TestVar.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
* @summary Tests <var> element
|
||||
* @run main/othervm TestVar
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestVar extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java id=\"decoder\">\n"
|
||||
+ " <var idref=\"decoder\"/>\n"
|
||||
+ " <var id=\"another\" idref=\"decoder\"/>\n"
|
||||
+ " <var idref=\"another\"/>\n"
|
||||
+ " <var id=\"decoder\" idref=\"another\"/>\n"
|
||||
+ " <var idref=\"decoder\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestVar().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (decoder != decoder.readObject()) {
|
||||
throw new Error("decoder instance expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue