1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.AccessibilityTools; 33 import util.SOfficeFactory; 34 import util.utils; 35 36 import com.sun.star.accessibility.AccessibleRole; 37 import com.sun.star.accessibility.XAccessible; 38 import com.sun.star.awt.XWindow; 39 import com.sun.star.container.XIndexAccess; 40 import com.sun.star.frame.XModel; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.sheet.XSpreadsheet; 44 import com.sun.star.sheet.XSpreadsheetDocument; 45 import com.sun.star.sheet.XSpreadsheets; 46 import com.sun.star.table.XCell; 47 import com.sun.star.uno.AnyConverter; 48 import com.sun.star.uno.Type; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.uno.XInterface; 51 52 /** 53 * Test for accessible object of spreadsheet document.<p> 54 * Object implements the following interfaces: 55 * <ul> 56 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code> 57 * </li> 58 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code> 59 * </li> 60 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection 61 * </code></li> 62 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code> 63 * </li> 64 * </ul> 65 * @see com.sun.star.accessibility.XAccessibleComponent 66 * @see com.sun.star.accessibility.XAccessibleContext 67 * @see com.sun.star.accessibility.XAccessibleSelection 68 * @see com.sun.star.accessibility.XAccessibleTable 69 * @see ifc.accessibility._XAccessibleComponent 70 * @see ifc.accessibility._XAccessibleContext 71 * @see ifc.accessibility._XAccessibleSelection 72 * @see ifc.accessibility._XAccessibleTable 73 */ 74 public class ScAccessibleSpreadsheet extends TestCase { 75 static XSpreadsheetDocument xSheetDoc = null; 76 77 /** 78 * Creates a spreadsheet document. 79 */ initialize( TestParameters tParam, PrintWriter log )80 protected void initialize( TestParameters tParam, PrintWriter log ) { 81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 82 try { 83 log.println( "creating a Spreadsheet document" ); 84 xSheetDoc = SOF.createCalcDoc(null); 85 } catch ( com.sun.star.uno.Exception e ) { 86 // Some exception occured.FAILED 87 e.printStackTrace( log ); 88 throw new StatusException( "Couldn't create document", e ); 89 } 90 } 91 92 /** 93 * Disposes a spreadsheet document. 94 */ cleanup( TestParameters tParam, PrintWriter log )95 protected void cleanup( TestParameters tParam, PrintWriter log ) { 96 log.println( " disposing xSheetDoc " ); 97 XComponent oComp = (XComponent)UnoRuntime.queryInterface 98 (XComponent.class, xSheetDoc); 99 util.DesktopTools.closeDoc(oComp); 100 } 101 102 103 /** 104 * Creating a Testenvironment for the interfaces to be tested. 105 * Obtains the accessible object for the spreadsheet. 106 */ createTestEnvironment( TestParameters Param, PrintWriter log )107 public synchronized TestEnvironment createTestEnvironment 108 ( TestParameters Param, PrintWriter log ) 109 throws StatusException { 110 111 XInterface oObj = null; 112 113 XModel xModel = (XModel) 114 UnoRuntime.queryInterface(XModel.class, xSheetDoc); 115 116 AccessibilityTools at = new AccessibilityTools(); 117 118 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), xModel); 119 XAccessible xRoot = at.getAccessibleObject(xWindow); 120 121 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE ); 122 123 oObj = AccessibilityTools.SearchedContext; 124 125 log.println("ImplementationName " + utils.getImplName(oObj)); 126 127 TestEnvironment tEnv = new TestEnvironment( oObj ); 128 129 // relation for XAccessibleEventBroadcaster 130 XCell xCell = null; 131 final String text = "Text for testing of the interface XAccessibleText"; 132 try { 133 XSpreadsheets oSheets = xSheetDoc.getSheets() ; 134 XIndexAccess oIndexSheets = (XIndexAccess) 135 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 136 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 137 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 138 xCell = oSheet.getCellByPosition(5, 5) ; 139 xCell.setFormula(text); 140 } catch(com.sun.star.lang.WrappedTargetException e) { 141 log.println("Exception ceating relation :"); 142 e.printStackTrace(log); 143 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 144 log.println("Exception ceating relation :"); 145 e.printStackTrace(log); 146 } catch(com.sun.star.lang.IllegalArgumentException e) { 147 log.println("Exception ceating relation :"); 148 e.printStackTrace(log); 149 } 150 151 final XCell fCell = xCell ; 152 153 tEnv.addObjRelation("EventProducer", 154 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 155 public void fireEvent() { 156 fCell.setFormula("firing event"); 157 fCell.setFormula(text); 158 } 159 }); 160 161 return tEnv; 162 } 163 164 } 165