diff options
author | Rüdiger Timm <rt@openoffice.org> | 2005-03-30 08:04:28 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2005-03-30 08:04:28 +0000 |
commit | 60465f2b27784a412b8b8ca0641bcb07731a00a1 (patch) | |
tree | 2162778a6159a1974b7e019fa2b1b2b4d1e9b1fb /vcl/qa | |
parent | b60b5d8330cf2f8527e6d16392bd51adc2288cc6 (diff) |
INTEGRATION: CWS vcl38 (1.1.2); FILE ADDED
2005/03/22 15:43:14 sg 1.1.2.1: #i44325#NEW: initial version
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/complex/persistent_window_states/PersistentWindowTest.java | 427 |
1 files changed, 427 insertions, 0 deletions
diff --git a/vcl/qa/complex/persistent_window_states/PersistentWindowTest.java b/vcl/qa/complex/persistent_window_states/PersistentWindowTest.java new file mode 100644 index 000000000000..3c749f8965cf --- /dev/null +++ b/vcl/qa/complex/persistent_window_states/PersistentWindowTest.java @@ -0,0 +1,427 @@ +/************************************************************************* + * + * $RCSfile: PersistentWindowTest.java,v $ + * + * $Revision: 1.2 $ + * + * last change:$Date: 2005-03-30 09:04:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +package complex.persistent_window_states; + + +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XInitialization; +import com.sun.star.uno.Type; +import com.sun.star.uno.Any; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XComponent; +import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XFramesSupplier; +import com.sun.star.frame.XFrames; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.container.XIndexAccess; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.AnyConverter; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.awt.Rectangle; +import com.sun.star.util.XCloseable; +import helper.ConfigurationRead; +import complexlib.ComplexTestCase; +import helper.OfficeProvider; +import complex.persistent_window_states.DocumentHandle; + +/** + * Parameters: + * <ul> + * <li>NoOffice=yes - StarOffice is not started initially.</li> + * </ul> + */ +public class PersistentWindowTest extends ComplexTestCase { + + private XMultiServiceFactory xMSF; + private OfficeProvider oProvider; + private int iOfficeCloseTime = 0; + + /** + * A frunction to tell the framework, which test functions are available. + * Right now, it's only 'checkPersistentWindowState'. + * @return All test methods. + */ + public String[] getTestMethodNames() { + return new String[]{"checkPersistentWindowState"}; + } + + /** + * Test if all available document types change the + * persistent Window Attributes + * + * The test follows basically these steps: + * - Create a configuration reader and a componentloader + * - Look for all document types in the configuration + * - Do for every doc type + * - start office + * - read configuration attibute settings + * - create a new document + * - resize the document and close it + * - close office + * - start office + * - read configuration attribute settings + * - create another new document + * - compare old settings with new ones: should be different + * - compare the document size with the resized document: should be equal + * - close office + * - Test finished + */ + public void checkPersistentWindowState() + { + try { + + log.println("Connect the first time."); + log.println("AppExecCommand: " + (String)param.get("AppExecutionCommand")); + log.println("ConnString: " + (String)param.get("ConnectionString")); + oProvider = new OfficeProvider(); + iOfficeCloseTime = param.getInt("OfficeCloseTime"); + if ( iOfficeCloseTime == 0 ) { + iOfficeCloseTime = 1000; + } + + if (!connect()) return; + + // create the configuration provider + Object o = null; + try { + o = xMSF.createInstance( + "com.sun.star.configuration.ConfigurationProvider"); + } + catch(com.sun.star.uno.Exception e) { + failed("Cannot create \"com.sun.star.configuration."+ + "ConfigurationProvider\""); + return; + } + + // fetch the multi service factory for setup + XMultiServiceFactory xCP = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, o); + + // create the configuration reader + ConfigurationRead cfgRead = new ConfigurationRead(xCP); + + // just test the wrong ones, not all. + String [] els = new String[]{ + "Office/Factories/com.sun.star.drawing.DrawingDocument", + "Office/Factories/com.sun.star.formula.FormulaProperties", + //"Office/Factories/com.sun.star.presentation.PresentationDocument", + "Office/Factories/com.sun.star.sheet.SpreadsheetDocument", + "Office/Factories/com.sun.star.text.GlobalDocument", + "Office/Factories/com.sun.star.text.TextDocument", + "Office/Factories/com.sun.star.text.WebDocument", + }; + // uncomment the following line for all doc types +// String [] els = cfgRead.getSubNodeNames("Office/Factories"); + + log.println("Found "+ els.length + " document types to test.\n"); + if (!disconnect()) return; + + // for all types + for(int i=0; i<els.length; i++) { + log.println("\tStart test for document type " + i + ": " + els[i]); + // exclude chart documents: cannot be created this way. + if ( els[i].indexOf("ChartDocument") != -1) { + log.println("Skipping chart document: cannot be create like this."); + continue; + } + + // start an office + if (!connect()) return; + + // get configuration + String[] settings = getConfigurationAndLoader(xMSF, els[i]); + if (settings == null) { + log.println("Skipping document type " + els[i]); + disconnect(); + continue; + } + String cfg = settings[1]; + + // load a document + DocumentHandle handle = loadDocument(xMSF, settings[0]); + + // first size + Rectangle rect1 = handle.getDocumentPosSize(); + + // resize + handle.resizeDocument(); + // after resize + Rectangle rect2 = handle.getDocumentPosSize(); + + // disposeManager and start a new office + if (!disconnect()) return; + + if (!connect()) return; + + // get configuration + settings = getConfigurationAndLoader(xMSF, els[i]); + + String newCfg = settings[1]; + + // load a document + handle = loadDocument(xMSF, settings[0]); + + Rectangle newRect = handle.getDocumentPosSize(); + + // print the settings and window sizes + log.println("----------------------------"); + log.println("Initial Config String : " + cfg); + log.println("Config String after restart: " + newCfg); + + log.println("----------------------------"); + log.println("Initial window (X,Y,Width,Height): " + +rect1.X+";"+rect1.Y+";"+ rect1.Width+";"+rect1.Height); + log.println("Window after resize (X,Y,Width,Height): " + +rect2.X+";"+rect2.Y+";"+ rect2.Width+";"+rect2.Height); + log.println("Window after restart (X,Y,Width,Height): " + +newRect.X+";"+newRect.Y+";"+newRect.Width+";" + +newRect.Height); + + // compare to see if resize worked + log.println("----------------------------"); + assure("Resize values for "+ els[i] + + " are equal.", !compareRectangles(rect1, rect2), true); + // compare settings and sizes + assure("Config settings for "+ els[i] + + " were not changed.", !cfg.equals(newCfg), true); + assure("Resized and restarted window for "+ els[i] + + " are not equal.", compareRectangles(rect2, newRect), true); + log.println("----------------------------"); + + // disposeManager + if (!disconnect()) return; + + log.println("\tFinish test for document type " + i + ": " + els[i]); + + } + } + catch(Exception e) { + e.printStackTrace(); + } + } + + /** + * Get the configuration settings and the document loader + * @param xMSF A MultiServiceFactory from an office + * @param cfgString A configuration string + * @return Settings and Loader + */ + private static String[] getConfigurationAndLoader(XMultiServiceFactory xMSF, + String cfgString) { + String[] conf = new String[2]; + + try { + Object o = xMSF.createInstance( + "com.sun.star.configuration.ConfigurationProvider"); + + // fetch the multi service factory for setup + XMultiServiceFactory xCP = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, o); + + // create the configuration reader + ConfigurationRead cfgRead = new ConfigurationRead(xCP); + + // get the document loader + String loader = getStringFromObject( + cfgRead.getByHierarchicalName(cfgString + "/ooSetupFactoryEmptyDocumentURL")); + + if (loader == null) return null; + log.println("\tLoader: " + loader); + + // read attributes + String hierchName = cfgString + "/ooSetupFactoryWindowAttributes"; + String setupSettings = getStringFromObject(cfgRead.getByHierarchicalName(hierchName)); + // remove slots: just plain document types have to start + if ( loader.indexOf("?slot") != -1 ) { + loader = loader.substring(0, loader.indexOf("?slot")); + System.out.println("Loader: "+loader); + } + + conf[0] = loader; + conf[1] = setupSettings; + } + catch(com.sun.star.uno.Exception e) {} + return conf; + } + + /** + * Load a document + * @param xMSF A MultiServiceFactory from an office + * @param docLoader A documet loader + * @return A handle to the document + */ + private DocumentHandle loadDocument(XMultiServiceFactory xMSF, + String docLoader) { + DocumentHandle docHandle = null; + try { + // create component loaader + XComponentLoader xCompLoader = (XComponentLoader) + UnoRuntime.queryInterface( + XComponentLoader.class, xMSF.createInstance( + "com.sun.star.frame.Desktop")); + XFramesSupplier xFrameSupp = (XFramesSupplier)UnoRuntime.queryInterface(XFramesSupplier.class, xCompLoader); + // close all existing frames + XFrames xFrames = xFrameSupp.getFrames(); + XIndexAccess xAcc = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xFrames); + for ( int i=0; i<xAcc.getCount(); i++ ) { + XCloseable xClose = (XCloseable)UnoRuntime.queryInterface(XCloseable.class, xAcc.getByIndex(i)); + try { + if ( xClose != null ) { + xClose.close(false); + } + else { + failed("Could not query frame for XCloseable!"); + } + } + catch( com.sun.star.uno.Exception e ) { + e.printStackTrace((java.io.PrintWriter)log); + failed("Could not query frame for XCloseable!"); + } + } + docHandle = new DocumentHandle(xCompLoader); + docHandle.loadDocument(docLoader, false); + } + catch(com.sun.star.uno.Exception e) { + e.printStackTrace(); + } + catch(java.lang.Exception e) { + e.printStackTrace(); + } + return docHandle; + } + + private boolean connect() { + try { + xMSF = (XMultiServiceFactory)oProvider.getManager(param); + try { + Thread.sleep(10000); + } + catch(java.lang.InterruptedException e) {} + } + catch (java.lang.Exception e) { + log.println(e.getClass().getName()); + log.println("Message: " + e.getMessage()); + failed("Cannot connect the Office."); + return false; + } + return true; + } + + private boolean disconnect() { + try { + XDesktop desk = null; + desk = (XDesktop) UnoRuntime.queryInterface( + XDesktop.class, xMSF.createInstance( + "com.sun.star.frame.Desktop")); + xMSF = null; + desk.terminate(); + log.println("Waiting " + iOfficeCloseTime + " milliseconds for the Office to close down"); + try { + Thread.sleep(iOfficeCloseTime); + } + catch(java.lang.InterruptedException e) {} + } + catch (java.lang.Exception e) { + e.printStackTrace(); + failed("Cannot dispose the Office."); + return false; + } + return true; + } + + private static String getStringFromObject(Object oName) { + if (oName instanceof String) + return (String)oName; + String value = null; + if (oName instanceof Any) { + try { + value = AnyConverter.toString(oName); + if (value == null) { + log.println("Got a void css.uno.Any as loading string."); + } + } + catch(Exception e) { + log.println("This document type cannot be opened directly."); + } + } + return value; + } + + /** + * Compare two rectangles. Return true, if both are equal, false + * otherwise. + * @param rect1 First Rectangle. + * @param rect2 Second Rectangle. + * @return True, if the rectangles are equal. + */ + private boolean compareRectangles(Rectangle rect1, Rectangle rect2) { + boolean result = true; + result &= (rect1.X==rect2.X); + result &= (rect1.Y==rect2.Y); + result &= (rect1.Width==rect2.Width); + result &= (rect1.Height==rect2.Height); + return result; + } +} |