use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.
the class StructTest method testStructWithArrayLongArrayAs1D.
@Test
public void testStructWithArrayLongArrayAs1D() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 24;
long[] array1;
long[] array2;
long[] array3;
StructWithArray s = new StructWithArray();
LongPtr p = s.longArrayAsPtr();
array1 = s.longArray1D();
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(i + 1);
}
array2 = s.longArray1D();
assertEquals(D1, array2.length);
for (int i = 0; i < array2.length; i++) {
assertEquals(i + 1, array2[i]);
}
array3 = new long[D1];
for (int i = 0; i < array3.length; i++) {
array3[i] = 2 * (i + 1);
}
s.longArray1D(array3);
for (int i = 0; i < D1; i++) {
assertEquals(2 * (i + 1), p.next(i).get());
}
try {
s.longArray1D(new long[D1 / 2]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.
the class StructTest method testStructWithArrayLongArrayAsPtr.
@Test
public void testStructWithArrayLongArrayAsPtr() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 24;
StructWithArray s = new StructWithArray();
LongPtr p = s.longArrayAsPtr();
LongPtr q;
LongPtr r;
assertEquals(s.getHandle(), p.getHandle());
for (int i = 0; i < D1; i++) {
p.next(i).set(i + 1);
}
q = s.longArrayAsPtr();
for (int i = 0; i < D1; i++) {
assertEquals(i + 1, q.next(i).get());
}
r = Struct.allocate(LongPtr.class, D1);
assertNotEquals(s.getHandle(), r.getHandle());
for (int i = 0; i < D1; i++) {
r.next(i).set(2 * (i + 1));
}
s.longArrayAsPtr(r);
for (int i = 0; i < D1; i++) {
assertEquals(2 * (i + 1), p.next(i).get());
}
}
use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.
the class BridgeCallbackTest method testMarshalLargeStructReturnValueByVal.
@Test
public void testMarshalLargeStructReturnValueByVal() {
LongPtr address = new LongPtr();
Points ps = returnLargeStructByVal(1, 2, 3, 4, 5, 6, 7, 8, address);
assertEquals(1, ps.p1().x());
assertEquals(2, ps.p1().y());
assertEquals(3, ps.p2().x());
assertEquals(4, ps.p2().y());
assertEquals(5, ps.p3().x());
assertEquals(6, ps.p3().y());
assertEquals(7, ps.p4().x());
assertEquals(8, ps.p4().y());
assertFalse(address.get() == ps.getHandle());
}
use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.
the class StructTest method testStructWithArrayLongArrayAsBuffer.
@Test
public void testStructWithArrayLongArrayAsBuffer() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 24;
StructWithArray s = new StructWithArray();
LongPtr p = s.longArrayAsPtr();
LongBuffer b1;
LongBuffer b2;
LongBuffer b3;
for (int i = 0; i < D1; i++) {
p.next(i).set(i + 1);
}
b1 = s.longArrayAsBuffer();
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 * 8).order(ByteOrder.nativeOrder()).asLongBuffer();
for (int i = 0; i < D1; i++) {
b2.put(i, 2 * (i + 1));
}
s.longArrayAsBuffer(b2);
for (int i = 0; i < D1; i++) {
assertEquals(2 * (i + 1), p.next(i).get());
}
b3 = LongBuffer.allocate(D1);
assertFalse(b3.isDirect());
for (int i = 0; i < D1; i++) {
b3.put(i, 3 * (i + 1));
}
s.longArrayAsBuffer(b3);
for (int i = 0; i < D1; i++) {
assertEquals(3 * (i + 1), p.next(i).get());
}
try {
s.longArrayAsBuffer(LongBuffer.allocate(D1 / 2));
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.
the class StructTest method testStructWithArrayLongArrayAs3D.
@Test
public void testStructWithArrayLongArrayAs3D() {
assertEquals(192, StructWithArray.sizeOf());
final int D1 = 2;
final int D2 = 3;
final int D3 = 4;
long[][][] array1;
long[][][] array2;
long[][][] array3;
StructWithArray s = new StructWithArray();
LongPtr p = s.longArrayAsPtr();
array1 = s.longArray3D();
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(i + 1);
}
array2 = s.longArray3D();
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 long[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] = 2 * ((i * D2 + j) * D3 + k + 1);
}
}
}
s.longArray3D(array3);
for (int i = 0; i < D1 * D2 * D3; i++) {
assertEquals(2 * (i + 1), p.next(i).get());
}
try {
s.longArray3D(new long[D1 / 2][][]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
try {
s.longArray3D(new long[D1][D2 / 2][]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
try {
s.longArray3D(new long[D1][D2][D3 / 2]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
Aggregations