1 /* 2 * Copyright (c) 2001, 2018, 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.Method.argumentTypeNames; 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 test for the implementation of an object of the type <BR> 36 * Method. <BR> 37 * <BR> 38 * The test checks up that results of the method <BR> 39 * <code>com.sun.jdi.Method.argumentTypeNames()</code> <BR> 40 * complies with its spec when a type is one of PrimitiveTypes. <BR> 41 * <BR> 42 * The cases for testing are as follows. <BR> 43 * <BR> 44 * When a gebuggee creates an object of <BR> 45 * the following class type: <BR> 46 * class TestClass { <BR> 47 * public void primitiveargsmethod ( <BR> 48 * boolean bl, <BR> 49 * byte bt, <BR> 50 * char ch, <BR> 51 * double db, <BR> 52 * float fl, <BR> 53 * int in, <BR> 54 * long l, <BR> 55 * short sh ) { <BR> 56 * return ; <BR> 57 * } <BR> 58 * } <BR> 59 * for all of the above primitive type arguments, <BR> 60 * a debugger forms text strings with corresponding <BR> 61 * types, that is 'boolean', 'byte', 'char', and etc. <BR> 62 * <BR> 63 */ 64 65 public class argumenttypenames001 { 66 67 //----------------------------------------------------- templete section 68 static final int PASSED = 0; 69 static final int FAILED = 2; 70 static final int PASS_BASE = 95; 71 72 //----------------------------------------------------- templete parameters 73 static final String 74 sHeader1 = "\n==> nsk/jdi/Method/argumentTypeNames/argumenttypenames001", 75 sHeader2 = "--> debugger: ", 76 sHeader3 = "##> debugger: "; 77 78 //----------------------------------------------------- main method 79 main(String argv[])80 public static void main (String argv[]) { 81 int result = run(argv, System.out); 82 System.exit(result + PASS_BASE); 83 } 84 run(String argv[], PrintStream out)85 public static int run (String argv[], PrintStream out) { 86 return new argumenttypenames001().runThis(argv, out); 87 } 88 89 //-------------------------------------------------- log procedures 90 91 //private static boolean verbMode = false; 92 93 private static Log logHandler; 94 log1(String message)95 private static void log1(String message) { 96 logHandler.display(sHeader1 + message); 97 } log2(String message)98 private static void log2(String message) { 99 logHandler.display(sHeader2 + message); 100 } log3(String message)101 private static void log3(String message) { 102 logHandler.complain(sHeader3 + message); 103 } 104 105 // ************************************************ test parameters 106 107 private String debuggeeName = 108 "nsk.jdi.Method.argumentTypeNames.argumenttypenames001a"; 109 110 String mName = "nsk.jdi.Method.argumentTypeNames"; 111 112 //====================================================== test program 113 114 static ArgumentHandler argsHandler; 115 static int testExitCode = PASSED; 116 117 //------------------------------------------------------ common section 118 runThis(String argv[], PrintStream out)119 private int runThis (String argv[], PrintStream out) { 120 121 Debugee debuggee; 122 123 argsHandler = new ArgumentHandler(argv); 124 logHandler = new Log(out, argsHandler); 125 Binder binder = new Binder(argsHandler, logHandler); 126 127 if (argsHandler.verbose()) { 128 debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp 129 } else { 130 debuggee = binder.bindToDebugee(debuggeeName); // *** tp 131 } 132 133 IOPipe pipe = new IOPipe(debuggee); 134 135 debuggee.redirectStderr(out); 136 log2("argumenttypenames001a debuggee launched"); 137 debuggee.resume(); 138 139 String line = pipe.readln(); 140 if ((line == null) || !line.equals("ready")) { 141 log3("signal received is not 'ready' but: " + line); 142 return FAILED; 143 } else { 144 log2("'ready' recieved"); 145 } 146 147 VirtualMachine vm = debuggee.VM(); 148 149 //------------------------------------------------------ testing section 150 log1(" TESTING BEGINS"); 151 152 for (int i = 0; ; i++) { 153 pipe.println("newcheck"); 154 line = pipe.readln(); 155 156 if (line.equals("checkend")) { 157 log2(" : returned string is 'checkend'"); 158 break ; 159 } else if (!line.equals("checkready")) { 160 log3("ERROR: returned string is not 'checkready'"); 161 testExitCode = FAILED; 162 break ; 163 } 164 165 log1("new check: #" + i); 166 167 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part 168 169 List listOfDebuggeeClasses = vm.classesByName(mName + ".argumenttypenames001aTestClass"); 170 if (listOfDebuggeeClasses.size() != 1) { 171 testExitCode = FAILED; 172 log3("ERROR: listOfDebuggeeClasses.size() != 1"); 173 break ; 174 } 175 176 List methods = null; 177 Method m = null; 178 179 List argTypeNames = null; 180 181 182 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 183 methodsByName("primitiveargsmethod"); 184 m = (Method) methods.get(0); 185 argTypeNames = m.argumentTypeNames(); 186 187 int i2; 188 189 for (i2 = 0; ; i2++) { 190 191 int expresult = 0; 192 193 log2("new check: #" + i2); 194 195 switch (i2) { 196 197 case 0: // boolean arg 198 199 if (!argTypeNames.contains("boolean")) { 200 log3("ERROR: !argTypes.contains('boolean')"); 201 expresult = 1; 202 break; 203 } 204 break; 205 206 case 1: // byte arg 207 208 if (!argTypeNames.contains("byte")) { 209 log3("ERROR: !argTypes.contains('byte')"); 210 expresult = 1; 211 break; 212 } 213 break; 214 215 case 2: // char arg 216 217 if (!argTypeNames.contains("char")) { 218 log3("ERROR: !argTypes.contains('char')"); 219 expresult = 1; 220 break; 221 } 222 break; 223 224 case 3: // double arg 225 226 if (!argTypeNames.contains("double")) { 227 log3("ERROR: !argTypes.contains('double')"); 228 expresult = 1; 229 break; 230 } 231 break; 232 233 case 4: // float arg 234 235 if (!argTypeNames.contains("float")) { 236 log3("ERROR: !argTypes.contains('float')"); 237 expresult = 1; 238 break; 239 } 240 break; 241 case 5: // int arg 242 243 if (!argTypeNames.contains("int")) { 244 log3("ERROR: !argTypes.contains('int')"); 245 expresult = 1; 246 break; 247 } 248 break; 249 250 case 6: // long arg 251 252 if (!argTypeNames.contains("long")) { 253 log3("ERROR: !argTypes.contains('long')"); 254 expresult = 1; 255 break; 256 } 257 break; 258 259 case 7: // short arg 260 261 if (!argTypeNames.contains("short")) { 262 log3("ERROR: !argTypes.contains('short')"); 263 expresult = 1; 264 break; 265 } 266 break; 267 268 269 default: expresult = 2; 270 break ; 271 } 272 273 if (expresult == 2) { 274 log2(" test cases finished"); 275 break ; 276 } else if (expresult == 1) { 277 log3("ERROR: expresult != true; check # = " + i); 278 testExitCode = FAILED; 279 } 280 } 281 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 282 } 283 log1(" TESTING ENDS"); 284 285 //-------------------------------------------------- test summary section 286 //------------------------------------------------- standard end section 287 288 pipe.println("quit"); 289 log2("waiting for the debuggee to finish ..."); 290 debuggee.waitFor(); 291 292 int status = debuggee.getStatus(); 293 if (status != PASSED + PASS_BASE) { 294 log3("debuggee returned UNEXPECTED exit status: " + 295 status + " != PASS_BASE"); 296 testExitCode = FAILED; 297 } else { 298 log2("debuggee returned expected exit status: " + 299 status + " == PASS_BASE"); 300 } 301 302 if (testExitCode != PASSED) { 303 logHandler.complain("TEST FAILED"); 304 } 305 return testExitCode; 306 } 307 } 308