use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class ClassInteropTest method nonpublicTypeNotvisible.
@Test(expected = com.oracle.truffle.api.interop.UnknownIdentifierException.class)
public void nonpublicTypeNotvisible() {
Object type = JavaInteropTest.message(Message.KEY_INFO, obj, "NonStaticInterface");
assertEquals("Non-public member type not visible", 0, type);
type = JavaInteropTest.message(Message.KEYS, obj);
assertTrue("Type is a truffle object", type instanceof TruffleObject);
String[] names = JavaInterop.asJavaObject(String[].class, (TruffleObject) type);
assertEquals("Non-public member type not enumerated", -1, Arrays.asList(names).indexOf("NonStaticInterface"));
JavaInteropTest.message(Message.READ, obj, "NonStaticInterface");
fail("Cannot read non-static member type");
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropDocumentationTest method showHowToCheckForNull.
@Test
public void showHowToCheckForNull() throws Throwable {
if (!loadedOK) {
return;
}
Method m = INTEROP_SNIPPETS.getDeclaredMethod("isNullValue", TruffleObject.class);
m.setAccessible(true);
Constructor<?> constructor = INTEROP_SNIPPETS.getDeclaredConstructor();
constructor.setAccessible(true);
Object interopSnippets = constructor.newInstance();
assertTrue("Yes, it is null", (boolean) m.invoke(interopSnippets, JavaInterop.asTruffleObject(null)));
TruffleObject nonNullValue = JavaInterop.asTruffleObject(this);
assertFalse("No, it is not null", (boolean) m.invoke(interopSnippets, nonNullValue));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropNullTest method testNullArg.
@Test
public void testNullArg() {
TruffleObject callback = JavaInterop.asTruffleFunction(StringCallback.class, (obj) -> {
Assert.assertNull(obj);
});
CallTarget target = Truffle.getRuntime().createCallTarget(new TestRootNode(callback));
target.call(new TestNull());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class JavaInteropTest method assertKeysAndProperties.
@SuppressWarnings("unchecked")
@Test
public void assertKeysAndProperties() {
TruffleObject keys = sendKeys(obj);
List<Object> list = JavaInterop.asJavaObject(List.class, keys);
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(obj, true);
list = JavaInterop.asJavaObject(List.class, keys);
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 JavaInteropTest method emptyArrayHasSize.
@Test
public void emptyArrayHasSize() {
data.arr = new String[] {};
Object arrObj = message(Message.READ, obj, "arr");
assertTrue("It's obj: " + arrObj, arrObj instanceof TruffleObject);
TruffleObject truffleArr = (TruffleObject) arrObj;
assertEquals("It has size", Boolean.TRUE, message(Message.HAS_SIZE, truffleArr));
assertEquals("Zero elements", 0, message(Message.GET_SIZE, truffleArr));
}
Aggregations