Search in sources :

Example 61 with InteropLibrary

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

the class InteropAssertionsTest method testRemoveHashEntry.

@Test
public void testRemoveHashEntry() throws UnsupportedMessageException, UnknownKeyException {
    // we need no multi threaded context.
    setupEnv(Context.create());
    HashTest hashTest = new HashTest();
    InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
    hashTest.writeHashEntry(1, -1);
    hashLib.removeHashEntry(hashTest, 1);
    assertFails(() -> {
        hashLib.removeHashEntry(hashTest, null);
        return null;
    }, NullPointerException.class);
    hashTest.writeHashEntry(1, -1);
    hashTest.hasHashEntries = false;
    assertFails(() -> {
        hashLib.removeHashEntry(hashTest, 1);
        return null;
    }, AssertionError.class);
    hashTest.writeHashEntry(1, -1);
    hashTest.hasHashEntries = true;
    hashTest.removeable = (k) -> false;
    assertFails(() -> {
        hashLib.removeHashEntry(hashTest, 1);
        return null;
    }, AssertionError.class);
    hashTest.writeHashEntry(1, -1);
    hashTest.hasHashEntries = true;
    hashTest.removeable = (k) -> true;
    hashTest.data = null;
    assertFails(() -> {
        hashLib.removeHashEntry(hashTest, 1);
        return null;
    }, AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 62 with InteropLibrary

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

the class InteropAssertionsTest method testIsHashEntryReadable.

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

Example 63 with InteropLibrary

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

the class InteropAssertionsTest method testIsHashEntryWritable.

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

Example 64 with InteropLibrary

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

the class InteropAssertionsTest method hasIteratorNextElement.

@Test
public void hasIteratorNextElement() throws UnsupportedMessageException {
    IteratorTest iteratorTest = new IteratorTest(1);
    InteropLibrary iteratorLib = createLibrary(InteropLibrary.class, iteratorTest);
    assertEquals(true, iteratorLib.hasIteratorNextElement(iteratorTest));
    iteratorTest.isIterator = false;
    assertFails(() -> iteratorLib.hasIteratorNextElement(iteratorTest), AssertionError.class);
    iteratorTest.isIterator = true;
    iteratorTest.hasNext = null;
    assertFails(() -> iteratorLib.hasIteratorNextElement(iteratorTest), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 65 with InteropLibrary

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

the class InteropDateTimeTest method testDefaults.

@Test
public void testDefaults() {
    Defaults o = new Defaults();
    InteropLibrary library = createLibrary(InteropLibrary.class, o);
    assertFalse(library.isDate(o));
    assertFalse(library.isTime(o));
    assertFalse(library.isTimeZone(o));
    assertFalse(library.isDuration(o));
    assertFails(() -> library.asInstant(o), UnsupportedMessageException.class);
    assertFails(() -> library.asDate(o), UnsupportedMessageException.class);
    assertFails(() -> library.asTime(o), UnsupportedMessageException.class);
    assertFails(() -> library.asTimeZone(o), UnsupportedMessageException.class);
    assertFails(() -> library.asDuration(o), UnsupportedMessageException.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) 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