1 /******************************************************************************* 2 * Copyright (c) Mar 6, 2013 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.debug.tests.eval; 15 16 import org.eclipse.debug.core.model.IValue; 17 import org.eclipse.jdt.debug.core.IJavaThread; 18 import org.eclipse.jdt.debug.tests.AbstractDebugTest; 19 20 /** 21 * Tests that evaluations in non-generified source 22 * 23 * @since 3.8.100 24 */ 25 public class GeneralEvalTests extends AbstractDebugTest { 26 27 28 /** 29 * @param name 30 */ GeneralEvalTests(String name)31 public GeneralEvalTests(String name) { 32 super(name); 33 } 34 35 /** 36 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=329294 37 * @throws Exception 38 */ testInnerType1()39 public void testInnerType1() throws Exception { 40 IJavaThread thread = null; 41 try { 42 String typename = "bug329294"; 43 createLineBreakpoint(22, typename); 44 thread = launchToBreakpoint(typename); 45 assertNotNull("The program did not suspend", thread); 46 String snippet = "inner"; 47 doEval(thread, snippet); 48 } 49 finally { 50 removeAllBreakpoints(); 51 terminateAndRemove(thread); 52 } 53 } 54 55 /** 56 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=329294 57 * @throws Exception 58 */ testInnerType2()59 public void testInnerType2() throws Exception { 60 IJavaThread thread = null; 61 try { 62 String typename = "bug329294"; 63 createLineBreakpoint(26, typename); 64 thread = launchToBreakpoint(typename); 65 assertNotNull("The program did not suspend", thread); 66 String snippet = "fInner1.innerBool"; 67 doEval(thread, snippet); 68 } 69 finally { 70 removeAllBreakpoints(); 71 terminateAndRemove(thread); 72 } 73 } 74 75 /** 76 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=329294 77 * @throws Exception 78 */ testInnerType3()79 public void testInnerType3() throws Exception { 80 IJavaThread thread = null; 81 try { 82 String typename = "bug329294"; 83 createLineBreakpoint(30, typename); 84 thread = launchToBreakpoint(typename); 85 assertNotNull("The program did not suspend", thread); 86 String snippet = "!fInner1.innerBool"; 87 doEval(thread, snippet); 88 } 89 finally { 90 removeAllBreakpoints(); 91 terminateAndRemove(thread); 92 } 93 } 94 95 /** 96 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=329294 97 * @throws Exception 98 */ testInnerAnonymousType()99 public void testInnerAnonymousType() throws Exception { 100 IJavaThread thread = null; 101 try { 102 String typename = "bug329294"; 103 createLineBreakpoint(7, typename); 104 thread = launchToBreakpoint(typename); 105 assertNotNull("The program did not suspend", thread); 106 String snippet = "fInner1.innerBool"; 107 doEval(thread, snippet); 108 } 109 finally { 110 removeAllBreakpoints(); 111 terminateAndRemove(thread); 112 } 113 } 114 115 /** 116 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 117 * @throws Exception 118 */ testMultipleInfixEval1()119 public void testMultipleInfixEval1() throws Exception { 120 IJavaThread thread = null; 121 try { 122 String typename = "bug401270"; 123 createLineBreakpoint(16, typename); 124 thread = launchToBreakpoint(typename); 125 assertNotNull("the program did not suspend", thread); 126 String snippet = "(true==true==true==true==true)"; 127 IValue value = doEval(thread, snippet); 128 assertTrue("The result of (true==true==true==true==true) should be true", Boolean.parseBoolean(value.getValueString())); 129 } 130 finally { 131 removeAllBreakpoints(); 132 terminateAndRemove(thread); 133 } 134 } 135 136 /** 137 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 138 * @throws Exception 139 */ testMultipleInfixEval2()140 public void testMultipleInfixEval2() throws Exception { 141 IJavaThread thread = null; 142 try { 143 String typename = "bug401270"; 144 createLineBreakpoint(17, typename); 145 thread = launchToBreakpoint(typename); 146 assertNotNull("the program did not suspend", thread); 147 String snippet = "!(true==true==true==true==true)"; 148 IValue value = doEval(thread, snippet); 149 assertFalse("The result of !(true==true==true==true==true) should be false", Boolean.parseBoolean(value.getValueString())); 150 } 151 finally { 152 removeAllBreakpoints(); 153 terminateAndRemove(thread); 154 } 155 } 156 157 /** 158 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 159 * @throws Exception 160 */ testMultipleInfixEval3()161 public void testMultipleInfixEval3() throws Exception { 162 IJavaThread thread = null; 163 try { 164 String typename = "bug401270"; 165 createLineBreakpoint(18, typename); 166 thread = launchToBreakpoint(typename); 167 assertNotNull("the program did not suspend", thread); 168 String snippet = "(true&&true&&true&&true&&true)"; 169 IValue value = doEval(thread, snippet); 170 assertTrue("The result of (true&&true&&true&&true&&true) should be true", Boolean.parseBoolean(value.getValueString())); 171 } 172 finally { 173 removeAllBreakpoints(); 174 terminateAndRemove(thread); 175 } 176 } 177 178 /** 179 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 180 * @throws Exception 181 */ testMultipleInfixEval4()182 public void testMultipleInfixEval4() throws Exception { 183 IJavaThread thread = null; 184 try { 185 String typename = "bug401270"; 186 createLineBreakpoint(19, typename); 187 thread = launchToBreakpoint(typename); 188 assertNotNull("the program did not suspend", thread); 189 String snippet = "!(true&&true&&true&&true&&true)"; 190 IValue value = doEval(thread, snippet); 191 assertFalse("The result of !(true&&true&&true&&true&&true) should be false", Boolean.parseBoolean(value.getValueString())); 192 } 193 finally { 194 removeAllBreakpoints(); 195 terminateAndRemove(thread); 196 } 197 } 198 199 /** 200 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 201 * @throws Exception 202 */ testMultipleInfixEval5()203 public void testMultipleInfixEval5() throws Exception { 204 IJavaThread thread = null; 205 try { 206 String typename = "bug401270"; 207 createLineBreakpoint(20, typename); 208 thread = launchToBreakpoint(typename); 209 assertNotNull("the program did not suspend", thread); 210 String snippet = "true&&true||false"; 211 IValue value = doEval(thread, snippet); 212 assertTrue("The result of true&&true||false should be true", Boolean.parseBoolean(value.getValueString())); 213 } 214 finally { 215 removeAllBreakpoints(); 216 terminateAndRemove(thread); 217 } 218 } 219 220 /** 221 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 222 * @throws Exception 223 */ testMultipleInfixEval6()224 public void testMultipleInfixEval6() throws Exception { 225 IJavaThread thread = null; 226 try { 227 String typename = "bug401270"; 228 createLineBreakpoint(21, typename); 229 thread = launchToBreakpoint(typename); 230 assertNotNull("the program did not suspend", thread); 231 String snippet = "(1<=2==true||false)"; 232 IValue value = doEval(thread, snippet); 233 assertTrue("The result of (1<=2==true||false) should be true", Boolean.parseBoolean(value.getValueString())); 234 } 235 finally { 236 removeAllBreakpoints(); 237 terminateAndRemove(thread); 238 } 239 } 240 241 /** 242 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 243 * @throws Exception 244 */ testMultipleInfixEval7()245 public void testMultipleInfixEval7() throws Exception { 246 IJavaThread thread = null; 247 try { 248 String typename = "bug401270"; 249 createLineBreakpoint(22, typename); 250 thread = launchToBreakpoint(typename); 251 assertNotNull("the program did not suspend", thread); 252 String snippet = "!(1<=2==true||false)"; 253 IValue value = doEval(thread, snippet); 254 assertFalse("The result of !(1<=2==true||false) should be false", Boolean.parseBoolean(value.getValueString())); 255 } 256 finally { 257 removeAllBreakpoints(); 258 terminateAndRemove(thread); 259 } 260 } 261 262 /** 263 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 264 * @throws Exception 265 */ testMultipleInfixEval8()266 public void testMultipleInfixEval8() throws Exception { 267 IJavaThread thread = null; 268 try { 269 String typename = "bug401270"; 270 createLineBreakpoint(23, typename); 271 thread = launchToBreakpoint(typename); 272 assertNotNull("the program did not suspend", thread); 273 String snippet = "(true != false && false)"; 274 IValue value = doEval(thread, snippet); 275 assertFalse("The result of (true != false && false) should be false", Boolean.parseBoolean(value.getValueString())); 276 } 277 finally { 278 removeAllBreakpoints(); 279 terminateAndRemove(thread); 280 } 281 } 282 283 /** 284 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 285 * @throws Exception 286 */ testMultipleInfixEval9()287 public void testMultipleInfixEval9() throws Exception { 288 IJavaThread thread = null; 289 try { 290 String typename = "bug401270"; 291 createLineBreakpoint(24, typename); 292 thread = launchToBreakpoint(typename); 293 assertNotNull("the program did not suspend", thread); 294 String snippet = "!(true != false && false)"; 295 IValue value = doEval(thread, snippet); 296 assertTrue("The result of !(true != false && false) should be true", Boolean.parseBoolean(value.getValueString())); 297 } 298 finally { 299 removeAllBreakpoints(); 300 terminateAndRemove(thread); 301 } 302 } 303 304 /** 305 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 306 * @throws Exception 307 */ testMultipleInfixEval10()308 public void testMultipleInfixEval10() throws Exception { 309 IJavaThread thread = null; 310 try { 311 String typename = "bug401270"; 312 createLineBreakpoint(22, typename); 313 thread = launchToBreakpoint(typename); 314 assertNotNull("the program did not suspend", thread); 315 String snippet = "(true||true||true||true||true)"; 316 IValue value = doEval(thread, snippet); 317 assertTrue("The result of (true||true||true||true||true) should be true", Boolean.parseBoolean(value.getValueString())); 318 } 319 finally { 320 removeAllBreakpoints(); 321 terminateAndRemove(thread); 322 } 323 } 324 325 /** 326 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 327 * @throws Exception 328 */ testMultipleInfixEval11()329 public void testMultipleInfixEval11() throws Exception { 330 IJavaThread thread = null; 331 try { 332 String typename = "bug401270"; 333 createLineBreakpoint(23, typename); 334 thread = launchToBreakpoint(typename); 335 assertNotNull("the program did not suspend", thread); 336 String snippet = "!(true||true||true||true||true)"; 337 IValue value = doEval(thread, snippet); 338 assertFalse("The result of !(true||true||true||true||true) should be false", Boolean.parseBoolean(value.getValueString())); 339 } 340 finally { 341 removeAllBreakpoints(); 342 terminateAndRemove(thread); 343 } 344 } 345 346 /** 347 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 348 * @throws Exception 349 */ testMultipleInfixEval12()350 public void testMultipleInfixEval12() throws Exception { 351 IJavaThread thread = null; 352 try { 353 String typename = "bug401270"; 354 createLineBreakpoint(24, typename); 355 thread = launchToBreakpoint(typename); 356 assertNotNull("the program did not suspend", thread); 357 String snippet = "(true==true||true!=true&&true)"; 358 IValue value = doEval(thread, snippet); 359 assertTrue("The result of (true==true||true!=true&&true) should be true", Boolean.parseBoolean(value.getValueString())); 360 } 361 finally { 362 removeAllBreakpoints(); 363 terminateAndRemove(thread); 364 } 365 } 366 367 /** 368 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 369 * @throws Exception 370 */ testMultipleInfixEval13()371 public void testMultipleInfixEval13() throws Exception { 372 IJavaThread thread = null; 373 try { 374 String typename = "bug401270"; 375 createLineBreakpoint(25, typename); 376 thread = launchToBreakpoint(typename); 377 assertNotNull("the program did not suspend", thread); 378 String snippet = "!(true==true||true!=true&&true)"; 379 IValue value = doEval(thread, snippet); 380 assertFalse("The result of !(true==true||true!=true&&true) should be false", Boolean.parseBoolean(value.getValueString())); 381 } 382 finally { 383 removeAllBreakpoints(); 384 terminateAndRemove(thread); 385 } 386 } 387 388 /** 389 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 390 * @throws Exception 391 */ testMultipleInfixEval14()392 public void testMultipleInfixEval14() throws Exception { 393 IJavaThread thread = null; 394 try { 395 String typename = "bug401270"; 396 createLineBreakpoint(25, typename); 397 thread = launchToBreakpoint(typename); 398 assertNotNull("the program did not suspend", thread); 399 String snippet = "(true || !(true==true||true!=true&&true))"; 400 IValue value = doEval(thread, snippet); 401 assertTrue("The result of (true || !(true==true||true!=true&&true)) should be true", Boolean.parseBoolean(value.getValueString())); 402 } 403 finally { 404 removeAllBreakpoints(); 405 terminateAndRemove(thread); 406 } 407 } 408 409 /** 410 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 411 * @throws Exception 412 */ testMultipleInfixEval15()413 public void testMultipleInfixEval15() throws Exception { 414 IJavaThread thread = null; 415 try { 416 String typename = "bug401270"; 417 createLineBreakpoint(25, typename); 418 thread = launchToBreakpoint(typename); 419 assertNotNull("the program did not suspend", thread); 420 String snippet = "(true && true || false || !(true==true||true!=true&&true))"; 421 IValue value = doEval(thread, snippet); 422 assertTrue("The result of (true && true || false || !(true==true||true!=true&&true)) should be true", Boolean.parseBoolean(value.getValueString())); 423 } 424 finally { 425 removeAllBreakpoints(); 426 terminateAndRemove(thread); 427 } 428 } 429 430 /** 431 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=401270 432 * @throws Exception 433 */ testMultipleInfixEval16()434 public void testMultipleInfixEval16() throws Exception { 435 IJavaThread thread = null; 436 try { 437 String typename = "bug401270"; 438 createLineBreakpoint(25, typename); 439 thread = launchToBreakpoint(typename); 440 assertNotNull("the program did not suspend", thread); 441 String snippet = "(true && true || !(false&&true) || !(true==true||true!=true&&true))"; 442 IValue value = doEval(thread, snippet); 443 assertTrue("The result of (true && true || !(false&&true) || !(true==true||true!=true&&true)) should be true", Boolean.parseBoolean(value.getValueString())); 444 } 445 finally { 446 removeAllBreakpoints(); 447 terminateAndRemove(thread); 448 } 449 } 450 451 /** 452 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=403028 453 * @throws Exception 454 */ testCompoundCondition()455 public void testCompoundCondition() throws Exception { 456 IJavaThread thread = null; 457 try { 458 String typename = "bug401270"; 459 createLineBreakpoint(25, typename); 460 thread = launchToBreakpoint(typename); 461 assertNotNull("the program did not suspend", thread); 462 String snippet = "(true && true || !(false&&true) || !(true==true||true!=true&&true))"; 463 IValue value = doEval(thread, snippet); 464 assertTrue("The result of (true && true || !(false&&true) || !(true==true||true!=true&&true)) should be true", Boolean.parseBoolean(value.getValueString())); 465 } 466 finally { 467 removeAllBreakpoints(); 468 terminateAndRemove(thread); 469 } 470 } 471 472 /** 473 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=508105 474 * 475 * @throws Exception 476 */ testMultiByteCharacters()477 public void testMultiByteCharacters() throws Exception { 478 IJavaThread thread = null; 479 try { 480 String typename = "bug401270"; 481 createLineBreakpoint(25, typename); 482 thread = launchToBreakpoint(typename); 483 assertNotNull("the program did not suspend", thread); 484 485 String snippet = "int äüßö€ = 1; { if(äüßö€ < 0) return false; }; return äüßö€ > 0"; 486 IValue value = doEval(thread, snippet); 487 assertTrue("The result of 'int äüßö€ = 1; { if(äüßö€ < 0) return false; }; return äüßö€ > 0' should be true", Boolean.parseBoolean(value.getValueString())); 488 489 snippet = "\"ทดสอบ\".length() > 0"; 490 value = doEval(thread, snippet); 491 assertTrue("The result of '\"ทดสอบ\".length() > 0' should be true", Boolean.parseBoolean(value.getValueString())); 492 493 snippet = "return \"ทดสอบ\".length() == 5"; 494 value = doEval(thread, snippet); 495 assertTrue("The result of 'return \"ทดสอบ\".length() == 5' should be true", Boolean.parseBoolean(value.getValueString())); 496 497 snippet = "{return \"ทดสอบ\".length() != 5;}"; 498 value = doEval(thread, snippet); 499 assertFalse("The result of '{return \"ทดสอบ\".length() != 5;}' should be false", Boolean.parseBoolean(value.getValueString())); 500 501 snippet = "{/**/};\n{return \"ทดสอบ\".charAt(0) == '\\\\';}"; 502 value = doEval(thread, snippet); 503 assertFalse("The result of '{/**/};\\n{return \\\"ทดสอบ\\\".charAt(0) == '\\\\\\\\';}' should be false", Boolean.parseBoolean(value.getValueString())); 504 } 505 finally { 506 removeAllBreakpoints(); 507 terminateAndRemove(thread); 508 } 509 } 510 511 /** 512 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=508105 513 * 514 * @throws Exception 515 */ XtestAReturn()516 public void XtestAReturn() throws Exception { 517 IJavaThread thread = null; 518 try { 519 String typename = "bug401270"; 520 createLineBreakpoint(25, typename); 521 thread = launchToBreakpoint(typename); 522 assertNotNull("the program did not suspend", thread); 523 524 String snippet = "int a = 1; return a > 0"; 525 IValue value = doEval(thread, snippet); 526 assertTrue("The result of 'int a = 1; return a > 0' should be true", Boolean.parseBoolean(value.getValueString())); 527 528 snippet = "int areturn = 1; return areturn > 0"; 529 value = doEval(thread, snippet); 530 assertTrue("The result of 'int areturn = 1; return areturn > 0' should be true", Boolean.parseBoolean(value.getValueString())); 531 532 } 533 finally { 534 removeAllBreakpoints(); 535 terminateAndRemove(thread); 536 } 537 } 538 } 539