1 /* |
1 /* |
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
85 for (int i = 0; i < n; i++) { |
85 for (int i = 0; i < n; i++) { |
86 ck(b, (long)a[i + 7], (long)(($type$)ic(i))); |
86 ck(b, (long)a[i + 7], (long)(($type$)ic(i))); |
87 } |
87 } |
88 } |
88 } |
89 |
89 |
|
90 private static void absBulkGet($Type$Buffer b) { |
|
91 int n = b.capacity(); |
|
92 int len = n - 7*2; |
|
93 $type$[] a = new $type$[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)(($type$)ic(i))); |
|
99 } |
|
100 } |
|
101 |
90 private static void relPut($Type$Buffer b) { |
102 private static void relPut($Type$Buffer b) { |
91 int n = b.capacity(); |
103 int n = b.capacity(); |
92 b.clear(); |
104 b.clear(); |
93 for (int i = 0; i < n; i++) |
105 for (int i = 0; i < n; i++) |
94 b.put(($type$)ic(i)); |
106 b.put(($type$)ic(i)); |
134 + " put into same buffer"); |
146 + " put into same buffer"); |
135 } |
147 } |
136 } |
148 } |
137 } |
149 } |
138 |
150 |
|
151 private static void absBulkPutArray($Type$Buffer b) { |
|
152 int n = b.capacity(); |
|
153 b.clear(); |
|
154 int lim = n - 7; |
|
155 int len = lim - 7; |
|
156 b.limit(lim); |
|
157 $type$[] a = new $type$[len + 7]; |
|
158 for (int i = 0; i < len; i++) |
|
159 a[i + 7] = ($type$)ic(i); |
|
160 b.position(42); |
|
161 b.put(7, a, 7, len); |
|
162 ck(b, b.position() == 42); |
|
163 } |
|
164 |
139 //6231529 |
165 //6231529 |
140 private static void callReset($Type$Buffer b) { |
166 private static void callReset($Type$Buffer b) { |
141 b.position(0); |
167 b.position(0); |
142 b.mark(); |
168 b.mark(); |
143 |
169 |
450 $Type$Buffer xb, $Type$Buffer yb, |
476 $Type$Buffer xb, $Type$Buffer yb, |
451 $type$ x, $type$ y) { |
477 $type$ x, $type$ y) { |
452 fail(problem + String.format(": x=%s y=%s", x, y), xb, yb); |
478 fail(problem + String.format(": x=%s y=%s", x, y), xb, yb); |
453 } |
479 } |
454 |
480 |
|
481 private static void catchNullArgument(Buffer b, Runnable thunk) { |
|
482 tryCatch(b, NullPointerException.class, thunk); |
|
483 } |
|
484 |
455 private static void catchIllegalArgument(Buffer b, Runnable thunk) { |
485 private static void catchIllegalArgument(Buffer b, Runnable thunk) { |
456 tryCatch(b, IllegalArgumentException.class, thunk); |
486 tryCatch(b, IllegalArgumentException.class, thunk); |
457 } |
487 } |
458 |
488 |
459 private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) { |
489 private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) { |
474 thunk.run(); |
504 thunk.run(); |
475 } catch (Throwable x) { |
505 } catch (Throwable x) { |
476 if (ex.isAssignableFrom(x.getClass())) { |
506 if (ex.isAssignableFrom(x.getClass())) { |
477 caught = true; |
507 caught = true; |
478 } else { |
508 } else { |
479 fail(x.getMessage() + " not expected"); |
509 String s = x.getMessage(); |
|
510 if (s == null) |
|
511 s = x.getClass().getName(); |
|
512 fail(s + " not expected"); |
480 } |
513 } |
481 } |
514 } |
482 if (!caught) { |
515 if (!caught) { |
483 fail(ex.getName() + " not thrown", b); |
516 fail(ex.getName() + " not thrown", b); |
484 } |
517 } |
609 if (e.getMessage() == null) { |
645 if (e.getMessage() == null) { |
610 fail("Non-null IllegalArgumentException message expected for" |
646 fail("Non-null IllegalArgumentException message expected for" |
611 + " negative limit"); |
647 + " negative limit"); |
612 } |
648 } |
613 } |
649 } |
|
650 |
|
651 // Exceptions in absolute bulk operations |
|
652 |
|
653 catchNullArgument(b, () -> b.get(7, null, 0, 42)); |
|
654 catchNullArgument(b, () -> b.put(7, ($type$[])null, 0, 42)); |
|
655 |
|
656 $type$[] tmpa = new $type$[42]; |
|
657 catchIndexOutOfBounds(b, () -> b.get(7, tmpa, -1, 42)); |
|
658 catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 42, 1)); |
|
659 catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 41, -1)); |
|
660 catchIndexOutOfBounds(b, () -> b.get(-1, tmpa, 0, 1)); |
|
661 catchIndexOutOfBounds(b, () -> b.get(b.limit(), tmpa, 0, 1)); |
|
662 catchIndexOutOfBounds(b, () -> b.get(b.limit() - 41, tmpa, 0, 42)); |
|
663 |
|
664 catchIndexOutOfBounds(b, () -> b.put(7, tmpa, -1, 42)); |
|
665 catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 42, 1)); |
|
666 catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 41, -1)); |
|
667 catchIndexOutOfBounds(b, () -> b.put(-1, tmpa, 0, 1)); |
|
668 catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1)); |
|
669 catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42)); |
614 |
670 |
615 // Values |
671 // Values |
616 |
672 |
617 b.clear(); |
673 b.clear(); |
618 b.put(($type$)0); |
674 b.put(($type$)0); |
817 |
873 |
818 catchReadOnlyBuffer(b, () -> relPut(rb)); |
874 catchReadOnlyBuffer(b, () -> relPut(rb)); |
819 catchReadOnlyBuffer(b, () -> absPut(rb)); |
875 catchReadOnlyBuffer(b, () -> absPut(rb)); |
820 catchReadOnlyBuffer(b, () -> bulkPutArray(rb)); |
876 catchReadOnlyBuffer(b, () -> bulkPutArray(rb)); |
821 catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb)); |
877 catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb)); |
|
878 catchReadOnlyBuffer(b, () -> absBulkPutArray(rb)); |
822 |
879 |
823 // put($Type$Buffer) should not change source position |
880 // put($Type$Buffer) should not change source position |
824 final $Type$Buffer src = $Type$Buffer.allocate(1); |
881 final $Type$Buffer src = $Type$Buffer.allocate(1); |
825 catchReadOnlyBuffer(b, () -> rb.put(src)); |
882 catchReadOnlyBuffer(b, () -> rb.put(src)); |
826 ck(src, src.position(), 0); |
883 ck(src, src.position(), 0); |
901 ck(b, end, b.limit()); |
958 ck(b, end, b.limit()); |
902 ck(b, s.length(), b.capacity()); |
959 ck(b, s.length(), b.capacity()); |
903 b.position(6); |
960 b.position(6); |
904 ck(b, b.subSequence(0,3).toString().equals("ghi")); |
961 ck(b, b.subSequence(0,3).toString().equals("ghi")); |
905 |
962 |
|
963 // absolute bulk get |
|
964 char[] c = new char[end + 1 - (start - 1) + 1]; // [start - 1, end + 1] |
|
965 b.limit(end + 2); |
|
966 b.get(start - 1, c, 0, c.length); |
|
967 for (int i = 0; i < c.length; i++) |
|
968 ck(b, c[i], s.charAt(start - 1 + i)); |
|
969 |
906 // The index, relative to the position, must be non-negative and |
970 // The index, relative to the position, must be non-negative and |
907 // smaller than remaining(). |
971 // smaller than remaining(). |
908 catchIndexOutOfBounds(b, () -> b.charAt(-1)); |
972 catchIndexOutOfBounds(b, () -> b.charAt(-1)); |
909 catchIndexOutOfBounds(b, () -> b.charAt(b.remaining())); |
973 catchIndexOutOfBounds(b, () -> b.charAt(b.remaining())); |
910 // The index must be non-negative and less than the buffer's limit. |
974 // The index must be non-negative and less than the buffer's limit. |