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