author | bpb |
Fri, 24 Jul 2015 11:52:30 -0700 | |
changeset 31873 | 87b015c2cd36 |
parent 14342 | 8435a30053c1 |
child 36933 | 3e6453e2d833 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
14001
diff
changeset
|
2 |
* Copyright (c) 2000, 2012, 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.*; |
|
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 BasicDouble |
|
38 |
extends Basic |
|
39 |
{ |
|
40 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
41 |
private static final double[] VALUES = { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
42 |
Double.MIN_VALUE, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
43 |
(double) -1, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
44 |
(double) 0, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
45 |
(double) 1, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
46 |
Double.MAX_VALUE, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
47 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
48 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
49 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
50 |
|
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 |
Double.NEGATIVE_INFINITY, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
55 |
Double.POSITIVE_INFINITY, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
56 |
Double.NaN, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
57 |
(double) -0.0, |
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 |
}; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
60 |
|
2 | 61 |
private static void relGet(DoubleBuffer b) { |
62 |
int n = b.capacity(); |
|
63 |
double v; |
|
64 |
for (int i = 0; i < n; i++) |
|
65 |
ck(b, (long)b.get(), (long)((double)ic(i))); |
|
66 |
b.rewind(); |
|
67 |
} |
|
68 |
||
69 |
private static void relGet(DoubleBuffer b, int start) { |
|
70 |
int n = b.remaining(); |
|
71 |
double v; |
|
72 |
for (int i = start; i < n; i++) |
|
73 |
ck(b, (long)b.get(), (long)((double)ic(i))); |
|
74 |
b.rewind(); |
|
75 |
} |
|
76 |
||
77 |
private static void absGet(DoubleBuffer b) { |
|
78 |
int n = b.capacity(); |
|
79 |
double v; |
|
80 |
for (int i = 0; i < n; i++) |
|
81 |
ck(b, (long)b.get(), (long)((double)ic(i))); |
|
82 |
b.rewind(); |
|
83 |
} |
|
84 |
||
85 |
private static void bulkGet(DoubleBuffer b) { |
|
86 |
int n = b.capacity(); |
|
87 |
double[] a = new double[n + 7]; |
|
88 |
b.get(a, 7, n); |
|
89 |
for (int i = 0; i < n; i++) |
|
90 |
ck(b, (long)a[i + 7], (long)((double)ic(i))); |
|
91 |
} |
|
92 |
||
93 |
private static void relPut(DoubleBuffer b) { |
|
94 |
int n = b.capacity(); |
|
95 |
b.clear(); |
|
96 |
for (int i = 0; i < n; i++) |
|
97 |
b.put((double)ic(i)); |
|
98 |
b.flip(); |
|
99 |
} |
|
100 |
||
101 |
private static void absPut(DoubleBuffer b) { |
|
102 |
int n = b.capacity(); |
|
103 |
b.clear(); |
|
104 |
for (int i = 0; i < n; i++) |
|
105 |
b.put(i, (double)ic(i)); |
|
106 |
b.limit(n); |
|
107 |
b.position(0); |
|
108 |
} |
|
109 |
||
110 |
private static void bulkPutArray(DoubleBuffer b) { |
|
111 |
int n = b.capacity(); |
|
112 |
b.clear(); |
|
113 |
double[] a = new double[n + 7]; |
|
114 |
for (int i = 0; i < n; i++) |
|
115 |
a[i + 7] = (double)ic(i); |
|
116 |
b.put(a, 7, n); |
|
117 |
b.flip(); |
|
118 |
} |
|
119 |
||
120 |
private static void bulkPutBuffer(DoubleBuffer b) { |
|
121 |
int n = b.capacity(); |
|
122 |
b.clear(); |
|
123 |
DoubleBuffer c = DoubleBuffer.allocate(n + 7); |
|
124 |
c.position(7); |
|
125 |
for (int i = 0; i < n; i++) |
|
126 |
c.put((double)ic(i)); |
|
127 |
c.flip(); |
|
128 |
c.position(7); |
|
129 |
b.put(c); |
|
130 |
b.flip(); |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
131 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
132 |
b.put(b); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
133 |
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
|
134 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
135 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
136 |
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
|
137 |
+ " put into same buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
138 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
139 |
} |
2 | 140 |
} |
141 |
||
142 |
//6231529 |
|
143 |
private static void callReset(DoubleBuffer b) { |
|
144 |
b.position(0); |
|
145 |
b.mark(); |
|
146 |
||
147 |
b.duplicate().reset(); |
|
148 |
b.asReadOnlyBuffer().reset(); |
|
149 |
} |
|
150 |
||
151 |
||
152 |
||
153 |
// 6221101-6234263 |
|
154 |
||
155 |
private static void putBuffer() { |
|
156 |
final int cap = 10; |
|
157 |
||
158 |
DoubleBuffer direct1 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
159 |
DoubleBuffer nondirect1 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
160 |
direct1.put(nondirect1); |
|
161 |
||
162 |
DoubleBuffer direct2 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
163 |
DoubleBuffer nondirect2 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
164 |
nondirect2.put(direct2); |
|
165 |
||
166 |
DoubleBuffer direct3 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
167 |
DoubleBuffer direct4 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
168 |
direct3.put(direct4); |
|
169 |
||
170 |
DoubleBuffer nondirect3 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
171 |
DoubleBuffer nondirect4 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
172 |
nondirect3.put(nondirect4); |
|
173 |
} |
|
174 |
||
175 |
||
176 |
||
177 |
||
178 |
||
179 |
||
180 |
||
181 |
||
182 |
||
183 |
||
184 |
||
185 |
||
186 |
||
187 |
||
188 |
||
189 |
||
190 |
||
191 |
private static void checkSlice(DoubleBuffer b, DoubleBuffer slice) { |
|
192 |
ck(slice, 0, slice.position()); |
|
193 |
ck(slice, b.remaining(), slice.limit()); |
|
194 |
ck(slice, b.remaining(), slice.capacity()); |
|
195 |
if (b.isDirect() != slice.isDirect()) |
|
196 |
fail("Lost direction", slice); |
|
197 |
if (b.isReadOnly() != slice.isReadOnly()) |
|
198 |
fail("Lost read-only", slice); |
|
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 |
||
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 |
||
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
316 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
317 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
318 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
319 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
320 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
321 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
322 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
323 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
324 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
325 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
326 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
327 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
328 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
329 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
330 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
331 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
332 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
333 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
334 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
335 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
336 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
337 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
338 |
|
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 |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
341 |
private static void fail(String problem, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
342 |
DoubleBuffer xb, DoubleBuffer yb, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
343 |
double x, double y) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
344 |
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
|
345 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
346 |
|
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
347 |
private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) { |
2 | 348 |
boolean caught = false; |
349 |
try { |
|
350 |
thunk.run(); |
|
351 |
} catch (Throwable x) { |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
352 |
if (ex.isAssignableFrom(x.getClass())) { |
2 | 353 |
caught = true; |
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
354 |
} else { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
355 |
fail(x.getMessage() + " not expected"); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
356 |
} |
2 | 357 |
} |
358 |
if (!caught) |
|
359 |
fail(ex.getName() + " not thrown", b); |
|
360 |
} |
|
361 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
362 |
private static void tryCatch(double [] t, Class<?> ex, Runnable thunk) { |
2 | 363 |
tryCatch(DoubleBuffer.wrap(t), ex, thunk); |
364 |
} |
|
365 |
||
366 |
public static void test(int level, final DoubleBuffer b, boolean direct) { |
|
367 |
||
368 |
show(level, b); |
|
369 |
||
370 |
if (direct != b.isDirect()) |
|
371 |
fail("Wrong direction", b); |
|
372 |
||
373 |
// Gets and puts |
|
374 |
||
375 |
relPut(b); |
|
376 |
relGet(b); |
|
377 |
absGet(b); |
|
378 |
bulkGet(b); |
|
379 |
||
380 |
absPut(b); |
|
381 |
relGet(b); |
|
382 |
absGet(b); |
|
383 |
bulkGet(b); |
|
384 |
||
385 |
bulkPutArray(b); |
|
386 |
relGet(b); |
|
387 |
||
388 |
bulkPutBuffer(b); |
|
389 |
relGet(b); |
|
390 |
||
391 |
||
392 |
||
393 |
||
394 |
||
395 |
||
396 |
||
397 |
||
398 |
||
399 |
||
400 |
||
401 |
||
402 |
||
403 |
||
404 |
||
405 |
||
406 |
||
407 |
||
408 |
||
409 |
||
410 |
||
411 |
||
412 |
||
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
413 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
414 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
415 |
|
13563
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
416 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
417 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
418 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
419 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
420 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
421 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
422 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
423 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
424 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
425 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
426 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
427 |
|
13c8e8f0302b
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents:
5506
diff
changeset
|
428 |
|
2 | 429 |
// Compact |
430 |
||
431 |
relPut(b); |
|
432 |
b.position(13); |
|
433 |
b.compact(); |
|
434 |
b.flip(); |
|
435 |
relGet(b, 13); |
|
436 |
||
437 |
// Exceptions |
|
438 |
||
439 |
relPut(b); |
|
440 |
b.limit(b.capacity() / 2); |
|
441 |
b.position(b.limit()); |
|
442 |
||
443 |
tryCatch(b, BufferUnderflowException.class, new Runnable() { |
|
444 |
public void run() { |
|
445 |
b.get(); |
|
446 |
}}); |
|
447 |
||
448 |
tryCatch(b, BufferOverflowException.class, new Runnable() { |
|
449 |
public void run() { |
|
450 |
b.put((double)42); |
|
451 |
}}); |
|
452 |
||
453 |
// The index must be non-negative and lesss than the buffer's limit. |
|
454 |
tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
|
455 |
public void run() { |
|
456 |
b.get(b.limit()); |
|
457 |
}}); |
|
458 |
tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
|
459 |
public void run() { |
|
460 |
b.get(-1); |
|
461 |
}}); |
|
462 |
||
463 |
tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
|
464 |
public void run() { |
|
465 |
b.put(b.limit(), (double)42); |
|
466 |
}}); |
|
467 |
||
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
468 |
tryCatch(b, InvalidMarkException.class, new Runnable() { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
469 |
public void run() { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
470 |
b.position(0); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
471 |
b.mark(); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
472 |
b.compact(); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
473 |
b.reset(); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
474 |
}}); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
475 |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
476 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
477 |
b.position(b.limit() + 1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
478 |
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
|
479 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
480 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
481 |
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
|
482 |
+ " position beyond limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
483 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
484 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
485 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
486 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
487 |
b.position(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
488 |
fail("IllegalArgumentException expected for negative position"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
489 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
490 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
491 |
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
|
492 |
+ " negative position"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
493 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
494 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
495 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
496 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
497 |
b.limit(b.capacity() + 1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
498 |
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
|
499 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
500 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
501 |
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
|
502 |
+ " limit beyond capacity"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
503 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
504 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
505 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
506 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
507 |
b.limit(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
508 |
fail("IllegalArgumentException expected for negative limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
509 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
510 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
511 |
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
|
512 |
+ " negative limit"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
513 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
514 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
515 |
|
2 | 516 |
// Values |
517 |
||
518 |
b.clear(); |
|
519 |
b.put((double)0); |
|
520 |
b.put((double)-1); |
|
521 |
b.put((double)1); |
|
522 |
b.put(Double.MAX_VALUE); |
|
523 |
b.put(Double.MIN_VALUE); |
|
524 |
||
525 |
||
526 |
||
527 |
||
528 |
||
529 |
||
530 |
||
531 |
||
532 |
||
533 |
b.put(-Double.MAX_VALUE); |
|
534 |
b.put(-Double.MIN_VALUE); |
|
535 |
b.put(Double.NEGATIVE_INFINITY); |
|
536 |
b.put(Double.POSITIVE_INFINITY); |
|
537 |
b.put(Double.NaN); |
|
538 |
b.put(0.5121609353879392); // Changes value if incorrectly swapped |
|
539 |
||
540 |
||
541 |
double v; |
|
542 |
b.flip(); |
|
543 |
ck(b, b.get(), 0); |
|
544 |
ck(b, b.get(), (double)-1); |
|
545 |
ck(b, b.get(), 1); |
|
546 |
ck(b, b.get(), Double.MAX_VALUE); |
|
547 |
ck(b, b.get(), Double.MIN_VALUE); |
|
548 |
||
549 |
||
550 |
||
551 |
||
552 |
||
553 |
||
554 |
||
555 |
||
556 |
||
557 |
||
558 |
||
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
559 |
|
2 | 560 |
ck(b, b.get(), -Double.MAX_VALUE); |
561 |
ck(b, b.get(), -Double.MIN_VALUE); |
|
562 |
ck(b, b.get(), Double.NEGATIVE_INFINITY); |
|
563 |
ck(b, b.get(), Double.POSITIVE_INFINITY); |
|
564 |
if (Double.doubleToRawLongBits(v = b.get()) |
|
565 |
!= Double.doubleToRawLongBits(Double.NaN)) |
|
566 |
fail(b, (long)Double.NaN, (long)v); |
|
567 |
ck(b, b.get(), 0.5121609353879392); |
|
568 |
||
569 |
||
570 |
||
571 |
// Comparison |
|
572 |
b.rewind(); |
|
573 |
DoubleBuffer b2 = DoubleBuffer.allocate(b.capacity()); |
|
574 |
b2.put(b); |
|
575 |
b2.flip(); |
|
576 |
b.position(2); |
|
577 |
b2.position(2); |
|
578 |
if (!b.equals(b2)) { |
|
579 |
for (int i = 2; i < b.limit(); i++) { |
|
580 |
double x = b.get(i); |
|
581 |
double y = b2.get(i); |
|
582 |
if (x != y |
|
583 |
||
584 |
|| Double.compare(x, y) != 0 |
|
585 |
||
586 |
||
587 |
||
588 |
||
589 |
) |
|
590 |
out.println("[" + i + "] " + x + " != " + y); |
|
591 |
} |
|
592 |
fail("Identical buffers not equal", b, b2); |
|
593 |
} |
|
594 |
if (b.compareTo(b2) != 0) |
|
595 |
fail("Comparison to identical buffer != 0", b, b2); |
|
596 |
||
597 |
b.limit(b.limit() + 1); |
|
598 |
b.position(b.limit() - 1); |
|
599 |
b.put((double)99); |
|
600 |
b.rewind(); |
|
601 |
b2.rewind(); |
|
602 |
if (b.equals(b2)) |
|
603 |
fail("Non-identical buffers equal", b, b2); |
|
604 |
if (b.compareTo(b2) <= 0) |
|
605 |
fail("Comparison to shorter buffer <= 0", b, b2); |
|
606 |
b.limit(b.limit() - 1); |
|
607 |
||
608 |
b.put(2, (double)42); |
|
609 |
if (b.equals(b2)) |
|
610 |
fail("Non-identical buffers equal", b, b2); |
|
611 |
if (b.compareTo(b2) <= 0) |
|
612 |
fail("Comparison to lesser buffer <= 0", b, b2); |
|
613 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
614 |
// Check equals and compareTo with interesting values |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
615 |
for (double x : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
616 |
DoubleBuffer xb = DoubleBuffer.wrap(new double[] { x }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
617 |
if (xb.compareTo(xb) != 0) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
618 |
fail("compareTo not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
619 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
620 |
if (! xb.equals(xb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
621 |
fail("equals not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
622 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
623 |
for (double y : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
624 |
DoubleBuffer yb = DoubleBuffer.wrap(new double[] { y }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
625 |
if (xb.compareTo(yb) != - yb.compareTo(xb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
626 |
fail("compareTo not anti-symmetric", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
627 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
628 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
629 |
if ((xb.compareTo(yb) == 0) != xb.equals(yb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
630 |
fail("compareTo inconsistent with equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
631 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
632 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
633 |
if (xb.compareTo(yb) != Double.compare(x, y)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
634 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
635 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
636 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
637 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
638 |
if (x == 0.0 && y == 0.0) continue; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
639 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
640 |
fail("Incorrect results for DoubleBuffer.compareTo", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
641 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
642 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
643 |
if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
644 |
fail("Incorrect results for DoubleBuffer.equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
645 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
646 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
647 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
648 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
649 |
|
2 | 650 |
// Sub, dup |
651 |
||
652 |
relPut(b); |
|
653 |
relGet(b.duplicate()); |
|
654 |
b.position(13); |
|
655 |
relGet(b.duplicate(), 13); |
|
656 |
relGet(b.duplicate().slice(), 13); |
|
657 |
relGet(b.slice(), 13); |
|
658 |
relGet(b.slice().duplicate(), 13); |
|
659 |
||
660 |
// Slice |
|
661 |
||
662 |
b.position(5); |
|
663 |
DoubleBuffer sb = b.slice(); |
|
664 |
checkSlice(b, sb); |
|
665 |
b.position(0); |
|
666 |
DoubleBuffer sb2 = sb.slice(); |
|
667 |
checkSlice(sb, sb2); |
|
668 |
||
669 |
if (!sb.equals(sb2)) |
|
670 |
fail("Sliced slices do not match", sb, sb2); |
|
671 |
if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) |
|
672 |
fail("Array offsets do not match: " |
|
673 |
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2); |
|
674 |
||
675 |
||
676 |
||
677 |
||
678 |
||
679 |
||
680 |
||
681 |
||
682 |
||
683 |
||
684 |
||
685 |
||
686 |
||
687 |
||
688 |
||
689 |
||
690 |
||
691 |
||
692 |
||
693 |
||
694 |
||
695 |
||
696 |
||
697 |
||
698 |
||
699 |
||
700 |
||
701 |
||
702 |
||
703 |
||
704 |
||
705 |
||
706 |
// Read-only views |
|
707 |
||
708 |
b.rewind(); |
|
709 |
final DoubleBuffer rb = b.asReadOnlyBuffer(); |
|
710 |
if (!b.equals(rb)) |
|
711 |
fail("Buffer not equal to read-only view", b, rb); |
|
712 |
show(level + 1, rb); |
|
713 |
||
714 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
715 |
public void run() { |
|
716 |
relPut(rb); |
|
717 |
}}); |
|
718 |
||
719 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
720 |
public void run() { |
|
721 |
absPut(rb); |
|
722 |
}}); |
|
723 |
||
724 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
725 |
public void run() { |
|
726 |
bulkPutArray(rb); |
|
727 |
}}); |
|
728 |
||
729 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
730 |
public void run() { |
|
731 |
bulkPutBuffer(rb); |
|
732 |
}}); |
|
733 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
734 |
// put(DoubleBuffer) should not change source position |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
735 |
final DoubleBuffer src = DoubleBuffer.allocate(1); |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
736 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
737 |
public void run() { |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
738 |
rb.put(src); |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
739 |
}}); |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
740 |
ck(src, src.position(), 0); |
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
741 |
|
2 | 742 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
743 |
public void run() { |
|
744 |
rb.compact(); |
|
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 |
||
790 |
||
791 |
||
792 |
||
793 |
||
794 |
||
795 |
||
796 |
||
797 |
||
798 |
||
799 |
||
800 |
||
801 |
||
802 |
||
803 |
||
804 |
||
14001
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
805 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
806 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
807 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
808 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
809 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
810 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
811 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
812 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
813 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
814 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
815 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
816 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
817 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
818 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
819 |
|
e8e8413ad49a
7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents:
13563
diff
changeset
|
820 |
|
2 | 821 |
if (rb.getClass().getName().startsWith("java.nio.Heap")) { |
822 |
||
823 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
824 |
public void run() { |
|
825 |
rb.array(); |
|
826 |
}}); |
|
827 |
||
828 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
829 |
public void run() { |
|
830 |
rb.arrayOffset(); |
|
831 |
}}); |
|
832 |
||
833 |
if (rb.hasArray()) |
|
834 |
fail("Read-only heap buffer's backing array is accessible", |
|
835 |
rb); |
|
836 |
||
837 |
} |
|
838 |
||
839 |
// Bulk puts from read-only buffers |
|
840 |
||
841 |
b.clear(); |
|
842 |
rb.rewind(); |
|
843 |
b.put(rb); |
|
844 |
||
845 |
||
846 |
||
847 |
||
848 |
||
849 |
||
850 |
||
851 |
||
852 |
||
853 |
||
854 |
||
855 |
relPut(b); // Required by testViews |
|
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 |
||
886 |
||
887 |
||
888 |
||
889 |
||
890 |
||
891 |
||
892 |
||
893 |
||
894 |
||
895 |
||
896 |
||
897 |
||
898 |
||
899 |
||
900 |
||
901 |
||
902 |
||
903 |
||
904 |
||
905 |
||
906 |
||
907 |
||
908 |
||
909 |
||
910 |
||
911 |
||
912 |
||
913 |
||
914 |
||
915 |
||
916 |
||
917 |
||
918 |
||
919 |
||
920 |
||
921 |
||
922 |
||
923 |
||
924 |
||
925 |
||
926 |
||
927 |
||
928 |
||
929 |
||
930 |
||
931 |
||
932 |
||
933 |
||
934 |
||
935 |
||
936 |
||
937 |
||
938 |
||
939 |
||
940 |
||
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
941 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
942 |
|
2 | 943 |
public static void test(final double [] ba) { |
944 |
int offset = 47; |
|
945 |
int length = 900; |
|
946 |
final DoubleBuffer b = DoubleBuffer.wrap(ba, offset, length); |
|
947 |
show(0, b); |
|
948 |
ck(b, b.capacity(), ba.length); |
|
949 |
ck(b, b.position(), offset); |
|
950 |
ck(b, b.limit(), offset + length); |
|
951 |
||
952 |
// The offset must be non-negative and no larger than <array.length>. |
|
953 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
954 |
public void run() { |
|
955 |
DoubleBuffer.wrap(ba, -1, ba.length); |
|
956 |
}}); |
|
957 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
958 |
public void run() { |
|
959 |
DoubleBuffer.wrap(ba, ba.length + 1, ba.length); |
|
960 |
}}); |
|
961 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
962 |
public void run() { |
|
963 |
DoubleBuffer.wrap(ba, 0, -1); |
|
964 |
}}); |
|
965 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
966 |
public void run() { |
|
967 |
DoubleBuffer.wrap(ba, 0, ba.length + 1); |
|
968 |
}}); |
|
969 |
||
970 |
// A NullPointerException will be thrown if the array is null. |
|
971 |
tryCatch(ba, NullPointerException.class, new Runnable() { |
|
972 |
public void run() { |
|
973 |
DoubleBuffer.wrap((double []) null, 0, 5); |
|
974 |
}}); |
|
975 |
tryCatch(ba, NullPointerException.class, new Runnable() { |
|
976 |
public void run() { |
|
977 |
DoubleBuffer.wrap((double []) null); |
|
978 |
}}); |
|
979 |
} |
|
980 |
||
981 |
private static void testAllocate() { |
|
982 |
// An IllegalArgumentException will be thrown for negative capacities. |
|
983 |
tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() { |
|
984 |
public void run() { |
|
985 |
DoubleBuffer.allocate(-1); |
|
986 |
}}); |
|
31873
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
987 |
try { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
988 |
DoubleBuffer.allocate(-1); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
989 |
} catch (IllegalArgumentException e) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
990 |
if (e.getMessage() == null) { |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
991 |
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
|
992 |
+ " attempt to allocate negative capacity buffer"); |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
993 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
994 |
} |
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
995 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
996 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
997 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
998 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
999 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1000 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1001 |
|
87b015c2cd36
8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents:
14342
diff
changeset
|
1002 |
|
2 | 1003 |
|
1004 |
||
1005 |
||
1006 |
||
1007 |
||
1008 |
||
1009 |
} |
|
1010 |
||
1011 |
public static void test() { |
|
1012 |
testAllocate(); |
|
1013 |
test(0, DoubleBuffer.allocate(7 * 1024), false); |
|
1014 |
test(0, DoubleBuffer.wrap(new double[7 * 1024], 0, 7 * 1024), false); |
|
1015 |
test(new double[1024]); |
|
1016 |
||
1017 |
||
1018 |
||
1019 |
||
1020 |
||
1021 |
||
1022 |
||
1023 |
||
1024 |
||
1025 |
||
1026 |
callReset(DoubleBuffer.allocate(10)); |
|
1027 |
||
1028 |
||
1029 |
||
1030 |
putBuffer(); |
|
1031 |
||
1032 |
} |
|
1033 |
||
1034 |
} |