jdk/test/com/sun/jdi/GetSetLocalTest.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 2 90ce3da70b43
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/** hard coded linenumbers in other tests - DO NOT CHANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 *  @test/nodynamiccopyright/
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *  @bug 4300412
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *  @summary Test GetLocal* and SetLocal* functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *  @author Serguei Spitsyn
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  @run compile -g GetSetLocalTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  @run main GetSetLocalTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
class GetSetLocalTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
        int intVar = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
        System.out.println("GetSetLocalTarg: Started");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
        intVar = staticMeth(intVar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
        System.out.println("GetSetLocalTarg: Finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
     * The line numbers of this method *MUST NOT* be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
     * because the testing algorithm counts on this layout!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
     * It's in calls to resumeTo("GetSetLocalTarg", line).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    public static int staticMeth(int intArg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
        System.out.println("staticMeth: Started");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        int result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
             { boolean bool_1 = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
             boolean bool_2 = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
             { byte byte_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
             byte byte_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
             { char   char_1 = '1';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
             char   char_2 = '2';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
             { short  short_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
             short  short_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
             { int    int_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
             int int_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
             { long long_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             long long_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
             { float  float_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
             float float_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
             { double double_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
             double double_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
             { String string_1 = "1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
             String string_2 = "2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
             intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             { Object obj_1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
               intArg++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
             Object obj_2 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
             intArg++;  // <-- Last stop is at this point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                        //     Only obj_2 and intArg are valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                        // Note: even result is not valid here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        result = 10;    // <- This is first init of result var
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        System.out.println("staticMeth: Finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
public class GetSetLocalTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    GetSetLocalTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        new GetSetLocalTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /********** test assist **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    Method getMethod(String className, String methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        List refs = vm().classesByName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (refs.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            failure(" Failure: " + refs.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    " ReferenceTypes named: " + className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        ReferenceType refType = (ReferenceType)refs.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        List meths = refType.methodsByName(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (meths.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            failure(" Failure: " + meths.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    " methods named: " + methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return (Method)meths.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    List printAllVariables(String className, String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        println("printAllVariables for method: " + className + "." + methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Method method = getMethod(className, methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        List localVars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            localVars = method.variables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            println(" Success: got a list of all method variables: " + methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        catch (com.sun.jdi.AbsentInformationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            failure(" Failure: AbsentInformationException has been thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        for (Iterator it = localVars.iterator(); it.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            LocalVariable lv = (LocalVariable) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            printOneVariable(lv, index++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return localVars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    void checkGetSetAllVariables(List localVars, StackFrame frame) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        println("\n checkGetSetAllVariables for method at particular frame location: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        for (Iterator it = localVars.iterator(); it.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            LocalVariable lv = (LocalVariable) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            String lv_name = lv.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            print(" Variable " + lv_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                Value val = frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                frame.setValue(lv, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                println(" has been get/set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                if (lv_name.compareTo("intArg") != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    lv_name.compareTo("obj_2")  != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    failure(" Failure: AbsentInformationException is expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            } catch (java.lang.IllegalArgumentException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                println(" is not valid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if (lv_name.compareTo("intArg") == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    lv_name.compareTo("obj_2")  == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    failure(" Failure: AbsentInformationException was not expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    void printOneVariable(LocalVariable lv, int index) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        String tyname = lv.typeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        println(" Var  name: " + lv.name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        println(" Var  type: " + tyname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        println(" Var index: " + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        println(" Signature: " + lv.type().signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // Sorry, there is no way to get (and print)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // a local variable slot numbers using JDI!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    void printFrameVariables(StackFrame frame) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        List localVars = frame.visibleVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        println("\n Visible variables at this point are: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        for (Iterator it = localVars.iterator(); it.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            LocalVariable lv = (LocalVariable) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            printOneVariable(lv, index++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            println(" Var value: " + frame.getValue(lv));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    BooleanValue incrValue(BooleanValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        boolean value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return vm().mirrorOf(!value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    ByteValue incrValue(ByteValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        byte value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    CharValue incrValue(CharValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        char value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    ShortValue incrValue(ShortValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        short value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    IntegerValue incrValue(IntegerValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    LongValue incrValue(LongValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        long value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    FloatValue incrValue(FloatValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        float value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return  vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    DoubleValue incrValue(DoubleValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        double value = val.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return vm().mirrorOf(++value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    StringReference incrValue(StringReference val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        String newstr = new String("Set String ").concat(val.value());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return vm().mirrorOf(newstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    void checkSetBooleanTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        BooleanValue get = (BooleanValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        BooleanValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        get = (BooleanValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        boolean v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        boolean v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    void checkSetByteTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        ByteValue get = (ByteValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        ByteValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        get = (ByteValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        byte v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        byte v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    void checkSetCharTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        CharValue get = (CharValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        CharValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        get = (CharValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        char v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        char v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    void checkSetShortTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        ShortValue get = (ShortValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        ShortValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        get = (ShortValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        short v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        short v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    void checkSetIntegerTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        IntegerValue get = (IntegerValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        IntegerValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        get = (IntegerValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        int v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        int v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    void checkSetLongTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        LongValue get = (LongValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        LongValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        get = (LongValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        long v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        long v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    void checkSetFloatTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        FloatValue get = (FloatValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        FloatValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        get = (FloatValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        float v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        float v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    void checkSetDoubleTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        DoubleValue get = (DoubleValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        DoubleValue set = incrValue(get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        get = (DoubleValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        double v1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        double v2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (v1 == v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            println(" Success: Value was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            failure(" Failure: Value was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    void checkSetStringTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        StringReference get = (StringReference) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        StringReference set = incrValue((StringReference) frame.getValue(lv));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        get = (StringReference) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        String str1 = get.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        String str2 = set.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        // Check if set was done properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (str1.compareTo(str2) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            println(" Success: String was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            failure(" Failure: String was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    void checkSetObjectTypes(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        ObjectReference get = (ObjectReference) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        ObjectReference set = get; // FIXME: Don't know how to create a mirror of Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        // To get the new value which has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        get = (ObjectReference) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        println(" Var  Set: " + set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        println(" Var  Get: " + get);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (set.uniqueID() == get.uniqueID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            println(" Success: Object was set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            failure(" Failure: Object was NOT set correctly!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    void negativeIntegerCheck(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            IntegerValue get = (IntegerValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            println(" Get: No ClassCastException error!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        } catch(java.lang.ClassCastException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            println(" Success: Get: ClassCastException error has cought as expected!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            IntegerValue set = vm().mirrorOf((int) 0x3F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            println(" Set: No InvalidTypeException with Integer error!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        } catch(com.sun.jdi.InvalidTypeException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            println(" Success: Set: InvalidTypeException with Integer error has cought as expected!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    void negativeFloatCheck(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            FloatValue get = (FloatValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            println(" Get: No ClassCastException error!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        } catch(java.lang.ClassCastException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            println(" Success: Get: ClassCastException with Float error has cought as expected!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            FloatValue set = vm().mirrorOf(1.2345f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            println(" Set: No InvalidTypeException with Float error!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        } catch(com.sun.jdi.InvalidTypeException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            println(" Success: Set: InvalidTypeException error has cought as expected!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    void negativeDoubleCheck(StackFrame frame, LocalVariable lv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            DoubleValue get = (DoubleValue) frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            println(" Get: No ClassCastException error!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        } catch(java.lang.ClassCastException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            println(" Success: Get: ClassCastException  with Double error has cought as expected!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            DoubleValue set = vm().mirrorOf(1.2345E02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            frame.setValue(lv, set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            println(" Set: No InvalidTypeException with Double error!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        } catch(com.sun.jdi.InvalidTypeException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            println(" Success: Set: InvalidTypeException error has cought as expected!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    void checkSetFrameVariables(StackFrame frame) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        List localVars = frame.visibleVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        println("\n Set variable values:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        for (Iterator it = localVars.iterator(); it.hasNext();index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            LocalVariable lv = (LocalVariable) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            String signature = lv.type().signature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            switch (signature.charAt(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            case 'Z': // Boolean Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                checkSetBooleanTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            case 'B': // Byte Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                checkSetByteTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            case 'C': // Char Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                checkSetCharTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            case 'S': // Short Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                checkSetShortTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            case 'I': // Integer Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                checkSetIntegerTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                if (index > 0) { // To skip integer method parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            case 'J': // Long Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                checkSetLongTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            case 'F': // Float Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                checkSetFloatTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                negativeDoubleCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            case 'D': // Double Type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                checkSetDoubleTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                if (signature.compareTo("Ljava/lang/String;") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    checkSetStringTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                if (signature.compareTo("Ljava/lang/Object;") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    checkSetObjectTypes(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    negativeIntegerCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    negativeFloatCheck(frame, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                printOneVariable(lv, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                failure(" Failure: List of local variables has a wrong entry!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * Get to the top of main() to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        BreakpointEvent bpe = startToMain("GetSetLocalTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        println("startToMain(GetSetLocalTarg)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        List localVars = printAllVariables("GetSetLocalTarg", "staticMeth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        println("targetClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        println("mainThread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        EventRequestManager erm = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        println("EventRequestManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        StackFrame frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        for (int line = 38; line < 118; line += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            println("\n resumeTo(GetSetLocalTarg, " + line + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            bpe = resumeTo("GetSetLocalTarg", line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            frame = bpe.thread().frame(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            printFrameVariables(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            checkSetFrameVariables(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // Check if we can Get/Set all local vars using last frame state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        checkGetSetAllVariables(localVars, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * resume until the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            println("GetSetLocalTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            throw new Exception("GetSetLocalTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
}