Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanValue/equals/equals002.java
41161 views
1
/*
2
* Copyright (c) 2002, 2018, 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
package nsk.jdi.BooleanValue.equals;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.connect.*;
32
import java.io.*;
33
import java.util.*;
34
import java.util.jar.*;
35
36
/**
37
* The test check up case when parameter has boundary values of primitive <br>
38
* types and when parameter is <code>null</code>.<br>
39
* Analyse of the method executing is performed by <code>PerformComparing</code>
40
* method.<br>
41
* First parameter of <code>PerformComparing</code> is static field of <code>testedObj</code>,<br>
42
* which is placed onto debugee's side. <br>
43
*
44
* Second parameter is got from debugee too:<br>
45
* Debugee has array of boundary values of each primitive type, <code>execTest</code> reads<br>
46
* them and calls <code>PerformComparing</code> for each of them.<br>
47
*/
48
public class equals002 {
49
50
private final static String prefix = "nsk.jdi.BooleanValue.equals.";
51
private final static String className = "equals002";
52
private final static String debuggerName = prefix + className;
53
private final static String debugeeName = debuggerName + "a";
54
private final static String objectToCheck = "testedObj";
55
private final static String arrPrimitives = "testedFields";
56
57
private static int exitStatus;
58
private static Log log;
59
private static Debugee debugee;
60
private static ReferenceType refType;
61
62
public static void main(String argv[]) {
63
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
64
}
65
66
public static int run(String argv[], PrintStream out) {
67
68
exitStatus = Consts.TEST_FAILED;
69
70
ArgumentHandler argHandler = new ArgumentHandler(argv);
71
log = new Log(out, argHandler);
72
73
debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);
74
execTest();
75
debugee.quit();
76
77
return exitStatus;
78
}
79
80
private static void display(String msg) {
81
log.display("debugger> " + msg);
82
}
83
84
private static void complain(String msg) {
85
log.complain("debugger FAILURE> " + msg + "\n");
86
}
87
88
private static void execTest() {
89
90
exitStatus = Consts.TEST_FAILED;
91
92
refType = debugee.classByName(debugeeName);
93
if ( refType == null ) {
94
complain("Class '" + debugeeName + "' not found.");
95
return;
96
}
97
98
// getting of object to check
99
Field field = refType.fieldByName(objectToCheck);
100
if ( field == null ) {
101
complain("Field '" + objectToCheck + "' not found.");
102
return;
103
}
104
Value objectValue = refType.getValue(field);
105
if ( objectValue == null ) {
106
complain("Field '" + objectToCheck + "' not initialized.");
107
return;
108
}
109
110
// geting of array of primitive types
111
field = refType.fieldByName(arrPrimitives);
112
if ( field == null ) {
113
complain("Field '" + arrPrimitives + "' not found.");
114
return;
115
}
116
Value arrValue = refType.getValue(field);
117
if ( arrValue == null || !(arrValue instanceof ArrayReference) ) {
118
complain("Field '" + arrValue + "' is wrong.");
119
return;
120
}
121
ArrayReference primitivValues = (ArrayReference )arrValue;
122
123
List fieldList = ((ClassType )objectValue.type()).allFields();
124
125
Value v1, currentValue;
126
BooleanValue value;
127
Field fldOtherType;
128
String msg;
129
130
exitStatus = Consts.TEST_PASSED;
131
132
// comparing loop
133
for (int i = 0; i < fieldList.size(); i++ ) {
134
field = (Field )fieldList.get(i);
135
log.display("");
136
msg = "***" + field;
137
v1 = ((ObjectReference )objectValue).getValue(field);
138
if ( !(v1 instanceof BooleanValue) ) {
139
msg += " is not BooleanValue (skipped)";
140
exitStatus = Consts.TEST_FAILED;
141
continue;
142
}
143
value = (BooleanValue )v1;
144
145
// comparing with debugee's fields
146
for (int j = 0; j < primitivValues.length(); j++) {
147
arrValue = primitivValues.getValue(j);
148
149
fldOtherType = refType.fieldByName(((StringReference )arrValue).value());
150
if ( fldOtherType == null ) {
151
complain("Field '" + arrValue + "' not found.");
152
exitStatus = Consts.TEST_FAILED;
153
continue;
154
}
155
156
currentValue = refType.getValue(fldOtherType);
157
158
if ( !PerformComparing(value, currentValue) )
159
exitStatus = Consts.TEST_FAILED;
160
}
161
}
162
}
163
164
private static boolean PerformComparing(BooleanValue value, Object object ) {
165
boolean res = true;
166
String msg = "";
167
try {
168
if ( value.equals(object) ) {
169
if ( object instanceof BooleanValue ) {
170
if ( value.value() == ((PrimitiveValue )object).booleanValue() ) {
171
msg += "--> " + value + " == " + object;
172
} else {
173
msg += "##> " + value + " == " + object;
174
res = false;
175
}
176
}
177
else {
178
msg += "##> " + value + " == " + object
179
+ " : are different types " + value.type() + " - "
180
+ ((Value )object).type();
181
res = false;
182
}
183
if ( object == null ) {
184
msg += " ***Wrong result!!!***";
185
res = false;
186
}
187
} else {
188
if ( object instanceof BooleanValue ) {
189
if ( value.value() != ((PrimitiveValue )object).booleanValue() ) {
190
msg += "--> " + value + " != " + object;
191
} else {
192
msg += "##> " + value + " != " + object;
193
res = false;
194
}
195
}
196
else {
197
msg += "--> " + value + " != " + object;
198
}
199
}
200
201
} catch (Exception e) {
202
msg += " ***Unexpected " + e + "***";
203
res = false;
204
}
205
206
if ( !res )
207
complain(msg);
208
else
209
display(msg);
210
211
return res;
212
}
213
}
214
215