1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sc; 29 30 import java.io.PrintWriter; 31 32 import lib.Status; 33 import lib.StatusException; 34 import lib.TestCase; 35 import lib.TestEnvironment; 36 import lib.TestParameters; 37 import util.AccessibilityTools; 38 import util.SOfficeFactory; 39 import util.utils; 40 41 import com.sun.star.accessibility.AccessibleRole; 42 import com.sun.star.accessibility.XAccessible; 43 import com.sun.star.accessibility.XAccessibleAction; 44 import com.sun.star.accessibility.XAccessibleContext; 45 import com.sun.star.accessibility.XAccessibleStateSet; 46 import com.sun.star.awt.XWindow; 47 import com.sun.star.container.XIndexAccess; 48 import com.sun.star.frame.XController; 49 import com.sun.star.frame.XDispatch; 50 import com.sun.star.frame.XDispatchProvider; 51 import com.sun.star.frame.XModel; 52 import com.sun.star.lang.XMultiServiceFactory; 53 import com.sun.star.sheet.XSpreadsheet; 54 import com.sun.star.sheet.XSpreadsheetDocument; 55 import com.sun.star.sheet.XSpreadsheets; 56 import com.sun.star.table.XCell; 57 import com.sun.star.uno.AnyConverter; 58 import com.sun.star.uno.Type; 59 import com.sun.star.uno.UnoRuntime; 60 import com.sun.star.uno.XInterface; 61 import com.sun.star.util.URL; 62 import com.sun.star.util.XCloseable; 63 import com.sun.star.util.XURLTransformer; 64 65 /** 66 * Test for object which is represented by accessible component of 67 * a printed header in 'Page Preview' mode. 68 * 69 * Object implements the following interfaces : 70 * <ul> 71 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 72 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 73 * </ul> <p> 74 * 75 * @see com.sun.star.accessibility.XAccessibleComponent 76 * @see com.sun.star.accessibility.XAccessibleContext 77 * @see ifc.n.star.accessibility._XAccessibleComponent 78 * @see ifc.n.star.accessibility._XAccessibleContext 79 */ 80 public class ScAccessiblePageHeaderArea extends TestCase { 81 82 static XSpreadsheetDocument xSpreadsheetDoc = null; 83 84 /** 85 * Called to create an instance of <code>TestEnvironment</code> 86 * with an object to test and related objects. 87 * Switchs the document to Print Preview mode. 88 * Obtains accissible object for the page view. 89 * 90 * @param tParam test parameters 91 * @param log writer to log information while testing 92 * 93 * @see TestEnvironment 94 * @see #getTestEnvironment() 95 */ 96 protected TestEnvironment createTestEnvironment( 97 TestParameters Param, PrintWriter log) { 98 99 XInterface oObj = null; 100 101 // inserting some content to have non-empty page preview 102 XCell xCell = null; 103 try { 104 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ; 105 XIndexAccess oIndexSheets = (XIndexAccess) 106 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 107 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 108 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 109 xCell = oSheet.getCellByPosition(0, 0) ; 110 xCell.setFormula("ScAccessiblePageHeaderArea"); 111 } catch(com.sun.star.lang.WrappedTargetException e) { 112 log.println("Exception ceating relation :"); 113 e.printStackTrace(log); 114 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 115 log.println("Exception ceating relation :"); 116 e.printStackTrace(log); 117 } catch(com.sun.star.lang.IllegalArgumentException e) { 118 log.println("Exception ceating relation :"); 119 e.printStackTrace(log); 120 } 121 122 XModel aModel = (XModel) 123 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); 124 125 XController xController = aModel.getCurrentController(); 126 127 // switching to 'Page Preview' mode 128 try { 129 XDispatchProvider xDispProv = (XDispatchProvider) 130 UnoRuntime.queryInterface(XDispatchProvider.class, xController); 131 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 132 UnoRuntime.queryInterface(XURLTransformer.class, 133 ( (XMultiServiceFactory) Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 134 // Because it's an in/out parameter we must use an array of URL objects. 135 URL[] aParseURL = new URL[1]; 136 aParseURL[0] = new URL(); 137 aParseURL[0].Complete = ".uno:PrintPreview"; 138 xParser.parseStrict(aParseURL); 139 URL aURL = aParseURL[0]; 140 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); 141 if(xDispatcher != null) 142 xDispatcher.dispatch( aURL, null ); 143 } catch (com.sun.star.uno.Exception e) { 144 log.println("Couldn't change mode"); 145 throw new StatusException(Status.failed("Couldn't change mode")); 146 } 147 148 try { 149 Thread.sleep(500); 150 } catch (InterruptedException ex) {} 151 152 AccessibilityTools at = new AccessibilityTools(); 153 154 XWindow xWindow = at.getCurrentContainerWindow( (XMultiServiceFactory) Param.getMSF(), aModel); 155 XAccessible xRoot = at.getAccessibleObject(xWindow); 156 157 try { 158 oObj = at.getAccessibleObjectForRole 159 (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0); 160 XAccessibleContext cont = (XAccessibleContext) 161 UnoRuntime.queryInterface(XAccessibleContext.class, oObj); 162 XAccessibleStateSet StateSet = cont.getAccessibleStateSet(); 163 if (StateSet.contains((short)27)) { 164 log.println("Object is transient"); 165 } 166 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { 167 throw new StatusException("Couldn't find needed Child",iabe); 168 } 169 170 log.println("ImplementationName " + utils.getImplName(oObj)); 171 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 172 173 TestEnvironment tEnv = new TestEnvironment(oObj); 174 175 XAccessibleContext zoomIn = 176 at.getAccessibleObjectForRole(xRoot,AccessibleRole.PUSH_BUTTON, "Zoom In"); 177 178 final XAccessibleAction pressZoom = (XAccessibleAction) 179 UnoRuntime.queryInterface(XAccessibleAction.class, zoomIn); 180 tEnv.addObjRelation("EventProducer", 181 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 182 public void fireEvent() { 183 try { 184 pressZoom.doAccessibleAction(0); 185 } catch (com.sun.star.lang.IndexOutOfBoundsException ibe) {} 186 } 187 }); 188 189 return tEnv; 190 191 } 192 193 /** 194 * Called while disposing a <code>TestEnvironment</code>. 195 * Disposes calc document. 196 * @param tParam test parameters 197 * @param tEnv the environment to cleanup 198 * @param log writer to log information while testing 199 */ 200 protected void cleanup( TestParameters Param, PrintWriter log) { 201 log.println( " disposing xSheetDoc " ); 202 try { 203 XCloseable oComp = (XCloseable) 204 UnoRuntime.queryInterface (XCloseable.class, xSpreadsheetDoc) ; 205 oComp.close(true); 206 }catch(com.sun.star.util.CloseVetoException e) { 207 log.println("Couldn't close document: "+e.getMessage()); 208 } 209 } 210 211 /** 212 * Called while the <code>TestCase</code> initialization. In the 213 * implementation does nothing. Subclasses can override to initialize 214 * objects shared among all <code>TestEnvironment</code>s. 215 * 216 * @param tParam test parameters 217 * @param log writer to log information while testing 218 * 219 * @see #initializeTestCase() 220 */ 221 protected void initialize(TestParameters Param, PrintWriter log) { 222 // get a soffice factory object 223 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF()); 224 225 try { 226 log.println("creating a spreadsheetdocument"); 227 xSpreadsheetDoc = SOF.createCalcDoc(null); 228 } catch (com.sun.star.uno.Exception e) { 229 e.printStackTrace( log ); 230 throw new StatusException( "Couldn't create document ", e ); 231 } 232 } 233 }