diff --git a/scripting/workben/data/doc_with_beanshell_scripts.sxw b/scripting/workben/data/doc_with_beanshell_scripts.sxw new file mode 100644 index 000000000000..f0066610d577 Binary files /dev/null and b/scripting/workben/data/doc_with_beanshell_scripts.sxw differ diff --git a/scripting/workben/data/testdata/Function.csv b/scripting/workben/data/testdata/Function.csv index cab21fdc7c33..b924c86f4bd6 100644 --- a/scripting/workben/data/testdata/Function.csv +++ b/scripting/workben/data/testdata/Function.csv @@ -1 +1,4 @@ -_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 diff --git a/scripting/workben/ifc/scripting/_XFunction.java b/scripting/workben/ifc/scripting/_XFunction.java index 431127ce7c18..d871ac9bfcc8 100644 --- a/scripting/workben/ifc/scripting/_XFunction.java +++ b/scripting/workben/ifc/scripting/_XFunction.java @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -62,6 +62,7 @@ package ifc.script.framework.provider; 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.lang.XMultiServiceFactory; @@ -81,10 +82,18 @@ import java.util.Iterator; public class _XFunction extends MultiMethodTest { public XFunction oObj = null; + public XFunctionProvider oProvider = null; + /** * Retrieves object relation. */ 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() { @@ -111,8 +120,18 @@ public class _XFunction extends MultiMethodTest { private boolean runInvokeTest(Parameters testdata) { 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 output = ""; + boolean result = true; log.println(testdata.get("description")); @@ -123,7 +142,19 @@ public class _XFunction extends MultiMethodTest { Object[][] aOutParam = new Object[1][]; 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"; } catch (com.sun.star.lang.IllegalArgumentException iae) { @@ -147,10 +178,26 @@ public class _XFunction extends MultiMethodTest { 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); - if (output.equals(expected)) - return true; - else - return false; + if (!output.equals(expected)) + result = false; + + return result; } } diff --git a/scripting/workben/ifc/scripting/_XScriptInfoAccess.java b/scripting/workben/ifc/scripting/_XScriptInfoAccess.java index a286966c1fcd..e667ed519a4f 100644 --- a/scripting/workben/ifc/scripting/_XScriptInfoAccess.java +++ b/scripting/workben/ifc/scripting/_XScriptInfoAccess.java @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -119,7 +119,7 @@ public class _XScriptInfoAccess extends MultiMethodTest { log.println(testdata.get("description")); - try { + // try { log.println("In _XScriptInfoAccess.getScriptLogicalNames()"); String[] logicalNames = oObj.getScriptLogicalNames(); @@ -135,11 +135,11 @@ public class _XScriptInfoAccess extends MultiMethodTest { } } } - } - catch (com.sun.star.uno.Exception e) { - log.println("Caught UNO Exception :" + e); - output = "com.sun.star.uno.Exception"; - } + // } + // catch (com.sun.star.uno.Exception e) { + // log.println("Caught UNO Exception :" + e); + // output = "com.sun.star.uno.Exception"; + // } log.println("expected: " + expected + ", output: " + output); if (output.equals(expected)) diff --git a/scripting/workben/ifc/scripting/_XScriptSecurity.java b/scripting/workben/ifc/scripting/_XScriptSecurity.java index e28a1e5431be..e5a9a0d44d0d 100644 --- a/scripting/workben/ifc/scripting/_XScriptSecurity.java +++ b/scripting/workben/ifc/scripting/_XScriptSecurity.java @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -200,14 +200,8 @@ public class _XScriptSecurity extends MultiMethodTest { try { String uri = util.utils.getFullTestURL(location); - if ( oObj.checkPermission(uri, "execute" ) ) - { - output = "true"; - } - else - { - output = "false"; - } + oObj.checkPermission(uri, "execute" ); + output = "true"; } catch (com.sun.star.security.AccessControlException ace) { log.println("Couldn't invoke script:" + ace); diff --git a/scripting/workben/mod/_scripting/Function.java b/scripting/workben/mod/_scripting/Function.java index fabbaa5a8352..2f906debdf49 100644 --- a/scripting/workben/mod/_scripting/Function.java +++ b/scripting/workben/mod/_scripting/Function.java @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -83,27 +83,30 @@ import drafts.com.sun.star.script.framework.provider.XFunction; import drafts.com.sun.star.script.framework.provider.XFunctionProvider; public class Function extends TestCase { - //private String script = "script://MemoryUtils.MemUsage"; - private String script = "script://HighlightText.showForm"; + private String script = "script://returns-Integer"; + private String doc = "doc_with_beanshell_scripts.sxw"; + public void initialize( TestParameters tParam, PrintWriter log ) { } public synchronized TestEnvironment createTestEnvironment( TestParameters tParam, PrintWriter log ) throws StatusException { XInterface oObj = null; - log.println("creating test environment"); + XFunctionProvider provider = null; + + log.println("creating test environment"); try { XMultiServiceFactory xMSF = tParam.getMSF(); SOfficeFactory SOF = null; SOF = SOfficeFactory.getFactory( xMSF ); - String docPath = util.utils.getFullTestURL( "ExampleSpreadSheetLatest.sxc" ); + String docPath = util.utils.getFullTestURL(doc); XComponent doc = SOF.loadDocument( docPath ); XModel model = ( XModel ) UnoRuntime.queryInterface( XModel.class, doc ); oObj = (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 ); } catch (com.sun.star.uno.Exception e) { @@ -112,6 +115,7 @@ public class Function extends TestCase { } TestEnvironment tEnv = new TestEnvironment(oObj) ; + tEnv.addObjRelation("provider", provider); TestDataLoader.setupData(tEnv, "Function"); return tEnv ;