Search in sources :

Example 41 with LongBuffer

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

the class LongBufferTest method testPutlong.

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

Example 42 with LongBuffer

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

the class LongBufferTest method testCompareTo.

public void testCompareTo() {
    // compare to self
    assertEquals(0, buf.compareTo(buf));
    // normal cases
    assertTrue(buf.capacity() > 5);
    buf.clear();
    LongBuffer other = LongBuffer.allocate(buf.capacity());
    loadTestData1(other);
    assertEquals(0, buf.compareTo(other));
    assertEquals(0, other.compareTo(buf));
    buf.position(1);
    assertTrue(buf.compareTo(other) > 0);
    assertTrue(other.compareTo(buf) < 0);
    other.position(2);
    assertTrue(buf.compareTo(other) < 0);
    assertTrue(other.compareTo(buf) > 0);
    buf.position(2);
    other.limit(5);
    assertTrue(buf.compareTo(other) > 0);
    assertTrue(other.compareTo(buf) < 0);
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 43 with LongBuffer

use of java.nio.LongBuffer 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 44 with LongBuffer

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

the class WrappedLongBufferTest method testWrappedLongBuffer_IllegalArg.

/**
     * @tests java.nio.CharBuffer#allocate(char[],int,int)
     * 
     */
public void testWrappedLongBuffer_IllegalArg() {
    long[] array = new long[20];
    try {
        LongBuffer.wrap(array, -1, 0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        LongBuffer.wrap(array, 21, 0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        LongBuffer.wrap(array, 0, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        LongBuffer.wrap(array, 0, 21);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        LongBuffer.wrap(array, Integer.MAX_VALUE, 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        LongBuffer.wrap(array, 1, Integer.MAX_VALUE);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        LongBuffer.wrap((long[]) null, -1, 0);
        //$NON-NLS-1$
        fail("Should throw NPE");
    } catch (NullPointerException e) {
    }
    LongBuffer buf = LongBuffer.wrap(array, 2, 16);
    assertEquals(buf.position(), 2);
    assertEquals(buf.limit(), 18);
    assertEquals(buf.capacity(), 20);
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 45 with LongBuffer

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

the class ReadOnlyLongBufferTest method testPutLongBuffer.

public void testPutLongBuffer() {
    LongBuffer other = LongBuffer.allocate(1);
    try {
        buf.put(other);
        //$NON-NLS-1$
        fail("Should throw ReadOnlyBufferException");
    } catch (ReadOnlyBufferException e) {
    // expected
    }
    try {
        buf.put((LongBuffer) null);
        //$NON-NLS-1$
        fail("Should throw ReadOnlyBufferException");
    } catch (ReadOnlyBufferException e) {
    // expected
    }
    try {
        buf.put(buf);
        //$NON-NLS-1$
        fail("Should throw ReadOnlyBufferException");
    } catch (ReadOnlyBufferException e) {
    // expected
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) LongBuffer(java.nio.LongBuffer)

Aggregations

LongBuffer (java.nio.LongBuffer)49 ByteBuffer (java.nio.ByteBuffer)16 DoubleBuffer (java.nio.DoubleBuffer)10 FloatBuffer (java.nio.FloatBuffer)10 IntBuffer (java.nio.IntBuffer)10 ShortBuffer (java.nio.ShortBuffer)10 CharBuffer (java.nio.CharBuffer)9 Test (org.junit.Test)7 BufferOverflowException (java.nio.BufferOverflowException)4 BufferUnderflowException (java.nio.BufferUnderflowException)3 Bitmap (android.graphics.Bitmap)2 InvalidMarkException (java.nio.InvalidMarkException)2 ByteSource (org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Buffer (java.nio.Buffer)1 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)1 BytePointer (org.bytedeco.javacpp.BytePointer)1 DoublePointer (org.bytedeco.javacpp.DoublePointer)1