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);
}
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);
}
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);
}
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);
}
Aggregations