Mercurial > hg > rhino-tests
changeset 354:6fcf6a73fde4 draft
Several new tests added into InvocableTest.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Thu, 24 Apr 2014 10:01:24 +0200 |
parents | 6cb1ff232c39 |
children | 80ea8e60703a |
files | ChangeLog src/org/RhinoTests/InvocableTest.java |
diffstat | 2 files changed, 68 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Apr 15 13:19:41 2014 +0200 +++ b/ChangeLog Thu Apr 24 10:01:24 2014 +0200 @@ -1,3 +1,8 @@ +2014-04-24 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/InvocableTest.java: + Several new tests added into InvocableTest. + 2014-04-15 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/BindingsTest.java:
--- a/src/org/RhinoTests/InvocableTest.java Tue Apr 15 13:19:41 2014 +0200 +++ b/src/org/RhinoTests/InvocableTest.java Thu Apr 24 10:01:24 2014 +0200 @@ -1,7 +1,7 @@ /* Rhino test framework - Copyright (C) 2011 Red Hat + Copyright (C) 2011, 2012, 2013, 2014 Red Hat This file is part of IcedTea. @@ -83,6 +83,36 @@ protected void testInvokeFunction() throws ScriptException, NoSuchMethodException { final String script = "function foo() {" + + "}"; + this.scriptEngine.eval(script); + this.invocableEngine.invokeFunction("foo"); + } + + /** + * Test the JavaScript method invocation. + * + * @throws ScriptException in case there's something wrong in JS engine. + * @throws NoSuchMethodException if wrong method is called. + */ + protected void testInvokeFunction2() throws ScriptException, NoSuchMethodException { + final String script = + "function foo() {" + + " println('\tHello, world!');" + + "}"; + this.scriptEngine.eval(script); + this.invocableEngine.invokeFunction("foo"); + } + + /** + * Test the JavaScript method invocation. + * + * @throws ScriptException in case there's something wrong in JS engine. + * @throws NoSuchMethodException if wrong method is called. + */ + protected void testInvokeFunction3() throws ScriptException, NoSuchMethodException { + final String script = + "function foo() {" + + " println('\tHello, world!');" + " println('\tHello, world!');" + "}"; this.scriptEngine.eval(script); @@ -126,6 +156,36 @@ } /** + * Test invocation of method containing parameters. + * + * @throws ScriptException in case there's something wrong in JS engine. + * @throws NoSuchMethodException if wrong method is called. + */ + protected void testInvokeFunctionWithParameters2() throws ScriptException, NoSuchMethodException { + final String script = + "function printHello(str1, val2) {" + + " println('\t' + str1 + ' ' + val2);" + + "}"; + this.scriptEngine.eval(script); + this.invocableEngine.invokeFunction("printHello", "hello", 42); + } + + /** + * Test invocation of method containing parameters. + * + * @throws ScriptException in case there's something wrong in JS engine. + * @throws NoSuchMethodException if wrong method is called. + */ + protected void testInvokeFunctionWithParameters3() throws ScriptException, NoSuchMethodException { + final String script = + "function printHello(val1, str2) {" + + " println('\t' + val1 + ' ' + str2);" + + "}"; + this.scriptEngine.eval(script); + this.invocableEngine.invokeFunction("printHello", 42, "world!"); + } + + /** * Prints all properties of Java object. * * @throws ScriptException in case there's something wrong in JS engine. @@ -234,6 +294,8 @@ assertTrue(result.doubleValue() == 4.6, "function returns incorrect value " + result); result = (Double)this.invocableEngine.invokeFunction("plus", Double.valueOf(0), Double.valueOf(1.1)); assertTrue(result.doubleValue() == 1.1, "function returns incorrect value " + result); + result = (Double)this.invocableEngine.invokeFunction("plus", Double.valueOf(1.1), Double.valueOf(0)); + assertTrue(result.doubleValue() == 1.1, "function returns incorrect value " + result); result = (Double)this.invocableEngine.invokeFunction("plus", Double.valueOf(-1.234), Double.valueOf(1.234)); assertTrue(result.doubleValue() == 0, "function returns incorrect value " + result); }