use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method noNonStaticPropertiesForAClass.
@SuppressWarnings("unchecked")
@Test
public void noNonStaticPropertiesForAClass() {
TruffleObject pojo = JavaInterop.asTruffleObject(PublicPOJO.class);
TruffleObject result = sendKeys(pojo);
List<Object> propertyNames = JavaInterop.asJavaObject(List.class, result);
assertEquals("3 members: static field 'y', static method 'readY', plus 'class'", 3, propertyNames.size());
assertThat(propertyNames, CoreMatchers.hasItems("y", "readY", "class"));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method executableAsFunctionalInterface3.
@Ignore("Interface not accessible")
@Test
public void executableAsFunctionalInterface3() throws Exception {
assumeTrue("JDK 9 or later", System.getProperty("java.specification.version").compareTo("1.9") >= 0);
TruffleObject executable = new FunctionObject();
FunctionalWithDefaults f = JavaInterop.asJavaFunction(FunctionalWithDefaults.class, executable);
assertEquals(42, f.call((Object) 13, (Object) 29));
assertEquals(50, f.call(13, 37));
f.hashCode();
f.equals(null);
f.toString();
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method testRecursiveListMarshalling.
@Test
public void testRecursiveListMarshalling() throws UnknownIdentifierException, UnsupportedMessageException {
List<GregorianCalendar> testList = Arrays.asList(new GregorianCalendar());
TruffleObject list = JavaInterop.asTruffleObject(testList);
Object firstElement = ForeignAccess.sendRead(Message.READ.createNode(), list, 0);
assertTrue(JavaInterop.isJavaObject(firstElement));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method accessAllProperties.
@Test
public void accessAllProperties() {
TruffleObject pojo = JavaInterop.asTruffleObject(new PrivatePOJO());
Map<?, ?> map = JavaInterop.asJavaObject(Map.class, pojo);
int cnt = 0;
for (Map.Entry<?, ?> entry : map.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
assertNotNull(key);
assertNotNull(value);
cnt++;
}
assertEquals("No properties", 0, cnt);
assertEquals("Empty: " + map, 0, map.size());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method indexJavaArrayWithNumberTypes.
@Test
public void indexJavaArrayWithNumberTypes() throws Exception {
int[] a = new int[] { 1, 2, 3 };
TruffleObject truffleObject = JavaInterop.asTruffleObject(a);
assertEquals(2, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1));
assertEquals(2, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1.0));
assertEquals(2, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1L));
ForeignAccess.sendWrite(Message.WRITE.createNode(), truffleObject, 1, 42);
ForeignAccess.sendWrite(Message.WRITE.createNode(), truffleObject, 1.0, 42);
ForeignAccess.sendWrite(Message.WRITE.createNode(), truffleObject, 1L, 42);
assertEquals(42, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1));
assertEquals(42, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1.0));
assertEquals(42, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1L));
}
Aggregations