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.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.drawing.XDrawPages; 40 import com.sun.star.drawing.XDrawPagesSupplier; 41 import com.sun.star.frame.XDispatch; 42 import com.sun.star.frame.XDispatchProvider; 43 import com.sun.star.frame.XModel; 44 import com.sun.star.lang.XComponent; 45 import com.sun.star.lang.XMultiServiceFactory; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 import com.sun.star.util.URL; 49 import com.sun.star.util.XURLTransformer; 50 51 public class AccessibleSlideView extends TestCase { 52 53 XModel aModel = null; 54 XComponent xImpressDoc = null; 55 56 /** 57 * Called to create an instance of <code>TestEnvironment</code> with an 58 * object to test and related objects. Subclasses should implement this 59 * method to provide the implementation and related objects. The method is 60 * called from <code>getTestEnvironment()</code>. 61 * 62 * @param Param test parameters 63 * @param log writer to log information while testing 64 * 65 * @see TestEnvironment 66 * @see #getTestEnvironment 67 */ createTestEnvironment(TestParameters Param, PrintWriter log)68 protected TestEnvironment createTestEnvironment 69 (TestParameters Param, PrintWriter log) { 70 XInterface oObj = null; 71 72 AccessibilityTools at = new AccessibilityTools(); 73 74 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 75 UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel); 76 XDrawPages oDPn = oDPS.getDrawPages(); 77 78 oDPn.insertNewByIndex(0); 79 80 shortWait(); 81 82 XWindow xWindow = at.getCurrentWindow ( 83 (XMultiServiceFactory)Param.getMSF(),aModel); 84 XAccessible xRoot = at.getAccessibleObject(xWindow); 85 86 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 87 88 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT); 89 90 oObj = AccessibilityTools.SearchedContext; 91 92 System.out.println("ImplementationName "+utils.getImplName(oObj)); 93 94 TestEnvironment tEnv = new TestEnvironment(oObj); 95 96 //util.dbg.printInterfaces(oObj); 97 log.println("Implementationname: "+util.utils.getImplName(oObj)); 98 99 final XDrawPages DrawPages = oDPn; 100 101 tEnv.addObjRelation("EventProducer", 102 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 103 public void fireEvent() { 104 DrawPages.insertNewByIndex(2); 105 } 106 }); 107 108 return tEnv; 109 110 } 111 112 /** 113 * Called while disposing a <code>TestEnvironment</code>. 114 * Disposes Impress documents. 115 * @param Param test parameters 116 * @param log writer to log information while testing 117 */ cleanup( TestParameters Param, PrintWriter log )118 protected void cleanup( TestParameters Param, PrintWriter log ) { 119 log.println("disposing impress document"); 120 util.DesktopTools.closeDoc(xImpressDoc); 121 } 122 123 /** 124 * Called while the <code>TestCase</code> initialization. In the 125 * implementation does nothing. Subclasses can override to initialize 126 * objects shared among all <code>TestEnvironment</code>s. 127 * 128 * @param Param test parameters 129 * @param log writer to log information while testing 130 * 131 * @see #initializeTestCase 132 */ initialize(TestParameters Param, PrintWriter log)133 protected void initialize(TestParameters Param, PrintWriter log) { 134 // get a soffice factory object 135 SOfficeFactory SOF = SOfficeFactory.getFactory( 136 (XMultiServiceFactory)Param.getMSF()); 137 138 try { 139 log.println( "creating a impress document" ); 140 xImpressDoc = SOF.createImpressDoc(null); 141 } catch (com.sun.star.uno.Exception e) { 142 e.printStackTrace( log ); 143 throw new StatusException("Couldn't create document", e); 144 } 145 146 shortWait(); 147 148 aModel = (XModel) 149 UnoRuntime.queryInterface(XModel.class, xImpressDoc); 150 151 //Change to Outline view 152 try { 153 String aSlotID = "slot:27011"; 154 XDispatchProvider xDispProv = (XDispatchProvider) 155 UnoRuntime.queryInterface( XDispatchProvider.class, 156 aModel.getCurrentController() ); 157 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 158 UnoRuntime.queryInterface(XURLTransformer.class, 159 ((XMultiServiceFactory)Param.getMSF()). 160 createInstance("com.sun.star.util.URLTransformer")); 161 // Because it's an in/out parameter we must use an array of URL objects. 162 URL[] aParseURL = new URL[1]; 163 aParseURL[0] = new URL(); 164 aParseURL[0].Complete = aSlotID; 165 xParser.parseStrict(aParseURL); 166 URL aURL = aParseURL[0]; 167 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 168 if( xDispatcher != null ) 169 xDispatcher.dispatch( aURL, null ); 170 } catch (com.sun.star.uno.Exception e) { 171 log.println("Couldn't change mode"); 172 } 173 174 shortWait(); 175 176 } 177 shortWait()178 private void shortWait() { 179 try { 180 Thread.sleep(2000) ; 181 } catch (InterruptedException e) { 182 System.out.println("While waiting :" + e) ; 183 } 184 } 185 } 186 187