Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/genericSignature/gensignature001.java
41161 views
/*1* Copyright (c) 2004, 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*/2223package nsk.jdi.LocalVariable.genericSignature;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import java.util.*;31import java.io.*;3233/**34* The test for the LocalVariable.genericSignature() method.35*36* This class is used as debugger part of the test.37*/3839public class gensignature001 {4041// communication signals constants42static final String READY = "ready";43static final String QUIT = "quit";4445static final String PACKAGE_NAME = "nsk.jdi.LocalVariable.genericSignature.";46static final String DEBUGEE_CLASS_NAME = PACKAGE_NAME + "gensignature001a";4748// tested class name and signature constants49static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";50static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";51static final String THIS_GENERIC_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + "<TT;TN;>" + ";";5253// tested method name constant54static final String TESTED_METHOD_NAME = "testedMethod";5556private static Debugee debugee;57private static ReferenceType debugeeClass;5859// list of tested variables names and signatures60static final String varsList[][] = {6162// not generic arguments63{"arg11PrimBoolean", null},64{"arg12PrimInt", null},65{"arg13Object", null},66{"arg14String", null},67{"arg15PrimArrShort", null},68{"arg16ObjArrObject", null},6970// generic arguments71{"arg21GenObject", "TT;"},72{"arg22GenNumber", "TN;"},73{"arg23GenObjectArr", "[TT;"},74{"arg24GenNumberArr", "[TN;"},75{"arg25GenObjectList", "Ljava/util/List<TT;>;"},76{"arg26GenNumberList", "Ljava/util/List<TN;>;"},77{"arg27GenObjectDerivedList", "Ljava/util/List<+TT;>;"},78{"arg28GenNumberDerivedList", "Ljava/util/List<+TN;>;"},7980// not generic variables81{"var11PrimBoolean", null},82{"var12PrimInt", null},83{"var13Object", null},84{"var14String", null},85{"var15PrimArrShort", null},86{"var16ObjArrObject", null},8788// generic variables89{"var21GenObject", "TT;"},90{"var22GenNumber", "TN;"},91{"var23GenObjectArr", "[TT;"},92{"var24GenNumberArr", "[TN;"},93{"var25GenObjectList", "Ljava/util/List<TT;>;"},94{"var26GenNumberList", "Ljava/util/List<TN;>;"},95{"var27GenObjectDerivedList", "Ljava/util/List<+TT;>;"},96{"var28GenNumberDerivedList", "Ljava/util/List<+TN;>;"},979899};100101static ArgumentHandler argHandler;102static Log log;103104public static void main (String argv[]) {105int result = run(argv, System.out);106System.exit(result + Consts.JCK_STATUS_BASE);107}108109public static int run (String argv[], PrintStream out) {110return new gensignature001().runThis(argv, out);111}112113private int runThis (String argv[], PrintStream out) {114115int testResult = Consts.TEST_PASSED;116117argHandler = new ArgumentHandler(argv);118log = new Log(out, argHandler);119120debugee = Debugee.prepareDebugee(argHandler, log, DEBUGEE_CLASS_NAME);121122debugeeClass = debugee.classByName(DEBUGEE_CLASS_NAME);123if ( debugeeClass == null ) {124log.complain("Class '" + DEBUGEE_CLASS_NAME + "' not found.");125testResult = Consts.TEST_FAILED;126}127128129log.display("Checking started.");130do {131ReferenceType testedClass = debugee.classByName(TESTED_CLASS_NAME);132log.display("Found tested class: " + testedClass.name());133134Method testedMethod = debugee.methodByName(testedClass, TESTED_METHOD_NAME);135log.display("Found tested method: " + testedMethod.name());136137for (int i = 0; i < varsList.length; i++) {138139List localVars = null;140try {141localVars = testedMethod.variablesByName(varsList[i][0]);142} catch (AbsentInformationException e) {143log.complain("Unexpected AbsentInformationException while calling variablesByName() for " +144varsList[i][0]);145testResult = Consts.TEST_FAILED;146continue;147}148if (localVars.size() != 1) {149log.complain("Not unique local variable '" + varsList[i][0] + "' : " + localVars.size());150testResult = Consts.TEST_FAILED;151continue;152}153log.display("Found local variable: " + varsList[i][0]);154155LocalVariable var = (LocalVariable)localVars.get(0);156String expSignature = varsList[i][1];157log.display("Getting generic signature for local variable: " + varsList[i][0]);158159String actSignature = "";160try {161actSignature = var.genericSignature();162} catch (Exception e) {163log.complain("Unexpected exception while calling genericSignature() for " +164varsList[i][0] + " : " + e.getMessage());165e.printStackTrace(out);166testResult = Consts.TEST_FAILED;167continue;168}169170if ((expSignature == null && actSignature != null) ||171(expSignature != null && !expSignature.equals(actSignature))) {172log.complain("Unexpected generic signature for local variable '" + varsList[i][0] + "': " +173actSignature + "\n\tExpected generic signature: " + expSignature);174testResult = Consts.TEST_FAILED;175} else {176log.display("\tgot expected generic signature: " + actSignature);177}178}179180} while (false);181log.display("All checking completed.");182183debugee.quit();184return testResult;185}186} // end of gensignature001 class187188189