Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/management/openmbean/EqualsTest.java
41149 views
1
/*
2
* Copyright (c) 2005, 2015, 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
* @bug 5072174
27
* @summary Test CompositeDataSupport.equals with ArrayType
28
* @author Shanliang JIANG
29
*
30
* @run clean EqualsTest
31
* @run build EqualsTest
32
* @run main EqualsTest
33
*/
34
35
import javax.management.ObjectName;
36
import javax.management.openmbean.*;
37
38
public class EqualsTest {
39
40
/*
41
* Print message
42
*/
43
private static void echo(String message) {
44
System.out.println(message);
45
}
46
47
/**
48
* Main
49
*/
50
public static void main(String[] args) throws Exception {
51
echo("=-=-= Test CompositeDataSupport.equals() with ArrayType =-=-=");
52
53
echo(">>> Two SimpleTypes with different descriptions");
54
CompositeType ct1 = new CompositeType(
55
"MyType",
56
"for test",
57
new String[] {"a", "b"},
58
new String[] {"a_desc", "b_desc"},
59
new OpenType[] {SimpleType.BOOLEAN,SimpleType.STRING});
60
61
CompositeType ct2 = new CompositeType(
62
"MyType",
63
"for test",
64
new String[] {"a", "b"},
65
new String[] {"aa_desc", "bb_desc"},
66
new OpenType[] {SimpleType.BOOLEAN, SimpleType.STRING});
67
68
if (!ct1.equals(ct2)) {
69
throw new RuntimeException("CompositeType.equals fails!");
70
}
71
if (ct1.hashCode() != ct2.hashCode()) {
72
throw new RuntimeException("CompositeType.hashCode fails!");
73
}
74
75
echo(">>> Two SimpleTypes with equal values");
76
CompositeData compositeData0 = new CompositeDataSupport(
77
ct1,
78
new String[] {"a", "b"},
79
new Object[] {new Boolean(true), ""});
80
81
CompositeData compositeData1 = new CompositeDataSupport(
82
ct2,
83
new String[] {"a", "b"},
84
new Object[] {new Boolean(true), ""});
85
86
if (!compositeData0.equals(compositeData1)) {
87
throw new RuntimeException("CompositeDataSupport.equals fails!");
88
}
89
if (compositeData0.hashCode() != compositeData1.hashCode()) {
90
throw new RuntimeException("CompositeDataSupport.hashCode fails!");
91
}
92
93
echo(">>> Two ArrayTypes with different references");
94
CompositeType ct3 = new CompositeType(
95
"MyType",
96
"for test",
97
new String[] {"a"},
98
new String[] {"a_desc"},
99
new OpenType[] {new ArrayType(1, SimpleType.STRING)});
100
101
CompositeData compositeData2 = new CompositeDataSupport(
102
ct3,
103
new String[] {"a"},
104
new Object[] {new String[] {"x", "y"}});
105
106
CompositeData compositeData3 = new CompositeDataSupport(
107
ct3,
108
new String[] {"a"},
109
new Object[] {new String[] {"x", "y"}});
110
111
if (!compositeData2.equals(compositeData3)) {
112
throw new RuntimeException("CompositeDataSupport.equals fails!");
113
}
114
if (compositeData2.hashCode() != compositeData3.hashCode()) {
115
throw new RuntimeException("CompositeDataSupport.hashCode fails!");
116
}
117
118
echo(">>> Two ArrayTypes with different values");
119
CompositeData compositeData4 = new CompositeDataSupport(
120
ct3,
121
new String[] {"a"},
122
new Object[] {new String[] {"x", "y", "x"}});
123
124
if (compositeData2.equals(compositeData4)) {
125
throw new RuntimeException("CompositeDataSupport.equals fails!");
126
}
127
128
echo(">>> Two 2-dimension ArrayTypes with equal values");
129
CompositeType ct4 = new CompositeType(
130
"MyType",
131
"for test",
132
new String[] {"a"},
133
new String[] {"a_desc"},
134
new OpenType[] {new ArrayType(2, SimpleType.OBJECTNAME)});
135
136
final String s = "t:t=t";
137
CompositeData compositeData5 = new CompositeDataSupport(
138
ct4,
139
new String[] {"a"},
140
new Object[] {
141
new ObjectName[][] {
142
new ObjectName[] {
143
new ObjectName(s), new ObjectName(s)
144
},
145
new ObjectName[] {
146
new ObjectName(s), new ObjectName(s)
147
}
148
}
149
});
150
151
CompositeData compositeData6 = new CompositeDataSupport(
152
ct4,
153
new String[] {"a"},
154
new Object[] {
155
new ObjectName[][] {
156
new ObjectName[] {
157
new ObjectName(s), new ObjectName(s)
158
},
159
new ObjectName[] {
160
new ObjectName(s), new ObjectName(s)
161
}
162
}
163
});
164
165
if (!compositeData5.equals(compositeData6)) {
166
throw new RuntimeException("CompositeDataSupport.equals fails!");
167
}
168
if (compositeData5.hashCode() != compositeData6.hashCode()) {
169
throw new RuntimeException("CompositeDataSupport.hashCode fails!");
170
}
171
172
echo(">>> Two primitive ArrayTypes with different descriptions");
173
CompositeType ct5 = new CompositeType(
174
"MyType",
175
"for test",
176
new String[] {"a", "b"},
177
new String[] {"a_desc", "b_desc"},
178
new OpenType[] {
179
SimpleType.BOOLEAN,
180
ArrayType.getPrimitiveArrayType(short[].class)
181
});
182
183
CompositeType ct6 = new CompositeType(
184
"MyType",
185
"for test",
186
new String[] {"a", "b"},
187
new String[] {"aa_desc", "bb_desc"},
188
new OpenType[] {
189
SimpleType.BOOLEAN,
190
ArrayType.getPrimitiveArrayType(short[].class)
191
});
192
193
if (!ct5.equals(ct6)) {
194
throw new RuntimeException("CompositeType.equals fails!");
195
}
196
if (ct5.hashCode() != ct6.hashCode()) {
197
throw new RuntimeException("CompositeType.hashCode fails!");
198
}
199
200
echo(">>> Two primitive ArrayTypes with different references");
201
CompositeType ct7 = new CompositeType(
202
"MyType",
203
"for test",
204
new String[] {"a"},
205
new String[] {"a_desc"},
206
new OpenType[] {
207
ArrayType.getPrimitiveArrayType(int[].class)
208
});
209
210
CompositeData compositeData7 = new CompositeDataSupport(
211
ct7,
212
new String[] {"a"},
213
new Object[] {new int[] {1, 2}});
214
215
CompositeData compositeData8 = new CompositeDataSupport(
216
ct7,
217
new String[] {"a"},
218
new Object[] {new int[] {1, 2}});
219
220
if (!compositeData7.equals(compositeData8)) {
221
throw new RuntimeException("CompositeDataSupport.equals fails!");
222
}
223
if (compositeData7.hashCode() != compositeData8.hashCode()) {
224
throw new RuntimeException("CompositeDataSupport.hashCode fails!");
225
}
226
227
echo(">>> Two primitive ArrayTypes with different values");
228
CompositeData compositeData9 = new CompositeDataSupport(
229
ct7,
230
new String[] {"a"},
231
new Object[] {new int[] {1, 2, 3}});
232
233
if (compositeData7.equals(compositeData9)) {
234
throw new RuntimeException("CompositeDataSupport.equals fails!");
235
}
236
237
echo(">>> Two 2-dimension primitive ArrayTypes with equal values");
238
CompositeType ct8 = new CompositeType(
239
"MyType",
240
"for test",
241
new String[] {"a"},
242
new String[] {"a_desc"},
243
new OpenType[] {
244
ArrayType.getPrimitiveArrayType(boolean[][].class)
245
});
246
247
CompositeData compositeData10 = new CompositeDataSupport(
248
ct8,
249
new String[] {"a"},
250
new Object[] {new boolean[][]
251
{new boolean[] {true, true},
252
new boolean[] {true, true}}});
253
254
CompositeData compositeData11 = new CompositeDataSupport(
255
ct8,
256
new String[] {"a"},
257
new Object[] {new boolean[][]
258
{new boolean[] {true, true},
259
new boolean[] {true, true}}});
260
261
if (!compositeData10.equals(compositeData11)) {
262
throw new RuntimeException("CompositeDataSupport.equals fails!");
263
}
264
if (compositeData10.hashCode() != compositeData11.hashCode()) {
265
throw new RuntimeException("CompositeDataSupport.hashCode fails!");
266
}
267
}
268
}
269
270