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.awt.XExtendedToolkit; 30 import com.sun.star.awt.XWindow; 31 import com.sun.star.frame.XModel; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.text.XTextDocument; 34 import com.sun.star.uno.UnoRuntime; 35 import com.sun.star.uno.XInterface; 36 37 import java.io.PrintWriter; 38 39 import lib.StatusException; 40 import lib.TestCase; 41 import lib.TestEnvironment; 42 import lib.TestParameters; 43 44 import util.AccessibilityTools; 45 import util.SOfficeFactory; 46 import util.utils; 47 48 49 /** 50 * Test for object which is represented by accessible component 51 * of a menu separator in main menu of a document. <p> 52 * 53 * Object implements the following interfaces : 54 * <ul> 55 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 56 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 57 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 58 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 59 * </ul> <p> 60 * 61 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 63 * @see com.sun.star.accessibility.XAccessibleComponent 64 * @see com.sun.star.accessibility.XAccessibleContext 65 * @see ifc.accessibility._XAccessibleExtendedComponent 66 * @see ifc.accessibility._XAccessibleEventBroadcaster 67 * @see ifc.accessibility._XAccessibleComponent 68 * @see ifc.accessibility._XAccessibleContext 69 */ 70 public class AccessibleMenuSeparator extends TestCase { 71 private static XTextDocument xTextDoc = null; 72 private static XAccessibleAction action = null; 73 private static XMultiServiceFactory msf = null; 74 75 /** 76 * Finds first accessible component with role <code>SEPARATOR</code> 77 * and implementation name <code>AccessibleMenuSeparator</code> 78 * walking through the accessible component tree of a document. 79 */ 80 protected TestEnvironment createTestEnvironment(TestParameters Param, 81 PrintWriter log) { 82 shortWait(); 83 84 AccessibilityTools at = new AccessibilityTools(); 85 86 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc). 87 getCurrentController().getFrame().getContainerWindow(); 88 89 XAccessible xRoot = at.getAccessibleObject(xWindow); 90 91 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 92 XAccessibleContext MenuBar = at.getAccessibleObjectForRole(xRoot, 93 AccessibleRole.MENU_BAR); 94 XAccessibleAction act = null; 95 XInterface oObj = null; 96 97 try { 98 //activate Edit-Menu 99 XAccessible Menu = MenuBar.getAccessibleChild(1); 100 act = (XAccessibleAction) UnoRuntime.queryInterface( 101 XAccessibleAction.class, Menu); 102 act.doAccessibleAction(0); 103 104 shortWait(); 105 106 107 //get a menue-separator 108 oObj = Menu.getAccessibleContext().getAccessibleChild(3); 109 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 110 e.printStackTrace(log); 111 } 112 113 log.println("ImplementationName " + utils.getImplName(oObj)); 114 115 TestEnvironment tEnv = new TestEnvironment(oObj); 116 117 final XAccessibleAction aAct = act; 118 119 tEnv.addObjRelation("EventProducer", 120 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 121 public void fireEvent() { 122 try { 123 aAct.doAccessibleAction(0); 124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 125 e.printStackTrace(); 126 } 127 } 128 }); 129 130 return tEnv; 131 } 132 133 /** 134 * Creates writer document. 135 */ 136 protected void initialize(TestParameters Param, PrintWriter log) { 137 try { 138 msf = (XMultiServiceFactory) Param.getMSF(); 139 140 SOfficeFactory SOF = SOfficeFactory.getFactory(msf); 141 xTextDoc = SOF.createTextDoc(null); 142 } catch (com.sun.star.uno.Exception e) { 143 throw new StatusException("Can't create document", e); 144 } 145 } 146 147 /** 148 * Disposes document. 149 */ 150 protected void cleanup(TestParameters Param, PrintWriter log) { 151 util.DesktopTools.closeDoc(xTextDoc); 152 ; 153 } 154 155 /** 156 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 157 * reset</code> call. 158 */ 159 private void shortWait() { 160 try { 161 Thread.sleep(500); 162 } catch (InterruptedException e) { 163 log.println("While waiting :" + e); 164 } 165 } 166 }