jdk/test/com/sun/jdi/RequestReflectionTest.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /**
       
    25  *  @test
       
    26  *  @bug 4425840
       
    27  *  @author Robert Field
       
    28  *
       
    29  *  @run build TestScaffold VMConnection TargetListener TargetAdapter
       
    30  *  @run compile -g RequestReflectionTest.java
       
    31  *  @run main RequestReflectionTest
       
    32  *
       
    33  *  @summary RequestReflectionTest checks to see that reflective
       
    34  *  accessors on EventRequests return what they are given.
       
    35  */
       
    36 import com.sun.jdi.*;
       
    37 import com.sun.jdi.event.*;
       
    38 import com.sun.jdi.request.*;
       
    39 
       
    40 import java.util.List;
       
    41 
       
    42 
       
    43     /********** target program **********/
       
    44 
       
    45 class RequestReflectionTarg {
       
    46     int foo = 9;
       
    47 
       
    48     public static void main(String args[]) {
       
    49         System.out.println("Why, hello there...");
       
    50         (new RequestReflectionTarg()).bar();
       
    51     }
       
    52 
       
    53     void bar() {
       
    54         ++foo;
       
    55     }
       
    56 }
       
    57 
       
    58     /********** test program **********/
       
    59 
       
    60 public class RequestReflectionTest extends TestScaffold {
       
    61 
       
    62     RequestReflectionTest (String args[]) {
       
    63         super(args);
       
    64     }
       
    65 
       
    66     public static void main(String[] args)      throws Exception {
       
    67         new RequestReflectionTest(args).startTests();
       
    68     }
       
    69 
       
    70     /********** test core **********/
       
    71 
       
    72     protected void runTests() throws Exception {
       
    73         /*
       
    74          * Get to the top of main():
       
    75          */
       
    76         BreakpointEvent bpe = startToMain("RequestReflectionTarg");
       
    77         ReferenceType targ = bpe.location().declaringType();
       
    78         ThreadReference thread = bpe.thread();
       
    79 
       
    80         Field fooField = targ.fieldByName("foo");
       
    81         if (fooField == null) {
       
    82             throw new Exception("test error: cannot find field foo");
       
    83         }
       
    84         List meths = targ.methodsByName("bar");
       
    85         if (meths.size() != 1) {
       
    86             throw new Exception("test error: should be one bar()");
       
    87         }
       
    88         Method barMethod = (Method)meths.get(0);
       
    89 
       
    90         List exClasses = vm().classesByName("java.lang.Exception");
       
    91         if (exClasses.size() != 1) {
       
    92             throw new Exception(
       
    93                "test error: should be one java.lang.Exception");
       
    94         }
       
    95         ReferenceType exceptionClass = (ReferenceType)exClasses.get(0);
       
    96         EventRequestManager erm = eventRequestManager();
       
    97 
       
    98         StepRequest sr =
       
    99             erm.createStepRequest(thread, StepRequest.STEP_MIN,
       
   100                                   StepRequest.STEP_OUT);
       
   101         sr.setSuspendPolicy(EventRequest.SUSPEND_NONE);
       
   102         sr.enable();
       
   103         if (!sr.thread().equals(thread)) {
       
   104             throw new Exception(
       
   105                     "RequestReflectionTest fail: exceptions do not match " +
       
   106                     thread + " != " + sr.thread());
       
   107         }
       
   108         if (sr.size() != StepRequest.STEP_MIN) {
       
   109             throw new Exception(
       
   110                     "RequestReflectionTest fail: size does not match " +
       
   111                     sr.size() + " != " + StepRequest.STEP_MIN);
       
   112         }
       
   113         if (sr.depth() != StepRequest.STEP_OUT) {
       
   114             throw new Exception(
       
   115                     "RequestReflectionTest fail: depth does not match " +
       
   116                     sr.depth() + " != " + StepRequest.STEP_OUT);
       
   117         }
       
   118         if (sr.suspendPolicy() != EventRequest.SUSPEND_NONE) {
       
   119             throw new Exception(
       
   120                     "RequestReflectionTest fail: wrong suspend policy " +
       
   121                     sr.suspendPolicy());
       
   122         }
       
   123         if (!sr.isEnabled()) {
       
   124             throw new Exception(
       
   125                     "RequestReflectionTest fail: should be enabled");
       
   126         }
       
   127         sr.disable();
       
   128 
       
   129         sr = erm.createStepRequest(thread, StepRequest.STEP_LINE,
       
   130                                   StepRequest.STEP_INTO);
       
   131         sr.setSuspendPolicy(EventRequest.SUSPEND_ALL);
       
   132         if (sr.size() != StepRequest.STEP_LINE) {
       
   133             throw new Exception(
       
   134                     "RequestReflectionTest fail: size does not match " +
       
   135                     sr.size() + " != " + StepRequest.STEP_LINE);
       
   136         }
       
   137         if (sr.depth() != StepRequest.STEP_INTO) {
       
   138             throw new Exception(
       
   139                     "RequestReflectionTest fail: depth does not match " +
       
   140                     sr.depth() + " != " + StepRequest.STEP_INTO);
       
   141         }
       
   142         if (sr.suspendPolicy() != EventRequest.SUSPEND_ALL) {
       
   143             throw new Exception(
       
   144                     "RequestReflectionTest fail: wrong suspend policy " +
       
   145                     sr.suspendPolicy());
       
   146         }
       
   147         if (sr.isEnabled()) {
       
   148             throw new Exception(
       
   149                     "RequestReflectionTest fail: should not be enabled");
       
   150         }
       
   151 
       
   152         AccessWatchpointRequest awr =
       
   153             erm.createAccessWatchpointRequest(fooField);
       
   154         if (!awr.field().equals(fooField)) {
       
   155             throw new Exception(
       
   156                     "RequestReflectionTest fail: fields do not match " +
       
   157                     fooField + " != " + awr.field());
       
   158         }
       
   159         if (awr.suspendPolicy() != EventRequest.SUSPEND_ALL) {
       
   160             throw new Exception(
       
   161                     "RequestReflectionTest fail: wrong suspend policy " +
       
   162                     awr.suspendPolicy());
       
   163         }
       
   164         if (awr.isEnabled()) {
       
   165             throw new Exception(
       
   166                     "RequestReflectionTest fail: should not be enabled");
       
   167         }
       
   168         BreakpointRequest bpr =
       
   169             erm.createBreakpointRequest(barMethod.location());
       
   170         bpr.setSuspendPolicy(EventRequest.SUSPEND_NONE);
       
   171         bpr.enable();
       
   172         if (!bpr.location().method().equals(barMethod)) {
       
   173             throw new Exception(
       
   174                     "RequestReflectionTest fail: methodss do not match " +
       
   175                     barMethod + " != " + bpr.location().method());
       
   176         }
       
   177         if (bpr.suspendPolicy() != EventRequest.SUSPEND_NONE) {
       
   178             throw new Exception(
       
   179                     "RequestReflectionTest fail: wrong suspend policy " +
       
   180                     bpr.suspendPolicy());
       
   181         }
       
   182         if (!bpr.isEnabled()) {
       
   183             throw new Exception(
       
   184                     "RequestReflectionTest fail: should be enabled");
       
   185         }
       
   186         ExceptionRequest exr =
       
   187             erm.createExceptionRequest(exceptionClass, true, false);
       
   188         exr.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
       
   189         exr.enable();
       
   190         exr.disable();
       
   191         if (!exr.exception().equals(exceptionClass)) {
       
   192             throw new Exception(
       
   193                     "RequestReflectionTest fail: not java.lang.Exception " +
       
   194                     exr.exception());
       
   195         }
       
   196         if (exr.suspendPolicy() != EventRequest.SUSPEND_EVENT_THREAD) {
       
   197             throw new Exception(
       
   198                     "RequestReflectionTest fail: wrong suspend policy " +
       
   199                     exr.suspendPolicy());
       
   200         }
       
   201         if (exr.isEnabled()) {
       
   202             throw new Exception(
       
   203                     "RequestReflectionTest fail: should not be enabled");
       
   204         }
       
   205 
       
   206         listenUntilVMDisconnect();
       
   207 
       
   208         println("RequestReflectionTest: passed");
       
   209     }
       
   210 }