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