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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations