0N/A/*
2362N/A * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4425840
0N/A * @author Robert Field
0N/A *
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
0N/A * @run compile -g RequestReflectionTest.java
0N/A * @run main RequestReflectionTest
0N/A *
0N/A * @summary RequestReflectionTest checks to see that reflective
0N/A * accessors on EventRequests return what they are given.
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.List;
0N/A
0N/A
0N/A /********** target program **********/
0N/A
0N/Aclass RequestReflectionTarg {
0N/A int foo = 9;
0N/A
0N/A public static void main(String args[]) {
0N/A System.out.println("Why, hello there...");
0N/A (new RequestReflectionTarg()).bar();
0N/A }
0N/A
0N/A void bar() {
0N/A ++foo;
0N/A }
0N/A}
0N/A
0N/A /********** test program **********/
0N/A
0N/Apublic class RequestReflectionTest extends TestScaffold {
0N/A
0N/A RequestReflectionTest (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new RequestReflectionTest(args).startTests();
0N/A }
0N/A
0N/A /********** test core **********/
0N/A
0N/A protected void runTests() throws Exception {
0N/A /*
0N/A * Get to the top of main():
0N/A */
0N/A BreakpointEvent bpe = startToMain("RequestReflectionTarg");
0N/A ReferenceType targ = bpe.location().declaringType();
0N/A ThreadReference thread = bpe.thread();
0N/A
0N/A Field fooField = targ.fieldByName("foo");
0N/A if (fooField == null) {
0N/A throw new Exception("test error: cannot find field foo");
0N/A }
0N/A List meths = targ.methodsByName("bar");
0N/A if (meths.size() != 1) {
0N/A throw new Exception("test error: should be one bar()");
0N/A }
0N/A Method barMethod = (Method)meths.get(0);
0N/A
0N/A List exClasses = vm().classesByName("java.lang.Exception");
0N/A if (exClasses.size() != 1) {
0N/A throw new Exception(
0N/A "test error: should be one java.lang.Exception");
0N/A }
0N/A ReferenceType exceptionClass = (ReferenceType)exClasses.get(0);
0N/A EventRequestManager erm = eventRequestManager();
0N/A
0N/A StepRequest sr =
0N/A erm.createStepRequest(thread, StepRequest.STEP_MIN,
0N/A StepRequest.STEP_OUT);
0N/A sr.setSuspendPolicy(EventRequest.SUSPEND_NONE);
0N/A sr.enable();
0N/A if (!sr.thread().equals(thread)) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: exceptions do not match " +
0N/A thread + " != " + sr.thread());
0N/A }
0N/A if (sr.size() != StepRequest.STEP_MIN) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: size does not match " +
0N/A sr.size() + " != " + StepRequest.STEP_MIN);
0N/A }
0N/A if (sr.depth() != StepRequest.STEP_OUT) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: depth does not match " +
0N/A sr.depth() + " != " + StepRequest.STEP_OUT);
0N/A }
0N/A if (sr.suspendPolicy() != EventRequest.SUSPEND_NONE) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: wrong suspend policy " +
0N/A sr.suspendPolicy());
0N/A }
0N/A if (!sr.isEnabled()) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: should be enabled");
0N/A }
0N/A sr.disable();
0N/A
0N/A sr = erm.createStepRequest(thread, StepRequest.STEP_LINE,
0N/A StepRequest.STEP_INTO);
0N/A sr.setSuspendPolicy(EventRequest.SUSPEND_ALL);
0N/A if (sr.size() != StepRequest.STEP_LINE) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: size does not match " +
0N/A sr.size() + " != " + StepRequest.STEP_LINE);
0N/A }
0N/A if (sr.depth() != StepRequest.STEP_INTO) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: depth does not match " +
0N/A sr.depth() + " != " + StepRequest.STEP_INTO);
0N/A }
0N/A if (sr.suspendPolicy() != EventRequest.SUSPEND_ALL) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: wrong suspend policy " +
0N/A sr.suspendPolicy());
0N/A }
0N/A if (sr.isEnabled()) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: should not be enabled");
0N/A }
0N/A
0N/A AccessWatchpointRequest awr =
0N/A erm.createAccessWatchpointRequest(fooField);
0N/A if (!awr.field().equals(fooField)) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: fields do not match " +
0N/A fooField + " != " + awr.field());
0N/A }
0N/A if (awr.suspendPolicy() != EventRequest.SUSPEND_ALL) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: wrong suspend policy " +
0N/A awr.suspendPolicy());
0N/A }
0N/A if (awr.isEnabled()) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: should not be enabled");
0N/A }
0N/A BreakpointRequest bpr =
0N/A erm.createBreakpointRequest(barMethod.location());
0N/A bpr.setSuspendPolicy(EventRequest.SUSPEND_NONE);
0N/A bpr.enable();
0N/A if (!bpr.location().method().equals(barMethod)) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: methodss do not match " +
0N/A barMethod + " != " + bpr.location().method());
0N/A }
0N/A if (bpr.suspendPolicy() != EventRequest.SUSPEND_NONE) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: wrong suspend policy " +
0N/A bpr.suspendPolicy());
0N/A }
0N/A if (!bpr.isEnabled()) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: should be enabled");
0N/A }
0N/A ExceptionRequest exr =
0N/A erm.createExceptionRequest(exceptionClass, true, false);
0N/A exr.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
0N/A exr.enable();
0N/A exr.disable();
0N/A if (!exr.exception().equals(exceptionClass)) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: not java.lang.Exception " +
0N/A exr.exception());
0N/A }
0N/A if (exr.suspendPolicy() != EventRequest.SUSPEND_EVENT_THREAD) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: wrong suspend policy " +
0N/A exr.suspendPolicy());
0N/A }
0N/A if (exr.isEnabled()) {
0N/A throw new Exception(
0N/A "RequestReflectionTest fail: should not be enabled");
0N/A }
0N/A
0N/A listenUntilVMDisconnect();
0N/A
0N/A println("RequestReflectionTest: passed");
0N/A }
0N/A}