Search in sources :

Example 66 with BufferOverflowException

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

the class CharBufferTest method testPutcharArray.

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

Example 67 with BufferOverflowException

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

the class CharBufferTest method testAppendOverFlow.

public void testAppendOverFlow() throws IOException {
    CharBuffer cb = CharBuffer.allocate(1);
    CharSequence cs = "String";
    cb.put('A');
    try {
        cb.append('C');
        fail("should throw BufferOverflowException.");
    } catch (BufferOverflowException ex) {
    // expected;
    }
    try {
        cb.append(cs);
        fail("should throw BufferOverflowException.");
    } catch (BufferOverflowException ex) {
    // expected;
    }
    try {
        cb.append(cs, 1, 2);
        fail("should throw BufferOverflowException.");
    } catch (BufferOverflowException ex) {
    // expected;
    }
}
Also used : CharBuffer(java.nio.CharBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 68 with BufferOverflowException

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

Example 69 with BufferOverflowException

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

Example 70 with BufferOverflowException

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

the class DoubleBufferTest method testPutdoubleArrayintint.

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