Search in sources :

Example 61 with BufferOverflowException

use of java.nio.BufferOverflowException in project robovm by robovm.

the class LongBufferTest method testPutlongArrayintint.

/*
     * Class under test for java.nio.LongBuffer put(long[], int, int)
     */
public void testPutlongArrayintint() {
    buf.clear();
    long[] array = new long[buf.capacity()];
    try {
        buf.put(new long[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((long[]) null, 0, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        buf.put(array, 2, array.length);
        //$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(array, 1, Integer.MAX_VALUE);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    assertEquals(buf.position(), 0);
    loadTestData2(array, 0, array.length);
    LongBuffer ret = buf.put(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
}
Also used : LongBuffer(java.nio.LongBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 62 with BufferOverflowException

use of java.nio.BufferOverflowException in project robovm by robovm.

the class ShortBufferTest method testPutshort.

/*
     * Class under test for java.nio.ShortBuffer put(short)
     */
public void testPutshort() {
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        ShortBuffer ret = buf.put((short) i);
        assertEquals(buf.get(i), (short) i);
        assertSame(ret, buf);
    }
    try {
        buf.put((short) 0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
}
Also used : BufferOverflowException(java.nio.BufferOverflowException) ShortBuffer(java.nio.ShortBuffer)

Example 63 with BufferOverflowException

use of java.nio.BufferOverflowException in project robovm by robovm.

the class ShortBufferTest method testPutShortBuffer.

/*
     * Class under test for java.nio.ShortBuffer put(java.nio.ShortBuffer)
     */
public void testPutShortBuffer() {
    ShortBuffer other = ShortBuffer.allocate(buf.capacity());
    try {
        buf.put(buf);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        buf.put(ShortBuffer.allocate(buf.capacity() + 1));
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
    try {
        buf.flip();
        buf.put((ShortBuffer) null);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    loadTestData2(other);
    other.clear();
    buf.clear();
    ShortBuffer ret = buf.put(other);
    assertEquals(other.position(), other.capacity());
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(other, buf);
    assertSame(ret, buf);
}
Also used : BufferOverflowException(java.nio.BufferOverflowException) ShortBuffer(java.nio.ShortBuffer)

Example 64 with BufferOverflowException

use of java.nio.BufferOverflowException 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)

Example 65 with BufferOverflowException

use of java.nio.BufferOverflowException in project robovm by robovm.

the class CharBufferTest method testPutcharArrayintint.

/*
	 * Class under test for java.nio.CharBuffer put(char[], int, int)
	 */
public void testPutcharArrayintint() {
    buf.clear();
    char[] array = new char[buf.capacity()];
    try {
        buf.put((char[]) null, 0, 1);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        buf.put(new char[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((char[]) null, 0, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        buf.put(array, 2, array.length);
        //$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(array, 1, Integer.MAX_VALUE);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    assertEquals(buf.position(), 0);
    loadTestData2(array, 0, array.length);
    CharBuffer ret = buf.put(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
}
Also used : CharBuffer(java.nio.CharBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Aggregations

BufferOverflowException (java.nio.BufferOverflowException)78 ByteBuffer (java.nio.ByteBuffer)27 ShortBufferException (javax.crypto.ShortBufferException)10 CharBuffer (java.nio.CharBuffer)9 ShortBuffer (java.nio.ShortBuffer)7 Test (org.junit.Test)7 FloatBuffer (java.nio.FloatBuffer)6 IntBuffer (java.nio.IntBuffer)6 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 IpPrefix (android.net.IpPrefix)4 Inet6Address (java.net.Inet6Address)4 DoubleBuffer (java.nio.DoubleBuffer)4 LongBuffer (java.nio.LongBuffer)4 MappedByteBuffer (java.nio.MappedByteBuffer)4 Pointer (com.cetsoft.imcache.offheap.bytebuffer.Pointer)2 EOFException (java.io.EOFException)2 CoderResult (java.nio.charset.CoderResult)2 JSONObject (org.json_voltpatches.JSONObject)2