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.argumentTypes; 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.argumentTypes()</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 argumenttypes001aTestClass { <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 their corresponding Type objects <BR> 61 * BooleanType, ByteType, CharType, etc. <BR> 62 * <BR> 63 */ 64 65 public class argumenttypes001 { 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/argumentTypes/argumenttypes001", 75 sHeader2 = "--> argumenttypes001: ", 76 sHeader3 = "##> argumenttypes001: "; 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 argumenttypes001().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.argumentTypes.argumenttypes001a"; 109 110 String mName = "nsk.jdi.Method.argumentTypes"; 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("argumenttypes001a 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 + ".argumenttypes001aTestClass"); 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 Method m1 = null; 179 List argTypes = null; 180 181 182 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 183 methodsByName("primitiveargsmethod"); 184 m = (Method) methods.get(0); 185 try { 186 argTypes = m.argumentTypes(); 187 } catch ( ClassNotLoadedException e ) { 188 log3("ERROR: CNLE: argTypes = m.argumentTypes();"); 189 testExitCode = FAILED; 190 break; 191 } 192 193 int i2; 194 195 for (i2 = 0; ; i2++) { 196 197 int expresult = 0; 198 199 log2("new check: #" + i2); 200 201 switch (i2) { 202 203 case 0: // boolean arg 204 BooleanType blType = null; 205 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 206 methodsByName("bl"); 207 m1 = (Method) methods.get(0); 208 try { 209 blType = (BooleanType) m1.returnType(); 210 } catch ( ClassCastException e1 ) { 211 log3("ERROR: CCE: (BooleanType) m1.returnType();"); 212 expresult = 1; 213 break; 214 } catch ( ClassNotLoadedException e2 ) { 215 log3("ERROR: CNLE: (BooleanType) m1.returnType();"); 216 expresult = 1; 217 break; 218 } 219 220 if (!argTypes.contains(blType)) { 221 log3("ERROR: !argTypes.contains(blType)"); 222 expresult = 1; 223 break; 224 } 225 break; 226 227 case 1: // byte arg 228 ByteType btType = null; 229 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 230 methodsByName("bt"); 231 m1 = (Method) methods.get(0); 232 try { 233 btType = (ByteType) m1.returnType(); 234 } catch ( ClassCastException e1 ) { 235 log3("ERROR: CCE: (ByteType) m1.returnType();"); 236 expresult = 1; 237 break; 238 } catch ( ClassNotLoadedException e2 ) { 239 log3("ERROR: CNLE: (ByteType) m1.returnType();"); 240 expresult = 1; 241 break; 242 } 243 244 if (!argTypes.contains(btType)) { 245 log3("ERROR: !argTypes.contains(btType)"); 246 expresult = 1; 247 break; 248 } 249 break; 250 251 case 2: // char arg 252 CharType chType = null; 253 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 254 methodsByName("ch"); 255 m1 = (Method) methods.get(0); 256 try { 257 chType = (CharType) m1.returnType(); 258 } catch ( ClassCastException e1 ) { 259 log3("ERROR: CCE: (CharType) m1.returnType();"); 260 expresult = 1; 261 break; 262 } catch ( ClassNotLoadedException e2 ) { 263 log3("ERROR: CNLE: CharType) m1.returnType();"); 264 expresult = 1; 265 break; 266 } 267 268 if (!argTypes.contains(chType)) { 269 log3("ERROR: !argTypes.contains(chType)"); 270 expresult = 1; 271 break; 272 } 273 break; 274 275 case 3: // double arg 276 DoubleType dbType = null; 277 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 278 methodsByName("db"); 279 m1 = (Method) methods.get(0); 280 try { 281 dbType = (DoubleType) m1.returnType(); 282 } catch ( ClassCastException e1 ) { 283 log3("ERROR: CCE: (DoubleType) m1.returnType();"); 284 expresult = 1; 285 break; 286 } catch ( ClassNotLoadedException e2 ) { 287 log3("ERROR: CNLE: (DoubleType) m1.returnType();"); 288 expresult = 1; 289 break; 290 } 291 292 if (!argTypes.contains(dbType)) { 293 log3("ERROR: !argTypes.contains(dbType)"); 294 expresult = 1; 295 break; 296 } 297 break; 298 299 case 4: // float arg 300 FloatType flType = null; 301 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 302 methodsByName("fl"); 303 m1 = (Method) methods.get(0); 304 try { 305 flType = (FloatType) m1.returnType(); 306 } catch ( ClassCastException e1 ) { 307 log3("ERROR: CCE: (FloatType) m1.returnType();"); 308 expresult = 1; 309 break; 310 } catch ( ClassNotLoadedException e2 ) { 311 log3("ERROR: CNLE: (FloatType) m1.returnType();"); 312 expresult = 1; 313 break; 314 } 315 316 if (!argTypes.contains(flType)) { 317 log3("ERROR: !argTypes.contains(flType)"); 318 expresult = 1; 319 break; 320 } 321 break; 322 case 5: // int arg 323 IntegerType inType = null; 324 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 325 methodsByName("in"); 326 m1 = (Method) methods.get(0); 327 try { 328 inType = (IntegerType) m1.returnType(); 329 } catch ( ClassCastException e1 ) { 330 log3("ERROR: CCE: (IntegerType) m1.returnType();"); 331 expresult = 1; 332 break; 333 } catch ( ClassNotLoadedException e2 ) { 334 log3("ERROR: CNLE: (IntegerType) m1.returnType();"); 335 expresult = 1; 336 break; 337 } 338 339 if (!argTypes.contains(inType)) { 340 log3("ERROR: !argTypes.contains(inType)"); 341 expresult = 1; 342 break; 343 } 344 break; 345 346 case 6: // long arg 347 LongType lnType = null; 348 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 349 methodsByName("ln"); 350 m1 = (Method) methods.get(0); 351 try { 352 lnType = (LongType) m1.returnType(); 353 } catch ( ClassCastException e1 ) { 354 log3("ERROR: CCE: (LongType) m1.returnType();"); 355 expresult = 1; 356 break; 357 } catch ( ClassNotLoadedException e2 ) { 358 log3("ERROR: CNLE: (LongType) m1.returnType();"); 359 expresult = 1; 360 break; 361 } 362 363 if (!argTypes.contains(lnType)) { 364 log3("ERROR: !argTypes.contains(lnType)"); 365 expresult = 1; 366 break; 367 } 368 break; 369 370 case 7: // short arg 371 ShortType shType = null; 372 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 373 methodsByName("sh"); 374 m1 = (Method) methods.get(0); 375 try { 376 shType = (ShortType) m1.returnType(); 377 } catch ( ClassCastException e1 ) { 378 log3("ERROR: CCE: (ShortType) m1.returnType();"); 379 expresult = 1; 380 break; 381 } catch ( ClassNotLoadedException e2 ) { 382 log3("ERROR: CNLE: (ShortType) m1.returnType();"); 383 expresult = 1; 384 break; 385 } 386 387 if (!argTypes.contains(shType)) { 388 log3("ERROR: !argTypes.contains(shType)"); 389 expresult = 1; 390 break; 391 } 392 break; 393 394 395 default: expresult = 2; 396 break ; 397 } 398 399 if (expresult == 2) { 400 log2(" test cases finished"); 401 break ; 402 } else if (expresult == 1) { 403 log3("ERROR: expresult != true; check # = " + i); 404 testExitCode = FAILED; 405 } 406 } 407 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 408 } 409 log1(" TESTING ENDS"); 410 411 //-------------------------------------------------- test summary section 412 //------------------------------------------------- standard end section 413 414 pipe.println("quit"); 415 log2("waiting for the debuggee to finish ..."); 416 debuggee.waitFor(); 417 418 int status = debuggee.getStatus(); 419 if (status != PASSED + PASS_BASE) { 420 log3("debuggee returned UNEXPECTED exit status: " + 421 status + " != PASS_BASE"); 422 testExitCode = FAILED; 423 } else { 424 log2("debuggee returned expected exit status: " + 425 status + " == PASS_BASE"); 426 } 427 428 if (testExitCode != PASSED) { 429 logHandler.complain("TEST FAILED"); 430 } 431 return testExitCode; 432 } 433 } 434