private void doPlusWithInts(int a, int b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(int.class, int.class)); Number n = plus.execute(a, b).as(Number.class); assert a + b == n.intValue() : "(" + a + " + " + b + ") = " + n.intValue(); }
private void doPlusWithShorts(int a, int b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(short.class, short.class)); Number n = plus.execute((short) a, (short) b).as(Number.class); assert a + b == n.intValue() : "(" + a + " + " + b + ") = " + n.intValue(); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityFloat() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); Number n = (Number) apply.execute(value).get(); assertDouble("The same value returned", value, n.floatValue()); }
private void doPlusWithFloat(float a, float b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(float.class, float.class)); Number n = plus.execute(a, b).as(Number.class); assertDouble("Correct value computed: (" + a + " + " + b + ")", a + b, n.floatValue()); }
@Test public void testNull() throws Exception { if (getClass() == TruffleTCK.class) { return; } TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull()); Object res = retNull.invoke(null); assertNull("Should yield real Java null", res); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityByte() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); byte value = (byte) RANDOM.nextInt(100); Number n = (Number) apply.execute(value).get(); assertEquals("The same value returned", value, n.byteValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityInt() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); int value = RANDOM.nextInt(100); Number n = (Number) apply.execute(value).get(); assertEquals("The same value returned", value, n.intValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveReturnTypeFloat() throws Exception { PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); Number n = apply.execute(fn).as(Number.class); assertDouble("The same value returned (" + value + " + 10): ", value + 10, n.floatValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveReturnTypeDouble() throws Exception { PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); Number n = apply.execute(fn).as(Number.class); assertDouble("The same value returned (" + value + " + 10): ", value + 10, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityBoxedString() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); String value = "Value" + RANDOM.nextInt(1000) + RANDOM.nextDouble(); BoxedValue boxed = new BoxedValue(value); String ret = (String) apply.execute(boxed).get(); assertEquals("The same value returned", value, ret); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveReturnTypeByte() throws Exception { PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); byte value = (byte) RANDOM.nextInt(100); TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); Number n = apply.execute(fn).as(Number.class); assertEquals("The same value returned (" + value + " + 10): ", value + 10, n.byteValue()); }
/** @since 0.8 or earlier */ @Test public void testSumRealOfComplexNumbersB() throws Exception { String id = complexSumReal(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); ComplexNumbersB numbers = new ComplexNumbersB(new double[]{2, 30, 10}, new double[]{-1, -1, -1}); Number n = (Number) apply.execute(numbers).get(); assertDouble("The same value returned", 42.0, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testMaxOrMinValue() throws Exception { PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true)); Object res = apply.execute(fn).get(); assert res instanceof Number : "result should be a number: " + res; Number n = (Number) res; assert 42 == n.intValue() : "32 > 18 and plus 10"; }
/** @since 0.16 */ @Test public void testGetSize() throws Exception { String id = objectWithElement(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); List<?> object = JavaInterop.asJavaObject(List.class, (TruffleObject) apply.execute().get()); Assert.assertEquals(4, object.size()); }
/** @since 0.8 or earlier */ @Test public void testNull() throws Exception { PolyglotEngine.Value retNull = findGlobalSymbol(returnsNull()); Object res = retNull.execute().get(); assertNull("Should yield real Java null", res); }
/** @since 0.16 */ @Test public void testReadValueFromForeign() throws Exception { String id = readValueFromForeign(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); Assert.assertEquals(42.0, ((Number) apply.execute(JavaInterop.asTruffleObject(new TestObject(42.0))).get()).doubleValue(), 0.1); }
/** @since 0.8 or earlier */ @Test public void readWriteFloatValue() throws Exception { String id = valuesObject(); ValuesObject values = findGlobalSymbol(id).execute().as(ValuesObject.class); assertDouble("Zero", 0, values.floatValue()); final float value = RANDOM.nextFloat() * 1000.0f; values.floatValue(value); assertDouble("Correct value", value, values.floatValue()); }
/** @since 0.8 or earlier */ @Test public void readWriteIntValue() throws Exception { String id = valuesObject(); ValuesObject values = findGlobalSymbol(id).execute().as(ValuesObject.class); assertEquals("Zero", 0, values.intValue()); final int value = RANDOM.nextInt(); values.intValue(value); assertEquals("Correct value", value, values.intValue()); }
/** @since 0.8 or earlier */ @Test public void readWriteDoubleValue() throws Exception { String id = valuesObject(); ValuesObject values = findGlobalSymbol(id).execute().as(ValuesObject.class); assertDouble("Zero", 0, values.doubleValue()); final double value = RANDOM.nextDouble() * 1000.0; values.doubleValue(value); assertDouble("Correct value", value, values.doubleValue()); }
/** @since 0.16 */ @Test public void testHasSize() throws Exception { String id = objectWithElement(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); MessageInterface object = JavaInterop.asJavaObject(MessageInterface.class, (TruffleObject) apply.execute().get()); Assert.assertEquals(true, object.hasSize()); }