use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method testNewClass.
@Test
public void testNewClass() throws InteropException {
TruffleObject hashMapClass = JavaInterop.asTruffleObject(HashMap.class);
Object hashMap = ForeignAccess.sendNew(Message.createNew(0).createNode(), hashMapClass);
assertThat(hashMap, CoreMatchers.instanceOf(TruffleObject.class));
assertTrue(JavaInterop.isJavaObject(HashMap.class, (TruffleObject) hashMap));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class OverloadedTest method testVarArgs.
@Test
public void testVarArgs() throws InteropException {
TruffleObject stringClass = JavaInterop.asTruffleObject(String.class);
assertEquals("bla", ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), stringClass, "format", "bla"));
assertEquals("42", ForeignAccess.sendInvoke(Message.createInvoke(2).createNode(), stringClass, "format", "%d", 42));
assertEquals("1337", ForeignAccess.sendInvoke(Message.createInvoke(3).createNode(), stringClass, "format", "%d%d", 13, 37));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class OverloadedTest method testWidening.
@Test
public void testWidening() throws InteropException {
Node n = Message.createInvoke(1).createNode();
Num num = new Num();
TruffleObject numobj = JavaInterop.asTruffleObject(num);
ForeignAccess.sendInvoke(n, numobj, "d", (byte) 42);
assertEquals("int", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "d", (short) 42);
assertEquals("int", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "d", 42);
assertEquals("int", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "d", 42.1f);
assertEquals("double", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "d", 42.1d);
assertEquals("double", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "d", 0x8000_0000L);
assertEquals("double", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "d", 42L);
assertEquals("int", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "f", 42L);
assertEquals("int", num.parameter);
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class CallbackWithOverloadConvertTest method callWithCharTest.
@Test
public void callWithCharTest() {
TruffleObject truffle = JavaInterop.asTruffleObject(this);
CallWithChar callback = JavaInterop.asJavaObject(CallWithChar.class, truffle);
callback.callback('A');
assertEquals('A', ch);
assertEquals("Int remains zero", 0, i);
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class CallbackWithOverloadConvertTest method callWithIntTest.
@Test
public void callWithIntTest() {
TruffleObject truffle = JavaInterop.asTruffleObject(this);
CallWithInt callback = JavaInterop.asJavaObject(CallWithInt.class, truffle);
callback.callback(32);
assertEquals("Char not changed", 0, ch);
assertEquals("Int changed", 32, i);
}
Aggregations