1 /** hard coded linenumbers in other tests - DO NOT CHANGE
2 * @test/nodynamiccopyright/
3 * @bug 4490824
4 * @summary JDI: provide arguments when no debug attributes present
5 *
6 * @author jjh
7 *
8 * @run build TestScaffold VMConnection TargetListener TargetAdapter
9 * @run compile ArgumentValuesTest.java
10 * @run driver ArgumentValuesTest
11 */
12 import com.sun.jdi.*;
13 import com.sun.jdi.event.*;
14 import com.sun.jdi.request.*;
15
16 import java.util.*;
17
18 /********** target program **********/
19
20 class ArgumentValuesTarg {
21 static char s_char1 = 'a';
22 static byte s_byte1 = (byte) 146;
23 static short s_short1 = (short) 28123;
24 static int s_int1 = 3101246;
25 static long s_long1 = 0x0123456789ABCDEFL;
26 static float s_float1 = 2.3145f;
27 static double s_double1 = 1.469d;
28 static int s_iarray1[] = {1, 2, 3};
29 static int s_marray1[][] = {{1, 2, 3}, {3, 4, 5}, null, {6, 7}};
30 static String s_sarray1[] = {"abc", null, "def", "ghi"};
31 static String s_string1 = "abcdef";
32
33 static String s_string2 = "xy";
34 static String s_string3 = "wz";
35 static List<Integer> intList;
36
37 public static void noArgs() {
38 int index = 0; // line 38
39 }
40
41 public static void allArgs(char p_char, byte p_byte, short p_short,
42 int p_int, long p_long, float p_float,
43 double p_double, int p_iarray[], int p_marray[][],
44 String p_sarray1[], String p_string) {
45 int index = 0; // line 45
46 }
47
48 public static void varArgs(String ... p1) {
49 int index = 0; // line 49
50 }
51
52 public static void genericArgs(List<Integer> p1) {
53 int index = 0; // line 53
54 }
55
56 public void instanceMethod(char p_char, byte p_byte) {
57 int index = 0; // line 57
58 }
59
60 public static void main(String[] args) {
61 System.out.println("Howdy!");
62 allArgs(
63 s_char1, s_byte1, s_short1, s_int1,
64 s_long1, s_float1, s_double1, s_iarray1,
65 s_marray1, s_sarray1, s_string1);
66
67 noArgs();
68 varArgs(s_string1, s_string2, s_string3);
69 ArgumentValuesTarg avt = new ArgumentValuesTarg();
70 intList = new ArrayList<Integer>(10);
71 intList.add(10);
72 intList.add(20);
73 genericArgs(intList);
74
75 avt.instanceMethod(s_char1, s_byte1);
76
77 System.out.println("Goodbye from ArgumentValuesTarg!");
78 }
79 }
80
81 /********** test program **********/
82
83 public class ArgumentValuesTest extends TestScaffold {
84 // Must be in same order as args to allArgs(....)
85 String fieldNames[] = {"s_char1", "s_byte1", "s_short1", "s_int1",
86 "s_long1", "s_float1", "s_double1", "s_iarray1",
87 "s_marray1", "s_sarray1", "s_string1"};
88
89 String fieldNamesVarArgs[] = {"s_string1", "s_string2", "s_string3"};
90 String fieldNamesInstance[] = {"s_char1", "s_byte1"};
91
92 ReferenceType targetClass;
93 ThreadReference mainThread;
94
95 ArgumentValuesTest (String args[]) {
96 super(args);
97 }
98
99 public static void main(String[] args)
100 throws Exception
101 {
102 new ArgumentValuesTest (args).startTests();
103 }
104
105 /********** test core **********/
106
107 protected void runTests()
108 throws Exception
109 {
110 /*
111 * Get to the top of main() to determine targetClass and mainThread
112 */
113 BreakpointEvent bpe = startToMain("ArgumentValuesTarg");
114 targetClass = bpe.location().declaringType();
115 mainThread = bpe.thread();
116 EventRequestManager erm = vm().eventRequestManager();
117
118
119 {
120 System.out.println("----- Testing each type of arg");
121 bpe = resumeTo("ArgumentValuesTarg", 45);
122 StackFrame frame = bpe.thread().frame(0);
123
124 Method mmm = frame.location().method();
125 System.out.println("Arg types are: " + mmm.argumentTypeNames());
126
127 List<Value> argVals = frame.getArgumentValues();
128
129 if (argVals.size() != fieldNames.length) {
130 failure("failure: Varargs: expected length " + fieldNames.length +
131 " args, got: " + argVals);
132 }
133 for (int ii = 0; ii < argVals.size(); ii++) {
134 Value gotVal = argVals.get(ii);
135
136 Field theField = targetClass.fieldByName(fieldNames[ii]);
137 Value expectedVal = targetClass.getValue(theField);
138 System.out.println(fieldNames[ii] + ": gotVal = " + gotVal +
139 ", expected = " + expectedVal);
140 //System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());
141 if (!gotVal.equals(expectedVal)) {
142 failure(" failure: gotVal != expected");
143 }
144 }
145 }
146
147 // a method with no params
148 {
149 System.out.println("----- Testing no args");
150 bpe = resumeTo("ArgumentValuesTarg", 38);
151 StackFrame frame = bpe.thread().frame(0);
152
153 Method mmm = frame.location().method();
154 System.out.println("Arg types are: " + mmm.argumentTypeNames());
155
156 List<Value> argVals = frame.getArgumentValues();
157 if (argVals.size() == 0) {
158 System.out.println("Empty arg list ok");
159 } else {
160 failure("failure: Expected empty val list, got: " + argVals);
161 }
162 }
163
164 // var args. 3 Strings are passed in and they appear
165 // as a String[3] in the method.
166 {
167 System.out.println("----- Testing var args");
168 bpe = resumeTo("ArgumentValuesTarg", 49);
169 StackFrame frame = bpe.thread().frame(0);
170
171 Method mmm = frame.location().method();
172 System.out.println("Arg types are: " + mmm.argumentTypeNames());
173
174 List<Value> argVals = frame.getArgumentValues();
175 if (argVals.size() != 1) {
176 failure("failure: Varargs: expected one arg, got: " + argVals);
177 }
178 argVals = ((ArrayReference)argVals.get(0)).getValues();
179
180 if (argVals.size() != fieldNamesVarArgs.length) {
181 failure("failure: Varargs: expected length " + fieldNamesVarArgs.length +
182 " array elements, got: " + argVals);
183 }
184
185 for (int ii = 0; ii < argVals.size(); ii++) {
186 Value gotVal = argVals.get(ii);
187
188 Field theField = targetClass.fieldByName(fieldNamesVarArgs[ii]);
189 Value expectedVal = targetClass.getValue(theField);
190 System.out.println(fieldNamesVarArgs[ii] + ": gotVal = " + gotVal +
191 ", expected = " + expectedVal);
192 //System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());
193 if (!gotVal.equals(expectedVal)) {
194 failure(" failure: gotVal != expected");
195 }
196 }
197 }
198
199 // a method with with one generic param
200 {
201 System.out.println("----- Testing generic args");
202 bpe = resumeTo("ArgumentValuesTarg", 53);
203 StackFrame frame = bpe.thread().frame(0);
204
205 Method mmm = frame.location().method();
206 System.out.println("Arg types are: " + mmm.argumentTypeNames());
207
208 List<Value> argVals = frame.getArgumentValues();
209 if (argVals.size() != 1) {
210 failure("failure: Expected one arg, got: " + argVals);
211 } else {
212 Value gotVal = argVals.get(0);
213
214 Field theField = targetClass.fieldByName("intList");
215 Value expectedVal = targetClass.getValue(theField);
216 System.out.println("intList " + ": gotVal = " + gotVal +
217 ", expected = " + expectedVal);
218 if (!gotVal.equals(expectedVal)) {
219 failure("failure: gotVal != expected");
220 }
221 }
222 }
223
224 // test instance method call
225 {
226 System.out.println("----- Testing instance method call");
227 bpe = resumeTo("ArgumentValuesTarg", 57);
228 StackFrame frame = bpe.thread().frame(0);
229
230 Method mmm = frame.location().method();
231 System.out.println("Arg types are: " + mmm.argumentTypeNames());
232
233 List<Value> argVals = frame.getArgumentValues();
234
235 if (argVals.size() != fieldNamesInstance.length) {
236 failure("failure: Varargs: expected length " + fieldNamesInstance.length +
237 " args, got: " + argVals);
238 }
239 for (int ii = 0; ii < argVals.size(); ii++) {
240 Value gotVal = argVals.get(ii);
241
242 Field theField = targetClass.fieldByName(fieldNamesInstance[ii]);
243 Value expectedVal = targetClass.getValue(theField);
244 System.out.println(fieldNamesInstance[ii] + ": gotVal = " + gotVal +
245 ", expected = " + expectedVal);
246 //System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());
247 if (!gotVal.equals(expectedVal)) {
|
1 /*
2 * Copyright (c) 2007, 2017, 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 // THIS TEST IS LINE NUMBER SENSITIVE
25
26 /**
27 * @test
28 * @bug 4490824
29 * @summary JDI: provide arguments when no debug attributes present
30 *
31 * @author jjh
32 *
33 * @run build TestScaffold VMConnection TargetListener TargetAdapter
34 * @run compile ArgumentValuesTest.java
35 * @run driver ArgumentValuesTest
36 */
37 import com.sun.jdi.*;
38 import com.sun.jdi.event.*;
39 import com.sun.jdi.request.*;
40
41 import java.util.*;
42
43 /********** target program **********/
44
45 class ArgumentValuesTarg {
46 static char s_char1 = 'a';
47 static byte s_byte1 = (byte) 146;
48 static short s_short1 = (short) 28123;
49 static int s_int1 = 3101246;
50 static long s_long1 = 0x0123456789ABCDEFL;
51 static float s_float1 = 2.3145f;
52 static double s_double1 = 1.469d;
53 static int s_iarray1[] = {1, 2, 3};
54 static int s_marray1[][] = {{1, 2, 3}, {3, 4, 5}, null, {6, 7}};
55 static String s_sarray1[] = {"abc", null, "def", "ghi"};
56 static String s_string1 = "abcdef";
57
58 static String s_string2 = "xy";
59 static String s_string3 = "wz";
60 static List<Integer> intList;
61
62 public static void noArgs() {
63 int index = 0; // line NO_ARGS_LINE_1
64 }
65
66 public static void allArgs(char p_char, byte p_byte, short p_short,
67 int p_int, long p_long, float p_float,
68 double p_double, int p_iarray[], int p_marray[][],
69 String p_sarray1[], String p_string) {
70 int index = 0; // line ALL_ARGS_LINE_1
71 }
72
73 public static void varArgs(String ... p1) {
74 int index = 0; // line VAR_ARGS_LINE_1
75 }
76
77 public static void genericArgs(List<Integer> p1) {
78 int index = 0; // line GENERIC_ARGS_LINE_1
79 }
80
81 public void instanceMethod(char p_char, byte p_byte) {
82 int index = 0; // line INSTANCE_METHOD_LINE_1
83 }
84
85 public static void main(String[] args) {
86 System.out.println("Howdy!");
87 allArgs(
88 s_char1, s_byte1, s_short1, s_int1,
89 s_long1, s_float1, s_double1, s_iarray1,
90 s_marray1, s_sarray1, s_string1);
91
92 noArgs();
93 varArgs(s_string1, s_string2, s_string3);
94 ArgumentValuesTarg avt = new ArgumentValuesTarg();
95 intList = new ArrayList<Integer>(10);
96 intList.add(10);
97 intList.add(20);
98 genericArgs(intList);
99
100 avt.instanceMethod(s_char1, s_byte1);
101
102 System.out.println("Goodbye from ArgumentValuesTarg!");
103 }
104 }
105
106 /********** test program **********/
107
108 public class ArgumentValuesTest extends TestScaffold {
109 static final int NO_ARGS_LINE_1 = 63;
110 static final int ALL_ARGS_LINE_1 = 70;
111 static final int VAR_ARGS_LINE_1 = 74;
112 static final int GENERIC_ARGS_LINE_1 = 78;
113 static final int INSTANCE_METHOD_LINE_1 = 82;
114
115 // Must be in same order as args to allArgs(....)
116 String fieldNames[] = {"s_char1", "s_byte1", "s_short1", "s_int1",
117 "s_long1", "s_float1", "s_double1", "s_iarray1",
118 "s_marray1", "s_sarray1", "s_string1"};
119
120 String fieldNamesVarArgs[] = {"s_string1", "s_string2", "s_string3"};
121 String fieldNamesInstance[] = {"s_char1", "s_byte1"};
122
123 ReferenceType targetClass;
124 ThreadReference mainThread;
125
126 ArgumentValuesTest (String args[]) {
127 super(args);
128 }
129
130 public static void main(String[] args)
131 throws Exception
132 {
133 new ArgumentValuesTest (args).startTests();
134 }
135
136 /********** test core **********/
137
138 protected void runTests()
139 throws Exception
140 {
141 /*
142 * Get to the top of main() to determine targetClass and mainThread
143 */
144 BreakpointEvent bpe = startToMain("ArgumentValuesTarg");
145 targetClass = bpe.location().declaringType();
146 mainThread = bpe.thread();
147 EventRequestManager erm = vm().eventRequestManager();
148
149
150 {
151 System.out.println("----- Testing each type of arg");
152 bpe = resumeTo("ArgumentValuesTarg", ALL_ARGS_LINE_1);
153 StackFrame frame = bpe.thread().frame(0);
154
155 Method mmm = frame.location().method();
156 System.out.println("Arg types are: " + mmm.argumentTypeNames());
157
158 List<Value> argVals = frame.getArgumentValues();
159
160 if (argVals.size() != fieldNames.length) {
161 failure("failure: Varargs: expected length " + fieldNames.length +
162 " args, got: " + argVals);
163 }
164 for (int ii = 0; ii < argVals.size(); ii++) {
165 Value gotVal = argVals.get(ii);
166
167 Field theField = targetClass.fieldByName(fieldNames[ii]);
168 Value expectedVal = targetClass.getValue(theField);
169 System.out.println(fieldNames[ii] + ": gotVal = " + gotVal +
170 ", expected = " + expectedVal);
171 //System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());
172 if (!gotVal.equals(expectedVal)) {
173 failure(" failure: gotVal != expected");
174 }
175 }
176 }
177
178 // a method with no params
179 {
180 System.out.println("----- Testing no args");
181 bpe = resumeTo("ArgumentValuesTarg", NO_ARGS_LINE_1);
182 StackFrame frame = bpe.thread().frame(0);
183
184 Method mmm = frame.location().method();
185 System.out.println("Arg types are: " + mmm.argumentTypeNames());
186
187 List<Value> argVals = frame.getArgumentValues();
188 if (argVals.size() == 0) {
189 System.out.println("Empty arg list ok");
190 } else {
191 failure("failure: Expected empty val list, got: " + argVals);
192 }
193 }
194
195 // var args. 3 Strings are passed in and they appear
196 // as a String[3] in the method.
197 {
198 System.out.println("----- Testing var args");
199 bpe = resumeTo("ArgumentValuesTarg", VAR_ARGS_LINE_1);
200 StackFrame frame = bpe.thread().frame(0);
201
202 Method mmm = frame.location().method();
203 System.out.println("Arg types are: " + mmm.argumentTypeNames());
204
205 List<Value> argVals = frame.getArgumentValues();
206 if (argVals.size() != 1) {
207 failure("failure: Varargs: expected one arg, got: " + argVals);
208 }
209 argVals = ((ArrayReference)argVals.get(0)).getValues();
210
211 if (argVals.size() != fieldNamesVarArgs.length) {
212 failure("failure: Varargs: expected length " + fieldNamesVarArgs.length +
213 " array elements, got: " + argVals);
214 }
215
216 for (int ii = 0; ii < argVals.size(); ii++) {
217 Value gotVal = argVals.get(ii);
218
219 Field theField = targetClass.fieldByName(fieldNamesVarArgs[ii]);
220 Value expectedVal = targetClass.getValue(theField);
221 System.out.println(fieldNamesVarArgs[ii] + ": gotVal = " + gotVal +
222 ", expected = " + expectedVal);
223 //System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());
224 if (!gotVal.equals(expectedVal)) {
225 failure(" failure: gotVal != expected");
226 }
227 }
228 }
229
230 // a method with with one generic param
231 {
232 System.out.println("----- Testing generic args");
233 bpe = resumeTo("ArgumentValuesTarg", GENERIC_ARGS_LINE_1);
234 StackFrame frame = bpe.thread().frame(0);
235
236 Method mmm = frame.location().method();
237 System.out.println("Arg types are: " + mmm.argumentTypeNames());
238
239 List<Value> argVals = frame.getArgumentValues();
240 if (argVals.size() != 1) {
241 failure("failure: Expected one arg, got: " + argVals);
242 } else {
243 Value gotVal = argVals.get(0);
244
245 Field theField = targetClass.fieldByName("intList");
246 Value expectedVal = targetClass.getValue(theField);
247 System.out.println("intList " + ": gotVal = " + gotVal +
248 ", expected = " + expectedVal);
249 if (!gotVal.equals(expectedVal)) {
250 failure("failure: gotVal != expected");
251 }
252 }
253 }
254
255 // test instance method call
256 {
257 System.out.println("----- Testing instance method call");
258 bpe = resumeTo("ArgumentValuesTarg", INSTANCE_METHOD_LINE_1);
259 StackFrame frame = bpe.thread().frame(0);
260
261 Method mmm = frame.location().method();
262 System.out.println("Arg types are: " + mmm.argumentTypeNames());
263
264 List<Value> argVals = frame.getArgumentValues();
265
266 if (argVals.size() != fieldNamesInstance.length) {
267 failure("failure: Varargs: expected length " + fieldNamesInstance.length +
268 " args, got: " + argVals);
269 }
270 for (int ii = 0; ii < argVals.size(); ii++) {
271 Value gotVal = argVals.get(ii);
272
273 Field theField = targetClass.fieldByName(fieldNamesInstance[ii]);
274 Value expectedVal = targetClass.getValue(theField);
275 System.out.println(fieldNamesInstance[ii] + ": gotVal = " + gotVal +
276 ", expected = " + expectedVal);
277 //System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());
278 if (!gotVal.equals(expectedVal)) {
|