Search in sources :

Example 6 with LongPtr

use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.

the class StructTest method testStructWithArrayLongArrayAs2D.

@Test
public void testStructWithArrayLongArrayAs2D() {
    assertEquals(192, StructWithArray.sizeOf());
    final int D1 = 3;
    final int D2 = 8;
    long[][] array1;
    long[][] array2;
    long[][] array3;
    StructWithArray s = new StructWithArray();
    LongPtr p = s.longArrayAsPtr();
    array1 = s.longArray2D();
    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(i + 1);
    }
    array2 = s.longArray2D();
    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 long[D1][D2];
    for (int i = 0; i < array3.length; i++) {
        for (int j = 0; j < array3[i].length; j++) {
            array3[i][j] = 2 * (i * D2 + j + 1);
        }
    }
    s.longArray2D(array3);
    for (int i = 0; i < D1 * D2; i++) {
        assertEquals(2 * (i + 1), p.next(i).get());
    }
    try {
        s.longArray2D(new long[D1 / 2][]);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        s.longArray2D(new long[D1][D2 / 2]);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : LongPtr(org.robovm.rt.bro.ptr.LongPtr) Test(org.junit.Test)

Example 7 with LongPtr

use of org.robovm.rt.bro.ptr.LongPtr in project robovm by robovm.

the class BridgeCallbackTest method testInstanceMethods.

@Test
public void testInstanceMethods() throws Exception {
    NativeObj obj = new NativeObj();
    Method setHandle = NativeObject.class.getDeclaredMethod("setHandle", long.class);
    setHandle.setAccessible(true);
    setHandle.invoke(obj, 0x12345678);
    LongPtr l = new LongPtr();
    assertEquals(100 * 100, obj.simpleInstanceMethod(100, l));
    assertEquals(obj.getHandle(), l.get());
    SmallStruct ss1 = new SmallStruct().v1((byte) 64).v2((byte) 128);
    SmallStruct ss2 = obj.returnSmallStructInstanceMethod(ss1, l);
    assertNotEquals(ss1.getHandle(), ss2.getHandle());
    assertEquals(64, ss2.v1() & 0xff);
    assertEquals(128, ss2.v2() & 0xff);
    assertEquals(obj.getHandle(), l.get());
    LargeStruct ls1 = new LargeStruct().v1(0x12).v2(0x1234).v3(0x12345678).v4(0x123456789abcdef0L);
    LargeStruct ls2 = obj.returnLargeStructInstanceMethod(ls1, l);
    assertNotEquals(ls1.getHandle(), ls2.getHandle());
    assertEquals(0x12, ls2.v1());
    assertEquals(0x1234, ls2.v2());
    assertEquals(0x12345678, ls2.v3());
    assertEquals(0x123456789abcdef0L, ls2.v4());
    assertEquals(obj.getHandle(), l.get());
}
Also used : LongPtr(org.robovm.rt.bro.ptr.LongPtr) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 LongPtr (org.robovm.rt.bro.ptr.LongPtr)7 Method (java.lang.reflect.Method)1 LongBuffer (java.nio.LongBuffer)1