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 AccessibleOutlineView 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 tParam test parameters 63 * @param log writer to log information while testing 64 * 65 * @see TestEnvironment 66 * @see #getTestEnvironment() 67 */ 68 protected TestEnvironment createTestEnvironment 69 (TestParameters Param, PrintWriter log) { 70 XInterface oObj = null; 71 72 AccessibilityTools at = new AccessibilityTools(); 73 74 XWindow xWindow = at.getCurrentWindow ( 75 (XMultiServiceFactory)Param.getMSF(),aModel); 76 XAccessible xRoot = at.getAccessibleObject(xWindow); 77 78 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT); 79 80 oObj = AccessibilityTools.SearchedContext; 81 82 log.println("ImplementationName "+utils.getImplName(oObj)); 83 84 TestEnvironment tEnv = new TestEnvironment(oObj); 85 86 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 87 UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel); 88 final XDrawPages oDPn = oDPS.getDrawPages(); 89 90 tEnv.addObjRelation("EventMsg","Inserting a drawpage via API has no "+ 91 "effect to the outline view #101050# \r\n"+ 92 "Therefore the listener isn't called"); 93 94 tEnv.addObjRelation("EventProducer", 95 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 96 public void fireEvent() { 97 oDPn.insertNewByIndex(1); 98 } 99 }); 100 101 return tEnv; 102 103 } 104 105 /** 106 * Called while disposing a <code>TestEnvironment</code>. 107 * Disposes Impress documents. 108 * @param tParam test parameters 109 * @param tEnv the environment to cleanup 110 * @param log writer to log information while testing 111 */ 112 protected void cleanup( TestParameters Param, PrintWriter log ) { 113 log.println("disposing Impress document"); 114 util.DesktopTools.closeDoc(xImpressDoc); 115 } 116 117 /** 118 * Called while the <code>TestCase</code> initialization. In the 119 * implementation does nothing. Subclasses can override to initialize 120 * objects shared among all <code>TestEnvironment</code>s. 121 * 122 * @param tParam test parameters 123 * @param log writer to log information while testing 124 * 125 * @see #initializeTestCase() 126 */ 127 protected void initialize(TestParameters Param, PrintWriter log) { 128 // get a soffice factory object 129 SOfficeFactory SOF = SOfficeFactory.getFactory( 130 (XMultiServiceFactory)Param.getMSF()); 131 132 try { 133 log.println( "creating a impress document" ); 134 xImpressDoc = SOF.createImpressDoc(null); 135 shortWait(); 136 } catch (com.sun.star.uno.Exception e) { 137 e.printStackTrace( log ); 138 throw new StatusException("Couldn't create document", e); 139 } 140 141 aModel = (XModel) 142 UnoRuntime.queryInterface(XModel.class, xImpressDoc); 143 144 XInterface oObj = aModel.getCurrentController(); 145 146 //Change to Outline view 147 try { 148 String aSlotID = "slot:27010"; 149 XDispatchProvider xDispProv = (XDispatchProvider) 150 UnoRuntime.queryInterface( XDispatchProvider.class, oObj ); 151 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 152 UnoRuntime.queryInterface(XURLTransformer.class, 153 ((XMultiServiceFactory)Param.getMSF()). 154 createInstance("com.sun.star.util.URLTransformer")); 155 // Because it's an in/out parameter we must use an array of URL objects. 156 URL[] aParseURL = new URL[1]; 157 aParseURL[0] = new URL(); 158 aParseURL[0].Complete = aSlotID; 159 xParser.parseStrict(aParseURL); 160 URL aURL = aParseURL[0]; 161 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 162 if( xDispatcher != null ) 163 xDispatcher.dispatch( aURL, null ); 164 } catch (com.sun.star.uno.Exception e) { 165 log.println("Couldn't change mode"); 166 } 167 shortWait(); 168 } 169 170 private void shortWait() { 171 try { 172 Thread.sleep(2000) ; 173 } catch (InterruptedException e) { 174 System.out.println("While waiting :" + e) ; 175 } 176 } 177 } 178 179