Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassObjectReference/toString/tostring001.java
41161 views
/*1* Copyright (c) 2002, 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.ClassObjectReference.toString;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.request.*;31import com.sun.jdi.event.*;32import com.sun.jdi.connect.*;33import java.io.*;34import java.util.*;3536/**37* The debugger application of the test.38*/39public class tostring001 {4041//------------------------------------------------------- immutable common fields4243final static String SIGNAL_READY = "ready";44final static String SIGNAL_GO = "go";45final static String SIGNAL_QUIT = "quit";4647private static int waitTime;48private static int exitStatus;49private static ArgumentHandler argHandler;50private static Log log;51private static Debugee debuggee;52private static ReferenceType debuggeeClass;5354//------------------------------------------------------- mutable common fields5556private final static String prefix = "nsk.jdi.ClassObjectReference.toString.";57private final static String className = "tostring001";58private final static String debuggerName = prefix + className;59private final static String debuggeeName = debuggerName + "a";6061//------------------------------------------------------- test specific fields6263/** debuggee's methods for check **/64private final static String checkedClasses[] = {65"java.lang.Boolean" ,66"java.lang.Byte" ,67"java.lang.Character",68"java.lang.Double" ,69"java.lang.Float" ,70"java.lang.Integer" ,71"java.lang.Long" ,72"java.lang.Short" ,73"java.lang.String" ,74"java.lang.Object" ,7576debuggeeName + "$innerClass",77debuggeeName + "$innerInterf",78prefix + "tostring001aClass",79prefix + "tostring001aInterf"80};8182//------------------------------------------------------- immutable common methods8384public static void main(String argv[]) {85System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));86}8788private static void display(String msg) {89log.display("debugger > " + msg);90}9192private static void complain(String msg) {93log.complain("debugger FAILURE > " + msg);94}9596public static int run(String argv[], PrintStream out) {9798exitStatus = Consts.TEST_PASSED;99100argHandler = new ArgumentHandler(argv);101log = new Log(out, argHandler);102waitTime = argHandler.getWaitTime() * 60000;103104debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);105106debuggeeClass = debuggee.classByName(debuggeeName);107if ( debuggeeClass == null ) {108complain("Class '" + debuggeeName + "' not found.");109exitStatus = Consts.TEST_FAILED;110}111112execTest();113114debuggee.quit();115116return exitStatus;117}118119//------------------------------------------------------ mutable common method120121private static void execTest() {122123BreakpointRequest brkp = debuggee.setBreakpoint(debuggeeClass,124tostring001a.brkpMethodName,125tostring001a.brkpLineNumber);126debuggee.resume();127128debuggee.sendSignal(SIGNAL_GO);129Event event = null;130131// waiting the breakpoint event132try {133event = debuggee.waitingEvent(brkp, waitTime);134} catch (InterruptedException e) {135throw new Failure("unexpected InterruptedException while waiting for Breakpoint event");136}137if (!(event instanceof BreakpointEvent)) {138debuggee.resume();139throw new Failure("BreakpointEvent didn't arrive");140}141142ThreadReference thread = ((BreakpointEvent)event).thread();143List params = new Vector();144ClassType testedClass = (ClassType)debuggeeClass;145146display("Checking toString() method for ClassObjectReferences of debuggee's fields...");147String brackets[] = {"", "[]", "[][]"};148149for (int i=0; i < checkedClasses.length; i++) {150151String basicName = checkedClasses[i];152153for (int dim = 0; dim<3; dim++) {154155String className = basicName + brackets[dim];156ReferenceType refType = debuggee.classByName(className);157if (refType == null) {158complain("Could NOT FIND class: " + className);159exitStatus = Consts.TEST_FAILED;160continue;161}162163try {164ClassObjectReference classObjRef = refType.classObject();165String str = classObjRef.toString();166if (str == null) {167complain("toString() returns null for ClassObjectReferences of debugges's field: " + className);168exitStatus = Consts.TEST_FAILED;169} else if (str.length() == 0) {170complain("toString() returns empty string for ClassObjectReferences of debugges's field: " + className);171exitStatus = Consts.TEST_FAILED;172} else {173display("toString() method returns for " + className + " : " + str);174}175} catch(Exception e) {176complain("unexpected " + e + " while taking ClassObjectReferences of debugges's field: " + className);177exitStatus = Consts.TEST_FAILED;178}179}180}181182display("Checking completed!");183debuggee.resume();184}185186//--------------------------------------------------------- test specific methods187188}189//--------------------------------------------------------- test specific classes190191192