author | martin |
Tue, 08 Dec 2009 12:41:01 -0800 | |
changeset 4502 | 18f387917b89 |
parent 2593 | 76032557be03 |
child 5506 | 202f599c92aa |
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 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(); |
|
131 |
} |
|
132 |
||
133 |
//6231529 |
|
134 |
private static void callReset(DoubleBuffer b) { |
|
135 |
b.position(0); |
|
136 |
b.mark(); |
|
137 |
||
138 |
b.duplicate().reset(); |
|
139 |
b.asReadOnlyBuffer().reset(); |
|
140 |
} |
|
141 |
||
142 |
||
143 |
||
144 |
// 6221101-6234263 |
|
145 |
||
146 |
private static void putBuffer() { |
|
147 |
final int cap = 10; |
|
148 |
||
149 |
DoubleBuffer direct1 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
150 |
DoubleBuffer nondirect1 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
151 |
direct1.put(nondirect1); |
|
152 |
||
153 |
DoubleBuffer direct2 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
154 |
DoubleBuffer nondirect2 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
155 |
nondirect2.put(direct2); |
|
156 |
||
157 |
DoubleBuffer direct3 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
158 |
DoubleBuffer direct4 = ByteBuffer.allocateDirect(cap).asDoubleBuffer(); |
|
159 |
direct3.put(direct4); |
|
160 |
||
161 |
DoubleBuffer nondirect3 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
162 |
DoubleBuffer nondirect4 = ByteBuffer.allocate(cap).asDoubleBuffer(); |
|
163 |
nondirect3.put(nondirect4); |
|
164 |
} |
|
165 |
||
166 |
||
167 |
||
168 |
||
169 |
||
170 |
||
171 |
||
172 |
||
173 |
||
174 |
||
175 |
||
176 |
||
177 |
||
178 |
||
179 |
||
180 |
||
181 |
||
182 |
private static void checkSlice(DoubleBuffer b, DoubleBuffer slice) { |
|
183 |
ck(slice, 0, slice.position()); |
|
184 |
ck(slice, b.remaining(), slice.limit()); |
|
185 |
ck(slice, b.remaining(), slice.capacity()); |
|
186 |
if (b.isDirect() != slice.isDirect()) |
|
187 |
fail("Lost direction", slice); |
|
188 |
if (b.isReadOnly() != slice.isReadOnly()) |
|
189 |
fail("Lost read-only", slice); |
|
190 |
} |
|
191 |
||
192 |
||
193 |
||
194 |
||
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 |
||
287 |
||
288 |
||
289 |
||
290 |
||
291 |
||
292 |
||
293 |
||
294 |
||
295 |
||
296 |
||
297 |
||
298 |
||
299 |
||
300 |
||
301 |
||
302 |
||
303 |
||
304 |
||
305 |
||
306 |
||
1634
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 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
312 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
313 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
314 |
|
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
315 |
|
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 |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
332 |
private static void fail(String problem, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
333 |
DoubleBuffer xb, DoubleBuffer yb, |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
334 |
double x, double y) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
335 |
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
|
336 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
337 |
|
2 | 338 |
private static void tryCatch(Buffer b, Class ex, Runnable thunk) { |
339 |
boolean caught = false; |
|
340 |
try { |
|
341 |
thunk.run(); |
|
342 |
} catch (Throwable x) { |
|
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
343 |
if (ex.isAssignableFrom(x.getClass())) { |
2 | 344 |
caught = true; |
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
345 |
} else { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
346 |
fail(x.getMessage() + " not expected"); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
347 |
} |
2 | 348 |
} |
349 |
if (!caught) |
|
350 |
fail(ex.getName() + " not thrown", b); |
|
351 |
} |
|
352 |
||
353 |
private static void tryCatch(double [] t, Class ex, Runnable thunk) { |
|
354 |
tryCatch(DoubleBuffer.wrap(t), ex, thunk); |
|
355 |
} |
|
356 |
||
357 |
public static void test(int level, final DoubleBuffer b, boolean direct) { |
|
358 |
||
359 |
show(level, b); |
|
360 |
||
361 |
if (direct != b.isDirect()) |
|
362 |
fail("Wrong direction", b); |
|
363 |
||
364 |
// Gets and puts |
|
365 |
||
366 |
relPut(b); |
|
367 |
relGet(b); |
|
368 |
absGet(b); |
|
369 |
bulkGet(b); |
|
370 |
||
371 |
absPut(b); |
|
372 |
relGet(b); |
|
373 |
absGet(b); |
|
374 |
bulkGet(b); |
|
375 |
||
376 |
bulkPutArray(b); |
|
377 |
relGet(b); |
|
378 |
||
379 |
bulkPutBuffer(b); |
|
380 |
relGet(b); |
|
381 |
||
382 |
||
383 |
||
384 |
||
385 |
||
386 |
||
387 |
||
388 |
||
389 |
||
390 |
||
391 |
||
392 |
||
393 |
||
394 |
||
395 |
||
396 |
||
397 |
||
398 |
||
399 |
||
400 |
||
401 |
||
402 |
||
403 |
||
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
404 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
405 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
406 |
|
2 | 407 |
// Compact |
408 |
||
409 |
relPut(b); |
|
410 |
b.position(13); |
|
411 |
b.compact(); |
|
412 |
b.flip(); |
|
413 |
relGet(b, 13); |
|
414 |
||
415 |
// Exceptions |
|
416 |
||
417 |
relPut(b); |
|
418 |
b.limit(b.capacity() / 2); |
|
419 |
b.position(b.limit()); |
|
420 |
||
421 |
tryCatch(b, BufferUnderflowException.class, new Runnable() { |
|
422 |
public void run() { |
|
423 |
b.get(); |
|
424 |
}}); |
|
425 |
||
426 |
tryCatch(b, BufferOverflowException.class, new Runnable() { |
|
427 |
public void run() { |
|
428 |
b.put((double)42); |
|
429 |
}}); |
|
430 |
||
431 |
// The index must be non-negative and lesss than the buffer's limit. |
|
432 |
tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
|
433 |
public void run() { |
|
434 |
b.get(b.limit()); |
|
435 |
}}); |
|
436 |
tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
|
437 |
public void run() { |
|
438 |
b.get(-1); |
|
439 |
}}); |
|
440 |
||
441 |
tryCatch(b, IndexOutOfBoundsException.class, new Runnable() { |
|
442 |
public void run() { |
|
443 |
b.put(b.limit(), (double)42); |
|
444 |
}}); |
|
445 |
||
1634
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
446 |
tryCatch(b, InvalidMarkException.class, new Runnable() { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
447 |
public void run() { |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
448 |
b.position(0); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
449 |
b.mark(); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
450 |
b.compact(); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
451 |
b.reset(); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
452 |
}}); |
3871c2046043
6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents:
2
diff
changeset
|
453 |
|
2 | 454 |
// Values |
455 |
||
456 |
b.clear(); |
|
457 |
b.put((double)0); |
|
458 |
b.put((double)-1); |
|
459 |
b.put((double)1); |
|
460 |
b.put(Double.MAX_VALUE); |
|
461 |
b.put(Double.MIN_VALUE); |
|
462 |
||
463 |
||
464 |
||
465 |
||
466 |
||
467 |
||
468 |
||
469 |
||
470 |
||
471 |
b.put(-Double.MAX_VALUE); |
|
472 |
b.put(-Double.MIN_VALUE); |
|
473 |
b.put(Double.NEGATIVE_INFINITY); |
|
474 |
b.put(Double.POSITIVE_INFINITY); |
|
475 |
b.put(Double.NaN); |
|
476 |
b.put(0.5121609353879392); // Changes value if incorrectly swapped |
|
477 |
||
478 |
||
479 |
double v; |
|
480 |
b.flip(); |
|
481 |
ck(b, b.get(), 0); |
|
482 |
ck(b, b.get(), (double)-1); |
|
483 |
ck(b, b.get(), 1); |
|
484 |
ck(b, b.get(), Double.MAX_VALUE); |
|
485 |
ck(b, b.get(), Double.MIN_VALUE); |
|
486 |
||
487 |
||
488 |
||
489 |
||
490 |
||
491 |
||
492 |
||
493 |
||
494 |
||
495 |
||
496 |
||
497 |
ck(b, b.get(), -Double.MAX_VALUE); |
|
498 |
ck(b, b.get(), -Double.MIN_VALUE); |
|
499 |
ck(b, b.get(), Double.NEGATIVE_INFINITY); |
|
500 |
ck(b, b.get(), Double.POSITIVE_INFINITY); |
|
501 |
if (Double.doubleToRawLongBits(v = b.get()) |
|
502 |
!= Double.doubleToRawLongBits(Double.NaN)) |
|
503 |
fail(b, (long)Double.NaN, (long)v); |
|
504 |
ck(b, b.get(), 0.5121609353879392); |
|
505 |
||
506 |
||
507 |
||
508 |
// Comparison |
|
509 |
b.rewind(); |
|
510 |
DoubleBuffer b2 = DoubleBuffer.allocate(b.capacity()); |
|
511 |
b2.put(b); |
|
512 |
b2.flip(); |
|
513 |
b.position(2); |
|
514 |
b2.position(2); |
|
515 |
if (!b.equals(b2)) { |
|
516 |
for (int i = 2; i < b.limit(); i++) { |
|
517 |
double x = b.get(i); |
|
518 |
double y = b2.get(i); |
|
519 |
if (x != y |
|
520 |
||
521 |
|| Double.compare(x, y) != 0 |
|
522 |
||
523 |
||
524 |
||
525 |
||
526 |
) |
|
527 |
out.println("[" + i + "] " + x + " != " + y); |
|
528 |
} |
|
529 |
fail("Identical buffers not equal", b, b2); |
|
530 |
} |
|
531 |
if (b.compareTo(b2) != 0) |
|
532 |
fail("Comparison to identical buffer != 0", b, b2); |
|
533 |
||
534 |
b.limit(b.limit() + 1); |
|
535 |
b.position(b.limit() - 1); |
|
536 |
b.put((double)99); |
|
537 |
b.rewind(); |
|
538 |
b2.rewind(); |
|
539 |
if (b.equals(b2)) |
|
540 |
fail("Non-identical buffers equal", b, b2); |
|
541 |
if (b.compareTo(b2) <= 0) |
|
542 |
fail("Comparison to shorter buffer <= 0", b, b2); |
|
543 |
b.limit(b.limit() - 1); |
|
544 |
||
545 |
b.put(2, (double)42); |
|
546 |
if (b.equals(b2)) |
|
547 |
fail("Non-identical buffers equal", b, b2); |
|
548 |
if (b.compareTo(b2) <= 0) |
|
549 |
fail("Comparison to lesser buffer <= 0", b, b2); |
|
550 |
||
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
551 |
// Check equals and compareTo with interesting values |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
552 |
for (double x : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
553 |
DoubleBuffer xb = DoubleBuffer.wrap(new double[] { x }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
554 |
if (xb.compareTo(xb) != 0) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
555 |
fail("compareTo not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
556 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
557 |
if (! xb.equals(xb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
558 |
fail("equals not reflexive", xb, xb, x, x); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
559 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
560 |
for (double y : VALUES) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
561 |
DoubleBuffer yb = DoubleBuffer.wrap(new double[] { y }); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
562 |
if (xb.compareTo(yb) != - yb.compareTo(xb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
563 |
fail("compareTo not anti-symmetric", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
564 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
565 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
566 |
if ((xb.compareTo(yb) == 0) != xb.equals(yb)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
567 |
fail("compareTo inconsistent with equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
568 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
569 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
570 |
if (xb.compareTo(yb) != Double.compare(x, y)) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
571 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
572 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
573 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
574 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
575 |
if (x == 0.0 && y == 0.0) continue; |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
576 |
|
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
577 |
fail("Incorrect results for DoubleBuffer.compareTo", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
578 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
579 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
580 |
if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) { |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
581 |
fail("Incorrect results for DoubleBuffer.equals", |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
582 |
xb, yb, x, y); |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
583 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
584 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
585 |
} |
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
2593
diff
changeset
|
586 |
|
2 | 587 |
// Sub, dup |
588 |
||
589 |
relPut(b); |
|
590 |
relGet(b.duplicate()); |
|
591 |
b.position(13); |
|
592 |
relGet(b.duplicate(), 13); |
|
593 |
relGet(b.duplicate().slice(), 13); |
|
594 |
relGet(b.slice(), 13); |
|
595 |
relGet(b.slice().duplicate(), 13); |
|
596 |
||
597 |
// Slice |
|
598 |
||
599 |
b.position(5); |
|
600 |
DoubleBuffer sb = b.slice(); |
|
601 |
checkSlice(b, sb); |
|
602 |
b.position(0); |
|
603 |
DoubleBuffer sb2 = sb.slice(); |
|
604 |
checkSlice(sb, sb2); |
|
605 |
||
606 |
if (!sb.equals(sb2)) |
|
607 |
fail("Sliced slices do not match", sb, sb2); |
|
608 |
if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) |
|
609 |
fail("Array offsets do not match: " |
|
610 |
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2); |
|
611 |
||
612 |
||
613 |
||
614 |
||
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 |
// Read-only views |
|
644 |
||
645 |
b.rewind(); |
|
646 |
final DoubleBuffer rb = b.asReadOnlyBuffer(); |
|
647 |
if (!b.equals(rb)) |
|
648 |
fail("Buffer not equal to read-only view", b, rb); |
|
649 |
show(level + 1, rb); |
|
650 |
||
651 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
652 |
public void run() { |
|
653 |
relPut(rb); |
|
654 |
}}); |
|
655 |
||
656 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
657 |
public void run() { |
|
658 |
absPut(rb); |
|
659 |
}}); |
|
660 |
||
661 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
662 |
public void run() { |
|
663 |
bulkPutArray(rb); |
|
664 |
}}); |
|
665 |
||
666 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
667 |
public void run() { |
|
668 |
bulkPutBuffer(rb); |
|
669 |
}}); |
|
670 |
||
671 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
672 |
public void run() { |
|
673 |
rb.compact(); |
|
674 |
}}); |
|
675 |
||
676 |
||
677 |
||
678 |
||
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 |
||
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 |
if (rb.getClass().getName().startsWith("java.nio.Heap")) { |
|
735 |
||
736 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
737 |
public void run() { |
|
738 |
rb.array(); |
|
739 |
}}); |
|
740 |
||
741 |
tryCatch(b, ReadOnlyBufferException.class, new Runnable() { |
|
742 |
public void run() { |
|
743 |
rb.arrayOffset(); |
|
744 |
}}); |
|
745 |
||
746 |
if (rb.hasArray()) |
|
747 |
fail("Read-only heap buffer's backing array is accessible", |
|
748 |
rb); |
|
749 |
||
750 |
} |
|
751 |
||
752 |
// Bulk puts from read-only buffers |
|
753 |
||
754 |
b.clear(); |
|
755 |
rb.rewind(); |
|
756 |
b.put(rb); |
|
757 |
||
758 |
||
759 |
||
760 |
||
761 |
||
762 |
||
763 |
||
764 |
||
765 |
||
766 |
||
767 |
||
768 |
relPut(b); // Required by testViews |
|
769 |
||
770 |
} |
|
771 |
||
772 |
||
773 |
||
774 |
||
775 |
||
776 |
||
777 |
||
778 |
||
779 |
||
780 |
||
781 |
||
782 |
||
783 |
||
784 |
||
785 |
||
786 |
||
787 |
||
788 |
||
789 |
||
790 |
||
791 |
||
792 |
||
793 |
||
794 |
||
795 |
||
796 |
||
797 |
||
798 |
||
799 |
||
800 |
||
801 |
||
802 |
||
803 |
||
804 |
||
805 |
||
806 |
||
807 |
||
808 |
||
809 |
||
810 |
||
811 |
||
812 |
||
813 |
||
814 |
||
815 |
||
816 |
||
817 |
||
818 |
||
819 |
||
820 |
||
821 |
||
822 |
||
823 |
||
824 |
||
825 |
||
826 |
||
827 |
||
828 |
||
829 |
||
830 |
||
831 |
||
832 |
||
833 |
||
834 |
||
835 |
||
836 |
||
837 |
||
838 |
||
839 |
||
840 |
||
841 |
||
842 |
||
843 |
||
844 |
||
845 |
||
846 |
||
847 |
||
848 |
||
849 |
||
850 |
||
851 |
||
852 |
||
853 |
||
2593
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
854 |
|
76032557be03
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents:
1639
diff
changeset
|
855 |
|
2 | 856 |
public static void test(final double [] ba) { |
857 |
int offset = 47; |
|
858 |
int length = 900; |
|
859 |
final DoubleBuffer b = DoubleBuffer.wrap(ba, offset, length); |
|
860 |
show(0, b); |
|
861 |
ck(b, b.capacity(), ba.length); |
|
862 |
ck(b, b.position(), offset); |
|
863 |
ck(b, b.limit(), offset + length); |
|
864 |
||
865 |
// The offset must be non-negative and no larger than <array.length>. |
|
866 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
867 |
public void run() { |
|
868 |
DoubleBuffer.wrap(ba, -1, ba.length); |
|
869 |
}}); |
|
870 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
871 |
public void run() { |
|
872 |
DoubleBuffer.wrap(ba, ba.length + 1, ba.length); |
|
873 |
}}); |
|
874 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
875 |
public void run() { |
|
876 |
DoubleBuffer.wrap(ba, 0, -1); |
|
877 |
}}); |
|
878 |
tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { |
|
879 |
public void run() { |
|
880 |
DoubleBuffer.wrap(ba, 0, ba.length + 1); |
|
881 |
}}); |
|
882 |
||
883 |
// A NullPointerException will be thrown if the array is null. |
|
884 |
tryCatch(ba, NullPointerException.class, new Runnable() { |
|
885 |
public void run() { |
|
886 |
DoubleBuffer.wrap((double []) null, 0, 5); |
|
887 |
}}); |
|
888 |
tryCatch(ba, NullPointerException.class, new Runnable() { |
|
889 |
public void run() { |
|
890 |
DoubleBuffer.wrap((double []) null); |
|
891 |
}}); |
|
892 |
} |
|
893 |
||
894 |
private static void testAllocate() { |
|
895 |
// An IllegalArgumentException will be thrown for negative capacities. |
|
896 |
tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() { |
|
897 |
public void run() { |
|
898 |
DoubleBuffer.allocate(-1); |
|
899 |
}}); |
|
900 |
||
901 |
||
902 |
||
903 |
||
904 |
||
905 |
||
906 |
} |
|
907 |
||
908 |
public static void test() { |
|
909 |
testAllocate(); |
|
910 |
test(0, DoubleBuffer.allocate(7 * 1024), false); |
|
911 |
test(0, DoubleBuffer.wrap(new double[7 * 1024], 0, 7 * 1024), false); |
|
912 |
test(new double[1024]); |
|
913 |
||
914 |
||
915 |
||
916 |
||
917 |
||
918 |
||
919 |
||
920 |
||
921 |
||
922 |
||
923 |
callReset(DoubleBuffer.allocate(10)); |
|
924 |
||
925 |
||
926 |
||
927 |
putBuffer(); |
|
928 |
||
929 |
} |
|
930 |
||
931 |
} |