Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Accessible/isPrivate/isprivate002.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.isPrivate;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 isprivate002 {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.isPrivate.";55private final static String className = "isprivate002";56private final static String debuggerName = prefix + className;57private final static String debuggeeName = debuggerName + "a";5859//------------------------------------------------------- test specific fields6061private final static String[] testedFieldNames = {"f1", "f2"};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();116117if (checkedClass.isPrivate()) {118display("Accessible.isPrivate() returned true for " + className);119} else {120complain("Accessible.isPrivate() returned false for " + className);121exitStatus = Consts.TEST_FAILED;122}123124} catch (Exception e) {125complain("Unexpected exception while checking of " + className + ": " + e);126e.printStackTrace(System.out);127exitStatus = Consts.TEST_FAILED;128}129}130}131//--------------------------------------------------------- test specific classes132133134