Search in sources :

Example 96 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testIsHashEntryRemovable.

@Test
public void testIsHashEntryRemovable() {
    HashTest hashTest = new HashTest();
    InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
    assertFalse(hashLib.isHashEntryRemovable(hashTest, 1));
    hashTest.hasHashEntries = false;
    hashTest.removeable = (k) -> true;
    assertFails(() -> hashLib.isHashEntryRemovable(hashTest, 1), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.removeable = (k) -> true;
    hashTest.insertable = (k) -> true;
    assertFails(() -> hashLib.isHashEntryRemovable(hashTest, 1), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 97 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testGetLanguage.

@Test
public void testGetLanguage() throws UnsupportedMessageException {
    GetLanguageTest v = new GetLanguageTest();
    InteropLibrary l = createLibrary(InteropLibrary.class, v);
    Class<? extends TruffleLanguage<?>> testLanguage = ProxyLanguage.class;
    assertFails(() -> l.getSourceLocation(null), NullPointerException.class);
    v.hasLanguage = false;
    v.getLanguage = null;
    assertFalse(l.hasLanguage(v));
    assertFails(() -> l.getLanguage(v), UnsupportedMessageException.class);
    v.hasLanguage = true;
    v.getLanguage = () -> testLanguage;
    assertTrue(l.hasLanguage(v));
    assertSame(testLanguage, l.getLanguage(v));
    v.hasLanguage = true;
    v.getLanguage = null;
    assertFails(() -> l.hasLanguage(v), AssertionError.class);
    assertFails(() -> l.getLanguage(v), AssertionError.class);
    v.hasLanguage = true;
    v.getLanguage = () -> null;
    assertFails(() -> l.hasLanguage(v), AssertionError.class);
    assertFails(() -> l.getLanguage(v), AssertionError.class);
    v.hasLanguage = false;
    v.getLanguage = () -> testLanguage;
    assertFails(() -> l.hasLanguage(v), AssertionError.class);
    assertFails(() -> l.getLanguage(v), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 98 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testIsHashEntryModifiable.

@Test
public void testIsHashEntryModifiable() {
    HashTest hashTest = new HashTest();
    InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
    assertFalse(hashLib.isHashEntryModifiable(hashTest, 1));
    hashTest.hasHashEntries = false;
    hashTest.modifiable = (k) -> true;
    assertFails(() -> hashLib.isHashEntryModifiable(hashTest, 1), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.modifiable = (k) -> true;
    hashTest.insertable = (k) -> true;
    assertFails(() -> hashLib.isHashEntryModifiable(hashTest, 1), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 99 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method testMetaObject.

@Test
public void testMetaObject() throws UnsupportedMessageException {
    GetMetaObjectTest instance = new GetMetaObjectTest();
    MetaObjectTest v = new MetaObjectTest();
    InteropLibrary l = createLibrary(InteropLibrary.class, v);
    v.isMetaObject = false;
    v.isMetaInstance = null;
    v.getMetaQualifiedName = null;
    v.getMetaSimpleName = null;
    assertFalse(l.isMetaObject(v));
    assertFails(() -> l.getMetaQualifiedName(v), UnsupportedMessageException.class);
    assertFails(() -> l.getMetaSimpleName(v), UnsupportedMessageException.class);
    assertFails(() -> l.isMetaInstance(v, v), UnsupportedMessageException.class);
    v.isMetaObject = true;
    v.isMetaInstance = (o) -> o == instance;
    v.getMetaQualifiedName = () -> "testQualifiedName";
    v.getMetaSimpleName = () -> "testSimpleName";
    assertTrue(l.isMetaObject(v));
    assertEquals("testQualifiedName", l.getMetaQualifiedName(v));
    assertEquals("testSimpleName", l.getMetaSimpleName(v));
    assertTrue(l.isMetaInstance(v, instance));
    assertFalse(l.isMetaInstance(v, new GetMetaObjectTest()));
    assertFails(() -> l.isMetaInstance(v, new Object()), ClassCastException.class);
    v.isMetaObject = true;
    v.isMetaInstance = null;
    v.getMetaQualifiedName = null;
    v.getMetaSimpleName = null;
    assertFails(() -> l.isMetaObject(v), AssertionError.class);
    assertFails(() -> l.getMetaSimpleName(v), AssertionError.class);
    assertFails(() -> l.getMetaQualifiedName(v), AssertionError.class);
    assertFails(() -> l.isMetaInstance(v, v), AssertionError.class);
    v.isMetaObject = true;
    v.isMetaInstance = (o) -> o == instance;
    v.getMetaQualifiedName = () -> new Object();
    v.getMetaSimpleName = () -> new Object();
    assertFails(() -> l.isMetaObject(v), AssertionError.class);
    assertFails(() -> l.getMetaSimpleName(v), AssertionError.class);
    assertFails(() -> l.getMetaQualifiedName(v), AssertionError.class);
    assertFails(() -> l.isMetaInstance(v, new Object()), ClassCastException.class);
    v.isMetaObject = true;
    v.isMetaInstance = (o) -> o == instance;
    TestStringWrapper testQualifiedName = new TestStringWrapper("testQualifiedName");
    TestStringWrapper testSimpleName = new TestStringWrapper("testSimpleName");
    v.getMetaQualifiedName = () -> testQualifiedName;
    v.getMetaSimpleName = () -> testSimpleName;
    assertTrue(l.isMetaObject(v));
    assertSame(testQualifiedName, l.getMetaQualifiedName(v));
    assertSame(testSimpleName, l.getMetaSimpleName(v));
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 100 with InteropLibrary

use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.

the class InteropAssertionsTest method getIteratorNextElement.

@Test
public void getIteratorNextElement() throws UnsupportedMessageException, StopIterationException {
    // we need no multi threaded context.
    setupEnv(Context.create());
    IteratorTest iteratorTest = new IteratorTest(1);
    InteropLibrary iteratorLib = createLibrary(InteropLibrary.class, iteratorTest);
    assertEquals(iteratorTest.next.get(), iteratorLib.getIteratorNextElement(iteratorTest));
    iteratorTest.isIterator = false;
    assertFails(() -> iteratorLib.getIteratorNextElement(iteratorTest), AssertionError.class);
    iteratorTest.isIterator = true;
    iteratorTest.hasNext = () -> true;
    iteratorTest.next = Object::new;
    assertFails(() -> iteratorLib.getIteratorNextElement(iteratorTest), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Aggregations

InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)158 Test (org.junit.Test)76 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)60 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)51 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)18 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)18 ArityException (com.oracle.truffle.api.interop.ArityException)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)15 WasmInstance (org.graalvm.wasm.WasmInstance)15 WebAssembly (org.graalvm.wasm.api.WebAssembly)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)12 RootNode (com.oracle.truffle.api.nodes.RootNode)12 InteropException (com.oracle.truffle.api.interop.InteropException)11 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)11 Dictionary (org.graalvm.wasm.api.Dictionary)8 SourceSection (com.oracle.truffle.api.source.SourceSection)6 CallTarget (com.oracle.truffle.api.CallTarget)5 Node (com.oracle.truffle.api.nodes.Node)5 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)5 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)5