Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLDecoder/spec/TestArray.java
41155 views
1
/*
2
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @summary Tests <array> element
27
* @run main/othervm -Djava.security.manager=allow TestArray
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.XMLDecoder;
32
import java.lang.reflect.Array;
33
34
public final class TestArray extends AbstractTest {
35
public static final String XML
36
= "<java>\n"
37
+ " <array class=\"java.lang.Number\">\n"
38
+ " <byte>-111</byte>\n"
39
+ " <long>1111</long>\n"
40
+ " </array>\n"
41
+ " <array length=\"3\">\n"
42
+ " <void index=\"1\">\n"
43
+ " <string>Hello, world!</string>\n"
44
+ " </void>\n"
45
+ " </array>\n"
46
+ "</java>";
47
48
public static void main(String[] args) {
49
new TestArray().test(true);
50
}
51
52
@Override
53
protected void validate(XMLDecoder decoder) {
54
Number[] numbers = getArray(Number.class, 2, decoder.readObject());
55
if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
56
throw new Error("unexpected byte value");
57
}
58
if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
59
throw new Error("unexpected long value");
60
}
61
62
Object[] objects = getArray(Object.class, 3, decoder.readObject());
63
if (objects[0] != null) {
64
throw new Error("unexpected first value");
65
}
66
if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
67
throw new Error("unexpected string value");
68
}
69
if (objects[2] != null) {
70
throw new Error("unexpected last value");
71
}
72
}
73
74
private static <T> T[] getArray(Class<T> component, int length, Object object) {
75
Class type = object.getClass();
76
if (!type.isArray()) {
77
throw new Error("array expected");
78
}
79
if (!type.getComponentType().equals(component)) {
80
throw new Error("unexpected component type");
81
}
82
if (length != Array.getLength(object)) {
83
throw new Error("unexpected array length");
84
}
85
return (T[]) object;
86
}
87
}
88
89