Skip to content
Snippets Groups Projects
Commit 05c3b530 authored by stepan's avatar stepan
Browse files

Update interop tests

parent 94e313d1
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,10 @@ public abstract class AbstractMRTest {
return false;
}
protected boolean testToNative(TruffleObject obj) {
return true;
}
protected int getSize(@SuppressWarnings("unused") TruffleObject obj) {
throw new UnsupportedOperationException("override if hasSize returns true");
}
......@@ -123,6 +127,9 @@ public abstract class AbstractMRTest {
@Test
public void testNativePointer() throws Exception {
for (TruffleObject obj : createTruffleObjects()) {
if (!testToNative(obj)) {
continue;
}
try {
assertTrue(obj.getClass().getSimpleName(), ForeignAccess.sendToNative(Message.TO_NATIVE.createNode(), obj) == obj);
} catch (UnsupportedMessageException unsupportedMessageException) {
......
......@@ -26,13 +26,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Assert;
import org.junit.Test;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.data.RInteropScalar;
import org.junit.Assert;
public class RInteropScalarMRTest extends AbstractMRTest {
......@@ -67,6 +67,11 @@ public class RInteropScalarMRTest extends AbstractMRTest {
return true;
}
@Override
protected boolean isPointer(TruffleObject obj) {
return false;
}
@Override
protected Object getUnboxed(TruffleObject obj) {
RInteropScalar is = (RInteropScalar) obj;
......
......@@ -37,6 +37,8 @@ import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.java.JavaInterop;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RObject;
import com.oracle.truffle.r.runtime.data.RVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
......@@ -101,6 +103,11 @@ public class VectorMRTest extends AbstractMRTest {
return create("as.numeric()");
}
@Override
protected boolean testToNative(TruffleObject obj) {
return obj instanceof RObject;
}
@Override
protected boolean isBoxed(TruffleObject obj) {
return ((RAbstractVector) obj).getLength() == 1;
......@@ -122,6 +129,11 @@ public class VectorMRTest extends AbstractMRTest {
return ((RAbstractVector) obj).getLength();
}
@Override
protected boolean isPointer(TruffleObject obj) {
return obj instanceof RVector<?>;
}
private static TruffleObject create(String createTxt) throws Exception {
Source src = Source.newBuilder(createTxt).mimeType("text/x-r").name("test.R").build();
return engine.eval(src).as(RAbstractVector.class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment