1 /*
   2  * Copyright (c) 2000, 2019, 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 /* 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 final float[] VALUES = {
  41         Float.MIN_VALUE,
  42         (float) -1,
  43         (float) 0,
  44         (float) 1,
  45         Float.MAX_VALUE,
  46 
  47         Float.NEGATIVE_INFINITY,
  48         Float.POSITIVE_INFINITY,
  49         Float.NaN,
  50         (float) -0.0,
  51 
  52 
  53 
  54 
  55 
  56 
  57 
  58     };
  59 
  60     private static void relGet(FloatBuffer b) {
  61         int n = b.capacity();
  62         for (int i = 0; i < n; i++)
  63             ck(b, (long)b.get(), (long)((float)ic(i)));
  64         b.rewind();
  65     }
  66 
  67     private static void relGet(FloatBuffer b, int start) {
  68         int n = b.remaining();
  69         for (int i = start; i < n; i++)
  70             ck(b, (long)b.get(), (long)((float)ic(i)));
  71         b.rewind();
  72     }
  73 
  74     private static void absGet(FloatBuffer b) {
  75         int n = b.capacity();
  76         for (int i = 0; i < n; i++)
  77             ck(b, (long)b.get(), (long)((float)ic(i)));
  78         b.rewind();
  79     }
  80 
  81     private static void bulkGet(FloatBuffer b) {
  82         int n = b.capacity();
  83         float[] a = new float[n + 7];
  84         b.get(a, 7, n);
  85         for (int i = 0; i < n; i++) {
  86             ck(b, (long)a[i + 7], (long)((float)ic(i)));
  87         }
  88     }
  89 
  90     private static void absBulkGet(FloatBuffer b) {
  91         int n = b.capacity();
  92         int len = n - 7*2;
  93         float[] a = new float[n + 7];
  94         b.position(42);
  95         b.get(7, a, 7, len);
  96         ck(b, b.position() == 42);
  97         for (int i = 0; i < len; i++) {
  98             ck(b, (long)a[i + 7], (long)((float)ic(i)));
  99         }
 100     }
 101 
 102     private static void relPut(FloatBuffer b) {
 103         int n = b.capacity();
 104         b.clear();
 105         for (int i = 0; i < n; i++)
 106             b.put((float)ic(i));
 107         b.flip();
 108     }
 109 
 110     private static void absPut(FloatBuffer b) {
 111         int n = b.capacity();
 112         b.clear();
 113         for (int i = 0; i < n; i++)
 114             b.put(i, (float)ic(i));
 115         b.limit(n);
 116         b.position(0);
 117     }
 118 
 119     private static void bulkPutArray(FloatBuffer b) {
 120         int n = b.capacity();
 121         b.clear();
 122         float[] a = new float[n + 7];
 123         for (int i = 0; i < n; i++)
 124             a[i + 7] = (float)ic(i);
 125         b.put(a, 7, n);
 126         b.flip();
 127     }
 128 
 129     private static void bulkPutBuffer(FloatBuffer b) {
 130         int n = b.capacity();
 131         b.clear();
 132         FloatBuffer c = FloatBuffer.allocate(n + 7);
 133         c.position(7);
 134         for (int i = 0; i < n; i++)
 135             c.put((float)ic(i));
 136         c.flip();
 137         c.position(7);
 138         b.put(c);
 139         b.flip();
 140         try {
 141             b.put(b);
 142             fail("IllegalArgumentException expected for put into same buffer");
 143         } catch (IllegalArgumentException e) {
 144             if (e.getMessage() == null) {
 145                 fail("Non-null IllegalArgumentException message expected from"
 146                      + " put into same buffer");
 147             }
 148         }
 149     }
 150 
 151     private static void absBulkPutArray(FloatBuffer b) {
 152         int n = b.capacity();
 153         b.clear();
 154         int lim = n - 7;
 155         int len = lim - 7;
 156         b.limit(lim);
 157         float[] a = new float[len + 7];
 158         for (int i = 0; i < len; i++)
 159             a[i + 7] = (float)ic(i);
 160         b.position(42);
 161         b.put(7, a, 7, len);
 162         ck(b, b.position() == 42);
 163     }
 164 
 165     private static void absBulkPutBuffer(FloatBuffer b, boolean direct) {
 166         int n = b.capacity();
 167         b.clear();
 168         int lim = n - 7;
 169         int len = lim - 7;
 170         b.limit(lim);
 171         FloatBuffer c = direct ?
 172 
 173 
 174 
 175             ByteBuffer.allocateDirect(Float.BYTES*(len + 7))
 176                 .asFloatBuffer()
 177 
 178             : FloatBuffer.allocate(len + 7);
 179 
 180         if (direct)
 181             System.out.println("Direct buffer: " + c.getClass().getName());
 182 
 183         for (int i = 0; i < len; i++)
 184             c.put(i + 7, (float)ic(i));
 185         b.position(42);
 186         c.position(42);
 187         b.put(7, c, 7, len);
 188         ck(b, b.position() == 42);
 189         ck(c, c.position() == 42);
 190     }
 191 
 192     //6231529
 193     private static void callReset(FloatBuffer b) {
 194         b.position(0);
 195         b.mark();
 196 
 197         b.duplicate().reset();
 198         b.asReadOnlyBuffer().reset();
 199     }
 200 
 201 
 202 
 203     // 6221101-6234263
 204 
 205     private static void putBuffer() {
 206         final int cap = 10;
 207 
 208         FloatBuffer direct1 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
 209         FloatBuffer nondirect1 = ByteBuffer.allocate(cap).asFloatBuffer();
 210         direct1.put(nondirect1);
 211 
 212         FloatBuffer direct2 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
 213         FloatBuffer nondirect2 = ByteBuffer.allocate(cap).asFloatBuffer();
 214         nondirect2.put(direct2);
 215 
 216         FloatBuffer direct3 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
 217         FloatBuffer direct4 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
 218         direct3.put(direct4);
 219 
 220         FloatBuffer nondirect3 = ByteBuffer.allocate(cap).asFloatBuffer();
 221         FloatBuffer nondirect4 = ByteBuffer.allocate(cap).asFloatBuffer();
 222         nondirect3.put(nondirect4);
 223     }
 224 
 225 
 226 
 227 
 228 
 229 
 230 
 231 
 232 
 233 
 234 
 235 
 236 
 237 
 238 
 239 
 240 
 241     private static void checkSlice(FloatBuffer b, FloatBuffer slice) {
 242         ck(slice, 0, slice.position());
 243         ck(slice, b.remaining(), slice.limit());
 244         ck(slice, b.remaining(), slice.capacity());
 245         if (b.isDirect() != slice.isDirect())
 246             fail("Lost direction", slice);
 247         if (b.isReadOnly() != slice.isReadOnly())
 248             fail("Lost read-only", slice);
 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 
 287 
 288 
 289 
 290 
 291 
 292 
 293 
 294 
 295 
 296 
 297 
 298 
 299 
 300 
 301 
 302 
 303 
 304 
 305 
 306 
 307 
 308 
 309 
 310 
 311 
 312 
 313 
 314 
 315 
 316 
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 
 325 
 326 
 327 
 328 
 329 
 330 
 331 
 332 
 333 
 334 
 335 
 336 
 337 
 338 
 339 
 340 
 341 
 342 
 343 
 344 
 345 
 346 
 347 
 348 
 349 
 350 
 351 
 352 
 353 
 354 
 355 
 356 
 357 
 358 
 359 
 360 
 361 
 362 
 363 
 364 
 365 
 366 
 367 
 368 
 369 
 370 
 371 
 372 
 373 
 374 
 375 
 376 
 377 
 378 
 379 
 380 
 381 
 382 
 383 
 384 
 385 
 386 
 387 
 388 
 389 
 390 
 391 
 392 
 393 
 394 
 395 
 396 
 397 
 398 
 399 
 400 
 401 
 402 
 403 
 404 
 405 
 406 
 407 
 408 
 409 
 410 
 411 
 412 
 413 
 414 
 415 
 416 
 417 
 418 
 419 
 420 
 421 
 422 
 423 
 424 
 425 
 426 
 427 
 428 
 429 
 430 
 431 
 432 
 433 
 434 
 435 
 436 
 437 
 438 
 439 
 440 
 441 
 442 
 443 
 444 
 445 
 446 
 447 
 448 
 449 
 450 
 451 
 452 
 453 
 454 
 455 
 456 
 457 
 458 
 459 
 460 
 461 
 462 
 463 
 464 
 465 
 466 
 467 
 468 
 469 
 470 
 471 
 472 
 473 
 474 
 475 
 476 
 477 
 478 
 479 
 480 
 481 
 482 
 483 
 484 
 485 
 486 
 487 
 488 
 489 
 490 
 491 
 492 
 493 
 494 
 495 
 496 
 497 
 498 
 499 
 500 
 501 
 502     private static void fail(String problem,
 503                              FloatBuffer xb, FloatBuffer yb,
 504                              float x, float y) {
 505         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
 506     }
 507 
 508     private static void catchNullArgument(Buffer b, Runnable thunk) {
 509         tryCatch(b, NullPointerException.class, thunk);
 510     }
 511 
 512     private static void catchIllegalArgument(Buffer b, Runnable thunk) {
 513         tryCatch(b, IllegalArgumentException.class, thunk);
 514     }
 515 
 516     private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
 517         tryCatch(b, ReadOnlyBufferException.class, thunk);
 518     }
 519 
 520     private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
 521         tryCatch(b, IndexOutOfBoundsException.class, thunk);
 522     }
 523 
 524     private static void catchIndexOutOfBounds(float[] t, Runnable thunk) {
 525         tryCatch(t, IndexOutOfBoundsException.class, thunk);
 526     }
 527 
 528     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
 529         boolean caught = false;
 530         try {
 531             thunk.run();
 532         } catch (Throwable x) {
 533             if (ex.isAssignableFrom(x.getClass())) {
 534                 caught = true;
 535             } else {
 536                 String s = x.getMessage();
 537                 if (s == null)
 538                     s = x.getClass().getName();
 539                 fail(s + " not expected");
 540             }
 541         }
 542         if (!caught) {
 543             fail(ex.getName() + " not thrown", b);
 544         }
 545     }
 546 
 547     private static void tryCatch(float[] t, Class<?> ex, Runnable thunk) {
 548         tryCatch(FloatBuffer.wrap(t), ex, thunk);
 549     }
 550 
 551     public static void test(int level, final FloatBuffer b, boolean direct) {
 552 
 553         show(level, b);
 554 
 555         if (direct != b.isDirect())
 556             fail("Wrong direction", b);
 557 
 558         // Gets and puts
 559 
 560         relPut(b);
 561         relGet(b);
 562         absGet(b);
 563         bulkGet(b);
 564 
 565         absPut(b);
 566         relGet(b);
 567         absGet(b);
 568         bulkGet(b);
 569 
 570         bulkPutArray(b);
 571         relGet(b);
 572 
 573         bulkPutBuffer(b);
 574         relGet(b);
 575 
 576         absBulkPutArray(b);
 577         absBulkGet(b);
 578 
 579         absBulkPutBuffer(b, direct);
 580         absBulkGet(b);
 581 
 582         absBulkPutBuffer(b, !direct);
 583         absBulkGet(b);
 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         // Compact
 622 
 623         relPut(b);
 624         b.position(13);
 625         b.compact();
 626         b.flip();
 627         relGet(b, 13);
 628 
 629         // Exceptions
 630 
 631         relPut(b);
 632         b.limit(b.capacity() / 2);
 633         b.position(b.limit());
 634 
 635         tryCatch(b, BufferUnderflowException.class, () -> b.get());
 636         tryCatch(b, BufferOverflowException.class, () -> b.put((float)42));
 637         // The index must be non-negative and less than the buffer's limit.
 638         catchIndexOutOfBounds(b, () -> b.get(b.limit()));
 639         catchIndexOutOfBounds(b, () -> b.get(-1));
 640         catchIndexOutOfBounds(b, () -> b.put(b.limit(), (float)42));
 641         tryCatch(b, InvalidMarkException.class,
 642                 () -> b.position(0).mark().compact().reset());
 643 
 644         try {
 645             b.position(b.limit() + 1);
 646             fail("IllegalArgumentException expected for position beyond limit");
 647         } catch (IllegalArgumentException e) {
 648             if (e.getMessage() == null) {
 649                 fail("Non-null IllegalArgumentException message expected for"
 650                      + " position beyond limit");
 651             }
 652         }
 653 
 654         try {
 655             b.position(-1);
 656             fail("IllegalArgumentException expected for negative position");
 657         } catch (IllegalArgumentException e) {
 658             if (e.getMessage() == null) {
 659                 fail("Non-null IllegalArgumentException message expected for"
 660                      + " negative position");
 661             }
 662         }
 663 
 664         try {
 665             b.limit(b.capacity() + 1);
 666             fail("IllegalArgumentException expected for limit beyond capacity");
 667         } catch (IllegalArgumentException e) {
 668             if (e.getMessage() == null) {
 669                 fail("Non-null IllegalArgumentException message expected for"
 670                      + " limit beyond capacity");
 671             }
 672         }
 673 
 674         try {
 675             b.limit(-1);
 676             fail("IllegalArgumentException expected for negative limit");
 677         } catch (IllegalArgumentException e) {
 678             if (e.getMessage() == null) {
 679                 fail("Non-null IllegalArgumentException message expected for"
 680                      + " negative limit");
 681             }
 682         }
 683 
 684         // Exceptions in absolute bulk operations
 685 
 686         catchNullArgument(b, () -> b.get(7, null, 0, 42));
 687         catchNullArgument(b, () -> b.put(7, (float[])null, 0, 42));
 688         catchNullArgument(b, () -> b.put(7, (FloatBuffer)null, 0, 42));
 689 
 690         float[] tmpa = new float[42];
 691         catchIndexOutOfBounds(b, () -> b.get(7, tmpa, -1, 42));
 692         catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 42, 1));
 693         catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 41, -1));
 694         catchIndexOutOfBounds(b, () -> b.get(-1, tmpa, 0, 1));
 695         catchIndexOutOfBounds(b, () -> b.get(b.limit(), tmpa, 0, 1));
 696         catchIndexOutOfBounds(b, () -> b.get(b.limit() - 41, tmpa, 0, 42));
 697 
 698         catchIndexOutOfBounds(b, () -> b.put(7, tmpa, -1, 42));
 699         catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 42, 1));
 700         catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 41, -1));
 701         catchIndexOutOfBounds(b, () -> b.put(-1, tmpa, 0, 1));
 702         catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
 703         catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
 704 
 705         FloatBuffer tmpb = FloatBuffer.allocate(42);
 706         catchIndexOutOfBounds(b, () -> b.put(7, tmpb, -1, 42));
 707         catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 42, 1));
 708         catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 42, -1));
 709         catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 41, 2));
 710         catchIndexOutOfBounds(b, () -> b.put(-1, tmpb, 0, 1));
 711         catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpb, 0, 1));
 712         catchIndexOutOfBounds(b, () -> b.put(0, tmpb, 0, -1));
 713         catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpb, 0, 42));
 714 
 715         // Values
 716 
 717         b.clear();
 718         b.put((float)0);
 719         b.put((float)-1);
 720         b.put((float)1);
 721         b.put(Float.MAX_VALUE);
 722         b.put(Float.MIN_VALUE);
 723 
 724         b.put(-Float.MAX_VALUE);
 725         b.put(-Float.MIN_VALUE);
 726         b.put(Float.NEGATIVE_INFINITY);
 727         b.put(Float.POSITIVE_INFINITY);
 728         b.put(Float.NaN);
 729         b.put(0.91697687f);             // Changes value if incorrectly swapped
 730 
 731 
 732 
 733 
 734 
 735 
 736 
 737 
 738 
 739 
 740         b.flip();
 741         ck(b, b.get(), 0);
 742         ck(b, b.get(), (float)-1);
 743         ck(b, b.get(), 1);
 744         ck(b, b.get(), Float.MAX_VALUE);
 745         ck(b, b.get(), Float.MIN_VALUE);
 746 
 747 
 748         float v;
 749         ck(b, b.get(), -Float.MAX_VALUE);
 750         ck(b, b.get(), -Float.MIN_VALUE);
 751         ck(b, b.get(), Float.NEGATIVE_INFINITY);
 752         ck(b, b.get(), Float.POSITIVE_INFINITY);
 753         if (Float.floatToRawIntBits(v = b.get()) !=
 754             Float.floatToRawIntBits(Float.NaN)) {
 755             fail(b, (long)Float.NaN, (long)v);
 756         }
 757         ck(b, b.get(), 0.91697687f);
 758 
 759 
 760 
 761 
 762 
 763 
 764 
 765 
 766 
 767 
 768 
 769 
 770 
 771 
 772 
 773         // Comparison
 774         b.rewind();
 775         FloatBuffer b2 = FloatBuffer.allocate(b.capacity());
 776         b2.put(b);
 777         b2.flip();
 778         b.position(2);
 779         b2.position(2);
 780         if (!b.equals(b2)) {
 781             for (int i = 2; i < b.limit(); i++) {
 782                 float x = b.get(i);
 783                 float y = b2.get(i);
 784                 if (x != y
 785 
 786 
 787 
 788 
 789                     || Float.compare(x, y) != 0
 790 
 791                     ) {
 792                     out.println("[" + i + "] " + x + " != " + y);
 793                 }
 794             }
 795             fail("Identical buffers not equal", b, b2);
 796         }
 797         if (b.compareTo(b2) != 0) {
 798             fail("Comparison to identical buffer != 0", b, b2);
 799         }
 800         b.limit(b.limit() + 1);
 801         b.position(b.limit() - 1);
 802         b.put((float)99);
 803         b.rewind();
 804         b2.rewind();
 805         if (b.equals(b2))
 806             fail("Non-identical buffers equal", b, b2);
 807         if (b.compareTo(b2) <= 0)
 808             fail("Comparison to shorter buffer <= 0", b, b2);
 809         b.limit(b.limit() - 1);
 810 
 811         b.put(2, (float)42);
 812         if (b.equals(b2))
 813             fail("Non-identical buffers equal", b, b2);
 814         if (b.compareTo(b2) <= 0)
 815             fail("Comparison to lesser buffer <= 0", b, b2);
 816 
 817         // Check equals and compareTo with interesting values
 818         for (float x : VALUES) {
 819             FloatBuffer xb = FloatBuffer.wrap(new float[] { x });
 820             if (xb.compareTo(xb) != 0) {
 821                 fail("compareTo not reflexive", xb, xb, x, x);
 822             }
 823             if (!xb.equals(xb)) {
 824                 fail("equals not reflexive", xb, xb, x, x);
 825             }
 826             for (float y : VALUES) {
 827                 FloatBuffer yb = FloatBuffer.wrap(new float[] { y });
 828                 if (xb.compareTo(yb) != - yb.compareTo(xb)) {
 829                     fail("compareTo not anti-symmetric",
 830                          xb, yb, x, y);
 831                 }
 832                 if ((xb.compareTo(yb) == 0) != xb.equals(yb)) {
 833                     fail("compareTo inconsistent with equals",
 834                          xb, yb, x, y);
 835                 }
 836                 if (xb.compareTo(yb) != Float.compare(x, y)) {
 837 
 838                     if (x == 0.0 && y == 0.0) continue;
 839 
 840 
 841 
 842 
 843                     fail("Incorrect results for FloatBuffer.compareTo",
 844                          xb, yb, x, y);
 845                 }
 846                 if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) {
 847                     fail("Incorrect results for FloatBuffer.equals",
 848                          xb, yb, x, y);
 849                 }
 850             }
 851         }
 852 
 853         // Sub, dup
 854 
 855         relPut(b);
 856         relGet(b.duplicate());
 857         b.position(13);
 858         relGet(b.duplicate(), 13);
 859         relGet(b.duplicate().slice(), 13);
 860         relGet(b.slice(), 13);
 861         relGet(b.slice().duplicate(), 13);
 862 
 863         // Slice
 864 
 865         b.position(5);
 866         FloatBuffer sb = b.slice();
 867         checkSlice(b, sb);
 868         b.position(0);
 869         FloatBuffer sb2 = sb.slice();
 870         checkSlice(sb, sb2);
 871 
 872         if (!sb.equals(sb2))
 873             fail("Sliced slices do not match", sb, sb2);
 874         if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
 875             fail("Array offsets do not match: "
 876                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
 877         }
 878 
 879 
 880 
 881 
 882 
 883 
 884 
 885 
 886 
 887 
 888 
 889 
 890 
 891 
 892 
 893 
 894 
 895 
 896 
 897 
 898 
 899 
 900 
 901 
 902 
 903 
 904 
 905 
 906 
 907 
 908 
 909 
 910         // Read-only views
 911 
 912         b.rewind();
 913         final FloatBuffer rb = b.asReadOnlyBuffer();
 914         if (!b.equals(rb))
 915             fail("Buffer not equal to read-only view", b, rb);
 916         show(level + 1, rb);
 917 
 918         catchReadOnlyBuffer(b, () -> relPut(rb));
 919         catchReadOnlyBuffer(b, () -> absPut(rb));
 920         catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
 921         catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 922         catchReadOnlyBuffer(b, () -> absBulkPutArray(rb));
 923         catchReadOnlyBuffer(b, () -> absBulkPutBuffer(rb, direct));
 924 
 925         // put(FloatBuffer) should not change source position
 926         final FloatBuffer src = FloatBuffer.allocate(1);
 927         catchReadOnlyBuffer(b, () -> rb.put(src));
 928         ck(src, src.position(), 0);
 929 
 930         catchReadOnlyBuffer(b, () -> rb.compact());
 931 
 932 
 933 
 934 
 935 
 936 
 937 
 938 
 939 
 940 
 941 
 942 
 943 
 944 
 945 
 946 
 947 
 948 
 949 
 950 
 951 
 952 
 953 
 954 
 955 
 956 
 957         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
 958             catchReadOnlyBuffer(b, () -> rb.array());
 959             catchReadOnlyBuffer(b, () -> rb.arrayOffset());
 960             if (rb.hasArray()) {
 961                 fail("Read-only heap buffer's backing array is accessible", rb);
 962             }
 963         }
 964 
 965         // Bulk puts from read-only buffers
 966 
 967         b.clear();
 968         rb.rewind();
 969         b.put(rb);
 970 
 971 
 972 
 973 
 974 
 975 
 976 
 977 
 978 
 979 
 980 
 981         relPut(b);                       // Required by testViews
 982 
 983 
 984 
 985 
 986 
 987 
 988     }
 989 
 990 
 991 
 992 
 993 
 994 
 995 
 996 
 997 
 998 
 999 
1000 
1001 
1002 
1003 
1004 
1005 
1006 
1007 
1008 
1009 
1010 
1011 
1012 
1013 
1014 
1015 
1016 
1017 
1018 
1019 
1020 
1021 
1022 
1023 
1024 
1025 
1026 
1027 
1028 
1029 
1030 
1031 
1032 
1033     public static void test(final float [] ba) {
1034         int offset = 47;
1035         int length = 900;
1036         final FloatBuffer b = FloatBuffer.wrap(ba, offset, length);
1037         show(0, b);
1038         ck(b, b.capacity(), ba.length);
1039         ck(b, b.position(), offset);
1040         ck(b, b.limit(), offset + length);
1041 
1042         // The offset must be non-negative and no larger than <array.length>.
1043         catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, -1, ba.length));
1044         catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, ba.length + 1, ba.length));
1045         catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, 0, -1));
1046         catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, 0, ba.length + 1));
1047 
1048         // A NullPointerException will be thrown if the array is null.
1049         tryCatch(ba, NullPointerException.class,
1050                 () -> FloatBuffer.wrap((float []) null, 0, 5));
1051         tryCatch(ba, NullPointerException.class,
1052                 () -> FloatBuffer.wrap((float []) null));
1053     }
1054 
1055     private static void testAllocate() {
1056         // An IllegalArgumentException will be thrown for negative capacities.
1057         catchIllegalArgument((Buffer) null, () -> FloatBuffer.allocate(-1));
1058         try {
1059             FloatBuffer.allocate(-1);
1060         } catch (IllegalArgumentException e) {
1061             if (e.getMessage() == null) {
1062                 fail("Non-null IllegalArgumentException message expected for"
1063                      + " attempt to allocate negative capacity buffer");
1064             }
1065         }
1066 
1067 
1068 
1069 
1070 
1071 
1072 
1073 
1074 
1075 
1076 
1077     }
1078 
1079     public static void test() {
1080         testAllocate();
1081         test(0, FloatBuffer.allocate(7 * 1024), false);
1082         test(0, FloatBuffer.wrap(new float[7 * 1024], 0, 7 * 1024), false);
1083         test(new float[1024]);
1084 
1085 
1086 
1087 
1088 
1089 
1090 
1091 
1092 
1093 
1094         callReset(FloatBuffer.allocate(10));
1095 
1096 
1097 
1098         putBuffer();
1099 
1100     }
1101 
1102 }