1 /* 2 * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package nsk.jdi.Accessible.modifiers; 25 26 import nsk.share.*; 27 import nsk.share.jpda.*; 28 import nsk.share.jdi.*; 29 30 import com.sun.jdi.*; 31 import java.util.*; 32 import java.io.*; 33 34 /** 35 * The modifiers001 test checks the method <code>modifiers()</code> 36 * of the JDI interface <code>Accessible</code> of com.sun.jdi package 37 * for ClassType, InterfaceType 38 */ 39 40 public class modifiers001 extends Log { 41 static java.io.PrintStream out_stream; 42 static boolean verbose_mode = false; 43 44 /** The main class names of the debugger & debugee applications. */ 45 private final static String 46 package_prefix = "nsk.jdi.Accessible.modifiers.", 47 // package_prefix = "", // for DEBUG without package 48 thisClassName = package_prefix + "modifiers001", 49 debugeeName = thisClassName + "a"; 50 51 52 static ArgumentHandler argsHandler; 53 private static Log logHandler; 54 55 56 /** Debugee's classes for check **/ 57 private final static String classes_for_check[][] = { 58 59 {"java.lang.Boolean" , "public, final", "class"}, 60 {"java.lang.Byte" , "public, final", "class"}, 61 {"java.lang.Character", "public, final", "class"}, 62 {"java.lang.Double" , "public, final", "class"}, 63 {"java.lang.Float" , "public, final", "class"}, 64 {"java.lang.Integer" , "public, final", "class"}, 65 {"java.lang.Long" , "public, final", "class"}, 66 {"java.lang.String" , "public, final", "class"}, 67 {"java.lang.Object" , "public ", "class"}, 68 69 {thisClassName, "public", "class"}, 70 {thisClassName+"a", "public", "class"}, 71 72 {debugeeName+"$fin_s_cls", "final, static", "class"}, 73 {debugeeName+"$abs_s_cls", "abstract, static", "class"}, 74 {debugeeName+"$s_interf", "abstract, static, interface", "interface"}, 75 76 {package_prefix + "simple_class", "<no modifiers>", "class"}, 77 {package_prefix + "abstract_class", "abstract", "class"}, 78 {package_prefix + "final_class", "final", "class"}, 79 {package_prefix + "interf", "abstract, interface", "interface"} 80 }; 81 82 83 public static void main (String argv[]) { 84 int result = run(argv,System.out); 85 if (result != 0) { 86 throw new RuntimeException("TEST FAILED with result " + result); 87 } 88 89 } 90 91 /** 92 * JCK-like entry point to the test: perform testing, and 93 * return exit code 0 (PASSED) or either 2 (FAILED). 94 */ 95 public static int run (String argv[], PrintStream out) { 96 out_stream = out; 97 98 int v_test_result = new modifiers001().runThis(argv,out_stream); 99 if ( v_test_result == 2/*STATUS_FAILED*/ ) { 100 logHandler.complain("\n==> nsk/jdi/Accessible/modifiers/modifiers001 test FAILED"); 101 } 102 else { 103 logHandler.display("\n==> nsk/jdi/Accessible/modifiers/modifiers001 test PASSED"); 104 } 105 return v_test_result; 106 } 107 108 private void print_log_on_verbose(String message) { 109 logHandler.display(message); 110 } 111 112 /** 113 * Non-static variant of the method <code>run(args,out)</code> 114 */ 115 private int runThis (String argv[], PrintStream out) { 116 if ( out_stream == null ) { 117 out_stream = out; 118 } 119 120 121 Debugee debugee; 122 123 argsHandler = new ArgumentHandler(argv); 124 logHandler = new Log(out, argsHandler); 125 Binder binder = new Binder(argsHandler, logHandler); 126 127 128 if (argsHandler.verbose()) { 129 debugee = binder.bindToDebugee(debugeeName + " -vbs"); 130 } else { 131 debugee = binder.bindToDebugee(debugeeName); 132 } 133 134 IOPipe pipe = new IOPipe(debugee); 135 136 137 logHandler.display("==> nsk/jdi/Accessible/modifiers/modifiers001 test LOG:"); 138 logHandler.display("==> test checks the modifiers() method of Accessible interface"); 139 logHandler.display(" of the com.sun.jdi package for ClassType, InterfaceType\n"); 140 141 142 debugee.redirectStderr(out); 143 print_log_on_verbose("--> modifiers001: modifiers001a debugee launched"); 144 debugee.resume(); 145 146 String line = pipe.readln(); 147 if (line == null) { 148 logHandler.complain 149 ("##> modifiers001: UNEXPECTED debugee's signal (not \"ready\") - " + line); 150 return 2/*STATUS_FAILED*/; 151 } 152 if (!line.equals("ready")) { 153 logHandler.complain 154 ("##> modifiers001: UNEXPECTED debugee's signal (not \"ready\") - " + line); 155 return 2/*STATUS_FAILED*/; 156 } 157 else { 158 print_log_on_verbose("--> modifiers001: debugee's \"ready\" signal recieved!"); 159 } 160 161 logHandler.display 162 ("--> modifiers001: checking debugee's classes by Accessible.modifiers() method...\n"); 163 int all_classes_count = 0; 164 int class_not_found_errors = 0; 165 int class_not_found_exceptions = 0; 166 int modifiers_method_errors = 0; 167 // modifiers001a obj = new modifiers001a(); 168 for (int i=0; i<classes_for_check.length; i++) { 169 String className = classes_for_check[i][0]; 170 all_classes_count++; 171 ReferenceType refType = debugee.classByName(className); 172 if (refType == null) { 173 logHandler.complain("##> isPublic001: Could NOT FIND class: " + className); 174 class_not_found_errors++; 175 continue; 176 } 177 Class class_obj; 178 try { 179 class_obj = Class.forName(className); 180 } 181 catch (ClassNotFoundException e) { 182 logHandler.complain 183 ("##> modifiers001: Class.forName("+className+") - "+e.toString()); 184 class_not_found_exceptions++; 185 continue; 186 } 187 int expected_modifiers = class_obj.getModifiers(); 188 String s_type = classes_for_check[i][2]; 189 String s_modifiers = classes_for_check[i][1]; 190 int got_modifiers = refType.modifiers(); 191 logHandler.display(""); 192 if ( got_modifiers != expected_modifiers ) { 193 logHandler.complain("##> modifiers001: UNEXPECTED modifiers() method result (" 194 + "0x" + Integer.toHexString(got_modifiers) + ") for " + s_type + ": " + className 195 + "(" + s_modifiers + ")"); 196 logHandler.complain("##> expected modifiers() method result = " 197 + "0x" + Integer.toHexString(expected_modifiers)); 198 modifiers_method_errors++; 199 } 200 else { 201 print_log_on_verbose("--> modifiers001: expected modifiers() method result (" 202 + "0x" + Integer.toHexString(got_modifiers) + ") for " + s_type + ": " + className 203 + "(" + s_modifiers + ")"); 204 } 205 } 206 logHandler.display 207 ("--> modifiers001: checking debugee's classes completed!"); 208 logHandler.display 209 ("--> modifiers001: number of checked classes = " + all_classes_count); 210 if ( class_not_found_errors > 0 ) { 211 logHandler.complain("##> modifiers001: \"class not found ERRORS\" counter = " 212 + class_not_found_errors); 213 } 214 if ( class_not_found_exceptions > 0 ) { 215 logHandler.complain("##> modifiers001: \"class not found EXCEPTIONS\" counter = " 216 + class_not_found_exceptions); 217 } 218 logHandler.display("##> modifiers001: modifiers() method ERRORS counter = " 219 + modifiers_method_errors); 220 int v_test_result = 0/*STATUS_PASSED*/; 221 if (class_not_found_errors + class_not_found_exceptions + modifiers_method_errors > 0) { 222 v_test_result = 2/*STATUS_FAILED*/; 223 } 224 225 print_log_on_verbose("--> modifiers001: waiting for debugee finish..."); 226 pipe.println("quit"); 227 debugee.waitFor(); 228 229 int status = debugee.getStatus(); 230 if (status != 0/*STATUS_PASSED*/ + 95/*STATUS_TEMP*/) { 231 logHandler.complain 232 ("##> modifiers001: UNEXPECTED Debugee's exit status (not 95) - " + status); 233 v_test_result = 2/*STATUS_FAILED*/; 234 } 235 else { 236 print_log_on_verbose 237 ("--> modifiers001: expected Debugee's exit status - " + status); 238 } 239 240 return v_test_result; 241 } 242 }