use of java.nio.DoubleBuffer in project j2objc by google.
the class DoubleBufferTest method testSlice.
public void testSlice() {
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(buf.capacity() - 1);
DoubleBuffer slice = buf.slice();
assertEquals(buf.isReadOnly(), slice.isReadOnly());
assertEquals(buf.isDirect(), slice.isDirect());
assertEquals(buf.order(), slice.order());
assertEquals(slice.position(), 0);
assertEquals(slice.limit(), buf.remaining());
assertEquals(slice.capacity(), buf.remaining());
try {
slice.reset();
// $NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// FIXME:
if (!slice.isReadOnly()) {
loadTestData1(slice);
assertContentLikeTestData1(buf, 1, 0, slice.capacity());
buf.put(2, 500);
assertEquals(slice.get(1), 500, 0.0);
}
}
use of java.nio.DoubleBuffer in project j2objc by google.
the class DoubleBufferTest method testCompact.
public void testCompact() {
// case: buffer is full
buf.clear();
buf.mark();
loadTestData1(buf);
DoubleBuffer ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), buf.capacity());
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
try {
buf.reset();
// $NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: buffer is empty
buf.position(0);
buf.limit(0);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 0);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
try {
buf.reset();
// $NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: normal
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(5);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 4);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 1.0, 4);
try {
buf.reset();
// $NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
}
use of java.nio.DoubleBuffer in project j2objc by google.
the class DoubleBufferTest method testPutdoubleArray.
/*
* Class under test for java.nio.DoubleBuffer put(double[])
*/
public void testPutdoubleArray() {
double[] array = new double[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
array[0] = (double) i;
DoubleBuffer ret = buf.put(array);
assertEquals(buf.get(i), (double) i, 0.0);
assertSame(ret, buf);
}
try {
buf.put(array);
// $NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
}
use of java.nio.DoubleBuffer in project j2objc by google.
the class BufferTest method testBuffersIndependentLimit.
private void testBuffersIndependentLimit(ByteBuffer b) {
CharBuffer c = b.asCharBuffer();
b.limit(b.capacity());
c.put(1, (char) 1);
b.limit(0);
c.put(1, (char) 1);
b.limit(b.capacity());
ShortBuffer s = b.asShortBuffer();
b.limit(b.capacity());
s.put(1, (short) 1);
b.limit(0);
s.put(1, (short) 1);
b.limit(b.capacity());
IntBuffer i = b.asIntBuffer();
i.put(1, (int) 1);
b.limit(0);
i.put(1, (int) 1);
b.limit(b.capacity());
LongBuffer l = b.asLongBuffer();
l.put(1, (long) 1);
b.limit(0);
l.put(1, (long) 1);
b.limit(b.capacity());
FloatBuffer f = b.asFloatBuffer();
f.put(1, (float) 1);
b.limit(0);
f.put(1, (float) 1);
b.limit(b.capacity());
DoubleBuffer d = b.asDoubleBuffer();
d.put(1, (double) 1);
b.limit(0);
d.put(1, (double) 1);
}
use of java.nio.DoubleBuffer in project jna by java-native-access.
the class PointerBufferTest method testDoubleBufferPut.
public void testDoubleBufferPut() {
final double MAGIC = 1234.5678;
Memory m = new Memory(8);
ByteBuffer buf = m.getByteBuffer(0, m.size()).order(ByteOrder.nativeOrder());
DoubleBuffer db = buf.asDoubleBuffer();
db.put(MAGIC).flip();
assertEquals("Int not written to memory", MAGIC, m.getDouble(0), 0d);
}
Aggregations