Search in sources :

Example 71 with BufferOverflowException

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

the class FloatBufferTest method testPutfloatArray.

/*
     * Class under test for java.nio.FloatBuffer put(float[])
     */
public void testPutfloatArray() {
    float[] array = new float[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        array[0] = (float) i;
        FloatBuffer ret = buf.put(array);
        assertEquals(buf.get(i), (float) i, 0.0);
        assertSame(ret, buf);
    }
    try {
        buf.put(array);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
    try {
        buf.position(buf.limit());
        buf.put((float[]) null);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 72 with BufferOverflowException

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

the class CharBufferTest method testPutStringintint.

public void testPutStringintint() {
    buf.clear();
    String str = String.valueOf(new char[buf.capacity()]);
    // CharBuffer
    try {
        buf.put(String.valueOf(new char[buf.capacity() + 1]), 0, buf.capacity() + 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
    try {
        buf.put((String) null, 0, buf.capacity() + 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    assertEquals(0, buf.position());
    buf.clear();
    try {
        buf.put(str, -1, str.length());
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.put(str, str.length() + 1, str.length() + 2);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.put((String) null, -1, 0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    buf.put(str, str.length(), str.length());
    assertEquals(buf.position(), 0);
    try {
        buf.put(str, 2, 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.put(str, 2, str.length() + 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    char[] array = new char[buf.capacity()];
    loadTestData2(array, 0, array.length);
    str = String.valueOf(array);
    CharBuffer ret = buf.put(str, 0, str.length());
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, str.toCharArray(), 0, str.length());
    assertSame(ret, buf);
}
Also used : CharBuffer(java.nio.CharBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 73 with BufferOverflowException

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

the class CharBufferTest method testPutCharBuffer.

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

Example 74 with BufferOverflowException

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

the class FloatBufferTest method testPutfloatArrayintint.

/*
     * Class under test for java.nio.FloatBuffer put(float[], int, int)
     */
public void testPutfloatArrayintint() {
    buf.clear();
    float[] array = new float[buf.capacity()];
    try {
        buf.put(new float[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((float[]) 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);
    FloatBuffer ret = buf.put(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
}
Also used : FloatBuffer(java.nio.FloatBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 75 with BufferOverflowException

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

the class IntBufferTest method testPutintArray.

/*
     * Class under test for java.nio.IntBuffer put(int[])
     */
public void testPutintArray() {
    int[] array = new int[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        array[0] = (int) i;
        IntBuffer ret = buf.put(array);
        assertEquals(buf.get(i), (int) i);
        assertSame(ret, buf);
    }
    try {
        buf.put(array);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
    try {
        buf.position(buf.limit());
        buf.put((int[]) null);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : IntBuffer(java.nio.IntBuffer) 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