blob: f785cff3dcd985c7f0acab6fbe0996a99ce5620c [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
ohair2283b9d2010-05-25 15:58:33 -07002 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
duke6e45e102007-12-01 00:00:00 +00003 * 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 *
ohair2283b9d2010-05-25 15:58:33 -070019 * 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.
duke6e45e102007-12-01 00:00:00 +000022 */
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
33import java.nio.*;
alanb7d6d5672008-11-25 19:26:54 +000034import java.lang.reflect.Method;
duke6e45e102007-12-01 00:00:00 +000035
36
37public class BasicByte
38 extends Basic
39{
40
martin05aeea02009-12-08 12:41:01 -080041 private static final byte[] VALUES = {
42 Byte.MIN_VALUE,
43 (byte) -1,
44 (byte) 0,
45 (byte) 1,
46 Byte.MAX_VALUE,
47
48
49
50
51
52
53
54
55
56
57
58
59 };
60
duke6e45e102007-12-01 00:00:00 +000061 private static void relGet(ByteBuffer b) {
62 int n = b.capacity();
63 byte v;
64 for (int i = 0; i < n; i++)
65 ck(b, (long)b.get(), (long)((byte)ic(i)));
66 b.rewind();
67 }
68
69 private static void relGet(ByteBuffer b, int start) {
70 int n = b.remaining();
71 byte v;
72 for (int i = start; i < n; i++)
73 ck(b, (long)b.get(), (long)((byte)ic(i)));
74 b.rewind();
75 }
76
77 private static void absGet(ByteBuffer b) {
78 int n = b.capacity();
79 byte v;
80 for (int i = 0; i < n; i++)
81 ck(b, (long)b.get(), (long)((byte)ic(i)));
82 b.rewind();
83 }
84
85 private static void bulkGet(ByteBuffer b) {
86 int n = b.capacity();
87 byte[] a = new byte[n + 7];
88 b.get(a, 7, n);
89 for (int i = 0; i < n; i++)
90 ck(b, (long)a[i + 7], (long)((byte)ic(i)));
91 }
92
93 private static void relPut(ByteBuffer b) {
94 int n = b.capacity();
95 b.clear();
96 for (int i = 0; i < n; i++)
97 b.put((byte)ic(i));
98 b.flip();
99 }
100
101 private static void absPut(ByteBuffer b) {
102 int n = b.capacity();
103 b.clear();
104 for (int i = 0; i < n; i++)
105 b.put(i, (byte)ic(i));
106 b.limit(n);
107 b.position(0);
108 }
109
110 private static void bulkPutArray(ByteBuffer b) {
111 int n = b.capacity();
112 b.clear();
113 byte[] a = new byte[n + 7];
114 for (int i = 0; i < n; i++)
115 a[i + 7] = (byte)ic(i);
116 b.put(a, 7, n);
117 b.flip();
118 }
119
120 private static void bulkPutBuffer(ByteBuffer b) {
121 int n = b.capacity();
122 b.clear();
123 ByteBuffer c = ByteBuffer.allocate(n + 7);
124 c.position(7);
125 for (int i = 0; i < n; i++)
126 c.put((byte)ic(i));
127 c.flip();
128 c.position(7);
129 b.put(c);
130 b.flip();
131 }
132
133 //6231529
134 private static void callReset(ByteBuffer b) {
135 b.position(0);
136 b.mark();
137
138 b.duplicate().reset();
139 b.asReadOnlyBuffer().reset();
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 private static void checkSlice(ByteBuffer b, ByteBuffer slice) {
183 ck(slice, 0, slice.position());
184 ck(slice, b.remaining(), slice.limit());
185 ck(slice, b.remaining(), slice.capacity());
186 if (b.isDirect() != slice.isDirect())
187 fail("Lost direction", slice);
188 if (b.isReadOnly() != slice.isReadOnly())
189 fail("Lost read-only", slice);
190 }
191
192
193
194 private static void checkBytes(ByteBuffer b, byte[] bs) {
195 int n = bs.length;
196 int p = b.position();
197 byte v;
198 if (b.order() == ByteOrder.BIG_ENDIAN) {
199 for (int i = 0; i < n; i++)
200 ck(b, b.get(), bs[i]);
201 } else {
202 for (int i = n - 1; i >= 0; i--)
203 ck(b, b.get(), bs[i]);
204 }
205 b.position(p);
206 }
207
alanb7d6d5672008-11-25 19:26:54 +0000208 private static void compact(Buffer b) {
209 try {
210 Class<?> cl = b.getClass();
211 Method m = cl.getDeclaredMethod("compact");
212 m.setAccessible(true);
213 m.invoke(b);
214 } catch (Exception e) {
215 fail(e.getMessage(), b);
216 }
217 }
218
219 private static void checkInvalidMarkException(final Buffer b) {
220 tryCatch(b, InvalidMarkException.class, new Runnable() {
221 public void run() {
222 b.mark();
223 compact(b);
224 b.reset();
225 }});
226 }
227
duke6e45e102007-12-01 00:00:00 +0000228 private static void testViews(int level, ByteBuffer b, boolean direct) {
229
230 ShortBuffer sb = b.asShortBuffer();
231 BasicShort.test(level, sb, direct);
232 checkBytes(b, new byte[] { 0, (byte)ic(0) });
alanb7d6d5672008-11-25 19:26:54 +0000233 checkInvalidMarkException(sb);
duke6e45e102007-12-01 00:00:00 +0000234
235 CharBuffer cb = b.asCharBuffer();
236 BasicChar.test(level, cb, direct);
237 checkBytes(b, new byte[] { 0, (byte)ic(0) });
alanb7d6d5672008-11-25 19:26:54 +0000238 checkInvalidMarkException(cb);
duke6e45e102007-12-01 00:00:00 +0000239
240 IntBuffer ib = b.asIntBuffer();
241 BasicInt.test(level, ib, direct);
242 checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
alanb7d6d5672008-11-25 19:26:54 +0000243 checkInvalidMarkException(ib);
duke6e45e102007-12-01 00:00:00 +0000244
245 LongBuffer lb = b.asLongBuffer();
246 BasicLong.test(level, lb, direct);
247 checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)ic(0) });
alanb7d6d5672008-11-25 19:26:54 +0000248 checkInvalidMarkException(lb);
duke6e45e102007-12-01 00:00:00 +0000249
250 FloatBuffer fb = b.asFloatBuffer();
251 BasicFloat.test(level, fb, direct);
252 checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
alanb7d6d5672008-11-25 19:26:54 +0000253 checkInvalidMarkException(fb);
duke6e45e102007-12-01 00:00:00 +0000254
255 DoubleBuffer db = b.asDoubleBuffer();
256 BasicDouble.test(level, db, direct);
257 checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
alanb7d6d5672008-11-25 19:26:54 +0000258 checkInvalidMarkException(db);
duke6e45e102007-12-01 00:00:00 +0000259 }
260
261 private static void testHet(int level, ByteBuffer b) {
262
263 int p = b.position();
264 b.limit(b.capacity());
265 show(level, b);
266 out.print(" put:");
267
268 b.putChar((char)1);
269 b.putChar((char)Character.MAX_VALUE);
270 out.print(" char");
271
272 b.putShort((short)1);
273 b.putShort((short)Short.MAX_VALUE);
274 out.print(" short");
275
276 b.putInt(1);
277 b.putInt(Integer.MAX_VALUE);
278 out.print(" int");
279
280 b.putLong((long)1);
281 b.putLong((long)Long.MAX_VALUE);
282 out.print(" long");
283
284 b.putFloat((float)1);
285 b.putFloat((float)Float.MIN_VALUE);
286 b.putFloat((float)Float.MAX_VALUE);
287 out.print(" float");
288
289 b.putDouble((double)1);
290 b.putDouble((double)Double.MIN_VALUE);
291 b.putDouble((double)Double.MAX_VALUE);
292 out.print(" double");
293
294 out.println();
295 b.limit(b.position());
296 b.position(p);
297 show(level, b);
298 out.print(" get:");
299
300 ck(b, b.getChar(), 1);
301 ck(b, b.getChar(), Character.MAX_VALUE);
302 out.print(" char");
303
304 ck(b, b.getShort(), 1);
305 ck(b, b.getShort(), Short.MAX_VALUE);
306 out.print(" short");
307
308 ck(b, b.getInt(), 1);
309 ck(b, b.getInt(), Integer.MAX_VALUE);
310 out.print(" int");
311
312 ck(b, b.getLong(), 1);
313 ck(b, b.getLong(), Long.MAX_VALUE);
314 out.print(" long");
315
316 ck(b, (long)b.getFloat(), 1);
317 ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
318 ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
319 out.print(" float");
320
321 ck(b, (long)b.getDouble(), 1);
322 ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
323 ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
324 out.print(" double");
325
326 out.println();
327
328 }
329
330
331
martin05aeea02009-12-08 12:41:01 -0800332 private static void fail(String problem,
333 ByteBuffer xb, ByteBuffer yb,
334 byte x, byte y) {
335 fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
336 }
337
duke6e45e102007-12-01 00:00:00 +0000338 private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
339 boolean caught = false;
340 try {
341 thunk.run();
342 } catch (Throwable x) {
alanb7d6d5672008-11-25 19:26:54 +0000343 if (ex.isAssignableFrom(x.getClass())) {
duke6e45e102007-12-01 00:00:00 +0000344 caught = true;
alanb7d6d5672008-11-25 19:26:54 +0000345 } else {
346 fail(x.getMessage() + " not expected");
347 }
duke6e45e102007-12-01 00:00:00 +0000348 }
349 if (!caught)
350 fail(ex.getName() + " not thrown", b);
351 }
352
353 private static void tryCatch(byte [] t, Class ex, Runnable thunk) {
354 tryCatch(ByteBuffer.wrap(t), ex, thunk);
355 }
356
357 public static void test(int level, final ByteBuffer b, boolean direct) {
358
359 show(level, b);
360
361 if (direct != b.isDirect())
362 fail("Wrong direction", b);
363
364 // Gets and puts
365
366 relPut(b);
367 relGet(b);
368 absGet(b);
369 bulkGet(b);
370
371 absPut(b);
372 relGet(b);
373 absGet(b);
374 bulkGet(b);
375
376 bulkPutArray(b);
377 relGet(b);
378
379 bulkPutBuffer(b);
380 relGet(b);
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
alanb4d003962009-04-15 14:53:34 +0100404
405
406
duke6e45e102007-12-01 00:00:00 +0000407 // Compact
408
409 relPut(b);
410 b.position(13);
411 b.compact();
412 b.flip();
413 relGet(b, 13);
414
415 // Exceptions
416
duke6e45e102007-12-01 00:00:00 +0000417 relPut(b);
418 b.limit(b.capacity() / 2);
419 b.position(b.limit());
420
421 tryCatch(b, BufferUnderflowException.class, new Runnable() {
422 public void run() {
423 b.get();
424 }});
425
426 tryCatch(b, BufferOverflowException.class, new Runnable() {
427 public void run() {
428 b.put((byte)42);
429 }});
430
431 // The index must be non-negative and lesss than the buffer's limit.
432 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
433 public void run() {
434 b.get(b.limit());
435 }});
436 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
437 public void run() {
438 b.get(-1);
439 }});
440
441 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
442 public void run() {
443 b.put(b.limit(), (byte)42);
444 }});
445
alanb7d6d5672008-11-25 19:26:54 +0000446 tryCatch(b, InvalidMarkException.class, new Runnable() {
447 public void run() {
448 b.position(0);
449 b.mark();
450 b.compact();
451 b.reset();
452 }});
453
duke6e45e102007-12-01 00:00:00 +0000454 // Values
455
456 b.clear();
457 b.put((byte)0);
458 b.put((byte)-1);
459 b.put((byte)1);
460 b.put(Byte.MAX_VALUE);
461 b.put(Byte.MIN_VALUE);
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479 byte v;
480 b.flip();
481 ck(b, b.get(), 0);
482 ck(b, b.get(), (byte)-1);
483 ck(b, b.get(), 1);
484 ck(b, b.get(), Byte.MAX_VALUE);
485 ck(b, b.get(), Byte.MIN_VALUE);
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508 // Comparison
509 b.rewind();
510 ByteBuffer b2 = ByteBuffer.allocate(b.capacity());
511 b2.put(b);
512 b2.flip();
513 b.position(2);
514 b2.position(2);
515 if (!b.equals(b2)) {
516 for (int i = 2; i < b.limit(); i++) {
517 byte x = b.get(i);
518 byte y = b2.get(i);
519 if (x != y
520
521
522
523
524
525
526 )
527 out.println("[" + i + "] " + x + " != " + y);
528 }
529 fail("Identical buffers not equal", b, b2);
530 }
531 if (b.compareTo(b2) != 0)
532 fail("Comparison to identical buffer != 0", b, b2);
533
534 b.limit(b.limit() + 1);
535 b.position(b.limit() - 1);
536 b.put((byte)99);
537 b.rewind();
538 b2.rewind();
539 if (b.equals(b2))
540 fail("Non-identical buffers equal", b, b2);
541 if (b.compareTo(b2) <= 0)
542 fail("Comparison to shorter buffer <= 0", b, b2);
543 b.limit(b.limit() - 1);
544
545 b.put(2, (byte)42);
546 if (b.equals(b2))
547 fail("Non-identical buffers equal", b, b2);
548 if (b.compareTo(b2) <= 0)
549 fail("Comparison to lesser buffer <= 0", b, b2);
550
martin05aeea02009-12-08 12:41:01 -0800551 // Check equals and compareTo with interesting values
552 for (byte x : VALUES) {
553 ByteBuffer xb = ByteBuffer.wrap(new byte[] { x });
554 if (xb.compareTo(xb) != 0) {
555 fail("compareTo not reflexive", xb, xb, x, x);
556 }
557 if (! xb.equals(xb)) {
558 fail("equals not reflexive", xb, xb, x, x);
559 }
560 for (byte y : VALUES) {
561 ByteBuffer yb = ByteBuffer.wrap(new byte[] { y });
562 if (xb.compareTo(yb) != - yb.compareTo(xb)) {
563 fail("compareTo not anti-symmetric",
564 xb, yb, x, y);
565 }
566 if ((xb.compareTo(yb) == 0) != xb.equals(yb)) {
567 fail("compareTo inconsistent with equals",
568 xb, yb, x, y);
569 }
570 if (xb.compareTo(yb) != Byte.compare(x, y)) {
571
572
573
574
575
576
577 fail("Incorrect results for ByteBuffer.compareTo",
578 xb, yb, x, y);
579 }
580 if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) {
581 fail("Incorrect results for ByteBuffer.equals",
582 xb, yb, x, y);
583 }
584 }
585 }
586
duke6e45e102007-12-01 00:00:00 +0000587 // Sub, dup
588
589 relPut(b);
590 relGet(b.duplicate());
591 b.position(13);
592 relGet(b.duplicate(), 13);
593 relGet(b.duplicate().slice(), 13);
594 relGet(b.slice(), 13);
595 relGet(b.slice().duplicate(), 13);
596
597 // Slice
598
599 b.position(5);
600 ByteBuffer sb = b.slice();
601 checkSlice(b, sb);
602 b.position(0);
603 ByteBuffer sb2 = sb.slice();
604 checkSlice(sb, sb2);
605
606 if (!sb.equals(sb2))
607 fail("Sliced slices do not match", sb, sb2);
608 if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
609 fail("Array offsets do not match: "
610 + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
611
612
613
614 // Views
615
616 b.clear();
617 b.order(ByteOrder.BIG_ENDIAN);
618 testViews(level + 1, b, direct);
619
620 for (int i = 1; i <= 9; i++) {
621 b.position(i);
622 show(level + 1, b);
623 testViews(level + 2, b, direct);
624 }
625
626 b.position(0);
627 b.order(ByteOrder.LITTLE_ENDIAN);
628 testViews(level + 1, b, direct);
629
630 // Heterogeneous accessors
631
632 b.order(ByteOrder.BIG_ENDIAN);
633 for (int i = 0; i <= 9; i++) {
634 b.position(i);
635 testHet(level + 1, b);
636 }
637 b.order(ByteOrder.LITTLE_ENDIAN);
638 b.position(3);
639 testHet(level + 1, b);
640
641
642
643 // Read-only views
644
645 b.rewind();
646 final ByteBuffer rb = b.asReadOnlyBuffer();
647 if (!b.equals(rb))
648 fail("Buffer not equal to read-only view", b, rb);
649 show(level + 1, rb);
650
651 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
652 public void run() {
653 relPut(rb);
654 }});
655
656 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
657 public void run() {
658 absPut(rb);
659 }});
660
661 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
662 public void run() {
663 bulkPutArray(rb);
664 }});
665
666 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
667 public void run() {
668 bulkPutBuffer(rb);
669 }});
670
671 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
672 public void run() {
673 rb.compact();
674 }});
675
676
677
678 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
679 public void run() {
680 rb.putChar((char)1);
681 }});
682 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
683 public void run() {
684 rb.putChar(0, (char)1);
685 }});
686
687 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
688 public void run() {
689 rb.putShort((short)1);
690 }});
691 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
692 public void run() {
693 rb.putShort(0, (short)1);
694 }});
695
696 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
697 public void run() {
698 rb.putInt(1);
699 }});
700 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
701 public void run() {
702 rb.putInt(0, 1);
703 }});
704
705 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
706 public void run() {
707 rb.putLong((long)1);
708 }});
709 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
710 public void run() {
711 rb.putLong(0, (long)1);
712 }});
713
714 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
715 public void run() {
716 rb.putFloat((float)1);
717 }});
718 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
719 public void run() {
720 rb.putFloat(0, (float)1);
721 }});
722
723 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
724 public void run() {
725 rb.putDouble((double)1);
726 }});
727 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
728 public void run() {
729 rb.putDouble(0, (double)1);
730 }});
731
732
733
734 if (rb.getClass().getName().startsWith("java.nio.Heap")) {
735
736 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
737 public void run() {
738 rb.array();
739 }});
740
741 tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
742 public void run() {
743 rb.arrayOffset();
744 }});
745
746 if (rb.hasArray())
747 fail("Read-only heap buffer's backing array is accessible",
748 rb);
749
750 }
751
752 // Bulk puts from read-only buffers
753
754 b.clear();
755 rb.rewind();
756 b.put(rb);
757
758
759 // For byte buffers, test both the direct and non-direct cases
760 ByteBuffer ob
761 = (b.isDirect()
762 ? ByteBuffer.allocate(rb.capacity())
763 : ByteBuffer.allocateDirect(rb.capacity()));
764 rb.rewind();
765 ob.put(rb);
766
767
768 relPut(b); // Required by testViews
769
770 }
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
alanb4d003962009-04-15 14:53:34 +0100854
855
duke6e45e102007-12-01 00:00:00 +0000856 public static void test(final byte [] ba) {
857 int offset = 47;
858 int length = 900;
859 final ByteBuffer b = ByteBuffer.wrap(ba, offset, length);
860 show(0, b);
861 ck(b, b.capacity(), ba.length);
862 ck(b, b.position(), offset);
863 ck(b, b.limit(), offset + length);
864
865 // The offset must be non-negative and no larger than <array.length>.
866 tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
867 public void run() {
868 ByteBuffer.wrap(ba, -1, ba.length);
869 }});
870 tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
871 public void run() {
872 ByteBuffer.wrap(ba, ba.length + 1, ba.length);
873 }});
874 tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
875 public void run() {
876 ByteBuffer.wrap(ba, 0, -1);
877 }});
878 tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
879 public void run() {
880 ByteBuffer.wrap(ba, 0, ba.length + 1);
881 }});
882
883 // A NullPointerException will be thrown if the array is null.
884 tryCatch(ba, NullPointerException.class, new Runnable() {
885 public void run() {
886 ByteBuffer.wrap((byte []) null, 0, 5);
887 }});
888 tryCatch(ba, NullPointerException.class, new Runnable() {
889 public void run() {
890 ByteBuffer.wrap((byte []) null);
891 }});
892 }
893
894 private static void testAllocate() {
895 // An IllegalArgumentException will be thrown for negative capacities.
896 tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
897 public void run() {
898 ByteBuffer.allocate(-1);
899 }});
900
901 tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
902 public void run() {
903 ByteBuffer.allocateDirect(-1);
904 }});
905
906 }
907
908 public static void test() {
909 testAllocate();
910 test(0, ByteBuffer.allocate(7 * 1024), false);
911 test(0, ByteBuffer.wrap(new byte[7 * 1024], 0, 7 * 1024), false);
912 test(new byte[1024]);
913
914 ByteBuffer b = ByteBuffer.allocateDirect(7 * 1024);
915 for (b.position(0); b.position() < b.limit(); )
916 ck(b, b.get(), 0);
917 test(0, b, true);
918
919
920
921
922
923 callReset(ByteBuffer.allocate(10));
924
925
926
927
928
929 }
930
931}