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
}
}
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);
}
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);
}
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);
}
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
}
}
Aggregations