rev 16922 : 8177507: line number sensitive tests for jdi should be unified
Reviewed-by: duke

   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)) {
 248                     failure("     failure: gotVal != expected");
 249                 }
 250             }
 251         }
 252 
 253 
 254         /*
 255          * resume the target listening for events
 256          */
 257         listenUntilVMDisconnect();
 258 
 259         /*
 260          * deal with results of test if anything has called failure("foo")
 261          * testFailed will be true
 262          */
 263         if (!testFailed) {
 264             println("ArgumentValuesTest: passed");
 265         } else {
 266             throw new Exception("ArgumentValuesTest: failed");
 267         }
 268     }
 269 }
--- EOF ---