use of java.nio.InvalidMarkException in project j2objc by google.
the class FloatBufferTest method testCompact.
public void testCompact() {
// case: buffer is full
buf.clear();
buf.mark();
loadTestData1(buf);
FloatBuffer ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), buf.capacity());
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0.0f, 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.0f, 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.0f, 4);
try {
buf.reset();
// $NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
}
use of java.nio.InvalidMarkException in project j2objc by google.
the class ShortBufferTest method testSlice.
public void testSlice() {
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(buf.capacity() - 1);
ShortBuffer 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
}
// slice share the same content with buf
if (!slice.isReadOnly()) {
loadTestData1(slice);
assertContentLikeTestData1(buf, 1, (short) 0, slice.capacity());
buf.put(2, (short) 500);
assertEquals(slice.get(1), 500);
}
}
use of java.nio.InvalidMarkException in project j2objc by google.
the class ByteBufferTest method checkAllocateDirect.
private void checkAllocateDirect(int capacity) {
ByteBuffer b = ByteBuffer.allocateDirect(capacity);
assertEquals(capacity, b.capacity());
assertEquals(0, b.position());
assertEquals(capacity, b.limit());
assertContentEquals(b, new byte[capacity], 0, capacity);
try {
b.reset();
fail();
} catch (InvalidMarkException expected) {
}
}
use of java.nio.InvalidMarkException in project j2objc by google.
the class ByteBufferTest method testSlice.
public void testSlice() {
assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
buf.position(1);
buf.limit(buf.capacity() - 1);
ByteBuffer 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();
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// slice share the same content with buf
if (!slice.isReadOnly()) {
loadTestData1(slice);
assertContentLikeTestData1(buf, 1, (byte) 0, slice.capacity());
buf.put(2, (byte) 100);
assertEquals(slice.get(1), 100);
}
}
use of java.nio.InvalidMarkException in project robovm by robovm.
the class AbstractBufferTest method testReset.
public void testReset() {
// save state
int oldPosition = baseBuf.position();
int oldLimit = baseBuf.limit();
baseBuf.mark();
baseBuf.position(baseBuf.limit());
baseBuf.reset();
assertEquals(baseBuf.position(), oldPosition);
baseBuf.mark();
baseBuf.position(baseBuf.limit());
baseBuf.reset();
assertEquals(baseBuf.position(), oldPosition);
Buffer ret = baseBuf.reset();
assertSame(ret, baseBuf);
baseBuf.clear();
try {
baseBuf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// restore state
baseBuf.limit(oldLimit);
baseBuf.position(oldPosition);
}
Aggregations