Mercurial > hg > truffle
diff truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22139:597953a8e6f0
Testing behavior of primitive types returned from an interop method.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 09 Sep 2015 19:18:44 +0200 |
parents | a583d7ffd285 |
children | 92906003d607 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java Wed Sep 09 18:53:14 2015 +0200 +++ b/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java Wed Sep 09 19:18:44 2015 +0200 @@ -347,6 +347,72 @@ } @Test + public void testPrimitiveReturnTypeByte() throws Exception { + TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); + + byte value = (byte) RANDOM.nextInt(100); + + TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); + Number n = apply.invoke(null, fn).as(Number.class); + assertEquals("The same value returned", value + 10, n.byteValue()); + } + + @Test + public void testPrimitiveReturnTypeShort() throws Exception { + TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); + + short value = (short) RANDOM.nextInt(100); + + TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); + Number n = apply.invoke(null, fn).as(Number.class); + assertEquals("The same value returned", value + 10, n.shortValue()); + } + + @Test + public void testPrimitiveReturnTypeInt() throws Exception { + TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); + + int value = RANDOM.nextInt(100); + + TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); + Number n = apply.invoke(null, fn).as(Number.class); + assertEquals("The same value returned", value + 10, n.intValue()); + } + + @Test + public void testPrimitiveReturnTypeLong() throws Exception { + TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); + + long value = RANDOM.nextInt(1000); + + TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); + Number n = apply.invoke(null, fn).as(Number.class); + assertEquals("The same value returned", value + 10, n.longValue()); + } + + @Test + public void testPrimitiveReturnTypeFloat() throws Exception { + TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); + + float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); + + TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); + Number n = apply.invoke(null, fn).as(Number.class); + assertEquals("The same value returned", value + 10, n.floatValue(), 0.01); + } + + @Test + public void testPrimitiveReturnTypeDouble() throws Exception { + TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers()); + + double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); + + TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); + Number n = apply.invoke(null, fn).as(Number.class); + assertEquals("The same value returned", value + 10, n.doubleValue(), 0.01); + } + + @Test public void testCoExistanceOfMultipleLanguageInstances() throws Exception { final String countMethod = countInvocations(); TruffleVM.Symbol count1 = findGlobalSymbol(countMethod);