use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class SSLEngineTest method test_unwrap_ByteBuffer_ByteBuffer_02.
/**
* javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
* ReadOnlyBufferException should be thrown.
*/
@KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_ByteBuffer_ByteBuffer_02() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(100).asReadOnlyBuffer();
SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
sse.unwrap(bbs, bbd);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
} catch (Exception e) {
fail(e + " was thrown instead of ReadOnlyBufferException");
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class SSLEngineTest method test_unwrap_03.
/**
* javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
* int offset, int length)
* Exception case: ReadOnlyBufferException should be thrown.
*/
@KnownFailure("Fixed on DonutBurger, Wrong Exception thrown")
public void test_unwrap_03() {
String host = "new host";
int port = 8080;
ByteBuffer bbR = ByteBuffer.allocate(100).asReadOnlyBuffer();
ByteBuffer[] bbA = { bbR, ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
ByteBuffer bb = ByteBuffer.allocate(10);
SSLEngine sse = getEngine(host, port);
sse.setUseClientMode(true);
try {
sse.unwrap(bb, bbA, 0, bbA.length);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
} catch (Exception e) {
fail(e + " was thrown instead of ReadOnlyBufferException");
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class WrappedCharBufferTest2 method testPutCharBuffer.
public void testPutCharBuffer() {
CharBuffer other = CharBuffer.allocate(1);
try {
buf.put(other);
fail();
} catch (ReadOnlyBufferException expected) {
}
try {
buf.put((CharBuffer) null);
fail();
} catch (ReadOnlyBufferException expected) {
} catch (NullPointerException expected) {
}
try {
buf.put(buf);
fail();
} catch (ReadOnlyBufferException expected) {
} catch (IllegalArgumentException expected) {
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ByteBufferTest method testPutintbyte.
/*
* Class under test for java.nio.ByteBuffer put(int, byte)
*/
public void testPutintbyte() {
if (buf.isReadOnly()) {
try {
buf.put(0, (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(), 0);
ByteBuffer ret = buf.put(i, (byte) i);
assertEquals(buf.get(i), (byte) i);
assertSame(ret, buf);
}
try {
buf.put(-1, (byte) 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(buf.limit(), (byte) 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ByteBufferTest method testPutbyteArrayintint.
/*
* Class under test for java.nio.ByteBuffer put(byte[], int, int)
*/
public void testPutbyteArrayintint() {
buf.clear();
byte[] array = new byte[buf.capacity()];
if (buf.isReadOnly()) {
try {
buf.put(array, 0, array.length);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (ReadOnlyBufferException e) {
// expected
}
return;
}
try {
buf.put(new byte[buf.capacity() + 1], 0, buf.capacity() + 1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
assertEquals(buf.position(), 0);
try {
buf.put(array, -1, array.length);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, array.length + 1, 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
buf.put(array, array.length, 0);
assertEquals(buf.position(), 0);
try {
buf.put(array, 0, -1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, 2, array.length);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, 2, Integer.MAX_VALUE);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, Integer.MAX_VALUE, 1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put((byte[]) null, 2, Integer.MAX_VALUE);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
assertEquals(buf.position(), 0);
loadTestData2(array, 0, array.length);
ByteBuffer ret = buf.put(array, 0, array.length);
assertEquals(buf.position(), buf.capacity());
assertContentEquals(buf, array, 0, array.length);
assertSame(ret, buf);
}
Aggregations