J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* Type-specific source code for unit test |
| 25 | * |
| 26 | * Regenerate the BasicX classes via genBasic.sh whenever this file changes. |
| 27 | * We check in the generated source files so that the test tree can be used |
| 28 | * independently of the rest of the source tree. |
| 29 | */ |
| 30 | |
| 31 | // -- This file was mechanically generated: Do not edit! -- // |
| 32 | |
| 33 | import java.nio.*; |
| 34 | |
| 35 | |
| 36 | public class BasicFloat |
| 37 | extends Basic |
| 38 | { |
| 39 | |
| 40 | private static void relGet(FloatBuffer b) { |
| 41 | int n = b.capacity(); |
| 42 | float v; |
| 43 | for (int i = 0; i < n; i++) |
| 44 | ck(b, (long)b.get(), (long)((float)ic(i))); |
| 45 | b.rewind(); |
| 46 | } |
| 47 | |
| 48 | private static void relGet(FloatBuffer b, int start) { |
| 49 | int n = b.remaining(); |
| 50 | float v; |
| 51 | for (int i = start; i < n; i++) |
| 52 | ck(b, (long)b.get(), (long)((float)ic(i))); |
| 53 | b.rewind(); |
| 54 | } |
| 55 | |
| 56 | private static void absGet(FloatBuffer b) { |
| 57 | int n = b.capacity(); |
| 58 | float v; |
| 59 | for (int i = 0; i < n; i++) |
| 60 | ck(b, (long)b.get(), (long)((float)ic(i))); |
| 61 | b.rewind(); |
| 62 | } |
| 63 | |
| 64 | private static void bulkGet(FloatBuffer b) { |
| 65 | int n = b.capacity(); |
| 66 | float[] a = new float[n + 7]; |
| 67 | b.get(a, 7, n); |
| 68 | for (int i = 0; i < n; i++) |
| 69 | ck(b, (long)a[i + 7], (long)((float)ic(i))); |
| 70 | } |
| 71 | |
| 72 | private static void relPut(FloatBuffer b) { |
| 73 | int n = b.capacity(); |
| 74 | b.clear(); |
| 75 | for (int i = 0; i < n; i++) |
| 76 | b.put((float)ic(i)); |
| 77 | b.flip(); |
| 78 | } |
| 79 | |
| 80 | private static void absPut(FloatBuffer b) { |
| 81 | int n = b.capacity(); |
| 82 | b.clear(); |
| 83 | for (int i = 0; i < n; i++) |
| 84 | b.put(i, (float)ic(i)); |
| 85 | b.limit(n); |
| 86 | b.position(0); |
| 87 | } |
| 88 | |
| 89 | private static void bulkPutArray(FloatBuffer b) { |
| 90 | int n = b.capacity(); |
| 91 | b.clear(); |
| 92 | float[] a = new float[n + 7]; |
| 93 | for (int i = 0; i < n; i++) |
| 94 | a[i + 7] = (float)ic(i); |
| 95 | b.put(a, 7, n); |
| 96 | b.flip(); |
| 97 | } |
| 98 | |
| 99 | private static void bulkPutBuffer(FloatBuffer b) { |
| 100 | int n = b.capacity(); |
| 101 | b.clear(); |
| 102 | FloatBuffer c = FloatBuffer.allocate(n + 7); |
| 103 | c.position(7); |
| 104 | for (int i = 0; i < n; i++) |
| 105 | c.put((float)ic(i)); |
| 106 | c.flip(); |
| 107 | c.position(7); |
| 108 | b.put(c); |
| 109 | b.flip(); |
| 110 | } |
| 111 | |
| 112 | //6231529 |
| 113 | private static void callReset(FloatBuffer b) { |
| 114 | b.position(0); |
| 115 | b.mark(); |
| 116 | |
| 117 | b.duplicate().reset(); |
| 118 | b.asReadOnlyBuffer().reset(); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | |
| 123 | // 6221101-6234263 |
| 124 | |
| 125 | private static void putBuffer() { |
| 126 | final int cap = 10; |
| 127 | |
| 128 | FloatBuffer direct1 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
| 129 | FloatBuffer nondirect1 = ByteBuffer.allocate(cap).asFloatBuffer(); |
| 130 | direct1.put(nondirect1); |
| 131 | |
| 132 | FloatBuffer direct2 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
| 133 | FloatBuffer nondirect2 = ByteBuffer.allocate(cap).asFloatBuffer(); |
| 134 | nondirect2.put(direct2); |
| 135 | |
| 136 | FloatBuffer direct3 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
| 137 | FloatBuffer direct4 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
| 138 | direct3.put(direct4); |
| 139 | |
| 140 | FloatBuffer nondirect3 = ByteBuffer.allocate(cap).asFloatBuffer(); |
| 141 | FloatBuffer nondirect4 = ByteBuffer.allocate(cap).asFloatBuffer(); |
| 142 | nondirect3.put(nondirect4); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | private static void checkSlice(FloatBuffer b, FloatBuffer slice) { |
| 162 | ck(slice, 0, slice.position()); |
| 163 | ck(slice, b.remaining(), slice.limit()); |
| 164 | ck(slice, b.remaining(), slice.capacity()); |
| 165 | if (b.isDirect() != slice.isDirect()) |
| 166 | fail("Lost direction", slice); |
| 167 | if (b.isReadOnly() != slice.isReadOnly()) |
| 168 | fail("Lost read-only", slice); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | private static void tryCatch(Buffer b, Class ex, Runnable thunk) { |
| 287 | boolean caught = false; |
| 288 | try { |
| 289 | thunk.run(); |
| 290 | } catch (Throwable x) { |
| 291 | if (ex.isAssignableFrom(x.getClass())) |
| 292 | caught = true; |
| 293 | } |
| 294 | if (!caught) |
| 295 | fail(ex.getName() + " not thrown", b); |
| 296 | } |
| 297 | |
| 298 | private static void tryCatch(float [] t, Class ex, Runnable thunk) { |
| 299 | tryCatch(FloatBuffer.wrap(t), ex, thunk); |
| 300 | } |
| 301 | |
| 302 | public static void test(int level, final FloatBuffer b, boolean direct) { |
| 303 | |
| 304 | show(level, b); |
| 305 | |
| 306 | if (direct != b.isDirect()) |
| 307 | fail("Wrong direction", b); |
| 308 | |
| 309 | // Gets and puts |
| 310 | |
| 311 | relPut(b); |
| 312 | relGet(b); |
| 313 | absGet(b); |
| 314 | bulkGet(b); |
| 315 | |
| 316 | absPut(b); |
| 317 | relGet(b); |
| 318 | absGet(b); |
| 319 | bulkGet(b); |
| 320 | |
| 321 | bulkPutArray(b); |
| 322 | relGet(b); |
| 323 | |
| 324 | bulkPutBuffer(b); |
| 325 | relGet(b); |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | // Compact |
| 350 | |
| 351 | relPut(b); |
| 352 | b.position(13); |
| 353 | b.compact(); |
| 354 | b.flip(); |
| 355 | relGet(b, 13); |
| 356 | |
| 357 | // Exceptions |
| 358 | |
| 359 | boolean caught = false; |
| 360 | relPut(b); |
| 361 | b.limit(b.capacity() / 2); |
| 362 | b.position(b.limit()); |
| 363 | |
| 364 | tryCatch(b, BufferUnderflowException.class, new Runnable() { |
| 365 | public void run() { |
| 366 | b.get(); |
| 367 | }}); |
| 368 | |
| 369 | tryCatch(b, BufferOverflowException.class, new Runnable() { |
| 370 | public void run() { |
| 371 | b.put((float)42); |
| 372 | }}); |
| 373 | |
| 374 | // The index must be non-negative and lesss than the buffer's limit. |
| 375 | tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
| 376 | public void run() { |
| 377 | b.get(b.limit()); |
| 378 | }}); |
| 379 | tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
| 380 | public void run() { |
| 381 | b.get(-1); |
| 382 | }}); |
| 383 | |
| 384 | tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
| 385 | public void run() { |
| 386 | b.put(b.limit(), (float)42); |
| 387 | }}); |
| 388 | |
| 389 | // Values |
| 390 | |
| 391 | b.clear(); |
| 392 | b.put((float)0); |
| 393 | b.put((float)-1); |
| 394 | b.put((float)1); |
| 395 | b.put(Float.MAX_VALUE); |
| 396 | b.put(Float.MIN_VALUE); |
| 397 | |
| 398 | b.put(-Float.MAX_VALUE); |
| 399 | b.put(-Float.MIN_VALUE); |
| 400 | b.put(Float.NEGATIVE_INFINITY); |
| 401 | b.put(Float.POSITIVE_INFINITY); |
| 402 | b.put(Float.NaN); |
| 403 | b.put(0.91697687f); // Changes value if incorrectly swapped |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | float v; |
| 415 | b.flip(); |
| 416 | ck(b, b.get(), 0); |
| 417 | ck(b, b.get(), (float)-1); |
| 418 | ck(b, b.get(), 1); |
| 419 | ck(b, b.get(), Float.MAX_VALUE); |
| 420 | ck(b, b.get(), Float.MIN_VALUE); |
| 421 | |
| 422 | |
| 423 | ck(b, b.get(), -Float.MAX_VALUE); |
| 424 | ck(b, b.get(), -Float.MIN_VALUE); |
| 425 | ck(b, b.get(), Float.NEGATIVE_INFINITY); |
| 426 | ck(b, b.get(), Float.POSITIVE_INFINITY); |
| 427 | if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN)) |
| 428 | fail(b, (long)Float.NaN, (long)v); |
| 429 | ck(b, b.get(), 0.91697687f); |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | // Comparison |
| 444 | b.rewind(); |
| 445 | FloatBuffer b2 = FloatBuffer.allocate(b.capacity()); |
| 446 | b2.put(b); |
| 447 | b2.flip(); |
| 448 | b.position(2); |
| 449 | b2.position(2); |
| 450 | if (!b.equals(b2)) { |
| 451 | for (int i = 2; i < b.limit(); i++) { |
| 452 | float x = b.get(i); |
| 453 | float y = b2.get(i); |
| 454 | if (x != y |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | || Float.compare(x, y) != 0 |
| 460 | |
| 461 | ) |
| 462 | out.println("[" + i + "] " + x + " != " + y); |
| 463 | } |
| 464 | fail("Identical buffers not equal", b, b2); |
| 465 | } |
| 466 | if (b.compareTo(b2) != 0) |
| 467 | fail("Comparison to identical buffer != 0", b, b2); |
| 468 | |
| 469 | b.limit(b.limit() + 1); |
| 470 | b.position(b.limit() - 1); |
| 471 | b.put((float)99); |
| 472 | b.rewind(); |
| 473 | b2.rewind(); |
| 474 | if (b.equals(b2)) |
| 475 | fail("Non-identical buffers equal", b, b2); |
| 476 | if (b.compareTo(b2) <= 0) |
| 477 | fail("Comparison to shorter buffer <= 0", b, b2); |
| 478 | b.limit(b.limit() - 1); |
| 479 | |
| 480 | b.put(2, (float)42); |
| 481 | if (b.equals(b2)) |
| 482 | fail("Non-identical buffers equal", b, b2); |
| 483 | if (b.compareTo(b2) <= 0) |
| 484 | fail("Comparison to lesser buffer <= 0", b, b2); |
| 485 | |
| 486 | // Sub, dup |
| 487 | |
| 488 | relPut(b); |
| 489 | relGet(b.duplicate()); |
| 490 | b.position(13); |
| 491 | relGet(b.duplicate(), 13); |
| 492 | relGet(b.duplicate().slice(), 13); |
| 493 | relGet(b.slice(), 13); |
| 494 | relGet(b.slice().duplicate(), 13); |
| 495 | |
| 496 | // Slice |
| 497 | |
| 498 | b.position(5); |
| 499 | FloatBuffer sb = b.slice(); |
| 500 | checkSlice(b, sb); |
| 501 | b.position(0); |
| 502 | FloatBuffer sb2 = sb.slice(); |
| 503 | checkSlice(sb, sb2); |
| 504 | |
| 505 | if (!sb.equals(sb2)) |
| 506 | fail("Sliced slices do not match", sb, sb2); |
| 507 | if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) |
| 508 | fail("Array offsets do not match: " |
| 509 | + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2); |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | // Read-only views |
| 543 | |
| 544 | b.rewind(); |
| 545 | final FloatBuffer rb = b.asReadOnlyBuffer(); |
| 546 | if (!b.equals(rb)) |
| 547 | fail("Buffer not equal to read-only view", b, rb); |
| 548 | show(level + 1, rb); |
| 549 | |
| 550 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 551 | public void run() { |
| 552 | relPut(rb); |
| 553 | }}); |
| 554 | |
| 555 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 556 | public void run() { |
| 557 | absPut(rb); |
| 558 | }}); |
| 559 | |
| 560 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 561 | public void run() { |
| 562 | bulkPutArray(rb); |
| 563 | }}); |
| 564 | |
| 565 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 566 | public void run() { |
| 567 | bulkPutBuffer(rb); |
| 568 | }}); |
| 569 | |
| 570 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 571 | public void run() { |
| 572 | rb.compact(); |
| 573 | }}); |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | if (rb.getClass().getName().startsWith("java.nio.Heap")) { |
| 634 | |
| 635 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 636 | public void run() { |
| 637 | rb.array(); |
| 638 | }}); |
| 639 | |
| 640 | tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
| 641 | public void run() { |
| 642 | rb.arrayOffset(); |
| 643 | }}); |
| 644 | |
| 645 | if (rb.hasArray()) |
| 646 | fail("Read-only heap buffer's backing array is accessible", |
| 647 | rb); |
| 648 | |
| 649 | } |
| 650 | |
| 651 | // Bulk puts from read-only buffers |
| 652 | |
| 653 | b.clear(); |
| 654 | rb.rewind(); |
| 655 | b.put(rb); |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | relPut(b); // Required by testViews |
| 668 | |
| 669 | } |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | public static void test(final float [] ba) { |
| 754 | int offset = 47; |
| 755 | int length = 900; |
| 756 | final FloatBuffer b = FloatBuffer.wrap(ba, offset, length); |
| 757 | show(0, b); |
| 758 | ck(b, b.capacity(), ba.length); |
| 759 | ck(b, b.position(), offset); |
| 760 | ck(b, b.limit(), offset + length); |
| 761 | |
| 762 | // The offset must be non-negative and no larger than <array.length>. |
| 763 | tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
| 764 | public void run() { |
| 765 | FloatBuffer.wrap(ba, -1, ba.length); |
| 766 | }}); |
| 767 | tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
| 768 | public void run() { |
| 769 | FloatBuffer.wrap(ba, ba.length + 1, ba.length); |
| 770 | }}); |
| 771 | tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
| 772 | public void run() { |
| 773 | FloatBuffer.wrap(ba, 0, -1); |
| 774 | }}); |
| 775 | tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
| 776 | public void run() { |
| 777 | FloatBuffer.wrap(ba, 0, ba.length + 1); |
| 778 | }}); |
| 779 | |
| 780 | // A NullPointerException will be thrown if the array is null. |
| 781 | tryCatch(ba, NullPointerException.class, new Runnable() { |
| 782 | public void run() { |
| 783 | FloatBuffer.wrap((float []) null, 0, 5); |
| 784 | }}); |
| 785 | tryCatch(ba, NullPointerException.class, new Runnable() { |
| 786 | public void run() { |
| 787 | FloatBuffer.wrap((float []) null); |
| 788 | }}); |
| 789 | } |
| 790 | |
| 791 | private static void testAllocate() { |
| 792 | // An IllegalArgumentException will be thrown for negative capacities. |
| 793 | tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() { |
| 794 | public void run() { |
| 795 | FloatBuffer.allocate(-1); |
| 796 | }}); |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | } |
| 804 | |
| 805 | public static void test() { |
| 806 | testAllocate(); |
| 807 | test(0, FloatBuffer.allocate(7 * 1024), false); |
| 808 | test(0, FloatBuffer.wrap(new float[7 * 1024], 0, 7 * 1024), false); |
| 809 | test(new float[1024]); |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | callReset(FloatBuffer.allocate(10)); |
| 821 | |
| 822 | |
| 823 | |
| 824 | putBuffer(); |
| 825 | |
| 826 | } |
| 827 | |
| 828 | } |