use of org.robovm.rt.bro.ptr.ShortPtr in project robovm by robovm.
the class StructTest method testStructWithArrayShortArrayAs2D.
@Test
public void testStructWithArrayShortArrayAs2D() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 3;
final int D2 = 8;
short[][] array1;
short[][] array2;
short[][] array3;
StructWithArray s = new StructWithArray();
ShortPtr p = s.shortArrayAsPtr();
array1 = s.shortArray2D();
assertEquals(D1, array1.length);
for (int i = 0; i < array1.length; i++) {
assertEquals(D2, array1[i].length);
for (int j = 0; j < array1[i].length; j++) {
assertEquals(0, array1[i][j]);
}
}
for (int i = 0; i < D1 * D2; i++) {
p.next(i).set((short) (i + 1));
}
array2 = s.shortArray2D();
assertEquals(D1, array2.length);
for (int i = 0; i < array2.length; i++) {
assertEquals(D2, array2[i].length);
for (int j = 0; j < array2[i].length; j++) {
assertEquals(i * D2 + j + 1, array2[i][j]);
}
}
array3 = new short[D1][D2];
for (int i = 0; i < array3.length; i++) {
for (int j = 0; j < array3[i].length; j++) {
array3[i][j] = (short) (2 * (i * D2 + j + 1));
}
}
s.shortArray2D(array3);
for (int i = 0; i < D1 * D2; i++) {
assertEquals(2 * (i + 1), p.next(i).get() & 0xffff);
}
try {
s.shortArray2D(new short[D1 / 2][]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
try {
s.shortArray2D(new short[D1][D2 / 2]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of org.robovm.rt.bro.ptr.ShortPtr in project robovm by robovm.
the class StructTest method testStructWithArrayShortArrayAsBuffer.
@Test
public void testStructWithArrayShortArrayAsBuffer() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 24;
StructWithArray s = new StructWithArray();
ShortPtr p = s.shortArrayAsPtr();
ShortBuffer b1;
ShortBuffer b2;
ShortBuffer b3;
for (int i = 0; i < D1; i++) {
p.next(i).set((short) (i + 1));
}
b1 = s.shortArrayAsBuffer();
assertEquals(D1, b1.capacity());
assertEquals(D1, b1.limit());
assertEquals(0, b1.position());
for (int i = 0; i < D1; i++) {
assertEquals(i + 1, b1.get(i));
}
b2 = ByteBuffer.allocateDirect(D1 * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
for (int i = 0; i < D1; i++) {
b2.put(i, (short) (2 * (i + 1)));
}
s.shortArrayAsBuffer(b2);
for (int i = 0; i < D1; i++) {
assertEquals(2 * (i + 1), p.next(i).get() & 0xffff);
}
b3 = ShortBuffer.allocate(D1);
assertFalse(b3.isDirect());
for (int i = 0; i < D1; i++) {
b3.put(i, (short) (3 * (i + 1)));
}
s.shortArrayAsBuffer(b3);
for (int i = 0; i < D1; i++) {
assertEquals(3 * (i + 1), p.next(i).get() & 0xffff);
}
try {
s.shortArrayAsBuffer(ShortBuffer.allocate(D1 / 2));
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of org.robovm.rt.bro.ptr.ShortPtr in project robovm by robovm.
the class StructTest method testStructWithArrayShortArrayAsPtr.
@Test
public void testStructWithArrayShortArrayAsPtr() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 24;
StructWithArray s = new StructWithArray();
ShortPtr p = s.shortArrayAsPtr();
ShortPtr q;
ShortPtr r;
assertEquals(s.getHandle(), p.getHandle());
for (int i = 0; i < D1; i++) {
p.next(i).set((short) (i + 1));
}
q = s.shortArrayAsPtr();
for (int i = 0; i < D1; i++) {
assertEquals(i + 1, q.next(i).get());
}
r = Struct.allocate(ShortPtr.class, D1);
assertNotEquals(s.getHandle(), r.getHandle());
for (int i = 0; i < D1; i++) {
r.next(i).set((short) (2 * (i + 1)));
}
s.shortArrayAsPtr(r);
for (int i = 0; i < D1; i++) {
assertEquals(2 * (i + 1), p.next(i).get() & 0xffff);
}
}
use of org.robovm.rt.bro.ptr.ShortPtr in project robovm by robovm.
the class StructTest method testStructWithArrayShortArrayAs1D.
@Test
public void testStructWithArrayShortArrayAs1D() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 24;
short[] array1;
short[] array2;
short[] array3;
StructWithArray s = new StructWithArray();
ShortPtr p = s.shortArrayAsPtr();
array1 = s.shortArray1D();
assertEquals(D1, array1.length);
for (int i = 0; i < array1.length; i++) {
assertEquals(0, array1[i]);
}
for (int i = 0; i < D1; i++) {
p.next(i).set((short) (i + 1));
}
array2 = s.shortArray1D();
assertEquals(D1, array2.length);
for (int i = 0; i < array2.length; i++) {
assertEquals(i + 1, array2[i]);
}
array3 = new short[D1];
for (int i = 0; i < array3.length; i++) {
array3[i] = (short) (2 * (i + 1));
}
s.shortArray1D(array3);
for (int i = 0; i < D1; i++) {
assertEquals(2 * (i + 1), p.next(i).get() & 0xffff);
}
try {
s.shortArray1D(new short[D1 / 2]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of org.robovm.rt.bro.ptr.ShortPtr in project robovm by robovm.
the class StructTest method testStructWithArrayShortArrayAs3D.
@Test
public void testStructWithArrayShortArrayAs3D() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 2;
final int D2 = 3;
final int D3 = 4;
short[][][] array1;
short[][][] array2;
short[][][] array3;
StructWithArray s = new StructWithArray();
ShortPtr p = s.shortArrayAsPtr();
array1 = s.shortArray3D();
assertEquals(D1, array1.length);
for (int i = 0; i < array1.length; i++) {
assertEquals(D2, array1[i].length);
for (int j = 0; j < array1[i].length; j++) {
assertEquals(D3, array1[i][j].length);
for (int k = 0; k < array1[i][j].length; k++) {
assertEquals(0, array1[i][j][k]);
}
}
}
for (int i = 0; i < D1 * D2 * D3; i++) {
p.next(i).set((short) (i + 1));
}
array2 = s.shortArray3D();
assertEquals(D1, array2.length);
for (int i = 0; i < array2.length; i++) {
assertEquals(D2, array2[i].length);
for (int j = 0; j < array2[i].length; j++) {
assertEquals(D3, array2[i][j].length);
for (int k = 0; k < array2[i][j].length; k++) {
assertEquals((i * D2 + j) * D3 + k + 1, array2[i][j][k]);
}
}
}
array3 = new short[D1][D2][D3];
for (int i = 0; i < array3.length; i++) {
for (int j = 0; j < array3[i].length; j++) {
for (int k = 0; k < array3[i][j].length; k++) {
array3[i][j][k] = (short) (2 * ((i * D2 + j) * D3 + k + 1));
}
}
}
s.shortArray3D(array3);
for (int i = 0; i < D1 * D2 * D3; i++) {
assertEquals(2 * (i + 1), p.next(i).get() & 0xffff);
}
try {
s.shortArray3D(new short[D1 / 2][][]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
try {
s.shortArray3D(new short[D1][D2 / 2][]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
try {
s.shortArray3D(new short[D1][D2][D3 / 2]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
Aggregations