Search in sources :

Example 21 with ReadOnlyBufferException

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");
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) SSLEngine(javax.net.ssl.SSLEngine) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ReadOnlyBufferException(java.nio.ReadOnlyBufferException) KnownFailure(dalvik.annotation.KnownFailure)

Example 22 with 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");
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) SSLEngine(javax.net.ssl.SSLEngine) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ReadOnlyBufferException(java.nio.ReadOnlyBufferException) KnownFailure(dalvik.annotation.KnownFailure)

Example 23 with 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) {
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) CharBuffer(java.nio.CharBuffer)

Example 24 with ReadOnlyBufferException

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
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) ByteBuffer(java.nio.ByteBuffer)

Example 25 with ReadOnlyBufferException

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);
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ReadOnlyBufferException (java.nio.ReadOnlyBufferException)35 ByteBuffer (java.nio.ByteBuffer)22 SSLException (javax.net.ssl.SSLException)10 IOException (java.io.IOException)7 SSLEngineResult (javax.net.ssl.SSLEngineResult)7 SSLEngine (javax.net.ssl.SSLEngine)6 BufferOverflowException (java.nio.BufferOverflowException)5 KeyManagementException (java.security.KeyManagementException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 CharBuffer (java.nio.CharBuffer)4 KnownFailure (dalvik.annotation.KnownFailure)3 BufferUnderflowException (java.nio.BufferUnderflowException)3 ByteBuf (io.netty.buffer.ByteBuf)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 Cipher (javax.crypto.Cipher)2 ShortBufferException (javax.crypto.ShortBufferException)2 IvParameterSpec (javax.crypto.spec.IvParameterSpec)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2