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