use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method testHasKeysDefaults.
@Test
public void testHasKeysDefaults() {
TruffleObject noKeys = new NoKeysObject();
assertFalse(hasKeys(noKeys));
TruffleObject keysObj = new DefaultHasKeysObject();
assertTrue(hasKeys(keysObj));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method testNewObject.
@Test
public void testNewObject() throws InteropException {
TruffleObject objectClass = JavaInterop.asTruffleObject(Object.class);
Object object = ForeignAccess.sendNew(Message.createNew(0).createNode(), objectClass);
assertThat(object, CoreMatchers.instanceOf(TruffleObject.class));
assertTrue(JavaInterop.isJavaObject(Object.class, (TruffleObject) object));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class AsCollectionsTest method testAsList.
@Test
public void testAsList() {
List origList = Arrays.asList(new String[] { "a", "b", "c" });
TruffleObject to = new ListBasedTO(origList);
assertTrue(JavaInteropTest.isArray(to));
List interopList = com.oracle.truffle.api.interop.java.JavaInterop.asJavaObject(List.class, to);
assertEquals(origList.size(), interopList.size());
assertEquals(origList.toString(), interopList.toString());
// Test get out of bounds
try {
interopList.get(1000);
fail();
} catch (IndexOutOfBoundsException ioobex) {
// O.K.
}
// Test set out of bounds
try {
interopList.set(1000, "1000");
fail();
} catch (IndexOutOfBoundsException ioobex) {
// O.K.
}
Object old = interopList.set(1, "bbb");
assertEquals("b", old);
assertEquals("bbb", interopList.get(1));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class AsCollectionsTest method testInvokeListOfMapProxy.
@Test
public void testInvokeListOfMapProxy() throws InteropException {
TruffleObject validator = com.oracle.truffle.api.interop.java.JavaInterop.asTruffleObject(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ProxyValidator.class }, (p, method, args) -> {
List<Map> listOfMap = (List<Map>) args[0];
assertEquals(1, listOfMap.size());
Map map = listOfMap.get(0);
assertEquals(1, map.size());
assertEquals("bar", map.get("foo"));
return true;
}));
MapBasedTO mapTO = new MapBasedTO(Collections.singletonMap("foo", "bar"));
TruffleObject listOfMapTO = new ListBasedTO(Arrays.asList(mapTO));
assertEquals(Boolean.TRUE, ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), validator, "test", listOfMapTO));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class AsCollectionsTest method testInvokeMap.
@Test
public void testInvokeMap() throws InteropException {
TruffleObject validator = com.oracle.truffle.api.interop.java.JavaInterop.asTruffleObject(new Validator());
MapBasedTO mapTO = new MapBasedTO(Collections.singletonMap("foo", "bar"));
assertEquals(Boolean.TRUE, ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), validator, "validateMap", mapTO, mapTO));
}
Aggregations