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.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.AccessibilityTools; 37 import util.SOfficeFactory; 38 import util.utils; 39 40 import com.sun.star.accessibility.AccessibleRole; 41 import com.sun.star.accessibility.XAccessible; 42 import com.sun.star.awt.XWindow; 43 import com.sun.star.container.XIndexAccess; 44 import com.sun.star.frame.XModel; 45 import com.sun.star.lang.XComponent; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.sheet.XSpreadsheet; 48 import com.sun.star.sheet.XSpreadsheetDocument; 49 import com.sun.star.sheet.XSpreadsheets; 50 import com.sun.star.table.XCell; 51 import com.sun.star.uno.AnyConverter; 52 import com.sun.star.uno.Type; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.uno.XInterface; 55 56 /** 57 * Test for accessible object of spreadsheet document.<p> 58 * Object implements the following interfaces: 59 * <ul> 60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code> 61 * </li> 62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code> 63 * </li> 64 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection 65 * </code></li> 66 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code> 67 * </li> 68 * </ul> 69 * @see com.sun.star.accessibility.XAccessibleComponent 70 * @see com.sun.star.accessibility.XAccessibleContext 71 * @see com.sun.star.accessibility.XAccessibleSelection 72 * @see com.sun.star.accessibility.XAccessibleTable 73 * @see ifc.accessibility._XAccessibleComponent 74 * @see ifc.accessibility._XAccessibleContext 75 * @see ifc.accessibility._XAccessibleSelection 76 * @see ifc.accessibility._XAccessibleTable 77 */ 78 public class ScAccessibleSpreadsheet extends TestCase { 79 static XSpreadsheetDocument xSheetDoc = null; 80 81 /** 82 * Creates a spreadsheet document. 83 */ 84 protected void initialize( TestParameters tParam, PrintWriter log ) { 85 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 86 try { 87 log.println( "creating a Spreadsheet document" ); 88 xSheetDoc = SOF.createCalcDoc(null); 89 } catch ( com.sun.star.uno.Exception e ) { 90 // Some exception occures.FAILED 91 e.printStackTrace( log ); 92 throw new StatusException( "Couldn't create document", e ); 93 } 94 } 95 96 /** 97 * Disposes a spreadsheet document. 98 */ 99 protected void cleanup( TestParameters tParam, PrintWriter log ) { 100 log.println( " disposing xSheetDoc " ); 101 XComponent oComp = (XComponent)UnoRuntime.queryInterface 102 (XComponent.class, xSheetDoc); 103 util.DesktopTools.closeDoc(oComp); 104 } 105 106 107 /** 108 * Creating a Testenvironment for the interfaces to be tested. 109 * Obtains the accessible object for the spreadsheet. 110 */ 111 public synchronized TestEnvironment createTestEnvironment 112 ( TestParameters Param, PrintWriter log ) 113 throws StatusException { 114 115 XInterface oObj = null; 116 117 XModel xModel = (XModel) 118 UnoRuntime.queryInterface(XModel.class, xSheetDoc); 119 120 AccessibilityTools at = new AccessibilityTools(); 121 122 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), xModel); 123 XAccessible xRoot = at.getAccessibleObject(xWindow); 124 125 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE ); 126 127 oObj = AccessibilityTools.SearchedContext; 128 129 log.println("ImplementationName " + utils.getImplName(oObj)); 130 131 TestEnvironment tEnv = new TestEnvironment( oObj ); 132 133 // relation for XAccessibleEventBroadcaster 134 XCell xCell = null; 135 final String text = "Text for testing of the interface XAccessibleText"; 136 try { 137 XSpreadsheets oSheets = xSheetDoc.getSheets() ; 138 XIndexAccess oIndexSheets = (XIndexAccess) 139 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 140 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 141 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 142 xCell = oSheet.getCellByPosition(5, 5) ; 143 xCell.setFormula(text); 144 } catch(com.sun.star.lang.WrappedTargetException e) { 145 log.println("Exception ceating relation :"); 146 e.printStackTrace(log); 147 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 148 log.println("Exception ceating relation :"); 149 e.printStackTrace(log); 150 } catch(com.sun.star.lang.IllegalArgumentException e) { 151 log.println("Exception ceating relation :"); 152 e.printStackTrace(log); 153 } 154 155 final XCell fCell = xCell ; 156 157 tEnv.addObjRelation("EventProducer", 158 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 159 public void fireEvent() { 160 fCell.setFormula("firing event"); 161 fCell.setFormula(text); 162 } 163 }); 164 165 return tEnv; 166 } 167 168 } 169