Search in sources :

Example 6 with TestCallback

use of com.oracle.truffle.nfi.test.interop.TestCallback in project graal by oracle.

the class ErrnoNFITest method testErrnoCallback.

@Test
public void testErrnoCallback(@Inject(TestErrnoCallback.class) CallTarget target) {
    TestCallback callback = new TestCallback(0, (args) -> {
        destroyErrno();
        return null;
    });
    Object ret = target.call(42, callback);
    Assert.assertEquals(42, ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TestCallback(com.oracle.truffle.nfi.test.interop.TestCallback) Test(org.junit.Test)

Example 7 with TestCallback

use of com.oracle.truffle.nfi.test.interop.TestCallback in project graal by oracle.

the class WrappedPrimitiveNFITest method passObjectTest.

@Test
public void passObjectTest(@Inject(PassObjectNode.class) CallTarget target) {
    TestCallback getObject = new TestCallback(0, (args) -> {
        return argument;
    });
    TestCallback verifyObject = new TestCallback(2, (args) -> {
        Assert.assertSame("arg 1", argument, args[0]);
        Assert.assertSame("arg 2", argument, args[1]);
        return argument;
    });
    Object ret = target.call(argument, getObject, verifyObject);
    Assert.assertSame("return value", argument, ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) NullObject(com.oracle.truffle.nfi.test.interop.NullObject) TestCallback(com.oracle.truffle.nfi.test.interop.TestCallback) Test(org.junit.Test)

Example 8 with TestCallback

use of com.oracle.truffle.nfi.test.interop.TestCallback in project graal by oracle.

the class NumericNFITest method testCallback.

@Test
public void testCallback(@Inject(TestCallbackNode.class) CallTarget callTarget) {
    TruffleObject callback = new TestCallback(1, (args) -> {
        checkExpectedArg(42 + 1, args[0]);
        return unboxNumber(args[0]) + 5;
    });
    Object ret = callTarget.call(callback, 42);
    checkExpectedRet((42 + 6) * 2, ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TestCallback(com.oracle.truffle.nfi.test.interop.TestCallback) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 9 with TestCallback

use of com.oracle.truffle.nfi.test.interop.TestCallback in project graal by oracle.

the class ImplicitConvertNFITest method testConvert.

@Test
public void testConvert(@Inject(TestConvertNode.class) CallTarget callTarget) {
    TruffleObject callback = new TestCallback(1, this::callback);
    Object ret = callTarget.call(callback, value);
    if (type == NativeSimpleType.POINTER) {
        Assert.assertThat("return value", ret, is(instanceOf(TruffleObject.class)));
        TruffleObject obj = (TruffleObject) ret;
        Assert.assertTrue("isBoxed", isBoxed(obj));
        ret = unbox(obj);
        Assert.assertThat("unboxed return value", ret, is(instanceOf(Long.class)));
    } else {
        Assert.assertThat("return value", ret, is(instanceOf(Number.class)));
    }
    long retValue = ((Number) ret).longValue();
    Assert.assertEquals("callback return", numericValue * 2, retValue);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TestCallback(com.oracle.truffle.nfi.test.interop.TestCallback) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 TestCallback (com.oracle.truffle.nfi.test.interop.TestCallback)9 Test (org.junit.Test)7 InteropException (com.oracle.truffle.api.interop.InteropException)2 NullObject (com.oracle.truffle.nfi.test.interop.NullObject)2 BeforeClass (org.junit.BeforeClass)1