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