Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/type/type004.java
42103 views
/*1* Copyright (c) 2003, 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.Field.type;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;3031import java.io.*;32import java.util.*;3334/**35* The debugger application of the test.36*/37public class type004 {3839//------------------------------------------------------- immutable common fields4041final static String SIGNAL_READY = "ready";42final static String SIGNAL_GO = "go";43final static String SIGNAL_QUIT = "quit";4445private static int waitTime;46private static int exitStatus;47private static ArgumentHandler argHandler;48private static Log log;49private static Debugee debuggee;50private static ReferenceType debuggeeClass;5152//------------------------------------------------------- mutable common fields5354private final static String prefix = "nsk.jdi.Field.type.";55private final static String className = "type004";56private final static String debuggerName = prefix + className;57private final static String debuggeeName = debuggerName + "a";5859//------------------------------------------------------- test specific fields6061private final static String[] expectedFieldNames = {"f1", "f2", "f3"};62private final static String[] expectedEnumFieldsNames = { "e1", "e2" };6364//------------------------------------------------------- immutable common methods6566public static void main(String argv[]) {67System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));68}6970private static void display(String msg) {71log.display("debugger > " + msg);72}7374private static void complain(String msg) {75log.complain("debugger FAILURE > " + msg);76}7778public static int run(String argv[], PrintStream out) {7980exitStatus = Consts.TEST_PASSED;8182argHandler = new ArgumentHandler(argv);83log = new Log(out, argHandler);84waitTime = argHandler.getWaitTime() * 60000;8586debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);8788debuggeeClass = debuggee.classByName(debuggeeName);89if ( debuggeeClass == null ) {90complain("Class '" + debuggeeName + "' not found.");91exitStatus = Consts.TEST_FAILED;92}9394execTest();9596debuggee.quit();9798return exitStatus;99}100101//------------------------------------------------------ mutable common method102103private static void execTest() {104for (int i=0; i < expectedFieldNames.length; i++) {105check(expectedFieldNames[i]);106display("");107}108display("Checking completed!");109}110111//--------------------------------------------------------- test specific methods112113private static void check (String fieldName) {114try {115ClassType checkedClass = (ClassType)debuggeeClass.fieldByName(fieldName).type();116String className = checkedClass.name();117118for (int i = 0; i < expectedEnumFieldsNames.length; i++) {119Field foundField = checkedClass.fieldByName(expectedEnumFieldsNames[i]);120if (foundField != null) {121if (foundField.type().equals(checkedClass)) {122display("enum " + className + " has field " + expectedEnumFieldsNames[i]);123display("\t of expected type " + className);124} else {125complain("enum " + className + " has field " + expectedEnumFieldsNames[i]);126complain("\t of unexpected type " + foundField.type().name());127exitStatus = Consts.TEST_FAILED;128}129} else {130complain("enum " + className + " does not have field " + expectedEnumFieldsNames[i]);131complain("\t of type " + className);132exitStatus = Consts.TEST_FAILED;133}134}135} catch (Exception e) {136complain("Unexpected exception while checking of " + className + ": " + e);137e.printStackTrace(System.out);138exitStatus = Consts.TEST_FAILED;139}140}141}142//--------------------------------------------------------- test specific classes143144145