author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 53959 | 1542e63eb537 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53855 | 2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
40 |
private static final float[] VALUES = { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
41 |
Float.MIN_VALUE, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
42 |
(float) -1, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
43 |
(float) 0, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
44 |
(float) 1, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
45 |
Float.MAX_VALUE, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
46 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
47 |
Float.NEGATIVE_INFINITY, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
48 |
Float.POSITIVE_INFINITY, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
49 |
Float.NaN, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
50 |
(float) -0.0, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
51 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
52 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
53 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
54 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
55 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
56 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
57 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
58 |
}; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
59 |
|
2 | 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); |
|
37913 | 85 |
for (int i = 0; i < n; i++) { |
2 | 86 |
ck(b, (long)a[i + 7], (long)((float)ic(i))); |
37913 | 87 |
} |
2 | 88 |
} |
89 |
||
53855 | 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 |
||
2 | 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(); |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
140 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
141 |
b.put(b); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
142 |
fail("IllegalArgumentException expected for put into same buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
143 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
144 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
145 |
fail("Non-null IllegalArgumentException message expected from" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
146 |
+ " put into same buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
147 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
148 |
} |
2 | 149 |
} |
150 |
||
53855 | 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 |
||
2 | 165 |
//6231529 |
166 |
private static void callReset(FloatBuffer b) { |
|
167 |
b.position(0); |
|
168 |
b.mark(); |
|
169 |
||
170 |
b.duplicate().reset(); |
|
171 |
b.asReadOnlyBuffer().reset(); |
|
172 |
} |
|
173 |
||
174 |
||
175 |
||
176 |
// 6221101-6234263 |
|
177 |
||
178 |
private static void putBuffer() { |
|
179 |
final int cap = 10; |
|
180 |
||
181 |
FloatBuffer direct1 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
|
182 |
FloatBuffer nondirect1 = ByteBuffer.allocate(cap).asFloatBuffer(); |
|
183 |
direct1.put(nondirect1); |
|
184 |
||
185 |
FloatBuffer direct2 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
|
186 |
FloatBuffer nondirect2 = ByteBuffer.allocate(cap).asFloatBuffer(); |
|
187 |
nondirect2.put(direct2); |
|
188 |
||
189 |
FloatBuffer direct3 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
|
190 |
FloatBuffer direct4 = ByteBuffer.allocateDirect(cap).asFloatBuffer(); |
|
191 |
direct3.put(direct4); |
|
192 |
||
193 |
FloatBuffer nondirect3 = ByteBuffer.allocate(cap).asFloatBuffer(); |
|
194 |
FloatBuffer nondirect4 = ByteBuffer.allocate(cap).asFloatBuffer(); |
|
195 |
nondirect3.put(nondirect4); |
|
196 |
} |
|
197 |
||
198 |
||
199 |
||
200 |
||
201 |
||
202 |
||
203 |
||
204 |
||
205 |
||
206 |
||
207 |
||
208 |
||
209 |
||
210 |
||
211 |
||
212 |
||
213 |
||
214 |
private static void checkSlice(FloatBuffer b, FloatBuffer slice) { |
|
215 |
ck(slice, 0, slice.position()); |
|
216 |
ck(slice, b.remaining(), slice.limit()); |
|
217 |
ck(slice, b.remaining(), slice.capacity()); |
|
218 |
if (b.isDirect() != slice.isDirect()) |
|
219 |
fail("Lost direction", slice); |
|
220 |
if (b.isReadOnly() != slice.isReadOnly()) |
|
221 |
fail("Lost read-only", slice); |
|
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 |
||
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 |
||
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
339 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
340 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
341 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
342 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
343 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
344 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
345 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
346 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
347 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
348 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
349 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
350 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
351 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
352 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
353 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
354 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
355 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
356 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
357 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
358 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
359 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
360 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
361 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
362 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
363 |
|
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
364 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
365 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
366 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
367 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
368 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
369 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
370 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
371 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
372 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
373 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
374 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
375 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
376 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
377 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
378 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
379 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
380 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
381 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
382 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
383 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
384 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
385 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
386 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
387 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
388 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
389 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
390 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
391 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
392 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
393 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
394 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
395 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
396 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
397 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
398 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
399 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
400 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
401 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
402 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
403 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
404 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
405 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
406 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
407 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
408 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
409 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
410 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
411 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
412 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
413 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
414 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
415 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
416 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
417 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
418 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
419 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
420 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
421 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
422 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
423 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
424 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
425 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
426 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
427 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
428 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
429 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
430 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
431 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
432 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
433 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
434 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
435 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
436 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
437 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
438 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
439 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
440 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
441 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
442 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
443 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
444 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
445 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
446 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
447 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
448 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
449 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
450 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
451 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
452 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
453 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
454 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
455 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
456 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
457 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
458 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
459 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
460 |
|
37913 | 461 |
|
462 |
||
463 |
||
464 |
||
465 |
||
466 |
||
467 |
||
468 |
||
469 |
||
470 |
||
471 |
||
472 |
||
473 |
||
474 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
475 |
private static void fail(String problem, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
476 |
FloatBuffer xb, FloatBuffer yb, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
477 |
float x, float y) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
478 |
fail(problem + String.format(": x=%s y=%s", x, y), xb, yb); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
479 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
480 |
|
53855 | 481 |
private static void catchNullArgument(Buffer b, Runnable thunk) { |
482 |
tryCatch(b, NullPointerException.class, thunk); |
|
483 |
} |
|
484 |
||
37913 | 485 |
private static void catchIllegalArgument(Buffer b, Runnable thunk) { |
486 |
tryCatch(b, IllegalArgumentException.class, thunk); |
|
487 |
} |
|
488 |
||
489 |
private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) { |
|
490 |
tryCatch(b, ReadOnlyBufferException.class, thunk); |
|
491 |
} |
|
492 |
||
493 |
private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) { |
|
494 |
tryCatch(b, IndexOutOfBoundsException.class, thunk); |
|
495 |
} |
|
496 |
||
497 |
private static void catchIndexOutOfBounds(float[] t, Runnable thunk) { |
|
498 |
tryCatch(t, IndexOutOfBoundsException.class, thunk); |
|
499 |
} |
|
500 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
501 |
private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) { |
2 | 502 |
boolean caught = false; |
503 |
try { |
|
504 |
thunk.run(); |
|
505 |
} catch (Throwable x) { |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
506 |
if (ex.isAssignableFrom(x.getClass())) { |
2 | 507 |
caught = true; |
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
508 |
} else { |
53855 | 509 |
String s = x.getMessage(); |
510 |
if (s == null) |
|
511 |
s = x.getClass().getName(); |
|
512 |
fail(s + " not expected"); |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
513 |
} |
2 | 514 |
} |
37913 | 515 |
if (!caught) { |
2 | 516 |
fail(ex.getName() + " not thrown", b); |
37913 | 517 |
} |
2 | 518 |
} |
519 |
||
37913 | 520 |
private static void tryCatch(float[] t, Class<?> ex, Runnable thunk) { |
2 | 521 |
tryCatch(FloatBuffer.wrap(t), ex, thunk); |
522 |
} |
|
523 |
||
524 |
public static void test(int level, final FloatBuffer b, boolean direct) { |
|
525 |
||
526 |
show(level, b); |
|
527 |
||
528 |
if (direct != b.isDirect()) |
|
529 |
fail("Wrong direction", b); |
|
530 |
||
531 |
// Gets and puts |
|
532 |
||
533 |
relPut(b); |
|
534 |
relGet(b); |
|
535 |
absGet(b); |
|
536 |
bulkGet(b); |
|
537 |
||
538 |
absPut(b); |
|
539 |
relGet(b); |
|
540 |
absGet(b); |
|
541 |
bulkGet(b); |
|
542 |
||
543 |
bulkPutArray(b); |
|
544 |
relGet(b); |
|
545 |
||
546 |
bulkPutBuffer(b); |
|
547 |
relGet(b); |
|
548 |
||
53855 | 549 |
absBulkPutArray(b); |
550 |
absBulkGet(b); |
|
551 |
||
2 | 552 |
|
553 |
||
554 |
||
555 |
||
556 |
||
557 |
||
558 |
||
559 |
||
560 |
||
561 |
||
562 |
||
563 |
||
564 |
||
565 |
||
566 |
||
567 |
||
568 |
||
569 |
||
570 |
||
571 |
||
572 |
||
573 |
||
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
574 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
575 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
576 |
|
13563
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
577 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
578 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
579 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
580 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
581 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
582 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
583 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
584 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
585 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
586 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
587 |
|
2 | 588 |
// Compact |
589 |
||
590 |
relPut(b); |
|
591 |
b.position(13); |
|
592 |
b.compact(); |
|
593 |
b.flip(); |
|
594 |
relGet(b, 13); |
|
595 |
||
596 |
// Exceptions |
|
597 |
||
598 |
relPut(b); |
|
599 |
b.limit(b.capacity() / 2); |
|
600 |
b.position(b.limit()); |
|
601 |
||
37913 | 602 |
tryCatch(b, BufferUnderflowException.class, () -> b.get()); |
603 |
tryCatch(b, BufferOverflowException.class, () -> b.put((float)42)); |
|
604 |
// The index must be non-negative and less than the buffer's limit. |
|
605 |
catchIndexOutOfBounds(b, () -> b.get(b.limit())); |
|
606 |
catchIndexOutOfBounds(b, () -> b.get(-1)); |
|
607 |
catchIndexOutOfBounds(b, () -> b.put(b.limit(), (float)42)); |
|
608 |
tryCatch(b, InvalidMarkException.class, |
|
609 |
() -> b.position(0).mark().compact().reset()); |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
610 |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
611 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
612 |
b.position(b.limit() + 1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
613 |
fail("IllegalArgumentException expected for position beyond limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
614 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
615 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
616 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
617 |
+ " position beyond limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
618 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
619 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
620 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
621 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
622 |
b.position(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
623 |
fail("IllegalArgumentException expected for negative position"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
624 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
625 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
626 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
627 |
+ " negative position"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
628 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
629 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
630 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
631 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
632 |
b.limit(b.capacity() + 1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
633 |
fail("IllegalArgumentException expected for limit beyond capacity"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
634 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
635 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
636 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
637 |
+ " limit beyond capacity"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
638 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
639 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
640 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
641 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
642 |
b.limit(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
643 |
fail("IllegalArgumentException expected for negative limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
644 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
645 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
646 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
647 |
+ " negative limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
648 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
649 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
650 |
|
53959
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
651 |
// Exceptions in absolute bulk and slice operations |
53855 | 652 |
|
653 |
catchNullArgument(b, () -> b.get(7, null, 0, 42)); |
|
654 |
catchNullArgument(b, () -> b.put(7, (float[])null, 0, 42)); |
|
655 |
||
656 |
float[] tmpa = new float[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)); |
|
670 |
||
53959
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
671 |
catchIndexOutOfBounds(b, () -> b.slice(-1, 7)); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
672 |
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7)); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
673 |
catchIndexOutOfBounds(b, () -> b.slice(0, -1)); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
674 |
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1)); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
675 |
|
2 | 676 |
// Values |
677 |
||
678 |
b.clear(); |
|
679 |
b.put((float)0); |
|
680 |
b.put((float)-1); |
|
681 |
b.put((float)1); |
|
682 |
b.put(Float.MAX_VALUE); |
|
683 |
b.put(Float.MIN_VALUE); |
|
684 |
||
685 |
b.put(-Float.MAX_VALUE); |
|
686 |
b.put(-Float.MIN_VALUE); |
|
687 |
b.put(Float.NEGATIVE_INFINITY); |
|
688 |
b.put(Float.POSITIVE_INFINITY); |
|
689 |
b.put(Float.NaN); |
|
690 |
b.put(0.91697687f); // Changes value if incorrectly swapped |
|
691 |
||
692 |
||
693 |
||
694 |
||
695 |
||
696 |
||
697 |
||
698 |
||
699 |
||
700 |
||
701 |
b.flip(); |
|
702 |
ck(b, b.get(), 0); |
|
703 |
ck(b, b.get(), (float)-1); |
|
704 |
ck(b, b.get(), 1); |
|
705 |
ck(b, b.get(), Float.MAX_VALUE); |
|
706 |
ck(b, b.get(), Float.MIN_VALUE); |
|
707 |
||
708 |
||
37913 | 709 |
float v; |
2 | 710 |
ck(b, b.get(), -Float.MAX_VALUE); |
711 |
ck(b, b.get(), -Float.MIN_VALUE); |
|
712 |
ck(b, b.get(), Float.NEGATIVE_INFINITY); |
|
713 |
ck(b, b.get(), Float.POSITIVE_INFINITY); |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
714 |
if (Float.floatToRawIntBits(v = b.get()) != |
37913 | 715 |
Float.floatToRawIntBits(Float.NaN)) { |
2 | 716 |
fail(b, (long)Float.NaN, (long)v); |
37913 | 717 |
} |
2 | 718 |
ck(b, b.get(), 0.91697687f); |
719 |
||
720 |
||
721 |
||
722 |
||
723 |
||
724 |
||
725 |
||
726 |
||
727 |
||
728 |
||
729 |
||
730 |
||
731 |
||
37913 | 732 |
|
733 |
||
2 | 734 |
// Comparison |
735 |
b.rewind(); |
|
736 |
FloatBuffer b2 = FloatBuffer.allocate(b.capacity()); |
|
737 |
b2.put(b); |
|
738 |
b2.flip(); |
|
739 |
b.position(2); |
|
740 |
b2.position(2); |
|
741 |
if (!b.equals(b2)) { |
|
742 |
for (int i = 2; i < b.limit(); i++) { |
|
743 |
float x = b.get(i); |
|
744 |
float y = b2.get(i); |
|
745 |
if (x != y |
|
746 |
||
747 |
||
748 |
||
749 |
||
750 |
|| Float.compare(x, y) != 0 |
|
751 |
||
37913 | 752 |
) { |
2 | 753 |
out.println("[" + i + "] " + x + " != " + y); |
37913 | 754 |
} |
2 | 755 |
} |
756 |
fail("Identical buffers not equal", b, b2); |
|
757 |
} |
|
37913 | 758 |
if (b.compareTo(b2) != 0) { |
2 | 759 |
fail("Comparison to identical buffer != 0", b, b2); |
37913 | 760 |
} |
2 | 761 |
b.limit(b.limit() + 1); |
762 |
b.position(b.limit() - 1); |
|
763 |
b.put((float)99); |
|
764 |
b.rewind(); |
|
765 |
b2.rewind(); |
|
766 |
if (b.equals(b2)) |
|
767 |
fail("Non-identical buffers equal", b, b2); |
|
768 |
if (b.compareTo(b2) <= 0) |
|
769 |
fail("Comparison to shorter buffer <= 0", b, b2); |
|
770 |
b.limit(b.limit() - 1); |
|
771 |
||
772 |
b.put(2, (float)42); |
|
773 |
if (b.equals(b2)) |
|
774 |
fail("Non-identical buffers equal", b, b2); |
|
775 |
if (b.compareTo(b2) <= 0) |
|
776 |
fail("Comparison to lesser buffer <= 0", b, b2); |
|
777 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
778 |
// Check equals and compareTo with interesting values |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
779 |
for (float x : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
780 |
FloatBuffer xb = FloatBuffer.wrap(new float[] { x }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
781 |
if (xb.compareTo(xb) != 0) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
782 |
fail("compareTo not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
783 |
} |
37913 | 784 |
if (!xb.equals(xb)) { |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
785 |
fail("equals not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
786 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
787 |
for (float y : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
788 |
FloatBuffer yb = FloatBuffer.wrap(new float[] { y }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
789 |
if (xb.compareTo(yb) != - yb.compareTo(xb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
790 |
fail("compareTo not anti-symmetric", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
791 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
792 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
793 |
if ((xb.compareTo(yb) == 0) != xb.equals(yb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
794 |
fail("compareTo inconsistent with equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
795 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
796 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
797 |
if (xb.compareTo(yb) != Float.compare(x, y)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
798 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
799 |
if (x == 0.0 && y == 0.0) continue; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
800 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
801 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
802 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
803 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
804 |
fail("Incorrect results for FloatBuffer.compareTo", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
805 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
806 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
807 |
if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
808 |
fail("Incorrect results for FloatBuffer.equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
809 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
810 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
811 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
812 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
813 |
|
2 | 814 |
// Sub, dup |
815 |
||
816 |
relPut(b); |
|
817 |
relGet(b.duplicate()); |
|
818 |
b.position(13); |
|
819 |
relGet(b.duplicate(), 13); |
|
820 |
relGet(b.duplicate().slice(), 13); |
|
821 |
relGet(b.slice(), 13); |
|
822 |
relGet(b.slice().duplicate(), 13); |
|
823 |
||
824 |
// Slice |
|
825 |
||
826 |
b.position(5); |
|
827 |
FloatBuffer sb = b.slice(); |
|
828 |
checkSlice(b, sb); |
|
829 |
b.position(0); |
|
830 |
FloatBuffer sb2 = sb.slice(); |
|
831 |
checkSlice(sb, sb2); |
|
832 |
||
833 |
if (!sb.equals(sb2)) |
|
834 |
fail("Sliced slices do not match", sb, sb2); |
|
37913 | 835 |
if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) { |
2 | 836 |
fail("Array offsets do not match: " |
837 |
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2); |
|
37913 | 838 |
} |
2 | 839 |
|
53959
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
840 |
int bPos = b.position(); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
841 |
int bLim = b.limit(); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
842 |
|
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
843 |
b.position(7); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
844 |
b.limit(42); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
845 |
FloatBuffer rsb = b.slice(); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
846 |
b.position(0); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
847 |
b.limit(b.capacity()); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
848 |
FloatBuffer asb = b.slice(7, 35); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
849 |
checkSlice(rsb, asb); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
850 |
|
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
851 |
b.position(bPos); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
852 |
b.limit(bLim); |
1542e63eb537
5071718: (bf) Add ByteBuffer.slice(int offset, int length)
bpb
parents:
53855
diff
changeset
|
853 |
|
2 | 854 |
|
855 |
||
856 |
||
857 |
||
858 |
||
859 |
||
860 |
||
861 |
||
862 |
||
863 |
||
864 |
||
865 |
||
866 |
||
867 |
||
868 |
||
869 |
||
870 |
||
871 |
||
872 |
||
873 |
||
874 |
||
875 |
||
876 |
||
877 |
||
878 |
||
879 |
||
880 |
||
881 |
||
882 |
||
883 |
||
884 |
||
885 |
// Read-only views |
|
886 |
||
887 |
b.rewind(); |
|
888 |
final FloatBuffer rb = b.asReadOnlyBuffer(); |
|
889 |
if (!b.equals(rb)) |
|
890 |
fail("Buffer not equal to read-only view", b, rb); |
|
891 |
show(level + 1, rb); |
|
892 |
||
37913 | 893 |
catchReadOnlyBuffer(b, () -> relPut(rb)); |
894 |
catchReadOnlyBuffer(b, () -> absPut(rb)); |
|
895 |
catchReadOnlyBuffer(b, () -> bulkPutArray(rb)); |
|
896 |
catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb)); |
|
53855 | 897 |
catchReadOnlyBuffer(b, () -> absBulkPutArray(rb)); |
2 | 898 |
|
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
899 |
// put(FloatBuffer) should not change source position |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
900 |
final FloatBuffer src = FloatBuffer.allocate(1); |
37913 | 901 |
catchReadOnlyBuffer(b, () -> rb.put(src)); |
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
902 |
ck(src, src.position(), 0); |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
903 |
|
37913 | 904 |
catchReadOnlyBuffer(b, () -> rb.compact()); |
2 | 905 |
|
906 |
||
907 |
||
908 |
||
909 |
||
910 |
||
911 |
||
912 |
||
913 |
||
914 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
915 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
916 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
917 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
918 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
919 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
920 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
921 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
922 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
923 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
924 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
925 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
926 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
927 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
928 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
929 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
930 |
|
2 | 931 |
if (rb.getClass().getName().startsWith("java.nio.Heap")) { |
37913 | 932 |
catchReadOnlyBuffer(b, () -> rb.array()); |
933 |
catchReadOnlyBuffer(b, () -> rb.arrayOffset()); |
|
934 |
if (rb.hasArray()) { |
|
935 |
fail("Read-only heap buffer's backing array is accessible", rb); |
|
936 |
} |
|
2 | 937 |
} |
938 |
||
939 |
// Bulk puts from read-only buffers |
|
940 |
||
941 |
b.clear(); |
|
942 |
rb.rewind(); |
|
943 |
b.put(rb); |
|
944 |
||
945 |
||
946 |
||
947 |
||
948 |
||
949 |
||
950 |
||
951 |
||
952 |
||
953 |
||
954 |
||
955 |
relPut(b); // Required by testViews |
|
956 |
||
36933
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
957 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
958 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
959 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
960 |
|
3e6453e2d833
8149469: ByteBuffer API and implementation enhancements for VarHandles
psandoz
parents:
31873
diff
changeset
|
961 |
|
2 | 962 |
} |
963 |
||
964 |
||
965 |
||
966 |
||
967 |
||
968 |
||
969 |
||
970 |
||
971 |
||
972 |
||
973 |
||
974 |
||
975 |
||
976 |
||
977 |
||
978 |
||
979 |
||
980 |
||
981 |
||
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 |
||
53855 | 1007 |
|
1008 |
||
1009 |
||
1010 |
||
1011 |
||
1012 |
||
1013 |
||
2 | 1014 |
public static void test(final float [] ba) { |
1015 |
int offset = 47; |
|
1016 |
int length = 900; |
|
1017 |
final FloatBuffer b = FloatBuffer.wrap(ba, offset, length); |
|
1018 |
show(0, b); |
|
1019 |
ck(b, b.capacity(), ba.length); |
|
1020 |
ck(b, b.position(), offset); |
|
1021 |
ck(b, b.limit(), offset + length); |
|
1022 |
||
1023 |
// The offset must be non-negative and no larger than <array.length>. |
|
37913 | 1024 |
catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, -1, ba.length)); |
1025 |
catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, ba.length + 1, ba.length)); |
|
1026 |
catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, 0, -1)); |
|
1027 |
catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, 0, ba.length + 1)); |
|
2 | 1028 |
|
1029 |
// A NullPointerException will be thrown if the array is null. |
|
37913 | 1030 |
tryCatch(ba, NullPointerException.class, |
1031 |
() -> FloatBuffer.wrap((float []) null, 0, 5)); |
|
1032 |
tryCatch(ba, NullPointerException.class, |
|
1033 |
() -> FloatBuffer.wrap((float []) null)); |
|
2 | 1034 |
} |
1035 |
||
1036 |
private static void testAllocate() { |
|
1037 |
// An IllegalArgumentException will be thrown for negative capacities. |
|
37913 | 1038 |
catchIllegalArgument((Buffer) null, () -> FloatBuffer.allocate(-1)); |
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1039 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1040 |
FloatBuffer.allocate(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1041 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1042 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1043 |
fail("Non-null IllegalArgumentException message expected for" |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1044 |
+ " attempt to allocate negative capacity buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1045 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1046 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1047 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1048 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1049 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1050 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1051 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1052 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1053 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1054 |
|
2 | 1055 |
|
1056 |
||
1057 |
||
1058 |
} |
|
1059 |
||
1060 |
public static void test() { |
|
1061 |
testAllocate(); |
|
1062 |
test(0, FloatBuffer.allocate(7 * 1024), false); |
|
1063 |
test(0, FloatBuffer.wrap(new float[7 * 1024], 0, 7 * 1024), false); |
|
1064 |
test(new float[1024]); |
|
1065 |
||
1066 |
||
1067 |
||
1068 |
||
1069 |
||
1070 |
||
1071 |
||
1072 |
||
1073 |
||
1074 |
||
1075 |
callReset(FloatBuffer.allocate(10)); |
|
1076 |
||
1077 |
||
1078 |
||
1079 |
putBuffer(); |
|
1080 |
||
1081 |
} |
|
1082 |
||
1083 |
} |