diff options
Diffstat (limited to 'scripting/workben/ifc/scripting')
-rw-r--r-- | scripting/workben/ifc/scripting/ScriptingUtils.java | 124 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/SecurityDialogUtil.java | 176 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XFunction.java | 169 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XFunctionProvider.java | 101 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptInfo.java | 331 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptInfoAccess.java | 228 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptInvocation.java | 232 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptNameResolver.java | 186 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptSecurity.java | 409 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptStorageManager.java | 267 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/_XScriptStorageRefresh.java | 90 | ||||
-rw-r--r-- | scripting/workben/ifc/scripting/makefile.mk | 40 |
12 files changed, 2353 insertions, 0 deletions
diff --git a/scripting/workben/ifc/scripting/ScriptingUtils.java b/scripting/workben/ifc/scripting/ScriptingUtils.java new file mode 100644 index 000000000000..3ccdab02e2c9 --- /dev/null +++ b/scripting/workben/ifc/scripting/ScriptingUtils.java @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework; + +import java.io.File; +import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.XComponentContext; + +public class ScriptingUtils { + private XScriptStorageManager storageManager; + private static ScriptingUtils utils; + + private ScriptingUtils() { + } + + public static ScriptingUtils getDefault() { + if (utils == null) { + synchronized (ScriptingUtils.class) { + if (utils == null) + utils = new ScriptingUtils(); + } + } + return utils; + } + + public static void cleanUserDir() { + } + + public static void cleanShareDir() { + } + + public Object getScriptStorage(XMultiServiceFactory xMSF, String location) { + int id = getStorageId(xMSF, location); + return storageManager.getScriptStorage(id); + } + + public int getStorageId(XMultiServiceFactory xMSF, String location) { + + if (location.equals("share")) + return 0; + + if (location.equals("user")) + return 1; + + XSimpleFileAccess access = null; + String uri = util.utils.getFullTestURL(location); + + if (storageManager == null) { + try { + XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet.class, xMSF); + + XComponentContext xContext = (XComponentContext) + UnoRuntime.queryInterface(XComponentContext.class, + xProp.getPropertyValue("DefaultContext")); + + XInterface ifc = (XInterface) + xContext.getValueByName("/singletons/drafts.com.sun.star." + + "script.framework.storage.theScriptStorageManager"); + + storageManager = (XScriptStorageManager) + UnoRuntime.queryInterface(XScriptStorageManager.class, ifc); + } + catch( Exception e ) { + return -1; + } + } + + access = getXSimpleFileAccess(xMSF); + if (access == null) + return -1; + + int id = storageManager.createScriptStorageWithURI(access, uri); + + return id; + } + + public XSimpleFileAccess getXSimpleFileAccess(XMultiServiceFactory xMSF) { + XSimpleFileAccess access = null; + + try { + Object fa = + xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); + + access = (XSimpleFileAccess) + UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); + } + catch (com.sun.star.uno.Exception e) { + return null; + } + return access; + } +} diff --git a/scripting/workben/ifc/scripting/SecurityDialogUtil.java b/scripting/workben/ifc/scripting/SecurityDialogUtil.java new file mode 100644 index 000000000000..ae7adb4bf696 --- /dev/null +++ b/scripting/workben/ifc/scripting/SecurityDialogUtil.java @@ -0,0 +1,176 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package ifc.script.framework; + +import com.sun.star.awt.*; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import drafts.com.sun.star.accessibility.*; +import drafts.com.sun.star.awt.XExtendedToolkit; + +// Jsuite classes +import util.AccessibilityTools; +import util.dbg; +/** +* Thread that pushes the buttons or checkbox +* on the message box that is on top. +*/ +public class SecurityDialogUtil extends Thread { + +private XMultiServiceFactory xMSF = null; +private String errorMsg; +private boolean errorHappened; +private String btnName; +private boolean checkBox; + +/** + * Constructor. + * @param xMSF A MultiServiceFactory. + * @param log The log writer. + */ +public SecurityDialogUtil(XMultiServiceFactory xMSF, String btnName, boolean checkBox ) +{ + this.xMSF = xMSF; + this.btnName = btnName; + this.checkBox = checkBox; + errorMsg = ""; + errorHappened=false; +} + +/** + * Returns the error message that occured while + * accessing and pressing the button. + * @return Error message. + */ +public String getErrorMessage() +{ + return errorMsg; +} + +/** + * Is there an error message available? + * @return true, if an error happened + */ +public boolean hasErrorMessage() +{ + return !errorMsg.equals(""); +} + +/** + * Press the named button in the currently visible dialog box. + */ +public void run() +{ + // wait for the message box to appear + try + { + Thread.currentThread().sleep(4000) ; + } + catch (InterruptedException e) + { + System.err.println("While waiting :" + e.getMessage()) ; + } + + // access the message box + + XAccessibleContext xCon = null; + try + { + XInterface x = (XInterface) xMSF.createInstance( + "com.sun.star.awt.Toolkit") ; + XExtendedToolkit tk = + (XExtendedToolkit)UnoRuntime.queryInterface( + XExtendedToolkit.class,x); + AccessibilityTools at = new AccessibilityTools(); + XWindow xWindow = (XWindow)UnoRuntime.queryInterface( + XWindow.class,tk.getActiveTopWindow()); + XAccessible xRoot = at.getAccessibleObject(xWindow); + xCon = xRoot.getAccessibleContext(); + } + catch (Exception e) + { + errorMsg="Exception while using Accessibility\n"+ + e.getMessage(); + return; + } + // get the button + XInterface oObj = null; + try + { + /* System.err.println("Name of the AccessibleContext:\n\t"+ + xCon.getAccessibleName()); */ + int count = xCon.getAccessibleChildCount(); + // System.err.println("Number of children: "+count); + for (int i=0; i<count; i++) { + XAccessible xAcc = xCon.getAccessibleChild(i); + String name = + xAcc.getAccessibleContext().getAccessibleName(); + // System.out.println("Child "+i+": "+ name); + // check for button + if ( name.equals( btnName ) && ( UnoRuntime.queryInterface( + XButton.class, xAcc ) != null ) ) + { + // System.out.println("Child "+i+": "+ name); + oObj = xAcc.getAccessibleContext(); + } + // check for checkbox + if ( checkBox && ( UnoRuntime.queryInterface( XCheckBox.class, xAcc ) != null ) ) + { + // want to do this action now + // probably equates to toggle cb + XAccessibleAction xAction = + (XAccessibleAction)UnoRuntime.queryInterface( + XAccessibleAction.class, xAcc.getAccessibleContext()); + xAction.doAccessibleAction(0); + + // might be worth using oObj2 to double check the new state?? + } + } + if (oObj == null) { + errorMsg="No button has been found:\n"+ + "No action is triggered."; + return; + } + // press button + XAccessibleAction xAction = + (XAccessibleAction)UnoRuntime.queryInterface( + XAccessibleAction.class, oObj); + xAction.doAccessibleAction(0); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) { + errorMsg="Exception\n"+ + e.getMessage(); + } +} + +} + + + + diff --git a/scripting/workben/ifc/scripting/_XFunction.java b/scripting/workben/ifc/scripting/_XFunction.java new file mode 100644 index 000000000000..3981f42d1956 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XFunction.java @@ -0,0 +1,169 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.Exception; +import com.sun.star.beans.XPropertySet; + +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; + +import java.util.Collection; +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() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_invoke"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runInvokeTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("invoke()", result); + } + + 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")); + + try{ + Object[] aParams = new Object[0]; + short[][] aOutParamIndex = new short[1][]; + aOutParamIndex[0] = new short[0]; + Object[][] aOutParam = new Object[1][]; + aOutParam[0] = new Object[0]; + + 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) { + log.println("Couldn't invoke script:" + iae); + output = "com.sun.star.lang.IllegalArgumentException"; + } + catch (com.sun.star.script.CannotConvertException cce) { + log.println("Couldn't invoke script:" + cce); + output = "com.sun.star.script.CannotConvertException"; + } + catch (com.sun.star.reflection.InvocationTargetException ite) { + log.println("Couldn't invoke script:" + ite); + output = "com.sun.star.reflection.InvocationTargetException"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Couldn't invoke script:" + re); + output = "com.sun.star.uno.RuntimeException"; + } + catch(java.lang.Exception e){ + log.println("Couldn't invoke script:" + e); + 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)) + result = false; + + return result; + } +} diff --git a/scripting/workben/ifc/scripting/_XFunctionProvider.java b/scripting/workben/ifc/scripting/_XFunctionProvider.java new file mode 100644 index 000000000000..0baad7ef9d33 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XFunctionProvider.java @@ -0,0 +1,101 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.provider; + +import drafts.com.sun.star.script.framework.provider.XFunctionProvider; +import drafts.com.sun.star.script.framework.provider.XFunction; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.Exception; +import com.sun.star.beans.XPropertySet; + +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; + +import java.util.Collection; +import java.util.Iterator; + +public class _XFunctionProvider extends MultiMethodTest { + + public XFunctionProvider oObj = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void _getFunction() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getFunction"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runGetFunctionTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("getFunction()", result); + } + + private boolean runGetFunctionTest(Parameters testdata) { + String description = testdata.get("description"); + String logicalname = testdata.get("logicalname"); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + XFunction function = oObj.getFunction(logicalname); + + if (function == null) + output = "null"; + else + output = "XFunction.class"; + + log.println("expected: " + expected + ", output: " + output); + if (output.equals(expected)) + return true; + else + return false; + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptInfo.java b/scripting/workben/ifc/scripting/_XScriptInfo.java new file mode 100644 index 000000000000..9ab7b46fd1ef --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptInfo.java @@ -0,0 +1,331 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.storage; + +import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; +import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess; +import drafts.com.sun.star.script.framework.storage.XScriptInfo; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.Exception; +import com.sun.star.beans.XPropertySet; + +import java.util.Collection; +import java.util.Iterator; + +import java.io.PrintWriter; +import lib.Parameters; +import lib.MultiMethodTest; +import lib.StatusException; + +public class _XScriptInfo extends MultiMethodTest { + + public XScriptInfo oObj = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void _getLogicalName() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getLogicalName"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + output = oObj.getLogicalName(); + + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + } + else { + result = false; + } + + tRes.tested("getLogicalName()", result); + } + + public void _getParcelURI() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getParcelURI"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + output = oObj.getParcelURI(); + + log.println("expected: " + expected + ", output: " + output); + result &= output.endsWith(expected); + } + } + else { + result = false; + } + tRes.tested("getParcelURI()", result); + } + + public void _getLanguage() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getLanguage"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + output = oObj.getLanguage(); + + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + } + else { + result = false; + } + tRes.tested("getLanguage()", result); + } + + public void _getFunctionName() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getFunctionName"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + output = oObj.getFunctionName(); + + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + } + else { + result = false; + } + tRes.tested("getFunctionName()", result); + } + + public void _getLanguageProperties() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getLanguageProperties"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + try { + XPropertySet langProps = oObj.getLanguageProperties(); + output = (String)langProps.getPropertyValue("classpath"); + + if (output == null) + output = "null"; + } + 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); + result &= output.equals(expected); + } + } + else { + result = false; + } + tRes.tested("getLanguageProperties()", true); + } + + public void _getFileSetNames() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getFileSetNames"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + String[] fileSets = oObj.getFileSetNames(); + + if (fileSets == null) + output = "null"; + else if (fileSets.length != 1) + output = "WrongNumberOfFileSets"; + else + output = fileSets[0]; + + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + } + else { + result = false; + } + tRes.tested("getFileSetNames()", result); + } + + public void _getFilesInFileSet() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getFilesInFileSet"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + String[] filesInFileSet = + oObj.getFilesInFileSet(oObj.getFileSetNames()[0]); + + if (filesInFileSet == null) + output = "null"; + else if (filesInFileSet.length != 1) + output = "WrongNumberOfFilesInFileSet"; + else + output = filesInFileSet[0]; + + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + } + else { + result = false; + } + tRes.tested("getFilesInFileSet()", result); + } + + public void _getDescription() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getDescription"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + output = oObj.getDescription(); + + if (output == null) + output = "null"; + else if (output.length() == 0) + output = "empty"; + + log.println("expected: [" + expected + "], output: [" + + output + "]"); + result &= output.equals(expected); + } + } + else { + result = false; + } + + tRes.tested("getDescription()", result); + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptInfoAccess.java b/scripting/workben/ifc/scripting/_XScriptInfoAccess.java new file mode 100644 index 000000000000..bb26d5110dd0 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptInfoAccess.java @@ -0,0 +1,228 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.storage; + +import ifc.script.framework.ScriptingUtils; + +import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess; +import drafts.com.sun.star.script.framework.storage.XScriptInfo; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.Exception; +import com.sun.star.beans.XPropertySet; + +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; + +import java.util.Collection; +import java.util.Iterator; + +public class _XScriptInfoAccess extends MultiMethodTest { + + public XScriptInfoAccess oObj = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void _getScriptLogicalNames() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getScriptLogicalNames"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runGetScriptLogicalNamesTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("getScriptLogicalNames()", result); + } + + private boolean runGetScriptLogicalNamesTest(Parameters testdata) { + String description = testdata.get("description"); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + // try { + log.println("In _XScriptInfoAccess.getScriptLogicalNames()"); + String[] logicalNames = oObj.getScriptLogicalNames(); + + if (logicalNames == null) + output = "null"; + else if (logicalNames.length == 0) + output = "empty"; + else { + for (int i = 0; i < logicalNames.length; i++) { + if (logicalNames[i].equals(expected)) { + output = logicalNames[i]; + break; + } + } + } + // } + // 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)) + return true; + else + return false; + } + + public void _getImplementations() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getImplementations"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runGetImplementationsTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("getImplementations()", result); + } + + private boolean runGetImplementationsTest(Parameters testdata) { + String description = testdata.get("description"); + String logicalname = testdata.get("logicalname"); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + // performs a basic check to see if 1 match (XScriptInfo) is returned + // the XScriptInfo object is tested more completely in _XScriptInfo + // which is drive from ScriptInfo + + try { + XScriptInfo[] impls = oObj.getImplementations(logicalname); + + // should only be one match + if (impls == null) + output = "null"; + else if (impls.length == 0) + output = "empty"; + else + output = impls[0].getLogicalName(); + } + 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)) + return true; + else + return false; + } + + public void _getAllImplementations() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getAllImplementations"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runGetAllImplementationsTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("getAllImplementations()", result); + } + + private boolean runGetAllImplementationsTest(Parameters testdata) { + String description = testdata.get("description"); + String location = testdata.get("location"); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + Object obj = ScriptingUtils.getDefault().getScriptStorage( + tParam.getMSF(), location); + + XScriptInfoAccess access = (XScriptInfoAccess) + UnoRuntime.queryInterface(XScriptInfoAccess.class, obj); + + XScriptInfo[] impls = access.getAllImplementations(); + + if (impls == null || impls.length == 0) { + output = "empty"; + } + else { + for (int i = 0; i < impls.length - 1; i++) + output += impls[i].getLogicalName() + ","; + output += impls[impls.length - 1].getLogicalName(); + } + + log.println("expected: " + expected + ", output: " + output); + if (output.equals(expected)) + return true; + else + return false; + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptInvocation.java b/scripting/workben/ifc/scripting/_XScriptInvocation.java new file mode 100644 index 000000000000..a35a153f0e48 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptInvocation.java @@ -0,0 +1,232 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.runtime; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Collection; + +import drafts.com.sun.star.script.framework.runtime.XScriptInvocation; +import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.frame.XModel; + +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; +import util.SOfficeFactory; + +public class _XScriptInvocation extends MultiMethodTest { + + public XScriptInvocation oObj = null; + private XScriptStorageManager storageManager = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void after() throws StatusException { + } + + public void _invoke() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_invoke"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runInvokeTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("invoke()", result); + } + + private boolean runInvokeTest(Parameters testdata) { + String description = testdata.get("description"); + String logicalname = testdata.get("logicalname"); + String context = testdata.get("context"); + String location = testdata.get("location"); + String expected = testdata.get("expected"); + String output = ""; + + int storageId = getStorageId(location); + + XModel ctx = null; + if (!context.equals("null")) + ctx = loadDocument(context); + + HashMap map = new HashMap(); + map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId)); + map.put("SCRIPTING_DOC_URI", "hahaha"); + if (ctx != null) + map.put("SCRIPTING_DOC_REF", ctx); + + Parameters params = new Parameters(map); + Object[] args = new Object[0]; + + Object[][] result = new Object[1][0]; + result[0] = new Object[0]; + + short[][] num = new short[1][0]; + num[0] = new short[0]; + + log.println(description + ": " + logicalname); + + try { + Object ret = oObj.invoke(logicalname, params, args, num, result); + log.println("return type is: " + ret.getClass().getName() + + ", value is: " + ret.toString()); + output = "success"; + } + catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("Couldn't invoke script:" + iae); + output = "com.sun.star.lang.IllegalArgumentException"; + } + catch (com.sun.star.script.CannotConvertException cce) { + log.println("Couldn't invoke script:" + cce); + output = "com.sun.star.script.CannotConvertException"; + } + catch (com.sun.star.reflection.InvocationTargetException ite) { + log.println("Couldn't invoke script:" + ite); + output = "com.sun.star.reflection.InvocationTargetException"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Couldn't invoke script:" + re); + output = "com.sun.star.uno.RuntimeException"; + } + + if (ctx != null) + ctx.dispose(); + + log.println("expected: " + expected + ", output: " + output); + if (output.equals(expected)) + return true; + else + return false; + } + + private int getStorageId(String location) { + + if (location.equals("share")) + return 0; + + if (location.equals("user")) + return 1; + + XSimpleFileAccess access = null; + String uri = util.utils.getFullTestURL(location); + + if (storageManager == null) { + try { + XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet.class, tParam.getMSF()); + + XComponentContext xContext = (XComponentContext) + UnoRuntime.queryInterface(XComponentContext.class, + xProp.getPropertyValue("DefaultContext")); + + XInterface ifc = (XInterface) + xContext.getValueByName("/singletons/drafts.com.sun.star." + + "script.framework.storage.theScriptStorageManager"); + + storageManager = (XScriptStorageManager) + UnoRuntime.queryInterface(XScriptStorageManager.class, ifc); + } + catch( Exception e ) { + return -1; + } + } + + access = getXSimpleFileAccess(); + if (access == null) + return -1; + + int id = storageManager.createScriptStorageWithURI(access, uri); + + return id; + } + + private XSimpleFileAccess getXSimpleFileAccess() { + XSimpleFileAccess access = null; + + try { + Object fa = tParam.getMSF().createInstance( + "com.sun.star.ucb.SimpleFileAccess"); + + access = (XSimpleFileAccess) + UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); + } + catch (com.sun.star.uno.Exception e) { + return null; + } + return access; + } + + private XModel loadDocument(String name) { + XModel model = null; + SOfficeFactory factory = SOfficeFactory.getFactory(tParam.getMSF()); + + String fullname = util.utils.getFullTestURL(name); + + try { + Object obj = factory.loadDocument(fullname); + model = (XModel) UnoRuntime.queryInterface(XModel.class, obj); + } + catch (com.sun.star.lang.IllegalArgumentException iae) { + return null; + } + catch (Exception e) { + return null; + } + + try { + Thread.sleep(5000); + } + catch (InterruptedException ie) { + } + + return model; + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptNameResolver.java b/scripting/workben/ifc/scripting/_XScriptNameResolver.java new file mode 100644 index 000000000000..1f31448af1b3 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptNameResolver.java @@ -0,0 +1,186 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.runtime; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Collection; + +import drafts.com.sun.star.script.framework.runtime.XScriptNameResolver; +import drafts.com.sun.star.script.framework.storage.XScriptInfo; +import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; + +public class _XScriptNameResolver extends MultiMethodTest { + + public XScriptNameResolver oObj = null; + private XScriptStorageManager storageManager = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void _resolve() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_resolve"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runResolveTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + tRes.tested("resolve()", result); + } + + private boolean runResolveTest(Parameters data) { + String description = data.get("description"); + String location = data.get("location"); + String logicalname = data.get("logicalname"); + String expected = data.get("expected"); + String output = ""; + + int storageId = getStorageId(location); + + log.println(description + ": " + logicalname); + + HashMap map = new HashMap(); + map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId)); + map.put("SCRIPTING_DOC_URI", util.utils.getFullTestURL(location)); + + Parameters params = new Parameters(map); + Object[] args = new Object[] {params}; + + try { + XInterface ifc = (XInterface) oObj.resolve(logicalname, args); + + if (ifc == null) + output = "null"; + else if (UnoRuntime.queryInterface(XScriptInfo.class, ifc) == null) + output = "null"; + else + output = "XScriptInfo.class"; + } + catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("caught IllegalArgumentException: " + iae); + output = "com.sun.star.lang.IllegalArgumentException"; + } + catch (com.sun.star.script.CannotConvertException cce) { + log.println("caught CannotConvertException: " + cce); + output = "com.sun.star.script.CannotConvertException"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("caught RuntimeException: " + re); + output = "com.sun.star.uno.RuntimeException"; + } + + log.println("expected: " + expected + ", output: " + output); + if (output.equals(expected)) + return true; + else + return false; + } + + private int getStorageId(String location) { + + if (location.equals("share")) + return 0; + + if (location.equals("user")) + return 1; + + XSimpleFileAccess access = null; + String uri = util.utils.getFullTestURL(location); + + if (storageManager == null) { + try { + XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet.class, tParam.getMSF()); + + XComponentContext xContext = (XComponentContext) + UnoRuntime.queryInterface(XComponentContext.class, + xProp.getPropertyValue("DefaultContext")); + + XInterface ifc = (XInterface) + xContext.getValueByName("/singletons/drafts.com.sun.star." + + "script.framework.storage.theScriptStorageManager"); + + storageManager = (XScriptStorageManager) + UnoRuntime.queryInterface(XScriptStorageManager.class, ifc); + } + catch( Exception e ) { + return -1; + } + } + + access = getXSimpleFileAccess(); + if (access == null) + return -1; + + int id = storageManager.createScriptStorageWithURI(access, uri); + + return id; + } + + private XSimpleFileAccess getXSimpleFileAccess() { + XSimpleFileAccess access = null; + + try { + Object fa = tParam.getMSF().createInstance( + "com.sun.star.ucb.SimpleFileAccess"); + + access = (XSimpleFileAccess) + UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); + } + catch (com.sun.star.uno.Exception e) { + return null; + } + return access; + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptSecurity.java b/scripting/workben/ifc/scripting/_XScriptSecurity.java new file mode 100644 index 000000000000..ee5ade31e7f4 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptSecurity.java @@ -0,0 +1,409 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.security; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Collection; + +import drafts.com.sun.star.script.framework.security.XScriptSecurity; +import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.PropertyValue; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.frame.XModel; +import com.sun.star.container.XNameReplace; +import com.sun.star.util.XChangesBatch; +import com.sun.star.reflection.InvocationTargetException; + +import ifc.script.framework.SecurityDialogUtil; + +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; +import util.SOfficeFactory; + +public class _XScriptSecurity extends MultiMethodTest { + + public XScriptSecurity oObj = null; + private XScriptStorageManager storageManager = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void after() throws StatusException { + } + + public void _checkPermission() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_checkPermission"); + + Iterator tests; + + if (c != null) { + tests = c.iterator(); + + while (tests.hasNext()) { + result &= runCheckPermissionTest((Parameters)tests.next()); + } + } + else { + result = false; + } + + // set security to always without confirmation dialog and empty path + // list so other tests can run without dialog popping up + setSecurity(2, "false", "false", null); + + tRes.tested("checkPermission()", result); + } + + private boolean runCheckPermissionTest(Parameters testdata) { + // description of test + String description = testdata.get("description"); + + // document location + String location = testdata.get("location"); + + //security settings + String runmacro = testdata.get("runmacro"); + String confirm = testdata.get("confirm"); + String warning = testdata.get("warning"); + String pathlist = testdata.get("pathlist"); + + //do this test produce a dialog? + String dialog = testdata.get("dialog"); + //is checkbox to be ticked? + String checkBoxStr = testdata.get("checkbox"); + //name of button in dialog to press + String buttonName = testdata.get("buttonName"); + + //expected result + String expected = testdata.get("expected"); + //do we need to check the pathlist? + String checkpath = testdata.get("checkpath"); + + String output = null; + + log.println(description); + + // get the officeBasic setting + int officeBasic = 0; + if( runmacro.equals("never") ) + { + officeBasic = 0; + } + else if ( runmacro.equals("pathlist") ) + { + officeBasic = 1; + } + else if ( runmacro.equals("always") ) + { + officeBasic = 2; + } + + // should pathlist include doc? + String secureURLs = null; + if( pathlist.equals("true") ) + { + String uri = util.utils.getFullTestURL(location); + secureURLs = uri.substring(0, uri.lastIndexOf('/')); + } + + if ( !setSecurity( officeBasic, confirm, warning, secureURLs ) ) + { + log.println( "failed to set security" ); + return false; + } + + if( dialog.equals( "true" ) ) + { + // is the checkbox to be ticked? + boolean checkBox = false; + if( checkBoxStr.equals( "true" ) ) + { + checkBox = true; + } + new SecurityDialogUtil( tParam.getMSF(), buttonName, checkBox ).start(); + } + // need to set up dialog utils thread first + int storageId = getStorageId(location); + + try { + String uri = util.utils.getFullTestURL(location); + oObj.checkPermission(uri, "execute" ); + output = "true"; + } + catch (com.sun.star.security.AccessControlException ace) { + log.println("Couldn't invoke script:" + ace); + output = "com.sun.star.security.AccessControlException"; + } + catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("Couldn't invoke script:" + iae); + output = "com.sun.star.lang.IllegalArgumentException"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Couldn't invoke script:" + re); + output = "com.sun.star.uno.RuntimeException"; + } + + log.println("expected: " + expected + ", output: " + output); + if (output.equals(expected)) + { + if( checkpath.equals("true") ) + { + String setPath = getPathList(); + String expectedPath = "empty"; + if( checkBoxStr.equals( "true" ) ) + { + String uri = util.utils.getFullTestURL(location); + expectedPath = uri.substring(0, uri.lastIndexOf('/')); + } + log.println("pathlist: expected: " + expectedPath + ", output: " + setPath); + if( setPath.equals( expectedPath ) ) + { + return true; + } + else + { + return false; + } + } + return true; + } + else + return false; + } + + private String getPathList() + { + String result = ""; + try { + Object oProv = tParam.getMSF().createInstance( + "com.sun.star.configuration.ConfigurationProvider" ); + + XMultiServiceFactory xProv = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, oProv); + + //the path to the security settings in the registry + PropertyValue aPathArg = new PropertyValue(); + aPathArg.Name="nodepath"; + aPathArg.Value="org.openoffice.Office.Common/Security/Scripting"; + // we don't want to cache the write + PropertyValue aModeArg = new PropertyValue(); + aModeArg.Name="lazywrite"; + aModeArg.Value=new Boolean(false); + + Object[] aArgs = new Object[2]; + aArgs[0]=aPathArg; + aArgs[1]=aModeArg; + Object oConfigUpdate = xProv.createInstanceWithArguments( + "com.sun.star.configuration.ConfigurationAccess", + aArgs ); + XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet.class, oConfigUpdate ); + + String[] paths = (String[])xPropertySet.getPropertyValue("SecureURL"); + if (paths == null || paths.length == 0) + result = "empty"; + else + result = paths[0]; + + } catch (Exception e) + { + result = e.getClass().getName() + " getting list of secure URLs"; + } + return result; + } + + private boolean setSecurity( int officeBasic, String confirm, + String warning, String secureURLs ) + { + boolean success=false; + try { + Object oProv = tParam.getMSF().createInstance( + "com.sun.star.configuration.ConfigurationProvider" ); + + XMultiServiceFactory xProv = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, oProv); + + //the path to the security settings in the registry + PropertyValue aPathArg = new PropertyValue(); + aPathArg.Name="nodepath"; + aPathArg.Value="org.openoffice.Office.Common/Security/Scripting"; + // we don't want to cache the write + PropertyValue aModeArg = new PropertyValue(); + aModeArg.Name="lazywrite"; + aModeArg.Value=new Boolean(false); + + Object[] aArgs = new Object[2]; + aArgs[0]=aPathArg; + aArgs[1]=aModeArg; + Object oConfigUpdate = xProv.createInstanceWithArguments( + "com.sun.star.configuration.ConfigurationUpdateAccess", + aArgs ); + XNameReplace xNameReplace = (XNameReplace)UnoRuntime.queryInterface( + XNameReplace.class, oConfigUpdate ); + XChangesBatch xChangesBatch = (XChangesBatch)UnoRuntime.queryInterface( + XChangesBatch.class, oConfigUpdate ); + + Object[] aSecureURLs; + if (secureURLs == null) { + aSecureURLs = new Object[0]; + } + else { + aSecureURLs = new Object[1]; + aSecureURLs[0] = secureURLs; + } + log.println("setting SecureURL"); + xNameReplace.replaceByName( "SecureURL", aSecureURLs ); + + log.println("setting OfficeBasic"); + xNameReplace.replaceByName( "OfficeBasic", new Integer(officeBasic) ); + + Boolean bConfirm = null; + if( ( confirm != null ) && ( confirm.equals("true") ) ) + { + bConfirm = new Boolean( true ); + } + else + { + bConfirm = new Boolean( false ); + } + log.println("setting Confirmation"); + xNameReplace.replaceByName( "Confirmation", bConfirm ); + + Boolean bWarning = null; + if( ( warning != null ) && ( warning.equals("true") ) ) + { + bWarning = new Boolean( true ); + } + else + { + bWarning = new Boolean( false ); + } + log.println("setting Warning"); + xNameReplace.replaceByName( "Warning", bWarning ); + + // and now commit the changes + xChangesBatch.commitChanges(); + success=true; + } catch (Exception e) { + log.println("Error updating security settings: " + + e.getMessage() ); + } + return success; + } + + private int getStorageId(String location) { + + XSimpleFileAccess access = null; + String uri = util.utils.getFullTestURL(location); + + if (storageManager == null) { + try { + XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet.class, tParam.getMSF()); + + XComponentContext xContext = (XComponentContext) + UnoRuntime.queryInterface(XComponentContext.class, + xProp.getPropertyValue("DefaultContext")); + + XInterface ifc = (XInterface) + xContext.getValueByName("/singletons/drafts.com.sun.star." + + "script.framework.storage.theScriptStorageManager"); + + storageManager = (XScriptStorageManager) + UnoRuntime.queryInterface(XScriptStorageManager.class, ifc); + } + catch( Exception e ) { + return -1; + } + } + + access = getXSimpleFileAccess(); + if (access == null) + return -1; + + int id = storageManager.createScriptStorageWithURI(access, uri); + + return id; + } + + private XSimpleFileAccess getXSimpleFileAccess() { + XSimpleFileAccess access = null; + + try { + Object fa = tParam.getMSF().createInstance( + "com.sun.star.ucb.SimpleFileAccess"); + + access = (XSimpleFileAccess) + UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); + } + catch (com.sun.star.uno.Exception e) { + return null; + } + return access; + } + + private XModel loadDocument(String name) { + XModel model = null; + SOfficeFactory factory = SOfficeFactory.getFactory(tParam.getMSF()); + + String fullname = util.utils.getFullTestURL(name); + + try { + Object obj = factory.loadDocument(fullname); + model = (XModel) UnoRuntime.queryInterface(XModel.class, obj); + } + catch (com.sun.star.lang.IllegalArgumentException iae) { + return null; + } + catch (Exception e) { + return null; + } + + try { + Thread.sleep(5000); + } + catch (InterruptedException ie) { + } + + return model; + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptStorageManager.java b/scripting/workben/ifc/scripting/_XScriptStorageManager.java new file mode 100644 index 000000000000..d24b97070b57 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptStorageManager.java @@ -0,0 +1,267 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.storage; + +import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; +import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess; + +import java.util.Iterator; +import java.util.Collection; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.Exception; + +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; + +public class _XScriptStorageManager extends MultiMethodTest { + + public XScriptStorageManager oObj = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void _createScriptStorage() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_createScriptStorage"); + + if (c == null) { + tRes.tested("createScriptStorage()", false); + return; + } + + Iterator tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + XSimpleFileAccess access = getXSimpleFileAccess(); + + if (access == null) { + output = "Couldn't create XSimpleFileAccess"; + } + else { + try { + int id = oObj.createScriptStorage(access); + output = "success"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Exception from createScriptStorage: " + re); + output = "com.sun.star.uno.RuntimeException"; + } + } + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + tRes.tested("createScriptStorage()", result); + } + + public void _createScriptStorageWithURI() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_createScriptStorageWithURI"); + + if (c == null) { + tRes.tested("createScriptStorageWithURI()", false); + return; + } + + Iterator tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String location = testdata.get("location"); + String output = ""; + + log.println(testdata.get("description")); + + String uri = util.utils.getFullTestURL(location); + XSimpleFileAccess access = getXSimpleFileAccess(); + + try { + int id = oObj.createScriptStorageWithURI(access, uri); + + XInterface ifc = (XInterface)oObj.getScriptStorage(id); + + if (ifc == null) + output = "null"; + else { + Object info = UnoRuntime.queryInterface( + XScriptInfoAccess.class, ifc); + + if (info == null) + output = "null"; + else + output = "XScriptInfoAccess.class"; + } + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Caught RuntimeException: " + re); + output = "com.sun.star.uno.RuntimeException"; + } + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + + tRes.tested("createScriptStorageWithURI()", result); + } + + public void _getScriptStorage() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_getScriptStorage"); + + if (c == null) { + tRes.tested("getScriptStorage()", false); + return; + } + + Iterator tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String location = testdata.get("location"); + String output = ""; + + log.println(testdata.get("description")); + + try { + int storageid = getStorageId(location); + + XInterface ifc = (XInterface)oObj.getScriptStorage(storageid); + + if (ifc == null) + output = "null"; + else { + Object info = UnoRuntime.queryInterface( + XScriptInfoAccess.class, ifc); + + if (info == null) + output = "null"; + else + output = "XScriptInfoAccess.class"; + } + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Caught RuntimeException: " + re); + output = "com.sun.star.uno.RuntimeException"; + } + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + tRes.tested("getScriptStorage()", result); + } + + public void _refreshScriptStorage() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_refreshScriptStorage"); + + if (c == null) { + tRes.tested("refreshScriptStorage()", false); + return; + } + + Iterator tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String location = testdata.get("location"); + String output = ""; + + log.println(testdata.get("description")); + + try { + String uri = util.utils.getFullTestURL(location); + log.println("calling refreshScriptStorage with URI: " + uri); + oObj.refreshScriptStorage(uri); + output = "success"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Caught RuntimeException: " + re); + output = "com.sun.star.uno.RuntimeException"; + } + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + tRes.tested("refreshScriptStorage()", result); + } + + private int getStorageId(String location) { + + if (location.equals("share")) + return 0; + + if (location.equals("user")) + return 1; + + String uri = util.utils.getFullTestURL(location); + + XSimpleFileAccess access = getXSimpleFileAccess(); + if (access == null) + return -1; + + return oObj.createScriptStorageWithURI(access, uri); + } + + private XSimpleFileAccess getXSimpleFileAccess() { + XSimpleFileAccess access = null; + + try { + Object fa = tParam.getMSF().createInstance( + "com.sun.star.ucb.SimpleFileAccess"); + + access = (XSimpleFileAccess) + UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); + } + catch (com.sun.star.uno.Exception e) { + return null; + } + return access; + } +} diff --git a/scripting/workben/ifc/scripting/_XScriptStorageRefresh.java b/scripting/workben/ifc/scripting/_XScriptStorageRefresh.java new file mode 100644 index 000000000000..56b5e7ec8f82 --- /dev/null +++ b/scripting/workben/ifc/scripting/_XScriptStorageRefresh.java @@ -0,0 +1,90 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package ifc.script.framework.storage; + +import drafts.com.sun.star.script.framework.storage.XScriptStorageRefresh; + +import java.util.Collection; +import java.util.Iterator; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.Exception; +import com.sun.star.beans.XPropertySet; + +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.StatusException; +import lib.Parameters; + +public class _XScriptStorageRefresh extends MultiMethodTest { + + public XScriptStorageRefresh oObj = null; + + /** + * Retrieves object relation. + */ + public void before() throws StatusException { + } + + public void _refresh() { + boolean result = true; + + Collection c = + (Collection) tEnv.getObjRelation("_refresh"); + + if (c == null) { + tRes.tested("refresh()", false); + return; + } + + Iterator tests = c.iterator(); + + while (tests.hasNext()) { + Parameters testdata = (Parameters)tests.next(); + String expected = testdata.get("expected"); + String output = ""; + + log.println(testdata.get("description")); + + try { + oObj.refresh(); + output = "success"; + } + catch (com.sun.star.uno.RuntimeException re) { + log.println("Caught RuntimeException: " + re); + output = "com.sun.star.uno.RuntimeException"; + } + log.println("expected: " + expected + ", output: " + output); + result &= output.equals(expected); + } + tRes.tested("refresh()", result); + } +} diff --git a/scripting/workben/ifc/scripting/makefile.mk b/scripting/workben/ifc/scripting/makefile.mk new file mode 100644 index 000000000000..15c8492d8da8 --- /dev/null +++ b/scripting/workben/ifc/scripting/makefile.mk @@ -0,0 +1,40 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/..$/.. +PRJNAME = testcase +TARGET = testcase + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar $(CLASSPATH)$ +JAVAFILES = $(foreach,j,$(shell @ls | grep java) $j) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk |