1 /* 2 * Copyright (C) 2011-2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.renderscript.cts; 18 19 import android.renderscript.Allocation; 20 21 import android.renderscript.Byte2; 22 import android.renderscript.Byte3; 23 import android.renderscript.Byte4; 24 25 import android.renderscript.Double2; 26 import android.renderscript.Double3; 27 import android.renderscript.Double4; 28 29 import android.renderscript.Element; 30 31 import android.renderscript.Float2; 32 import android.renderscript.Float3; 33 import android.renderscript.Float4; 34 35 import android.renderscript.Int2; 36 import android.renderscript.Int3; 37 import android.renderscript.Int4; 38 39 import android.renderscript.Long2; 40 import android.renderscript.Long3; 41 import android.renderscript.Long4; 42 43 import android.renderscript.RSRuntimeException; 44 45 import android.renderscript.Short2; 46 import android.renderscript.Short3; 47 import android.renderscript.Short4; 48 49 import android.renderscript.Type; 50 51 import com.android.cts.stub.R; 52 53 public class ComputeTest extends RSBaseCompute { 54 testJavaVectorTypes()55 public void testJavaVectorTypes() { 56 Byte2 b2 = new Byte2(); 57 b2.x = 1; 58 b2.y = 2; 59 b2 = new Byte2((byte)1, (byte)2); 60 assertTrue(b2.x == 1); 61 assertTrue(b2.y == 2); 62 Byte3 b3 = new Byte3(); 63 b3.x = 1; 64 b3.y = 2; 65 b3.z = 2; 66 b3 = new Byte3((byte)1, (byte)2, (byte)3); 67 assertTrue(b3.x == 1); 68 assertTrue(b3.y == 2); 69 assertTrue(b3.z == 3); 70 Byte4 b4 = new Byte4(); 71 b4.x = 1; 72 b4.y = 2; 73 b4.x = 3; 74 b4.w = 4; 75 b4 = new Byte4((byte)1, (byte)2, (byte)3, (byte)4); 76 assertTrue(b4.x == 1); 77 assertTrue(b4.y == 2); 78 assertTrue(b4.z == 3); 79 assertTrue(b4.w == 4); 80 81 Double2 d2 = new Double2(); 82 d2.x = 1.0; 83 d2.y = 2.0; 84 d2 = new Double2(1.0, 2.0); 85 assertTrue(d2.x == 1.0); 86 assertTrue(d2.y == 2.0); 87 Double3 d3 = new Double3(); 88 d3.x = 1.0; 89 d3.y = 2.0; 90 d3.z = 3.0; 91 d3 = new Double3(1.0, 2.0, 3.0); 92 assertTrue(d3.x == 1.0); 93 assertTrue(d3.y == 2.0); 94 assertTrue(d3.z == 3.0); 95 Double4 d4 = new Double4(); 96 d4.x = 1.0; 97 d4.y = 2.0; 98 d4.x = 3.0; 99 d4.w = 4.0; 100 d4 = new Double4(1.0, 2.0, 3.0, 4.0); 101 assertTrue(d4.x == 1.0); 102 assertTrue(d4.y == 2.0); 103 assertTrue(d4.z == 3.0); 104 assertTrue(d4.w == 4.0); 105 106 Float2 f2 = new Float2(); 107 f2.x = 1.0f; 108 f2.y = 2.0f; 109 f2 = new Float2(1.0f, 2.0f); 110 assertTrue(f2.x == 1.0f); 111 assertTrue(f2.y == 2.0f); 112 Float3 f3 = new Float3(); 113 f3.x = 1.0f; 114 f3.y = 2.0f; 115 f3.z = 3.0f; 116 f3 = new Float3(1.0f, 2.0f, 3.0f); 117 assertTrue(f3.x == 1.0f); 118 assertTrue(f3.y == 2.0f); 119 assertTrue(f3.z == 3.0f); 120 Float4 f4 = new Float4(); 121 f4.x = 1.0f; 122 f4.y = 2.0f; 123 f4.x = 3.0f; 124 f4.w = 4.0f; 125 f4 = new Float4(1.0f, 2.0f, 3.0f, 4.0f); 126 assertTrue(f4.x == 1.0f); 127 assertTrue(f4.y == 2.0f); 128 assertTrue(f4.z == 3.0f); 129 assertTrue(f4.w == 4.0f); 130 131 Int2 i2 = new Int2(); 132 i2.x = 1; 133 i2.y = 2; 134 i2 = new Int2(1, 2); 135 assertTrue(i2.x == 1); 136 assertTrue(i2.y == 2); 137 Int3 i3 = new Int3(); 138 i3.x = 1; 139 i3.y = 2; 140 i3.z = 3; 141 i3 = new Int3(1, 2, 3); 142 assertTrue(i3.x == 1); 143 assertTrue(i3.y == 2); 144 assertTrue(i3.z == 3); 145 Int4 i4 = new Int4(); 146 i4.x = 1; 147 i4.y = 2; 148 i4.x = 3; 149 i4.w = 4; 150 i4 = new Int4(1, 2, 3, 4); 151 assertTrue(i4.x == 1); 152 assertTrue(i4.y == 2); 153 assertTrue(i4.z == 3); 154 assertTrue(i4.w == 4); 155 156 Long2 l2 = new Long2(); 157 l2.x = 1; 158 l2.y = 2; 159 l2 = new Long2(1, 2); 160 assertTrue(l2.x == 1); 161 assertTrue(l2.y == 2); 162 Long3 l3 = new Long3(); 163 l3.x = 1; 164 l3.y = 2; 165 l3.z = 3; 166 l3 = new Long3(1, 2, 3); 167 assertTrue(l3.x == 1); 168 assertTrue(l3.y == 2); 169 assertTrue(l3.z == 3); 170 Long4 l4 = new Long4(); 171 l4.x = 1; 172 l4.y = 2; 173 l4.x = 3; 174 l4.w = 4; 175 l4 = new Long4(1, 2, 3, 4); 176 assertTrue(l4.x == 1); 177 assertTrue(l4.y == 2); 178 assertTrue(l4.z == 3); 179 assertTrue(l4.w == 4); 180 181 Short2 s2 = new Short2(); 182 s2.x = 1; 183 s2.y = 2; 184 s2 = new Short2((short)1, (short)2); 185 assertTrue(s2.x == 1); 186 assertTrue(s2.y == 2); 187 Short3 s3 = new Short3(); 188 s3.x = 1; 189 s3.y = 2; 190 s3.z = 3; 191 s3 = new Short3((short)1, (short)2, (short)3); 192 assertTrue(s3.x == 1); 193 assertTrue(s3.y == 2); 194 assertTrue(s3.z == 3); 195 Short4 s4 = new Short4(); 196 s4.x = 1; 197 s4.y = 2; 198 s4.x = 3; 199 s4.w = 4; 200 s4 = new Short4((short)1, (short)2, (short)3, (short)4); 201 assertTrue(s4.x == 1); 202 assertTrue(s4.y == 2); 203 assertTrue(s4.z == 3); 204 assertTrue(s4.w == 4); 205 } 206 initializeGlobals(ScriptC_primitives s)207 private boolean initializeGlobals(ScriptC_primitives s) { 208 float pF = s.get_floatTest(); 209 if (pF != 1.99f) { 210 return false; 211 } 212 s.set_floatTest(2.99f); 213 214 double pD = s.get_doubleTest(); 215 if (pD != 2.05) { 216 return false; 217 } 218 s.set_doubleTest(3.05); 219 220 byte pC = s.get_charTest(); 221 if (pC != -8) { 222 return false; 223 } 224 s.set_charTest((byte)-16); 225 226 short pS = s.get_shortTest(); 227 if (pS != -16) { 228 return false; 229 } 230 s.set_shortTest((short)-32); 231 232 int pI = s.get_intTest(); 233 if (pI != -32) { 234 return false; 235 } 236 s.set_intTest(-64); 237 238 long pL = s.get_longTest(); 239 if (pL != 17179869184l) { 240 return false; 241 } 242 s.set_longTest(17179869185l); 243 244 long puL = s.get_ulongTest(); 245 if (puL != 4611686018427387904L) { 246 return false; 247 } 248 s.set_ulongTest(4611686018427387903L); 249 250 long pLL = s.get_longlongTest(); 251 if (pLL != 68719476736L) { 252 return false; 253 } 254 s.set_longlongTest(68719476735L); 255 256 long pu64 = s.get_uint64_tTest(); 257 if (pu64 != 117179869184l) { 258 return false; 259 } 260 s.set_uint64_tTest(117179869185l); 261 262 ScriptField_AllVectorTypes avt; 263 avt = new ScriptField_AllVectorTypes(mRS, 1, 264 Allocation.USAGE_SCRIPT); 265 ScriptField_AllVectorTypes.Item avtItem; 266 avtItem = new ScriptField_AllVectorTypes.Item(); 267 avtItem.b2.x = 1; 268 avtItem.b2.y = 2; 269 avtItem.b3.x = 1; 270 avtItem.b3.y = 2; 271 avtItem.b3.z = 3; 272 avtItem.b4.x = 1; 273 avtItem.b4.y = 2; 274 avtItem.b4.z = 3; 275 avtItem.b4.w = 4; 276 277 avtItem.s2.x = 1; 278 avtItem.s2.y = 2; 279 avtItem.s3.x = 1; 280 avtItem.s3.y = 2; 281 avtItem.s3.z = 3; 282 avtItem.s4.x = 1; 283 avtItem.s4.y = 2; 284 avtItem.s4.z = 3; 285 avtItem.s4.w = 4; 286 287 avtItem.i2.x = 1; 288 avtItem.i2.y = 2; 289 avtItem.i3.x = 1; 290 avtItem.i3.y = 2; 291 avtItem.i3.z = 3; 292 avtItem.i4.x = 1; 293 avtItem.i4.y = 2; 294 avtItem.i4.z = 3; 295 avtItem.i4.w = 4; 296 297 avtItem.f2.x = 1.0f; 298 avtItem.f2.y = 2.0f; 299 avtItem.f3.x = 1.0f; 300 avtItem.f3.y = 2.0f; 301 avtItem.f3.z = 3.0f; 302 avtItem.f4.x = 1.0f; 303 avtItem.f4.y = 2.0f; 304 avtItem.f4.z = 3.0f; 305 avtItem.f4.w = 4.0f; 306 307 avt.set(avtItem, 0, true); 308 s.bind_avt(avt); 309 310 return true; 311 } 312 313 /** 314 * Test primitive types. 315 */ testPrimitives()316 public void testPrimitives() { 317 ScriptC_primitives t = new ScriptC_primitives(mRS, 318 mRes, 319 R.raw.primitives); 320 321 assertTrue(initializeGlobals(t)); 322 t.invoke_test(); 323 waitForMessage(); 324 checkForErrors(); 325 } 326 checkInit(ScriptC_array_init s)327 private void checkInit(ScriptC_array_init s) { 328 float[] fa = s.get_fa(); 329 assertTrue(fa[0] == 1.0); 330 assertTrue(fa[1] == 9.9999f); 331 assertTrue(fa[2] == 0); 332 assertTrue(fa[3] == 0); 333 assertTrue(fa.length == 4); 334 335 double[] da = s.get_da(); 336 assertTrue(da[0] == 7.0); 337 assertTrue(da[1] == 8.88888); 338 assertTrue(da.length == 2); 339 340 byte[] ca = s.get_ca(); 341 assertTrue(ca[0] == 'a'); 342 assertTrue(ca[1] == 7); 343 assertTrue(ca[2] == 'b'); 344 assertTrue(ca[3] == 'c'); 345 assertTrue(ca.length == 4); 346 347 short[] sa = s.get_sa(); 348 assertTrue(sa[0] == 1); 349 assertTrue(sa[1] == 1); 350 assertTrue(sa[2] == 2); 351 assertTrue(sa[3] == 3); 352 assertTrue(sa.length == 4); 353 354 int[] ia = s.get_ia(); 355 assertTrue(ia[0] == 5); 356 assertTrue(ia[1] == 8); 357 assertTrue(ia[2] == 0); 358 assertTrue(ia[3] == 0); 359 assertTrue(ia.length == 4); 360 361 long[] la = s.get_la(); 362 assertTrue(la[0] == 13); 363 assertTrue(la[1] == 21); 364 assertTrue(la.length == 2); 365 366 long[] lla = s.get_lla(); 367 assertTrue(lla[0] == 34); 368 assertTrue(lla[1] == 0); 369 assertTrue(lla[2] == 0); 370 assertTrue(lla[3] == 0); 371 assertTrue(lla.length == 4); 372 373 boolean[] ba = s.get_ba(); 374 assertTrue(ba[0] == true); 375 assertTrue(ba[1] == false); 376 assertTrue(ba[2] == false); 377 assertTrue(ba.length == 3); 378 } 379 380 /** 381 * Test array initialization. 382 */ testArrayInit()383 public void testArrayInit() { 384 ScriptC_array_init t = new ScriptC_array_init(mRS, 385 mRes, 386 R.raw.array_init); 387 388 checkInit(t); 389 t.invoke_array_init_test(); 390 Element[] e = new Element[2]; 391 e[0] = Element.FONT(mRS); 392 e[1] = Element.ELEMENT(mRS); 393 t.set_elemArr(e); 394 mRS.finish(); 395 waitForMessage(); 396 checkForErrors(); 397 } 398 399 initializeVector(ScriptC_vector s)400 private boolean initializeVector(ScriptC_vector s) { 401 Float2 F2 = s.get_f2(); 402 if (F2.x != 1.0f || F2.y != 2.0f) { 403 return false; 404 } 405 F2.x = 2.99f; 406 F2.y = 3.99f; 407 s.set_f2(F2); 408 409 Float3 F3 = s.get_f3(); 410 if (F3.x != 1.0f || F3.y != 2.0f || F3.z != 3.0f) { 411 return false; 412 } 413 F3.x = 2.99f; 414 F3.y = 3.99f; 415 F3.z = 4.99f; 416 s.set_f3(F3); 417 418 Float4 F4 = s.get_f4(); 419 if (F4.x != 1.0f || F4.y != 2.0f || F4.z != 3.0f || F4.w != 4.0f) { 420 return false; 421 } 422 F4.x = 2.99f; 423 F4.y = 3.99f; 424 F4.z = 4.99f; 425 F4.w = 5.99f; 426 s.set_f4(F4); 427 428 Double2 D2 = s.get_d2(); 429 if (D2.x != 1.0 || D2.y != 2.0) { 430 return false; 431 } 432 D2.x = 2.99; 433 D2.y = 3.99; 434 s.set_d2(D2); 435 436 Double3 D3 = s.get_d3(); 437 if (D3.x != 1.0 || D3.y != 2.0 || D3.z != 3.0) { 438 return false; 439 } 440 D3.x = 2.99; 441 D3.y = 3.99; 442 D3.z = 4.99; 443 s.set_d3(D3); 444 445 Double4 D4 = s.get_d4(); 446 if (D4.x != 1.0 || D4.y != 2.0 || D4.z != 3.0 || D4.w != 4.0) { 447 return false; 448 } 449 D4.x = 2.99; 450 D4.y = 3.99; 451 D4.z = 4.99; 452 D4.w = 5.99; 453 s.set_d4(D4); 454 455 Byte2 B2 = s.get_i8_2(); 456 if (B2.x != 1 || B2.y != 2) { 457 return false; 458 } 459 B2.x = 2; 460 B2.y = 3; 461 s.set_i8_2(B2); 462 463 Byte3 B3 = s.get_i8_3(); 464 if (B3.x != 1 || B3.y != 2 || B3.z != 3) { 465 return false; 466 } 467 B3.x = 2; 468 B3.y = 3; 469 B3.z = 4; 470 s.set_i8_3(B3); 471 472 Byte4 B4 = s.get_i8_4(); 473 if (B4.x != 1 || B4.y != 2 || B4.z != 3 || B4.w != 4) { 474 return false; 475 } 476 B4.x = 2; 477 B4.y = 3; 478 B4.z = 4; 479 B4.w = 5; 480 s.set_i8_4(B4); 481 482 Short2 S2 = s.get_u8_2(); 483 if (S2.x != 1 || S2.y != 2) { 484 return false; 485 } 486 S2.x = 2; 487 S2.y = 3; 488 s.set_u8_2(S2); 489 490 Short3 S3 = s.get_u8_3(); 491 if (S3.x != 1 || S3.y != 2 || S3.z != 3) { 492 return false; 493 } 494 S3.x = 2; 495 S3.y = 3; 496 S3.z = 4; 497 s.set_u8_3(S3); 498 499 Short4 S4 = s.get_u8_4(); 500 if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) { 501 return false; 502 } 503 S4.x = 2; 504 S4.y = 3; 505 S4.z = 4; 506 S4.w = 5; 507 s.set_u8_4(S4); 508 509 S2 = s.get_i16_2(); 510 if (S2.x != 1 || S2.y != 2) { 511 return false; 512 } 513 S2.x = 2; 514 S2.y = 3; 515 s.set_i16_2(S2); 516 517 S3 = s.get_i16_3(); 518 if (S3.x != 1 || S3.y != 2 || S3.z != 3) { 519 return false; 520 } 521 S3.x = 2; 522 S3.y = 3; 523 S3.z = 4; 524 s.set_i16_3(S3); 525 526 S4 = s.get_i16_4(); 527 if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) { 528 return false; 529 } 530 S4.x = 2; 531 S4.y = 3; 532 S4.z = 4; 533 S4.w = 5; 534 s.set_i16_4(S4); 535 536 Int2 I2 = s.get_u16_2(); 537 if (I2.x != 1 || I2.y != 2) { 538 return false; 539 } 540 I2.x = 2; 541 I2.y = 3; 542 s.set_u16_2(I2); 543 544 Int3 I3 = s.get_u16_3(); 545 if (I3.x != 1 || I3.y != 2 || I3.z != 3) { 546 return false; 547 } 548 I3.x = 2; 549 I3.y = 3; 550 I3.z = 4; 551 s.set_u16_3(I3); 552 553 Int4 I4 = s.get_u16_4(); 554 if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) { 555 return false; 556 } 557 I4.x = 2; 558 I4.y = 3; 559 I4.z = 4; 560 I4.w = 5; 561 s.set_u16_4(I4); 562 563 I2 = s.get_i32_2(); 564 if (I2.x != 1 || I2.y != 2) { 565 return false; 566 } 567 I2.x = 2; 568 I2.y = 3; 569 s.set_i32_2(I2); 570 571 I3 = s.get_i32_3(); 572 if (I3.x != 1 || I3.y != 2 || I3.z != 3) { 573 return false; 574 } 575 I3.x = 2; 576 I3.y = 3; 577 I3.z = 4; 578 s.set_i32_3(I3); 579 580 I4 = s.get_i32_4(); 581 if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) { 582 return false; 583 } 584 I4.x = 2; 585 I4.y = 3; 586 I4.z = 4; 587 I4.w = 5; 588 s.set_i32_4(I4); 589 590 Long2 L2 = s.get_u32_2(); 591 if (L2.x != 1 || L2.y != 2) { 592 return false; 593 } 594 L2.x = 2; 595 L2.y = 3; 596 s.set_u32_2(L2); 597 598 Long3 L3 = s.get_u32_3(); 599 if (L3.x != 1 || L3.y != 2 || L3.z != 3) { 600 return false; 601 } 602 L3.x = 2; 603 L3.y = 3; 604 L3.z = 4; 605 s.set_u32_3(L3); 606 607 Long4 L4 = s.get_u32_4(); 608 if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) { 609 return false; 610 } 611 L4.x = 2; 612 L4.y = 3; 613 L4.z = 4; 614 L4.w = 5; 615 s.set_u32_4(L4); 616 617 L2 = s.get_i64_2(); 618 if (L2.x != 1 || L2.y != 2) { 619 return false; 620 } 621 L2.x = 2; 622 L2.y = 3; 623 s.set_i64_2(L2); 624 625 L3 = s.get_i64_3(); 626 if (L3.x != 1 || L3.y != 2 || L3.z != 3) { 627 return false; 628 } 629 L3.x = 2; 630 L3.y = 3; 631 L3.z = 4; 632 s.set_i64_3(L3); 633 634 L4 = s.get_i64_4(); 635 if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) { 636 return false; 637 } 638 L4.x = 2; 639 L4.y = 3; 640 L4.z = 4; 641 L4.w = 5; 642 s.set_i64_4(L4); 643 644 L2 = s.get_u64_2(); 645 if (L2.x != 1 || L2.y != 2) { 646 return false; 647 } 648 L2.x = 2; 649 L2.y = 3; 650 s.set_u64_2(L2); 651 652 L3 = s.get_u64_3(); 653 if (L3.x != 1 || L3.y != 2 || L3.z != 3) { 654 return false; 655 } 656 L3.x = 2; 657 L3.y = 3; 658 L3.z = 4; 659 s.set_u64_3(L3); 660 661 L4 = s.get_u64_4(); 662 if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) { 663 return false; 664 } 665 L4.x = 2; 666 L4.y = 3; 667 L4.z = 4; 668 L4.w = 5; 669 s.set_u64_4(L4); 670 671 return true; 672 } 673 testVector()674 public void testVector() { 675 ScriptC_vector s = new ScriptC_vector(mRS, mRes, R.raw.vector); 676 if (!initializeVector(s)) { 677 fail("Failed to init vector components"); 678 } else { 679 s.invoke_vector_test(); 680 mRS.finish(); 681 waitForMessage(); 682 } 683 checkForErrors(); 684 } 685 initializeStructObject(ScriptC_struct_object s)686 private boolean initializeStructObject(ScriptC_struct_object s) { 687 ScriptField_objects_rs.Item i = new ScriptField_objects_rs.Item(); 688 i.e = Element.FONT(mRS); 689 i.i = 1; 690 s.set_myStruct(i); 691 return true; 692 } 693 testStructObject()694 public void testStructObject() { 695 ScriptC_struct_object s = 696 new ScriptC_struct_object(mRS, mRes, R.raw.struct_object); 697 if (!initializeStructObject(s)) { 698 fail("Failed to init structure with RS objects"); 699 } else { 700 s.invoke_struct_object_test(); 701 mRS.finish(); 702 waitForMessage(); 703 } 704 checkForErrors(); 705 } 706 testClamp()707 public void testClamp() { 708 ScriptC_clamp s = new ScriptC_clamp(mRS, mRes, R.raw.clamp); 709 s.invoke_clamp_test(); 710 mRS.finish(); 711 waitForMessage(); 712 checkForErrors(); 713 } 714 testClampRelaxed()715 public void testClampRelaxed() { 716 ScriptC_clamp_relaxed s = 717 new ScriptC_clamp_relaxed(mRS, mRes, R.raw.clamp_relaxed); 718 s.invoke_clamp_test(); 719 mRS.finish(); 720 waitForMessage(); 721 checkForErrors(); 722 } 723 724 /** 725 * Test utility functions. 726 */ testUtilityFunctions()727 public void testUtilityFunctions() { 728 ScriptC_primitives t = new ScriptC_primitives(mRS, 729 mRes, 730 R.raw.utils); 731 t.invoke_test(); 732 waitForMessage(); 733 checkForErrors(); 734 } 735 setUpAllocation(Allocation a, int val)736 void setUpAllocation(Allocation a, int val) { 737 Type t = a.getType(); 738 int x = t.getX(); 739 740 int[] arr = new int[x]; 741 for (int i = 0; i < x; i++) { 742 arr[i] = val; 743 } 744 a.copyFrom(arr); 745 } 746 checkAllocation(Allocation a, int val)747 void checkAllocation(Allocation a, int val) { 748 Type t = a.getType(); 749 int x = t.getX(); 750 751 int[] arr = new int[x]; 752 a.copyTo(arr); 753 for (int i = 0; i < x; i++) { 754 assertTrue(arr[i] == val); 755 } 756 } 757 758 /** 759 * Test support for reflected forEach() as well as validation of parameters. 760 */ testForEach()761 public void testForEach() { 762 ScriptC_negate s = new ScriptC_negate(mRS, 763 mRes, 764 R.raw.negate); 765 766 int x = 7; 767 Type t = new Type.Builder(mRS, Element.I32(mRS)).setX(x).create(); 768 Allocation in = Allocation.createTyped(mRS, t); 769 Allocation out = Allocation.createTyped(mRS, t); 770 771 int val = 5; 772 setUpAllocation(in, val); 773 s.forEach_root(in, out); 774 checkAllocation(out, -val); 775 776 Type badT = new Type.Builder(mRS, Element.I32(mRS)).setX(x-1).create(); 777 Allocation badOut = Allocation.createTyped(mRS, badT); 778 try { 779 s.forEach_root(in, badOut); 780 fail("should throw RSRuntimeException"); 781 } catch (RSRuntimeException e) { 782 } 783 checkForErrors(); 784 } 785 } 786