use of java.nio.FloatBuffer in project robovm by robovm.
the class FloatBufferTest method testDuplicate.
public void testDuplicate() {
buf.clear();
buf.mark();
buf.position(buf.limit());
// duplicate's contents should be the same as buf
FloatBuffer duplicate = buf.duplicate();
assertNotSame(buf, duplicate);
assertEquals(buf.position(), duplicate.position());
assertEquals(buf.limit(), duplicate.limit());
assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
assertEquals(buf.isDirect(), duplicate.isDirect());
assertEquals(buf.order(), duplicate.order());
assertContentEquals(buf, duplicate);
// duplicate's position, mark, and limit should be independent to buf
duplicate.reset();
assertEquals(duplicate.position(), 0);
duplicate.clear();
assertEquals(buf.position(), buf.limit());
buf.reset();
assertEquals(buf.position(), 0);
// duplicate share the same content with buf
if (!duplicate.isReadOnly()) {
loadTestData1(buf);
assertContentEquals(buf, duplicate);
loadTestData2(duplicate);
assertContentEquals(buf, duplicate);
}
}
use of java.nio.FloatBuffer in project robovm by robovm.
the class FloatBufferTest method testPutFloatBuffer.
/*
* Class under test for java.nio.FloatBuffer put(java.nio.FloatBuffer)
*/
public void testPutFloatBuffer() {
FloatBuffer other = FloatBuffer.allocate(buf.capacity());
try {
buf.put(buf);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IllegalArgumentException e) {
// expected
}
try {
buf.put(FloatBuffer.allocate(buf.capacity() + 1));
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
try {
buf.flip();
buf.put((FloatBuffer) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
buf.clear();
loadTestData2(other);
other.clear();
buf.clear();
FloatBuffer ret = buf.put(other);
assertEquals(other.position(), other.capacity());
assertEquals(buf.position(), buf.capacity());
assertContentEquals(other, buf);
assertSame(ret, buf);
}
use of java.nio.FloatBuffer in project robovm by robovm.
the class FloatBufferTest method testPutintfloat.
/*
* Class under test for java.nio.FloatBuffer put(int, float)
*/
public void testPutintfloat() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), 0);
FloatBuffer ret = buf.put(i, (float) i);
assertEquals(buf.get(i), (float) i, 0.0);
assertSame(ret, buf);
}
try {
buf.put(-1, 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(buf.limit(), 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
}
use of java.nio.FloatBuffer in project robovm by robovm.
the class FloatBufferTest method testPutfloat.
/*
* Class under test for java.nio.FloatBuffer put(float)
*/
public void testPutfloat() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
FloatBuffer ret = buf.put((float) i);
assertEquals(buf.get(i), (float) i, 0.0);
assertSame(ret, buf);
}
try {
buf.put(0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
}
use of java.nio.FloatBuffer in project robovm by robovm.
the class FloatBufferTest method testEquals.
public void testEquals() {
// equal to self
assertTrue(buf.equals(buf));
FloatBuffer readonly = buf.asReadOnlyBuffer();
assertTrue(buf.equals(readonly));
FloatBuffer duplicate = buf.duplicate();
assertTrue(buf.equals(duplicate));
// always false, if type mismatch
assertFalse(buf.equals(Boolean.TRUE));
assertTrue(buf.capacity() > 5);
buf.limit(buf.capacity()).position(0);
readonly.limit(readonly.capacity()).position(1);
assertFalse(buf.equals(readonly));
buf.limit(buf.capacity() - 1).position(0);
duplicate.limit(duplicate.capacity()).position(0);
assertFalse(buf.equals(duplicate));
}
Aggregations