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 package mod._toolkit; 24 25 import com.sun.star.accessibility.AccessibleRole; 26 import com.sun.star.accessibility.XAccessible; 27 import com.sun.star.accessibility.XAccessibleAction; 28 import com.sun.star.accessibility.XAccessibleContext; 29 import com.sun.star.accessibility.XAccessibleSelection; 30 import com.sun.star.awt.XExtendedToolkit; 31 import com.sun.star.awt.XWindow; 32 import com.sun.star.beans.PropertyValue; 33 import com.sun.star.frame.XController; 34 import com.sun.star.frame.XDesktop; 35 import com.sun.star.frame.XDispatch; 36 import com.sun.star.frame.XDispatchProvider; 37 import com.sun.star.frame.XModel; 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.XInterface; 42 import com.sun.star.util.URL; 43 import com.sun.star.util.XURLTransformer; 44 45 import java.io.PrintWriter; 46 47 import lib.StatusException; 48 import lib.TestCase; 49 import lib.TestEnvironment; 50 import lib.TestParameters; 51 52 import util.AccessibilityTools; 53 import util.DesktopTools; 54 import util.SOfficeFactory; 55 56 57 /** 58 * Test for object that implements the following interfaces : 59 * <ul> 60 * <li><code> 61 * ::com::sun::star::accessibility::XAccessibleContext</code></li> 62 * <li><code> 63 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster 64 * </code></li> 65 * <li><code> 66 * ::com::sun::star::accessibility::XAccessibleComponent</code></li> 67 * <li><code> 68 * ::com::sun::star::accessibility::XAccessibleExtendedComponent 69 * </code></li> 70 * <li><code> 71 * ::com::sun::star::accessibility::XAccessibleSelection 72 * </code></li> 73 * </ul> <p> 74 * 75 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 76 * @see com.sun.star.accessibility.XAccessibleContext 77 * @see com.sun.star.accessibility.XAccessibleComponent 78 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 79 * @see com.sun.star.accessibility.XAccessibleSelection 80 * @see ifc.accessibility._XAccessibleEventBroadcaster 81 * @see ifc.accessibility._XAccessibleContext 82 * @see ifc.accessibility._XAccessibleComponent 83 * @see ifc.accessibility.XAccessibleExtendedComponent 84 * @see ifc.accessibility.XAccessibleSelection 85 */ 86 public class AccessibleTabControl extends TestCase { 87 private static XDesktop the_Desk; 88 private static XTextDocument xTextDoc; 89 private static XAccessibleAction accCloseButton = null; 90 91 /** 92 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 93 */ 94 protected void initialize(TestParameters Param, PrintWriter log) { 95 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 96 DesktopTools.createDesktop( 97 (XMultiServiceFactory) Param.getMSF())); 98 } 99 100 /** 101 * Closes an InsertFields dialog, disposes the document, if exists, created in 102 * <code>createTestEnvironment</code> method. 103 */ 104 protected void cleanup(TestParameters Param, PrintWriter log) { 105 try { 106 if (accCloseButton != null) { 107 log.println("closing InsertFields Dialog"); 108 accCloseButton.doAccessibleAction(0); 109 } 110 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 111 e.printStackTrace(log); 112 } 113 114 log.println("disposing xTextDoc"); 115 116 if (xTextDoc != null) { 117 util.DesktopTools.closeDoc(xTextDoc); 118 ; 119 } 120 } 121 122 /** 123 * Creates a text document, opens an InsertField dialog. 124 * Then obtains an accessible object with 125 * the role <code>AccessibleRole.PAGETABLIST</code>. 126 * Object relations created : 127 * <ul> 128 * <li> <code>'EventProducer'</code> for 129 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 130 * selects items </li> 131 * <li> <code>'XAccessibleSelection.multiSelection'</code> 132 * of type <code>Boolean</code> for 133 * {@link ifc.accessibility._XAccessibleSelection}: 134 * indicates that component supports single selection mode.</li> 135 * </ul> 136 * 137 * @param tParam test parameters 138 * @param log writer to log information while testing 139 * 140 * @see com.sun.star.awt.Toolkit 141 * @see com.sun.star.accessibility.AccessibleRole 142 * @see ifc.accessibility._XAccessibleEventBroadcaster 143 * @see ifc.accessibility._XAccessibleSelection 144 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 145 * @see com.sun.star.accessibility.XAccessibleSelection 146 */ 147 protected TestEnvironment createTestEnvironment(TestParameters tParam, 148 PrintWriter log) { 149 log.println("creating a test environment"); 150 151 if (xTextDoc != null) { 152 util.DesktopTools.closeDoc(xTextDoc); 153 ; 154 } 155 156 // get a soffice factory object 157 SOfficeFactory SOF = SOfficeFactory.getFactory( 158 (XMultiServiceFactory) tParam.getMSF()); 159 160 try { 161 log.println("creating a text document"); 162 xTextDoc = SOF.createTextDoc(null); 163 } catch (com.sun.star.uno.Exception e) { 164 // Some exception occures.FAILED 165 e.printStackTrace(log); 166 throw new StatusException("Couldn't create document", e); 167 } 168 169 shortWait(); 170 171 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 172 xTextDoc); 173 174 XController secondController = aModel1.getCurrentController(); 175 176 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface( 177 XDispatchProvider.class, 178 secondController); 179 180 XURLTransformer urlTransf = null; 181 182 try { 183 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance( 184 "com.sun.star.util.URLTransformer"); 185 urlTransf = (XURLTransformer) UnoRuntime.queryInterface( 186 XURLTransformer.class, transf); 187 } catch (com.sun.star.uno.Exception e) { 188 e.printStackTrace(log); 189 throw new StatusException("Couldn't create URLTransformer", e); 190 } 191 192 XDispatch getting = null; 193 log.println("opening InsertField dialog"); 194 195 URL[] url = new URL[1]; 196 url[0] = new URL(); 197 url[0].Complete = ".uno:InsertField"; 198 urlTransf.parseStrict(url); 199 getting = aProv.queryDispatch(url[0], "", 0); 200 201 PropertyValue[] noArgs = new PropertyValue[0]; 202 getting.dispatch(url[0], noArgs); 203 204 shortWait(); 205 206 XInterface oObj = null; 207 208 try { 209 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance( 210 "com.sun.star.awt.Toolkit"); 211 } catch (com.sun.star.uno.Exception e) { 212 log.println("Couldn't get toolkit"); 213 e.printStackTrace(log); 214 throw new StatusException("Couldn't get toolkit", e); 215 } 216 217 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 218 XExtendedToolkit.class, oObj); 219 220 AccessibilityTools at = new AccessibilityTools(); 221 222 shortWait(); 223 224 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 225 tk.getActiveTopWindow()); 226 227 XAccessible xRoot = at.getAccessibleObject(xWindow); 228 229 oObj = at.getAccessibleObjectForRole(xRoot, 230 AccessibleRole.PAGE_TAB_LIST); 231 232 XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot, 233 AccessibleRole.PUSH_BUTTON, 234 "Close"); 235 236 accCloseButton = (XAccessibleAction) UnoRuntime.queryInterface( 237 XAccessibleAction.class, closeButton); 238 239 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 240 241 TestEnvironment tEnv = new TestEnvironment(oObj); 242 243 final XAccessibleSelection selection = (XAccessibleSelection) (XAccessibleSelection) UnoRuntime.queryInterface( 244 XAccessibleSelection.class, 245 oObj); 246 247 tEnv.addObjRelation("EventProducer", 248 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 249 public void fireEvent() { 250 try { 251 selection.selectAccessibleChild(1); 252 selection.selectAccessibleChild(0); 253 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 254 } 255 } 256 }); 257 258 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected", 259 new Boolean(true)); 260 261 tEnv.addObjRelation("XAccessibleSelection.multiSelection", 262 new Boolean(false)); 263 264 return tEnv; 265 } 266 267 /** 268 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 269 * reset</code> call. 270 */ 271 private void shortWait() { 272 try { 273 Thread.currentThread().sleep(500); 274 } catch (InterruptedException e) { 275 System.out.println("While waiting :" + e); 276 } 277 } 278 }