Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Accessible/modifiers/modifiers002.java
41161 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.Accessible.modifiers;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 modifiers002 {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.Accessible.modifiers.";55private final static String className = "modifiers002";56private final static String debuggerName = prefix + className;57private final static String debuggeeName = debuggerName + "a";5859//------------------------------------------------------- test specific fields6061private final static String[] testedFieldNames = {"f1", "f2", "f3"};6263//------------------------------------------------------- immutable common methods6465public static void main(String argv[]) {66System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));67}6869private static void display(String msg) {70log.display("debugger > " + msg);71}7273private static void complain(String msg) {74log.complain("debugger FAILURE > " + msg);75}7677public static int run(String argv[], PrintStream out) {7879exitStatus = Consts.TEST_PASSED;8081argHandler = new ArgumentHandler(argv);82log = new Log(out, argHandler);83waitTime = argHandler.getWaitTime() * 60000;8485debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);8687debuggeeClass = debuggee.classByName(debuggeeName);88if ( debuggeeClass == null ) {89complain("Class '" + debuggeeName + "' not found.");90exitStatus = Consts.TEST_FAILED;91}9293execTest();9495debuggee.quit();9697return exitStatus;98}99100//------------------------------------------------------ mutable common method101102private static void execTest() {103for (int i=0; i < testedFieldNames.length; i++) {104check(testedFieldNames[i]);105display("");106}107display("Checking completed!");108}109110//--------------------------------------------------------- test specific methods111112private static void check (String fieldName) {113try {114ClassType checkedClass = (ClassType)debuggeeClass.fieldByName(fieldName).type();115String className = checkedClass.name();116117int modifiers = checkedClass.modifiers();118if (fieldName.equals("f1") || fieldName.equals("f2")) {119if ((0x0010 & modifiers) == 0x0010 /* ACC_FINAL */) {120display("Accessible.modifiers() returned expected ACC_FINAL flag for type: " + className);121} else {122complain("Accessible.modifiers() did not return ACC_FINAL flag for type: " + className);123exitStatus = Consts.TEST_FAILED;124}125}126127if ((0x0020 & modifiers) == 0x0020 /* ACC_SUPER */) {128display("Accessible.modifiers() returned expected ACC_SUPER flag for type: " + className);129} else {130complain("Accessible.modifiers() did not return ACC_SUPER flag for type: " + className);131exitStatus = Consts.TEST_FAILED;132}133134if (fieldName.equals("f2")) {135if ((0x0001 & modifiers) == 0x0001 /* ACC_PUBLIC */) {136display("Accessible.modifiers() returned expected ACC_PUBLIC flag for type: " + className);137} else {138complain("Accessible.modifiers() did not return ACC_PUBLIC flag for type: " + className);139exitStatus = Consts.TEST_FAILED;140}141}142143if (fieldName.equals("f3")) {144if ((0x0400 & modifiers) == 0x0400 /* ACC_ABSTRACT */) {145display("Accessible.modifiers() returned expected ACC_ABSTRACT flag for type: " + className);146} else {147complain("Accessible.modifiers() did not return ACC_ABSTRACT flag for type: " + className);148exitStatus = Consts.TEST_FAILED;149}150}151152} catch (Exception e) {153complain("Unexpected exception while checking of " + className + ": " + e);154e.printStackTrace(System.out);155exitStatus = Consts.TEST_FAILED;156}157}158}159//--------------------------------------------------------- test specific classes160161162