Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/isEnumConstant/isenumconstant001.java
41160 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.isEnumConstant;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 isenumconstant001 {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.isEnumConstant.";55private final static String className = "isenumconstant001";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", "f4"};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() {104//debuggee.receiveExpectedSignal(SIGNAL_GO);105106for (int i=0; i < expectedFieldNames.length; i++) {107check(expectedFieldNames[i]);108display("");109}110111display("Checking completed!");112}113114//--------------------------------------------------------- test specific methods115116private static void check (String fieldName) {117try {118ClassType checkedClass = (ClassType)debuggeeClass.fieldByName(fieldName).type();119String className = checkedClass.name();120121for (int i = 0; i < expectedEnumFieldsNames.length; i++) {122123Field checkedField = checkedClass.fieldByName(expectedEnumFieldsNames[i]);124if (checkedField.isEnumConstant()) {125display("Field.isEnumConstant() returned expected true for");126display("\t" + expectedEnumFieldsNames[i] + " field of enum " + className );127} else {128display("Field.isEnumConstant() returned unexpected false for");129display("\t" + expectedEnumFieldsNames[i] + " field of enum " + className );130exitStatus = Consts.TEST_FAILED;131}132}133134} catch (Exception e) {135complain("Unexpected exception while checking of " + className + ": " + e);136e.printStackTrace(System.out);137exitStatus = Consts.TEST_FAILED;138}139}140}141//--------------------------------------------------------- test specific classes142143144