diff truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 21960:a88981c5ce8b

Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 18 Jun 2015 16:09:38 +0200
parents 9c8c0937da41
children e7c2d36daf72
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java	Wed Jun 17 13:39:26 2015 -0700
+++ b/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java	Thu Jun 18 16:09:38 2015 +0200
@@ -92,6 +92,16 @@
     protected abstract String plusInt();
 
     /**
+     * Name of a function in your language to perform a callback to foreign function. Your function
+     * should prepare two numbers (18 and 32) and apply them to the function passed in as an
+     * argument of your function. It should then add 10 to the returned value and return the result
+     * back to its caller.
+     *
+     * @return name of globally exported symbol
+     */
+    protected abstract String applyNumbers();
+
+    /**
      * Return a code snippet that is invalid in your language. Its
      * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield
      * an exception.
@@ -161,6 +171,32 @@
         fail("Should yield IOException, but returned " + ret);
     }
 
+    @Test
+    public void testMaxOrMinValue() throws Exception {
+        TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
+
+        Object res = apply.invoke(null, new MaxMinObject(true));
+
+        assert res instanceof Number : "result should be a number: " + res;
+
+        Number n = (Number) res;
+
+        assert 42 == n.intValue() : "32 > 18 and plus 10";
+    }
+
+    @Test
+    public void testMaxOrMinValue2() throws Exception {
+        TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
+
+        Object res = apply.invoke(null, new MaxMinObject(false));
+
+        assert res instanceof Number : "result should be a number: " + res;
+
+        Number n = (Number) res;
+
+        assert 28 == n.intValue() : "18 < 32 and plus 10";
+    }
+
     private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception {
         TruffleVM.Symbol s = vm().findGlobalSymbol(name);
         assert s != null : "Symbol " + name + " is not found!";