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.Rectangle; 39 import com.sun.star.awt.XWindow; 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.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 47 /** 48 * Test for object which is represented by accessible component of 49 * a spreadsheet document. 50 * 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 54 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 55 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 56 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li> 57 * </ul> <p> 58 * 59 * @see com.sun.star.accessibility.XAccessibleComponent 60 * @see com.sun.star.accessibility.XAccessibleContext 61 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 62 * @see com.sun.star.accessibility.XAccessibleSelection 63 * @see ifc.accessibility._XAccessibleComponent 64 * @see ifc.accessibility._XAccessibleEventBroadcaster 65 * @see ifc.accessibility._XAccessibleSelection 66 * @see ifc.accessibility._XAccessibleContext 67 */ 68 public class ScAccessibleDocument extends TestCase { 69 70 static XComponent xSpreadsheetDoc = null; 71 72 /** 73 * Called to create an instance of <code>TestEnvironment</code> 74 * with an object to test and related objects. 75 * Obtains accessible object for the spreadsheet document. 76 * 77 * @param Param test parameters 78 * @param log writer to log information while testing 79 * 80 * @see TestEnvironment 81 * @see #getTestEnvironment 82 */ createTestEnvironment( TestParameters Param, PrintWriter log)83 protected TestEnvironment createTestEnvironment( 84 TestParameters Param, PrintWriter log) { 85 86 XInterface oObj = null; 87 88 // get the drawpage of drawing here 89 log.println( "getting Drawpages" ); 90 91 XModel aModel = (XModel) 92 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); 93 94 AccessibilityTools at = new AccessibilityTools(); 95 96 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 97 XAccessible xRoot = at.getAccessibleObject(xWindow); 98 99 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT, ""); 100 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 101 log.println("ImplementationName " + utils.getImplName(oObj)); 102 103 TestEnvironment tEnv = new TestEnvironment(oObj); 104 105 final XWindow xDocWin = xWindow; 106 tEnv.addObjRelation("EventProducer", 107 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 108 public void fireEvent() { 109 Rectangle rect = xDocWin.getPosSize(); 110 xDocWin.setPosSize(rect.X,rect.Y,rect.Height,rect.Width-10,com.sun.star.awt.PosSize.POSSIZE); 111 } 112 }); 113 114 return tEnv; 115 116 } 117 118 /** 119 * Called while disposing a <code>TestEnvironment</code>. 120 * Disposes calc document. 121 * @param Param test parameters 122 * @param log writer to log information while testing 123 */ cleanup( TestParameters Param, PrintWriter log)124 protected void cleanup( TestParameters Param, PrintWriter log) { 125 log.println( " disposing xSheetDoc " ); 126 util.DesktopTools.closeDoc(xSpreadsheetDoc); 127 } 128 129 /** 130 * Called while the <code>TestCase</code> initialization. In the 131 * implementation does nothing. Subclasses can override to initialize 132 * objects shared among all <code>TestEnvironment</code>s. 133 * 134 * @param Param test parameters 135 * @param log writer to log information while testing 136 * 137 * @see #initializeTestCase 138 */ initialize(TestParameters Param, PrintWriter log)139 protected void initialize(TestParameters Param, PrintWriter log) { 140 // get a soffice factory object 141 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 142 143 try { 144 log.println("creating a spreadsheetdocument"); 145 String url = utils.getFullTestURL("calcshapes.sxc"); 146 log.println("loading document "+url); 147 xSpreadsheetDoc = SOF.loadDocument(url); 148 shortWait(); 149 } catch (com.sun.star.uno.Exception e) { 150 e.printStackTrace( log ); 151 throw new StatusException( "Couldn't create document ", e ); 152 } 153 } 154 155 /** 156 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 157 * reset</code> call. 158 */ shortWait()159 private void shortWait() { 160 try { 161 Thread.sleep(500) ; 162 } catch (InterruptedException e) { 163 log.println("While waiting :" + e) ; 164 } 165 } 166 167 } 168