Search in sources :

Example 1 with DoublePtr

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

the class StructTest method testStructWithArrayDoubleArrayAsPtr.

@Test
public void testStructWithArrayDoubleArrayAsPtr() {
    assertEquals(192, StructWithArray.sizeOf());
    final int D1 = 24;
    StructWithArray s = new StructWithArray();
    DoublePtr p = s.doubleArrayAsPtr();
    DoublePtr q;
    DoublePtr r;
    assertEquals(s.getHandle(), p.getHandle());
    for (int i = 0; i < D1; i++) {
        p.next(i).set(i + 1);
    }
    q = s.doubleArrayAsPtr();
    for (int i = 0; i < D1; i++) {
        assertEquals(i + 1, q.next(i).get(), 0.0001);
    }
    r = Struct.allocate(DoublePtr.class, D1);
    assertNotEquals(s.getHandle(), r.getHandle());
    for (int i = 0; i < D1; i++) {
        r.next(i).set(2 * (i + 1));
    }
    s.doubleArrayAsPtr(r);
    for (int i = 0; i < D1; i++) {
        assertEquals(2 * (i + 1), p.next(i).get(), 0.0001);
    }
}
Also used : DoublePtr(org.robovm.rt.bro.ptr.DoublePtr) Test(org.junit.Test)

Example 2 with DoublePtr

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

the class StructTest method testStructWithArrayDoubleArrayAsBuffer.

@Test
public void testStructWithArrayDoubleArrayAsBuffer() {
    assertEquals(192, StructWithArray.sizeOf());
    final int D1 = 24;
    StructWithArray s = new StructWithArray();
    DoublePtr p = s.doubleArrayAsPtr();
    DoubleBuffer b1;
    DoubleBuffer b2;
    DoubleBuffer b3;
    for (int i = 0; i < D1; i++) {
        p.next(i).set(i + 1);
    }
    b1 = s.doubleArrayAsBuffer();
    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), 0.0001);
    }
    b2 = ByteBuffer.allocateDirect(D1 * 8).order(ByteOrder.nativeOrder()).asDoubleBuffer();
    for (int i = 0; i < D1; i++) {
        b2.put(i, 2 * (i + 1));
    }
    s.doubleArrayAsBuffer(b2);
    for (int i = 0; i < D1; i++) {
        assertEquals(2 * (i + 1), p.next(i).get(), 0.0001);
    }
    b3 = DoubleBuffer.allocate(D1);
    assertFalse(b3.isDirect());
    for (int i = 0; i < D1; i++) {
        b3.put(i, 3 * (i + 1));
    }
    s.doubleArrayAsBuffer(b3);
    for (int i = 0; i < D1; i++) {
        assertEquals(3 * (i + 1), p.next(i).get(), 0.0001);
    }
    try {
        s.doubleArrayAsBuffer(DoubleBuffer.allocate(D1 / 2));
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) DoublePtr(org.robovm.rt.bro.ptr.DoublePtr) Test(org.junit.Test)

Example 3 with DoublePtr

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

the class StructTest method testStructWithArrayDoubleArrayAs1D.

@Test
public void testStructWithArrayDoubleArrayAs1D() {
    assertEquals(192, StructWithArray.sizeOf());
    final int D1 = 24;
    double[] array1;
    double[] array2;
    double[] array3;
    StructWithArray s = new StructWithArray();
    DoublePtr p = s.doubleArrayAsPtr();
    array1 = s.doubleArray1D();
    assertEquals(D1, array1.length);
    for (int i = 0; i < array1.length; i++) {
        assertEquals(0, array1[i], 0.0001);
    }
    for (int i = 0; i < D1; i++) {
        p.next(i).set(i + 1);
    }
    array2 = s.doubleArray1D();
    assertEquals(D1, array2.length);
    for (int i = 0; i < array2.length; i++) {
        assertEquals(i + 1, array2[i], 0.0001);
    }
    array3 = new double[D1];
    for (int i = 0; i < array3.length; i++) {
        array3[i] = 2 * (i + 1);
    }
    s.doubleArray1D(array3);
    for (int i = 0; i < D1; i++) {
        assertEquals(2 * (i + 1), p.next(i).get(), 0.0001);
    }
    try {
        s.doubleArray1D(new double[D1 / 2]);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : DoublePtr(org.robovm.rt.bro.ptr.DoublePtr) Test(org.junit.Test)

Example 4 with DoublePtr

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

the class StructTest method testStructWithArrayDoubleArrayAs3D.

@Test
public void testStructWithArrayDoubleArrayAs3D() {
    assertEquals(192, StructWithArray.sizeOf());
    final int D1 = 2;
    final int D2 = 3;
    final int D3 = 4;
    double[][][] array1;
    double[][][] array2;
    double[][][] array3;
    StructWithArray s = new StructWithArray();
    DoublePtr p = s.doubleArrayAsPtr();
    array1 = s.doubleArray3D();
    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], 0.0001);
            }
        }
    }
    for (int i = 0; i < D1 * D2 * D3; i++) {
        p.next(i).set(i + 1);
    }
    array2 = s.doubleArray3D();
    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], 0.0001);
            }
        }
    }
    array3 = new double[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.doubleArray3D(array3);
    for (int i = 0; i < D1 * D2 * D3; i++) {
        assertEquals(2 * (i + 1), p.next(i).get(), 0.0001);
    }
    try {
        s.doubleArray3D(new double[D1 / 2][][]);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        s.doubleArray3D(new double[D1][D2 / 2][]);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        s.doubleArray3D(new double[D1][D2][D3 / 2]);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : DoublePtr(org.robovm.rt.bro.ptr.DoublePtr) Test(org.junit.Test)

Example 5 with DoublePtr

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

the class StructTest method testStructWithArrayDoubleArrayAs2D.

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

Aggregations

Test (org.junit.Test)5 DoublePtr (org.robovm.rt.bro.ptr.DoublePtr)5 DoubleBuffer (java.nio.DoubleBuffer)1