use of com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.Data in project graal by oracle.
the class LanguageSPIHostInteropTest method invokeJavaLangObjectFields.
@Test
public void invokeJavaLangObjectFields() throws InteropException {
Data data = new Data();
TruffleObject obj = (TruffleObject) env.asGuestValue(data);
Object string = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "toString");
assertTrue(string instanceof String && ((String) string).startsWith(Data.class.getName() + "@"));
Object clazz = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "getClass");
assertTrue(clazz instanceof TruffleObject && env.asHostObject(clazz) == Data.class);
assertEquals(true, ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), obj, "equals", obj));
assertTrue(ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "hashCode") instanceof Integer);
for (String m : new String[] { "notify", "notifyAll", "wait" }) {
assertThrowsExceptionWithCause(() -> ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, m), IllegalMonitorStateException.class);
}
}
use of com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.Data in project graal by oracle.
the class LanguageSPIHostInteropTest method assertKeysAndProperties.
@SuppressWarnings("unchecked")
@Test
public void assertKeysAndProperties() {
Data dataObj = new Data();
TruffleObject data = (TruffleObject) env.asGuestValue(dataObj);
TruffleObject keys = sendKeys(data);
List<Object> list = context.asValue(keys).as(List.class);
assertThat(list, CoreMatchers.hasItems("x", "y", "arr", "value", "map", "dataMap", "data", "plus"));
Method[] objectMethods = Object.class.getMethods();
for (Method objectMethod : objectMethods) {
assertThat("No java.lang.Object methods", list, CoreMatchers.not(CoreMatchers.hasItem(objectMethod.getName())));
}
keys = sendKeys(data, true);
list = context.asValue(keys).as(List.class);
for (Method objectMethod : objectMethods) {
assertThat("java.lang.Object methods", list, CoreMatchers.hasItem(objectMethod.getName()));
}
}
use of com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.Data in project graal by oracle.
the class LanguageSPIHostInteropTest method testAsGuestValue.
@Test
public void testAsGuestValue() {
Object object = new Object();
// Test that asTruffleValue() returns the same as asTruffleObject() for non-primitive types:
assertEquals(env.asGuestValue(object), env.asGuestValue(object));
Data data = new Data();
Object obj = env.asGuestValue(data);
assertEquals(obj, env.asGuestValue(data));
// Test that asTruffleValue() returns non-wraped primitives:
object = 42;
assertTrue(env.asGuestValue(object) == object);
object = (byte) 42;
assertTrue(env.asGuestValue(object) == object);
object = (short) 42;
assertTrue(env.asGuestValue(object) == object);
object = 424242424242L;
assertTrue(env.asGuestValue(object) == object);
object = 42.42;
assertTrue(env.asGuestValue(object) == object);
object = true;
assertTrue(env.asGuestValue(object) == object);
object = "42";
assertTrue(env.asGuestValue(object) == object);
object = '4';
assertTrue(env.asGuestValue(object) == object);
object = true;
assertTrue(env.asGuestValue(object) == object);
}
Aggregations