Path: blob/master/test/jdk/com/sun/jdi/AllLineLocations.java
41152 views
/*1* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 424872826* @summary Test ReferenceType.allLineLocations27* @author Gordon Hirsch28*29* @run build TestScaffold VMConnection30* @run compile -g RefTypes.java31* @run build AllLineLocations32*33* @run driver AllLineLocations RefTypes34*/35import com.sun.jdi.*;36import com.sun.jdi.event.*;37import com.sun.jdi.request.*;3839import java.util.List;4041public class AllLineLocations extends TestScaffold {4243public static void main(String args[]) throws Exception {44new AllLineLocations(args).startTests();45}4647AllLineLocations(String args[]) {48super(args);49}5051protected void runTests() throws Exception {5253/*54* Get to a point where the classes are loaded.55*/56BreakpointEvent bp = startTo("RefTypes", "loadClasses", "()V");57stepOut(bp.thread());5859/*60* These classes should have no line numbers, except for61* one in the implicit constructor.62*/63ReferenceType rt = findReferenceType("AllAbstract");64if (rt == null) {65throw new Exception("AllAbstract: not loaded");66}67List list = rt.allLineLocations();68if (list.size() != 1) {69throw new Exception("AllAbstract: incorrect number of line locations");70}71if (rt.locationsOfLine(5000).size() != 0) {72throw new Exception("AllAbstract: incorrect locationsOfLine");73}74Method method = findMethod(rt, "<init>", "()V");75if (method == null) {76throw new Exception("AllAbstract.<init> not found");77}78List list2 = method.allLineLocations();79if (!list2.equals(list)) {80throw new Exception("AllAbstract: line locations in wrong method");81}82if (method.locationsOfLine(5000).size() != 0) {83throw new Exception("AllAbstract: incorrect locationsOfLine");84}85System.out.println("AllAbstract: passed");8687rt = findReferenceType("AllNative");88if (rt == null) {89throw new Exception("AllNative: not loaded");90}91list = rt.allLineLocations();92if (list.size() != 1) {93throw new Exception("AllNative: incorrect number of line locations");94}95if (rt.locationsOfLine(5000).size() != 0) {96throw new Exception("AllNative: incorrect locationsOfLine");97}98method = findMethod(rt, "<init>", "()V");99if (method == null) {100throw new Exception("AllNative.<init> not found");101}102list2 = method.allLineLocations();103if (!list2.equals(list)) {104throw new Exception("AllNative: line locations in wrong method");105}106if (method.locationsOfLine(5000).size() != 0) {107throw new Exception("AllNative: incorrect locationsOfLine");108}109System.out.println("AllNative: passed");110111rt = findReferenceType("Interface");112if (rt == null) {113throw new Exception("Interface: not loaded");114}115list = rt.allLineLocations();116if (list.size() != 0) {117throw new Exception("Interface: locations reported for abstract methods");118}119System.out.println("Interface: passed");120121/*122* These classes have line numbers in one method and123* in the implicit constructor.124*/125rt = findReferenceType("Abstract");126if (rt == null) {127throw new Exception("Abstract: not loaded");128}129list = rt.allLineLocations();130if (list.size() != 5) {131throw new Exception("Abstract: incorrect number of line locations");132}133method = findMethod(rt, "b", "()V");134if (method == null) {135throw new Exception("Abstract.b not found");136}137list2 = method.allLineLocations();138list.removeAll(list2);139140// Remaining location should be in constructor141if ((list.size() != 1) ||142!(((Location)list.get(0)).method().name().equals("<init>"))) {143throw new Exception("Abstract: line locations in wrong method");144}145if (method.locationsOfLine(20).size() != 1) {146throw new Exception("Abstract method: incorrect locationsOfLine");147}148if (method.locationsOfLine(5000).size() != 0) {149throw new Exception("Abstract method: incorrect locationsOfLine");150}151method = findMethod(rt, "a", "()V");152if (method.locationsOfLine(5000).size() != 0) {153throw new Exception("Abstract method: incorrect locationsOfLine");154}155System.out.println("Abstract: passed");156157rt = findReferenceType("Native");158if (rt == null) {159throw new Exception("Native: not loaded");160}161list = rt.allLineLocations();162if (list.size() != 5) {163throw new Exception("Native: incorrect number of line locations");164}165if (rt.locationsOfLine(5000).size() != 0) {166throw new Exception("Native: incorrect locationsOfLine");167}168method = findMethod(rt, "b", "()V");169if (method == null) {170throw new Exception("Native.b not found");171}172list2 = method.allLineLocations();173list.removeAll(list2);174175// Remaining location should be in constructor176if ((list.size() != 1) ||177!(((Location)list.get(0)).method().name().equals("<init>"))) {178throw new Exception("Native: line locations in wrong method");179}180if (method.locationsOfLine(30).size() != 1) {181throw new Exception("Native method: incorrect locationsOfLine");182}183if (method.locationsOfLine(5000).size() != 0) {184throw new Exception("Native method: incorrect locationsOfLine");185}186method = findMethod(rt, "a", "()V");187if (method.locationsOfLine(5000).size() != 0) {188throw new Exception("Native method: incorrect locationsOfLine");189}190System.out.println("Native: passed");191192rt = findReferenceType("AbstractAndNative");193if (rt == null) {194throw new Exception("AbstractAndNative: not loaded");195}196list = rt.allLineLocations();197if (list.size() != 5) {198throw new Exception("AbstractAndNative: incorrect number of line locations");199}200if (rt.locationsOfLine(5000).size() != 0) {201throw new Exception("AbstractAndNative: incorrect locationsOfLine");202}203method = findMethod(rt, "c", "()V");204if (method == null) {205throw new Exception("AbstractAndNative.c not found");206}207list2 = method.allLineLocations();208list.removeAll(list2);209210// Remaining location should be in constructor211if ((list.size() != 1) ||212!(((Location)list.get(0)).method().name().equals("<init>"))) {213throw new Exception("AbstractAndNative: line locations in wrong method");214}215System.out.println("AbstractAndNative: passed");216217// Allow application to complete218resumeToVMDisconnect();219}220}221222223