Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | class IntMath { |
| 4 | |
| 5 | public static boolean mBoolean1, mBoolean2; |
| 6 | public static byte mByte1, mByte2; |
| 7 | public static char mChar1, mChar2; |
| 8 | public static short mShort1, mShort2; |
| 9 | public static int mInt1, mInt2; |
| 10 | public static float mFloat1, mFloat2; |
| 11 | public static long mLong1, mLong2; |
| 12 | public static double mDouble1, mDouble2; |
| 13 | public static volatile long mVolatileLong1, mVolatileLong2; |
| 14 | |
| 15 | |
| 16 | private int foo_; |
| 17 | |
| 18 | public IntMath(int stuff) { |
| 19 | foo_ = stuff; |
| 20 | } |
| 21 | |
| 22 | public IntMath() { |
| 23 | foo_ = 123; |
| 24 | } |
| 25 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame^] | 26 | static int constStringTest(int x) { |
| 27 | /* TODO: flesh this test out when we can call string library */ |
| 28 | String str = "Hello World!"; |
| 29 | return x * 2; |
| 30 | } |
| 31 | |
| 32 | static void throwNullPointerException() { |
| 33 | throw new NullPointerException(); |
| 34 | } |
| 35 | |
| 36 | static int catchBlock(int x) { |
| 37 | try { |
| 38 | x += 123; |
| 39 | throwNullPointerException(); |
| 40 | } catch (NullPointerException npe) { |
| 41 | x += 456; |
| 42 | } |
| 43 | return x; |
| 44 | } |
| 45 | |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 46 | static int staticFieldTest(int x) { |
| 47 | mBoolean1 = true; |
| 48 | mBoolean2 = false; |
| 49 | mByte1 = 127; |
| 50 | mByte2 = -128; |
| 51 | mChar1 = 32767; |
| 52 | mChar2 = 65535; |
| 53 | mShort1 = 32767; |
| 54 | mShort2 = -32768; |
| 55 | mInt1 = 65537; |
| 56 | mInt2 = -65537; |
| 57 | mFloat1 = 3.1415f; |
| 58 | mFloat2 = -1.0f / 0.0f; // -inf |
| 59 | mLong1 = 1234605616436508552L; // 0x1122334455667788 |
| 60 | mLong2 = -1234605616436508552L; |
| 61 | mDouble1 = 3.1415926535; |
| 62 | mDouble2 = 1.0 / 0.0; // +inf |
| 63 | mVolatileLong1 = mLong1 - 1; |
| 64 | mVolatileLong2 = mLong2 + 1; |
| 65 | |
| 66 | if (!mBoolean1) { return 10; } |
| 67 | if (mBoolean2) { return 11; } |
| 68 | if (mByte1 != 127) { return 12; } |
| 69 | if (mByte2 != -128) { return 13; } |
| 70 | if (mChar1 != 32767) { return 14; } |
| 71 | if (mChar2 != 65535) { return 15; } |
| 72 | if (mShort1 != 32767) { return 16; } |
| 73 | if (mShort2 != -32768) { return 17; } |
| 74 | if (mInt1 != 65537) { return 18; } |
| 75 | if (mInt2 != -65537) { return 19; } |
| 76 | if (!(mFloat1 > 3.141f && mFloat1 < 3.142f)) { return 20; } |
| 77 | if (mFloat2 >= mFloat1) { return 21; } |
| 78 | if (mLong1 != 1234605616436508552L) { return 22; } |
| 79 | if (mLong2 != -1234605616436508552L) { return 23; } |
| 80 | if (!(mDouble1 > 3.141592653 && mDouble1 < 3.141592654)) { return 24; } |
| 81 | if (mDouble2 <= mDouble1) { return 25; } |
| 82 | if (mVolatileLong1 != 1234605616436508551L) { return 26; } |
| 83 | if (mVolatileLong2 != -1234605616436508551L) { return 27; } |
| 84 | |
| 85 | return 1000 + x; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Try to cause some unary operations. |
| 90 | */ |
| 91 | static int unopTest(int x) { |
| 92 | x = -x; |
| 93 | x ^= 0xffffffff; |
| 94 | return x; |
| 95 | } |
| 96 | |
| 97 | static int shiftTest1() { |
| 98 | final int[] mBytes = { |
| 99 | 0x11, 0x22, 0x33, 0x44, 0x88, 0x99, 0xaa, 0xbb |
| 100 | }; |
| 101 | long l; |
| 102 | int i1, i2; |
| 103 | |
| 104 | if (mBytes[0] != 0x11) return 20; |
| 105 | if (mBytes[1] != 0x22) return 21; |
| 106 | if (mBytes[2] != 0x33) return 22; |
| 107 | if (mBytes[3] != 0x44) return 23; |
| 108 | if (mBytes[4] != 0x88) return 24; |
| 109 | if (mBytes[5] != 0x99) return 25; |
| 110 | if (mBytes[6] != 0xaa) return 26; |
| 111 | if (mBytes[7] != 0xbb) return 27; |
| 112 | |
| 113 | i1 = mBytes[0] | mBytes[1] << 8 | mBytes[2] << 16 | mBytes[3] << 24; |
| 114 | i2 = mBytes[4] | mBytes[5] << 8 | mBytes[6] << 16 | mBytes[7] << 24; |
| 115 | l = i1 | ((long)i2 << 32); |
| 116 | |
| 117 | if (i1 != 0x44332211) { return 0x80000000 | i1; } |
| 118 | if (i2 != 0xbbaa9988) { return 2; } |
| 119 | if (l != 0xbbaa998844332211L) { return 3; } |
| 120 | |
| 121 | l = (long)mBytes[0] |
| 122 | | (long)mBytes[1] << 8 |
| 123 | | (long)mBytes[2] << 16 |
| 124 | | (long)mBytes[3] << 24 |
| 125 | | (long)mBytes[4] << 32 |
| 126 | | (long)mBytes[5] << 40 |
| 127 | | (long)mBytes[6] << 48 |
| 128 | | (long)mBytes[7] << 56; |
| 129 | |
| 130 | if (l != 0xbbaa998844332211L) { return 4; } |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int shiftTest2() { |
| 135 | |
| 136 | long a = 0x11; |
| 137 | long b = 0x22; |
| 138 | long c = 0x33; |
| 139 | long d = 0x44; |
| 140 | long e = 0x55; |
| 141 | long f = 0x66; |
| 142 | long g = 0x77; |
| 143 | long h = 0x88; |
| 144 | |
| 145 | long result = ((a << 56) | (b << 48) | (c << 40) | (d << 32) | |
| 146 | (e << 24) | (f << 16) | (g << 8) | h); |
| 147 | |
| 148 | if (result != 0x1122334455667788L) { return 1; } |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int unsignedShiftTest() { |
| 153 | byte b = -4; |
| 154 | short s = -4; |
| 155 | char c = 0xfffc; |
| 156 | int i = -4; |
| 157 | |
| 158 | b >>>= 4; |
| 159 | s >>>= 4; |
| 160 | c >>>= 4; |
| 161 | i >>>= 4; |
| 162 | |
| 163 | if ((int) b != -1) { return 1; } |
| 164 | if ((int) s != -1) { return 2; } |
| 165 | if ((int) c != 0x0fff) { return 3; } |
| 166 | if (i != 268435455) { return 4; } |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static int convTest() { |
| 171 | |
| 172 | float f; |
| 173 | double d; |
| 174 | int i; |
| 175 | long l; |
| 176 | |
| 177 | /* int --> long */ |
| 178 | i = 7654; |
| 179 | l = (long) i; |
| 180 | if (l != 7654L) { return 1; } |
| 181 | |
| 182 | i = -7654; |
| 183 | l = (long) i; |
| 184 | if (l != -7654L) { return 2; } |
| 185 | |
| 186 | /* long --> int (with truncation) */ |
| 187 | l = 5678956789L; |
| 188 | i = (int) l; |
| 189 | if (i != 1383989493) { return 3; } |
| 190 | |
| 191 | l = -5678956789L; |
| 192 | i = (int) l; |
| 193 | if (i != -1383989493) { return 4; } |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int charSubTest() { |
| 198 | |
| 199 | char char1 = 0x00e9; |
| 200 | char char2 = 0xffff; |
| 201 | int i; |
| 202 | |
| 203 | /* chars are unsigned-expanded to ints before subtraction */ |
| 204 | i = char1 - char2; |
| 205 | if (i != 0xffff00ea) { return 1; } |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * We pass in the arguments and return the results so the compiler |
| 211 | * doesn't do the math for us. (x=70000, y=-3) |
| 212 | */ |
| 213 | static int intOperTest(int x, int y) { |
| 214 | int[] results = new int[10]; |
| 215 | |
| 216 | /* this seems to generate "op-int" instructions */ |
| 217 | results[0] = x + y; |
| 218 | results[1] = x - y; |
| 219 | results[2] = x * y; |
| 220 | results[3] = x * x; |
| 221 | results[4] = x / y; |
| 222 | results[5] = x % -y; |
| 223 | results[6] = x & y; |
| 224 | results[7] = x | y; |
| 225 | results[8] = x ^ y; |
| 226 | |
| 227 | /* this seems to generate "op-int/2addr" instructions */ |
| 228 | results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y); |
| 229 | |
| 230 | /* check this edge case while we're here (div-int/2addr) */ |
| 231 | int minInt = -2147483648; |
| 232 | int negOne = -results[5]; |
| 233 | int plusOne = 1; |
| 234 | int result = (((minInt + plusOne) - plusOne) / negOne) / negOne; |
| 235 | |
| 236 | if (result != minInt) { return 1;}; |
| 237 | if (results[0] != 69997) { return 2;}; |
| 238 | if (results[1] != 70003) { return 3;}; |
| 239 | if (results[2] != -210000) { return 4;}; |
| 240 | if (results[3] != 605032704) { return 5;}; |
| 241 | if (results[4] != -23333) { return 6;}; |
| 242 | if (results[5] != 1) { return 7;}; |
| 243 | if (results[6] != 70000) { return 8;}; |
| 244 | if (results[7] != -3) { return 9;}; |
| 245 | if (results[8] != -70003) { return 10;}; |
| 246 | if (results[9] != 70000) { return 11;}; |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * More operations, this time with 16-bit constants. (x=77777) |
| 253 | */ |
| 254 | static int lit16Test(int x) { |
| 255 | |
| 256 | int[] results = new int[8]; |
| 257 | |
| 258 | /* try to generate op-int/lit16" instructions */ |
| 259 | results[0] = x + 1000; |
| 260 | results[1] = 1000 - x; |
| 261 | results[2] = x * 1000; |
| 262 | results[3] = x / 1000; |
| 263 | results[4] = x % 1000; |
| 264 | results[5] = x & 1000; |
| 265 | results[6] = x | -1000; |
| 266 | results[7] = x ^ -1000; |
| 267 | |
| 268 | if (results[0] != 78777) { return 1; } |
| 269 | if (results[1] != -76777) { return 2; } |
| 270 | if (results[2] != 77777000) { return 3; } |
| 271 | if (results[3] != 77) { return 4; } |
| 272 | if (results[4] != 777) { return 5; } |
| 273 | if (results[5] != 960) { return 6; } |
| 274 | if (results[6] != -39) { return 7; } |
| 275 | if (results[7] != -76855) { return 8; } |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * More operations, this time with 8-bit constants. (x=-55555) |
| 281 | */ |
| 282 | static int lit8Test(int x) { |
| 283 | |
| 284 | int[] results = new int[8]; |
| 285 | |
| 286 | /* try to generate op-int/lit8" instructions */ |
| 287 | results[0] = x + 10; |
| 288 | results[1] = 10 - x; |
| 289 | results[2] = x * 10; |
| 290 | results[3] = x / 10; |
| 291 | results[4] = x % 10; |
| 292 | results[5] = x & 10; |
| 293 | results[6] = x | -10; |
| 294 | results[7] = x ^ -10; |
| 295 | int minInt = -2147483648; |
| 296 | int result = minInt / -1; |
| 297 | if (result != minInt) {return 1; } |
| 298 | if (results[0] != -55545) {return 2; } |
| 299 | if (results[1] != 55565) {return 3; } |
| 300 | if (results[2] != -555550) {return 4; } |
| 301 | if (results[3] != -5555) {return 5; } |
| 302 | if (results[4] != -5) {return 6; } |
| 303 | if (results[5] != 8) {return 7; } |
| 304 | if (results[6] != -1) {return 8; } |
| 305 | if (results[7] != 55563) {return 9; } |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /* |
| 311 | * Shift some data. (value=0xff00aa01, dist=8) |
| 312 | */ |
| 313 | static int intShiftTest(int value, int dist) { |
| 314 | int results[] = new int[4]; |
| 315 | results[0] = value << dist; |
| 316 | results[1] = value >> dist; |
| 317 | results[2] = value >>> dist; |
| 318 | results[3] = (((value << dist) >> dist) >>> dist) << dist; |
| 319 | if (results[0] != 0x00aa0100) {return 1; } |
| 320 | if (results[1] != 0xffff00aa) {return 2; } |
| 321 | if (results[2] != 0x00ff00aa) {return 3; } |
| 322 | if (results[3] != 0xaa00) {return 4; } |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * We pass in the arguments and return the results so the compiler |
| 328 | * doesn't do the math for us. (x=70000000000, y=-3) |
| 329 | */ |
| 330 | static int longOperTest(long x, long y) { |
| 331 | long[] results = new long[10]; |
| 332 | |
| 333 | /* this seems to generate "op-long" instructions */ |
| 334 | results[0] = x + y; |
| 335 | results[1] = x - y; |
| 336 | results[2] = x * y; |
| 337 | results[3] = x * x; |
| 338 | results[4] = x / y; |
| 339 | results[5] = x % -y; |
| 340 | results[6] = x & y; |
| 341 | results[7] = x | y; |
| 342 | results[8] = x ^ y; |
| 343 | /* this seems to generate "op-long/2addr" instructions */ |
| 344 | results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y); |
| 345 | /* check this edge case while we're here (div-long/2addr) */ |
| 346 | long minLong = -9223372036854775808L; |
| 347 | long negOne = -results[5]; |
| 348 | long plusOne = 1; |
| 349 | long result = (((minLong + plusOne) - plusOne) / negOne) / negOne; |
| 350 | if (result != minLong) { return 1; } |
| 351 | if (results[0] != 69999999997L) { return 2; } |
| 352 | if (results[1] != 70000000003L) { return 3; } |
| 353 | if (results[2] != -210000000000L) { return 4; } |
| 354 | if (results[3] != -6833923606740729856L) { return 5; } // overflow |
| 355 | if (results[4] != -23333333333L) { return 6; } |
| 356 | if (results[5] != 1) { return 7; } |
| 357 | if (results[6] != 70000000000L) { return 8; } |
| 358 | if (results[7] != -3) { return 9; } |
| 359 | if (results[8] != -70000000003L) { return 10; } |
| 360 | if (results[9] != 70000000000L) { return 11; } |
| 361 | if (results.length != 10) { return 12; } |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Shift some data. (value=0xd5aa96deff00aa01, dist=16) |
| 367 | */ |
| 368 | static long longShiftTest(long value, int dist) { |
| 369 | long results[] = new long[4]; |
| 370 | results[0] = value << dist; |
| 371 | results[1] = value >> dist; |
| 372 | results[2] = value >>> dist; |
| 373 | results[3] = (((value << dist) >> dist) >>> dist) << dist; |
| 374 | if (results[0] != 0x96deff00aa010000L) { return results[0]; } |
| 375 | if (results[1] != 0xffffd5aa96deff00L) { return results[1]; } |
| 376 | if (results[2] != 0x0000d5aa96deff00L) { return results[2]; } |
| 377 | if (results[3] != 0xffff96deff000000L) { return results[3]; } |
| 378 | if (results.length != 4) { return 5; } |
| 379 | |
| 380 | return results[0]; // test return-long |
| 381 | } |
| 382 | |
| 383 | static int switchTest(int a) { |
| 384 | int res = 1234; |
| 385 | |
| 386 | switch (a) { |
| 387 | case -1: res = 1; return res; |
| 388 | case 0: res = 2; return res; |
| 389 | case 1: /*correct*/ break; |
| 390 | case 2: res = 3; return res; |
| 391 | case 3: res = 4; return res; |
| 392 | case 4: res = 5; return res; |
| 393 | default: res = 6; return res; |
| 394 | } |
| 395 | switch (a) { |
| 396 | case 3: res = 7; return res; |
| 397 | case 4: res = 8; return res; |
| 398 | default: /*correct*/ break; |
| 399 | } |
| 400 | |
| 401 | a = 0x12345678; |
| 402 | |
| 403 | switch (a) { |
| 404 | case 0x12345678: /*correct*/ break; |
| 405 | case 0x12345679: res = 9; return res; |
| 406 | default: res = 1; return res; |
| 407 | } |
| 408 | switch (a) { |
| 409 | case 57: res = 10; return res; |
| 410 | case -6: res = 11; return res; |
| 411 | case 0x12345678: /*correct*/ break; |
| 412 | case 22: res = 12; return res; |
| 413 | case 3: res = 13; return res; |
| 414 | default: res = 14; return res; |
| 415 | } |
| 416 | switch (a) { |
| 417 | case -6: res = 15; return res; |
| 418 | case 3: res = 16; return res; |
| 419 | default: /*correct*/ break; |
| 420 | } |
| 421 | |
| 422 | a = -5; |
| 423 | switch (a) { |
| 424 | case 12: res = 17; return res; |
| 425 | case -5: /*correct*/ break; |
| 426 | case 0: res = 18; return res; |
| 427 | default: res = 19; return res; |
| 428 | } |
| 429 | |
| 430 | switch (a) { |
| 431 | default: /*correct*/ break; |
| 432 | } |
| 433 | return res; |
| 434 | } |
| 435 | /* |
| 436 | * Test the integer comparisons in various ways. |
| 437 | */ |
| 438 | static int testIntCompare(int minus, int plus, int plus2, int zero) { |
| 439 | int res = 1111; |
| 440 | |
| 441 | if (minus > plus) |
| 442 | return 1; |
| 443 | if (minus >= plus) |
| 444 | return 2; |
| 445 | if (plus < minus) |
| 446 | return 3; |
| 447 | if (plus <= minus) |
| 448 | return 4; |
| 449 | if (plus == minus) |
| 450 | return 5; |
| 451 | if (plus != plus2) |
| 452 | return 6; |
| 453 | |
| 454 | /* try a branch-taken */ |
| 455 | if (plus != minus) { |
| 456 | res = res; |
| 457 | } else { |
| 458 | return 7; |
| 459 | } |
| 460 | |
| 461 | if (minus > 0) |
| 462 | return 8; |
| 463 | if (minus >= 0) |
| 464 | return 9; |
| 465 | if (plus < 0) |
| 466 | return 10; |
| 467 | if (plus <= 0) |
| 468 | return 11; |
| 469 | if (plus == 0) |
| 470 | return 12; |
| 471 | if (zero != 0) |
| 472 | return 13; |
| 473 | |
| 474 | if (zero == 0) { |
| 475 | res = res; |
| 476 | } else { |
| 477 | return 14; |
| 478 | } |
| 479 | return res; |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | * Test cmp-long. |
| 484 | * |
| 485 | * minus=-5, alsoMinus=0xFFFFFFFF00000009, plus=4, alsoPlus=8 |
| 486 | */ |
| 487 | static int testLongCompare(long minus, long alsoMinus, long plus, |
| 488 | long alsoPlus) { |
| 489 | int res = 2222; |
| 490 | |
| 491 | if (minus > plus) |
| 492 | return 2; |
| 493 | if (plus < minus) |
| 494 | return 3; |
| 495 | if (plus == minus) |
| 496 | return 4; |
| 497 | |
| 498 | if (plus >= plus+1) |
| 499 | return 5; |
| 500 | if (minus >= minus+1) |
| 501 | return 6; |
| 502 | |
| 503 | /* try a branch-taken */ |
| 504 | if (plus != minus) { |
| 505 | res = res; |
| 506 | } else { |
| 507 | return 7; |
| 508 | } |
| 509 | |
| 510 | /* compare when high words are equal but low words differ */ |
| 511 | if (plus > alsoPlus) |
| 512 | return 8; |
| 513 | if (alsoPlus < plus) |
| 514 | return 9; |
| 515 | if (alsoPlus == plus) |
| 516 | return 10; |
| 517 | |
| 518 | /* high words are equal, low words have apparently different signs */ |
| 519 | if (minus < alsoMinus) // bug! |
| 520 | return 11; |
| 521 | if (alsoMinus > minus) |
| 522 | return 12; |
| 523 | if (alsoMinus == minus) |
| 524 | return 13; |
| 525 | |
| 526 | return res; |
| 527 | } |
| 528 | |
| 529 | /* |
| 530 | * Test cmpl-float and cmpg-float. |
| 531 | */ |
| 532 | static int testFloatCompare(float minus, float plus, float plus2, |
| 533 | float nan) { |
| 534 | |
| 535 | int res = 3333; |
| 536 | if (minus > plus) |
| 537 | res = 1; |
| 538 | if (plus < minus) |
| 539 | res = 2; |
| 540 | if (plus == minus) |
| 541 | res = 3; |
| 542 | if (plus != plus2) |
| 543 | res = 4; |
| 544 | |
| 545 | if (plus <= nan) |
| 546 | res = 5; |
| 547 | if (plus >= nan) |
| 548 | res = 6; |
| 549 | if (minus <= nan) |
| 550 | res = 7; |
| 551 | if (minus >= nan) |
| 552 | res = 8; |
| 553 | if (nan >= plus) |
| 554 | res = 9; |
| 555 | if (nan <= plus) |
| 556 | res = 10; |
| 557 | |
| 558 | if (nan == nan) |
| 559 | res = 1212; |
| 560 | |
| 561 | return res; |
| 562 | } |
| 563 | |
| 564 | static int testDoubleCompare(double minus, double plus, double plus2, |
| 565 | double nan) { |
| 566 | |
| 567 | int res = 4444; |
| 568 | |
| 569 | if (minus > plus) |
| 570 | return 1; |
| 571 | if (plus < minus) |
| 572 | return 2; |
| 573 | if (plus == minus) |
| 574 | return 3; |
| 575 | if (plus != plus2) |
| 576 | return 4; |
| 577 | |
| 578 | if (plus <= nan) |
| 579 | return 5; |
| 580 | if (plus >= nan) |
| 581 | return 6; |
| 582 | if (minus <= nan) |
| 583 | return 7; |
| 584 | if (minus >= nan) |
| 585 | return 8; |
| 586 | if (nan >= plus) |
| 587 | return 9; |
| 588 | if (nan <= plus) |
| 589 | return 10; |
| 590 | |
| 591 | if (nan == nan) |
| 592 | return 11; |
| 593 | return res; |
| 594 | } |
| 595 | |
| 596 | static int fibonacci(int n) { |
| 597 | if (n == 0) { |
| 598 | return 0; |
| 599 | } else if (n == 1) { |
| 600 | return 1; |
| 601 | } else { |
| 602 | return fibonacci(n - 1) + fibonacci(n - 2); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | static void throwNullPointerException() { |
| 608 | throw new NullPointerException("first throw"); |
| 609 | } |
| 610 | |
| 611 | static int throwAndCatch() { |
| 612 | try { |
| 613 | throwNullPointerException(); |
| 614 | return 1; |
| 615 | } catch (NullPointerException npe) { |
| 616 | return 0; |
| 617 | } |
| 618 | } |
| 619 | */ |
| 620 | |
| 621 | static int manyArgs(int a0, long a1, int a2, long a3, int a4, long a5, |
| 622 | int a6, int a7, double a8, float a9, double a10, short a11, int a12, |
| 623 | char a13, int a14, int a15, byte a16, boolean a17, int a18, int a19, |
| 624 | long a20, long a21, int a22, int a23, int a24, int a25, int a26) |
| 625 | { |
| 626 | if (a0 != 0) return 0; |
| 627 | if (a1 != 1L) return 1; |
| 628 | if (a2 != 2) return 2; |
| 629 | if (a3 != 3L) return 3; |
| 630 | if (a4 != 4) return 4; |
| 631 | if (a5 != 5L) return 5; |
| 632 | if (a6 != 6) return 6; |
| 633 | if (a7 != 7) return 7; |
| 634 | if (a8 != 8.0) return 8; |
| 635 | if (a9 != 9.0f) return 9; |
| 636 | if (a10 != 10.0) return 10; |
| 637 | if (a11 != (short)11) return 11; |
| 638 | if (a12 != 12) return 12; |
| 639 | if (a13 != (char)13) return 13; |
| 640 | if (a14 != 14) return 14; |
| 641 | if (a15 != 15) return 15; |
| 642 | if (a16 != (byte)-16) return 16; |
| 643 | if (a17 != true) return 17; |
| 644 | if (a18 != 18) return 18; |
| 645 | if (a19 != 19) return 19; |
| 646 | if (a20 != 20L) return 20; |
| 647 | if (a21 != 21L) return 21; |
| 648 | if (a22 != 22) return 22; |
| 649 | if (a23 != 23) return 23; |
| 650 | if (a24 != 24) return 24; |
| 651 | if (a25 != 25) return 25; |
| 652 | if (a26 != 26) return 26; |
| 653 | return -1; |
| 654 | } |
| 655 | |
| 656 | int virtualCall(int a) |
| 657 | { |
| 658 | return a * 2; |
| 659 | } |
| 660 | |
| 661 | void setFoo(int a) |
| 662 | { |
| 663 | foo_ = a; |
| 664 | } |
| 665 | |
| 666 | int getFoo() |
| 667 | { |
| 668 | return foo_; |
| 669 | } |
| 670 | |
| 671 | static int staticCall(int a) |
| 672 | { |
| 673 | IntMath foo = new IntMath(); |
| 674 | return foo.virtualCall(a); |
| 675 | } |
| 676 | |
| 677 | static int testIGetPut(int a) |
| 678 | { |
| 679 | IntMath foo = new IntMath(99); |
| 680 | IntMath foo123 = new IntMath(); |
| 681 | int z = foo.getFoo(); |
| 682 | z += a; |
| 683 | z += foo123.getFoo(); |
| 684 | foo.setFoo(z); |
| 685 | return foo.getFoo(); |
| 686 | } |
| 687 | |
| 688 | public static void main(String[] args) { |
| 689 | int res = unopTest(38); |
| 690 | if (res == 37) { |
| 691 | System.out.printf("unopTest PASSED\n"); |
| 692 | } else { |
| 693 | System.out.printf("unopTest FAILED: %d\n", res); |
| 694 | } |
| 695 | res = shiftTest1(); |
| 696 | if (res == 0) { |
| 697 | System.out.printf("shiftTest1 PASSED\n"); |
| 698 | } else { |
| 699 | System.out.printf("shiftTest1 FAILED: %d\n", res); |
| 700 | } |
| 701 | res = shiftTest2(); |
| 702 | if (res == 0) { |
| 703 | System.out.printf("shiftTest2 PASSED\n"); |
| 704 | } else { |
| 705 | System.out.printf("shiftTest2 FAILED: %d\n", res); |
| 706 | } |
| 707 | res = unsignedShiftTest(); |
| 708 | if (res == 0) { |
| 709 | System.out.printf("unsignedShiftTest PASSED\n"); |
| 710 | } else { |
| 711 | System.out.printf("unsignedShiftTest FAILED: %d\n", res); |
| 712 | } |
| 713 | res = convTest(); |
| 714 | if (res == 0) { |
| 715 | System.out.printf("convTest PASSED\n"); |
| 716 | } else { |
| 717 | System.out.printf("convTest FAILED: %d\n", res); |
| 718 | } |
| 719 | res = charSubTest(); |
| 720 | if (res == 0) { |
| 721 | System.out.printf("charSubTest PASSED\n"); |
| 722 | } else { |
| 723 | System.out.printf("charSubTest FAILED: %d\n", res); |
| 724 | } |
| 725 | res = intOperTest(70000, -3); |
| 726 | if (res == 0) { |
| 727 | System.out.printf("intOperTest PASSED\n"); |
| 728 | } else { |
| 729 | System.out.printf("intOperTest FAILED: %d\n", res); |
| 730 | } |
| 731 | res = longOperTest(70000000000L, -3L); |
| 732 | if (res == 0) { |
| 733 | System.out.printf("longOperTest PASSED\n"); |
| 734 | } else { |
| 735 | System.out.printf("longOperTest FAILED: %d\n", res); |
| 736 | } |
| 737 | long lres = longShiftTest(0xd5aa96deff00aa01L, 16); |
| 738 | if (lres == 0x96deff00aa010000L) { |
| 739 | System.out.printf("longShiftTest PASSED\n"); |
| 740 | } else { |
| 741 | System.out.printf("longShiftTest FAILED: %d\n", res); |
| 742 | } |
| 743 | |
| 744 | res = switchTest(1); |
| 745 | if (res == 1234) { |
| 746 | System.out.printf("switchTest PASSED\n"); |
| 747 | } else { |
| 748 | System.out.printf("switchTest FAILED: %d\n", res); |
| 749 | } |
| 750 | |
| 751 | res = testIntCompare(-5, 4, 4, 0); |
| 752 | if (res == 1111) { |
| 753 | System.out.printf("testIntCompare PASSED\n"); |
| 754 | } else { |
| 755 | System.out.printf("testIntCompare FAILED: %d\n", res); |
| 756 | } |
| 757 | |
| 758 | res = testLongCompare(-5L, -4294967287L, 4L, 8L); |
| 759 | if (res == 2222) { |
| 760 | System.out.printf("testLongCompare PASSED\n"); |
| 761 | } else { |
| 762 | System.out.printf("testLongCompare FAILED: %d\n", res); |
| 763 | } |
| 764 | |
| 765 | res = testFloatCompare(-5.0f, 4.0f, 4.0f, (1.0f/0.0f) / (1.0f/0.0f)); |
| 766 | if (res == 3333) { |
| 767 | System.out.printf("testFloatCompare PASSED\n"); |
| 768 | } else { |
| 769 | System.out.printf("testFloatCompare FAILED: %d\n", res); |
| 770 | } |
| 771 | |
| 772 | res = testDoubleCompare(-5.0, 4.0, 4.0, (1.0/0.0) / (1.0/0.0)); |
| 773 | if (res == 4444) { |
| 774 | System.out.printf("testDoubleCompare PASSED\n"); |
| 775 | } else { |
| 776 | System.out.printf("testDoubleCompare FAILED: %d\n", res); |
| 777 | } |
| 778 | |
| 779 | res = fibonacci(10); |
| 780 | if (res == 55) { |
| 781 | System.out.printf("fibonacci PASSED\n"); |
| 782 | } else { |
| 783 | System.out.printf("fibonacci FAILED: %d\n", res); |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | res = throwAndCatch(); |
| 788 | if (res == 0) { |
| 789 | System.out.printf("throwAndCatch PASSED\n"); |
| 790 | } else { |
| 791 | System.out.printf("throwAndCatch FAILED: %d\n", res); |
| 792 | } |
| 793 | */ |
| 794 | |
| 795 | res = manyArgs(0, 1L, 2, 3L, 4, 5L, 6, 7, 8.0, 9.0f, 10.0, |
| 796 | (short)11, 12, (char)13, 14, 15, (byte)-16, true, 18, |
| 797 | 19, 20L, 21L, 22, 23, 24, 25, 26); |
| 798 | if (res == -1) { |
| 799 | System.out.printf("manyArgs PASSED\n"); |
| 800 | } else { |
| 801 | System.out.printf("manyArgs FAILED: %d\n", res); |
| 802 | } |
| 803 | |
| 804 | res = staticCall(3); |
| 805 | if (res == 6) { |
| 806 | System.out.printf("virtualCall PASSED\n"); |
| 807 | } else { |
| 808 | System.out.printf("virtualCall FAILED: %d\n", res); |
| 809 | } |
| 810 | |
| 811 | res = testIGetPut(111); |
| 812 | if (res == 333) { |
| 813 | System.out.printf("testGetPut PASSED\n"); |
| 814 | } else { |
| 815 | System.out.printf("testGetPut FAILED: %d\n", res); |
| 816 | } |
| 817 | |
| 818 | res = staticFieldTest(404); |
| 819 | if (res == 1404) { |
| 820 | System.out.printf("staticFieldTest PASSED\n"); |
| 821 | } else { |
| 822 | System.out.printf("staticFieldTest FAILED: %d\n", res); |
| 823 | } |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame^] | 824 | |
| 825 | res = catchBlock(1000); |
| 826 | if (res == 1579) { |
| 827 | System.out.printf("catchBlock PASSED\n"); |
| 828 | } else { |
| 829 | System.out.printf("catchBlock FAILED: %d\n", res); |
| 830 | } |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 831 | } |
| 832 | } |