Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Accessible/isPublic/isPublic001.java
41161 views
/*1* Copyright (c) 2000, 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.isPublic;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import java.util.*;31import java.io.*;3233/**34* This test checks the method <code>isPublic()</code>35* of the JDI interface <code>Accessible</code> of com.sun.jdi package36* for ArrayType, ClassType, InterfaceType37*/3839public class isPublic001 extends Log {40static java.io.PrintStream out_stream;41static boolean verbose_mode = false;4243/** The main class names of the debugger & debugee applications. */44private final static String45package_prefix = "nsk.jdi.Accessible.isPublic.",46// package_prefix = "", // for DEBUG without package47thisClassName = package_prefix + "isPublic001",48debugeeName = thisClassName + "a";495051static ArgumentHandler argsHandler;52private static Log logHandler;535455/** Debugee's classes for check **/56private final static String classes_for_check[][] = {57{"boolean", "public", "primitive_type"},58{"byte" , "public", "primitive_type"},59{"char" , "public", "primitive_type"},60{"double" , "public", "primitive_type"},61{"float" , "public", "primitive_type"},62{"int" , "public", "primitive_type"},63{"long" , "public", "primitive_type"},6465{"java.lang.Boolean" , "public", "reference_type"},66{"java.lang.Byte" , "public", "reference_type"},67{"java.lang.Character", "public", "reference_type"},68{"java.lang.Double" , "public", "reference_type"},69{"java.lang.Float" , "public", "reference_type"},70{"java.lang.Integer" , "public", "reference_type"},71{"java.lang.Long" , "public", "reference_type"},72{"java.lang.String" , "public", "reference_type"},73{"java.lang.Object" , "public", "reference_type"},7475{thisClassName, "public", "reference_type" },76{thisClassName+"a", "public", "reference_type" },77{package_prefix + "pack_priv_cls", "package private", "reference_type"}, // class78{package_prefix + "pack_priv_interf", "package private", "reference_type"}, // interface7980{debugeeName+"$s_interf", "public", "reference_type"}, // interface8182{debugeeName+"$U", "private", "reference_type" },83{debugeeName+"$V", "protected", "reference_type" },84{debugeeName+"$W", "public", "reference_type" },85{debugeeName+"$P", "package private", "reference_type"}86};8788/**89* Re-call to <code>run(args,out)</code>, and exit with90* either status 95 or 97 (JCK-like exit status).91*/92public static void main (String argv[]) {93int exitCode = run(argv,System.out);94System.exit(exitCode + 95/*STATUS_TEMP*/);95}9697/**98* JCK-like entry point to the test: perform testing, and99* return exit code 0 (PASSED) or either 2 (FAILED).100*/101public static int run (String argv[], PrintStream out) {102out_stream = out;103104int v_test_result = new isPublic001().runThis(argv,out_stream);105if ( v_test_result == 2/*STATUS_FAILED*/ ) {106logHandler.complain("\n==> nsk/jdi/Accessible/isPublic/isPublic001 test FAILED");107}108else {109logHandler.display("\n==> nsk/jdi/Accessible/isPublic/isPublic001 test PASSED");110}111return v_test_result;112}113114private void print_log_on_verbose(String message) {115logHandler.display(message);116}117118/**119* Non-static variant of the method <code>run(args,out)</code>120*/121private int runThis (String argv[], PrintStream out) {122if ( out_stream == null ) {123out_stream = out;124}125126127128Debugee debugee;129130argsHandler = new ArgumentHandler(argv);131logHandler = new Log(out, argsHandler);132Binder binder = new Binder(argsHandler, logHandler);133134135if (argsHandler.verbose()) {136debugee = binder.bindToDebugee(debugeeName + " -vbs");137} else {138debugee = binder.bindToDebugee(debugeeName);139}140141IOPipe pipe = new IOPipe(debugee);142143logHandler.display("==> nsk/jdi/Accessible/isPublic/isPublic001 test LOG:");144logHandler.display("==> test checks the isPublic() method of Accessible interface");145logHandler.display(" of the com.sun.jdi package for ArrayType, ClassType, InterfaceType\n");146147148debugee.redirectStderr(out);149print_log_on_verbose("--> isPublic001: isPublic001a debugee launched");150debugee.resume();151152String line = pipe.readln();153if (line == null) {154logHandler.complain155("##> isPublic001: UNEXPECTED debugee's signal (not \"ready\") - " + line);156return 2/*STATUS_FAILED*/;157}158if (!line.equals("ready")) {159logHandler.complain160("##> isPublic001: UNEXPECTED debugee's signal (not \"ready\") - " + line);161return 2/*STATUS_FAILED*/;162}163else {164print_log_on_verbose("--> isPublic001: debugee's \"ready\" signal recieved!");165}166167logHandler.display168("--> isPublic001: checking debugee's classes by Accessible.isPublic() method...");169int all_classes_count = 0;170int class_not_found_errors = 0;171int isPublic_method_errors = 0;172for (int i=0; i<classes_for_check.length; i++) {173String basicName = classes_for_check[i][0];174for (int array_measure=0; array_measure<3; array_measure++) {175if ( array_measure == 0 ) { // not array type176if ( classes_for_check[i][2].equals("primitive_type") ) {177continue;178}179}180all_classes_count++;181String brackets[] = {"", "[]", "[][]"};182String className = basicName + brackets[array_measure];183ReferenceType refType = debugee.classByName(className);184if (refType == null) {185logHandler.complain("##> isPublic001: Could NOT FIND class: " + className);186class_not_found_errors++;187continue;188}189boolean isPublic = classes_for_check[i][1].equals("public");190if (refType.isPublic() != isPublic) {191logHandler.complain192("##> isPublic001: UNEXPECTED isPublic() method result (" + !isPublic +193") for class: " + className + "(" + classes_for_check[i][1] + ")");194isPublic_method_errors++;195}196else {197print_log_on_verbose198("--> isPublic001: expected isPublic() method result (" + isPublic +199") for class: " + className + "(" + classes_for_check[i][1] + ")");200}201}202}203logHandler.display("--> isPublic001: checking debugee's classes completed!");204logHandler.display("--> isPublic001: number of checked classes = " + all_classes_count);205if ( class_not_found_errors > 0 ) {206logHandler.complain("##> isPublic001: \"class not found ERRORS\" counter = "207+ class_not_found_errors);208}209if ( isPublic_method_errors > 0 ) {210logHandler.complain("##> isPublic001: isPublic() method ERRORS counter = "211+ isPublic_method_errors);212}213int v_test_result = 0/*STATUS_PASSED*/;214if (class_not_found_errors + isPublic_method_errors > 0) {215v_test_result = 2/*STATUS_FAILED*/;216}217218print_log_on_verbose("--> isPublic001: waiting for debugee finish...");219pipe.println("quit");220debugee.waitFor();221222int status = debugee.getStatus();223if (status != 0/*STATUS_PASSED*/ + 95/*STATUS_TEMP*/) {224logHandler.complain225("##> isPublic001: UNEXPECTED Debugee's exit status (not 95) - " + status);226v_test_result = 2/*STATUS_FAILED*/;227}228else {229print_log_on_verbose230("--> isPublic001: expected Debugee's exit status - " + status);231}232233return v_test_result;234}235}236237238