Search in sources :

Example 91 with InteropLibrary

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

the class InteropAssertionsTest method testIsHashEntryExisting.

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

Example 92 with InteropLibrary

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

the class InteropAssertionsTest method testGetHashKeysIterator.

@Test
public void testGetHashKeysIterator() throws UnsupportedMessageException {
    HashTest hashTest = new HashTest();
    InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
    hashLib.getHashKeysIterator(hashTest);
    hashTest.hasHashEntries = false;
    assertFails(() -> hashLib.getHashKeysIterator(hashTest), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.iterator = null;
    assertFails(() -> hashLib.getHashKeysIterator(hashTest), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.iterator = () -> null;
    assertFails(() -> hashLib.getHashKeysIterator(hashTest), AssertionError.class);
    hashTest.iterator = () -> new TruffleObject() {
    };
    assertFails(() -> hashLib.getHashKeysIterator(hashTest), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 93 with InteropLibrary

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

the class InteropAssertionsTest method testWriteHashEntry.

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

Example 94 with InteropLibrary

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

the class InteropAssertionsTest method testGetHashSize.

@Test
public void testGetHashSize() throws UnsupportedMessageException {
    HashTest hashTest = new HashTest();
    InteropLibrary hashLib = createLibrary(InteropLibrary.class, hashTest);
    assertEquals(hashTest.data.size(), hashLib.getHashSize(hashTest));
    hashTest.hasHashEntries = false;
    assertFails(() -> hashLib.getHashSize(hashTest), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.size = null;
    assertFails(() -> hashLib.getHashSize(hashTest), AssertionError.class);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 95 with InteropLibrary

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

the class InteropAssertionsTest method testReadHashValue.

@Test
public void testReadHashValue() 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);
    assertEquals(-1, hashLib.readHashValue(hashTest, 1));
    assertFails(() -> hashLib.readHashValue(hashTest, null), NullPointerException.class);
    hashTest.hasHashEntries = false;
    assertFails(() -> hashLib.readHashValue(hashTest, 1), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.readable = (k) -> false;
    assertFails(() -> hashLib.readHashValue(hashTest, 1), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.readable = null;
    hashTest.data.put(1, new Object());
    assertFails(() -> hashLib.readHashValue(hashTest, 1), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.readable = (k) -> true;
    hashTest.data = null;
    assertFails(() -> hashLib.readHashValue(hashTest, 1), AssertionError.class);
    hashTest.hasHashEntries = true;
    hashTest.readable = null;
    hashTest.data = Collections.singletonMap(1, -1);
    assertFails(() -> hashLib.readHashValue(hashTest, 2), UnknownKeyException.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