0N/A/*
2362N/A * Copyright (c) 2000, 2002, 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 * @summary Test Method.variables() and the like.
0N/A *
0N/A * @author Robert Field
0N/A *
0N/A * @library scaffold
0N/A * @run build JDIScaffold VMConnection
0N/A * @run compile -g Vars.java
0N/A * @run main/othervm Vars
0N/A */
0N/A
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport java.util.*;
0N/A
0N/A/*
0N/A * This class is internal
0N/A */
0N/Aabstract class AbstractTestVars {
0N/A abstract float test1(String blah, int i);
0N/A native int test2(double k, boolean b);
0N/A String test3(short sh, long lo) {
0N/A String st = "roses";
0N/A return st;
0N/A }
0N/A}
0N/A
0N/A/*
0N/A * This class is internal
0N/A */
0N/Aclass TestVars extends AbstractTestVars {
0N/A float test1(String blah, int i) {
0N/A return (float)1.1;
0N/A }
0N/A
0N/A void hi() {
0N/A return;
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new TestVars().hi();
0N/A return;
0N/A }
0N/A}
0N/A
0N/A/*
0N/A * "Vars" test runs TestVars and makes LocalVariable queries
0N/A */
0N/Apublic class Vars extends JDIScaffold {
0N/A final String[] args;
0N/A
0N/A boolean failed = false;
0N/A
0N/A Vars(String args[]) {
0N/A super();
0N/A this.args = args;
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new Vars(args).runTests();
0N/A }
0N/A
0N/A static final int VARIABLES = 1;
0N/A static final int BYNAME = 2;
0N/A static final int ARGUMENTS = 3;
0N/A
0N/A String testCase(Method method, int which) {
0N/A try {
0N/A List vars;
0N/A switch (which) {
0N/A case VARIABLES:
0N/A vars = method.variables();
0N/A break;
0N/A case BYNAME:
0N/A vars = method.variablesByName("st");
0N/A break;
0N/A case ARGUMENTS:
0N/A vars = method.arguments();
0N/A break;
0N/A default:
0N/A throw new InternalException("should not happen");
0N/A }
0N/A StringBuffer sb = new StringBuffer();
0N/A for (Iterator it = vars.iterator(); it.hasNext(); ) {
0N/A LocalVariable lv = (LocalVariable)it.next();
0N/A if (sb.length() > 0) {
0N/A sb.append(",");
0N/A }
0N/A sb.append(lv.name());
0N/A }
0N/A return sb.toString();
0N/A } catch (Exception exc) {
0N/A String st = exc.getClass().getName();
0N/A int inx = st.lastIndexOf('.');
0N/A return st.substring(inx+1);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets failed if fails.
0N/A */
0N/A void test(Method method, int which, String name, String expected) {
0N/A String got = testCase(method, which);
0N/A if (got.equals(expected)) {
0N/A System.out.println(name + ": got expected: " + got);
0N/A } else {
0N/A failed = true;
0N/A System.out.println(name + ": ERROR expected: " + expected);
0N/A System.out.println(" got: " + got);
0N/A }
0N/A }
0N/A
0N/A void test2(Method method, int which, String name, String expected, String expected2) {
0N/A String got = testCase(method, which);
0N/A if (got.equals(expected) || got.equals(expected2)) {
0N/A System.out.println(name + ": got expected: " + got);
0N/A } else {
0N/A failed = true;
0N/A System.out.println(name + ": ERROR expected: " + expected);
0N/A System.out.println(" got: " + got);
0N/A }
0N/A }
0N/A
0N/A protected void runTests() throws Exception {
0N/A List argList = new ArrayList(Arrays.asList(args));
0N/A argList.add("TestVars");
0N/A System.out.println("run args: " + argList);
0N/A connect((String[])argList.toArray(args));
0N/A waitForVMStart();
0N/A
0N/A /*
0N/A * Get to a point where the classes are loaded.
0N/A */
0N/A BreakpointEvent bp = resumeTo("TestVars", "hi", "()V");
0N/A
0N/A /*
0N/A * These classes should have no line numbers, except for
0N/A * one in the implicit constructor.
0N/A */
0N/A ReferenceType rt = findReferenceType("AbstractTestVars");
0N/A if (rt == null) {
0N/A throw new Exception("AbstractTestVars: not loaded");
0N/A }
0N/A Method method = findMethod(rt, "test1", "(Ljava/lang/String;I)F");
0N/A if (method == null) {
0N/A throw new Exception("Method not found");
0N/A }
0N/A test(method, VARIABLES, "abstract/variables",
0N/A "AbsentInformationException");
0N/A test(method, BYNAME, "abstract/variablesByName",
0N/A "AbsentInformationException");
0N/A test(method, ARGUMENTS, "abstract/arguments",
0N/A "AbsentInformationException");
0N/A
0N/A method = findMethod(rt, "test2", "(DZ)I");
0N/A if (method == null) {
0N/A throw new Exception("Method not found");
0N/A }
0N/A test(method, VARIABLES, "native/variables",
0N/A "AbsentInformationException");
0N/A test(method, BYNAME, "native/variablesByName",
0N/A "AbsentInformationException");
0N/A test(method, ARGUMENTS, "native/arguments",
0N/A "AbsentInformationException");
0N/A
0N/A method = findMethod(rt, "test3", "(SJ)Ljava/lang/String;");
0N/A if (method == null) {
0N/A throw new Exception("Method not found");
0N/A }
0N/A // javac can put these in whatever order it desires. hopper
0N/A // does it one way and mantis another.
0N/A test2(method, VARIABLES, "normal/variables", "sh,lo,st", "st,sh,lo");
0N/A test(method, BYNAME, "normal/variablesByName", "st");
0N/A test(method, ARGUMENTS, "normal/arguments", "sh,lo");
0N/A
0N/A // Allow application to complete
0N/A resumeToVMDeath();
0N/A
0N/A if (failed) {
0N/A throw new Exception("Vars: failed");
0N/A } else {
0N/A System.out.println("Vars: passed");
0N/A }
0N/A }
0N/A}