0N/A/*
2362N/A * Copyright (c) 1999, 2000, 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 4248728
0N/A * @summary Test ReferenceType.allLineLocations
0N/A * @author Gordon Hirsch
0N/A *
0N/A * @library scaffold
0N/A * @run build JDIScaffold VMConnection
0N/A * @run compile -g RefTypes.java
0N/A * @run build AllLineLocations
0N/A *
0N/A * @run main AllLineLocations RefTypes
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/Apublic class AllLineLocations extends JDIScaffold {
0N/A final String[] args;
0N/A
0N/A public static void main(String args[]) throws Exception {
0N/A new AllLineLocations(args).startTests();
0N/A }
0N/A
0N/A AllLineLocations(String args[]) {
0N/A super();
0N/A this.args = args;
0N/A }
0N/A
0N/A protected void runTests() throws Exception {
0N/A connect(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("RefTypes", "loadClasses", "()V");
0N/A stepOut(bp.thread());
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("AllAbstract");
0N/A if (rt == null) {
0N/A throw new Exception("AllAbstract: not loaded");
0N/A }
0N/A List list = rt.allLineLocations();
0N/A if (list.size() != 1) {
0N/A throw new Exception("AllAbstract: incorrect number of line locations");
0N/A }
0N/A if (rt.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("AllAbstract: incorrect locationsOfLine");
0N/A }
0N/A Method method = findMethod(rt, "<init>", "()V");
0N/A if (method == null) {
0N/A throw new Exception("AllAbstract.<init> not found");
0N/A }
0N/A List list2 = method.allLineLocations();
0N/A if (!list2.equals(list)) {
0N/A throw new Exception("AllAbstract: line locations in wrong method");
0N/A }
0N/A if (method.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("AllAbstract: incorrect locationsOfLine");
0N/A }
0N/A System.out.println("AllAbstract: passed");
0N/A
0N/A rt = findReferenceType("AllNative");
0N/A if (rt == null) {
0N/A throw new Exception("AllNative: not loaded");
0N/A }
0N/A list = rt.allLineLocations();
0N/A if (list.size() != 1) {
0N/A throw new Exception("AllNative: incorrect number of line locations");
0N/A }
0N/A if (rt.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("AllNative: incorrect locationsOfLine");
0N/A }
0N/A method = findMethod(rt, "<init>", "()V");
0N/A if (method == null) {
0N/A throw new Exception("AllNative.<init> not found");
0N/A }
0N/A list2 = method.allLineLocations();
0N/A if (!list2.equals(list)) {
0N/A throw new Exception("AllNative: line locations in wrong method");
0N/A }
0N/A if (method.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("AllNative: incorrect locationsOfLine");
0N/A }
0N/A System.out.println("AllNative: passed");
0N/A
0N/A rt = findReferenceType("Interface");
0N/A if (rt == null) {
0N/A throw new Exception("Interface: not loaded");
0N/A }
0N/A list = rt.allLineLocations();
0N/A if (list.size() != 0) {
0N/A throw new Exception("Interface: locations reported for abstract methods");
0N/A }
0N/A System.out.println("Interface: passed");
0N/A
0N/A /*
0N/A * These classes have line numbers in one method and
0N/A * in the implicit constructor.
0N/A */
0N/A rt = findReferenceType("Abstract");
0N/A if (rt == null) {
0N/A throw new Exception("Abstract: not loaded");
0N/A }
0N/A list = rt.allLineLocations();
0N/A if (list.size() != 5) {
0N/A throw new Exception("Abstract: incorrect number of line locations");
0N/A }
0N/A method = findMethod(rt, "b", "()V");
0N/A if (method == null) {
0N/A throw new Exception("Abstract.b not found");
0N/A }
0N/A list2 = method.allLineLocations();
0N/A list.removeAll(list2);
0N/A
0N/A // Remaining location should be in constructor
0N/A if ((list.size() != 1) ||
0N/A !(((Location)list.get(0)).method().name().equals("<init>"))) {
0N/A throw new Exception("Abstract: line locations in wrong method");
0N/A }
0N/A if (method.locationsOfLine(20).size() != 1) {
0N/A throw new Exception("Abstract method: incorrect locationsOfLine");
0N/A }
0N/A if (method.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("Abstract method: incorrect locationsOfLine");
0N/A }
0N/A method = findMethod(rt, "a", "()V");
0N/A if (method.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("Abstract method: incorrect locationsOfLine");
0N/A }
0N/A System.out.println("Abstract: passed");
0N/A
0N/A rt = findReferenceType("Native");
0N/A if (rt == null) {
0N/A throw new Exception("Native: not loaded");
0N/A }
0N/A list = rt.allLineLocations();
0N/A if (list.size() != 5) {
0N/A throw new Exception("Native: incorrect number of line locations");
0N/A }
0N/A if (rt.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("Native: incorrect locationsOfLine");
0N/A }
0N/A method = findMethod(rt, "b", "()V");
0N/A if (method == null) {
0N/A throw new Exception("Native.b not found");
0N/A }
0N/A list2 = method.allLineLocations();
0N/A list.removeAll(list2);
0N/A
0N/A // Remaining location should be in constructor
0N/A if ((list.size() != 1) ||
0N/A !(((Location)list.get(0)).method().name().equals("<init>"))) {
0N/A throw new Exception("Native: line locations in wrong method");
0N/A }
0N/A if (method.locationsOfLine(30).size() != 1) {
0N/A throw new Exception("Native method: incorrect locationsOfLine");
0N/A }
0N/A if (method.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("Native method: incorrect locationsOfLine");
0N/A }
0N/A method = findMethod(rt, "a", "()V");
0N/A if (method.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("Native method: incorrect locationsOfLine");
0N/A }
0N/A System.out.println("Native: passed");
0N/A
0N/A rt = findReferenceType("AbstractAndNative");
0N/A if (rt == null) {
0N/A throw new Exception("AbstractAndNative: not loaded");
0N/A }
0N/A list = rt.allLineLocations();
0N/A if (list.size() != 5) {
0N/A throw new Exception("AbstractAndNative: incorrect number of line locations");
0N/A }
0N/A if (rt.locationsOfLine(5000).size() != 0) {
0N/A throw new Exception("AbstractAndNative: incorrect locationsOfLine");
0N/A }
0N/A method = findMethod(rt, "c", "()V");
0N/A if (method == null) {
0N/A throw new Exception("AbstractAndNative.c not found");
0N/A }
0N/A list2 = method.allLineLocations();
0N/A list.removeAll(list2);
0N/A
0N/A // Remaining location should be in constructor
0N/A if ((list.size() != 1) ||
0N/A !(((Location)list.get(0)).method().name().equals("<init>"))) {
0N/A throw new Exception("AbstractAndNative: line locations in wrong method");
0N/A }
0N/A System.out.println("AbstractAndNative: passed");
0N/A
0N/A // Allow application to complete
0N/A resumeToVMDeath();
0N/A }
0N/A}