Search in sources :

Example 1 with Message

use of com.oracle.truffle.api.library.Message in project graal by oracle.

the class MessageTest method testM0Properties.

@Test
public void testM0Properties() throws ClassNotFoundException {
    Message m0 = Message.resolve(MessageLibrary.class, "m0");
    assertSame(MessageLibrary.class, m0.getLibraryClass());
    assertEquals(MessageLibrary.class.getName(), m0.getLibraryName());
    assertEquals(Arrays.asList(Object.class, String.class, int.class), m0.getParameterTypes());
    assertEquals(MessageLibrary.class.getName() + ".m0", m0.getQualifiedName());
    assertSame(Object.class, m0.getReceiverType());
    assertSame(String.class, m0.getReturnType());
    assertSame(m0.getSimpleName().intern(), m0.getSimpleName());
    assertSame(m0.getQualifiedName().intern(), m0.getQualifiedName());
    assertSame(Class.forName(MessageLibrary.class.getName()), m0.getLibraryClass());
    assertEquals("m0", m0.getSimpleName());
    Message m1 = Message.resolve(MessageLibrary.class, "m1");
    assertNotEquals(m0.hashCode(), m1.hashCode());
    assertEquals(m0.hashCode(), m0.hashCode());
    assertTrue(m0.equals(m0));
    assertFalse(m0.equals(m1));
    assertNotNull(m0.toString());
    assertNotNull(m1.toString());
}
Also used : Message(com.oracle.truffle.api.library.Message) Test(org.junit.Test)

Example 2 with Message

use of com.oracle.truffle.api.library.Message in project graal by oracle.

the class ReflectionTest method testReflectionOnObject.

@Test
public void testReflectionOnObject() throws Exception {
    ReflectiveObject object = new ReflectiveObject();
    ReflectionLibrary reflection = createLibrary(ReflectionLibrary.class, object);
    Message primitive = Message.resolve(ReflectionTestLibrary.class, "primitive");
    // TODO more tests necessary
    Assert.assertEquals(11, (int) reflection.send(object, primitive, 11));
    try {
        reflection.send(object, primitive, new Object());
        Assert.fail();
    } catch (ClassCastException e) {
    }
    try {
        reflection.send(object, primitive, 11, new Object());
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
}
Also used : Message(com.oracle.truffle.api.library.Message) ExportMessage(com.oracle.truffle.api.library.ExportMessage) ReflectionLibrary(com.oracle.truffle.api.library.ReflectionLibrary) Test(org.junit.Test) AbstractParametrizedLibraryTest(com.oracle.truffle.api.test.AbstractParametrizedLibraryTest)

Example 3 with Message

use of com.oracle.truffle.api.library.Message in project graal by oracle.

the class ReflectiveCallExample method runExample.

@Test
public void runExample() throws Exception {
    ReflectionLibrary reflection = ReflectionLibrary.getFactory().getUncached();
    Object value = new UnknownObject();
    // reflective lookup of the message.
    // might be a good idea to cache in a singleton.
    Message targetMessage = Message.resolve(ReflectiveCallTestLibrary.class, "message");
    assertEquals("result", reflection.send(value, targetMessage));
}
Also used : ExportMessage(com.oracle.truffle.api.library.ExportMessage) Message(com.oracle.truffle.api.library.Message) ReflectionLibrary(com.oracle.truffle.api.library.ReflectionLibrary) Test(org.junit.Test)

Example 4 with Message

use of com.oracle.truffle.api.library.Message in project graal by oracle.

the class MessageIdTest method testMessageIds.

@Test
public void testMessageIds() {
    List<Message> messages = MessageIdTestLibrary.FACTORY.getMessages();
    assertEquals(5, messages.size());
    int id = 0;
    for (Message message : messages) {
        assertEquals(id++, message.getId());
    }
}
Also used : Message(com.oracle.truffle.api.library.Message) Test(org.junit.Test)

Example 5 with Message

use of com.oracle.truffle.api.library.Message in project graal by oracle.

the class ReflectionTest method testReflectionDefault.

@Test
public void testReflectionDefault() throws Exception {
    Object receiver = new Object();
    ReflectionLibrary reflection = createLibrary(ReflectionLibrary.class, receiver);
    Message primitive = Message.resolve(ReflectionTestLibrary.class, "primitive");
    Message voidReturn = Message.resolve(ReflectionTestLibrary.class, "voidReturn");
    Assert.assertEquals(42, reflection.send(receiver, primitive, 12));
    try {
        reflection.send(receiver, voidReturn);
        Assert.fail();
    } catch (AbstractMethodError e) {
    }
}
Also used : Message(com.oracle.truffle.api.library.Message) ExportMessage(com.oracle.truffle.api.library.ExportMessage) ReflectionLibrary(com.oracle.truffle.api.library.ReflectionLibrary) Test(org.junit.Test) AbstractParametrizedLibraryTest(com.oracle.truffle.api.test.AbstractParametrizedLibraryTest)

Aggregations

Message (com.oracle.truffle.api.library.Message)5 Test (org.junit.Test)5 ExportMessage (com.oracle.truffle.api.library.ExportMessage)3 ReflectionLibrary (com.oracle.truffle.api.library.ReflectionLibrary)3 AbstractParametrizedLibraryTest (com.oracle.truffle.api.test.AbstractParametrizedLibraryTest)2