Search in sources :

Example 51 with TruffleObject

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");
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 52 with TruffleObject

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));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(java.lang.reflect.Method) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 53 with TruffleObject

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());
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 54 with TruffleObject

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()));
    }
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) AbstractList(java.util.AbstractList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 55 with TruffleObject

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));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)201 Test (org.junit.Test)135 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)34 InteropException (com.oracle.truffle.api.interop.InteropException)18 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)17 Specialization (com.oracle.truffle.api.dsl.Specialization)16 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)14 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)12 ArrayTruffleObject (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject)10 Node (com.oracle.truffle.api.nodes.Node)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)8 CallTarget (com.oracle.truffle.api.CallTarget)7 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)7 TestCallback (com.oracle.truffle.nfi.test.interop.TestCallback)7 LinkedHashMap (java.util.LinkedHashMap)7 Source (com.oracle.truffle.api.source.Source)6 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5