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