use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class LanguageSPIHostInteropTest method testSystemMethod.
@Test
public void testSystemMethod() throws InteropException {
TruffleObject system = (TruffleObject) env.lookupHostSymbol(System.class.getName());
Object value = ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), system, "getProperty", "file.separator");
assertThat(value, CoreMatchers.instanceOf(String.class));
assertThat(value, CoreMatchers.anyOf(CoreMatchers.equalTo("/"), CoreMatchers.equalTo("\\")));
Object getProperty = ForeignAccess.sendRead(Message.READ.createNode(), system, "getProperty");
assertThat(getProperty, CoreMatchers.instanceOf(TruffleObject.class));
assertTrue("IS_EXECUTABLE", ForeignAccess.sendIsExecutable(Message.IS_EXECUTABLE.createNode(), (TruffleObject) getProperty));
value = ForeignAccess.sendExecute(Message.createExecute(1).createNode(), (TruffleObject) getProperty, "file.separator");
assertThat(value, CoreMatchers.instanceOf(String.class));
assertThat(value, CoreMatchers.anyOf(CoreMatchers.equalTo("/"), CoreMatchers.equalTo("\\")));
}
use of com.oracle.truffle.api.interop.TruffleObject 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.interop.TruffleObject in project graal by oracle.
the class LanguageSPIHostInteropTest method keyInfo.
@Test
public void keyInfo() {
TruffleObject ipobj = new InternalPropertiesObject(-1, -1, 0, 0);
int keyInfo = getKeyInfo(ipobj, "p1");
assertTrue(KeyInfo.isReadable(keyInfo));
assertTrue(KeyInfo.isWritable(keyInfo));
assertFalse(KeyInfo.isInvocable(keyInfo));
assertFalse(KeyInfo.isInternal(keyInfo));
keyInfo = getKeyInfo(ipobj, "p6");
assertTrue(KeyInfo.isReadable(keyInfo));
assertTrue(KeyInfo.isWritable(keyInfo));
assertFalse(KeyInfo.isInvocable(keyInfo));
assertFalse(KeyInfo.isInternal(keyInfo));
keyInfo = getKeyInfo(ipobj, "p7");
assertEquals(0, keyInfo);
ipobj = new InternalPropertiesObject(0b0100010, 0b0100100, 0b0011000, 0);
keyInfo = getKeyInfo(ipobj, "p1");
assertTrue(KeyInfo.isReadable(keyInfo));
assertFalse(KeyInfo.isWritable(keyInfo));
assertFalse(KeyInfo.isInvocable(keyInfo));
keyInfo = getKeyInfo(ipobj, "p2");
assertFalse(KeyInfo.isReadable(keyInfo));
assertTrue(KeyInfo.isWritable(keyInfo));
assertFalse(KeyInfo.isInvocable(keyInfo));
keyInfo = getKeyInfo(ipobj, "p3");
assertFalse(KeyInfo.isReadable(keyInfo));
assertFalse(KeyInfo.isWritable(keyInfo));
assertTrue(KeyInfo.isInvocable(keyInfo));
keyInfo = getKeyInfo(ipobj, "p4");
assertFalse(KeyInfo.isReadable(keyInfo));
assertFalse(KeyInfo.isWritable(keyInfo));
assertTrue(KeyInfo.isInvocable(keyInfo));
keyInfo = getKeyInfo(ipobj, "p5");
assertTrue(KeyInfo.isReadable(keyInfo));
assertTrue(KeyInfo.isWritable(keyInfo));
assertFalse(KeyInfo.isInvocable(keyInfo));
keyInfo = getKeyInfo(ipobj, "p6");
assertFalse(KeyInfo.isReadable(keyInfo));
assertFalse(KeyInfo.isWritable(keyInfo));
assertFalse(KeyInfo.isInvocable(keyInfo));
keyInfo = getKeyInfo(ipobj, "p7");
assertEquals(0, keyInfo);
TruffleObject aobj = new ArrayTruffleObject(100);
testArrayObject(aobj, 100);
aobj = (TruffleObject) env.asGuestValue(new String[] { "A", "B", "C", "D" });
testArrayObject(aobj, 4);
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class LanguageSPIHostInteropTest 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 LanguageSPIHostInteropTest method testHasKeys.
@Test
public void testHasKeys() {
TruffleObject hasKeysObj = new HasKeysObject(true);
assertTrue(hasKeys(hasKeysObj));
hasKeysObj = new HasKeysObject(false);
assertFalse(hasKeys(hasKeysObj));
}
Aggregations