use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ByteBufferTest method testPutByteBuffer.
/*
* Class under test for java.nio.ByteBuffer put(java.nio.ByteBuffer)
*/
public void testPutByteBuffer() {
ByteBuffer other = ByteBuffer.allocate(buf.capacity());
if (buf.isReadOnly()) {
try {
buf.clear();
buf.put(other);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.clear();
buf.put((ByteBuffer) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (ReadOnlyBufferException e) {
// expected
}
return;
}
try {
buf.put(buf);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IllegalArgumentException e) {
// expected
}
try {
buf.put(ByteBuffer.allocate(buf.capacity() + 1));
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
try {
buf.put((ByteBuffer) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
loadTestData2(other);
other.clear();
buf.clear();
ByteBuffer ret = buf.put(other);
assertEquals(other.position(), other.capacity());
assertEquals(buf.position(), buf.capacity());
assertContentEquals(other, buf);
assertSame(ret, buf);
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ByteBufferTest method testPutbyte.
/*
* Class under test for java.nio.ByteBuffer put(byte)
*/
public void testPutbyte() {
if (buf.isReadOnly()) {
try {
buf.clear();
buf.put((byte) 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (ReadOnlyBufferException e) {
// expected
}
return;
}
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
ByteBuffer ret = buf.put((byte) i);
assertEquals(buf.get(i), (byte) i);
assertSame(ret, buf);
}
try {
buf.put((byte) 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ByteBufferTest method testCompact.
public void testCompact() {
if (buf.isReadOnly()) {
try {
buf.compact();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (ReadOnlyBufferException e) {
// expected
}
return;
}
// case: buffer is full
buf.clear();
buf.mark();
loadTestData1(buf);
ByteBuffer ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), buf.capacity());
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (byte) 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, (byte) 0, buf.capacity());
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: normal
assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
buf.position(1);
buf.limit(SMALL_TEST_LENGTH);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 4);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (byte) 1, 4);
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class CharBufferTest method testReadOnlyMap.
public void testReadOnlyMap() throws IOException {
CharBuffer cb = CharBuffer.wrap("ABCDE").asReadOnlyBuffer();
CharSequence cs = "String";
try {
cb.append('A');
fail("should throw ReadOnlyBufferException.");
} catch (ReadOnlyBufferException ex) {
// expected;
}
try {
cb.append(cs);
fail("should throw ReadOnlyBufferException.");
} catch (ReadOnlyBufferException ex) {
// expected;
}
try {
cb.append(cs, 1, 2);
fail("should throw ReadOnlyBufferException.");
} catch (ReadOnlyBufferException ex) {
// expected;
}
cb.append(cs, 1, 1);
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ReadOnlyCharBufferTest method testPutCharBuffer.
public void testPutCharBuffer() {
CharBuffer other = CharBuffer.allocate(1);
try {
buf.put(other);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put((CharBuffer) null);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put(buf);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
}
Aggregations