jdk/test/com/sun/jdi/MethodExitReturnValuesTest.java
author jjg
Thu, 22 May 2008 15:51:41 -0700
changeset 655 1ebc7ce89018
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6705945: com.sun.tools.javac.zip files do not have valid copyright Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 4195445 6204179
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary JDWP, JDI: Add return value to Method Exit Event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author Jim Holmlund
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run compile -g MethodExitReturnValuesTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run main MethodExitReturnValuesTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This test has a debuggee which calls a static method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for each kind of JDI Value, and then an instance method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * for each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The debugger turns on MethodExitEvents and checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * that the right return values are included in the MethodExitEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Each value is stored in a static var in the debuggee.  The debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * gets the values from these static vars to check for correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * return values in the MethodExitEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
class MethodExitReturnValuesTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // These are the values that will be returned by the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static URL[] urls = new URL[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static byte      byteValue = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static char      charValue = 'x';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static double    doubleValue = 2.2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static float     floatValue = 3.3f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static int       intValue = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static long      longValue = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static short     shortValue = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static boolean   booleanValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static Class       classValue = Object.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static ClassLoader classLoaderValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            urls[0] = new URL("hi there");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } catch (java.net.MalformedURLException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        classLoaderValue = new URLClassLoader(urls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static Thread      threadValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static ThreadGroup threadGroupValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static String      stringValue = "abc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static int[]       intArrayValue = new int[] {1, 2, 3};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static MethodExitReturnValuesTarg  objectValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        new MethodExitReturnValuesTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public String ivar = stringValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // arrays to be used in calls to native methods Array.get...(....)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static byte[]    arrByte      = new byte[]    {byteValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static char[]    arrChar      = new char[]    {charValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static double[]  arrDouble    = new double[]  {doubleValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static float[]   arrFloat     = new float[]   {floatValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static int[]     arrInt       = new int[]     {intValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static long[]    arrLong      = new long[]    {longValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static short[]   arrShort     = new short[]   {shortValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static boolean[] arrBoolean   = new boolean[] {booleanValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static Object[]  arrObject    = new Object[]  {objectValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // Used to show which set of tests follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static String s_show(String p1) { return p1;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // These are the static methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static byte s_bytef()      { return byteValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static char s_charf()      { return charValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static double s_doublef()  { return doubleValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static float s_floatf()    { return floatValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static int s_intf()        { return intValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static long s_longf()      { return longValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static short s_shortf()    { return shortValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static boolean s_booleanf(){ return booleanValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static String s_stringf()  { return stringValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static Class s_classf()    { return classValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static ClassLoader s_classLoaderf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                      { return classLoaderValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static Thread s_threadf()  { threadValue = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        return threadValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static ThreadGroup s_threadGroupf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                      { threadGroupValue = threadValue.getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                        return threadGroupValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static int[] s_intArrayf() { return intArrayValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static Object s_nullObjectf() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static Object s_objectf()  { return objectValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static void s_voidf()      {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // These are the instance methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public byte i_bytef()            { return byteValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public char i_charf()            { return charValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public double i_doublef()        { return doubleValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public float i_floatf()          { return floatValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public int i_intf()              { return intValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public long i_longf()            { return longValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public short i_shortf()          { return shortValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public boolean i_booleanf()      { return booleanValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public String i_stringf()        { return stringValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public Class i_classf()          { return classValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public ClassLoader i_classLoaderf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                     { return classLoaderValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public Thread i_threadf()        { return threadValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public ThreadGroup i_threadGroupf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                     { return threadGroupValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public int[] i_intArrayf()       { return intArrayValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Object i_nullObjectf()    { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public Object i_objectf()        { return objectValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void i_voidf()            {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    static void doit(MethodExitReturnValuesTarg xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        s_show("==========  Testing static methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        s_bytef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        s_charf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        s_doublef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        s_floatf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        s_intf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        s_longf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        s_shortf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        s_booleanf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        s_stringf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        s_classf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        s_classLoaderf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        s_threadf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        s_threadGroupf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        s_intArrayf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        s_nullObjectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        s_objectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        s_voidf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        s_show("==========  Testing instance methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        xx.i_bytef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        xx.i_charf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        xx.i_doublef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        xx.i_floatf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        xx.i_intf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        xx.i_longf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        xx.i_shortf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        xx.i_booleanf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        xx.i_stringf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        xx.i_intArrayf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        xx.i_classf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        xx.i_classLoaderf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        xx.i_threadf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        xx.i_threadGroupf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        xx.i_nullObjectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        xx.i_objectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        xx.i_voidf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Prove it works for native methods too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        s_show("==========  Testing native methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        StrictMath.sin(doubleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Array.getByte(arrByte, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Array.getChar(arrChar, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Array.getDouble(arrDouble, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Array.getFloat(arrFloat, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        Array.getInt(arrInt, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        Array.getLong(arrLong, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Array.getShort(arrShort, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Array.getBoolean(arrBoolean, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Array.get(arrObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        stringValue.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // The debugger will stop at the start of main,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // enable method exit events, and then do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // a resume.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        MethodExitReturnValuesTarg xx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            new MethodExitReturnValuesTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        doit(xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
public class MethodExitReturnValuesTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Class patterns for which we don't want events (copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * from the "Trace.java" example):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *     http://java.sun.com/javase/technologies/core/toolsapis/jpda/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private String[] excludes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        "javax.*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        "sun.*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        "com.sun.*"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    static VirtualMachineManager vmm ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    ClassType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    Field theValueField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    static int successes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    static final int expectedSuccesses = 44;  // determined by inspection :-)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    MethodExitReturnValuesTest(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        MethodExitReturnValuesTest meee = new MethodExitReturnValuesTest(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        vmm = Bootstrap.virtualMachineManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    // These are the methods that check for correct return values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    void ckByteValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Field theValueField = targetClass.fieldByName("byteValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        ByteValue theValue = (ByteValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        byte vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        byte rv = ((ByteValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            failure("failure: byte: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            System.out.println("Passed: byte " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    void ckCharValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        Field theValueField = targetClass.fieldByName("charValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        CharValue theValue = (CharValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        char vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        char rv = ((CharValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            failure("failure: char: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            System.out.println("Passed: char " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    void ckDoubleValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Field theValueField = targetClass.fieldByName("doubleValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        DoubleValue theValue = (DoubleValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        double vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        double rv = ((DoubleValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            failure("failure: double: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            System.out.println("Passed: double " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    void ckFloatValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        Field theValueField = targetClass.fieldByName("floatValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        FloatValue theValue = (FloatValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        float vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        float rv = ((FloatValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            failure("failure: float: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            System.out.println("Passed: float " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    void ckIntValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Field theValueField = targetClass.fieldByName("intValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        IntegerValue theValue = (IntegerValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        int vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        int rv = ((IntegerValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            failure("failure: int: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            System.out.println("Passed: int " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    void ckLongValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Field theValueField = targetClass.fieldByName("longValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        LongValue theValue = (LongValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        long vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        long rv = ((LongValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            failure("failure: long: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            System.out.println("Passed: long " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    void ckShortValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        Field theValueField = targetClass.fieldByName("shortValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        ShortValue theValue = (ShortValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        short vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        short rv = ((ShortValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            failure("failure: short: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            System.out.println("Passed: short " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    void ckBooleanValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        Field theValueField = targetClass.fieldByName("booleanValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        BooleanValue theValue = (BooleanValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        boolean vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        boolean rv = ((BooleanValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            failure("failure: boolean: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            System.out.println("Passed: boolean " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    void ckStringValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        Field theValueField = targetClass.fieldByName("stringValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        StringReference theValue = (StringReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        String vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        String rv = ((StringReference)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            failure("failure: String: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            System.out.println("Passed: String: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    void ckClassValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        Field theValueField = targetClass.fieldByName("classValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        ClassObjectReference vv = (ClassObjectReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        ClassObjectReference rv = (ClassObjectReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            failure("failure: Class: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            System.out.println("Passed: Class: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    void ckClassLoaderValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        Field theValueField = targetClass.fieldByName("classLoaderValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        ClassLoaderReference vv = (ClassLoaderReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        ClassLoaderReference rv = (ClassLoaderReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            failure("failure: ClassLoader: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            System.out.println("Passed: ClassLoader: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    void ckThreadValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        Field theValueField = targetClass.fieldByName("threadValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        ThreadReference vv = (ThreadReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        ThreadReference rv = (ThreadReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            failure("failure: Thread: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            System.out.println("Passed: Thread: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    void ckThreadGroupValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        Field theValueField = targetClass.fieldByName("threadGroupValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        ThreadGroupReference vv = (ThreadGroupReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        ThreadGroupReference rv = (ThreadGroupReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            failure("failure: ThreadgGroup: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            System.out.println("Passed: ThreadGroup: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    void ckArrayValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        Field theValueField = targetClass.fieldByName("intArrayValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        ArrayReference theValue = (ArrayReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        IntegerValue theElem2 = (IntegerValue)theValue.getValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        ArrayReference theRetValue = (ArrayReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        IntegerValue retElem2 = (IntegerValue)theRetValue.getValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int vv = theElem2.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        int rv = retElem2.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            failure("failure: in[2]: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            System.out.println("Passed: int[2]: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    void ckNullObjectValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if (retValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            failure("failure: NullObject: expected " + null + ", got " + retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            System.out.println("Passed: NullObject: " + retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    void ckObjectValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // We will check the ivar field which we know contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        // the value of 'stringValue'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        Field theValueField = targetClass.fieldByName("stringValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        StringReference theValue = (StringReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Field theIVarField = targetClass.fieldByName("ivar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        ObjectReference theRetValue = (ObjectReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        StringReference theRetValField = (StringReference)theRetValue.getValue(theIVarField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        String vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        String rv = theRetValField.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            failure("failure: Object: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
       } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            System.out.println("Passed: Object: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    void ckVoidValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        System.out.println("Passed: Void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    void ckSinValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        double rv = ((DoubleValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        double vv = StrictMath.sin(MethodExitReturnValuesTarg.doubleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (rv != vv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            failure("failure: sin: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            System.out.println("Passed: sin " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    // This is the MethodExitEvent handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public void methodExited(MethodExitEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        String origMethodName = event.method().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (vmm.majorInterfaceVersion() >= 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            vmm.minorInterfaceVersion() >= 6 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            vm().canGetMethodReturnValues()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            Value retValue = event.returnValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            if ("sin".equals(origMethodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                ckSinValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (!origMethodName.startsWith("s_") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                !origMethodName.startsWith("i_")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                // Check native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                if ("getByte".equals(origMethodName))         ckByteValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                else if ("getChar".equals(origMethodName))    ckCharValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                else if ("getDouble".equals(origMethodName))  ckDoubleValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                else if ("getFloat".equals(origMethodName))   ckFloatValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                else if ("getInt".equals(origMethodName))     ckIntValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                else if ("getLong".equals(origMethodName))    ckLongValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                else if ("getShort".equals(origMethodName))   ckShortValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                else if ("getBoolean".equals(origMethodName)) ckBooleanValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                else if ("getObject".equals(origMethodName))  ckObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                else if ("intern".equals(origMethodName))     ckStringValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            String methodName = origMethodName.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if ("show".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                System.out.println(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if ("bytef".equals(methodName))             ckByteValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            else if ("charf".equals(methodName))        ckCharValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            else if ("doublef".equals(methodName))      ckDoubleValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            else if ("floatf".equals(methodName))       ckFloatValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            else if ("intf".equals(methodName))         ckIntValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            else if ("longf".equals(methodName))        ckLongValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            else if ("shortf".equals(methodName))       ckShortValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            else if ("booleanf".equals(methodName))     ckBooleanValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            else if ("stringf".equals(methodName))      ckStringValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            else if ("classf".equals(methodName))       ckClassValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            else if ("classLoaderf".equals(methodName)) ckClassLoaderValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            else if ("threadf".equals(methodName))      ckThreadValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            else if ("threadGroupf".equals(methodName)) ckThreadGroupValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            else if ("intArrayf".equals(methodName))    ckArrayValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            else if ("nullObjectf".equals(methodName))  ckNullObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            else if ("objectf".equals(methodName))      ckObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            else if ("voidf".equals(methodName))        ckVoidValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                failure("failure: Unknown methodName: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            System.out.println("Return Value not available for method: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        BreakpointEvent bpe = startToMain("MethodExitReturnValuesTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        targetClass = (ClassType)bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        theValueField = targetClass.fieldByName("theValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         * Ask for method exit events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        MethodExitRequest exitRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            eventRequestManager().createMethodExitRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            exitRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        exitRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        exitRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * We are now set up to receive the notifications we want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         * Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (successes != expectedSuccesses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            failure("failure: Expected " + expectedSuccesses + ", but got " + successes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        System.out.println("All done, " + successes + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            System.out.println("MethodExitReturnValuesTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            System.out.println("MethodExitReturnValuesTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            throw new Exception("MethodExitReturnValuesTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
}