Kaydet (Commit) 93b11bc7 authored tarafından Tomas O'Connor's avatar Tomas O'Connor

Add beanshell tests and test of return values from beanshell scripts

üst b658df41
_invoke;description=Try to invoke a valid XFunction;expected=success _invoke;description=Try to find and invoke a valid user level XFunction;logicalname=script://HighlightText.showForm;expected=success
_invoke;description=Try to invoke a valid beanshell XFunction that returns an Integer;logicalname=script://returns-Integer;returntype=java.lang.Integer;expected=success
_invoke;description=Try to invoke a valid beanshell XFunction that returns a String;logicalname=script://returns-String;returntype=java.lang.String;returnvalue=testing;expected=success
_invoke;description=Try to invoke a valid beanshell XFunction that returns a Frame;logicalname=script://returns-Frame;expected=com.sun.star.uno.RuntimeException
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XFunction.java,v $ * $RCSfile: _XFunction.java,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change:$Date: 2002-12-10 14:12:05 $ * last change:$Date: 2003-03-25 16:55:03 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
package ifc.script.framework.provider; package ifc.script.framework.provider;
import drafts.com.sun.star.script.framework.provider.XFunction; import drafts.com.sun.star.script.framework.provider.XFunction;
import drafts.com.sun.star.script.framework.provider.XFunctionProvider;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
...@@ -81,10 +82,18 @@ import java.util.Iterator; ...@@ -81,10 +82,18 @@ import java.util.Iterator;
public class _XFunction extends MultiMethodTest { public class _XFunction extends MultiMethodTest {
public XFunction oObj = null; public XFunction oObj = null;
public XFunctionProvider oProvider = null;
/** /**
* Retrieves object relation. * Retrieves object relation.
*/ */
public void before() throws StatusException { public void before() throws StatusException {
log.println("getting provider");
oProvider = (XFunctionProvider) tEnv.getObjRelation("provider");
if (oProvider == null)
log.println("it's null");
else
log.println("it's not null");
} }
public void _invoke() { public void _invoke() {
...@@ -111,8 +120,18 @@ public class _XFunction extends MultiMethodTest { ...@@ -111,8 +120,18 @@ public class _XFunction extends MultiMethodTest {
private boolean runInvokeTest(Parameters testdata) { private boolean runInvokeTest(Parameters testdata) {
String description = testdata.get("description"); String description = testdata.get("description");
String logicalname = testdata.get("logicalname");
String expreturntype = testdata.get("returntype");
String expreturnvalue = testdata.get("returnvalue");
String gotreturntype = "null";
String gotreturnvalue = "null";
String location = testdata.get("location");
String expected = testdata.get("expected"); String expected = testdata.get("expected");
String output = ""; String output = "";
boolean result = true;
log.println(testdata.get("description")); log.println(testdata.get("description"));
...@@ -123,7 +142,19 @@ public class _XFunction extends MultiMethodTest { ...@@ -123,7 +142,19 @@ public class _XFunction extends MultiMethodTest {
Object[][] aOutParam = new Object[1][]; Object[][] aOutParam = new Object[1][];
aOutParam[0] = new Object[0]; aOutParam[0] = new Object[0];
oObj.invoke( aParams, aOutParamIndex, aOutParam ); XFunction func = oProvider.getFunction(logicalname);
if (func == null) {
log.println("Couldn't get XFunction for:" + logicalname);
return false;
}
Object ret = func.invoke( aParams, aOutParamIndex, aOutParam );
if (ret != null) {
gotreturntype = ret.getClass().getName();
gotreturnvalue = ret.toString();
}
output = "success"; output = "success";
} }
catch (com.sun.star.lang.IllegalArgumentException iae) { catch (com.sun.star.lang.IllegalArgumentException iae) {
...@@ -147,10 +178,26 @@ public class _XFunction extends MultiMethodTest { ...@@ -147,10 +178,26 @@ public class _XFunction extends MultiMethodTest {
output = "java.lang.Exception"; output = "java.lang.Exception";
} }
if (expreturntype != null) {
log.println("expected return type: " + expreturntype +
", got return type: " + gotreturntype);
if (!gotreturntype.equals(expreturntype))
result = false;
}
if (expreturnvalue != null) {
log.println("expected return value: " + expreturnvalue +
", got return value: " + gotreturnvalue);
if (!gotreturnvalue.equals(expreturnvalue))
result = false;
}
log.println("expected: " + expected + ", output: " + output); log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected)) if (!output.equals(expected))
return true; result = false;
else
return false; return result;
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XScriptInfoAccess.java,v $ * $RCSfile: _XScriptInfoAccess.java,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change:$Date: 2002-12-10 14:12:05 $ * last change:$Date: 2003-03-25 16:55:04 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -119,7 +119,7 @@ public class _XScriptInfoAccess extends MultiMethodTest { ...@@ -119,7 +119,7 @@ public class _XScriptInfoAccess extends MultiMethodTest {
log.println(testdata.get("description")); log.println(testdata.get("description"));
try { // try {
log.println("In _XScriptInfoAccess.getScriptLogicalNames()"); log.println("In _XScriptInfoAccess.getScriptLogicalNames()");
String[] logicalNames = oObj.getScriptLogicalNames(); String[] logicalNames = oObj.getScriptLogicalNames();
...@@ -135,11 +135,11 @@ public class _XScriptInfoAccess extends MultiMethodTest { ...@@ -135,11 +135,11 @@ public class _XScriptInfoAccess extends MultiMethodTest {
} }
} }
} }
} // }
catch (com.sun.star.uno.Exception e) { // catch (com.sun.star.uno.Exception e) {
log.println("Caught UNO Exception :" + e); // log.println("Caught UNO Exception :" + e);
output = "com.sun.star.uno.Exception"; // output = "com.sun.star.uno.Exception";
} // }
log.println("expected: " + expected + ", output: " + output); log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected)) if (output.equals(expected))
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XScriptSecurity.java,v $ * $RCSfile: _XScriptSecurity.java,v $
* *
* $Revision: 1.5 $ * $Revision: 1.6 $
* *
* last change:$Date: 2003-03-25 11:26:59 $ * last change:$Date: 2003-03-25 16:55:04 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -200,14 +200,8 @@ public class _XScriptSecurity extends MultiMethodTest { ...@@ -200,14 +200,8 @@ public class _XScriptSecurity extends MultiMethodTest {
try { try {
String uri = util.utils.getFullTestURL(location); String uri = util.utils.getFullTestURL(location);
if ( oObj.checkPermission(uri, "execute" ) ) oObj.checkPermission(uri, "execute" );
{ output = "true";
output = "true";
}
else
{
output = "false";
}
} }
catch (com.sun.star.security.AccessControlException ace) { catch (com.sun.star.security.AccessControlException ace) {
log.println("Couldn't invoke script:" + ace); log.println("Couldn't invoke script:" + ace);
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: Function.java,v $ * $RCSfile: Function.java,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change:$Date: 2003-03-25 11:26:53 $ * last change:$Date: 2003-03-25 16:55:06 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -83,27 +83,30 @@ import drafts.com.sun.star.script.framework.provider.XFunction; ...@@ -83,27 +83,30 @@ import drafts.com.sun.star.script.framework.provider.XFunction;
import drafts.com.sun.star.script.framework.provider.XFunctionProvider; import drafts.com.sun.star.script.framework.provider.XFunctionProvider;
public class Function extends TestCase { public class Function extends TestCase {
//private String script = "script://MemoryUtils.MemUsage"; private String script = "script://returns-Integer";
private String script = "script://HighlightText.showForm"; private String doc = "doc_with_beanshell_scripts.sxw";
public void initialize( TestParameters tParam, PrintWriter log ) { public void initialize( TestParameters tParam, PrintWriter log ) {
} }
public synchronized TestEnvironment createTestEnvironment( public synchronized TestEnvironment createTestEnvironment(
TestParameters tParam, PrintWriter log ) throws StatusException { TestParameters tParam, PrintWriter log ) throws StatusException {
XInterface oObj = null; XInterface oObj = null;
log.println("creating test environment"); XFunctionProvider provider = null;
log.println("creating test environment");
try { try {
XMultiServiceFactory xMSF = tParam.getMSF(); XMultiServiceFactory xMSF = tParam.getMSF();
SOfficeFactory SOF = null; SOfficeFactory SOF = null;
SOF = SOfficeFactory.getFactory( xMSF ); SOF = SOfficeFactory.getFactory( xMSF );
String docPath = util.utils.getFullTestURL( "ExampleSpreadSheetLatest.sxc" ); String docPath = util.utils.getFullTestURL(doc);
XComponent doc = SOF.loadDocument( docPath ); XComponent doc = SOF.loadDocument( docPath );
XModel model = ( XModel ) UnoRuntime.queryInterface( XModel.class, XModel model = ( XModel ) UnoRuntime.queryInterface( XModel.class,
doc ); doc );
oObj = oObj =
(XInterface)xMSF.createInstanceWithArguments( "drafts.com.sun.star.script.framework.provider.FunctionProvider", new Object[]{ model } ); (XInterface)xMSF.createInstanceWithArguments( "drafts.com.sun.star.script.framework.provider.FunctionProvider", new Object[]{ model } );
XFunctionProvider provider = ( XFunctionProvider )UnoRuntime.queryInterface( XFunctionProvider.class, oObj ); provider = ( XFunctionProvider )UnoRuntime.queryInterface( XFunctionProvider.class, oObj );
oObj = provider.getFunction( script ); oObj = provider.getFunction( script );
} catch (com.sun.star.uno.Exception e) { } catch (com.sun.star.uno.Exception e) {
...@@ -112,6 +115,7 @@ public class Function extends TestCase { ...@@ -112,6 +115,7 @@ public class Function extends TestCase {
} }
TestEnvironment tEnv = new TestEnvironment(oObj) ; TestEnvironment tEnv = new TestEnvironment(oObj) ;
tEnv.addObjRelation("provider", provider);
TestDataLoader.setupData(tEnv, "Function"); TestDataLoader.setupData(tEnv, "Function");
return tEnv ; return tEnv ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment