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._sd; 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.DrawTools; 34 import util.SOfficeFactory; 35 import util.utils; 36 37 import com.sun.star.accessibility.AccessibleRole; 38 import com.sun.star.accessibility.XAccessible; 39 import com.sun.star.awt.XWindow; 40 import com.sun.star.container.XIndexAccess; 41 import com.sun.star.drawing.XDrawPage; 42 import com.sun.star.drawing.XDrawPages; 43 import com.sun.star.drawing.XDrawPagesSupplier; 44 import com.sun.star.drawing.XDrawView; 45 import com.sun.star.drawing.XShape; 46 import com.sun.star.frame.XModel; 47 import com.sun.star.lang.XComponent; 48 import com.sun.star.lang.XMultiServiceFactory; 49 import com.sun.star.uno.AnyConverter; 50 import com.sun.star.uno.Type; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 54 public class AccessibleDrawDocumentView extends TestCase { 55 56 XComponent xDrawDoc; 57 58 /** 59 * Called to create an instance of <code>TestEnvironment</code> with an 60 * object to test and related objects. Subclasses should implement this 61 * method to provide the implementation and related objects. The method is 62 * called from <code>getTestEnvironment()</code>. 63 * 64 * @param tParam test parameters 65 * @param log writer to log information while testing 66 * 67 * @see TestEnvironment 68 * @see #getTestEnvironment 69 */ 70 protected TestEnvironment createTestEnvironment 71 (TestParameters Param, PrintWriter log) { 72 XInterface oObj = null; 73 74 // get a soffice factory object 75 SOfficeFactory SOF = SOfficeFactory.getFactory( 76 (XMultiServiceFactory)Param.getMSF()); 77 78 // get the drawpage of drawing here 79 log.println( "getting Drawpage" ); 80 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 81 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 82 XDrawPages oDPn = oDPS.getDrawPages(); 83 final XDrawPage fDP2 = oDPn.insertNewByIndex(1); 84 XIndexAccess oDPi = (XIndexAccess) 85 UnoRuntime.queryInterface(XIndexAccess.class, oDPn); 86 XDrawPage oDP = null; 87 try { 88 oDP = (XDrawPage) AnyConverter.toObject( 89 new Type(XDrawPage.class),oDPi.getByIndex(0)); 90 } catch (com.sun.star.lang.WrappedTargetException e) { 91 e.printStackTrace( log ); 92 throw new StatusException("Couldn't get by index", e); 93 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 94 e.printStackTrace( log ); 95 throw new StatusException("Couldn't get by index", e); 96 } catch (com.sun.star.lang.IllegalArgumentException e) { 97 e.printStackTrace( log ); 98 throw new StatusException("Couldn't get by index", e); 99 } 100 101 //get a Shape 102 log.println( "inserting a Shape" ); 103 XShape oShape = SOF.createShape(xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 104 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 105 106 XModel aModel = (XModel) 107 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 108 109 AccessibilityTools at = new AccessibilityTools(); 110 111 XWindow xWindow = at.getCurrentWindow ( 112 (XMultiServiceFactory)Param.getMSF(),aModel); 113 XAccessible xRoot = at.getAccessibleObject(xWindow); 114 115 //com.sun.star.accessibility.AccessibleRole 116 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT); 117 118 oObj = AccessibilityTools.SearchedContext; 119 120 log.println("ImplementationName "+utils.getImplName(oObj)); 121 122 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 123 124 TestEnvironment tEnv = new TestEnvironment(oObj); 125 126 final XDrawView xView = (XDrawView) UnoRuntime.queryInterface 127 (XDrawView.class, aModel.getCurrentController()) ; 128 final XDrawPage fDP1 = oDP; 129 130 tEnv.addObjRelation("EventProducer", 131 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 132 public void fireEvent() { 133 xView.setCurrentPage(fDP2); 134 xView.setCurrentPage(fDP1); 135 } 136 }); 137 138 return tEnv; 139 140 } 141 142 /** 143 * Called while disposing a <code>TestEnvironment</code>. 144 * Disposes Impress documents. 145 * @param tParam test parameters 146 * @param tEnv the environment to cleanup 147 * @param log writer to log information while testing 148 */ 149 protected void cleanup( TestParameters Param, PrintWriter log) { 150 log.println("disposing Draw document"); 151 util.DesktopTools.closeDoc(xDrawDoc); 152 } 153 154 /** 155 * Called while the <code>TestCase</code> initialization. In the 156 * implementation does nothing. Subclasses can override to initialize 157 * objects shared among all <code>TestEnvironment</code>s. 158 * 159 * @param tParam test parameters 160 * @param log writer to log information while testing 161 * 162 * @see #initializeTestCase 163 */ 164 protected void initialize(TestParameters Param, PrintWriter log) { 165 // get a soffice factory object 166 SOfficeFactory SOF = SOfficeFactory.getFactory( 167 (XMultiServiceFactory)Param.getMSF()); 168 169 try { 170 log.println( "creating a draw document" ); 171 xDrawDoc = SOF.createDrawDoc(null); 172 } catch (com.sun.star.uno.Exception e) { 173 // Some exception occures.FAILED 174 e.printStackTrace( log ); 175 throw new StatusException("Couldn't create document", e); 176 } 177 } 178 179 } 180