Cross Reference: Basic-X.java.template
xref
: /
openjdk7
/
jdk
/
test
/
java
/
nio
/
Buffer
/
Basic-X.java.template
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
0
N/A
/*
2362
N/A
* Copyright (c) 2000, 2008, Oracle
and
/
or
its affiliates. All rights reserved.
0
N/A
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0
N/A
*
0
N/A
* This code is free software; you can redistribute it
and
/
or
modify it
0
N/A
* under the terms of the GNU General Public License version 2 only, as
0
N/A
* published by the Free Software Foundation.
0
N/A
*
0
N/A
* This code is distributed in the hope that it will be useful, but WITHOUT
0
N/A
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0
N/A
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0
N/A
* version 2 for more details (a copy is included in the LICENSE file that
0
N/A
* accompanied this code).
0
N/A
*
0
N/A
* You should have received a copy of the GNU General Public License version
0
N/A
* 2 along with this work; if not, write to the Free Software Foundation,
0
N/A
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0
N/A
*
2362
N/A
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362
N/A
* or visit www.oracle.com if you need additional information or have any
2362
N/A
* questions.
0
N/A
*/
0
N/A
0
N/A
/* Type-specific source code for unit test
0
N/A
*
0
N/A
* Regenerate the BasicX classes via genBasic.sh whenever this file changes.
0
N/A
* We check in the generated source files so that the test tree can be used
0
N/A
* independently of the rest of the source tree.
0
N/A
*/
0
N/A
0
N/A
#
warn
This
file
is
preprocessed
before
being
compiled
0
N/A
0
N/A
import
java
.
nio
.*;
721
N/A
import
java
.
lang
.
reflect
.
Method
;
0
N/A
0
N/A
0
N/A
public
class
Basic
$
Type
$
0
N/A
extends
Basic
0
N/A
{
0
N/A
2005
N/A
private
static
final
$
type
$[]
VALUES
= {
2005
N/A
$
Fulltype
$.
MIN_VALUE
,
2005
N/A
($
type
$) -
1
,
2005
N/A
($
type
$)
0
,
2005
N/A
($
type
$)
1
,
2005
N/A
$
Fulltype
$.
MAX_VALUE
,
2005
N/A
#
if
[
float
]
2005
N/A
$
Fulltype
$.
NEGATIVE_INFINITY
,
2005
N/A
$
Fulltype
$.
POSITIVE_INFINITY
,
2005
N/A
$
Fulltype
$.
NaN
,
2005
N/A
($
type
$) -
0.0
,
2005
N/A
#
end
[
float
]
2005
N/A
#
if
[
double
]
2005
N/A
$
Fulltype
$.
NEGATIVE_INFINITY
,
2005
N/A
$
Fulltype
$.
POSITIVE_INFINITY
,
2005
N/A
$
Fulltype
$.
NaN
,
2005
N/A
($
type
$) -
0.0
,
2005
N/A
#
end
[
double
]
2005
N/A
};
2005
N/A
0
N/A
private
static
void
relGet
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
$
type
$ v;
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, (
long
)b.
get
(), (
long
)(($
type
$)
ic
(i)));
0
N/A
b.
rewind
();
0
N/A
}
0
N/A
0
N/A
private
static
void
relGet
($
Type
$
Buffer
b,
int
start
) {
0
N/A
int
n = b.
remaining
();
0
N/A
$
type
$ v;
0
N/A
for
(
int
i =
start
; i < n; i++)
0
N/A
ck
(b, (
long
)b.
get
(), (
long
)(($
type
$)
ic
(i)));
0
N/A
b.
rewind
();
0
N/A
}
0
N/A
0
N/A
private
static
void
absGet
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
$
type
$ v;
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, (
long
)b.
get
(), (
long
)(($
type
$)
ic
(i)));
0
N/A
b.
rewind
();
0
N/A
}
0
N/A
0
N/A
private
static
void
bulkGet
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
$
type
$[] a =
new
$
type
$[n +
7
];
0
N/A
b.
get
(a,
7
, n);
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, (
long
)a[i +
7
], (
long
)(($
type
$)
ic
(i)));
0
N/A
}
0
N/A
0
N/A
private
static
void
relPut
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
b.
put
(($
type
$)
ic
(i));
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
private
static
void
absPut
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
b.
put
(i, ($
type
$)
ic
(i));
0
N/A
b.
limit
(n);
0
N/A
b.
position
(
0
);
0
N/A
}
0
N/A
0
N/A
private
static
void
bulkPutArray
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
$
type
$[] a =
new
$
type
$[n +
7
];
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
a[i +
7
] = ($
type
$)
ic
(i);
0
N/A
b.
put
(a,
7
, n);
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
private
static
void
bulkPutBuffer
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
$
Type
$
Buffer
c = $
Type
$
Buffer
.
allocate
(n +
7
);
0
N/A
c.
position
(
7
);
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
c.
put
(($
type
$)
ic
(i));
0
N/A
c.
flip
();
0
N/A
c.
position
(
7
);
0
N/A
b.
put
(c);
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
//6231529
0
N/A
private
static
void
callReset
($
Type
$
Buffer
b) {
0
N/A
b.
position
(
0
);
0
N/A
b.
mark
();
0
N/A
0
N/A
b.
duplicate
().
reset
();
0
N/A
b.
asReadOnlyBuffer
().
reset
();
0
N/A
}
0
N/A
0
N/A
#
if
[
byte
]
0
N/A
#
else
[
byte
]
0
N/A
// 6221101-6234263
0
N/A
0
N/A
private
static
void
putBuffer
() {
0
N/A
final
int
cap
=
10
;
0
N/A
0
N/A
$
Type
$
Buffer
direct1
=
ByteBuffer
.
allocateDirect
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
$
Type
$
Buffer
nondirect1
=
ByteBuffer
.
allocate
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
direct1
.
put
(
nondirect1
);
0
N/A
0
N/A
$
Type
$
Buffer
direct2
=
ByteBuffer
.
allocateDirect
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
$
Type
$
Buffer
nondirect2
=
ByteBuffer
.
allocate
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
nondirect2
.
put
(
direct2
);
0
N/A
0
N/A
$
Type
$
Buffer
direct3
=
ByteBuffer
.
allocateDirect
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
$
Type
$
Buffer
direct4
=
ByteBuffer
.
allocateDirect
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
direct3
.
put
(
direct4
);
0
N/A
0
N/A
$
Type
$
Buffer
nondirect3
=
ByteBuffer
.
allocate
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
$
Type
$
Buffer
nondirect4
=
ByteBuffer
.
allocate
(
cap
).
as
$
Type
$
Buffer
();
0
N/A
nondirect3
.
put
(
nondirect4
);
0
N/A
}
0
N/A
#
end
[
byte
]
0
N/A
0
N/A
#
if
[
char
]
0
N/A
0
N/A
private
static
void
bulkPutString
($
Type
$
Buffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
StringBuffer
sb
=
new
StringBuffer
(n +
7
);
0
N/A
sb
.
append
(
"1234567"
);
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
sb
.
append
((
char
)
ic
(i));
0
N/A
b.
put
(
sb
.
toString
(),
7
,
7
+ n);
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
#
end
[
char
]
0
N/A
0
N/A
private
static
void
checkSlice
($
Type
$
Buffer
b, $
Type
$
Buffer
slice
) {
0
N/A
ck
(
slice
,
0
,
slice
.
position
());
0
N/A
ck
(
slice
, b.
remaining
(),
slice
.
limit
());
0
N/A
ck
(
slice
, b.
remaining
(),
slice
.
capacity
());
0
N/A
if
(b.
isDirect
() !=
slice
.
isDirect
())
0
N/A
fail
(
"Lost direction"
,
slice
);
0
N/A
if
(b.
isReadOnly
() !=
slice
.
isReadOnly
())
0
N/A
fail
(
"Lost read-only"
,
slice
);
0
N/A
}
0
N/A
0
N/A
#
if
[
byte
]
0
N/A
0
N/A
private
static
void
checkBytes
(
ByteBuffer
b,
byte
[]
bs
) {
0
N/A
int
n =
bs
.
length
;
0
N/A
int
p = b.
position
();
0
N/A
byte
v;
0
N/A
if
(b.
order
() ==
ByteOrder
.
BIG_ENDIAN
) {
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, b.
get
(),
bs
[i]);
0
N/A
}
else
{
0
N/A
for
(
int
i = n -
1
; i >=
0
; i--)
0
N/A
ck
(b, b.
get
(),
bs
[i]);
0
N/A
}
0
N/A
b.
position
(p);
0
N/A
}
0
N/A
721
N/A
private
static
void
compact
(
Buffer
b) {
721
N/A
try
{
721
N/A
Class
<?>
cl
= b.
getClass
();
721
N/A
Method
m =
cl
.
getDeclaredMethod
(
"compact"
);
721
N/A
m.
setAccessible
(
true
);
721
N/A
m.
invoke
(b);
721
N/A
}
catch
(
Exception
e) {
721
N/A
fail
(e.
getMessage
(), b);
721
N/A
}
721
N/A
}
721
N/A
721
N/A
private
static
void
checkInvalidMarkException
(
final
Buffer
b) {
721
N/A
tryCatch
(b,
InvalidMarkException
.
class
,
new
Runnable
() {
721
N/A
public
void
run
() {
721
N/A
b.
mark
();
721
N/A
compact
(b);
721
N/A
b.
reset
();
721
N/A
}});
721
N/A
}
721
N/A
0
N/A
private
static
void
testViews
(
int
level
,
ByteBuffer
b,
boolean
direct
) {
0
N/A
0
N/A
ShortBuffer
sb
= b.
asShortBuffer
();
0
N/A
BasicShort
.
test
(
level
,
sb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
sb
);
0
N/A
0
N/A
CharBuffer
cb
= b.
asCharBuffer
();
0
N/A
BasicChar
.
test
(
level
,
cb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
cb
);
0
N/A
0
N/A
IntBuffer
ib
= b.
asIntBuffer
();
0
N/A
BasicInt
.
test
(
level
,
ib
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
,
0
,
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
ib
);
0
N/A
0
N/A
LongBuffer
lb
= b.
asLongBuffer
();
0
N/A
BasicLong
.
test
(
level
,
lb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
,
0
,
0
,
0
,
0
,
0
,
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
lb
);
0
N/A
0
N/A
FloatBuffer
fb
= b.
asFloatBuffer
();
0
N/A
BasicFloat
.
test
(
level
,
fb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0x42
, (
byte
)
0xc2
,
0
,
0
});
721
N/A
checkInvalidMarkException
(
fb
);
0
N/A
0
N/A
DoubleBuffer
db
= b.
asDoubleBuffer
();
0
N/A
BasicDouble
.
test
(
level
,
db
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0x40
,
0x58
,
0x40
,
0
,
0
,
0
,
0
,
0
});
721
N/A
checkInvalidMarkException
(
db
);
0
N/A
}
0
N/A
0
N/A
private
static
void
testHet
(
int
level
,
ByteBuffer
b) {
0
N/A
0
N/A
int
p = b.
position
();
0
N/A
b.
limit
(b.
capacity
());
0
N/A
show
(
level
, b);
0
N/A
out
.
print
(
" put:"
);
0
N/A
0
N/A
b.
putChar
((
char
)
1
);
0
N/A
b.
putChar
((
char
)
Character
.
MAX_VALUE
);
0
N/A
out
.
print
(
" char"
);
0
N/A
0
N/A
b.
putShort
((
short
)
1
);
0
N/A
b.
putShort
((
short
)
Short
.
MAX_VALUE
);
0
N/A
out
.
print
(
" short"
);
0
N/A
0
N/A
b.
putInt
(
1
);
0
N/A
b.
putInt
(
Integer
.
MAX_VALUE
);
0
N/A
out
.
print
(
" int"
);
0
N/A
0
N/A
b.
putLong
((
long
)
1
);
0
N/A
b.
putLong
((
long
)
Long
.
MAX_VALUE
);
0
N/A
out
.
print
(
" long"
);
0
N/A
0
N/A
b.
putFloat
((
float
)
1
);
0
N/A
b.
putFloat
((
float
)
Float
.
MIN_VALUE
);
0
N/A
b.
putFloat
((
float
)
Float
.
MAX_VALUE
);
0
N/A
out
.
print
(
" float"
);
0
N/A
0
N/A
b.
putDouble
((
double
)
1
);
0
N/A
b.
putDouble
((
double
)
Double
.
MIN_VALUE
);
0
N/A
b.
putDouble
((
double
)
Double
.
MAX_VALUE
);
0
N/A
out
.
print
(
" double"
);
0
N/A
0
N/A
out
.
println
();
0
N/A
b.
limit
(b.
position
());
0
N/A
b.
position
(p);
0
N/A
show
(
level
, b);
0
N/A
out
.
print
(
" get:"
);
0
N/A
0
N/A
ck
(b, b.
getChar
(),
1
);
0
N/A
ck
(b, b.
getChar
(),
Character
.
MAX_VALUE
);
0
N/A
out
.
print
(
" char"
);
0
N/A
0
N/A
ck
(b, b.
getShort
(),
1
);
0
N/A
ck
(b, b.
getShort
(),
Short
.
MAX_VALUE
);
0
N/A
out
.
print
(
" short"
);
0
N/A
0
N/A
ck
(b, b.
getInt
(),
1
);
0
N/A
ck
(b, b.
getInt
(),
Integer
.
MAX_VALUE
);
0
N/A
out
.
print
(
" int"
);
0
N/A
0
N/A
ck
(b, b.
getLong
(),
1
);
0
N/A
ck
(b, b.
getLong
(),
Long
.
MAX_VALUE
);
0
N/A
out
.
print
(
" long"
);
0
N/A
0
N/A
ck
(b, (
long
)b.
getFloat
(),
1
);
0
N/A
ck
(b, (
long
)b.
getFloat
(), (
long
)
Float
.
MIN_VALUE
);
0
N/A
ck
(b, (
long
)b.
getFloat
(), (
long
)
Float
.
MAX_VALUE
);
0
N/A
out
.
print
(
" float"
);
0
N/A
0
N/A
ck
(b, (
long
)b.
getDouble
(),
1
);
0
N/A
ck
(b, (
long
)b.
getDouble
(), (
long
)
Double
.
MIN_VALUE
);
0
N/A
ck
(b, (
long
)b.
getDouble
(), (
long
)
Double
.
MAX_VALUE
);
0
N/A
out
.
print
(
" double"
);
0
N/A
0
N/A
out
.
println
();
0
N/A
0
N/A
}
0
N/A
0
N/A
#
end
[
byte
]
0
N/A
2005
N/A
private
static
void
fail
(
String
problem
,
2005
N/A
$
Type
$
Buffer
xb
, $
Type
$
Buffer
yb
,
2005
N/A
$
type
$ x, $
type
$ y) {
2005
N/A
fail
(
problem
+
String
.
format
(
": x=%s y=%s"
, x, y),
xb
,
yb
);
2005
N/A
}
2005
N/A
0
N/A
private
static
void
tryCatch
(
Buffer
b,
Class
ex
,
Runnable
thunk
) {
0
N/A
boolean
caught
=
false
;
0
N/A
try
{
0
N/A
thunk
.
run
();
0
N/A
}
catch
(
Throwable
x) {
721
N/A
if
(
ex
.
isAssignableFrom
(x.
getClass
())) {
0
N/A
caught
=
true
;
721
N/A
}
else
{
721
N/A
fail
(x.
getMessage
() +
" not expected"
);
721
N/A
}
0
N/A
}
0
N/A
if
(!
caught
)
0
N/A
fail
(
ex
.
getName
() +
" not thrown"
, b);
0
N/A
}
0
N/A
0
N/A
private
static
void
tryCatch
($
type
$ [] t,
Class
ex
,
Runnable
thunk
) {
0
N/A
tryCatch
($
Type
$
Buffer
.
wrap
(t),
ex
,
thunk
);
0
N/A
}
0
N/A
0
N/A
public
static
void
test
(
int
level
,
final
$
Type
$
Buffer
b,
boolean
direct
) {
0
N/A
0
N/A
show
(
level
, b);
0
N/A
0
N/A
if
(
direct
!= b.
isDirect
())
0
N/A
fail
(
"Wrong direction"
, b);
0
N/A
0
N/A
// Gets and puts
0
N/A
0
N/A
relPut
(b);
0
N/A
relGet
(b);
0
N/A
absGet
(b);
0
N/A
bulkGet
(b);
0
N/A
0
N/A
absPut
(b);
0
N/A
relGet
(b);
0
N/A
absGet
(b);
0
N/A
bulkGet
(b);
0
N/A
0
N/A
bulkPutArray
(b);
0
N/A
relGet
(b);
0
N/A
0
N/A
bulkPutBuffer
(b);
0
N/A
relGet
(b);
0
N/A
0
N/A
#
if
[
char
]
0
N/A
0
N/A
bulkPutString
(b);
0
N/A
relGet
(b);
0
N/A
b.
position
(
1
);
0
N/A
b.
limit
(
7
);
0
N/A
ck
(b, b.
toString
().
equals
(
"bcdefg"
));
0
N/A
0
N/A
// CharSequence ops
0
N/A
0
N/A
b.
position
(
2
);
0
N/A
ck
(b, b.
charAt
(
1
),
'd'
);
1108
N/A
CharBuffer
c = b.
subSequence
(
1
,
4
);
1108
N/A
ck
(c, c.
capacity
(), b.
capacity
());
1108
N/A
ck
(c, c.
position
(), b.
position
()+
1
);
1108
N/A
ck
(c, c.
limit
(), b.
position
()+
4
);
1108
N/A
ck
(c, b.
subSequence
(
1
,
4
).
toString
().
equals
(
"def"
));
0
N/A
0
N/A
// 4938424
0
N/A
b.
position
(
4
);
0
N/A
ck
(b, b.
charAt
(
1
),
'f'
);
0
N/A
ck
(b, b.
subSequence
(
1
,
3
).
toString
().
equals
(
"fg"
));
0
N/A
0
N/A
#
end
[
char
]
0
N/A
0
N/A
// Compact
0
N/A
0
N/A
relPut
(b);
0
N/A
b.
position
(
13
);
0
N/A
b.
compact
();
0
N/A
b.
flip
();
0
N/A
relGet
(b,
13
);
0
N/A
0
N/A
// Exceptions
0
N/A
0
N/A
relPut
(b);
0
N/A
b.
limit
(b.
capacity
() /
2
);
0
N/A
b.
position
(b.
limit
());
0
N/A
0
N/A
tryCatch
(b,
BufferUnderflowException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
();
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
BufferOverflowException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
put
(($
type
$)
42
);
0
N/A
}});
0
N/A
0
N/A
// The index must be non-negative and lesss than the buffer's limit.
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
(b.
limit
());
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
(-
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
put
(b.
limit
(), ($
type
$)
42
);
0
N/A
}});
0
N/A
721
N/A
tryCatch
(b,
InvalidMarkException
.
class
,
new
Runnable
() {
721
N/A
public
void
run
() {
721
N/A
b.
position
(
0
);
721
N/A
b.
mark
();
721
N/A
b.
compact
();
721
N/A
b.
reset
();
721
N/A
}});
721
N/A
0
N/A
// Values
0
N/A
0
N/A
b.
clear
();
0
N/A
b.
put
(($
type
$)
0
);
0
N/A
b.
put
(($
type
$)-
1
);
0
N/A
b.
put
(($
type
$)
1
);
0
N/A
b.
put
($
Fulltype
$.
MAX_VALUE
);
0
N/A
b.
put
($
Fulltype
$.
MIN_VALUE
);
0
N/A
#
if
[
float
]
0
N/A
b.
put
(-
Float
.
MAX_VALUE
);
0
N/A
b.
put
(-
Float
.
MIN_VALUE
);
0
N/A
b.
put
(
Float
.
NEGATIVE_INFINITY
);
0
N/A
b.
put
(
Float
.
POSITIVE_INFINITY
);
0
N/A
b.
put
(
Float
.
NaN
);
0
N/A
b.
put
(
0.91697687f
);
// Changes value if incorrectly swapped
0
N/A
#
end
[
float
]
0
N/A
#
if
[
double
]
0
N/A
b.
put
(-
Double
.
MAX_VALUE
);
0
N/A
b.
put
(-
Double
.
MIN_VALUE
);
0
N/A
b.
put
(
Double
.
NEGATIVE_INFINITY
);
0
N/A
b.
put
(
Double
.
POSITIVE_INFINITY
);
0
N/A
b.
put
(
Double
.
NaN
);
0
N/A
b.
put
(
0.5121609353879392
);
// Changes value if incorrectly swapped
0
N/A
#
end
[
double
]
0
N/A
0
N/A
$
type
$ v;
0
N/A
b.
flip
();
0
N/A
ck
(b, b.
get
(),
0
);
0
N/A
ck
(b, b.
get
(), ($
type
$)-
1
);
0
N/A
ck
(b, b.
get
(),
1
);
0
N/A
ck
(b, b.
get
(), $
Fulltype
$.
MAX_VALUE
);
0
N/A
ck
(b, b.
get
(), $
Fulltype
$.
MIN_VALUE
);
0
N/A
0
N/A
#
if
[
float
]
0
N/A
ck
(b, b.
get
(), -
Float
.
MAX_VALUE
);
0
N/A
ck
(b, b.
get
(), -
Float
.
MIN_VALUE
);
0
N/A
ck
(b, b.
get
(),
Float
.
NEGATIVE_INFINITY
);
0
N/A
ck
(b, b.
get
(),
Float
.
POSITIVE_INFINITY
);
0
N/A
if
(
Float
.
floatToRawIntBits
(v = b.
get
()) !=
Float
.
floatToRawIntBits
(
Float
.
NaN
))
0
N/A
fail
(b, (
long
)
Float
.
NaN
, (
long
)v);
0
N/A
ck
(b, b.
get
(),
0.91697687f
);
0
N/A
#
end
[
float
]
0
N/A
#
if
[
double
]
0
N/A
ck
(b, b.
get
(), -
Double
.
MAX_VALUE
);
0
N/A
ck
(b, b.
get
(), -
Double
.
MIN_VALUE
);
0
N/A
ck
(b, b.
get
(),
Double
.
NEGATIVE_INFINITY
);
0
N/A
ck
(b, b.
get
(),
Double
.
POSITIVE_INFINITY
);
0
N/A
if
(
Double
.
doubleToRawLongBits
(v = b.
get
())
0
N/A
!=
Double
.
doubleToRawLongBits
(
Double
.
NaN
))
0
N/A
fail
(b, (
long
)
Double
.
NaN
, (
long
)v);
0
N/A
ck
(b, b.
get
(),
0.5121609353879392
);
0
N/A
#
end
[
double
]
0
N/A
0
N/A
0
N/A
// Comparison
0
N/A
b.
rewind
();
0
N/A
$
Type
$
Buffer
b2
= $
Type
$
Buffer
.
allocate
(b.
capacity
());
0
N/A
b2
.
put
(b);
0
N/A
b2
.
flip
();
0
N/A
b.
position
(
2
);
0
N/A
b2
.
position
(
2
);
0
N/A
if
(!b.
equals
(
b2
)) {
0
N/A
for
(
int
i =
2
; i < b.
limit
(); i++) {
0
N/A
$
type
$ x = b.
get
(i);
0
N/A
$
type
$ y =
b2
.
get
(i);
0
N/A
if
(x != y
0
N/A
#
if
[
double
]
0
N/A
||
Double
.
compare
(x, y) !=
0
0
N/A
#
end
[
double
]
0
N/A
#
if
[
float
]
0
N/A
||
Float
.
compare
(x, y) !=
0
0
N/A
#
end
[
float
]
0
N/A
)
0
N/A
out
.
println
(
"["
+ i +
"] "
+ x +
" != "
+ y);
0
N/A
}
0
N/A
fail
(
"Identical buffers not equal"
, b,
b2
);
0
N/A
}
0
N/A
if
(b.
compareTo
(
b2
) !=
0
)
0
N/A
fail
(
"Comparison to identical buffer != 0"
, b,
b2
);
0
N/A
0
N/A
b.
limit
(b.
limit
() +
1
);
0
N/A
b.
position
(b.
limit
() -
1
);
0
N/A
b.
put
(($
type
$)
99
);
0
N/A
b.
rewind
();
0
N/A
b2
.
rewind
();
0
N/A
if
(b.
equals
(
b2
))
0
N/A
fail
(
"Non-identical buffers equal"
, b,
b2
);
0
N/A
if
(b.
compareTo
(
b2
) <=
0
)
0
N/A
fail
(
"Comparison to shorter buffer <= 0"
, b,
b2
);
0
N/A
b.
limit
(b.
limit
() -
1
);
0
N/A
0
N/A
b.
put
(
2
, ($
type
$)
42
);
0
N/A
if
(b.
equals
(
b2
))
0
N/A
fail
(
"Non-identical buffers equal"
, b,
b2
);
0
N/A
if
(b.
compareTo
(
b2
) <=
0
)
0
N/A
fail
(
"Comparison to lesser buffer <= 0"
, b,
b2
);
0
N/A
2005
N/A
// Check equals and compareTo with interesting values
2005
N/A
for
($
type
$ x :
VALUES
) {
2005
N/A
$
Type
$
Buffer
xb
= $
Type
$
Buffer
.
wrap
(
new
$
type
$[] { x });
2005
N/A
if
(
xb
.
compareTo
(
xb
) !=
0
) {
2005
N/A
fail
(
"compareTo not reflexive"
,
xb
,
xb
, x, x);
2005
N/A
}
2005
N/A
if
(!
xb
.
equals
(
xb
)) {
2005
N/A
fail
(
"equals not reflexive"
,
xb
,
xb
, x, x);
2005
N/A
}
2005
N/A
for
($
type
$ y :
VALUES
) {
2005
N/A
$
Type
$
Buffer
yb
= $
Type
$
Buffer
.
wrap
(
new
$
type
$[] { y });
2005
N/A
if
(
xb
.
compareTo
(
yb
) != -
yb
.
compareTo
(
xb
)) {
2005
N/A
fail
(
"compareTo not anti-symmetric"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
if
((
xb
.
compareTo
(
yb
) ==
0
) !=
xb
.
equals
(
yb
)) {
2005
N/A
fail
(
"compareTo inconsistent with equals"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
if
(
xb
.
compareTo
(
yb
) != $
Fulltype
$.
compare
(x, y)) {
2005
N/A
#
if
[
float
]
2005
N/A
if
(x ==
0.0
&& y ==
0.0
)
continue
;
2005
N/A
#
end
[
float
]
2005
N/A
#
if
[
double
]
2005
N/A
if
(x ==
0.0
&& y ==
0.0
)
continue
;
2005
N/A
#
end
[
double
]
2005
N/A
fail
(
"Incorrect results for $Type$Buffer.compareTo"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
if
(
xb
.
equals
(
yb
) != ((x == y) || ((x != x) && (y != y)))) {
2005
N/A
fail
(
"Incorrect results for $Type$Buffer.equals"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
}
2005
N/A
}
2005
N/A
0
N/A
// Sub, dup
0
N/A
0
N/A
relPut
(b);
0
N/A
relGet
(b.
duplicate
());
0
N/A
b.
position
(
13
);
0
N/A
relGet
(b.
duplicate
(),
13
);
0
N/A
relGet
(b.
duplicate
().
slice
(),
13
);
0
N/A
relGet
(b.
slice
(),
13
);
0
N/A
relGet
(b.
slice
().
duplicate
(),
13
);
0
N/A
0
N/A
// Slice
0
N/A
0
N/A
b.
position
(
5
);
0
N/A
$
Type
$
Buffer
sb
= b.
slice
();
0
N/A
checkSlice
(b,
sb
);
0
N/A
b.
position
(
0
);
0
N/A
$
Type
$
Buffer
sb2
=
sb
.
slice
();
0
N/A
checkSlice
(
sb
,
sb2
);
0
N/A
0
N/A
if
(!
sb
.
equals
(
sb2
))
0
N/A
fail
(
"Sliced slices do not match"
,
sb
,
sb2
);
0
N/A
if
((
sb
.
hasArray
()) && (
sb
.
arrayOffset
() !=
sb2
.
arrayOffset
()))
0
N/A
fail
(
"Array offsets do not match: "
0
N/A
+
sb
.
arrayOffset
() +
" != "
+
sb2
.
arrayOffset
(),
sb
,
sb2
);
0
N/A
0
N/A
#
if
[
byte
]
0
N/A
0
N/A
// Views
0
N/A
0
N/A
b.
clear
();
0
N/A
b.
order
(
ByteOrder
.
BIG_ENDIAN
);
0
N/A
testViews
(
level
+
1
, b,
direct
);
0
N/A
0
N/A
for
(
int
i =
1
; i <=
9
; i++) {
0
N/A
b.
position
(i);
0
N/A
show
(
level
+
1
, b);
0
N/A
testViews
(
level
+
2
, b,
direct
);
0
N/A
}
0
N/A
0
N/A
b.
position
(
0
);
0
N/A
b.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
0
N/A
testViews
(
level
+
1
, b,
direct
);
0
N/A
0
N/A
// Heterogeneous accessors
0
N/A
0
N/A
b.
order
(
ByteOrder
.
BIG_ENDIAN
);
0
N/A
for
(
int
i =
0
; i <=
9
; i++) {
0
N/A
b.
position
(i);
0
N/A
testHet
(
level
+
1
, b);
0
N/A
}
0
N/A
b.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
0
N/A
b.
position
(
3
);
0
N/A
testHet
(
level
+
1
, b);
0
N/A
0
N/A
#
end
[
byte
]
0
N/A
0
N/A
// Read-only views
0
N/A
0
N/A
b.
rewind
();
0
N/A
final
$
Type
$
Buffer
rb
= b.
asReadOnlyBuffer
();
0
N/A
if
(!b.
equals
(
rb
))
0
N/A
fail
(
"Buffer not equal to read-only view"
, b,
rb
);
0
N/A
show
(
level
+
1
,
rb
);
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
relPut
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
absPut
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
bulkPutArray
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
bulkPutBuffer
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
compact
();
0
N/A
}});
0
N/A
0
N/A
#
if
[
byte
]
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putChar
((
char
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putChar
(
0
, (
char
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putShort
((
short
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putShort
(
0
, (
short
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putInt
(
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putInt
(
0
,
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putLong
((
long
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putLong
(
0
, (
long
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putFloat
((
float
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putFloat
(
0
, (
float
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putDouble
((
double
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putDouble
(
0
, (
double
)
1
);
0
N/A
}});
0
N/A
0
N/A
#
end
[
byte
]
0
N/A
0
N/A
if
(
rb
.
getClass
().
getName
().
startsWith
(
"java.nio.Heap"
)) {
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
array
();
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
arrayOffset
();
0
N/A
}});
0
N/A
0
N/A
if
(
rb
.
hasArray
())
0
N/A
fail
(
"Read-only heap buffer's backing array is accessible"
,
0
N/A
rb
);
0
N/A
0
N/A
}
0
N/A
0
N/A
// Bulk puts from read-only buffers
0
N/A
0
N/A
b.
clear
();
0
N/A
rb
.
rewind
();
0
N/A
b.
put
(
rb
);
0
N/A
0
N/A
#
if
[
byte
]
0
N/A
// For byte buffers, test both the direct and non-direct cases
0
N/A
$
Type
$
Buffer
ob
0
N/A
= (b.
isDirect
()
0
N/A
? $
Type
$
Buffer
.
allocate
(
rb
.
capacity
())
0
N/A
: $
Type
$
Buffer
.
allocateDirect
(
rb
.
capacity
()));
0
N/A
rb
.
rewind
();
0
N/A
ob
.
put
(
rb
);
0
N/A
#
end
[
byte
]
0
N/A
0
N/A
relPut
(b);
// Required by testViews
0
N/A
0
N/A
}
0
N/A
0
N/A
#
if
[
char
]
0
N/A
0
N/A
private
static
void
testStr
() {
0
N/A
final
String
s =
"abcdefghijklm"
;
0
N/A
int
start
=
3
;
0
N/A
int
end
=
9
;
0
N/A
final
CharBuffer
b =
CharBuffer
.
wrap
(s,
start
,
end
);
0
N/A
show
(
0
, b);
0
N/A
ck
(b, b.
toString
().
equals
(s.
substring
(
start
,
end
)));
0
N/A
ck
(b, b.
toString
().
equals
(
"defghi"
));
0
N/A
ck
(b, b.
isReadOnly
());
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
put
(
'x'
);
0
N/A
}});
0
N/A
ck
(b,
start
, b.
position
());
0
N/A
ck
(b,
end
, b.
limit
());
0
N/A
ck
(b, s.
length
(), b.
capacity
());
1108
N/A
b.
position
(
6
);
1108
N/A
ck
(b, b.
subSequence
(
0
,
3
).
toString
().
equals
(
"ghi"
));
0
N/A
0
N/A
// The index, relative to the position, must be non-negative and
0
N/A
// smaller than remaining().
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
charAt
(-
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
charAt
(b.
remaining
());
0
N/A
}});
0
N/A
0
N/A
// The index must be non-negative and less than the buffer's limit.
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
(b.
limit
());
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
(-
1
);
0
N/A
}});
0
N/A
0
N/A
// The start must be non-negative and no larger than remaining().
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
subSequence
(-
1
, b.
remaining
());
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
subSequence
(b.
remaining
() +
1
, b.
remaining
());
0
N/A
}});
0
N/A
0
N/A
// The end must be no smaller than start and no larger than
0
N/A
// remaining().
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
subSequence
(
2
,
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
subSequence
(
0
, b.
remaining
() +
1
);
0
N/A
}});
0
N/A
0
N/A
// The offset must be non-negative and no larger than <array.length>.
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(s, -
1
, s.
length
());
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(s, s.
length
() +
1
, s.
length
());
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(s,
1
,
0
);
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(s,
0
, s.
length
() +
1
);
0
N/A
}});
0
N/A
}
0
N/A
0
N/A
#
end
[
char
]
0
N/A
0
N/A
public
static
void
test
(
final
$
type
$ []
ba
) {
0
N/A
int
offset
=
47
;
0
N/A
int
length
=
900
;
0
N/A
final
$
Type
$
Buffer
b = $
Type
$
Buffer
.
wrap
(
ba
,
offset
,
length
);
0
N/A
show
(
0
, b);
0
N/A
ck
(b, b.
capacity
(),
ba
.
length
);
0
N/A
ck
(b, b.
position
(),
offset
);
0
N/A
ck
(b, b.
limit
(),
offset
+
length
);
0
N/A
0
N/A
// The offset must be non-negative and no larger than <array.length>.
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(
ba
, -
1
,
ba
.
length
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(
ba
,
ba
.
length
+
1
,
ba
.
length
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(
ba
,
0
, -
1
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(
ba
,
0
,
ba
.
length
+
1
);
0
N/A
}});
0
N/A
0
N/A
// A NullPointerException will be thrown if the array is null.
0
N/A
tryCatch
(
ba
,
NullPointerException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(($
type
$ [])
null
,
0
,
5
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
NullPointerException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
wrap
(($
type
$ [])
null
);
0
N/A
}});
0
N/A
}
0
N/A
0
N/A
private
static
void
testAllocate
() {
0
N/A
// An IllegalArgumentException will be thrown for negative capacities.
0
N/A
tryCatch
((
Buffer
)
null
,
IllegalArgumentException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
allocate
(-
1
);
0
N/A
}});
0
N/A
#
if
[
byte
]
0
N/A
tryCatch
((
Buffer
)
null
,
IllegalArgumentException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
$
Type
$
Buffer
.
allocateDirect
(-
1
);
0
N/A
}});
0
N/A
#
end
[
byte
]
0
N/A
}
0
N/A
0
N/A
public
static
void
test
() {
0
N/A
testAllocate
();
0
N/A
test
(
0
, $
Type
$
Buffer
.
allocate
(
7
*
1024
),
false
);
0
N/A
test
(
0
, $
Type
$
Buffer
.
wrap
(
new
$
type
$[
7
*
1024
],
0
,
7
*
1024
),
false
);
0
N/A
test
(
new
$
type
$[
1024
]);
0
N/A
#
if
[
byte
]
0
N/A
$
Type
$
Buffer
b = $
Type
$
Buffer
.
allocateDirect
(
7
*
1024
);
0
N/A
for
(b.
position
(
0
); b.
position
() < b.
limit
(); )
0
N/A
ck
(b, b.
get
(),
0
);
0
N/A
test
(
0
, b,
true
);
0
N/A
#
end
[
byte
]
0
N/A
#
if
[
char
]
0
N/A
testStr
();
0
N/A
#
end
[
char
]
0
N/A
0
N/A
callReset
($
Type
$
Buffer
.
allocate
(
10
));
0
N/A
0
N/A
#
if
[
byte
]
0
N/A
#
else
[
byte
]
0
N/A
putBuffer
();
0
N/A
#
end
[
byte
]
0
N/A
}
0
N/A
0
N/A
}